コード例 #1
0
ファイル: test_cubic.py プロジェクト: theochem/grid
 def test_origin_of_tensor1d_grids(self):
     r"""Test that the origin is the first point."""
     oned = GaussLaguerre(10)
     oned2 = GaussLaguerre(20)
     grid = Tensor1DGrids(oned, oned2)
     assert_allclose(np.array([oned.points[0], oned2.points[0]]),
                     grid.origin)
コード例 #2
0
ファイル: test_onedgrid.py プロジェクト: thomaspigeon/grid
 def test_gausslaguerre(self):
     """Test Guass Laguerre polynomial grid."""
     points, weights = np.polynomial.laguerre.laggauss(10)
     weights = weights * np.exp(points) * np.power(points, 0)
     grid = GaussLaguerre(10)
     assert_allclose(grid.points, points)
     assert_allclose(grid.weights, weights)
コード例 #3
0
 def test_errors_raise(self):
     """Test errors raise."""
     with self.assertRaises(ValueError):
         GaussLaguerre(10, -1)
     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)
コード例 #4
0
 def test_linear_transform_coeff(self):
     """Test coefficient with linear transformation."""
     x = GaussLaguerre(10).points
     ltf = LinearTF(1, 10)
     inv_ltf = InverseTF(ltf)
     derivs_fun = [inv_ltf.deriv, inv_ltf.deriv2, inv_ltf.deriv3]
     coeff = np.array([2, 3, 4])
     coeff_b = ODE._transformed_coeff_ode_with_r(coeff, derivs_fun, x)
     # assert values
     assert_allclose(coeff_b[0], np.ones(len(x)) * coeff[0])
     assert_allclose(coeff_b[1], 1 / 4.5 * coeff[1])
     assert_allclose(coeff_b[2], (1 / 4.5) ** 2 * coeff[2])
コード例 #5
0
ファイル: test_ode.py プロジェクト: theochem/grid
def test_transformation_of_ode_with_linear_transform():
    """Test transformation of ODE with linear transformation."""
    x = GaussLaguerre(10).points
    # Obtain linear transformation with rmin = 1 and rmax = 10.
    ltf = LinearFiniteRTransform(1, 10)
    # The inverse is x_i = \frac{r_i - r_{min} - R} {r_i - r_{min} + R}
    inv_ltf = InverseRTransform(ltf)
    derivs_fun = [inv_ltf.deriv, inv_ltf.deriv2, inv_ltf.deriv3]
    # Test with 2y + 3y` + 4y``
    coeff = np.array([2, 3, 4])
    coeff_b = _transform_ode_from_derivs(coeff, derivs_fun, x)
    # assert values
    assert_allclose(coeff_b[0], np.ones(len(x)) * coeff[0])
    assert_allclose(coeff_b[1], 1 / 4.5 * coeff[1])
    assert_allclose(coeff_b[2], (1 / 4.5)**2 * coeff[2])
コード例 #6
0
ファイル: test_cubic.py プロジェクト: theochem/grid
    def test_point_and_weights_are_correct(self):
        r"""Test that the points and weights are correctly computed."""
        oned = GaussLaguerre(10)
        cubic = Tensor1DGrids(oned, oned, oned)

        index = 0  # Index for cubic points.
        for i in range(oned.size):
            for j in range(oned.size):
                for k in range(oned.size):
                    actual_pt = np.array(
                        [oned.points[i], oned.points[j], oned.points[k]])
                    assert_allclose(actual_pt, cubic.points[index, :])
                    actual_weight = oned.weights[i] * oned.weights[
                        j] * oned.weights[k]
                    assert_allclose(actual_weight, cubic.weights[index])
                    index += 1
