IMP logo
IMP Reference Guide  2.15.0
The Integrative Modeling Platform
BallMover.py

Symmetry ball mover

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]))