RMF
multistate.py
1 ## \example multistate.py
2 # Show how to create an detect files where frames represent multiple
3 # states of the same thing.
4 
5 from __future__ import print_function
6 import RMF
7 
8 tfn = RMF._get_temporary_file_path("multistate.rmf3")
9 print("File is", tfn)
10 
11 fh = RMF.create_rmf_file(tfn)
12 rh = fh.get_root_node()
13 pf = RMF.ParticleFactory(fh)
14 bf = RMF.BondFactory(fh)
15 sf = RMF.StateFactory(fh)
16 
17 
18 def create_hierarchy(state):
19  ns = []
20  rt = rh.add_child("state" + str(state), RMF.REPRESENTATION)
21  sf.get(rt).set_static_state_index(state)
22  for i in range(0, 3):
23  n = rt.add_child(str(i), RMF.REPRESENTATION)
24  ns.append(n)
25  pf.get(n).set_static_mass(1)
26  pf.get(n).set_static_radius(1)
27  for i in range(0, 2):
28  b = rt.add_child("b", RMF.BOND)
29  bd = bf.get(b)
30  bd.set_bonded_0(ns[i].get_id().get_index())
31  bd.set_bonded_1(ns[i + 1].get_id().get_index())
32  return ns
33 
34 all_ps = []
35 for i in range(0, 3):
36  all_ps.append(create_hierarchy(i))
37 
38 for frame in range(0, 4):
39  fh.add_frame(str(i), RMF.FRAME)
40  for state, sps in enumerate(all_ps):
41  for particle, p in enumerate(sps):
42  pf.get(
43  p).set_coordinates(RMF.Vector3(particle + frame + .1 * state,
44  frame + .1 * state,
45  frame + .1 * state))
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.