IMP logo
IMP Reference Guide  2.12.0
The Integrative Modeling Platform
pmi/dof/__init__.py
1 """@namespace IMP.pmi.dof
2  Create movers and set up constraints for PMI objects.
3  See the documentation of the DegreesOfFreedom class for more information.
4 """
5 
6 from __future__ import print_function
7 import IMP
8 import IMP.atom
9 import IMP.algebra
10 import IMP.pmi
11 import IMP.pmi.topology
12 import IMP.pmi.samplers
13 import IMP.pmi.tools
14 import itertools
15 import IMP.pmi.samplers
16 import warnings
17 
18 def create_rigid_body_movers(dof,maxtrans,maxrot):
19  mvs = []
20  for rb in dof.rigid_bodies:
21  mvs.append(IMP.core.RigidBodyMover(rb.get_model(), rb,
22  maxtrans, maxrot))
23  return mvs
24 
25 class DegreesOfFreedom(object):
26  """Simplify creation of constraints and movers for an IMP Hierarchy.
27 
28  * The various "create X" functions make movers for system components
29  as well as set up necessary constraints. For each of these functions,
30  you can generally pass PMI objects like
31  [Molecule](@ref IMP::pmi::topology::Molecule) or slices thereof.
32  * DegreesOfFreedom.create_rigid_body() lets you rigidify a molecule
33  (but allows you to also pass "nonrigid" components which move with
34  the body and also independently).
35  * DegreesOfFreedom.create_super_rigid_body() sets up a special
36  "Super Rigid Body" which moves rigidly but is not always constrained
37  to be rigid (so you can later move the parts separately). This is
38  good for speeding up sampling.
39  * DegreesOfFreedom.create_flexible_beads() sets up particles to move
40  individually.
41  * DegreesOfFreedom.setup_md() sets up particles to move with molecular
42  dynamics. Note that this is not (yet) compatible with rigid bodies,
43  and only works with some restraints.
44  * DegreesOfFreedom.constrain_symmetry() makes a symmetry constraint so
45  that clones automatically move with their references. If instead you
46  want a softer restraint, check out the
47  [SymmetryRestraint](@ref IMP::pmi::restraints::stereochemistry::SymmetryRestraint).
48  * When you are done you can access all movers with
49  DegreesOfFreedom.get_movers(). If you have set up rigid, super rigid,
50  or flexible beads, pass the movers to the `monte_carlo_sample_objects`
51  argument of
52  [ReplicaExchange0](@ref IMP::pmi::macros::ReplicaExchange0).
53  * If you are running MD, you have to separately pass the particles
54  (also returned from DegreesOfFreedom.setup_md()) to the
55  `molecular_dynamics_sample_objects` argument of
56  [ReplicaExchange0](@ref IMP::pmi::macros::ReplicaExchange0). Check
57  out an [MD example here](pmi_2atomistic_8py-example.html).
58  """
59  def __init__(self,model):
60  self.model = model
61  self.movers = []
62  self.fb_movers = [] #stores movers corresponding to floppy parts
63  self.rigid_bodies = [] #stores rigid body objects
64  self.flexible_beads = [] # stores all beads including nonrigid members of rigid bodies
65  self.nuisances = []
66  self._rb2mov = {} # Keys are the RigidBody objects, values are list of movers
67  # the following is needed to keep track of disabled movers
68  self.movers_particles_map=IMP.pmi.tools.OrderedDict()
69  self.movers_rb_map={}
70  self.movers_xyz_map={}
71  self.disabled_movers=[]
72 
73  #self.particle_map = {} # map from particles/rb objects to relevant movers+constraints
74  # internal mover = [mover obj, list of particles, enabled?] ?
75  # mover map = {particles/rbs : movers}
76 
77  def _get_nonrigid_hiers(self, nonrigid_parts, rigid_hiers, resolution):
78  """Get Hierarchy objects for nonrigid parts. Make sure that they are
79  a subset of the rigid body Hierarchies."""
80  if not nonrigid_parts:
81  return
82  nr_hiers = IMP.pmi.tools.input_adaptor(nonrigid_parts, resolution,
83  flatten=True)
84  if nr_hiers:
85  rb_idxs = set(h.get_particle_index() for h in rigid_hiers)
86  for h in nr_hiers:
87  p = h.get_particle()
88  if p.get_index() not in rb_idxs:
89  raise ValueError(
90  "You tried to create nonrigid members from "
91  "particles that aren't in the RigidBody!")
92  return nr_hiers
93 
95  rigid_parts,
96  nonrigid_parts=None,
97  max_trans=4.0,
98  max_rot=0.5,
99  nonrigid_max_trans = 4.0,
100  resolution='all',
101  name=None):
102  """Create rigid body constraint and mover
103  @param rigid_parts Can be one of the following inputs:
104  IMP Hierarchy, PMI System/State/Molecule/TempResidue, a list/set
105  (of list/set) of them or a RigidBody object.
106  Must be uniform input, however. No mixing object types.
107  @param nonrigid_parts Same input format as rigid_parts.
108  Must be a subset of rigid_parts particles.
109  @param max_trans Maximum rigid body translation
110  @param max_rot Maximum rigid body rotation
111  @param nonrigid_max_trans Maximum step for the nonrigid (bead) particles
112  @param resolution Only used if you pass PMI objects. Probably you
113  want 'all'.
114  @param name Rigid body name (if None, use IMP default)
115  @eturn (rb_movers,rb_object)
116  @note If you want all resolutions, pass PMI objects because this
117  function will get them all. Alternatively you can do your
118  selection elsewhere and just pass hierarchies.
119  """
120 
121  rb_movers = []
122 
123  # ADD CHECK: these particles are not already part of some RB or SRB
124 
125  # First, is this already a rigid body?
126  if type(rigid_parts) is IMP.core.RigidBody:
127  warnings.warn("Rigid Body Already Setup", IMP.pmi.ParameterWarning)
128  rb = rigid_parts
129  model=rb.get_model()
130  if name is None:
131  name = rb.get_name()
132  hiers= [IMP.atom.get_leaves(IMP.atom.Hierarchy(m.get_particle(i)))[0] for i in rb.get_member_particle_indexes()]
133  else:
134  ### Otherwise, setup RB
135  hiers = IMP.pmi.tools.input_adaptor(rigid_parts,
136  resolution,
137  flatten=True)
138 
139  if not hiers:
140  warnings.warn(
141  "No hierarchies were passed to create_rigid_body()",
143  return []
144 
145  # Need to do this before rigid body is set up so that we leave the
146  # system in a consistent state if a sanity check fails
147  nr_hiers = self._get_nonrigid_hiers(nonrigid_parts, hiers, resolution)
148 
149  if type(rigid_parts) is not IMP.core.RigidBody:
150  model=hiers[0].get_model()
151 
152  #we need to use the following constructor because the IMP.core.create_rigid_body seems
153  #to construct an arbitrary reference frame, which will be different for all copies.
154  #therefore, symmetry won't work all the time
155 
157  comcoor=IMP.core.XYZ(com).get_coordinates()
160  rbp=IMP.Particle(model)
162  for h in hiers:
163  rb.add_member(h.get_particle())
164 
165  self.rigid_bodies.append(rb)
166  rb.set_coordinates_are_optimized(True)
167  rb_mover = IMP.core.RigidBodyMover(rb.get_model(), rb, max_trans,
168  max_rot)
169  if name is not None:
170  rb.set_name(name)
171  rb_mover.set_name(name)
172  rb_movers.append(rb_mover)
173  self.movers_particles_map[rb_mover]=[]
174  self.movers_rb_map[rb_mover]=[rb]
175  rb_mover.set_was_used(True)
176  for h in hiers:
177  self.movers_particles_map[rb_mover]+=IMP.atom.get_leaves(h)
178  ### setup nonrigid parts
179  if nr_hiers:
180  floatkeys = [IMP.FloatKey(4), IMP.FloatKey(5), IMP.FloatKey(6)]
181  for h in nr_hiers:
182  self.flexible_beads.append(h)
183  p = h.get_particle()
184  rb.set_is_rigid_member(p.get_index(),False)
185  for fk in floatkeys:
186  p.set_is_optimized(fk,True)
187  fbmv=IMP.core.BallMover(p.get_model(), p,
188  IMP.FloatKeys(floatkeys),
189  nonrigid_max_trans)
190  self.fb_movers.append(fbmv)
191  self.movers_particles_map[fbmv]=IMP.atom.get_leaves(h)
192  self.movers_xyz_map[fbmv]=IMP.atom.get_leaves(h)
193  fbmv.set_was_used(True)
194  rb_movers.append(fbmv)
195 
196  self.movers += rb_movers # probably need to store more info
197  self._rb2mov[rb] = rb_movers #dictionary relating rb to movers
198 
199  return rb_movers,rb
200 
201  def create_main_chain_mover(self,molecule,resolution=10,lengths=[5,10]):
202  """Create crankshaft moves from a set of SUPER rigid body mover from one molecule.
203  See http://scfbm.biomedcentral.com/articles/10.1186/1751-0473-3-12
204  """
205  hiers=IMP.pmi.tools.input_adaptor(molecule,resolution,flatten=True)
206 
207  for length in lengths:
208  for n in range(len(hiers)-length):
209  hs=hiers[n+1:n+length]
210  #print("MIDDLE",n+1,n+length,hs)
211  self.create_super_rigid_body(hs, max_trans=0.0,max_rot=0.05, axis=(hiers[n].get_particle(),hiers[n+length].get_particle()))
212  #for n in range(1,len(hiers)-1,10):
213  # hs=hiers[n:]
214  # print("END",n,hs)
215  # self.create_super_rigid_body(hs, max_trans=0.01,axis=(hiers[n].get_particle(),hiers[n+1].get_particle()))
216  # hs=hiers[:n+1]
217  # print("BEGIN",n-1,hs)
218  # self.create_super_rigid_body(hs, max_trans=0.01,axis=(hiers[n].get_particle(),hiers[n-1].get_particle()))
219 
220  def create_super_rigid_body(self,
221  srb_parts,
222  max_trans=1.0,
223  max_rot=0.1,
224  chain_min_length=None,
225  chain_max_length=None,
226  resolution='all',
227  name=None,
228  axis=None):
229  """Create SUPER rigid body mover from one or more hierarchies.
230 
231  Can also create chain of SRBs. If you don't pass chain min/max,
232  it'll treat everything you pass as ONE rigid body.
233  If you DO pass chain min/max, it'll expect srb_parts is a list
234  and break it into bits.
235  @param srb_parts Can be one of the following inputs:
236  IMP Hierarchy, PMI System/State/Molecule/TempResidue,
237  or a list/set (of list/set) of them.
238  Must be uniform input, however. No mixing object types.
239  @param max_trans Maximum super rigid body translation
240  @param max_rot Maximum super rigid body rotation
241  @param chain_min_length Create a CHAIN of super rigid bodies -
242  must provide list; this parameter is the minimum chain length.
243  @param chain_max_length Maximum chain length
244  @param resolution Only used if you pass PMI objects. Probably you
245  want 'all'.
246  @param name The name of the SRB (hard to assign a good one
247  automatically)
248  @param axis A tuple containing two particles which are used to
249  compute the rotation axis of the SRB. The default is None,
250  meaning that the rotation axis is random.
251 
252  @note If you set the chain parameters, will NOT create an SRB from
253  all of them together, but rather in groups made from the
254  outermost list.
255  """
256 
257  srb_movers = []
258 
259  ## organize hierarchies based on chains
260  if chain_min_length is None and chain_max_length is None:
261  # the "chain" is just everything together
262  h = IMP.pmi.tools.input_adaptor(srb_parts,resolution,flatten=True)
263  if len(h)==0:
264  warnings.warn(
265  'No hierarchies were passed to create_super_rigid_body()',
267  return srb_movers
268  srb_groups = [h]
269  else:
270  if not hasattr(srb_parts,'__iter__'):
271  raise Exception("You tried to make a chain without a list!")
272  srb_groups = [IMP.pmi.tools.input_adaptor(h,resolution,flatten=True,
273  warn_about_slices=False) for h in srb_parts]
274 
275  ## create SRBs either from all hierarchies or chain
276  if chain_min_length is None and chain_max_length is None:
277  mv = self._setup_srb(srb_groups,max_trans,max_rot,axis)
278  if mv:
279  mv.set_was_used(True)
280  srb_movers.append(mv)
281  elif chain_min_length is not None and chain_max_length is not None:
282  for hs in IMP.pmi.tools.sublist_iterator(srb_groups, chain_min_length, chain_max_length):
283  mv = self._setup_srb(hs,max_trans,max_rot,axis)
284  if mv:
285  mv.set_was_used(True)
286  srb_movers.append(mv)
287  else:
288  raise Exception("DegreesOfFreedom: SetupSuperRigidBody: if you want chain, specify min AND max")
289  self.movers += srb_movers
290  if name is not None:
291  if len(srb_movers)>1:
292  for n,mv in enumerate(srb_movers):
293  mv.set_name(name+'_'+str(n))
294  else:
295  srb_movers[0].set_name(name)
296  return srb_movers
297 
298  def _setup_srb(self,hiers,max_trans,max_rot,axis):
299  if axis is None:
300  srbm = IMP.pmi.TransformMover(hiers[0][0].get_model(), max_trans, max_rot)
301  else:
302  srbm = IMP.pmi.TransformMover(hiers[0][0].get_model(),axis[0],axis[1],max_trans, max_rot)
303  srbm.set_was_used(True)
304  super_rigid_rbs,super_rigid_xyzs = IMP.pmi.tools.get_rbs_and_beads(hiers)
305  ct = 0
306  self.movers_particles_map[srbm]=[]
307  for h in hiers:
308  self.movers_particles_map[srbm]+=IMP.atom.get_leaves(h)
309  for xyz in super_rigid_xyzs:
310  srbm.add_xyz_particle(xyz)
311  ct+=1
312  for rb in super_rigid_rbs:
313  srbm.add_rigid_body_particle(rb)
314  ct+=1
315  if ct>1:
316  return srbm
317  else:
318  return 0
319 
320 
322  flex_parts,
323  max_trans=3.0,
324  resolution='all'):
325  """Create a chain of flexible beads
326 
327  @param flex_parts Can be one of the following inputs:
328  IMP Hierarchy, PMI System/State/Molecule/TempResidue,
329  or a list/set (of list/set) of them.
330  Must be uniform input, however. No mixing object types.
331  @param max_trans Maximum flexible bead translation
332  @param resolution Only used if you pass PMI objects. Probably
333  you want 'all'.
334  """
335 
336  fb_movers = []
337  hiers = IMP.pmi.tools.input_adaptor(flex_parts,
338  resolution,
339  flatten=True)
340  if not hiers or len(hiers)==0:
341  warnings.warn(
342  'No hierarchies were passed to create_flexible_beads()',
344  return fb_movers
345  for h in hiers:
346  p = h.get_particle()
347  IMP.core.XYZ(p).set_coordinates_are_optimized(True)
349  raise Exception("Cannot create flexible beads from members of rigid body")
350  self.flexible_beads.append(h)
351  fbmv=IMP.core.BallMover(p.get_model(), p, max_trans)
352  fb_movers.append(fbmv)
353  fbmv.set_was_used(True)
354  self.fb_movers.append(fbmv)
355  self.movers_particles_map[fbmv]=IMP.atom.get_leaves(h)
356  self.movers_xyz_map[fbmv]=IMP.atom.get_leaves(h)
357  self.movers += fb_movers
358  return fb_movers
359 
361  nuisance_p,
362  step_size,
363  name=None):
364  """Create MC normal mover for nuisance particles.
365  We will add an easier interface to add all of them from a PMI restraint
366  @param nuisance_p The Nuisance particle (an ISD::Scale)
367  @param step_size The maximum step size for Monte Carlo
368  @param name The name of the mover, useful for better output reading.
369  """
370  mv = IMP.core.NormalMover([nuisance_p],
371  IMP.FloatKeys([IMP.FloatKey("nuisance")]),
372  step_size)
373  if name is not None:
374  mv.set_name(name)
375  mv.set_was_used(True)
376  self.nuisances.append(nuisance_p)
377  self.movers.append(mv)
378  return [mv]
379 
380  def setup_md(self,
381  hspec):
382  """Setup particles for MD simulation. Returns all particles, just
383  pass this to molecular_dynamics_sample_objects in ReplicaExchange0.
384  @param hspec Can be one of the following inputs:
385  IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them.
386  Must be uniform input, however. No mixing object types.
387  """
388  vxkey = IMP.FloatKey('vx')
389  vykey = IMP.FloatKey('vy')
390  vzkey = IMP.FloatKey('vz')
391  hiers = IMP.pmi.tools.input_adaptor(hspec,flatten=True)
392  model = hiers[0].get_model()
393  all_ps = []
394  for hl in hiers:
395  for h in IMP.core.get_leaves(hl):
396  p = h.get_particle()
397  IMP.core.XYZ(model,p.get_index()).set_coordinates_are_optimized(True)
398  model.add_attribute(vxkey,p.get_index(),0.0)
399  model.add_attribute(vykey,p.get_index(),0.0)
400  model.add_attribute(vzkey,p.get_index(),0.0)
401  all_ps.append(p)
402  return all_ps
403 
405  references,
406  clones,
407  transform,
408  resolution='all',
409  type="AXIAL"):
410  """Create a symmetry constraint. Checks:
411  same number of particles
412  disable ANY movers involving symmetry copies
413  (later may support moving them WITH references,
414  but requires code to propagate constraint)
415  @param references Can be one of the following inputs:
416  IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them
417  @param clones Same format as references
418  @param transform The transform that moves a clone onto a reference
419  IMP.algebra.Transformation3D
420  @param resolution Only used if you pass PMI objects.
421  If you have a multires system, assuming each are rigid
422  bodies you probably only need one resolution.
423  @param type of symmetry. Implemented = AXIAL, RIGID_BODY
424  """
425 
426  # get all RBs and particles
427  href = IMP.pmi.tools.input_adaptor(references,resolution,flatten=True)
428  hclones = IMP.pmi.tools.input_adaptor(clones,resolution,flatten=True)
429 
430  ref_rbs,ref_beads = IMP.pmi.tools.get_rbs_and_beads(href)
431  clones_rbs,clones_beads = IMP.pmi.tools.get_rbs_and_beads(hclones)
432 
433  # dumb check for matching numbers of particles
434  #if len(ref_rbs)!=len(clones_rbs) or len(ref_beads)!=len(clones_beads):
435  # raise Exception("ERROR: Your references don't match your clones")
436 
437  # symmetry RBs
438  # this code produces weird results (random flipping of rigid bodies
439  #for ref,clone in zip(ref_rbs+ref_beads,clones_rbs+clones_beads):
440  # print(clone.get_particle().get_index(),ref.get_particle().get_index())
441  # IMP.core.Reference.setup_particle(clone.get_particle(),ref.get_particle())
442  for ref,clone in zip(ref_rbs,clones_rbs):
444 
445  for ref,clone in zip(ref_beads,clones_beads):
447 
448  # removing movers involved in clones
449  self.disable_movers(hclones)
450 
451  if type=="AXIAL":
452  sm = IMP.core.TransformationSymmetry(transform)
453 
454 
455  if type=="RIGID_BODY":
456  p=IMP.Particle(self.model)
457  p.set_name("RigidBody_Symmetry")
459  for cp in [(10,0,0),(0,10,0),(0,0,10)]:
460  p=IMP.Particle(self.model)
462  rb.add_member(p)
463  sm = IMP.core.TransformationSymmetry(rb.get_particle_index())
464  self.rigid_bodies.append(rb)
465  rb.set_coordinates_are_optimized(True)
466  rb_mover_tr = IMP.core.RigidBodyMover(rb.get_model(), rb.get_particle_index(), 0.0, 1.0)
467  rb_mover_rt = IMP.core.RigidBodyMover(rb.get_model(), rb.get_particle_index(), 10.0, 0.0)
468 
469  rb_mover_tr.set_name("RigidBody_Symmetry_Mover_Translate")
470  rb_mover_rt.set_name("RigidBody_Symmetry_Mover_Rotate")
471  print('Created rigid body symmetry restraint')
472  self.movers_particles_map[rb_mover_tr]=[]
473  self.movers_particles_map[rb_mover_rt]=[]
474  self.movers_rb_map[rb_mover_tr]=[rb]
475  self.movers_rb_map[rb_mover_rt]=[rb]
476  for h in hclones:
477  self.movers_particles_map[rb_mover_tr]+=IMP.atom.get_leaves(h)
478  self.movers_particles_map[rb_mover_rt]+=IMP.atom.get_leaves(h)
479  self.movers.append(rb_mover_tr) # probably need to store more info
480  self.movers.append(rb_mover_rt) # probably need to store more info
481  self._rb2mov[rb] = [rb_mover_tr,rb_mover_rt] #dictionary relating rb to movers
482  #self._rb2mov[rb] = [rb_mover_tr] #dictionary relating rb to movers
483 
485  self.model,[p.get_particle().get_index() for p in clones_rbs+clones_beads])
486  c = IMP.container.SingletonsConstraint(sm, None, lsc)
487  self.model.add_score_state(c)
488  print('Created symmetry restraint for',len(ref_rbs),'rigid bodies and',
489  len(ref_beads),'flexible beads')
490 
491 
492  #sym_movers = []
493 
494  #sym_movers = [m for cl in clones_rbs for m in self._rb2mov[cl]]
495  #self.movers = [m for m in self.movers if m not in sym_movers]
496  self.model.update()
497 
498 
499  def __repr__(self):
500  # would like something fancy like this:
501  #- super-rigid "SRB1"
502  # - rigid "Mol1" (8 rigid, 3 nonrigid)
503  # - rigid "Mol2" (8 rigid, 3 nonrigid)
504  # - rigid "Mol3" (8 rigid, 3 nonrigid)
505  return 'DegreesOfFreedom: ' + \
506  "\n".join(repr(m) for m in self.movers)
507 
508  def optimize_flexible_beads(self, nsteps, temperature=1.0):
509  '''Set up MC run with just flexible beads.
510  Optimization works much better when restraints
511  are already set up.'''
512  pts = IMP.pmi.tools.ParticleToSampleList()
513  for n, fb in enumerate(self.get_flexible_beads()):
514  pts.add_particle(fb, "Floppy_Bodies", 1.0, "Flexible_Bead_" + str(n))
515  if len(pts.get_particles_to_sample()) > 0:
516  mc = IMP.pmi.samplers.MonteCarlo(self.model, [pts], temperature)
517  print("optimize_flexible_beads: optimizing %i flexible beads" % len(self.get_flexible_beads()))
518  mc.optimize(nsteps)
519  else:
520  print("optimize_flexible_beads: no particle to optimize")
521 
522  def get_movers(self):
523  """Returns Enabled movers"""
524  if self.disabled_movers:
525  filtered_mover_list=[]
526  for mv in self.movers:
527  if not mv in self.disabled_movers:
528  filtered_mover_list.append(mv)
529  return filtered_mover_list
530  else:
531  return self.movers
532 
534  """Return all movers corresponding to individual beads"""
535  return self.fb_movers
536 
537  def get_rigid_bodies(self):
538  """Return list of rigid body objects"""
539  return self.rigid_bodies
540 
542  """Return all flexible beads, including nonrigid members of rigid bodies"""
543  return self.flexible_beads
544 
545  def disable_movers(self,objects,mover_types=None):
546  """Fix the position of the particles by disabling the corresponding movers
547  @param objects Can be one of the following inputs:
548  IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them.
549  Must be uniform input, however. No mixing object types.
550  @param mover_types further filter the mover type that will be disabled, it can be a list of IMP.core.RigidBodyMover,
551  IMP.core.BallMover etc etc if one wants to fix the corresponding rigid body, or the floppy bodies.
552  An empty mover_types list is interpreted as all possible movers.
553  It returns the list of fixed xyz particles (ie, floppy bodies/beads) and rigid bodies
554  whose movers were disabled
555  """
556  hierarchies = IMP.pmi.tools.input_adaptor(objects,
557  pmi_resolution='all',
558  flatten=True)
559  tmp_set=set()
560  fixed_rb=set()
561  fixed_xyz=set()
562  if mover_types is None: mover_types=[]
563 
564  inv_map = {}
565  for mv, ps in self.movers_particles_map.items():
566  for p in ps:
567  if p in inv_map: inv_map[p].append(mv)
568  else: inv_map[p]=[mv]
569 
570  for h in hierarchies:
571  if h in inv_map:
572  for mv in inv_map[h]:
573  if (type(mv) in mover_types or not mover_types):
574  tmp_set.add(mv)
575  if mv in self.movers_rb_map:
576  fixed_rb|=set(self.movers_rb_map[mv])
577  if mv in self.movers_xyz_map:
578  fixed_xyz|=set(self.movers_xyz_map[mv])
579  print("Fixing %s movers" %(str(len(list(tmp_set)))))
580  self.disabled_movers+=list(tmp_set)
581  return list(fixed_xyz),list(fixed_rb)
582 
583  def enable_all_movers(self):
584  """Reenable all movers: previously fixed particles will be released"""
585  self.disabled_movers=[]
586 
588  """Extract the nuisances from get_particles_to_sample()"""
589  try:
590  pslist = r.get_particles_to_sample()
591  except:
592  raise Exception("dof.get_nuisances_from_restraint(): the passed object does not have a "
593  "get_particles_to_sample() function")
594  for name in pslist:
595  is_sampled = True
596  if len(pslist[name])==3:
597  ps,maxtrans,is_sampled = pslist[name]
598  else:
599  ps,maxtrans = pslist[name]
600  if is_sampled:
601  self.create_nuisance_mover(ps[0],maxtrans,name)
def optimize_flexible_beads
Set up MC run with just flexible beads.
def get_rigid_bodies
Return list of rigid body objects.
Simple 3D transformation class.
static CenterOfMass setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor members)
Definition: CenterOfMass.h:81
Apply a SingletonFunction to a SingletonContainer to maintain an invariant.
Set the coordinates of a particle to be a transformed version of a reference.
Definition: core/symmetry.h:76
Set of Python classes to create a multi-state, multi-resolution IMP hierarchy.
def create_flexible_beads
Create a chain of flexible beads.
def enable_all_movers
Reenable all movers: previously fixed particles will be released.
Miscellaneous utilities.
Definition: tools.py:1
def get_nuisances_from_restraint
Extract the nuisances from get_particles_to_sample()
Modify the transformation of a rigid body.
def create_nuisance_mover
Create MC normal mover for nuisance particles.
def get_movers
Returns Enabled movers.
def get_floppy_body_movers
Return all movers corresponding to individual beads.
Move continuous particle variables by perturbing them within a ball.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:731
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition: XYZ.h:51
def setup_md
Setup particles for MD simulation.
A reference frame in 3D.
def create_main_chain_mover
Create crankshaft moves from a set of SUPER rigid body mover from one molecule.
def input_adaptor
Adapt things for PMI (degrees of freedom, restraints, ...) Returns list of list of hierarchies...
Definition: tools.py:918
def create_rigid_body
Create rigid body constraint and mover.
The standard decorator for manipulating molecular structures.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
def create_super_rigid_body
Create SUPER rigid body mover from one or more hierarchies.
Store a list of ParticleIndexes.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Modify the transformation of a rigid body.
Modify a set of continuous variables using a normal distribution.
Definition: NormalMover.h:20
Sampling of the system.
Definition: samplers.py:1
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Sample using Monte Carlo.
Definition: samplers.py:36
The general base class for IMP exceptions.
Definition: exception.h:49
static Reference setup_particle(Model *m, ParticleIndex pi, ParticleIndexAdaptor reference)
Definition: core/symmetry.h:32
Rotation3D get_identity_rotation_3d()
Return a rotation that does not do anything.
Definition: Rotation3D.h:356
Class to handle individual particles of a Model object.
Definition: Particle.h:41
def constrain_symmetry
Create a symmetry constraint.
Python classes to represent, score, sample and analyze models.
A decorator for a rigid body.
Definition: rigid_bodies.h:82
Functionality for loading, creating, manipulating and scoring atomic structures.
def get_rbs_and_beads
Returns unique objects in original order.
Definition: tools.py:1193
Hierarchies get_leaves(const Selection &h)
def get_flexible_beads
Return all flexible beads, including nonrigid members of rigid bodies.
def disable_movers
Fix the position of the particles by disabling the corresponding movers.
static RigidBody setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor ps)
Definition: rigid_bodies.h:174
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:752
Warning for probably incorrect input parameters.
def sublist_iterator
Yield all sublists of length >= lmin and <= lmax.
Definition: tools.py:627