Пример #1
0
 def test_spherical_complete(self):
     """Test atomic grid consistence for spherical integral."""
     num_pts = len(LEBEDEV_DEGREES)
     pts = UniformInteger(num_pts)
     for _ in range(10):
         start = np.random.rand() * 1e-5
         end = np.random.rand() * 10 + 10
         tf = PowerRTransform(start, end)
         rad_grid = tf.transform_1d_grid(pts)
         atgrid = AtomGrid(rad_grid, degrees=list(LEBEDEV_DEGREES.keys()))
         values = np.random.rand(len(LEBEDEV_DEGREES))
         pt_val = np.zeros(atgrid.size)
         for index, value in enumerate(values):
             pt_val[atgrid._indices[index]:atgrid._indices[index +
                                                           1]] = value
             rad_int_val = (value * rad_grid.weights[index] * 4 * np.pi *
                            rad_grid.points[index]**2)
             atgrid_int_val = np.sum(
                 pt_val[atgrid._indices[index]:atgrid._indices[index + 1]] *
                 atgrid.weights[atgrid._indices[index]:atgrid.
                                _indices[index + 1]])
             assert_almost_equal(rad_int_val, atgrid_int_val)
         ref_int_at = atgrid.integrate(pt_val)
         ref_int_rad = rad_grid.integrate(4 * np.pi * rad_grid.points**2 *
                                          values)
         assert_almost_equal(ref_int_at, ref_int_rad)
Пример #2
0
def test_integrate_gauss():
    """Test radial grid integral."""
    oned = UniformInteger(100)
    rtf = PowerRTransform(0.0005, 1e1)
    grid = rtf.transform_1d_grid(oned)
    assert isinstance(grid, OneDGrid)

    y = np.exp(-0.5 * grid.points ** 2)
    # time 4 \pi and r^2 to accommodate old horton test
    grid._weights = grid.weights * 4 * np.pi * grid.points ** 2
    assert_almost_equal(grid.integrate(y), (2 * np.pi) ** 1.5)
Пример #3
0
def test_basics2():
    """Test basic radial grid transform properties for bigger grid."""
    oned = UniformInteger(100)
    rtf = ExpRTransform(1e-3, 1e1)
    grid = rtf.transform_1d_grid(oned)
    assert isinstance(grid, OneDGrid)

    assert grid.size == 100
    # assert grid.shape == (100,)
    # assert grid.rtransform == rtf
    assert (grid.weights > 0).all()
    assert (grid.points == rtf.transform(oned.points)).all()
Пример #4
0
def test_basics1():
    """Test basic radial grid transform properties."""
    oned = UniformInteger(4)
    rtf = ExpRTransform(0.1, 1e1)
    grid = rtf.transform_1d_grid(oned)
    assert isinstance(grid, OneDGrid)

    assert grid.size == 4
    # assert grid.shape == (4,)
    # assert grid.rtransform == rtf
    assert (grid.weights > 0).all()
    assert (grid.points == rtf.transform(oned.points)).all()
Пример #5
0
 def test_domain(self):
     """Test domain errors."""
     rad = UniformInteger(10)
     with self.assertRaises(ValueError):
         tf = BeckeRTransform(0.1, 1.2)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = HandyModRTransform(0.1, 10.0, 2)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = KnowlesRTransform(0.1, 1.2, 2)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = LinearFiniteRTransform(0.1, 10)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = MultiExpRTransform(0.1, 1.2)
         tf.transform_1d_grid(rad)
Пример #6
0
 def test_integrate_hirshfeld_weights_single_1s(self):
     """Test molecular integral in H atom with Hirshfeld weights."""
     pts = UniformInteger(100)
     tf = ExpRTransform(1e-5, 2e1)
     rgrid = tf.transform_1d_grid(pts)
     coordinates = np.array([0.0, 0.0, -0.5])
     atg1 = AtomGrid.from_pruned(
         rgrid,
         0.5,
         sectors_r=np.array([]),
         sectors_degree=np.array([17]),
         center=coordinates,
     )
     mg = MolGrid(np.array([7]), [atg1], HirshfeldWeights())
     dist0 = np.sqrt(((coordinates - mg.points)**2).sum(axis=1))
     fn = np.exp(-2 * dist0) / np.pi
     occupation = mg.integrate(fn)
     assert_almost_equal(occupation, 1.0, decimal=6)
