IMP logo
IMP Reference Guide  2.22.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 import IMP.atom
6 import IMP.rmf
7 import RMF
8 import IMP.container
9 import IMP.display
10 import sys
11 
12 IMP.setup_from_argv(sys.argv, "simulation")
13 
14 k = 10.0
15 np = 10
16 frames = 10
17 
18 m = IMP.Model()
20  IMP.algebra.Vector3D(10, 10, 10))
21 
23  for i in range(0, np)]
25 for p in ps:
26  p.set_radius(1)
27  p.set_coordinates_are_optimized(True)
30  p.set_coordinates(IMP.algebra.get_random_vector_in(bb))
31 rs = []
33 pl = []
34 for i in range(0, len(ps) // 2):
35  pp = (ps[2 * i], ps[2 * i + 1])
36  pl.append(pp)
37  # create OK staring position
38  pp[1].set_coordinates(IMP.algebra.get_random_vector_on(pp[0].get_sphere()))
42  IMP.Particle(m, "molecule " + str(i)))
43  hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[0]))
44  hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[1]))
45  h.add_child(hr)
46 r = IMP.container.PairsRestraint(link, pl, "Bonds")
47 rs.append(r)
48 
49 ev = IMP.core.ExcludedVolumeRestraint(ps, k, 1, "EV")
50 rs.append(ev)
51 
55 rs.append(bbr)
56 
58 
60 bd.set_log_level(IMP.SILENT)
61 bd.set_scoring_function(sf)
62 
63 bd.set_maximum_time_step(10)
64 
65 rmf = RMF.create_rmf_file("brownian.rmf")
66 rmf.set_description("Brownian dynamics trajectory with 10fs timestep.\n")
70 
71 os = IMP.rmf.SaveOptimizerState(m, rmf)
72 os.update_always("initial conformation")
73 os.set_log_level(IMP.SILENT)
74 os.set_simulator(bd)
75 bd.add_optimizer_state(os)
76 
77 bd.optimize(frames)
78 
79 print("file is", rmf.get_name())