IMP  2.3.1
The Integrative Modeling Platform
rmf/simulation.py

This example shows writing a brownian dynamics simulation to a rmf file. It includes a bounding box, restraints and a hierarchy of particles.

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