IMP  2.0.1
The Integrative Modeling Platform
decay.py
1 ## \example misc/decay.py
2 ## Use the IMP::misc::DecayPairContainerOptimizerState to gradually break the bonds in a bd simulation.
3 
4 import IMP.atom
5 import IMP.container
6 import IMP.misc
7 import IMP.display
8 import IMP.example
9 import IMP.base
10 import sys
11 import IMP.rmf
12 #import IMP.benchmark
13 import RMF
14 import random
15 
16 IMP.base.setup_from_argv(sys.argv, "Use the IMP::misc::DecayPairContainerOptimizerState to gradually break the bonds in a bd simulation")
17 
18 if IMP.base.get_bool_flag("run_quick_test"):
19  np=8
20  nb=8
21  prob=.5
22  period=2
23  steps=10
24 else:
25  np=20
26  nb=40
27  prob=.9
28  period=10
29  steps=10000
30 
31 m= IMP.Model()
32 
34  IMP.algebra.Vector3D(100,100,100))
35 ps=[]
36 for i in range(0,np):
37  p= IMP.Particle(m)
39  d.set_coordinates(IMP.algebra.get_random_vector_in(bb))
40  d.set_radius(10)
41  d.set_coordinates_are_optimized(True)
45  ps.append(p)
47 
48 bds=[]
49 for i in range(0,nb):
50  pp= random.sample(ps, 2)
51  if pp not in bds and [pp[1], pp[0]] not in bds:
52  bds.append(pp)
53 
55 dos= IMP.misc.DecayPairContainerOptimizerState(cf, bds, "decay")
56 dos.set_period(period)
57 dos.set_log_level(IMP.base.VERBOSE)
58 
59 # create restraints
60 rs=[]
62 rs.append(IMP.container.SingletonsRestraint(box_score, ps, "box"))
64 rs.append(IMP.container.PairsRestraint(bond_score,
65  dos.get_output_container(),
66  "bonds"))
68 # equilibrate
69 print "equilibrating"
70 IMP.base.set_log_level(IMP.PROGRESS)
71 
72 #IMP.benchmark.set_is_profiling(True)
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.base.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])
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