diff --git a/testsuite/MDAnalysisTests/lib/test_nsgrid.py b/testsuite/MDAnalysisTests/lib/test_nsgrid.py index 97a9aed2a45..87a2bc3c2d9 100644 --- a/testsuite/MDAnalysisTests/lib/test_nsgrid.py +++ b/testsuite/MDAnalysisTests/lib/test_nsgrid.py @@ -40,16 +40,18 @@ def universe(): u = mda.Universe(GRO) return u + def run_grid_search(u, ref_id, cutoff=3): coords = u.atoms.positions searchcoords = u.atoms.positions[ref_id] - if searchcoords.shape == (3, ): + if searchcoords.shape == (3,): searchcoords = searchcoords[None, :] # Run grid search searcher = nsgrid.FastNS(cutoff, coords, box=u.dimensions) return searcher.search(searchcoords) + @pytest.mark.parametrize('box', [ np.zeros(3), # Bad shape np.zeros((3, 3)), # Collapsed box @@ -66,7 +68,8 @@ def test_pbc_box(box): @pytest.mark.parametrize('cutoff, match', ((-4, "Cutoff must be positive"), - (100000, "Cutoff 100000 too large for box"))) + (100000, + "Cutoff 100000 too large for box"))) def test_nsgrid_badcutoff(universe, cutoff, match): with pytest.raises(ValueError, match=match): run_grid_search(universe, 0, cutoff) @@ -160,13 +163,16 @@ def test_nsgrid_distances(universe): @pytest.mark.parametrize('box, results', ((None, [3, 13, 24]), - (np.array([10000., 10000., 10000., 90., 90., 90.]), [3, 13, 24]), - (np.array([10., 10., 10., 90., 90., 90.]), [3, 13, 24, 39, 67]), - (np.array([10., 10., 10., 60., 75., 90.]), [3, 13, 24, 39, 60, 79]))) + (np.array([10000., 10000., 10000., 90., 90., 90.]), + [3, 13, 24]), + (np.array([10., 10., 10., 90., 90., 90.]), + [3, 13, 24, 39, 67]), + (np.array([10., 10., 10., 60., 75., 90.]), + [3, 13, 24, 39, 60, 79]))) def test_nsgrid_search(box, results): np.random.seed(90003) points = (np.random.uniform(low=0, high=1.0, - size=(100, 3))*(10.)).astype(np.float32) + size=(100, 3)) * (10.)).astype(np.float32) cutoff = 2.0 query = np.array([1., 1., 1.], dtype=np.float32).reshape((1, 3)) @@ -175,7 +181,7 @@ def test_nsgrid_search(box, results): all_coords = np.concatenate([points, query]) lmax = all_coords.max(axis=0) lmin = all_coords.min(axis=0) - pseudobox[:3] = 1.1*(lmax - lmin) + pseudobox[:3] = 1.1 * (lmax - lmin) pseudobox[3:] = 90. shiftpoints, shiftquery = points.copy(), query.copy() shiftpoints -= lmin @@ -197,7 +203,7 @@ def test_nsgrid_search(box, results): def test_nsgrid_selfsearch(box, result): np.random.seed(90003) points = (np.random.uniform(low=0, high=1.0, - size=(100, 3))*(10.)).astype(np.float32) + size=(100, 3)) * (10.)).astype(np.float32) cutoff = 1.0 if box is None or np.allclose(box[:3], 0): # create a pseudobox @@ -207,7 +213,7 @@ def test_nsgrid_selfsearch(box, result): pseudobox = np.zeros(6, dtype=np.float32) lmax = points.max(axis=0) lmin = points.min(axis=0) - pseudobox[:3] = 1.1*(lmax - lmin) + pseudobox[:3] = 1.1 * (lmax - lmin) pseudobox[3:] = 90. shiftref = points.copy() shiftref -= lmin @@ -219,6 +225,7 @@ def test_nsgrid_selfsearch(box, result): pairs = searchresults.get_pairs() assert_equal(len(pairs), result) + def test_nsgrid_probe_close_to_box_boundary(): # FastNS.search used to segfault with this box, cutoff and reference # coordinate prior to PR #2136, so we ensure that this remains fixed. @@ -265,7 +272,7 @@ def test_around_overlapping(): # check that around 0.0 catches when atoms *are* superimposed u = mda.Universe.empty(60, trajectory=True) xyz = np.zeros((60, 3)) - x = np.tile(np.arange(12), (5,))+np.repeat(np.arange(5)*100, 12) + x = np.tile(np.arange(12), (5,)) + np.repeat(np.arange(5) * 100, 12) # x is 5 images of 12 atoms xyz[:, 0] = x # y and z are 0