IMP  2.0.1
The Integrative Modeling Platform
parallel/tasks.py

This module contains the setup and task functions used by local_distance.py.

1 ## \example parallel/tasks.py
2 ## This module contains the setup and task functions used by local_distance.py.
3 ##
4 
5 import IMP
6 import IMP.algebra
7 import IMP.core
8 
9 def setup():
10  """Create a Model containing two XYZ particles linked by a harmonic
11  distance restraint, one fixed at the origin. Return the Model and
12  the free XYZ particle."""
13  m = IMP.Model()
14  p1 = IMP.Particle(m)
16  p2 = IMP.Particle(m)
18  d1.set_coordinates(IMP.algebra.Vector3D(0,0,0))
20  m.add_restraint(r)
21  return m, d2
22 
23 # Note that setup and tasks are Python callables, i.e. functions (like setup
24 # above) or classes that implement the __call__ method (like Task below).
25 # The latter allows for parameters (Python objects) to be passed from the
26 # master to the slaves.
27 class Task(object):
28  def __init__(self, dist):
29  self.dist = dist
30  def __call__(self, m, d):
31  """Place the free XYZ particle at the specified distance from the
32  origin. Return the distance and the model's score. Note that the
33  input parameters to this method (m and d) are those returned by
34  the setup function above."""
35  d.set_coordinates(IMP.algebra.Vector3D(0,0,self.dist))
36  return (self.dist, m.evaluate(False))