1
1
import MDAnalysis
2
+ import numpy as np
2
3
3
4
try :
4
5
from MDAnalysisTests .datafiles import DCD , PSF
14
15
class SimpleRmsBench (object ):
15
16
"""Benchmarks for MDAnalysis.analysis.rms.rmsd"""
16
17
17
- params = ([100 , 500 , 2000 ], [None , [ 1.0 , 0.5 ] ], [False , True ], [False , True ])
18
- param_names = ["num_atoms" , "weights " , "center" , "superposition" ]
18
+ params = ([100 , 500 , 2000 ], [True , False ], [False , True ], [False , True ])
19
+ param_names = ["num_atoms" , "use_weights " , "center" , "superposition" ]
19
20
20
- def setup (self , num_atoms , weights , center , superposition ):
21
+ def setup (self , num_atoms , use_weights , center , superposition ):
21
22
# mimic rmsd docstring example code
22
23
self .u = MDAnalysis .Universe (PSF , DCD )
23
24
# ag.positions is the new syntax
24
25
# but older commit hashes will need to use
25
26
# ag.coordinates()
26
- try :
27
- self .A = self .u .atoms .positions .copy ()[:num_atoms ]
28
- self .u .trajectory [- 1 ]
29
- self .B = self .u .atoms .positions .copy ()[:num_atoms ]
30
- except :
31
- self .A = self .u .atoms .positions .copy ()[:num_atoms ]
32
- self .u .trajectory [- 1 ]
33
- self .B = self .u .atoms .positions .copy ()[:num_atoms ]
27
+ self .A = self .u .atoms .positions .copy ()[:num_atoms ]
28
+ self .u .trajectory [- 1 ]
29
+ self .B = self .u .atoms .positions .copy ()[:num_atoms ]
30
+ self .atoms = self .u .atoms [:num_atoms ]
31
+ self .weights = self .atoms .masses / np .sum (self .atoms .masses ) if use_weights else None
34
32
35
33
def time_rmsd (self , num_atoms , weights , center , superposition ):
36
34
"""Benchmark rmsd function using a setup similar to
@@ -40,7 +38,7 @@ def time_rmsd(self, num_atoms, weights, center, superposition):
40
38
rms .rmsd (
41
39
a = self .A ,
42
40
b = self .B ,
43
- weights = weights ,
41
+ weights = self . weights ,
44
42
center = center ,
45
43
superposition = superposition ,
46
44
)
0 commit comments