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