Exemple #1
0
    def test_raise_errors(self):
        """Test molgrid errors raise."""
        atg = AtomicGrid.special_init(
            self.rgrid,
            0.5,
            scales=np.array([]),
            degs=np.array([17]),
            center=np.array([0.0, 0.0, 0.0]),
        )
        # initilize errors
        with self.assertRaises(NotImplementedError):
            MolGrid([atg], np.array([1]), aim_weights="test")
        with self.assertRaises(ValueError):
            MolGrid([atg], np.array([1]), aim_weights=np.array(3))
        with self.assertRaises(TypeError):
            MolGrid([atg], np.array([1]), aim_weights=[3, 5])
        # integrate errors
        molg = MolGrid([atg], 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(NotImplementedError):
            molg.get_atomic_grid(0)
        with self.assertRaises(ValueError):
            molg.get_aim_weights(-3)

        molg = MolGrid([atg], np.array([1]), store=True)
        with self.assertRaises(ValueError):
            molg.get_atomic_grid(-5)
Exemple #2
0
    def test_molgrid_attrs(self):
        """Test MolGrid attributes."""
        # numbers = np.array([6, 8], int)
        coordinates = np.array([[0.0, 0.2, -0.5], [0.1, 0.0, 0.5]], float)
        atg1 = AtomicGrid.special_init(
            self.rgrid,
            1.228,
            scales=np.array([]),
            degs=np.array([17]),
            center=coordinates[0],
        )
        atg2 = AtomicGrid.special_init(
            self.rgrid,
            0.945,
            scales=np.array([]),
            degs=np.array([17]),
            center=coordinates[1],
        )
        mg = MolGrid([atg1, atg2], np.array([6, 8]), store=True)

        assert mg.size == 2 * 110 * 100
        assert mg.points.shape == (mg.size, 3)
        assert mg.weights.shape == (mg.size,)
        assert mg.aim_weights.shape == (mg.size,)
        assert mg.get_atomic_grid(0) is atg1
        assert mg.get_atomic_grid(1) is atg2

        simple_ag1 = mg.get_simple_atomic_grid(0)
        simple_ag2 = mg.get_simple_atomic_grid(1)
        assert_allclose(simple_ag1.points, atg1.points)
        assert_allclose(simple_ag2.points, atg2.points)

        aim_at1 = mg.get_aim_weights(0)
        aim_at2 = mg.get_aim_weights(1)
        assert_allclose(simple_ag1.weights, atg1.weights * aim_at1)
        assert_allclose(simple_ag2.weights, atg2.weights * aim_at2)