IMP  2.3.1
The Integrative Modeling Platform
dof.py
1 class dof(object):
2  """Degrees of Freedom
3  Tasks:
4  define rigid bodies and super rigid bodies
5  define symmetries (see representation.py)
6  create nuisances and their parameters
7  generate lists of MC or MD movers
8  """
9  def __init__(self,root,
10  maxtrans_rb=None,maxrot_rb=None,
11  maxtrans_srb=None,maxrot_srb=None):
12  self.rigid_bodies = []
13  self.fixed_rigid_bodies = []
14  self.floppy_bodies = []
15  self.super_rigid_bodies = []
16 
17  self.maxtrans_rb = 2.0
18  self.maxrot_rb = 0.04
19  self.maxtrans_srb = 2.0
20  self.maxrot_srb = 0.2
21  self.rigidbodiesarefixed = False
22  self.maxtrans_fb = 3.0
23  self.mdl = mdl
24 
25  def set_rigid_body_from_hierarchies(self, hiers, particles=None):
26  '''
27  This method allows the construction of a rigid body given a list
28  of hierarchies and or a list of particles.
29 
30  hiers: list of hierarchies
31  particles: (optional, default=None) list of particles to add to the rigid body
32  '''
33 
34  if particles is None:
35  rigid_parts = set()
36  else:
37  rigid_parts = set(particles)
38 
39  name = ""
40  print "set_rigid_body_from_hierarchies> setting up a new rigid body"
41  for hier in hiers:
42  ps = IMP.atom.get_leaves(hier)
43  for p in ps:
45  rb = IMP.core.RigidMember(p).get_rigid_body()
46  print "set_rigid_body_from_hierarchies> WARNING particle %s already belongs to rigid body %s" % (p.get_name(), rb.get_name())
47  else:
48  rigid_parts.add(p)
49  name += hier.get_name() + "-"
50  print "set_rigid_body_from_hierarchies> adding %s to the rigid body" % hier.get_name()
51  rb = IMP.atom.create_rigid_body(list(rigid_parts))
52  rb.set_coordinates_are_optimized(True)
53  rb.set_name(name + "rigid_body")
54  self.rigid_bodies.append(rb)
55  return rb
56 
57  def set_rigid_bodies(self, subunits):
58  '''
59  This method allows the construction of a rigid body given a list
60  of tuples, that identify the residue ranges and the subunit names (the names used
61  to create the component by using create_component.
62 
63  subunits: [(name_1,(first_residue_1,last_residue_1)),(name_2,(first_residue_2,last_residue_2)),.....]
64  or
65  [name_1,name_2,(name_3,(first_residue_3,last_residue_3)),.....]
66 
67  example: ["prot1","prot2",("prot3",(1,10))]
68 
69  sometimes, we know about structure of an interaction
70  and here we make such PPIs rigid
71  '''
72 
73  rigid_parts = set()
74  for s in subunits:
75  if type(s) == type(tuple()) and len(s) == 2:
76  sel = IMP.atom.Selection(
77  self.prot,
78  molecule=s[0],
79  residue_indexes=range(s[1][0],
80  s[1][1] + 1))
81  if len(sel.get_selected_particles()) == 0:
82  print "set_rigid_bodies: selected particle does not exists"
83  for p in sel.get_selected_particles():
84  # if not p in self.floppy_bodies:
86  rb = IMP.core.RigidMember(p).get_rigid_body()
87  print "set_rigid_body_from_hierarchies> WARNING particle %s already belongs to rigid body %s" % (p.get_name(), rb.get_name())
88  else:
89  rigid_parts.add(p)
90 
91  elif type(s) == type(str()):
92  sel = IMP.atom.Selection(self.prot, molecule=s)
93  if len(sel.get_selected_particles()) == 0:
94  print "set_rigid_bodies: selected particle does not exists"
95  for p in sel.get_selected_particles():
96  # if not p in self.floppy_bodies:
98  rb = IMP.core.RigidMember(p).get_rigid_body()
99  print "set_rigid_body_from_hierarchies> WARNING particle %s already belongs to rigid body %s" % (p.get_name(), rb.get_name())
100  else:
101  rigid_parts.add(p)
102 
103  rb = IMP.atom.create_rigid_body(list(rigid_parts))
104  rb.set_coordinates_are_optimized(True)
105  rb.set_name(''.join(str(subunits)) + "_rigid_body")
106  self.rigid_bodies.append(rb)
107  return rb
108 
109  def set_super_rigid_body_from_hierarchies(
110  self,
111  hiers,
112  axis=None,
113  min_size=0):
114  # axis is the rotation axis for 2D rotation
115  super_rigid_xyzs = set()
116  super_rigid_rbs = set()
117  name = ""
118  print "set_super_rigid_body_from_hierarchies> setting up a new SUPER rigid body"
119 
120  for hier in hiers:
121  ps = IMP.atom.get_leaves(hier)
122  for p in ps:
124  rb = IMP.core.RigidMember(p).get_rigid_body()
125  super_rigid_rbs.add(rb)
126  else:
127  super_rigid_xyzs.add(p)
128  print "set_rigid_body_from_hierarchies> adding %s to the rigid body" % hier.get_name()
129  if len(super_rigid_rbs) < min_size:
130  return
131  if axis is None:
132  self.super_rigid_bodies.append((super_rigid_xyzs, super_rigid_rbs))
133  else:
134  # these will be 2D rotation SRB
135  self.super_rigid_bodies.append(
136  (super_rigid_xyzs, super_rigid_rbs, axis))
137 
138  def fix_rigid_bodies(self, rigid_bodies):
139  self.fixed_rigid_bodies += rigid_bodies
140 
142  self,
143  hiers,
144  min_length=None,
145  max_length=None,
146  axis=None):
147  '''
148  this function takes a linear list of hierarchies (they are supposed
149  to be sequence-contiguous) and
150  produces a chain of super rigid bodies with given length range, specified
151  by min_length and max_length
152  '''
153  try:
154  hiers = IMP.pmi.tools.flatten_list(hiers)
155  except:
156  pass
157  for hs in IMP.pmi.tools.sublist_iterator(hiers, min_length, max_length):
158  self.set_super_rigid_body_from_hierarchies(hs, axis, min_length)
159 
160  def set_super_rigid_bodies(self, subunits, coords=None):
161  super_rigid_xyzs = set()
162  super_rigid_rbs = set()
163 
164  for s in subunits:
165  if type(s) == type(tuple()) and len(s) == 3:
166  sel = IMP.atom.Selection(
167  self.prot,
168  molecule=s[2],
169  residue_indexes=range(s[0],
170  s[1] + 1))
171  if len(sel.get_selected_particles()) == 0:
172  print "set_rigid_bodies: selected particle does not exists"
173  for p in sel.get_selected_particles():
175  rb = IMP.core.RigidMember(p).get_rigid_body()
176  super_rigid_rbs.add(rb)
177  else:
178  super_rigid_xyzs.add(p)
179  elif type(s) == type(str()):
180  sel = IMP.atom.Selection(self.prot, molecule=s)
181  if len(sel.get_selected_particles()) == 0:
182  print "set_rigid_bodies: selected particle does not exists"
183  for p in sel.get_selected_particles():
184  # if not p in self.floppy_bodies:
186  rb = IMP.core.RigidMember(p).get_rigid_body()
187  super_rigid_rbs.add(rb)
188  else:
189  super_rigid_xyzs.add(p)
190  self.super_rigid_bodies.append((super_rigid_xyzs, super_rigid_rbs))
191 
192  def remove_floppy_bodies(self, hierarchies):
193  '''
194  give a list of hierarchies, get the leaves and remove the corresponding particles
195  from the floppy bodies list. We need this function because sometimes
196  we want to constraint the floppy bodies in a rigid body. For instance
197  when you want to associate a bead with a density particle.
198  '''
199  for h in hierarchies:
200  ps = IMP.atom.get_leaves(h)
201  for p in ps:
202  if p in self.floppy_bodies:
203  print "remove_floppy_bodies: removing %s from floppy body list" % p.get_name()
204  self.floppy_bodies.remove(p)
205 
206  def set_floppy_bodies(self):
207  for p in self.floppy_bodies:
208  name = p.get_name()
209  p.set_name(name + "_floppy_body")
211  print "I'm trying to make this particle flexible although it was assigned to a rigid body", p.get_name()
212  rb = IMP.core.RigidMember(p).get_rigid_body()
213  try:
214  rb.set_is_rigid_member(p.get_index(), False)
215  except:
216  # some IMP versions still work with that
217  rb.set_is_rigid_member(p.get_particle_index(), False)
218  p.set_name(p.get_name() + "_rigid_body_member")
219 
220  def set_floppy_bodies_from_hierarchies(self, hiers):
221  for hier in hiers:
222  ps = IMP.atom.get_leaves(hier)
223  for p in ps:
224  IMP.core.XYZ(p).set_coordinates_are_optimized(True)
225  self.floppy_bodies.append(p)
226 
227  def get_particles_to_sample(self):
228  # get the list of samplable particles with their type
229  # and the mover displacement. Everything wrapped in a dictionary,
230  # to be used by samplers modules
231  ps = {}
232 
233  # remove symmetric particles: they are not sampled
234  rbtmp = []
235  fbtmp = []
236  srbtmp = []
237  if not self.rigidbodiesarefixed:
238  for rb in self.rigid_bodies:
240  if IMP.pmi.Symmetric(rb).get_symmetric() != 1:
241  rbtmp.append(rb)
242  else:
243  if rb not in self.fixed_rigid_bodies:
244  rbtmp.append(rb)
245 
246  for fb in self.floppy_bodies:
248  if IMP.pmi.Symmetric(fb).get_symmetric() != 1:
249  fbtmp.append(fb)
250  else:
251  fbtmp.append(fb)
252 
253  for srb in self.super_rigid_bodies:
254  # going to prune the fixed rigid bodies out
255  # of the super rigid body list
256  rigid_bodies = list(srb[1])
257  filtered_rigid_bodies = []
258  for rb in rigid_bodies:
259  if rb not in self.fixed_rigid_bodies:
260  filtered_rigid_bodies.append(rb)
261  srbtmp.append((srb[0], filtered_rigid_bodies))
262 
263  self.rigid_bodies = rbtmp
264  self.floppy_bodies = fbtmp
265  self.super_rigid_bodies = srbtmp
266 
267  ps["Rigid_Bodies_SimplifiedModel"] = (
268  self.rigid_bodies,
269  self.maxtrans_rb,
270  self.maxrot_rb)
271  ps["Floppy_Bodies_SimplifiedModel"] = (
272  self.floppy_bodies,
273  self.maxtrans_fb)
274  ps["SR_Bodies_SimplifiedModel"] = (
275  self.super_rigid_bodies,
276  self.maxtrans_srb,
277  self.maxrot_srb)
278  return ps
def remove_floppy_bodies
give a list of hierarchies, get the leaves and remove the corresponding particles from the floppy bod...
Definition: dof.py:192
Add symmetric attribute to a particle.
Definition: Symmetric.h:23
def set_rigid_bodies
This method allows the construction of a rigid body given a list of tuples, that identify the residue...
Definition: dof.py:57
def set_rigid_body_from_hierarchies
This method allows the construction of a rigid body given a list of hierarchies and or a list of part...
Definition: dof.py:25
static bool get_is_setup(Model *m, ParticleIndex pi)
Definition: Symmetric.h:29
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
def set_chain_of_super_rigid_bodies
this function takes a linear list of hierarchies (they are supposed to be sequence-contiguous) and pr...
Definition: dof.py:141
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
Definition: rigid_bodies.h:479
IMP::core::RigidBody create_rigid_body(Hierarchy h)
Hierarchies get_leaves(const Selection &h)
Select hierarchy particles identified by the biological name.
Definition: Selection.h:62
def sublist_iterator
this iterator yields all sublists of length >= lmin and <= lmax
Definition: tools.py:1015