RMF
alias.py
1 ## \example alias.py
2 # Show using aliases to provide two different organization schemes
3 # for manipulating a hierarchy.
4 from __future__ import print_function
5 import RMF
6 
7 # find the name for a temporary file to use to for writing the hdf5 file
8 tfn = RMF._get_temporary_file_path("aliases.rmf")
9 print("File is", tfn)
10 
11 # open the temporary file, clearing any existing contents
12 fh = RMF.create_rmf_file(tfn)
13 
14 # add a frame to the file
15 fh.add_frame("root", RMF.FRAME)
16 
17 rh = fh.get_root_node()
18 # add a bunch of "molecules" with colors
19 mrh = rh.add_child("molecules", RMF.REPRESENTATION)
20 
21 pf = RMF.ParticleFactory(fh)
22 cf = RMF.ColoredFactory(fh)
23 
24 red = []
25 green = []
26 blue = []
27 for i in range(0, 10):
28  curph = mrh.add_child("mol" + str(i), RMF.REPRESENTATION)
29  for j in range(0, 10):
30  curh = curph.add_child("atom" + str(j), RMF.REPRESENTATION)
31  p = pf.get(curh)
32  p.set_coordinates(RMF.Vector3(3 * i, 3 * j, 0))
33  p.set_mass(1)
34  p.set_radius(1)
35  c = cf.get(curh)
36  if j % 3 == 0:
37  c.set_rgb_color(RMF.Vector3(1, 0, 0))
38  red.append(curh)
39  elif j % 3 == 1:
40  c.set_rgb_color(RMF.Vector3(0, 1, 0))
41  green.append(curh)
42  else:
43  c.set_rgb_color(RMF.Vector3(0, 0, 1))
44  blue.append(curh)
45 
46 # add a second organization scheme by color
47 crh = rh.add_child("colors", RMF.REPRESENTATION)
48 
49 redh = crh.add_child("red", RMF.REPRESENTATION)
50 greenh = crh.add_child("green", RMF.REPRESENTATION)
51 blueh = crh.add_child("blue", RMF.REPRESENTATION)
52 
53 af = RMF.AliasFactory(fh)
54 for r in red:
55  af.get(redh.add_child("red", RMF.ALIAS)).set_aliased(r)
56 for g in green:
57  af.get(greenh.add_child("green", RMF.ALIAS)).set_aliased(g)
58 for b in blue:
59  af.get(blueh.add_child("blue", RMF.ALIAS)).set_aliased(b)
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.