1 """@namespace IMP.pmi.dof
2 Handling of degrees of freedom.
5 from __future__
import print_function
10 define rigid bodies and super rigid bodies
11 define symmetries (see representation.py)
12 create nuisances and their parameters
13 generate lists of MC or MD movers
15 def __init__(self,root,
16 maxtrans_rb=
None,maxrot_rb=
None,
17 maxtrans_srb=
None,maxrot_srb=
None):
18 self.rigid_bodies = []
19 self.fixed_rigid_bodies = []
20 self.floppy_bodies = []
21 self.super_rigid_bodies = []
23 self.maxtrans_rb = 2.0
25 self.maxtrans_srb = 2.0
27 self.rigidbodiesarefixed =
False
28 self.maxtrans_fb = 3.0
33 This method allows the construction of a rigid body given a list
34 of hierarchies and or a list of particles.
36 hiers: list of hierarchies
37 particles: (optional, default=None) list of particles to add to the rigid body
43 rigid_parts = set(particles)
46 print(
"set_rigid_body_from_hierarchies> setting up a new rigid body")
52 print(
"set_rigid_body_from_hierarchies> WARNING particle %s already belongs to rigid body %s" % (p.get_name(), rb.get_name()))
55 name += hier.get_name() +
"-"
56 print(
"set_rigid_body_from_hierarchies> adding %s to the rigid body" % hier.get_name())
58 rb.set_coordinates_are_optimized(
True)
59 rb.set_name(name +
"rigid_body")
60 self.rigid_bodies.append(rb)
65 This method allows the construction of a rigid body given a list
66 of tuples, that identify the residue ranges and the subunit names (the names used
67 to create the component by using create_component.
69 subunits: [(name_1,(first_residue_1,last_residue_1)),(name_2,(first_residue_2,last_residue_2)),.....]
71 [name_1,name_2,(name_3,(first_residue_3,last_residue_3)),.....]
73 example: ["prot1","prot2",("prot3",(1,10))]
75 sometimes, we know about structure of an interaction
76 and here we make such PPIs rigid
81 if type(s) == type(tuple())
and len(s) == 2:
85 residue_indexes=list(range(s[1][0],
87 if len(sel.get_selected_particles()) == 0:
88 print(
"set_rigid_bodies: selected particle does not exists")
89 for p
in sel.get_selected_particles():
93 print(
"set_rigid_body_from_hierarchies> WARNING particle %s already belongs to rigid body %s" % (p.get_name(), rb.get_name()))
97 elif type(s) == type(str()):
99 if len(sel.get_selected_particles()) == 0:
100 print(
"set_rigid_bodies: selected particle does not exists")
101 for p
in sel.get_selected_particles():
105 print(
"set_rigid_body_from_hierarchies> WARNING particle %s already belongs to rigid body %s" % (p.get_name(), rb.get_name()))
110 rb.set_coordinates_are_optimized(
True)
111 rb.set_name(
''.join(str(subunits)) +
"_rigid_body")
112 self.rigid_bodies.append(rb)
115 def set_super_rigid_body_from_hierarchies(
121 super_rigid_xyzs = set()
122 super_rigid_rbs = set()
124 print(
"set_super_rigid_body_from_hierarchies> setting up a new SUPER rigid body")
131 super_rigid_rbs.add(rb)
133 super_rigid_xyzs.add(p)
134 print(
"set_rigid_body_from_hierarchies> adding %s to the rigid body" % hier.get_name())
135 if len(super_rigid_rbs) < min_size:
138 self.super_rigid_bodies.append((super_rigid_xyzs, super_rigid_rbs))
141 self.super_rigid_bodies.append(
142 (super_rigid_xyzs, super_rigid_rbs, axis))
144 def fix_rigid_bodies(self, rigid_bodies):
145 self.fixed_rigid_bodies += rigid_bodies
154 this function takes a linear list of hierarchies (they are supposed
155 to be sequence-contiguous) and
156 produces a chain of super rigid bodies with given length range, specified
157 by min_length and max_length
160 hiers = IMP.pmi.tools.flatten_list(hiers)
164 self.set_super_rigid_body_from_hierarchies(hs, axis, min_length)
166 def set_super_rigid_bodies(self, subunits, coords=None):
167 super_rigid_xyzs = set()
168 super_rigid_rbs = set()
171 if type(s) == type(tuple())
and len(s) == 3:
175 residue_indexes=list(range(s[0],
177 if len(sel.get_selected_particles()) == 0:
178 print(
"set_rigid_bodies: selected particle does not exists")
179 for p
in sel.get_selected_particles():
182 super_rigid_rbs.add(rb)
184 super_rigid_xyzs.add(p)
185 elif type(s) == type(str()):
187 if len(sel.get_selected_particles()) == 0:
188 print(
"set_rigid_bodies: selected particle does not exists")
189 for p
in sel.get_selected_particles():
193 super_rigid_rbs.add(rb)
195 super_rigid_xyzs.add(p)
196 self.super_rigid_bodies.append((super_rigid_xyzs, super_rigid_rbs))
200 give a list of hierarchies, get the leaves and remove the corresponding particles
201 from the floppy bodies list. We need this function because sometimes
202 we want to constraint the floppy bodies in a rigid body. For instance
203 when you want to associate a bead with a density particle.
205 for h
in hierarchies:
208 if p
in self.floppy_bodies:
209 print(
"remove_floppy_bodies: removing %s from floppy body list" % p.get_name())
210 self.floppy_bodies.remove(p)
212 def set_floppy_bodies(self):
213 for p
in self.floppy_bodies:
215 p.set_name(name +
"_floppy_body")
217 print(
"I'm trying to make this particle flexible although it was assigned to a rigid body", p.get_name())
220 rb.set_is_rigid_member(p.get_index(),
False)
223 rb.set_is_rigid_member(p.get_particle_index(),
False)
224 p.set_name(p.get_name() +
"_rigid_body_member")
226 def set_floppy_bodies_from_hierarchies(self, hiers):
231 self.floppy_bodies.append(p)
233 def get_particles_to_sample(self):
243 if not self.rigidbodiesarefixed:
244 for rb
in self.rigid_bodies:
249 if rb
not in self.fixed_rigid_bodies:
252 for fb
in self.floppy_bodies:
259 for srb
in self.super_rigid_bodies:
262 rigid_bodies = list(srb[1])
263 filtered_rigid_bodies = []
264 for rb
in rigid_bodies:
265 if rb
not in self.fixed_rigid_bodies:
266 filtered_rigid_bodies.append(rb)
267 srbtmp.append((srb[0], filtered_rigid_bodies))
269 self.rigid_bodies = rbtmp
270 self.floppy_bodies = fbtmp
271 self.super_rigid_bodies = srbtmp
273 ps[
"Rigid_Bodies_SimplifiedModel"] = (
277 ps[
"Floppy_Bodies_SimplifiedModel"] = (
280 ps[
"SR_Bodies_SimplifiedModel"] = (
281 self.super_rigid_bodies,
def remove_floppy_bodies
give a list of hierarchies, get the leaves and remove the corresponding particles from the floppy bod...
Add symmetric attribute to a particle.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
def set_rigid_bodies
This method allows the construction of a rigid body given a list of tuples, that identify the residue...
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...
static bool get_is_setup(Model *m, ParticleIndex pi)
A decorator for a particle with x,y,z coordinates.
def set_chain_of_super_rigid_bodies
this function takes a linear list of hierarchies (they are supposed to be sequence-contiguous) and pr...
IMP::core::RigidBody create_rigid_body(Hierarchy h)
Hierarchies get_leaves(const Selection &h)
Select hierarchy particles identified by the biological name.