IMP logo
IMP Reference Guide  2.17.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 sys
12 import IMP.rmf
13 import RMF
14 import random
15 
17  sys.argv,
18  "Use the IMP::misc::DecayPairContainerOptimizerState to gradually "
19  "break the bonds in a bd simulation")
20 
21 if IMP.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.Model()
35 
37  IMP.algebra.Vector3D(100, 100, 100))
38 ps = []
39 for i in range(0, np):
40  p = m.add_particle("p")
42  d.set_coordinates(
43  IMP.algebra.Vector3D(10. * (i / 10), 10. * (i % 10), 10.))
44  d.set_radius(10)
45  d.set_coordinates_are_optimized(True)
49  ps.append(p)
51 
52 bds = []
53 for i in range(0, nb):
54  pp = random.sample(ps, 2)
55  if pp not in bds and [pp[1], pp[0]] not in bds:
56  bds.append(pp)
57 
59 dos = IMP.misc.DecayPairContainerOptimizerState(m, cf, bds, "decay")
60 dos.set_period(period)
61 dos.set_log_level(IMP.SILENT) # VERBOSE
62 
63 # create restraints
64 rs = []
66  IMP.core.HarmonicUpperBound(0, 10), bb)
67 ps_container = IMP.container.ListSingletonContainer(m, ps)
68 rs.append(IMP.container.SingletonsRestraint(box_score, ps_container, "box"))
70 rs.append(IMP.container.PairsRestraint(bond_score,
71  dos.get_output_container(),
72  "bonds"))
73 ev = IMP.core.ExcludedVolumeRestraint(ps_container, 10, 10)
74 IMP.set_log_level(IMP.SILENT)
75 
76 # set up simulator
78 bd.set_maximum_time_step(1000)
79 bd.set_scoring_function(rs + [ev])
80 bd.add_optimizer_state(dos)
81 
82 # set up display
83 fn = IMP.create_temporary_file_name("decay", ".rmf")
84 rmf = RMF.create_rmf_file(fn)
85 print("setting up file")
87 IMP.rmf.add_restraints(rmf, rs + [ev])
89 IMP.rmf.add_geometries(rmf, [g])
90 os = IMP.rmf.SaveOptimizerState(m, rmf)
91 os.set_period(max(steps / 100, 1))
92 bd.add_optimizer_state(os)
93 
94 # actually optimize things
95 print("running")
96 bd.optimize(steps)
97 
98 print("see", fn)