コード例 #7
0
ファイル: test_cubic.py プロジェクト: theochem/grid
 def test_raise_error_when_constructing_grid(self):
     r"""Test raising of error when constructing Tensor1DGrids."""
     oned = GaussLaguerre(10)
     # Test raises error
     with self.assertRaises(TypeError) as err:
         Tensor1DGrids(5, oned, oned)
     self.assertEqual(
         "Argument oned_x should be an instance of `OneDGrid`, got <class 'int'>",
         str(err.exception),
     )
     with self.assertRaises(TypeError) as err:
         Tensor1DGrids(oned, 5, oned)
     self.assertEqual(
         "Argument oned_y should be an instance of `OneDGrid`, got <class 'int'>",
         str(err.exception),
     )
     with self.assertRaises(TypeError) as err:
         Tensor1DGrids(oned, oned, 5)
     self.assertEqual(
         "Argument oned_z should be an instance of `OneDGrid`, got <class 'int'>",
         str(err.exception),
     )
コード例 #8
0
ファイル: test_molgrid.py プロジェクト: leila-pujal/grid
    def test_make_grid_different_grid_type(self):
        """Test different kind molgrid initizalize setting."""
        # three different radial grid
        rad2 = GaussLaguerre(50)
        rad3 = GaussLaguerre(70)
        # construct grid
        numbers = np.array([1, 8, 1])
        coordinates = np.array(
            [[0.0, 0.0, -0.5], [0.0, 0.0, 0.5], [0.0, 0.5, 0.0]], float)
        becke = BeckeWeights(order=3)

        # grid_type test with list
        mg = MolGrid.make_grid(
            numbers,
            coordinates,
            rad2,
            ["fine", "veryfine", "medium"],
            becke,
            store=True,
        )
        dist0 = np.sqrt(((coordinates[0] - mg.points)**2).sum(axis=1))
        dist1 = np.sqrt(((coordinates[1] - mg.points)**2).sum(axis=1))
        dist2 = np.sqrt(((coordinates[2] - mg.points)**2).sum(axis=1))
        fn = (np.exp(-2 * dist0) + np.exp(-2 * dist1) +
              np.exp(-2 * dist2)) / np.pi
        occupation = mg.integrate(fn)
        assert_almost_equal(occupation, 3, decimal=3)

        atgrid1 = AtomGrid.from_predefined(numbers[0],
                                           rad2,
                                           "fine",
                                           center=coordinates[0])
        atgrid2 = AtomGrid.from_predefined(numbers[1],
                                           rad2,
                                           "veryfine",
                                           center=coordinates[1])
        atgrid3 = AtomGrid.from_predefined(numbers[2],
                                           rad2,
                                           "medium",
                                           center=coordinates[2])
        assert_allclose(mg._atomic_grids[0].points, atgrid1.points)
        assert_allclose(mg._atomic_grids[1].points, atgrid2.points)
        assert_allclose(mg._atomic_grids[2].points, atgrid3.points)

        # grid type test with dict
        mg = MolGrid.make_grid(numbers,
                               coordinates,
                               rad3, {
                                   1: "fine",
                                   8: "veryfine"
                               },
                               becke,
                               store=True)
        dist0 = np.sqrt(((coordinates[0] - mg.points)**2).sum(axis=1))
        dist1 = np.sqrt(((coordinates[1] - mg.points)**2).sum(axis=1))
        dist2 = np.sqrt(((coordinates[2] - mg.points)**2).sum(axis=1))
        fn = (np.exp(-2 * dist0) + np.exp(-2 * dist1) +
              np.exp(-2 * dist2)) / np.pi
        occupation = mg.integrate(fn)
        assert_almost_equal(occupation, 3, decimal=3)

        atgrid1 = AtomGrid.from_predefined(numbers[0],
                                           rad3,
                                           "fine",
                                           center=coordinates[0])
        atgrid2 = AtomGrid.from_predefined(numbers[1],
                                           rad3,
                                           "veryfine",
                                           center=coordinates[1])
        atgrid3 = AtomGrid.from_predefined(numbers[2],
                                           rad3,
                                           "fine",
                                           center=coordinates[2])
        assert_allclose(mg._atomic_grids[0].points, atgrid1.points)
        assert_allclose(mg._atomic_grids[1].points, atgrid2.points)
        assert_allclose(mg._atomic_grids[2].points, atgrid3.points)
