def test_identical_environments_Wl_near(self): (box, positions) = util.make_fcc(4, 4, 4) # Use a really small cutoff to ensure that it is used as a soft cutoff comp = freud.order.Steinhardt(0.1, 6, num_neigh=12, Wl=True) comp.compute(box, positions) npt.assert_allclose(np.real(np.average(comp.order)), PERFECT_FCC_W6, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(np.real(comp.norm), PERFECT_FCC_W6, delta=1e-5) comp = freud.order.Steinhardt(1.5, 6, num_neigh=12, Wl=True, average=True) comp.compute(box, positions) npt.assert_allclose(np.real(np.average(comp.order)), PERFECT_FCC_W6, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(np.real(comp.norm), PERFECT_FCC_W6, delta=1e-5) self.assertEqual(len(positions), comp.num_particles)
def test_attribute_access(self): (box, positions) = util.make_fcc(4, 4, 4) func_names = ["compute", "computeSolLiqVariant", "computeSolLiqNoNorm"] for f in func_names: comp = freud.order.SolLiq(box, 2, .7, 6, 6) with self.assertRaises(AttributeError): comp.largest_cluster_size with self.assertRaises(AttributeError): comp.cluster_sizes with self.assertRaises(AttributeError): comp.Ql_mi with self.assertRaises(AttributeError): comp.clusters with self.assertRaises(AttributeError): comp.num_connections with self.assertRaises(AttributeError): comp.Ql_dot_ij with self.assertRaises(AttributeError): comp.num_particles func = getattr(comp, f) func(positions) comp.largest_cluster_size comp.cluster_sizes comp.Ql_mi comp.clusters comp.num_connections comp.Ql_dot_ij comp.num_particles
def test_cluster_keys(self): Nlattice = 4 Nrep = 5 np.random.seed(0) positions = [] for _ in range(Nrep): (box, pos) = util.make_fcc(Nlattice, Nlattice, Nlattice, noise=1e-2) positions.append(pos) # number of grid points (N = Nrep*Ngrid) Ngrid = positions[-1].shape[0] positions = np.array(positions).reshape((-1, 3)) clust = freud.cluster.Cluster(box, 0.5) clust.computeClusters(positions, box=box) # Test protected attribute access with self.assertRaises(AttributeError): clust.cluster_keys clust.computeClusterMembership(np.array(range(Nrep * Ngrid))) # Test if attributes are accessible now clust.cluster_keys self.assertEqual(len(clust.cluster_keys), Ngrid) ckeys = np.array(clust.cluster_keys) % Ngrid check_values = np.arange(Ngrid)[:, np.newaxis].repeat(Nrep, axis=1) self.assertTrue(np.all(ckeys == check_values))
def test_identical_environments_Ql_near(self): (box, positions) = util.make_fcc(4, 4, 4) # Perturb one position perturbed_positions = positions.copy() perturbed_positions[-1] += [0.1, 0, 0] # Use a really small cutoff to ensure that it is used as a soft cutoff comp = freud.order.Steinhardt(0.1, 6, num_neigh=12) comp.compute(box, positions) npt.assert_allclose(np.average(comp.order), PERFECT_FCC_Q6, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(comp.norm, PERFECT_FCC_Q6, delta=1e-5) # Ensure exactly 13 values change for the perturbed system comp.compute(box, perturbed_positions) self.assertEqual(sum(~np.isclose(comp.Ql, PERFECT_FCC_Q6, rtol=1e-6)), 13) comp = freud.order.Steinhardt(1.5, 6, num_neigh=12, average=True) comp.compute(box, positions) npt.assert_allclose(np.average(comp.order), PERFECT_FCC_Q6, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(comp.norm, PERFECT_FCC_Q6, delta=1e-5) # More than 13 particles should change for Ql averaged over neighbors comp.compute(box, perturbed_positions) self.assertGreater( sum(~np.isclose(comp.order, PERFECT_FCC_Q6, rtol=1e-6)), 13)
def test_voronoi_weights_fcc(self): # Test that voronoi neighbor weights are computed properly for 3D FCC L = 3 box, positions = util.make_fcc(nx=L, ny=L, nz=L) rbuf = np.max(box.L) / 2 vor = freud.locality._Voronoi() vor.compute(box, positions, rbuf, False) nlist = vor.nlist # Drop the tiny facets that come from numerical imprecision nlist = nlist.filter(nlist.weights > 1e-5) unique_indices, counts = np.unique(nlist.index_i, return_counts=True) # Every FCC particle should have 12 neighbors npt.assert_equal(counts, np.full(len(unique_indices), 12)) # Every facet area should be sqrt(2)/2 npt.assert_allclose(nlist.weights, np.full(len(nlist.weights), 0.5 * np.sqrt(2)), atol=1e-5) # Every cell should have volume 2 vor.compute(box, positions) npt.assert_allclose(vor.compute(box, positions, rbuf, False).volumes, np.full(len(vor.polytopes), 2.), atol=1e-5)
def test_identical_environments(self): (box, positions) = util.make_fcc(4, 4, 4) # Use a really small cutoff to ensure that it is used as a soft cutoff comp = freud.order.LocalWlNear(box, 0.1, 6, 12) with self.assertRaises(AttributeError): comp.num_particles with self.assertRaises(AttributeError): comp.Wl with self.assertRaises(AttributeError): comp.ave_Wl with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.compute(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.Wl, comp.Wl[0])) with self.assertRaises(AttributeError): comp.ave_Wl with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeAve(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.ave_Wl, comp.ave_Wl[0])) with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeNorm(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.norm_Wl, comp.norm_Wl[0])) with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeAveNorm(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.ave_norm_Wl, comp.ave_norm_Wl[0])) self.assertEqual(box, comp.box) self.assertEqual(len(positions), comp.num_particles)
def bench_setup(self, N): n = N np.random.seed(0) (self.box, self.positions) = util.make_fcc(n, n, n) self.random_quats = np.random.rand(len(self.positions), 4) self.random_quats /= np.linalg.norm(self.random_quats, axis=1)[:, np.newaxis] self.bo = freud.environment.BondOrder(self.rmax, self.k, self.num_neighbors, self.n_bins_t, self.n_bins_p)
def test_identical_environments(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.LocalWl(box, 1.5, 6) with self.assertRaises(AttributeError): comp.num_particles with self.assertRaises(AttributeError): comp.Wl with self.assertRaises(AttributeError): comp.ave_Wl with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.compute(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), -0.0026260, atol=1e-5)) self.assertTrue(np.allclose(comp.Wl, comp.Wl[0])) with self.assertRaises(AttributeError): comp.ave_Wl with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeAve(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), -0.0026260, atol=1e-5)) self.assertTrue(np.allclose(comp.ave_Wl, comp.ave_Wl[0])) with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeNorm(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), -0.0026260, atol=1e-5)) self.assertTrue(np.allclose(comp.norm_Wl, comp.norm_Wl[0])) with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeAveNorm(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), -0.0026260, atol=1e-5)) self.assertTrue(np.allclose(comp.ave_norm_Wl, comp.ave_norm_Wl[0])) self.assertEqual(box, comp.box) self.assertEqual(len(positions), comp.num_particles)
def test_identical_environments(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.LocalQl(box, 1.5, 6) with self.assertRaises(AttributeError): comp.num_particles with self.assertRaises(AttributeError): comp.Ql with self.assertRaises(AttributeError): comp.ave_Ql with self.assertRaises(AttributeError): comp.norm_Ql with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.compute(positions) npt.assert_allclose(np.average(comp.Ql), 0.57452422, rtol=1e-6) npt.assert_allclose(comp.Ql, comp.Ql[0], rtol=1e-6) with self.assertRaises(AttributeError): comp.ave_Ql with self.assertRaises(AttributeError): comp.norm_Ql with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.computeAve(positions) npt.assert_allclose(np.average(comp.Ql), 0.57452422, rtol=1e-6) npt.assert_allclose(comp.ave_Ql, comp.ave_Ql[0], rtol=1e-6) with self.assertRaises(AttributeError): comp.norm_Ql with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.computeNorm(positions) npt.assert_allclose(np.average(comp.Ql), 0.57452422, rtol=1e-6) npt.assert_allclose(comp.norm_Ql, comp.norm_Ql[0], rtol=1e-6) with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.computeAveNorm(positions) npt.assert_allclose(np.average(comp.Ql), 0.57452422, rtol=1e-6) npt.assert_allclose(comp.ave_norm_Ql, comp.ave_norm_Ql[0], rtol=1e-6) self.assertEqual(box, comp.box) self.assertEqual(len(positions), comp.num_particles)
def test_identical_environments_Ql_near(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.Steinhardt(1.5, 6, num_neigh=12) comp.compute(box, positions) npt.assert_allclose(np.average(comp.order), 0.57452422, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(comp.norm, 0.57452422, delta=1e-5) comp = freud.order.Steinhardt(1.5, 6, num_neigh=12, average=True) comp.compute(box, positions) npt.assert_allclose(np.average(comp.order), 0.57452422, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(comp.norm, 0.57452422, delta=1e-5)
def test_identical_environments_Ql(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.Steinhardt(1.5, 6) comp.compute(box, positions) npt.assert_allclose(np.average(comp.order), PERFECT_FCC_Q6, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(comp.norm, PERFECT_FCC_Q6, delta=1e-5) comp = freud.order.Steinhardt(1.5, 6, average=True) comp.compute(box, positions) npt.assert_allclose(np.average(comp.order), PERFECT_FCC_Q6, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(comp.norm, PERFECT_FCC_Q6, delta=1e-5)
def test_identical_environments(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.SolLiqNear(box, 2, .7, 6, 6, 12) comp.compute(positions) self.assertTrue(np.allclose(comp.largest_cluster_size, len(positions))) self.assertEqual(len(comp.cluster_sizes), 1) comp.computeSolLiqNoNorm(positions) self.assertTrue(np.allclose(comp.largest_cluster_size, len(positions))) self.assertEqual(len(comp.cluster_sizes), 1) comp.computeSolLiqVariant(positions) self.assertEqual(comp.largest_cluster_size, 1)
def test_filter_r(self): """Test that nlists are filtered to the correct rmax.""" np.random.seed(0) (box, positions) = util.make_fcc(4, 4, 4, noise=1e-2) index = np.random.randint(0, len(positions)) point = positions[index].reshape((1, 3)) others = np.concatenate([positions[:index], positions[index + 1:]]) # Creates a neighborlist with rmax larger than the interface rmax lc = freud.locality.LinkCell(box, 3.0).compute(box, others, point) inter = freud.interface.InterfaceMeasure(1.5) test_twelve = inter.compute(box, others, point, lc.nlist) self.assertEqual(test_twelve.ref_point_count, 12) self.assertEqual(len(test_twelve.ref_point_ids), 12)
def test_identical_environments_Wl(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.Steinhardt(1.5, 6, Wl=True) comp.compute(box, positions) npt.assert_allclose(np.real(np.average(comp.order)), -0.002626035, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(np.real(comp.norm), -0.002626035, delta=1e-5) comp = freud.order.Steinhardt(1.5, 6, Wl=True, average=True) comp.compute(box, positions) npt.assert_allclose(np.real(np.average(comp.order)), -0.002626035, atol=1e-5) npt.assert_allclose(comp.order, comp.order[0], atol=1e-5) self.assertAlmostEqual(np.real(comp.norm), -0.002626035, delta=1e-5) self.assertEqual(len(positions), comp.num_particles)
def test_repr_png(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.LocalQl(box, 1.5, 6) with self.assertRaises(AttributeError): comp.plot(mode="Ql") with self.assertRaises(AttributeError): comp.plot(mode="ave_Ql") with self.assertRaises(AttributeError): comp.plot(mode="ave_norm_Ql") with self.assertRaises(AttributeError): comp.plot(mode="norm_Ql") self.assertEqual(comp._repr_png_(), None) comp.compute(positions) comp.plot(mode="Ql") comp.computeAve(positions) comp.plot(mode="ave_Ql") comp.computeAveNorm(positions) comp.plot(mode="ave_norm_Ql") comp.computeNorm(positions) comp.plot(mode="norm_Ql")
def test_take_one(self): """Test that there is exactly 1 or 12 particles at the interface when one particle is removed from an FCC structure""" np.random.seed(0) (box, positions) = util.make_fcc(4, 4, 4, noise=1e-2) positions.flags['WRITEABLE'] = False index = np.random.randint(0, len(positions)) point = positions[index].reshape((1, 3)) others = np.concatenate([positions[:index], positions[index + 1:]]) inter = freud.interface.InterfaceMeasure(1.5) # Test attribute access with self.assertRaises(AttributeError): inter.ref_point_count with self.assertRaises(AttributeError): inter.ref_point_ids with self.assertRaises(AttributeError): inter.point_count with self.assertRaises(AttributeError): inter.point_ids test_one = inter.compute(box, point, others) # Test attribute access inter.ref_point_count inter.ref_point_ids inter.point_count inter.point_ids self.assertEqual(test_one.ref_point_count, 1) self.assertEqual(len(test_one.ref_point_ids), 1) test_twelve = inter.compute(box, others, point) self.assertEqual(test_twelve.ref_point_count, 12) self.assertEqual(len(test_twelve.ref_point_ids), 12)
def test_identical_environments(self): (box, positions) = util.make_fcc(4, 4, 4) comp = freud.order.LocalWl(box, 1.5, 6) with self.assertRaises(AttributeError): comp.num_particles with self.assertRaises(AttributeError): comp.Wl with self.assertRaises(AttributeError): comp.ave_Wl with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.compute(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.Wl, comp.Wl[0])) with self.assertRaises(AttributeError): comp.ave_Wl with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeAve(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.ave_Wl, comp.ave_Wl[0])) # Perturb one position to ensure exactly 13 particles' values change perturbed_positions = positions.copy() perturbed_positions[-1] += [0.1, 0, 0] comp.computeAve(perturbed_positions) self.assertEqual( sum(~np.isclose(np.real(comp.Wl), PERFECT_FCC_W6, rtol=1e-6)), 13) # More than 13 particles should change for Wl averaged over neighbors self.assertGreater( sum(~np.isclose(np.real(comp.ave_Wl), PERFECT_FCC_W6, rtol=1e-6)), 13) with self.assertRaises(AttributeError): comp.norm_Wl with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeNorm(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.norm_Wl, comp.norm_Wl[0])) with self.assertRaises(AttributeError): comp.ave_norm_Wl comp.computeAveNorm(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Wl)), PERFECT_FCC_W6, atol=1e-5)) self.assertTrue(np.allclose(comp.ave_norm_Wl, comp.ave_norm_Wl[0])) self.assertEqual(box, comp.box) self.assertEqual(len(positions), comp.num_particles)
def test_cluster_props(self): Nlattice = 4 Nrep = 5 np.random.seed(0) positions = [] for _ in range(Nrep): (box, pos) = util.make_fcc(Nlattice, Nlattice, Nlattice, noise=1e-2) positions.append(pos) # number of grid points (N = Nrep*Ngrid) Ngrid = positions[-1].shape[0] positions = np.array(positions).reshape((-1, 3)) # Test box access clust = freud.cluster.Cluster(box, 0.5) self.assertEqual(clust.box, box) # Test protected attribute access with self.assertRaises(AttributeError): clust.num_clusters with self.assertRaises(AttributeError): clust.num_particles with self.assertRaises(AttributeError): clust.cluster_idx # Test with explicit box provided clust.computeClusters(positions, box=box) # Test if attributes are accessible now clust.num_clusters clust.num_particles clust.cluster_idx # Test all property APIs props = freud.cluster.ClusterProperties(box) # Test protected attribute access with self.assertRaises(AttributeError): props.num_clusters with self.assertRaises(AttributeError): props.cluster_COM with self.assertRaises(AttributeError): props.cluster_G with self.assertRaises(AttributeError): props.cluster_sizes props.computeProperties(positions, clust.cluster_idx, box=box) # Test if attributes are accessible now props.num_clusters props.cluster_COM props.cluster_G props.cluster_sizes self.assertEqual(props.num_clusters, Ngrid) self.assertTrue(np.all(props.cluster_sizes == Nrep)) # Test without explicit box provided clust.computeClusters(positions) props = freud.cluster.ClusterProperties(box) props.computeProperties(positions, clust.cluster_idx, box=box) self.assertEqual(props.num_clusters, Ngrid) self.assertTrue(np.all(props.cluster_sizes == Nrep))
def test_bond_order(self): """Test the bond order diagram calculation.""" (box, positions) = util.make_fcc(4, 4, 4) quats = np.zeros((len(positions), 4), dtype=np.float32) quats[:, 0] = 1 r_cut = 1.5 num_neighbors = 12 npt = npp = 6 bo = freud.environment.BondOrder(r_cut, 0, num_neighbors, npt, npp) # Test access with self.assertRaises(AttributeError): bo.box with self.assertRaises(AttributeError): bo.bond_order # Test that there are exactly 12 non-zero bins for a perfect FCC # structure. bo.compute(box, positions, quats, positions, quats) op_value = bo.bond_order.copy() self.assertEqual(np.sum(op_value > 0), 12) # Test access bo.box bo.bond_order # Test all the basic attributes. self.assertEqual(bo.n_bins_theta, npt) self.assertEqual(bo.n_bins_phi, npp) self.assertEqual(bo.box, box) self.assertTrue(np.allclose( bo.theta, np.array([(2*i+1)*np.pi/6 for i in range(npt)]))) self.assertTrue(np.allclose( bo.phi, np.array([(2*i+1)*np.pi/12 for i in range(npp)]))) # Test that reset works. bo.reset() # Test access with self.assertRaises(AttributeError): bo.box with self.assertRaises(AttributeError): bo.bond_order # Test that lbod gives identical results when orientations are the # same. #TODO: Find a way to test a rotated system to ensure that lbod gives # noqa # the desired results. bo.accumulate(box, positions, quats, positions, quats, mode='lbod') self.assertTrue(np.allclose(bo.bond_order, op_value)) # Test access bo.box bo.bond_order # Test that obcd gives identical results when orientations are the # same. bo.compute(box, positions, quats, positions, quats, mode='obcd') self.assertTrue(np.allclose(bo.bond_order, op_value)) # Test that normal bod looks ordered for randomized orientations. np.random.seed(10893) random_quats = np.random.rand(len(positions), 4) random_quats /= np.linalg.norm(random_quats, axis=1)[:, np.newaxis] bo.compute(box, positions, random_quats, positions, random_quats) self.assertTrue(np.allclose(bo.bond_order, op_value)) # Ensure that obcd looks random for the randomized orientations. bo.compute(box, positions, random_quats, positions, random_quats, mode='obcd') self.assertTrue(not np.allclose(bo.bond_order, op_value)) self.assertEqual(np.sum(bo.bond_order > 0), bo.bond_order.size) # Test that oocd shows exactly one peak when all orientations are the # same. bo.reset() bo.accumulate(box, positions, quats, positions, quats, mode='oocd') self.assertEqual(np.sum(bo.bond_order > 0), 1) self.assertTrue(bo.bond_order[0, 0] > 0) # Test that oocd is highly disordered with random quaternions. In # practice, the edge bins may still not get any values, so just check # that we get a lot of values. bo.compute(box, positions, random_quats, positions, random_quats, mode='oocd') self.assertGreater(np.sum(bo.bond_order > 0), 30)
def test_identical_environments(self): (box, positions) = util.make_fcc(4, 4, 4) # Use a really small rcut to ensure that it is used as a soft cutoff comp = freud.order.LocalQlNear(box, 0.1, 6, 12) with self.assertRaises(AttributeError): comp.num_particles with self.assertRaises(AttributeError): comp.Ql with self.assertRaises(AttributeError): comp.ave_Ql with self.assertRaises(AttributeError): comp.norm_Ql with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.compute(positions) npt.assert_allclose(np.average(comp.Ql), PERFECT_FCC_Q6, rtol=1e-6) npt.assert_allclose(comp.Ql, comp.Ql[0], rtol=1e-6) with self.assertRaises(AttributeError): comp.ave_Ql with self.assertRaises(AttributeError): comp.norm_Ql with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.computeAve(positions) self.assertTrue( np.isclose(np.real(np.average(comp.Ql)), PERFECT_FCC_Q6, atol=1e-5)) self.assertTrue(np.allclose(comp.ave_Ql, comp.ave_Ql[0])) # Perturb one position to ensure exactly 13 particles' values change perturbed_positions = positions.copy() perturbed_positions[-1] += [0.1, 0, 0] comp.computeAve(perturbed_positions) self.assertEqual(sum(~np.isclose(comp.Ql, PERFECT_FCC_Q6, rtol=1e-6)), 13) # More than 13 particles should change for Ql averaged over neighbors self.assertGreater( sum(~np.isclose(comp.ave_Ql, PERFECT_FCC_Q6, rtol=1e-6)), 13) with self.assertRaises(AttributeError): comp.norm_Ql with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.computeNorm(positions) npt.assert_allclose(np.average(comp.Ql), PERFECT_FCC_Q6, rtol=1e-6) npt.assert_allclose(comp.norm_Ql, comp.norm_Ql[0], rtol=1e-6) with self.assertRaises(AttributeError): comp.ave_norm_Ql comp.computeAveNorm(positions) npt.assert_allclose(np.average(comp.Ql), PERFECT_FCC_Q6, rtol=1e-6) npt.assert_allclose(comp.ave_norm_Ql, comp.ave_norm_Ql[0], rtol=1e-6) self.assertEqual(box, comp.box) self.assertEqual(len(positions), comp.num_particles)