IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
move_aware_mc.py
1## \example core/move_aware_mc.py
2# This example shows how to do move-aware scoring with Monte Carlo.
3# Move-aware scoring can be significantly faster than regular
4# scoring when using moves that only move a few particles at a time.
5
6import IMP.core
7import IMP.container
8import IMP.algebra
9import IMP.display
10import sys
11
12IMP.setup_from_argv(sys.argv, "Optimize balls example")
13
15 num_balls = 2
16 num_mc_steps = 10
17else:
18 num_balls = 20
19 num_mc_steps = 1000
20
21m = IMP.Model()
23 IMP.algebra.Vector3D(30, 30, 30))
24ps = []
25for i in range(0, num_balls):
26 ps.append(IMP.Particle(m))
28 d.set_radius(10)
29 d.set_coordinates(IMP.algebra.get_random_vector_in(bb))
30 d.set_coordinates_are_optimized(True)
31
37 psl)
40mc.set_scoring_function(sf)
41
42# Turn on move-aware scoring.
43# At each MC step, only the scoring function terms that involve at least
44# one particle moved by a Mover will be rescored; the remaining terms will
45# be cached.
46mc.set_score_moved(True)
47
48mvs = [IMP.core.BallMover(m, p, 5) for p in ps]
50mc.add_mover(sm)
51IMP.set_log_level(IMP.SILENT)
52print("initial", sf.evaluate(False))
53after = mc.optimize(num_mc_steps)
54print("final", after)
55name = IMP.create_temporary_file_name("move_aware_mc", ".pym")
57for p in ps:
59 w.add_geometry(g)
60print("pymol", name)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
Applies a SingletonScore to each Singleton in a list.
Move continuous particle variables by perturbing them within a ball.
Prevent a set of particles and rigid bodies from inter-penetrating.
Upper bound harmonic function (non-zero when feature > mean).
A Monte Carlo optimizer.
Definition MonteCarlo.h:46
Create a scoring function on a list of restraints.
Applies a list of movers one at a time.
Definition SerialMover.h:26
Display an IMP::core::XYZR particle as a ball.
Definition XYZR.h:151
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition XYZR.h:48
Write a CGO file with the geometry.
Definition PymolWriter.h:34
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition VectorD.h:407
VectorD< D > get_random_vector_in(const BoundingBoxD< D > &bb)
Generate a random vector in a box with uniform density.
Various classes to hold sets of particles.
Basic functionality that is expected to be used by a wide variety of IMP users.
Output IMP model data in various file formats.
void set_log_level(LogLevel l)
Set the current global log level.
std::string create_temporary_file_name(std::string prefix="imp_temp", std::string suffix="")
Create a temporary file.
bool get_is_quick_test()
Definition flags.h:183
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.