IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
BallMover.py
1## \example BallMover.py
2# Symmetry ball mover
3
4import IMP
5import IMP.symmetry
6import IMP.core
7import sys
8
9IMP.setup_from_argv(sys.argv, "ball mover")
10
11
12# parameters
13S_ = 20. # cubic cell size
14K_ = 1.0 # intensity harmonic restraint
15KBT_ = 1.0 # temperature
16
17# create model
18m = IMP.Model()
19
20# add 2 particles
21ps = []
22for i in range(2):
23 p = m.add_particle("P%d" % i)
25 m, p, IMP.algebra.Sphere3D(IMP.algebra.Vector3D(0., 0., 0.), 1.0))
26 d.set_coordinates_are_optimized(True)
27 ps.append(p)
28
29# add harmonic restraint to distance
30h = IMP.core.Harmonic(0.0, K_)
32pr = IMP.core.PairRestraint(m, sps, (ps[0], ps[1]))
33
34# define cell centers
35ctrs = []
36for 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
43trs = []
44for ctr in ctrs:
45 trs.append(IMP.algebra.Transformation3D(ctr))
46
47# movers
48movers = []
49# symmetry mover with ps[0] being the master particle
50movers.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
53movers.append(IMP.core.BallMover(m, ps[1], 1.0))
54# serial mover
55sm = IMP.core.SerialMover(movers)
56
57# sampler
59mc.set_scoring_function([pr])
60mc.set_kt(KBT_)
61mc.set_return_best(False)
62mc.add_mover(sm)
63
64# prepare output
65log = open("traj.xyz", "w")
66
67# start sampling loop
68for 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]))
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Simple 3D transformation class.
Move continuous particle variables by perturbing them within a ball.
Harmonic function (symmetric about the mean)
A Monte Carlo optimizer.
Definition MonteCarlo.h:46
Applies a PairScore to a Pair.
Applies a list of movers one at a time.
Definition SerialMover.h:26
A score on the distance between the surfaces of two spheres.
A decorator for a particle with x,y,z coordinates and a radius.
Definition XYZR.h:27
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.
VectorD< 3 > Vector3D
Definition VectorD.h:407
Basic functionality that is expected to be used by a wide variety of IMP users.
Support for basic symmetry, such as periodic boundary conditions (PBC).
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.