IMP logo
IMP Reference Guide  2.18.0
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 
6 import IMP.core
7 import IMP.container
8 import IMP.algebra
9 import IMP.display
10 import sys
11 
12 IMP.setup_from_argv(sys.argv, "Optimize balls example")
13 
15  num_balls = 2
16  num_mc_steps = 10
17 else:
18  num_balls = 20
19  num_mc_steps = 1000
20 
21 m = IMP.Model()
23  IMP.algebra.Vector3D(30, 30, 30))
24 ps = []
25 for 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 
36  IMP.core.HarmonicUpperBound(0, 1), bb),
37  psl)
38 mc = IMP.core.MonteCarlo(m)
40 mc.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.
46 mc.set_score_moved(True)
47 
48 mvs = [IMP.core.BallMover(m, p, 5) for p in ps]
49 sm = IMP.core.SerialMover(mvs)
50 mc.add_mover(sm)
51 IMP.set_log_level(IMP.SILENT)
52 print("initial", sf.evaluate(False))
53 after = mc.optimize(num_mc_steps)
54 print("final", after)
55 name = IMP.create_temporary_file_name("move_aware_mc", ".pym")
57 for p in ps:
59  w.add_geometry(g)
60 print("pymol", name)
Applies a SingletonScore to each Singleton in a list.
A Monte Carlo optimizer.
Definition: MonteCarlo.h:45
bool get_is_quick_test()
Definition: flags.h:183
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Various classes to hold sets of particles.
Upper bound harmonic function (non-zero when feature > mean)
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition: XYZR.h:48
Create a scoring function on a list of restraints.
Move continuous particle variables by perturbing them within a ball.
Score particles based on how far outside a box they are.
Vector3D get_random_vector_in(const Cylinder3D &c)
Generate a random vector in a cylinder with uniform density.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:73
Store a list of ParticleIndexes.
void set_log_level(LogLevel l)
Set the current global log level.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition: VectorD.h:421
Prevent a set of particles and rigid bodies from inter-penetrating.
Class to handle individual particles of a Model object.
Definition: Particle.h:41
Write a CGO file with the geometry.
Definition: PymolWriter.h:34
Output IMP model data in various file formats.
Applies a list of movers one at a time.
Definition: SerialMover.h:23
Display an IMP::core::XYZR particle as a ball.
Definition: XYZR.h:151
std::string create_temporary_file_name(std::string prefix="imp_temp", std::string suffix="")
Create a temporary file.