RMF
externals.py

Show how to create an RMF file that has references to external files. And how to read it back, sort of.

1 ## \example externals.py
2 # Show how to create an RMF file that has references to external files.
3 # And how to read it back, sort of.
4 from __future__ import print_function
5 import RMF
6 import os.path
7 import sys
8 
9 input_pdb = os.path.join(os.path.split(sys.argv[0])[0], "simple.pdb")
10 rmf_name = RMF._get_temporary_file_path("externals.rmf")
11 output_pdb = RMF._get_temporary_file_path("simple.pdb")
12 print("file name is", rmf_name)
13 
14 rmf = RMF.create_rmf_file(rmf_name)
15 rmf.add_frame("root", RMF.FRAME)
16 
17 # copy simple.pdb to output dir
18 open(output_pdb, "w").write(open(input_pdb, "r").read())
19 pdb_relpath = "./simple.pdb"
20 
21 rpf = RMF.ReferenceFrameFactory(rmf)
22 ef = RMF.ExternalFactory(rmf)
23 # add a couple transformed copies of simple
24 c0 = rmf.get_root_node().add_child("copy0", RMF.REPRESENTATION)
25 rb0 = rpf.get(c0)
26 rb0.set_translation(RMF.Vector3(0, 0, 0))
27 rb0.set_rotation(RMF.Vector4(1, 0, 0, 0))
28 external = c0.add_child("simple.pdb", RMF.REPRESENTATION)
29 ed = ef.get(external)
30 ed.set_path(pdb_relpath)
31 
32 # add another, reusing the same reference node
33 c1 = rmf.get_root_node().add_child("copy1", RMF.REPRESENTATION)
34 rb1 = rpf.get(c1)
35 rb1.set_translation(RMF.Vector3(20, 0, 0))
36 rb1.set_rotation(RMF.Vector4(.5, .5, .5, .5))
37 c1.add_child(external)