コード例 #9
0
    def test_make_grid_different_rad_type(self):
        """Test different radial grid input for make molgrid."""
        # radial grid test with list
        rad1 = GaussLaguerre(30)
        rad2 = GaussLaguerre(50)
        rad3 = GaussLaguerre(70)
        # construct grid
        numbers = np.array([1, 8, 1])
        coordinates = np.array(
            [[0.0, 0.0, -0.5], [0.0, 0.0, 0.5], [0.0, 0.5, 0.0]], float
        )
        becke = BeckeWeights(order=3)
        # construct molgrid
        mg = MolGrid.from_preset(
            numbers,
            coordinates,
            [rad1, rad2, rad3],
            {1: "fine", 8: "veryfine"},
            becke,
            store=True,
            rotate=False,
        )
        dist0 = np.sqrt(((coordinates[0] - mg.points) ** 2).sum(axis=1))
        dist1 = np.sqrt(((coordinates[1] - mg.points) ** 2).sum(axis=1))
        dist2 = np.sqrt(((coordinates[2] - mg.points) ** 2).sum(axis=1))
        fn = (np.exp(-2 * dist0) + np.exp(-2 * dist1) + np.exp(-2 * dist2)) / np.pi
        occupation = mg.integrate(fn)
        assert_almost_equal(occupation, 3, decimal=3)

        atgrid1 = AtomGrid.from_preset(
            rad1, atnum=numbers[0], preset="fine", center=coordinates[0]
        )
        atgrid2 = AtomGrid.from_preset(
            rad2, atnum=numbers[1], preset="veryfine", center=coordinates[1]
        )
        atgrid3 = AtomGrid.from_preset(
            rad3, atnum=numbers[2], preset="fine", center=coordinates[2]
        )
        assert_allclose(mg._atgrids[0].points, atgrid1.points)
        assert_allclose(mg._atgrids[1].points, atgrid2.points)
        assert_allclose(mg._atgrids[2].points, atgrid3.points)

        # radial grid test with dict
        mg = MolGrid.from_preset(
            numbers,
            coordinates,
            {1: rad1, 8: rad3},
            {1: "fine", 8: "veryfine"},
            becke,
            store=True,
            rotate=False,
        )
        dist0 = np.sqrt(((coordinates[0] - mg.points) ** 2).sum(axis=1))
        dist1 = np.sqrt(((coordinates[1] - mg.points) ** 2).sum(axis=1))
        dist2 = np.sqrt(((coordinates[2] - mg.points) ** 2).sum(axis=1))
        fn = (np.exp(-2 * dist0) + np.exp(-2 * dist1) + np.exp(-2 * dist2)) / np.pi
        occupation = mg.integrate(fn)
        assert_almost_equal(occupation, 3, decimal=3)

        atgrid1 = AtomGrid.from_preset(
            rad1, atnum=numbers[0], preset="fine", center=coordinates[0]
        )
        atgrid2 = AtomGrid.from_preset(
            rad3, atnum=numbers[1], preset="veryfine", center=coordinates[1]
        )
        atgrid3 = AtomGrid.from_preset(
            rad1, atnum=numbers[2], preset="fine", center=coordinates[2]
        )
        assert_allclose(mg._atgrids[0].points, atgrid1.points)
        assert_allclose(mg._atgrids[1].points, atgrid2.points)
        assert_allclose(mg._atgrids[2].points, atgrid3.points)
コード例 #10
0
ファイル: test_onedgrid.py プロジェクト: thomaspigeon/grid
 def test_errors_raise(self):
     """Test errors raise."""
     with self.assertRaises(ValueError):
         GaussLaguerre(10, -1)