Пример #7
0
 def test_errors_raise(self):
     """Test errors raise."""
     with self.assertRaises(ValueError):
         GaussLaguerre(10, -1)
     with self.assertRaises(ValueError):
         GaussLaguerre(0, 1)
     with self.assertRaises(ValueError):
         GaussLegendre(-10)
     with self.assertRaises(ValueError):
         GaussChebyshev(-10)
     with self.assertRaises(ValueError):
         UniformInteger(-10)
     with self.assertRaises(ValueError):
         TanhSinh(10, 1)
     with self.assertRaises(ValueError):
         Simpson(4)
     with self.assertRaises(ValueError):
         GaussChebyshevType2(-10)
     with self.assertRaises(ValueError):
         GaussChebyshevLobatto(-10)
     with self.assertRaises(ValueError):
         Trapezoidal(-10)
     with self.assertRaises(ValueError):
         RectangleRuleSineEndPoints(-10)
     with self.assertRaises(ValueError):
         RectangleRuleSine(-10)
     with self.assertRaises(ValueError):
         TanhSinh(-11, 1)
     with self.assertRaises(ValueError):
         Simpson(-11)
     with self.assertRaises(ValueError):
         MidPoint(-10)
     with self.assertRaises(ValueError):
         ClenshawCurtis(-10)
     with self.assertRaises(ValueError):
         FejerFirst(-10)
     with self.assertRaises(ValueError):
         FejerSecond(-10)
Пример #8
0
 def test_make_grid_integral(self):
     """Test molecular make_grid works as designed."""
     pts = UniformInteger(70)
     tf = ExpRTransform(1e-5, 2e1)
     rgrid = tf.transform_1d_grid(pts)
     numbers = np.array([1, 1])
     coordinates = np.array([[0.0, 0.0, -0.5], [0.0, 0.0, 0.5]], float)
     becke = BeckeWeights(order=3)
     # construct molgrid
     for grid_type, deci in (
         ("coarse", 3),
         ("medium", 4),
         ("fine", 5),
         ("veryfine", 6),
         ("ultrafine", 6),
         ("insane", 6),
     ):
         mg = MolGrid.from_preset(numbers, coordinates, rgrid, grid_type,
                                  becke)
         dist0 = np.sqrt(((coordinates[0] - mg.points)**2).sum(axis=1))
         dist1 = np.sqrt(((coordinates[1] - mg.points)**2).sum(axis=1))
         fn = np.exp(-2 * dist0) / np.pi + np.exp(-2 * dist1) / np.pi
         occupation = mg.integrate(fn)
         assert_almost_equal(occupation, 2.0, decimal=deci)
Пример #9
0
    def test_from_predefined(self):
        """Test grid construction with predefined grid."""
        # test coarse grid
        pts = UniformInteger(20)
        tf = PowerRTransform(7.0879993828935345e-06, 16.05937640019924)
        rad_grid = tf.transform_1d_grid(pts)
        atgrid = AtomGrid.from_preset(rad_grid, atnum=1, preset="coarse")
        # 604 points for coarse H atom
        assert_equal(atgrid.size, 604)
        assert_almost_equal(
            np.sum(np.exp(-np.sum(atgrid.points**2, axis=1)) * atgrid.weights),
            5.56840953,
        )

        # test medium grid
        pts = UniformInteger(24)
        tf = PowerRTransform(3.69705074304963e-06, 19.279558946793685)
        rad_grid = tf.transform_1d_grid(pts)
        atgrid = AtomGrid.from_preset(rad_grid, atnum=1, preset="medium")
        # 928 points for coarse H atom
        assert_equal(atgrid.size, 928)
        assert_almost_equal(
            np.sum(np.exp(-np.sum(atgrid.points**2, axis=1)) * atgrid.weights),
            5.56834559,
        )
        # test fine grid
        pts = UniformInteger(34)
        tf = PowerRTransform(2.577533167224667e-07, 16.276983371222354)
        rad_grid = tf.transform_1d_grid(pts)
        atgrid = AtomGrid.from_preset(rad_grid, atnum=1, preset="fine")
        # 1984 points for coarse H atom
        assert_equal(atgrid.size, 1984)
        assert_almost_equal(
            np.sum(np.exp(-np.sum(atgrid.points**2, axis=1)) * atgrid.weights),
            5.56832800,
        )
        # test veryfine grid
        pts = UniformInteger(41)
        tf = PowerRTransform(1.1774580743206259e-07, 20.140888089596444)
        rad_grid = tf.transform_1d_grid(pts)
        atgrid = AtomGrid.from_preset(rad_grid, atnum=1, preset="veryfine")
        # 3154 points for coarse H atom
        assert_equal(atgrid.size, 3154)
        assert_almost_equal(
            np.sum(np.exp(-np.sum(atgrid.points**2, axis=1)) * atgrid.weights),
            5.56832800,
        )
        # test ultrafine grid
        pts = UniformInteger(49)
        tf = PowerRTransform(4.883104847991021e-08, 21.05456999309752)
        rad_grid = tf.transform_1d_grid(pts)
        atgrid = AtomGrid.from_preset(rad_grid, atnum=1, preset="ultrafine")
        # 4546 points for coarse H atom
        assert_equal(atgrid.size, 4546)
        assert_almost_equal(
            np.sum(np.exp(-np.sum(atgrid.points**2, axis=1)) * atgrid.weights),
            5.56832800,
        )
        # test insane grid
        pts = UniformInteger(59)
        tf = PowerRTransform(1.9221827244049134e-08, 21.413278983919113)
        rad_grid = tf.transform_1d_grid(pts)
        atgrid = AtomGrid.from_preset(rad_grid, atnum=1, preset="insane")
        # 6622 points for coarse H atom
        assert_equal(atgrid.size, 6622)
        assert_almost_equal(
            np.sum(np.exp(-np.sum(atgrid.points**2, axis=1)) * atgrid.weights),
            5.56832800,
        )
