Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
0
 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)
Beispiel #4
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)
Beispiel #5
0
    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,
            )
Beispiel #6
0
 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)