IMP  2.3.1
The Integrative Modeling Platform
sampling_tools.py
1 #!/usr/bin/env python
2 """useful tools for setting up sampling"""
3 
4 import IMP
5 import IMP.atom
6 
7 class SampleObjects(object):
8  """ hack class to provide things to sample for PMI::samplers """
9  def __init__(self,dict_name,pack_in_dict):
10  self.d={dict_name:pack_in_dict}
11  def get_particles_to_sample(self):
12  return self.d
13 
14 def enable_md_sampling(mdl,
15  hier=None,
16  particles=None,
17  include_siblings=False,
18  exclude_backbone=False):
19  """ Adds necessary attributes to the selected residues for MD sampling
20  @param model The IMP model
21  @param hier Hierarchy to sample
22  @param particles Particles to sample
23  @param selection Single or multiple selections for enabling sampling
24  @param include_siblings Get the siblings of the passed particles and sample them too
25  @param exclude_backbone Don't sample backbone atoms
26  """
27  vxkey = IMP.FloatKey('vx')
28  vykey = IMP.FloatKey('vy')
29  vzkey = IMP.FloatKey('vz')
30  backbone = [IMP.atom.AT_C,IMP.atom.AT_N, IMP.atom.AT_CA]
31  if particles is None:
32  particles=[]
33  if hier is not None:
34  particles+=IMP.atom.get_leaves(hier)
35  all_ps=[]
36  for p in particles:
37  if include_siblings:
38  ps=[x.get_particle() for x in IMP.atom.Hierarchy(p).get_parent().get_children()]
39  else:
40  ps=[p]
41  for pp in ps:
42  if exclude_backbone and IMP.atom.Atom(mdl,pp.get_particle_index()).get_atom_type() in backbone:
43  continue
44  IMP.core.XYZ(mdl,pp.get_particle_index()).set_coordinates_are_optimized(True)
45  mdl.add_attribute(vxkey,pp.get_particle_index(),0.0)
46  mdl.add_attribute(vykey,pp.get_particle_index(),0.0)
47  mdl.add_attribute(vzkey,pp.get_particle_index(),0.0)
48  all_ps.append(pp)
49  return [SampleObjects('Floppy_Bodies_SimplifiedModel',[all_ps])]
useful tools for setting up sampling
The standard decorator for manipulating molecular structures.
A decorator for a particle representing an atom.
Definition: atom/Atom.h:234
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)