IMP  2.4.0
The Integrative Modeling Platform
misc/decay.py

Use the IMP::misc::DecayPairContainerOptimizerState to gradually break the bonds in a bd simulation.

1 ## \example misc/decay.py
2 # Use the IMP::misc::DecayPairContainerOptimizerState to gradually break
3 # the bonds in a bd simulation.
4 
5 from __future__ import print_function
6 import IMP.atom
7 import IMP.container
8 import IMP.misc
9 import IMP.display
10 import IMP.example
11 import IMP.base
12 import sys
13 import IMP.rmf
14 #import IMP.benchmark
15 import RMF
16 import random
17 
19  sys.argv, "Use the IMP::misc::DecayPairContainerOptimizerState to gradually break the bonds in a bd simulation")
20 
21 if IMP.base.get_bool_flag("run_quick_test"):
22  np = 8
23  nb = 8
24  prob = .5
25  period = 2
26  steps = 10
27 else:
28  np = 20
29  nb = 40
30  prob = .9
31  period = 10
32  steps = 10000
33 
34 m = IMP.kernel.Model()
35 
37  IMP.algebra.Vector3D(100, 100, 100))
38 ps = []
39 for i in range(0, np):
40  p = IMP.kernel.Particle(m)
42  d.set_coordinates(IMP.algebra.Vector3D(10. * (i/10), 10. * (i%10), 10.))
43  d.set_radius(10)
44  d.set_coordinates_are_optimized(True)
48  ps.append(p)
50 
51 bds = []
52 for i in range(0, nb):
53  pp = random.sample(ps, 2)
54  if pp not in bds and [pp[1], pp[0]] not in bds:
55  bds.append(pp)
56 
58 dos = IMP.misc.DecayPairContainerOptimizerState(cf, bds, "decay")
59 dos.set_period(period)
60 dos.set_log_level(IMP.base.SILENT) # VERBOSE
61 
62 # create restraints
63 rs = []
65  IMP.core.HarmonicUpperBound(0, 10), bb)
66 rs.append(IMP.container.SingletonsRestraint(box_score, ps, "box"))
68 rs.append(IMP.container.PairsRestraint(bond_score,
69  dos.get_output_container(),
70  "bonds"))
71 ev = IMP.core.ExcludedVolumeRestraint(ps, 10, 10)
72 IMP.base.set_log_level(IMP.SILENT)
73 
74 # set up simulator
76 bd.set_maximum_time_step(1000)
77 bd.set_scoring_function(rs + [ev])
78 bd.add_optimizer_state(dos)
79 
80 # set up display
81 fn = IMP.base.create_temporary_file_name("decay", ".rmf")
82 rmf = RMF.create_rmf_file(fn)
83 print("setting up file")
85 IMP.rmf.add_restraints(rmf, rs + [ev])
87 IMP.rmf.add_geometries(rmf, [g])
88 os = IMP.rmf.SaveOptimizerState(m, rmf)
89 os.set_period(max(steps / 100, 1))
90 bd.add_optimizer_state(os)
91 
92 # actually optimize things
93 print("running")
94 bd.optimize(steps)
95 
96 print("see", fn)