def test_nsgrid_PBC_rect(): """Check that nsgrid works with rect boxes and PBC""" ref_id = 191 results = np.array( [191, 192, 672, 682, 683, 684, 995, 996, 2060, 2808, 3300, 3791, 3792] ) - 1 # Atomid are from gmx select so there start from 1 and not 0. hence -1! universe = mda.Universe(Martini_membrane_gro) cutoff = 7 # FastNS is called differently to max coverage searcher = nsgrid.FastNS(cutoff, universe.atoms.positions, box=universe.dimensions) results_grid = searcher.search( universe.atoms.positions[ref_id][None, :]).get_indices()[0] results_grid2 = searcher.search(universe.atoms.positions).get_indices( ) # call without specifying any ids, should do NS for all beads assert_equal(np.sort(results), np.sort(results_grid)) assert_equal(len(universe.atoms), len(results_grid2)) assert searcher.cutoff == 7 assert_equal(np.sort(results_grid), np.sort(results_grid2[ref_id]))
def run_grid_search(u, ref_id, cutoff=3): coords = u.atoms.positions searchcoords = u.atoms.positions[ref_id] if searchcoords.shape == (3, ): searchcoords = searchcoords[None, :] # Run grid search searcher = nsgrid.FastNS(cutoff, coords, box=u.dimensions) return searcher.search(searchcoords)
def test_fastns_warning(universe): """ Tests for warning on the use of FastNS. TODO: remove when nsgrid is fixed. """ wmsg = ("The current nsgrid code can return incorrect values and should " "not be used for production work.") with pytest.warns(UserWarning, match=wmsg): searcher = nsgrid.FastNS(3, universe.atoms.positions, universe.dimensions)
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) cutoff = 1.0 if box is None or np.allclose(box[:3], 0): # create a pseudobox # define the max range # and supply the pseudobox # along with only one set of coordinates 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:] = 90. shiftref = points.copy() shiftref -= lmin searcher = nsgrid.FastNS(cutoff, shiftref, box=pseudobox, pbc=False) searchresults = searcher.self_search() else: searcher = nsgrid.FastNS(cutoff, points, box=box) searchresults = searcher.self_search() pairs = searchresults.get_pairs() assert_equal(len(pairs), result)
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) cutoff = 2.0 query = np.array([1., 1., 1.], dtype=np.float32).reshape((1, 3)) if box is None: pseudobox = np.zeros(6, dtype=np.float32) 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:] = 90. shiftpoints, shiftquery = points.copy(), query.copy() shiftpoints -= lmin shiftquery -= lmin searcher = nsgrid.FastNS(cutoff, shiftpoints, box=pseudobox, pbc=False) searchresults = searcher.search(shiftquery) else: searcher = nsgrid.FastNS(cutoff, points, box) searchresults = searcher.search(query) indices = searchresults.get_pairs()[:, 1] assert_equal(np.sort(indices), results)
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. # See Issue #2132 for further information. ref = np.array([[55.783722, 44.190044, -54.16671]], dtype=np.float32) box = np.array([53.785854, 43.951054, 57.17597, 90., 90., 90.], dtype=np.float32) cutoff = 3.0 # search within a configuration where we know the expected outcome: conf = np.ones((1, 3), dtype=np.float32) searcher = nsgrid.FastNS(cutoff, conf, box) results = searcher.search(ref) # check if results are as expected: expected_pairs = np.zeros((1, 2), dtype=np.int64) expected_dists = np.array([2.3689647], dtype=np.float64) assert_equal(results.get_pairs(), expected_pairs) assert_allclose(results.get_pair_distances(), expected_dists, rtol=1.e-6)
def test_nsgrid_PBC_rect(): """Check that nsgrid works with rect boxes and PBC""" ref_id = 191 # Atomid are from gmx select so there start from 1 and not 0. hence -1! results = np.array([191, 192, 672, 682, 683, 684, 995, 996, 2060, 2808, 3300, 3791, 3792]) - 1 universe = mda.Universe(Martini_membrane_gro) cutoff = 7 # FastNS is called differently to max coverage searcher = nsgrid.FastNS(cutoff, universe.atoms.positions, box=universe.dimensions) results_grid = searcher.search(universe.atoms.positions[ref_id][None, :]).get_pairs() other_ix = sorted(i for (_, i) in results_grid) assert len(results) == len(results_grid) assert other_ix == sorted(results)
def test_pbc_box(box): """Check that PBC box accepts only well-formated boxes""" coords = np.array([[1.0, 1.0, 1.0]], dtype=np.float32) with pytest.raises(ValueError): nsgrid.FastNS(4.0, coords, box=box)