Пример #1
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)
Пример #2
0
    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.from_preset(
            numbers,
            coordinates,
            rad2,
            ["fine", "veryfine", "medium"],
            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(
            rad2, 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(
            rad2, atnum=numbers[2], preset="medium", 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)

        # grid type test with dict
        mg = MolGrid.from_preset(
            numbers,
            coordinates,
            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(
            rad3, 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(
            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)
Пример #3
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 = 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.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,
            )