RMF
externals.py
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.
4import RMF
5import os.path
6import sys
7
8input_pdb = os.path.join(os.path.split(sys.argv[0])[0], "simple.pdb")
9rmf_name = RMF._get_temporary_file_path("externals.rmf")
10output_pdb = RMF._get_temporary_file_path("simple.pdb")
11print("file name is", rmf_name)
12
13rmf = RMF.create_rmf_file(rmf_name)
14rmf.add_frame("root", RMF.FRAME)
15
16# copy simple.pdb to output dir
17open(output_pdb, "w").write(open(input_pdb, "r").read())
18pdb_relpath = "./simple.pdb"
19
20rpf = RMF.ReferenceFrameFactory(rmf)
21ef = RMF.ExternalFactory(rmf)
22# add a couple transformed copies of simple
23c0 = rmf.get_root_node().add_child("copy0", RMF.REPRESENTATION)
24rb0 = rpf.get(c0)
25rb0.set_translation(RMF.Vector3(0, 0, 0))
26rb0.set_rotation(RMF.Vector4(1, 0, 0, 0))
27external = c0.add_child("simple.pdb", RMF.REPRESENTATION)
28ed = ef.get(external)
29ed.set_path(pdb_relpath)
30
31# add another, reusing the same reference node
32c1 = rmf.get_root_node().add_child("copy1", RMF.REPRESENTATION)
33rb1 = rpf.get(c1)
34rb1.set_translation(RMF.Vector3(20, 0, 0))
35rb1.set_rotation(RMF.Vector4(.5, .5, .5, .5))
36c1.add_child(external)
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.