Skip to content

Commit

Permalink
Pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Boyd committed Oct 26, 2021
1 parent 736f4cf commit 6506201
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions testsuite/MDAnalysisTests/lib/test_nsgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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))

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6506201

Please sign in to comment.