IMP logo
IMP Reference Guide  develop.731656d855,2020/02/16
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 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.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(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(m, cf, bds, "decay")
58 dos.set_period(period)
59 dos.set_log_level(IMP.SILENT) # VERBOSE
60 
61 # create restraints
62 rs = []
64  IMP.core.HarmonicUpperBound(0, 10), bb)
65 ps_container = IMP.container.ListSingletonContainer(m, ps)
66 rs.append(IMP.container.SingletonsRestraint(box_score, ps_container, "box"))
68 rs.append(IMP.container.PairsRestraint(bond_score,
69  dos.get_output_container(),
70  "bonds"))
71 ev = IMP.core.ExcludedVolumeRestraint(ps_container, 10, 10)
72 IMP.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.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)