IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
core/incremental_mc.py

This example shows how to do incremental scoring with Monte Carlo. Incremental scoring can be significantly faster than non-incremental scoring when using moves that only move a few particles at a time.

1 ## \example core/incremental_mc.py
2 # This example shows how to do incremental scoring with Monte Carlo.
3 # Incremental scoring can be significantly faster than non-incremental
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)
39 isf = IMP.core.IncrementalScoringFunction(m, ps, [r, rb])
40 mc.set_incremental_scoring_function(isf)
41 
42 mvs = [IMP.core.BallMover(m, p, 5) for p in ps]
43 sm = IMP.core.SerialMover(mvs)
44 mc.add_mover(sm)
45 IMP.set_log_level(IMP.SILENT)
46 print("initial", isf.evaluate(False))
47 after = mc.optimize(num_mc_steps)
48 print("final", after)
49 name = IMP.create_temporary_file_name("incremental_mc", ".pym")
51 for p in ps:
53  w.add_geometry(g)
54 print("pymol", name)