Example #1
0
    def test_points_in_spheres(self):
        points = [[0, 0, 0], [2, 2, 2]]
        lattice = Lattice.cubic(3)
        center_points = [[1.5, 1.5, 1.5]]
        nns = get_points_in_spheres(all_coords=np.array(points),
                                    center_coords=np.array(center_points),
                                    r=3,
                                    pbc=False)[0]
        self.assertEqual(len(nns), 2)  # two neighbors
        sorted_nns = sorted(nns, key=lambda x: x[1])
        self.assertArrayAlmostEqual(sorted_nns[0][0], [2, 2, 2])
        self.assertArrayAlmostEqual(sorted_nns[1][0], [0, 0, 0])

        nns = get_points_in_spheres(all_coords=np.array(points),
                                    center_coords=np.array(center_points),
                                    r=3,
                                    pbc=True,
                                    lattice=lattice)[0]
        self.assertEqual(len(nns), 12)

        nns = get_points_in_spheres(all_coords=np.array(points),
                                    center_coords=np.array(center_points),
                                    r=3,
                                    pbc=[True, False, False],
                                    lattice=lattice)[0]
        self.assertEqual(len(nns), 4)
Example #2
0
    def test_points_in_spheres(self):
        points = [[0.0, 0.0, 0.0], [2.0, 2.0, 2.0]]
        lattice = Lattice.cubic(3)
        center_points = [[1.5, 1.5, 1.5]]
        nns = get_points_in_spheres(
            all_coords=np.array(points),
            center_coords=np.array(center_points),
            r=3,
            pbc=np.array([0, 0, 0], dtype=int),
            lattice=lattice,
            numerical_tol=1e-8,
        )
        self.assertEqual(len(nns[0]), 2)  # two neighbors

        nns = get_points_in_spheres(
            all_coords=np.array(points),
            center_coords=np.array(center_points),
            r=3,
            pbc=[1, 1, 1],
            lattice=lattice,
            numerical_tol=1e-8,
            return_fcoords=True,
        )
        self.assertEqual(len(nns[0]), 12)

        nns = get_points_in_spheres(
            all_coords=np.array(points),
            center_coords=np.array(center_points),
            r=3,
            pbc=np.array([True, False, False], dtype=int),
            lattice=lattice,
        )
        self.assertEqual(len(nns[0]), 4)