IMP  2.0.0
The Integrative Modeling Platform
simulation.py
1 ## \example rmf/simulation.py
2 ## This example shows writing a brownian dynamics simulation to a rmf file. It includes a bounding box, restraints and a hierarchy of particles.
3 
4 import IMP.atom
5 import IMP.rmf
6 import RMF
7 import IMP.container
8 import IMP.display
9 
10 k=10.0
11 np=10
12 frames=10
13 
14 m= IMP.Model()
16  IMP.algebra.Vector3D(10,10,10))
17 
18 ps= [IMP.core.XYZR.setup_particle(IMP.Particle(m)) for i in range(0,np)]
20 for p in ps:
21  p.set_radius(1)
22  p.set_coordinates_are_optimized(True)
25  p.set_coordinates(IMP.algebra.get_random_vector_in(bb))
26 rs=[]
28 pl=[]
29 for i in range(0, len(ps)/2):
30  pp=(ps[2*i], ps[2*i+1])
31  pl.append(pp)
32  # create OK staring position
33  pp[1].set_coordinates(IMP.algebra.get_random_vector_on(pp[0].get_sphere()))
36  hr= IMP.atom.Hierarchy.setup_particle(IMP.Particle(m, "molecule "+str(i)))
37  hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[0]))
38  hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[1]))
39  h.add_child(hr)
40 r= IMP.container.PairsRestraint(link, pl, "Bonds")
41 rs.append(r)
42 
43 ev= IMP.core.ExcludedVolumeRestraint(ps, k, 1, "EV")
44 rs.append(ev)
45 
48 rs.append(bbr)
49 
51 
53 bd.set_log_level(IMP.base.SILENT)
54 bd.set_scoring_function(sf)
55 
56 bd.set_maximum_time_step(10)
57 
58 name= IMP.base.create_temporary_file_name("brownian", ".rmf")
59 rmf= RMF.create_rmf_file(name)
60 rmf.set_description("Brownian dyanmics trajectory with 10fs timestep.\n")
63 IMP.rmf.add_geometry(rmf, IMP.display.BoundingBoxGeometry(bb))
64 
66 os.update_always("initial conformation")
67 os.set_log_level(IMP.base.SILENT)
68 os.set_simulator(bd)
69 bd.add_optimizer_state(os)
70 
71 bd.optimize(frames)
72 
73 print "file is", rmf.get_name()