1 """@namespace IMP.pmi.dof
2 Create movers and setup constraints for PMI objects.
3 * Start by creating the DegreesOfFreedom class with `dof = IMP::pmi::dof::DegreesOfFreedom(model)`
4 * The various "create X" functions make movers for system components as well as setup necessary constraints.
5 For each of these functions, you can generally pass PMI objects like [Molecule](@ref IMP::pmi::topology::Molecule) or slices thereof.
6 * DegreesOfFreedom.create_rigid_body() lets you rigidify a molecule (but allows you to also pass "nonrigid" components which move with the body and also independently).
7 * DegreesOfFreedom.create_super_rigid_body() sets up a special "Super Rigid Body" which moves
8 rigidly but is not always constrained to be rigid (so you can later move the parts separately). Good for speeding up sampling.
9 * DegreesOfFreedom.create_flexible_beads() sets up particles to move individually.
10 * DegreesOfFreedom.setup_md() sets up particles to move with molecular dynamics. Note that this is not (yet) compatible with rigid bodies, and only some restraints.
11 * DegreesOfFreedom.constrain_symmetry() makes a symmetry constraint so that clones automatically move with their references. If instead you want a softer restraint, check out the [SymmetryRestraint](@ref IMP::pmi::restraints::stereochemistry::SymmetryRestraint).
12 * When you are done you can access all movers with DegreesOfFreedom.get_movers(). If you have set up rigid, super rigid, or flexible beads, pass the movers to the `monte_carlo_sample_objects` argument of [ReplicaExchange0](@ref IMP::pmi::macros::ReplicaExchange0).
13 * If you are running MD, you have to separately pass the particles (also returned from DegreesOfFreedom.setup_md()) to the `molecular_dynamics_sample_objects` argument of [ReplicaExchange0](@ref IMP::pmi::macros::ReplicaExchange0). Check out an [MD example here](pmi_2atomistic_8py-example.html).
16 from __future__
import print_function
27 """A class to simplify create of constraints and movers for an IMP Hierarchy.
28 Call the various create() functions to get started.
29 Can get all enabled movers with get_movers(). Pass this to ReplicaExchange0.
31 def __init__(self,mdl):
34 self.rigid_bodies = []
35 self.flexible_beads = []
47 nonrigid_max_trans = 0.1,
50 """Create rigid body constraint and mover
51 @param rigid_parts Can be one of the following inputs:
52 IMP Hierarchy, PMI System/State/Molecule/TempResidue, a list/set (of list/set) of them
53 or a RigidBody object.
54 Must be uniform input, however. No mixing object types.
55 @param nonrigid_parts Same input format as rigid_parts.
56 Must be a subset of rigid_parts particles.
57 @param max_trans Maximum rigid body translation
58 @param max_rot Maximum rigid body rotation
59 @param nonrigid_max_trans Maximum step for the nonrigid (bead) particles
60 @param resolution Only used if you pass PMI objects. Probably you want 'all'.
61 @param name Rigid body name (if None, use IMP default)
62 \note If you want all resolutions, pass PMI objects because this function will get them all.
63 Alternatively you can do your selection elsewhere and just pass hierarchies.
64 Returns tuple (rb_movers,rb_object)
82 print(
"WARNING: No hierarchies were passed to create_rigid_body()")
85 self.rigid_bodies.append(rb)
86 rb.set_coordinates_are_optimized(
True)
90 rb_mover.set_name(name)
91 rb_movers.append(rb_mover)
100 rb_idxs = set(rb.get_member_indexes())
102 self.flexible_beads.append(h)
104 if not p.get_index()
in rb_idxs:
105 raise Exception(
"You tried to create nonrigid members from "
106 "particles that aren't in the RigidBody!")
108 rb.set_is_rigid_member(p.get_index(),
False)
110 p.set_is_optimized(fk,
True)
114 self.movers += rb_movers
121 chain_min_length=
None,
122 chain_max_length=
None,
125 """Create SUPER rigid body mover from one or more hierarchies. Can also create chain of SRBs.
126 @param srb_parts Can be one of the following inputs:
127 IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them.
128 Must be uniform input, however. No mixing object types.
129 @param max_trans Maximum super rigid body translation
130 @param max_rot Maximum super rigid body rotation
131 @param chain_min_length Create a CHAIN of super rigid bodies - must provide list
132 This parameter is the minimum chain length.
133 @param chain_max_length Maximum chain length
134 @param resolution Only used if you pass PMI objects. Probably you want 'all'.
135 @param name The name of the SRB (hard to assign a good one automatically)
136 \note If you set the chain parameters, will NOT create an SRB from all of them together,
137 but rather in groups made from the outermost list.
143 if chain_min_length
is None and chain_max_length
is None:
147 print(
'WARNING: No hierarchies were passed to create_super_rigid_body()')
151 if not hasattr(srb_parts,
'__iter__'):
152 raise Exception(
"You tried to make a chain without a list!")
156 if chain_min_length
is None and chain_max_length
is None:
157 srb_movers.append(self._setup_srb(srb_groups,max_trans,max_rot))
158 elif chain_min_length
is not None and chain_max_length
is not None:
160 srb_movers.append(self._setup_srb(hs,max_trans,max_rot))
162 raise Exception(
"DegreesOfFreedom: SetupSuperRigidBody: if you want chain, specify min AND max")
163 self.movers += srb_movers
165 if len(srb_movers)>1:
166 for n,mv
in enumerate(srb_movers):
167 mv.set_name(name+
'_'+str(n))
169 srb_movers[0].set_name(name)
172 def _setup_srb(self,hiers,max_trans,max_rot):
175 for xyz
in super_rigid_xyzs:
176 srbm.add_xyz_particle(xyz)
177 for rb
in super_rigid_rbs:
178 srbm.add_rigid_body_particle(rb)
186 """Create a chain of flexible beads
187 @param flex_parts Can be one of the following inputs:
188 IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them.
189 Must be uniform input, however. No mixing object types.
190 @param max_trans Maximum flexible bead translation
191 @param resolution Only used if you pass PMI objects. Probably you want 'all'.
198 if not hiers
or len(hiers)==0:
199 print(
'WARNING: No hierarchies were passed to create_flexible_beads()')
205 raise Exception(
"Cannot create flexible beads from members of rigid body")
206 self.flexible_beads.append(h)
208 self.movers += fb_movers
215 """Create MC normal mover for nuisance particles.
216 We will add an easier interface to add all of them from a PMI restraint
217 @param nuisance_p The Nuisance particle (an ISD::Scale)
218 @param step_size The maximum step size for Monte Carlo
219 @param name The name of the mover, useful for better output reading.
226 self.nuisances.append(nuisance_p)
227 self.movers.append(mv)
232 """Setup particles for MD simulation. Returns all particles, just
233 pass this to molecular_dynamics_sample_objects in ReplicaExchange0.
234 @param hspec Can be one of the following inputs:
235 IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them.
236 Must be uniform input, however. No mixing object types.
242 mdl = hiers[0].get_model()
246 IMP.core.XYZ(mdl,p.get_index()).set_coordinates_are_optimized(
True)
247 mdl.add_attribute(vxkey,p.get_index(),0.0)
248 mdl.add_attribute(vykey,p.get_index(),0.0)
249 mdl.add_attribute(vzkey,p.get_index(),0.0)
258 """Create a symmetry constraint. Checks:
259 same number of particles
260 disable ANY movers involving symmetry copies
261 (later may support moving them WITH references,
262 but requires code to propagate constraint)
263 @param references Can be one of the following inputs:
264 IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them
265 @param clones Same format as references
266 @param transform The transform that moves a clone onto a reference
267 IMP.algebra.Transformation3D
268 @param resolution Only used if you pass PMI objects.
269 If you have a multires system, assuming each are rigid
270 bodies you probably only need one resolution.
281 if len(ref_rbs)!=len(clones_rbs)
or len(ref_beads)!=len(clones_beads):
282 raise Exception(
"ERROR: Your references don't match your clones")
285 for ref,clone
in zip(ref_rbs+ref_beads,clones_rbs+clones_beads):
289 self.mdl,[p.get_particle_index()
for p
in clones_rbs+clones_beads])
291 self.mdl.add_score_state(c)
292 print(
'Created symmetry restraint for',len(ref_rbs),
'rigid bodies and',
293 len(ref_beads),
'flexible beads')
301 return 'DegreesOfFreedom: ' + \
302 "\n".join(repr(m)
for m
in self.movers)
305 '''Set up MC run with just flexible beads.
306 Optimization works much better when restraints
307 are already set up.'''
309 pts = IMP.pmi.tools.ParticleToSampleList()
311 pts.add_particle(fb,
"Floppy_Bodies", 1.0,
"Flexible_Bead_" + str(n))
312 if len(pts.get_particles_to_sample()) > 0:
314 print(
"optimize_flexible_beads: optimizing %i flexible beads" % len(self.
get_flexible_beads()))
317 print(
"optimize_flexible_beads: no particle to optimize")
320 """Should only return Enabled movers?"""
324 """Return list of rigid body objects"""
325 return self.rigid_bodies
328 """Return all flexible beads, including nonrigid members of rigid bodies"""
329 return self.flexible_beads
332 """Extract the nuisances from get_particles_to_sample()"""
334 pslist = r.get_particles_to_sample()
336 raise Exception(
"dof.get_nuisances_from_restraint(): the passed object does not have a "
337 "get_particles_to_sample() function")
340 if len(pslist[name])==3:
341 ps,maxtrans,is_sampled = pslist[name]
343 ps,maxtrans = pslist[name]
def optimize_flexible_beads
Set up MC run with just flexible beads.
A class to simplify create of constraints and movers for an IMP Hierarchy.
def get_rigid_bodies
Return list of rigid body objects.
Apply a SingletonFunction to a SingletonContainer to maintain an invariant.
Set of python classes to create a multi-state, multi-resolution IMP hierarchy.
def create_flexible_beads
Create a chain of flexible beads.
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
Should only return Enabled movers?
Modify a set of continuous variables by perturbing them within a ball.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
def setup_md
Setup particles for MD simulation.
def create_rigid_body
Create rigid body constraint and mover.
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.
Modify a set of continuous variables using a normal distribution.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Sample using Monte Carlo.
The general base class for IMP exceptions.
IMP::core::RigidBody create_rigid_body(Hierarchy h)
static Reference setup_particle(Model *m, ParticleIndex pi, ParticleIndexAdaptor reference)
def constrain_symmetry
Create a symmetry constraint.
Python classes to represent, score, sample and analyze models.
A decorator for a rigid body.
Functionality for loading, creating, manipulating and scoring atomic structures.
def get_flexible_beads
Return all flexible beads, including nonrigid members of rigid bodies.
static bool get_is_setup(const IMP::ParticleAdaptor &p)