IMP  2.4.0
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 from __future__ import print_function, division
6 import IMP.atom
7 import IMP.rmf
8 import RMF
9 import IMP.container
10 import IMP.display
11 
12 k = 10.0
13 np = 10
14 frames = 10
15 
16 m = IMP.kernel.Model()
18  IMP.algebra.Vector3D(10, 10, 10))
19 
21  for i in range(0, np)]
23 for p in ps:
24  p.set_radius(1)
25  p.set_coordinates_are_optimized(True)
28  p.set_coordinates(IMP.algebra.get_random_vector_in(bb))
29 rs = []
31 pl = []
32 for i in range(0, len(ps) // 2):
33  pp = (ps[2 * i], ps[2 * i + 1])
34  pl.append(pp)
35  # create OK staring position
36  pp[1].set_coordinates(IMP.algebra.get_random_vector_on(pp[0].get_sphere()))
40  IMP.kernel.Particle(m, "molecule " + str(i)))
41  hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[0]))
42  hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[1]))
43  h.add_child(hr)
44 r = IMP.container.PairsRestraint(link, pl, "Bonds")
45 rs.append(r)
46 
47 ev = IMP.core.ExcludedVolumeRestraint(ps, k, 1, "EV")
48 rs.append(ev)
49 
53 rs.append(bbr)
54 
56 
58 bd.set_log_level(IMP.base.SILENT)
59 bd.set_scoring_function(sf)
60 
61 bd.set_maximum_time_step(10)
62 
63 name = IMP.base.create_temporary_file_name("brownian", ".rmf")
64 rmf = RMF.create_rmf_file(name)
65 rmf.set_description("Brownian dyanmics trajectory with 10fs timestep.\n")
68 IMP.rmf.add_geometry(rmf, IMP.display.BoundingBoxGeometry(bb))
69 
70 os = IMP.rmf.SaveOptimizerState(m, rmf)
71 os.update_always("initial conformation")
72 os.set_log_level(IMP.base.SILENT)
73 os.set_simulator(bd)
74 bd.add_optimizer_state(os)
75 
76 bd.optimize(frames)
77 
78 print("file is", rmf.get_name())