IMP
2.0.0
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
incremental_mc.py
1
## \example core/incremental_mc.py
2
## 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.
3
4
import
IMP.core
5
import
IMP.container
6
import
IMP.algebra
7
import
IMP.display
8
m=
IMP.Model
()
9
bb=
IMP.algebra.BoundingBox3D
(
IMP.algebra.Vector3D
(0,0,0),
10
IMP.algebra.Vector3D
(30, 30, 30))
11
ps=[]
12
for
i
in
range(0,20):
13
ps.append(
IMP.Particle
(m))
14
d=
IMP.core.XYZR.setup_particle
(ps[-1])
15
d.set_radius(10)
16
d.set_coordinates(
IMP.algebra.get_random_vector_in
(bb))
17
d.set_coordinates_are_optimized(
True
)
18
19
psl=
IMP.container.ListSingletonContainer
(ps)
20
r=
IMP.core.ExcludedVolumeRestraint
(psl, 1)
21
rb=
IMP.container.SingletonsRestraint
(
IMP.core.BoundingBox3DSingletonScore
(
IMP.core.HarmonicUpperBound
(0,1), bb),
22
psl)
23
mc=
IMP.core.MonteCarlo
(m)
24
isf=
IMP.core.IncrementalScoringFunction
(ps, [r, rb])
25
mc.set_incremental_scoring_function(isf)
26
27
mvs=[
IMP.core.BallMover
([p], 5)
for
p
in
ps]
28
sm=
IMP.core.SerialMover
(mvs)
29
mc.add_mover(sm)
30
IMP.base.set_log_level
(IMP.base.SILENT)
31
print
"initial"
,isf.evaluate(
False
)
32
after=mc.optimize(10000)
33
print
"final"
, after
34
name=
IMP.base.create_temporary_file_name
(
"incremental_mc"
,
".pym"
)
35
w=
IMP.display.PymolWriter
(name)
36
for
p
in
ps:
37
g=
IMP.core.XYZRGeometry
(p)
38
w.add_geometry(g)
39
print
"pymol"
, name