RMF
reference_frame_particle.py

This simple example makes an RMF file with several rigid copies of the same thing

1 ## \example reference_frame_particle.py
2 # This simple example makes an RMF file with several rigid copies of the
3 # same thing
4 import RMF
5 
6 file_name = RMF._get_temporary_file_path("reference_frame.rmfz")
7 print("file is", file_name)
8 fh = RMF.create_rmf_file(file_name)
9 fh.add_frame("first frame", RMF.FRAME)
10 
11 rh = fh.get_root_node()
12 
13 reference_frame_factory = RMF.ReferenceFrameFactory(fh)
14 ball_factory = RMF.BallFactory(fh)
15 particle_factory = RMF.ParticleFactory(fh)
16 color_factory = RMF.ColoredFactory(fh)
17 bond_factory = RMF.BondFactory(fh)
18 
19 origin = rh.add_child("origin", RMF.REPRESENTATION)
20 pd = particle_factory.get(origin)
21 pd.set_radius(1)
22 pd.set_mass(2)
23 pd.set_coordinates(RMF.Vector3(0, 0, 0))
24 
25 for i in range(0, 3):
26  c = rh.add_child(str(i), RMF.REPRESENTATION)
27  pd = particle_factory.get(c)
28  pd.set_radius(1)
29  pd.set_mass(2)
30  coords = [0, 0, 0]
31  coords[i] = 2
32  pd.set_coordinates(RMF.Vector3(*coords))
33 
34 
35 frame = rh.add_child("frame", RMF.REPRESENTATION)
36 rbo = reference_frame_factory.get(frame)
37 rbo.set_translation(RMF.Vector3(5, 0, 0))
38 rbo.set_rotation(RMF.Vector4(1, 0, 0, 0))
39 pd = particle_factory.get(frame)
40 pd.set_radius(5)
41 pd.set_mass(2)
42 pd.set_coordinates(RMF.Vector3(0, 0, 0))
43 
44 for i in range(0, 3):
45  ch = frame.add_child("site", RMF.GEOMETRY)
46  coords = [0, 0, 0]
47  coords[i] = 5
48  v = RMF.Vector3(*coords)
49  ball_factory.get(ch).set_coordinates(v)
50  ball_factory.get(ch).set_radius(1)
51  bch = frame.add_child("bond", RMF.BOND)
52  bond_factory.get(bch).set_bonded_0(ch.get_id().get_index())
53  bond_factory.get(bch).set_bonded_1(frame.get_id().get_index())