RMF
alternatives.py
1## \example alternatives.py
2# The RMF format supports storing alternative representations of the structure
3# through the RMF::decorator::Alternatives decorator and associated types.
4# Multiple versions of the hierarchy are stored, all representing the same
5# biological entity. Different representations can be used for different
6# purposes based on resolution or other criteria.
7
8import RMF
9
10tfn = RMF._get_temporary_file_path("alternatives.rmf3")
11print("File is", tfn)
12
14f.add_frame("frame", RMF.FRAME)
15
16# make a trivial set of multiple resolution represntations
17rh = f.get_root_node()
18
19pf = RMF.ParticleFactory(f)
20gpf = RMF.GaussianParticleFactory(f)
21rff = RMF.ReferenceFrameFactory(f)
22
23
24def frange(x, y, jump):
25 while x < y:
26 yield x
27 x += jump
28
29
30def create_hierarchy(radius):
31 root = f.add_node(str(radius), RMF.REPRESENTATION)
32 for i in frange(0., 8, radius):
33 for j in frange(0., 8, radius):
34 for k in frange(0., 8, radius):
35 center = RMF.Vector3(
36 i + radius / 2,
37 j + radius / 2,
38 k + radius / 2)
39 n = root.add_child(
40 str(i) + "-" + str(j) + "-" + str(k),
41 RMF.REPRESENTATION)
42 d = pf.get(n)
43 d.set_static_radius(radius)
44 d.set_frame_coordinates(center)
45 d.set_static_mass(radius ** 3)
46 return root
47
48
49def create_gmm(radius=1.):
50 root = f.add_node("gmm" + str(radius), RMF.REPRESENTATION)
51 for i in frange(0., 8, radius):
52 for j in frange(0., 8, radius):
53 center = RMF.Vector3(
54 i + radius / 2,
55 j + radius / 2,
56 4)
57
58 n = root.add_child(
59 str(i) + "-" + str(j),
60 RMF.REPRESENTATION)
61 d = gpf.get(n)
62 d.set_variances(RMF.Vector3(radius / 2, radius / 2, 4))
63 d.set_static_mass(radius ** 3)
64 rf = rff.get(n)
65 rf.set_rotation(RMF.Vector4(1, 0, 0, 0))
66 rf.set_translation(center)
67 return root
68
69n = create_hierarchy(4)
70rh.add_child(n)
71
72af = RMF.AlternativesFactory(f)
73da = af.get(n)
74da.add_alternative(create_hierarchy(1), RMF.PARTICLE)
75da.add_alternative(create_hierarchy(2), RMF.PARTICLE)
76da.add_alternative(create_hierarchy(4), RMF.PARTICLE)
77da.add_alternative(create_gmm(), RMF.GAUSSIAN_PARTICLE)
78
80
81print("particles", RMF.get_resolutions(n, RMF.PARTICLE))
82print("gaussian particles", RMF.get_resolutions(n, RMF.GAUSSIAN_PARTICLE))
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.
void show_hierarchy(NodeConstHandle root, std::ostream &out)