@@ -230,12 +230,20 @@ def universe(self):
230
230
231
231
232
232
class TestDensityAnalysis (DensityParameters ):
233
- def check_DensityAnalysis (self , ag , ref_meandensity ,
234
- tmpdir , runargs = None , ** kwargs ):
233
+ def check_DensityAnalysis (
234
+ self ,
235
+ ag ,
236
+ ref_meandensity ,
237
+ tmpdir ,
238
+ client_DensityAnalysis ,
239
+ runargs = None ,
240
+ ** kwargs
241
+ ):
235
242
runargs = runargs if runargs else {}
236
243
with tmpdir .as_cwd ():
237
- D = density .DensityAnalysis (
238
- ag , delta = self .delta , ** kwargs ).run (** runargs )
244
+ D = density .DensityAnalysis (ag , delta = self .delta , ** kwargs ).run (
245
+ ** runargs , ** client_DensityAnalysis
246
+ )
239
247
assert_almost_equal (D .results .density .grid .mean (), ref_meandensity ,
240
248
err_msg = "mean density does not match" )
241
249
D .results .density .export (self .outfile )
@@ -247,125 +255,176 @@ def check_DensityAnalysis(self, ag, ref_meandensity,
247
255
)
248
256
249
257
@pytest .mark .parametrize ("mode" , ("static" , "dynamic" ))
250
- def test_run (self , mode , universe , tmpdir ):
258
+ def test_run (self , mode , universe , tmpdir , client_DensityAnalysis ):
251
259
updating = (mode == "dynamic" )
252
260
self .check_DensityAnalysis (
253
261
universe .select_atoms (self .selections [mode ], updating = updating ),
254
262
self .references [mode ]['meandensity' ],
255
- tmpdir = tmpdir
263
+ tmpdir = tmpdir ,
264
+ client_DensityAnalysis = client_DensityAnalysis ,
256
265
)
257
266
258
- def test_sliced (self , universe , tmpdir ):
267
+ def test_sliced (self , universe , tmpdir , client_DensityAnalysis ):
259
268
self .check_DensityAnalysis (
260
269
universe .select_atoms (self .selections ['static' ]),
261
270
self .references ['static_sliced' ]['meandensity' ],
262
271
tmpdir = tmpdir ,
272
+ client_DensityAnalysis = client_DensityAnalysis ,
263
273
runargs = dict (start = 1 , stop = - 1 , step = 2 ),
264
274
)
265
275
266
- def test_userdefn_eqbox (self , universe , tmpdir ):
276
+ def test_userdefn_eqbox (self , universe , tmpdir , client_DensityAnalysis ):
267
277
with warnings .catch_warnings ():
268
278
# Do not need to see UserWarning that box is too small
269
279
warnings .simplefilter ("ignore" )
270
280
self .check_DensityAnalysis (
271
281
universe .select_atoms (self .selections ['static' ]),
272
282
self .references ['static_defined' ]['meandensity' ],
273
283
tmpdir = tmpdir ,
284
+ client_DensityAnalysis = client_DensityAnalysis ,
274
285
gridcenter = self .gridcenters ['static_defined' ],
275
286
xdim = 10.0 ,
276
287
ydim = 10.0 ,
277
288
zdim = 10.0 ,
278
289
)
279
290
280
- def test_userdefn_neqbox (self , universe , tmpdir ):
291
+ def test_userdefn_neqbox (self , universe , tmpdir , client_DensityAnalysis ):
281
292
self .check_DensityAnalysis (
282
293
universe .select_atoms (self .selections ['static' ]),
283
294
self .references ['static_defined_unequal' ]['meandensity' ],
284
295
tmpdir = tmpdir ,
296
+ client_DensityAnalysis = client_DensityAnalysis ,
285
297
gridcenter = self .gridcenters ['static_defined' ],
286
298
xdim = 10.0 ,
287
299
ydim = 15.0 ,
288
300
zdim = 20.0 ,
289
301
)
290
302
291
- def test_userdefn_boxshape (self , universe ):
303
+ def test_userdefn_boxshape (self , universe , client_DensityAnalysis ):
292
304
D = density .DensityAnalysis (
293
- universe .select_atoms (self .selections ['static' ]),
294
- delta = 1.0 , xdim = 8.0 , ydim = 12.0 , zdim = 17.0 ,
295
- gridcenter = self .gridcenters ['static_defined' ]).run ()
305
+ universe .select_atoms (self .selections ["static" ]),
306
+ delta = 1.0 ,
307
+ xdim = 8.0 ,
308
+ ydim = 12.0 ,
309
+ zdim = 17.0 ,
310
+ gridcenter = self .gridcenters ["static_defined" ],
311
+ ).run (** client_DensityAnalysis )
296
312
assert D .results .density .grid .shape == (8 , 12 , 17 )
297
313
298
- def test_warn_userdefn_padding (self , universe ):
314
+ def test_warn_userdefn_padding (self , universe , client_DensityAnalysis ):
299
315
regex = (r"Box padding \(currently set at 1\.0\) is not used "
300
316
r"in user defined grids\." )
301
317
with pytest .warns (UserWarning , match = regex ):
302
318
D = density .DensityAnalysis (
303
- universe .select_atoms (self .selections ['static' ]),
304
- delta = self .delta , xdim = 100.0 , ydim = 100.0 , zdim = 100.0 , padding = 1.0 ,
305
- gridcenter = self .gridcenters ['static_defined' ]).run (step = 5 )
306
-
307
- def test_warn_userdefn_smallgrid (self , universe ):
319
+ universe .select_atoms (self .selections ["static" ]),
320
+ delta = self .delta ,
321
+ xdim = 100.0 ,
322
+ ydim = 100.0 ,
323
+ zdim = 100.0 ,
324
+ padding = 1.0 ,
325
+ gridcenter = self .gridcenters ["static_defined" ],
326
+ ).run (step = 5 , ** client_DensityAnalysis )
327
+
328
+ def test_warn_userdefn_smallgrid (self , universe , client_DensityAnalysis ):
308
329
regex = ("Atom selection does not fit grid --- "
309
330
"you may want to define a larger box" )
310
331
with pytest .warns (UserWarning , match = regex ):
311
332
D = density .DensityAnalysis (
312
- universe .select_atoms (self .selections ['static' ]),
313
- delta = self .delta , xdim = 1.0 , ydim = 2.0 , zdim = 2.0 , padding = 0.0 ,
314
- gridcenter = self .gridcenters ['static_defined' ]).run (step = 5 )
315
-
316
- def test_ValueError_userdefn_gridcenter_shape (self , universe ):
333
+ universe .select_atoms (self .selections ["static" ]),
334
+ delta = self .delta ,
335
+ xdim = 1.0 ,
336
+ ydim = 2.0 ,
337
+ zdim = 2.0 ,
338
+ padding = 0.0 ,
339
+ gridcenter = self .gridcenters ["static_defined" ],
340
+ ).run (step = 5 , ** client_DensityAnalysis )
341
+
342
+ def test_ValueError_userdefn_gridcenter_shape (
343
+ self , universe , client_DensityAnalysis
344
+ ):
317
345
# Test len(gridcenter) != 3
318
346
with pytest .raises (ValueError , match = "Gridcenter must be a 3D coordinate" ):
319
347
D = density .DensityAnalysis (
320
- universe .select_atoms (self .selections ['static' ]),
321
- delta = self .delta , xdim = 10.0 , ydim = 10.0 , zdim = 10.0 ,
322
- gridcenter = self .gridcenters ['error1' ]).run (step = 5 )
348
+ universe .select_atoms (self .selections ["static" ]),
349
+ delta = self .delta ,
350
+ xdim = 10.0 ,
351
+ ydim = 10.0 ,
352
+ zdim = 10.0 ,
353
+ gridcenter = self .gridcenters ["error1" ],
354
+ ).run (step = 5 , ** client_DensityAnalysis )
323
355
324
- def test_ValueError_userdefn_gridcenter_type (self , universe ):
356
+ def test_ValueError_userdefn_gridcenter_type (
357
+ self , universe , client_DensityAnalysis
358
+ ):
325
359
# Test gridcenter includes non-numeric strings
326
360
with pytest .raises (ValueError , match = "Gridcenter must be a 3D coordinate" ):
327
361
D = density .DensityAnalysis (
328
- universe .select_atoms (self .selections ['static' ]),
329
- delta = self .delta , xdim = 10.0 , ydim = 10.0 , zdim = 10.0 ,
330
- gridcenter = self .gridcenters ['error2' ]).run (step = 5 )
362
+ universe .select_atoms (self .selections ["static" ]),
363
+ delta = self .delta ,
364
+ xdim = 10.0 ,
365
+ ydim = 10.0 ,
366
+ zdim = 10.0 ,
367
+ gridcenter = self .gridcenters ["error2" ],
368
+ ).run (step = 5 , ** client_DensityAnalysis )
331
369
332
- def test_ValueError_userdefn_gridcenter_missing (self , universe ):
370
+ def test_ValueError_userdefn_gridcenter_missing (
371
+ self , universe , client_DensityAnalysis
372
+ ):
333
373
# Test no gridcenter provided when grid dimensions are given
334
374
regex = ("Gridcenter or grid dimensions are not provided" )
335
375
with pytest .raises (ValueError , match = regex ):
336
376
D = density .DensityAnalysis (
337
- universe .select_atoms (self .selections ['static' ]),
338
- delta = self .delta , xdim = 10.0 , ydim = 10.0 , zdim = 10.0 ).run (step = 5 )
377
+ universe .select_atoms (self .selections ["static" ]),
378
+ delta = self .delta ,
379
+ xdim = 10.0 ,
380
+ ydim = 10.0 ,
381
+ zdim = 10.0 ,
382
+ ).run (step = 5 , ** client_DensityAnalysis )
339
383
340
- def test_ValueError_userdefn_xdim_type (self , universe ):
384
+ def test_ValueError_userdefn_xdim_type (self , universe ,
385
+ client_DensityAnalysis ):
341
386
# Test xdim != int or float
342
387
with pytest .raises (ValueError , match = "xdim, ydim, and zdim must be numbers" ):
343
388
D = density .DensityAnalysis (
344
- universe .select_atoms (self .selections ['static' ]),
345
- delta = self .delta , xdim = "MDAnalysis" , ydim = 10.0 , zdim = 10.0 ,
346
- gridcenter = self .gridcenters ['static_defined' ]).run (step = 5 )
389
+ universe .select_atoms (self .selections ["static" ]),
390
+ delta = self .delta ,
391
+ xdim = "MDAnalysis" ,
392
+ ydim = 10.0 ,
393
+ zdim = 10.0 ,
394
+ gridcenter = self .gridcenters ["static_defined" ],
395
+ ).run (step = 5 , ** client_DensityAnalysis )
347
396
348
- def test_ValueError_userdefn_xdim_nanvalue (self , universe ):
397
+ def test_ValueError_userdefn_xdim_nanvalue (self , universe ,
398
+ client_DensityAnalysis ):
349
399
# Test xdim set to NaN value
350
400
regex = ("Gridcenter or grid dimensions have NaN element" )
351
401
with pytest .raises (ValueError , match = regex ):
352
402
D = density .DensityAnalysis (
353
- universe .select_atoms (self .selections ['static' ]),
354
- delta = self .delta , xdim = np .nan , ydim = 10.0 , zdim = 10.0 ,
355
- gridcenter = self .gridcenters ['static_defined' ]).run (step = 5 )
403
+ universe .select_atoms (self .selections ["static" ]),
404
+ delta = self .delta ,
405
+ xdim = np .nan ,
406
+ ydim = 10.0 ,
407
+ zdim = 10.0 ,
408
+ gridcenter = self .gridcenters ["static_defined" ],
409
+ ).run (step = 5 , ** client_DensityAnalysis )
356
410
357
- def test_warn_noatomgroup (self , universe ):
411
+ def test_warn_noatomgroup (self , universe , client_DensityAnalysis ):
358
412
regex = ("No atoms in AtomGroup at input time frame. "
359
413
"This may be intended; please ensure that "
360
414
"your grid selection covers the atomic "
361
415
"positions you wish to capture." )
362
416
with pytest .warns (UserWarning , match = regex ):
363
417
D = density .DensityAnalysis (
364
- universe .select_atoms (self .selections ['none' ]),
365
- delta = self .delta , xdim = 1.0 , ydim = 2.0 , zdim = 2.0 , padding = 0.0 ,
366
- gridcenter = self .gridcenters ['static_defined' ]).run (step = 5 )
367
-
368
- def test_ValueError_noatomgroup (self , universe ):
418
+ universe .select_atoms (self .selections ["none" ]),
419
+ delta = self .delta ,
420
+ xdim = 1.0 ,
421
+ ydim = 2.0 ,
422
+ zdim = 2.0 ,
423
+ padding = 0.0 ,
424
+ gridcenter = self .gridcenters ["static_defined" ],
425
+ ).run (step = 5 , ** client_DensityAnalysis )
426
+
427
+ def test_ValueError_noatomgroup (self , universe , client_DensityAnalysis ):
369
428
with pytest .raises (ValueError , match = "No atoms in AtomGroup at input"
370
429
" time frame. Grid for density"
371
430
" could not be automatically"
@@ -374,12 +433,13 @@ def test_ValueError_noatomgroup(self, universe):
374
433
" defined grid will "
375
434
"need to be provided instead." ):
376
435
D = density .DensityAnalysis (
377
- universe .select_atoms (self .selections ['none' ])).run (step = 5 )
436
+ universe .select_atoms (self .selections ["none" ])
437
+ ).run (step = 5 , ** client_DensityAnalysis )
378
438
379
- def test_warn_results_deprecated (self , universe ):
439
+ def test_warn_results_deprecated (self , universe , client_DensityAnalysis ):
380
440
D = density .DensityAnalysis (
381
441
universe .select_atoms (self .selections ['static' ]))
382
- D .run (stop = 1 )
442
+ D .run (stop = 1 , ** client_DensityAnalysis )
383
443
wmsg = "The `density` attribute was deprecated in MDAnalysis 2.0.0"
384
444
with pytest .warns (DeprecationWarning , match = wmsg ):
385
445
assert_equal (D .density .grid , D .results .density .grid )
0 commit comments