コード例 #1
0
ファイル: test_molgrid.py プロジェクト: tovrstra/grid
 def setUp(self):
     """Set up radial grid for integral tests."""
     pts = HortonLinear(100)
     tf = ExpRTransform(1e-3, 1e1)
     rad_pts = tf.transform(pts.points)
     rad_wts = tf.deriv(pts.points) * pts.weights
     self.rgrid = OneDGrid(rad_pts, rad_wts)
コード例 #2
0
ファイル: test_rtransform.py プロジェクト: theochem/grid
 def test_exp_bounds(self):
     """Test exponential tf raise errors."""
     with self.assertRaises(ValueError):
         ExpRTransform(-0.1, 1.0)
     with self.assertRaises(ValueError):
         ExpRTransform(0.1, -1.0)
     with self.assertRaises(ValueError):
         ExpRTransform(1.1, 0.9)
コード例 #3
0
ファイル: test_rtransform.py プロジェクト: theochem/grid
 def test_exp_basics(self):
     """Test exponential tf."""
     rtf = ExpRTransform(0.1, 1e1)
     gd = np.ones(100) * 0
     assert abs(rtf.transform(gd)[0] - 0.1) < 1e-15
     gd = np.ones(100) * 99
     assert abs(rtf.transform(gd)[0] - 1e1) < 1e-10
     self.check_consistency(rtf)
     self.check_deriv(rtf)
コード例 #4
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()
コード例 #5
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()
コード例 #6
0
ファイル: test_molgrid.py プロジェクト: leila-pujal/grid
 def test_integrate_hirshfeld_weights_single_1s(self):
     """Test molecular integral in H atom with Hirshfeld weights."""
     pts = HortonLinear(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,
         r_sectors=np.array([]),
         degs=np.array([17]),
         center=coordinates,
     )
     mg = MolGrid([atg1], HirshfeldWeights(), np.array([7]))
     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_make_grid_integral(self):
     """Test molecular make_grid works as designed."""
     pts = HortonLinear(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)
コード例 #8
0
ファイル: test_rtransform.py プロジェクト: theochem/grid
 def test_domain(self):
     """Test domain errors."""
     rad = GaussLegendre(10)
     with self.assertRaises(ValueError):
         tf = IdentityRTransform()
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = LinearInfiniteRTransform(0.1, 1.5)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = ExpRTransform(0.1, 1e1)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = PowerRTransform(1e-3, 1e2)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = HyperbolicRTransform(0.4 / 450, 1.0 / 450)
         tf.transform_1d_grid(rad)
コード例 #9
0
ファイル: test_rtransform.py プロジェクト: theochem/grid
 def test_exp_properties(self):
     """Test exponential tf properties."""
     rtf = ExpRTransform(0.1, 1e1)
     assert rtf.rmin == 0.1
     assert rtf.rmax == 1e1
コード例 #10
0
ファイル: test_molgrid.py プロジェクト: leila-pujal/grid
    def test_raise_errors(self):
        """Test molgrid errors raise."""
        atg = AtomGrid.from_pruned(
            self.rgrid,
            0.5,
            r_sectors=np.array([]),
            degs=np.array([17]),
            center=np.array([0.0, 0.0, 0.0]),
        )

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

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

        # test make_grid error
        pts = HortonLinear(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.make_grid(numbers, np.array([0.0, 0.0, 0.0]), rgrid,
                              "fine", becke)
        with self.assertRaises(ValueError):
            MolGrid.make_grid(np.array([1, 1]), np.array([[0.0, 0.0, 0.0]]),
                              rgrid, "fine", becke)
        with self.assertRaises(ValueError):
            MolGrid.make_grid(np.array([1, 1]), np.array([[0.0, 0.0, 0.0]]),
                              rgrid, "fine", becke)
        with self.assertRaises(TypeError):
            MolGrid.make_grid(
                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.make_grid(
                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
ファイル: test_molgrid.py プロジェクト: leila-pujal/grid
 def setUp(self):
     """Set up radial grid for integral tests."""
     pts = HortonLinear(100)
     tf = ExpRTransform(1e-5, 2e1)
     self.rgrid = tf.transform_1d_grid(pts)