RMF
benchmark_rmf.py
1 ## \example benchmark/benchmark_rmf.py
2 # \brief Benchmark operations on the RMF from python to see how much overhead
3 # that adds
4 
5 import RMF
6 import datetime
7 
8 scale = 5
9 
10 
11 def create_residue(nh, af, pf):
12  for i in range(0, 2 * scale):
13  child = nh.add_child("CA", RMF.REPRESENTATION)
14  pf.get(child).set_mass(1)
15  pf.get(child).set_radius(1.0 + i / 18.77)
16  af.get(child).set_element(7)
17 
18 
19 def create_chain(nh, rf, af, pf):
20  for i in range(0, 60 * scale):
21  child = nh.add_child(str(i), RMF.REPRESENTATION)
22  rf.get(child).set_residue_type("cys")
23  rf.get(child).set_residue_index(i)
24  create_residue(child, af, pf)
25 
26 
27 def create_hierarchy(file):
28  cf = RMF.ChainFactory(file)
29  af = RMF.AtomFactory(file)
30  rf = RMF.ResidueFactory(file)
31  pf = RMF.ParticleFactory(file)
32  n = file.get_root_node()
33  for i in range(0, 3 * scale):
34  child = n.add_child(str(i), RMF.REPRESENTATION)
35  cf.get(child).set_chain_id(str(i))
36  create_chain(child, rf, af, pf)
37 
38 
39 def create_frame(fh, ipf, atoms, frame):
40  ret = [0.0, 0.0, 0.0]
41  for n in atoms:
42  v = RMF.Vector3((1.0 * n.get_index() + 0 + frame) / 17.0,
43  (1.0 * n.get_index() + 1 + frame) / 19.0,
44  (1.0 * n.get_index() + 2 + frame) / 23.0)
45  ret[0] += v[0]
46  ret[1] += v[1]
47  ret[2] += v[2]
48  ipf.get(fh.get_node(n)).set_coordinates(v)
49  return ret[0] + ret[1] + ret[2]
50 
51 
52 def create(file):
53  create_hierarchy(file)
54  atoms = []
55  for n in file.get_node_ids():
56  if len(file.get_node(n).get_children()) == 0:
57  atoms.append(n)
58  ipf = RMF.IntermediateParticleFactory(file)
59  ret = 0.0
60  for i in range(0, 20):
61  file.add_frame("frame", RMF.FRAME)
62  ret += create_frame(file, ipf, atoms, i)
63  return ret
64 
65 
66 def traverse(file):
67  ret = 0.0
68  queue = [file.get_root_node()]
69  ipcf = RMF.IntermediateParticleConstFactory(file)
70  while (len(queue) > 0):
71  cur = queue[-1]
72  queue = queue[:-1]
73 
74  if ipcf.get_is(cur):
75  ret += ipcf.get(cur).get_radius()
76  queue += cur.get_children()
77 
78  return ret
79 
80 
81 def load(file, nodes):
82  ipcf = RMF.IntermediateParticleConstFactory(file)
83  v = [0.0, 0.0, 0.0]
84  for fr in file.get_frames():
85  file.set_current_frame(fr)
86  for n in nodes:
87  cur = ipcf.get(file.get_node(n)).get_coordinates()
88  v[0] += cur[0]
89  v[1] += cur[1]
90  v[2] += cur[2]
91  return v[0] + v[1] + v[2]
92 
93 
94 def benchmark_create(file, type):
95  start = datetime.datetime.now()
96  dist = create(file)
97  print(type, "create,", datetime.datetime.now() - start, ",", dist)
98 
99 
100 def benchmark_traverse(file, type):
101  start = datetime.datetime.now()
102  file.set_current_frame(RMF.FrameID(0))
103  t = traverse(file)
104  print(type, "traverse,", datetime.datetime.now() - start, ",", t)
105 
106 
107 def benchmark_load(file, type):
108  nodes = []
109  ipcf = RMF.IntermediateParticleConstFactory(file)
110  for n in file.get_node_ids():
111  if ipcf.get_is(file.get_node(n)):
112  nodes.append(n)
113  start = datetime.datetime.now()
114  dist = load(file, nodes)
115  print(type, "load,", datetime.datetime.now() - start, ",", dist)
116 
117 name = "benchmark_python.rmf"
118 fh = RMF.create_rmf_file(name)
119 benchmark_create(fh, " python rmf")
120 del fh
121 
123 benchmark_traverse(fh, "python rmf")
124 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.