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