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