5 from __future__
import print_function
12 def create_residue(nh, af, pf):
13 for i
in range(0, 2 * scale):
14 child = nh.add_child(
"CA", RMF.REPRESENTATION)
15 pf.get(child).set_mass(1)
16 pf.get(child).set_radius(1.0 + i / 18.77)
17 af.get(child).set_element(7)
20 def create_chain(nh, rf, af, pf):
21 for i
in range(0, 60 * scale):
22 child = nh.add_child(str(i), RMF.REPRESENTATION)
23 rf.get(child).set_residue_type(
"cys")
24 rf.get(child).set_residue_index(i)
25 create_residue(child, af, pf)
28 def create_hierarchy(file):
29 cf = RMF.ChainFactory(file)
30 af = RMF.AtomFactory(file)
31 rf = RMF.ResidueFactory(file)
32 pf = RMF.ParticleFactory(file)
33 n = file.get_root_node()
34 for i
in range(0, 3 * scale):
35 child = n.add_child(str(i), RMF.REPRESENTATION)
36 cf.get(child).set_chain_id(str(i))
37 create_chain(child, rf, af, pf)
40 def create_frame(fh, ipf, atoms, frame):
43 v =
RMF.Vector3((1.0 * n.get_index() + 0 + frame) / 17.0,
44 (1.0 * n.get_index() + 1 + frame) / 19.0,
45 (1.0 * n.get_index() + 2 + frame) / 23.0)
49 ipf.get(fh.get_node(n)).set_coordinates(v)
50 return ret[0] + ret[1] + ret[2]
54 create_hierarchy(file)
56 for n
in file.get_node_ids():
57 if len(file.get_node(n).get_children()) == 0:
59 ipf = RMF.IntermediateParticleFactory(file)
61 for i
in range(0, 20):
62 file.add_frame(
"frame", RMF.FRAME)
63 ret += create_frame(file, ipf, atoms, i)
69 queue = [file.get_root_node()]
70 ipcf = RMF.IntermediateParticleConstFactory(file)
71 while (len(queue) > 0):
76 ret += ipcf.get(cur).get_radius()
77 queue += cur.get_children()
82 def load(file, nodes):
83 ipcf = RMF.IntermediateParticleConstFactory(file)
85 for fr
in file.get_frames():
86 file.set_current_frame(fr)
88 cur = ipcf.get(file.get_node(n)).get_coordinates()
92 return v[0] + v[1] + v[2]
95 def benchmark_create(file, type):
96 start = datetime.datetime.now()
98 print(type,
"create,", datetime.datetime.now() - start,
",", dist)
101 def benchmark_traverse(file, type):
102 start = datetime.datetime.now()
105 print(type,
"traverse,", datetime.datetime.now() - start,
",", t)
108 def benchmark_load(file, type):
110 ipcf = RMF.IntermediateParticleConstFactory(file)
111 for n
in file.get_node_ids():
112 if ipcf.get_is(file.get_node(n)):
114 start = datetime.datetime.now()
115 dist = load(file, nodes)
116 print(type,
"load,", datetime.datetime.now() - start,
",", dist)
118 name =
"benchmark_python.rmf"
120 benchmark_create(fh,
" python rmf")
124 benchmark_traverse(fh,
"python rmf")
125 benchmark_load(fh,
"python rmf")
FileConstHandle open_rmf_file_read_only(std::string path)
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.