Пример #10
0
    def test_raise_errors(self):
        """Test molgrid errors raise."""
        atg = AtomGrid.from_pruned(
            self.rgrid,
            0.5,
            sectors_r=np.array([]),
            sectors_degree=np.array([17]),
            center=np.array([0.0, 0.0, 0.0]),
        )

        # errors of aim_weight
        with self.assertRaises(TypeError):
            MolGrid(atnums=np.array([1]), atgrids=[atg], aim_weights="test")
        with self.assertRaises(ValueError):
            MolGrid(atnums=np.array([1]),
                    atgrids=[atg],
                    aim_weights=np.array(3))
        with self.assertRaises(TypeError):
            MolGrid(atnums=np.array([1]), atgrids=[atg], aim_weights=[3, 5])

        # integrate errors
        becke = BeckeWeights({1: 0.472_431_53}, order=3)
        molg = MolGrid(np.array([1]), [atg], becke)
        with self.assertRaises(ValueError):
            molg.integrate()
        with self.assertRaises(TypeError):
            molg.integrate(1)
        with self.assertRaises(ValueError):
            molg.integrate(np.array([3, 5]))
        with self.assertRaises(ValueError):
            molg.get_atomic_grid(-3)
        molg = MolGrid(np.array([1]), [atg], becke, store=True)
        with self.assertRaises(ValueError):
            molg.get_atomic_grid(-5)

        # test make_grid error
        pts = UniformInteger(70)
        tf = ExpRTransform(1e-5, 2e1)
        rgrid = tf.transform_1d_grid(pts)
        numbers = np.array([1, 1])
        becke = BeckeWeights(order=3)
        # construct molgrid
        with self.assertRaises(ValueError):
            MolGrid.from_preset(numbers, np.array([0.0, 0.0, 0.0]), rgrid,
                                "fine", becke)
        with self.assertRaises(ValueError):
            MolGrid.from_preset(np.array([1, 1]), np.array([[0.0, 0.0, 0.0]]),
                                rgrid, "fine", becke)
        with self.assertRaises(ValueError):
            MolGrid.from_preset(np.array([1, 1]), np.array([[0.0, 0.0, 0.0]]),
                                rgrid, "fine", becke)
        with self.assertRaises(TypeError):
            MolGrid.from_preset(
                np.array([1, 1]),
                np.array([[0.0, 0.0, -0.5], [0.0, 0.0, 0.5]]),
                {3, 5},
                "fine",
                becke,
            )
        with self.assertRaises(TypeError):
            MolGrid.from_preset(
                np.array([1, 1]),
                np.array([[0.0, 0.0, -0.5], [0.0, 0.0, 0.5]]),
                rgrid,
                np.array([3, 5]),
                becke,
            )
Пример #11
0
 def setUp(self):
     """Set up radial grid for integral tests."""
     pts = UniformInteger(100)
     tf = ExpRTransform(1e-5, 2e1)
     self.rgrid = tf.transform_1d_grid(pts)
Пример #12
0
 def test_horton_linear(self):
     """Test horton linear grids."""
     grid = UniformInteger(10)
     assert_allclose(grid.points, np.arange(10))
     assert_allclose(grid.weights, np.ones(10))