IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
pmi/dof/__init__.py
1 """@namespace IMP.pmi.dof
2  Setup constraints and create movers for an IMP Hierarchy
3 """
4 
5 from __future__ import print_function
6 import IMP
7 import IMP.atom
8 import IMP.algebra
9 import IMP.pmi
10 import IMP.pmi.topology
11 import IMP.pmi.samplers
12 import itertools
13 
14 def get_hierarchies(spec):
15  """ given PMI Molecule/Residue or IMP objects, return hierarchies """
16  def get_h(s):
17  if type(s) is IMP.atom.Selection:
18  hs = [IMP.atom.Hierarchy(p) for p in s.get_selected_particles()]
19  elif type(s) is IMP.atom.Hierarchy:
20  hs = [s]
21  elif type(s) is IMP.pmi.topology.Molecule:
22  hs = [s.get_hierarchy()]
23  elif type(s) is IMP.pmi.topology._Residue:
24  hs = [s.get_hierarchy()]
25  else:
26  raise Exception("Cannot process type "+str(type(s)))
27  return hs
28 
29  if hasattr(spec,'__iter__'):
30  hhs = list(itertools.chain.from_iterable(get_h(item) for item in spec))
31  else:
32  hhs = get_h(spec)
33  return hhs
34 
35 def get_all_leaves(list_of_hs):
36  """ Just get the leaves from a list of hierarchies """
37  lvs = list(itertools.chain.from_iterable(IMP.atom.get_leaves(item) for item in list_of_hs))
38  return lvs
39 
40 class DegreesOfFreedom(object):
41  """A class to simplify create of constraints and movers for an IMP Hierarchy.
42  Call the various create() functions to get started."""
43  def __init__(self,mdl):
44  self.mdl = mdl
45  self.movers = []
46 
47  def create_rigid_body(self,
48  hspec,
49  max_trans=1.0,
50  max_rot=0.1):
51  """Create rigid body constraint and mover
52  @param hspec Can be one of the following inputs:
53  IMP Selection, Hierarchy,
54  PMI Molecule, Residue, or a list/set
55  @param max_trans Maximum rigid body translation
56  @param max_rot Maximum rigid body rotation
57  """
58  hs = get_hierarchies(hspec)
59  setup_rb = SetupRigidBody(hs,max_trans,max_rot)
60  self.movers.append(setup_rb)
61  return setup_rb
62 
64  hspec,
65  max_trans=1.0,
66  max_rot=0.1,
67  chain_min_length=None,
68  chain_max_length=None):
69  """Create SUPER rigid body mover from one or more hierarchies. Can also create chain of SRBs.
70  @param hspec Can be one of the following inputs:
71  IMP Selection, Hierarchy,
72  PMI Molecule, Residue, or a list/set
73  @param max_trans Maximum super rigid body translation
74  @param max_rot Maximum super rigid body rotation
75  @param chain_min_length Create a CHAIN of super rigid bodies - must provide list
76  This parameter is the minimum chain length.
77  @param chain_max_length max chain length
78  """
79  hiers = get_hierarchies(hspec)
80  setup_srb = SetupSuperRigidBody(hiers,max_trans,max_rot,chain_min_length,chain_max_length)
81  self.movers.append(setup_srb)
82  return setup_srb
83 
85  hspec,
86  max_trans):
87  """Create a chain of flexible beads
88  @param hspec Can be one of the following inputs:
89  IMP Selection, Hierarchy,
90  PMI Molecule, Residue, or a list/set
91  @param max_trans Maximum flexible bead translation
92  """
93  hiers = get_hierarchies(hspec)
94  setup_fb = SetupFlexibleBeads(hiers,max_trans)
95  self.movers.append(setup_fb)
96  return setup_fb
97 
98 
99  def show(self):
100  """Make it pretty"""
101 
102  def get_all_movers(self):
103  # possibly organize in some way?
104  all_movers = []
105  for m in self.movers:
106  all_movers+=m.get_movers()
107 
108 class SetupRigidBody(object):
109  """Sets up and stores RigidBodyMover and BallMovers for NonRigidMembers"""
110  def __init__(self,hiers,max_trans,max_rot):
111  self.rb = IMP.atom.create_rigid_body(hiers) #should we check first?
112  self.rb_mover = IMP.core.RigidBodyMover(self.rb,max_trans,max_rot)
113  self.flexible_movers = []
114 
115  def create_non_rigid_members(self,spec,max_trans=1.0):
116  hiers = get_hierarchies(spec)
117  floatkeys = [IMP.FloatKey(4), IMP.FloatKey(5), IMP.FloatKey(6)]
118  idxs = set(self.rb.get_member_indexes())
119  for h in hiers:
120  p = h.get_particle()
121  if not p.get_index() in idxs:
122  raise Exception("You tried to create nonrigid members from "
123  "particles that aren't in the RigidBody!")
124 
125  self.rb.set_is_rigid_member(p.get_index(),False)
126  for fk in floatkeys:
127  p.set_is_optimized(fk,True)
128  self.flexible_movers.append(IMP.core.BallMover([p],
129  IMP.FloatKeys(floatkeys),
130  max_trans))
131  def get_movers(self):
132  return [self.rb_mover]+self.flexible_movers
133 
134  def get_rigid_body(self):
135  return self.rb
136 
137 class SetupDiscreteRigidBody(SetupRigidBody):
138  pass
139 
140 class SetupSuperRigidBody(object):
141  def __init__(self,hiers,max_trans,max_rot,chain_min_length,chain_max_length):
142  self.movers = []
143  if chain_min_length is None and chain_max_length is None:
144  self._setup_srb(hiers,max_trans,max_rot)
145  elif chain_min_length is not None and chain_max_length is not None:
146  for hs in IMP.pmi.tools.sublist_iterator(hiers, chain_min_length, chain_max_length):
147  self._setup_srb(hs,max_trans,max_rot)
148  else:
149  raise Exception("DegreesOfFreedom: SetupSuperRigidBody: if you want chain, specify min AND max")
150 
151  def _setup_srb(self,hiers,max_trans,max_rot):
152  srbm = IMP.pmi.TransformMover(hiers[0].get_model(), max_trans, max_rot)
153  for p in get_all_leaves(hiers):
155  srbm.add_rigid_body_particle(p)
156  else:
157  srbm.add_xyz_particle(p)
158  self.movers.append(srbm)
159 
160  def get_movers(self):
161  return self.movers
162 
163 class SetupFlexibleBeads(object):
164  def __init__(self,hiers,max_trans):
165  self.movers = []
166  for p in get_all_leaves(hiers):
168  raise Exception("Cannot create flexible beads from members of rigid body")
169  self.movers.append(IMP.core.BallMover([p],max_trans))
170  def get_movers(self):
171  return self.movers
A class to simplify create of constraints and movers for an IMP Hierarchy.
Set up of system representation from topology files.
def create_flexible_beads
Create a chain of flexible beads.
Modify the transformation of a rigid body.
Modify a set of continuous variables by perturbing them within a ball.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:469
This class is constructed from within the State class.
def create_rigid_body
Create rigid body constraint and mover.
The standard decorator for manipulating molecular structures.
def create_super_rigid_body
Create SUPER rigid body mover from one or more hierarchies.
def get_all_leaves
Just get the leaves from a list of hierarchies.
Modify the transformation of a rigid body.
def get_hierarchies
given PMI Molecule/Residue or IMP objects, return hierarchies
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...
The general base class for IMP exceptions.
Definition: exception.h:49
Sets up and stores RigidBodyMover and BallMovers for NonRigidMembers.
IMP::core::RigidBody create_rigid_body(Hierarchy h)
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)
Select hierarchy particles identified by the biological name.
Definition: Selection.h:65
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:490
def sublist_iterator
Yield all sublists of length >= lmin and <= lmax.
Definition: tools.py:1055