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