IMP  2.1.1
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.get_random_vector_in(bb))
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 # equilibrate
72 print "equilibrating"
73 IMP.base.set_log_level(IMP.PROGRESS)
74 # IMP.benchmark.set_is_profiling(True)
76 IMP.base.set_log_level(IMP.SILENT)
77 
78 # set up simulator
80 bd.set_maximum_time_step(1000)
81 bd.set_scoring_function(rs + [ev])
82 bd.add_optimizer_state(dos)
83 
84 # set up display
85 fn = IMP.base.create_temporary_file_name("decay", ".rmf")
86 rmf = RMF.create_rmf_file(fn)
87 print "setting up file"
89 IMP.rmf.add_restraints(rmf, rs + [ev])
91 IMP.rmf.add_geometries(rmf, [g])
92 os = IMP.rmf.SaveOptimizerState(m, rmf)
93 os.set_period(max(steps / 100, 1))
94 bd.add_optimizer_state(os)
95 
96 # actually optimize things
97 print "running"
98 bd.optimize(steps)
99 
100 print "see", fn