예제 #1
0
 def test_get_localgrid_1s1s(self):
     """Test local grid for a molecule with one atom."""
     nums = np.array([1, 3])
     coords = np.array([[0.0, 0.0, -0.5], [0.0, 0.0, 0.5]])
     grid = MolGrid.from_size(
         nums, coords, self.rgrid, 110, BeckeWeights(), store=True, rotate=False
     )
     fn0 = np.exp(-4.0 * np.linalg.norm(grid.points - coords[0], axis=-1))
     fn1 = np.exp(-8.0 * np.linalg.norm(grid.points - coords[1], axis=-1))
     assert_allclose(grid.integrate(fn0), np.pi / 8, rtol=1e-5)
     assert_allclose(grid.integrate(fn1), np.pi / 64)
     # local grid centered on atom 0 to evaluate fn0
     local0 = grid.get_localgrid(coords[0], 5.0)
     assert local0.size < grid.size
     localfn0 = np.exp(-4.0 * np.linalg.norm(local0.points - coords[0], axis=-1))
     assert_allclose(fn0[local0.indices], localfn0)
     assert_allclose(local0.integrate(localfn0), np.pi / 8, rtol=1e-5)
     # local grid centered on atom 1 to evaluate fn1
     local1 = grid.get_localgrid(coords[1], 2.5)
     assert local1.size < grid.size
     localfn1 = np.exp(-8.0 * np.linalg.norm(local1.points - coords[1], axis=-1))
     assert_allclose(local1.integrate(localfn1), np.pi / 64, rtol=1e-6)
     assert_allclose(fn1[local1.indices], localfn1)
     # approximate the sum of fn0 and fn2 by combining results from local grids.
     fnsum = np.zeros(grid.size)
     fnsum[local0.indices] += localfn0
     fnsum[local1.indices] += localfn1
     assert_allclose(grid.integrate(fnsum), np.pi * (1 / 8 + 1 / 64), rtol=1e-5)
예제 #2
0
 def test_from_size(self):
     """Test horton style grid."""
     nums = np.array([1, 1])
     coors = np.array([[0, 0, -0.5], [0, 0, 0.5]])
     becke = BeckeWeights(order=3)
     mol_grid = MolGrid.from_size(nums,
                                  coors,
                                  self.rgrid,
                                  110,
                                  becke,
                                  rotate=False)
     atg1 = AtomGrid.from_pruned(
         self.rgrid,
         0.5,
         sectors_r=np.array([]),
         sectors_degree=np.array([17]),
         center=coors[0],
     )
     atg2 = AtomGrid.from_pruned(
         self.rgrid,
         0.5,
         sectors_r=np.array([]),
         sectors_degree=np.array([17]),
         center=coors[1],
     )
     ref_grid = MolGrid(nums, [atg1, atg2], becke, store=True)
     assert_allclose(ref_grid.points, mol_grid.points)
     assert_allclose(ref_grid.weights, mol_grid.weights)
예제 #3
0
    def test_get_localgrid_1s(self):
        """Test local grid for a molecule with one atom."""
        nums = np.array([1])
        coords = np.array([0.0, 0.0, 0.0])

        # initialize MolGrid with atomic grid
        atg1 = AtomGrid.from_pruned(
            self.rgrid,
            0.5,
            sectors_r=np.array([]),
            sectors_degree=np.array([17]),
            center=coords,
        )
        grid = MolGrid(np.array([1]), [atg1], BeckeWeights(), store=False)
        fn = np.exp(-2 * np.linalg.norm(grid.points, axis=-1))
        assert_allclose(grid.integrate(fn), np.pi)
        # conventional local grid
        localgrid = grid.get_localgrid(coords, 12.0)
        localfn = np.exp(-2 * np.linalg.norm(localgrid.points, axis=-1))
        assert localgrid.size < grid.size
        assert localgrid.size == 10560
        assert_allclose(localgrid.integrate(localfn), np.pi)
        assert_allclose(fn[localgrid.indices], localfn)
        # "whole" loal grid, useful for debugging code using local grids
        wholegrid = grid.get_localgrid(coords, np.inf)
        assert wholegrid.size == grid.size
        assert_allclose(wholegrid.points, grid.points)
        assert_allclose(wholegrid.weights, grid.weights)
        assert_allclose(wholegrid.indices, np.arange(grid.size))

        # initialize MolGrid like horton
        grid = MolGrid.from_size(nums,
                                 coords[np.newaxis, :],
                                 self.rgrid,
                                 110,
                                 BeckeWeights(),
                                 store=True)
        fn = np.exp(-4.0 * np.linalg.norm(grid.points, axis=-1))
        assert_allclose(grid.integrate(fn), np.pi / 8)
        localgrid = grid.get_localgrid(coords, 5.0)
        localfn = np.exp(-4.0 * np.linalg.norm(localgrid.points, axis=-1))
        assert localgrid.size < grid.size
        assert localgrid.size == 9900
        assert_allclose(localgrid.integrate(localfn), np.pi / 8, rtol=1e-5)
        assert_allclose(fn[localgrid.indices], localfn)