IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
BallMover.py
1 ## \example BallMover.py
2 # Symmetry ball mover
3 
4 import IMP
5 import IMP.symmetry
6 import IMP.core
7 import sys
8 
9 IMP.setup_from_argv(sys.argv, "ball mover")
10 
11 
12 # parameters
13 S_ = 20. # cubic cell size
14 K_ = 1.0 # intensity harmonic restraint
15 KBT_ = 1.0 # temperature
16 
17 # create model
18 m = IMP.Model()
19 
20 # add 2 particles
21 ps = []
22 for i in range(2):
23  p = m.add_particle("P%d" % i)
26  d.set_coordinates_are_optimized(True)
27  ps.append(p)
28 
29 # add harmonic restraint to distance
30 h = IMP.core.Harmonic(0.0, K_)
32 pr = IMP.core.PairRestraint(m, sps, (ps[0], ps[1]))
33 
34 # define cell centers
35 ctrs = []
36 for i in [0.0, -1.0, +1.0]:
37  for j in [0.0, -1.0, +1.0]:
38  for k in [0.0, -1.0, +1.0]:
39  ctrs.append(IMP.algebra.Vector3D(
40  float(i) * S_, float(j) * S_, float(k) * S_))
41 
42 # define transformation from primitive to all cells
43 trs = []
44 for ctr in ctrs:
45  trs.append(IMP.algebra.Transformation3D(ctr))
46 
47 # movers
48 movers = []
49 # symmetry mover with ps[0] being the master particle
50 movers.append(IMP.symmetry.BallMover(m.get_particle(ps[0]),
51  [m.get_particle(ps[1])], 1.0, ctrs, trs))
52 # normal BallMover for the other particle
53 movers.append(IMP.core.BallMover(m, ps[1], 1.0))
54 # serial mover
55 sm = IMP.core.SerialMover(movers)
56 
57 # sampler
58 mc = IMP.core.MonteCarlo(m)
59 mc.set_scoring_function([pr])
60 mc.set_kt(KBT_)
61 mc.set_return_best(False)
62 mc.add_mover(sm)
63 
64 # prepare output
65 log = open("traj.xyz", "w")
66 
67 # start sampling loop
68 for istep in range(0, 5000):
69  # do optimization
70  mc.optimize(10)
71 
72  # coordinates
73  xyz0 = IMP.core.XYZR(m, ps[0]).get_coordinates()
74  xyz1 = IMP.core.XYZR(m, ps[1]).get_coordinates()
75 
76  # print
77  log.write("\n2\n")
78  log.write("Na %6.3f %6.3f %6.3f\n" % (xyz0[0], xyz0[1], xyz0[2]))
79  log.write("Cl %6.3f %6.3f %6.3f\n" % (xyz1[0], xyz1[1], xyz1[2]))
A Monte Carlo optimizer.
Definition: MonteCarlo.h:45
Simple 3D transformation class.
Support for basic symmetry, such as periodic boundary conditions (PBC).
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition: XYZR.h:48
Move a particle and keep it in the primitive cell of a periodic lattice.
A score on the distance between the surfaces of two spheres.
Move continuous particle variables by perturbing them within a ball.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Basic functionality that is expected to be used by a wide variety of IMP users.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Applies a PairScore to a Pair.
Definition: PairRestraint.h:29
Applies a list of movers one at a time.
Definition: SerialMover.h:23
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:24
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27