Exemplo n.º 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.horton_molgrid(coords,
                                   nums,
                                   self.rgrid,
                                   110,
                                   BeckeWeights(),
                                   store=True)
     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)
Exemplo n.º 2
0
 def test_horton_molgrid(self):
     """Test horton style grid."""
     coors = np.array([[0, 0, -0.5], [0, 0, 0.5]])
     nums = [1, 1]
     mol_grid = MolGrid.horton_molgrid(coors, nums, self.rgrid, 110)
     atg1 = AtomicGrid.special_init(
         self.rgrid, 0.5, scales=np.array([]), degs=np.array([17]), center=coors[0]
     )
     atg2 = AtomicGrid.special_init(
         self.rgrid, 0.5, scales=np.array([]), degs=np.array([17]), center=coors[1]
     )
     ref_grid = MolGrid([atg1, atg2], nums, store=True)
     assert_allclose(ref_grid.points, mol_grid.points)
     assert_allclose(ref_grid.weights, mol_grid.weights)
Exemplo n.º 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,
                                    r_sectors=np.array([]),
                                    degs=np.array([17]),
                                    center=coords)
        grid = MolGrid([atg1], BeckeWeights(), np.array([1]), 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.horton_molgrid(coords[np.newaxis, :],
                                      nums,
                                      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)
Exemplo n.º 4
0
 def test_horton_molgrid(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.horton_molgrid(coors, nums, self.rgrid, 110, becke)
     atg1 = AtomGrid.from_pruned(
         self.rgrid,
         0.5,
         r_sectors=np.array([]),
         degs=np.array([17]),
         center=coors[0],
     )
     atg2 = AtomGrid.from_pruned(
         self.rgrid,
         0.5,
         r_sectors=np.array([]),
         degs=np.array([17]),
         center=coors[1],
     )
     ref_grid = MolGrid([atg1, atg2], becke, nums, store=True)
     assert_allclose(ref_grid.points, mol_grid.points)
     assert_allclose(ref_grid.weights, mol_grid.weights)