RMF
Toggle main menu visibility
alias.py
1
## \example alias.py
2
# Show using aliases to provide two different organization schemes
3
# for manipulating a hierarchy.
4
import
RMF
5
6
# find the name for a temporary file to use to for writing the hdf5 file
7
tfn = RMF._get_temporary_file_path(
"aliases.rmf"
)
8
print(
"File is"
, tfn)
9
10
# open the temporary file, clearing any existing contents
11
fh =
RMF.create_rmf_file
(tfn)
12
13
# add a frame to the file
14
fh.add_frame(
"root"
, RMF.FRAME)
15
16
rh = fh.get_root_node()
17
# add a bunch of "molecules" with colors
18
mrh = rh.add_child(
"molecules"
, RMF.REPRESENTATION)
19
20
pf = RMF.ParticleFactory(fh)
21
cf = RMF.ColoredFactory(fh)
22
23
red = []
24
green = []
25
blue = []
26
for
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
46
crh = rh.add_child(
"colors"
, RMF.REPRESENTATION)
47
48
redh = crh.add_child(
"red"
, RMF.REPRESENTATION)
49
greenh = crh.add_child(
"green"
, RMF.REPRESENTATION)
50
blueh = crh.add_child(
"blue"
, RMF.REPRESENTATION)
51
52
af = RMF.AliasFactory(fh)
53
for
r
in
red:
54
af.get(redh.add_child(
"red"
, RMF.ALIAS)).set_aliased(r)
55
for
g
in
green:
56
af.get(greenh.add_child(
"green"
, RMF.ALIAS)).set_aliased(g)
57
for
b
in
blue:
58
af.get(blueh.add_child(
"blue"
, RMF.ALIAS)).set_aliased(b)
RMF::Vector< 3U >
RMF::create_rmf_file
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.