IMP logo
IMP Reference Guide  develop.7400db2aee,2024/11/23
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 sys
11 import IMP.rmf
12 import RMF
13 import random
14 
16  sys.argv,
17  "Use the IMP::misc::DecayPairContainerOptimizerState to gradually "
18  "break the bonds in a bd simulation")
19 
20 if IMP.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.Model()
34 
36  IMP.algebra.Vector3D(100, 100, 100))
37 ps = []
38 for i in range(0, np):
39  p = m.add_particle("p")
41  d.set_coordinates(
42  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(m, cf, bds, "decay")
59 dos.set_period(period)
60 dos.set_log_level(IMP.SILENT) # VERBOSE
61 
62 # create restraints
63 rs = []
65  IMP.core.HarmonicUpperBound(0, 10), bb)
66 ps_container = IMP.container.ListSingletonContainer(m, ps)
67 rs.append(IMP.container.SingletonsRestraint(box_score, ps_container, "box"))
69 rs.append(IMP.container.PairsRestraint(bond_score,
70  dos.get_output_container(),
71  "bonds"))
72 ev = IMP.core.ExcludedVolumeRestraint(ps_container, 10, 10)
73 IMP.set_log_level(IMP.SILENT)
74 
75 # set up simulator
77 bd.set_maximum_time_step(1000)
78 bd.set_scoring_function(rs + [ev])
79 bd.add_optimizer_state(dos)
80 
81 # set up display
82 fn = IMP.create_temporary_file_name("decay", ".rmf")
83 rmf = RMF.create_rmf_file(fn)
84 print("setting up file")
86 IMP.rmf.add_restraints(rmf, rs + [ev])
88 IMP.rmf.add_geometries(rmf, [g])
89 os = IMP.rmf.SaveOptimizerState(m, rmf)
90 os.set_period(max(steps / 100, 1))
91 bd.add_optimizer_state(os)
92 
93 # actually optimize things
94 print("running")
95 bd.optimize(steps)
96 
97 print("see", fn)