2
2
import numpy as np
3
3
4
4
try :
5
- from MDAnalysisTests .datafiles import (GRO , TPR , XTC ,
6
- PSF , DCD ,
7
- TRZ_psf , TRZ )
8
5
from MDAnalysis .exceptions import NoDataError
6
+ from MDAnalysisTests .datafiles import DCD , GRO , PSF , TPR , TRZ , XTC , TRZ_psf
9
7
except :
10
8
pass
11
9
10
+
12
11
class AtomGroupMethodsBench (object ):
13
12
"""Benchmarks for the various MDAnalysis
14
13
atomgroup methods.
15
14
"""
15
+
16
16
# NOTE: the write() method has been
17
17
# excluded as file writing is considered
18
18
# a separate benchmarking category
19
19
20
20
params = (10 , 100 , 1000 , 10000 )
21
- param_names = [' num_atoms' ]
21
+ param_names = [" num_atoms" ]
22
22
23
23
def setup (self , num_atoms ):
24
24
self .u = MDAnalysis .Universe (GRO )
25
25
self .ag = self .u .atoms [:num_atoms ]
26
26
self .weights = np .ones (num_atoms )
27
- self .vdwradii = {'H' :1.0 ,
28
- 'C' :1.0 ,
29
- 'N' :1.0 ,
30
- 'O' :1.0 ,
31
- 'DUMMY' :1.0 }
32
- self .rot_matrix = np .ones ((3 ,3 ))
33
- self .trans = np .ones ((4 ,4 ))
27
+ self .vdwradii = {"H" : 1.0 , "C" : 1.0 , "N" : 1.0 , "O" : 1.0 , "DUMMY" : 1.0 }
28
+ self .rot_matrix = np .ones ((3 , 3 ))
29
+ self .trans = np .ones ((4 , 4 ))
34
30
35
31
def time_bbox_pbc (self , num_atoms ):
36
32
"""Benchmark bounding box calculation
@@ -60,15 +56,13 @@ def time_center_pbc(self, num_atoms):
60
56
"""Benchmark center calculation with
61
57
pbc active.
62
58
"""
63
- self .ag .center (weights = self .weights ,
64
- pbc = True )
59
+ self .ag .center (weights = self .weights , pbc = True )
65
60
66
61
def time_center_no_pbc (self , num_atoms ):
67
62
"""Benchmark center calculation with
68
63
pbc inactive.
69
64
"""
70
- self .ag .center (weights = self .weights ,
71
- pbc = False )
65
+ self .ag .center (weights = self .weights , pbc = False )
72
66
73
67
def time_centroid_pbc (self , num_atoms ):
74
68
"""Benchmark centroid calculation with
@@ -83,8 +77,7 @@ def time_centroid_no_pbc(self, num_atoms):
83
77
self .ag .centroid (pbc = False )
84
78
85
79
def time_concatenate (self , num_atoms ):
86
- """Benchmark atomgroup concatenation.
87
- """
80
+ """Benchmark atomgroup concatenation."""
88
81
self .ag .concatenate (self .ag )
89
82
90
83
def time_difference (self , num_atoms ):
@@ -97,7 +90,7 @@ def time_groupby(self, num_atoms):
97
90
"""Benchmark atomgroup groupby
98
91
operation.
99
92
"""
100
- self .ag .groupby (' resnames' )
93
+ self .ag .groupby (" resnames" )
101
94
102
95
def time_guess_bonds (self , num_atoms ):
103
96
"""Benchmark atomgroup bond guessing
@@ -106,18 +99,15 @@ def time_guess_bonds(self, num_atoms):
106
99
self .ag .guess_bonds (self .vdwradii )
107
100
108
101
def time_intersection (self , num_atoms ):
109
- """Benchmark ag intersection.
110
- """
102
+ """Benchmark ag intersection."""
111
103
self .ag .intersection (self .ag )
112
104
113
105
def time_is_strict_subset (self , num_atoms ):
114
- """Benchmark ag strict subset operation.
115
- """
106
+ """Benchmark ag strict subset operation."""
116
107
self .ag .is_strict_subset (self .ag )
117
108
118
109
def time_is_strict_superset (self , num_atoms ):
119
- """Benchmark ag strict superset operation.
120
- """
110
+ """Benchmark ag strict superset operation."""
121
111
self .ag .is_strict_superset (self .ag )
122
112
123
113
def time_isdisjoint (self , num_atoms ):
@@ -155,19 +145,17 @@ def time_rotateby(self, num_atoms):
155
145
"""Benchmark rotation by an angle
156
146
of the ag coordinates.
157
147
"""
158
- self .ag .rotateby (angle = 45 ,
159
- axis = [1 ,0 ,0 ])
148
+ self .ag .rotateby (angle = 45 , axis = [1 , 0 , 0 ])
160
149
161
150
def time_split (self , num_atoms ):
162
151
"""Benchmark ag splitting into
163
152
multiple ags based on a simple
164
153
criterion.
165
154
"""
166
- self .ag .split (' residue' )
155
+ self .ag .split (" residue" )
167
156
168
157
def time_subtract (self , num_atoms ):
169
- """Benchmark ag subtraction.
170
- """
158
+ """Benchmark ag subtraction."""
171
159
self .ag .subtract (self .ag )
172
160
173
161
def time_symmetric_difference (self , num_atoms ):
@@ -187,7 +175,7 @@ def time_translate(self, num_atoms):
187
175
translation vector to the ag
188
176
coordinates.
189
177
"""
190
- self .ag .translate ([0 ,0.5 ,1 ])
178
+ self .ag .translate ([0 , 0.5 , 1 ])
191
179
192
180
def time_union (self , num_atoms ):
193
181
"""Benchmark union operation
@@ -202,14 +190,13 @@ def time_wrap(self, num_atoms):
202
190
self .ag .wrap ()
203
191
204
192
205
-
206
193
class AtomGroupAttrsBench (object ):
207
194
"""Benchmarks for the various MDAnalysis
208
195
atomgroup attributes.
209
196
"""
210
197
211
198
params = (10 , 100 , 1000 , 10000 )
212
- param_names = [' num_atoms' ]
199
+ param_names = [" num_atoms" ]
213
200
214
201
def setup (self , num_atoms ):
215
202
self .u = MDAnalysis .Universe (GRO )
@@ -235,7 +222,7 @@ def time_dihedral(self, num_atoms):
235
222
"""
236
223
self .ag [:4 ].dihedral
237
224
238
- #TODO: use universe / ag that
225
+ # TODO: use universe / ag that
239
226
# is suitable for force calc
240
227
def time_forces (self , num_atoms ):
241
228
"""Benchmark atomgroup force
@@ -246,7 +233,7 @@ def time_forces(self, num_atoms):
246
233
except NoDataError :
247
234
pass
248
235
249
- #TODO: use universe / ag that
236
+ # TODO: use universe / ag that
250
237
# is suitable for velocity extraction
251
238
def time_velocity (self , num_atoms ):
252
239
"""Benchmark atomgroup velocity
@@ -265,8 +252,7 @@ def time_improper(self, num_atoms):
265
252
self .ag [:4 ].improper
266
253
267
254
def time_indices (self , num_atoms ):
268
- """Benchmark atom index calculation.
269
- """
255
+ """Benchmark atom index calculation."""
270
256
self .ag .ix
271
257
272
258
def time_atomcount (self , num_atoms ):
@@ -326,15 +312,17 @@ def time_bond(self, num_atoms):
326
312
327
313
class CompoundSplitting (object ):
328
314
"""Test how fast can we split compounds into masks and apply them
329
-
315
+
330
316
The benchmark used in Issue #3000. Parameterizes multiple compound number
331
317
and size combinations.
332
318
"""
333
-
334
- params = [(100 , 10000 , 1000000 ), # n_atoms
335
- (1 , 10 , 100 ), # n_compounds
336
- (True , False ), # homogeneous
337
- (True , False )] # contiguous
319
+
320
+ params = [
321
+ (100 , 10000 , 1000000 ), # n_atoms
322
+ (1 , 10 , 100 ), # n_compounds
323
+ (True , False ), # homogeneous
324
+ (True , False ),
325
+ ] # contiguous
338
326
339
327
def setup (self , n_atoms , n_compounds , homogeneous , contiguous ):
340
328
rg = np .random .Generator (np .random .MT19937 (3000 ))
@@ -345,7 +333,7 @@ def setup(self, n_atoms, n_compounds, homogeneous, contiguous):
345
333
346
334
if n_compounds == 1 and not (homogeneous and contiguous ):
347
335
raise NotImplementedError
348
-
336
+
349
337
if n_compounds == n_atoms :
350
338
if not (homogeneous and contiguous ):
351
339
raise NotImplementedError
@@ -354,51 +342,56 @@ def setup(self, n_atoms, n_compounds, homogeneous, contiguous):
354
342
ats_per_compound , remainder = divmod (n_atoms , n_compounds )
355
343
if remainder :
356
344
raise NotImplementedError
357
- compound_indices = np .tile (np .arange (n_compounds ),
358
- (ats_per_compound , 1 )).T .ravel ()
345
+ compound_indices = np .tile (
346
+ np .arange (n_compounds ), (ats_per_compound , 1 )
347
+ ).T .ravel ()
359
348
else :
360
- compound_indices = np .sort (np .floor (rg .random (n_atoms )
361
- * n_compounds ).astype (np .int ))
362
-
349
+ compound_indices = np .sort (
350
+ np .floor (rg .random (n_atoms ) * n_compounds ).astype (np .int )
351
+ )
352
+
363
353
unique_indices = np .unique (compound_indices )
364
354
if len (unique_indices ) != n_compounds :
365
355
raise RuntimeError
366
-
356
+
367
357
if not contiguous :
368
358
rg .shuffle (compound_indices )
369
-
370
- self .u = MDAnalysis .Universe .empty (n_atoms ,
371
- n_residues = n_compounds ,
372
- n_segments = 1 ,
373
- atom_resindex = compound_indices ,
374
- trajectory = True )
375
- self .u .atoms .positions = rg .random ((n_atoms , 3 ),
376
- dtype = np .float32 ) * 100
359
+
360
+ self .u = MDAnalysis .Universe .empty (
361
+ n_atoms ,
362
+ n_residues = n_compounds ,
363
+ n_segments = 1 ,
364
+ atom_resindex = compound_indices ,
365
+ trajectory = True ,
366
+ )
367
+ self .u .atoms .positions = rg .random ((n_atoms , 3 ), dtype = np .float32 ) * 100
377
368
self .u .dimensions = [50 , 50 , 50 , 90 , 90 , 90 ]
378
369
379
370
def time_center_compounds (self , * args ):
380
- self .u .atoms .center (None , compound = ' residues' )
371
+ self .u .atoms .center (None , compound = " residues" )
381
372
382
373
383
374
class FragmentFinding (object ):
384
375
"""Test how quickly we find fragments (distinct molecules from bonds)"""
376
+
385
377
# if we try to parametrize over topology &
386
378
# trajectory formats asv will use all
387
379
# possible combinations, so instead handle
388
380
# this in setup()
389
- params = ('large_fragment_small_solvents' ,
390
- 'large_fragment' ,
391
- 'polymer_chains' , # 20ish polymer chains
392
- )
393
- param_names = ['universe_type' ]
381
+ params = (
382
+ "large_fragment_small_solvents" ,
383
+ "large_fragment" ,
384
+ "polymer_chains" , # 20ish polymer chains
385
+ )
386
+ param_names = ["universe_type" ]
394
387
395
388
def setup (self , universe_type ):
396
- if universe_type == ' large_fragment_small_solvents' :
397
- univ = (TPR , XTC )
398
- elif universe_type == ' large_fragment' :
389
+ if universe_type == " large_fragment_small_solvents" :
390
+ univ = (TPR , XTC )
391
+ elif universe_type == " large_fragment" :
399
392
univ = (PSF , DCD )
400
393
else :
401
- univ = (TRZ_psf , TRZ )
394
+ univ = (TRZ_psf , TRZ )
402
395
self .u = MDAnalysis .Universe (* univ )
403
396
404
397
def time_find_fragments (self , universe_type ):
@@ -407,6 +400,7 @@ def time_find_fragments(self, universe_type):
407
400
408
401
class FragmentCaching (FragmentFinding ):
409
402
"""Test how quickly we find cached fragments"""
403
+
410
404
def setup (self , universe_type ):
411
405
super (FragmentCaching , self ).setup (universe_type )
412
406
frags = self .u .atoms .fragments # Priming the cache
0 commit comments