IMP  2.3.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 
8 
9 # parameters
10 S_ = 20. # cubic cell size
11 K_ = 1.0 # intensity harmonic restraint
12 KBT_ = 1.0 # temperature
13 
14 # create model
15 m = IMP.kernel.Model()
16 
17 # add 2 particles
18 ps = []
19 for i in range(2):
20  p = IMP.kernel.Particle(m)
23  d.set_coordinates_are_optimized(True)
24  ps.append(p)
25 
26 # add harmonic restraint to distance
27 h = IMP.core.Harmonic(0.0, K_)
29 pr = IMP.core.PairRestraint(sps, IMP.kernel.ParticlePair(ps[0], ps[1]))
30 m.add_restraint(pr)
31 
32 # define cell centers
33 ctrs = []
34 for i in [0.0, -1.0, +1.0]:
35  for j in [0.0, -1.0, +1.0]:
36  for k in [0.0, -1.0, +1.0]:
37  ctrs.append(IMP.algebra.Vector3D(
38  float(i) * S_, float(j) * S_, float(k) * S_))
39 
40 # define transformation from primitive to all cells
41 trs = []
42 for ctr in ctrs:
43  trs.append(IMP.algebra.Transformation3D(ctr))
44 
45 # movers
46 movers = []
47 # symmetry mover with ps[0] being the master particle
48 movers.append(IMP.symmetry.BallMover(ps[0], [ps[1]], 1.0, ctrs, trs))
49 # normal BallMover for the other particle
50 movers.append(IMP.core.BallMover([ps[1]], 1.0))
51 # serial mover
52 sm = IMP.core.SerialMover(movers)
53 
54 # sampler
55 mc = IMP.core.MonteCarlo(m)
56 mc.set_kt(KBT_)
57 mc.set_return_best(False)
58 mc.add_mover(sm)
59 
60 # prepare output
61 log = open("traj.xyz", "w")
62 
63 # start sampling loop
64 for istep in range(0, 5000):
65  # do optimization
66  mc.optimize(10)
67 
68  # coordinates
69  xyz0 = IMP.core.XYZR(ps[0]).get_coordinates()
70  xyz1 = IMP.core.XYZR(ps[1]).get_coordinates()
71 
72  # print
73  log.write("\n2\n")
74  log.write("Na %6.3f %6.3f %6.3f\n" % (xyz0[0], xyz0[1], xyz0[2]))
75  log.write("Cl %6.3f %6.3f %6.3f\n" % (xyz1[0], xyz1[1], xyz1[2]))