def setup_nl(self, L=10, rcut=3, N=40, num_neighbors=6): # Define values self.L = L self.rcut = rcut self.N = N self.num_neighbors = num_neighbors # Initialize Box and cell list self.cl = locality.NearestNeighbors(self.rcut, self.num_neighbors) self.fbox, self.points = make_box_and_random_points(L, N)
def test_single_neighbor(self): pos = np.zeros((10, 3), dtype=np.float32) pos[::2, 0] = 2 * np.arange(5) pos[1::2, 0] = pos[::2, 0] + .25 pos[:, 1] = pos[:, 0] pos[0] = (9, 7, 0) fbox = box.Box.square(L=4 * len(pos)) nn = locality.NearestNeighbors(1, 1).compute(fbox, pos, pos) nlist = nn.nlist self.assertEqual(len(nlist), len(pos))
def test_neighbor_count(self): L = 10 # Box Dimensions rcut = 3 # Cutoff radius N = 40 # number of particles num_neighbors = 6 # Initialize cell list cl = locality.NearestNeighbors(rcut, num_neighbors) fbox, points = make_box_and_random_points(L, N) cl.compute(fbox, points, points) self.assertEqual(cl.num_neighbors, num_neighbors) self.assertEqual(len(cl.getNeighbors(0)), num_neighbors)
def test_neighbor_count(self): L = 10 #Box Dimensions rcut = 3 #Cutoff radius N = 40 # number of particles num_neighbors = 6 fbox = box.Box.cube(L) #Initialize Box cl = locality.NearestNeighbors(rcut, num_neighbors) #Initialize cell list points = np.random.uniform(-L / 2, L / 2, (N, 3)).astype(np.float32) cl.compute(fbox, points, points) self.assertEqual(cl.getNumNeighbors(), num_neighbors) self.assertEqual(len(cl.getNeighbors(0)), num_neighbors)
def test_box_methods(self): L = 10 # Box Dimensions rcut = 3 # Cutoff radius N = 1 # number of particles num_neighbors = 6 # Initialize cell list cl = locality.NearestNeighbors(rcut, num_neighbors) fbox, points = make_box_and_random_points(L, N) cl.compute([L, L, L], points, points) self.assertEqual(cl.box, fbox) npt.assert_array_equal(cl.r_sq_list, [[-1, -1, -1, -1, -1, -1]]) npt.assert_array_equal(cl.wrapped_vectors, [[[-1, -1, -1], [-1, -1, -1], [-1, -1, -1], [-1, -1, -1], [-1, -1, -1], [-1, -1, -1]]])
def test_small_box(self): L = 10 # Box Dimensions N = 8 # number of particles num_neighbors = N - 1 fbox, pos = make_box_and_random_points(L, N) for box_cell_count in range(2, 8): rcut = L / box_cell_count / 1.0001 # Initialize cell list cl = locality.NearestNeighbors(rcut, num_neighbors) nlist = cl.compute(fbox, pos, pos).nlist # all particles should be all particles' neighbors if len(nlist) != N * (N - 1): raise AssertionError( 'Wrong-sized neighbor list in test_even_cells,' 'box_cell_count={}'.format(box_cell_count))
def test_repeated_neighbors(self): L = 10 # Box Dimensions N = 40 # number of particles num_neighbors = 6 fbox, pos = make_box_and_random_points(L, N) for rcut in np.random.uniform(L / 2, L / 5, 128): # Initialize cell list cl = locality.NearestNeighbors(rcut, num_neighbors) nlist = cl.compute(fbox, pos, pos).nlist all_pairs = list(set(zip(nlist.index_i, nlist.index_j))) if len(all_pairs) != len(nlist): raise AssertionError( 'Repeated neighbor pair sizes in test_repeated_neighbors, ' 'rcut={}'.format(rcut))
def test_strict_vals(self): L = 10 # Box Dimensions rcut = 2 # Cutoff radius num_neighbors = 1 # Initialize Box and cell list fbox = box.Box.cube(L) cl = locality.NearestNeighbors(rcut, num_neighbors, strict_cut=True) points = np.zeros(shape=(2, 3), dtype=np.float32) points[0] = [0.0, 0.0, 0.0] points[1] = [3.0, 0.0, 0.0] cl.compute(fbox, points, points) neighbor_list = cl.getNeighborList() rsq_list = cl.r_sq_list npt.assert_equal(neighbor_list[0, 0], cl.UINTMAX) npt.assert_equal(neighbor_list[1, 0], cl.UINTMAX) npt.assert_allclose(rsq_list[0, 0], -1.0, atol=1e-6) npt.assert_allclose(rsq_list[1, 0], -1.0, atol=1e-6)
def __init__(self, system, groups, log, activation_energy, sec_bond_weight): Bonding.__init__(self, system=system, groups=groups, log=log, activation_energy=activation_energy, sec_bond_weight=sec_bond_weight) # create freud nearest neighbor object # set number of neighbors self.n_neigh = 6 # create freud nearest neighbors object self.nn = locality.NearestNeighbors(rmax=self.cut_off_dist, n_neigh=self.n_neigh, strict_cut=True) snapshot = self.system.take_snapshot() self.fbox = box.Box(Lx=snapshot.box.Lx, Ly=snapshot.box.Ly, Lz=snapshot.box.Lz)
def test_two_ways(self): L = 10 # Box Dimensions rcut = 3 # Cutoff radius N = 40 # number of particles num_neighbors = 6 # Initialize cell list cl = locality.NearestNeighbors(rcut, num_neighbors) fbox, points = make_box_and_random_points(L, N) cl.compute(fbox, points, points) neighbor_list = cl.getNeighborList() rsq_list = cl.r_sq_list # pick particle at random pidx = np.random.randint(N) nidx = np.random.randint(num_neighbors) npt.assert_equal(neighbor_list[pidx, nidx], cl.getNeighbors(pidx)[nidx]) npt.assert_equal(rsq_list[pidx, nidx], cl.getRsq(pidx)[nidx])
def test_strict_vals(self): L = 10 #Box Dimensions rcut = 2 #Cutoff radius N = 2 # number of particles num_neighbors = 1 fbox = box.Box.cube(L) #Initialize Box cl = locality.NearestNeighbors(rcut, num_neighbors, strict_cut=True) #Initialize cell list points = np.zeros(shape=(2, 3), dtype=np.float32) points[0] = [0.0, 0.0, 0.0] points[1] = [3.0, 0.0, 0.0] cl.compute(fbox, points, points) neighbor_list = cl.getNeighborList() rsq_list = cl.getRsqList() npt.assert_equal(neighbor_list[0, 0], cl.getUINTMAX()) npt.assert_equal(neighbor_list[1, 0], cl.getUINTMAX()) npt.assert_equal(rsq_list[0, 0], -1.0) npt.assert_equal(rsq_list[1, 0], -1.0)
def test_two_ways(self): L = 10 #Box Dimensions rcut = 3 #Cutoff radius N = 40 # number of particles num_neighbors = 6 fbox = box.Box.cube(L) #Initialize Box cl = locality.NearestNeighbors(rcut, num_neighbors) #Initialize cell list points = np.random.uniform(-L / 2, L / 2, (N, 3)).astype(np.float32) cl.compute(fbox, points, points) neighbor_list = cl.getNeighborList() rsq_list = cl.getRsqList() # pick particle at random pidx = np.random.randint(N) nidx = np.random.randint(num_neighbors) npt.assert_equal(neighbor_list[pidx, nidx], cl.getNeighbors(pidx)[nidx]) npt.assert_equal(rsq_list[pidx, nidx], cl.getRsq(pidx)[nidx])
def test_cheap_hexatic(self): """Construct a poor man's hexatic order parameter using NeighborList properties""" fbox = box.Box.square(10) # make a square grid xs = np.linspace(-fbox.Lx / 2, fbox.Lx / 2, 10, endpoint=False) positions = np.zeros((len(xs)**2, 3), dtype=np.float32) positions[:, :2] = np.array(list(itertools.product(xs, xs)), dtype=np.float32) nn = locality.NearestNeighbors(1.5, 4) nn.compute(fbox, positions, positions) rijs = positions[nn.nlist.index_j] - positions[nn.nlist.index_i] fbox.wrap(rijs) thetas = np.arctan2(rijs[:, 1], rijs[:, 0]) cplx = np.exp(4 * 1j * thetas) psi4 = np.add.reduceat(cplx, nn.nlist.segments) / nn.nlist.neighbor_counts self.assertEqual(len(psi4), len(positions)) self.assertTrue(np.allclose(np.abs(psi4), 1))