IMP
2.0.1
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
tasks.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)
15
d1 =
IMP.core.XYZ.setup_particle
(p1)
16
p2 =
IMP.Particle
(m)
17
d2 =
IMP.core.XYZ.setup_particle
(p2)
18
d1.set_coordinates(
IMP.algebra.Vector3D
(0,0,0))
19
r =
IMP.core.DistanceRestraint
(
IMP.core.Harmonic
(0, 1), p1, p2)
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
))