|
21 | 21 | # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
|
22 | 22 | #
|
23 | 23 |
|
| 24 | +from distutils.util import strtobool |
| 25 | +import os |
| 26 | + |
24 | 27 | import pytest
|
25 | 28 |
|
26 | 29 | from collections import defaultdict, Counter
|
@@ -65,9 +68,11 @@ def test_pbc_box(box):
|
65 | 68 | nsgrid.FastNS(4.0, coords, box=box)
|
66 | 69 |
|
67 | 70 |
|
68 |
| -@pytest.mark.parametrize('cutoff', [-4, 100000]) |
69 |
| -def test_nsgrid_badcutoff(universe, cutoff): |
70 |
| - with pytest.raises(ValueError): |
| 71 | +@pytest.mark.parametrize('cutoff, match', ((-4, "Cutoff must be positive"), |
| 72 | + (100000, |
| 73 | + "Cutoff 100000 too large for box"))) |
| 74 | +def test_nsgrid_badcutoff(universe, cutoff, match): |
| 75 | + with pytest.raises(ValueError, match=match): |
71 | 76 | run_grid_search(universe, 0, cutoff)
|
72 | 77 |
|
73 | 78 |
|
@@ -371,3 +376,36 @@ def test_issue_2670():
|
371 | 376 |
|
372 | 377 | # should return the one atom overlap
|
373 | 378 | assert len(ag2.select_atoms('around 0.0 resid 3')) == 1
|
| 379 | + |
| 380 | + |
| 381 | +def high_mem_tests_enabled(): |
| 382 | + """ Returns true if ENABLE_HIGH_MEM_UNIT_TESTS is set to true.""" |
| 383 | + env = os.getenv("ENABLE_HIGH_MEM_UNIT_TESTS", default="0") |
| 384 | + try: |
| 385 | + return strtobool(env) |
| 386 | + except ValueError: |
| 387 | + return False |
| 388 | + |
| 389 | + |
| 390 | +reason = ("Turned off by default. The test can be enabled by setting " |
| 391 | + "the ENABLE_HIGH_MEM_UNIT_TESTS " |
| 392 | + "environment variable. Make sure you have at least 10GB of RAM.") |
| 393 | + |
| 394 | + |
| 395 | +# Tests that with a tiny cutoff to box ratio, the number of grids is capped |
| 396 | +# to avoid indexing overflow. Expected results copied from test_nsgrid_search |
| 397 | +# with no box. |
| 398 | +@pytest.mark.skipif(not high_mem_tests_enabled(), reason=reason) |
| 399 | +def test_issue_3183(): |
| 400 | + np.random.seed(90003) |
| 401 | + points = (np.random.uniform(low=0, high=1.0, |
| 402 | + size=(100, 3)) * (10.)).astype(np.float32) |
| 403 | + cutoff = 2.0 |
| 404 | + query = np.array([1., 1., 1.], dtype=np.float32).reshape((1, 3)) |
| 405 | + box = np.array([10000., 10000., 10000., 90., 90., 90.]) |
| 406 | + |
| 407 | + searcher = nsgrid.FastNS(cutoff, points, box) |
| 408 | + searchresults = searcher.search(query) |
| 409 | + indices = searchresults.get_pairs()[:, 1] |
| 410 | + want_results = [3, 13, 24] |
| 411 | + assert_equal(np.sort(indices), want_results) |
0 commit comments