Exemplo n.º 1
0
    def test_error_raises(self):
        """Tests for error raises."""
        with self.assertRaises(TypeError):
            AtomGrid.from_pruned(np.arange(3),
                                 1.0,
                                 r_sectors=np.arange(2),
                                 degs=np.arange(3))
        with self.assertRaises(ValueError):
            AtomGrid.from_pruned(
                OneDGrid(np.arange(3), np.arange(3)),
                radius=1.0,
                r_sectors=np.arange(2),
                degs=np.arange(0),
            )
        with self.assertRaises(ValueError):
            AtomGrid.from_pruned(
                OneDGrid(np.arange(3), np.arange(3)),
                radius=1.0,
                r_sectors=np.arange(2),
                degs=np.arange(4),
            )
        with self.assertRaises(ValueError):
            AtomGrid._generate_atomic_grid(
                OneDGrid(np.arange(3), np.arange(3)), np.arange(2))
        with self.assertRaises(ValueError):
            AtomGrid.from_pruned(
                OneDGrid(np.arange(3), np.arange(3)),
                radius=1.0,
                r_sectors=np.array([0.3, 0.5, 0.7]),
                degs=np.array([3, 5, 7, 5]),
                center=np.array([0, 0, 0, 0]),
            )

        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)), size=110)
        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)), degs=17)
        with self.assertRaises(ValueError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)),
                     degs=[17],
                     rotate=-1)
        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)),
                     degs=[17],
                     rotate="asdfaf")
        # error of radial grid
        with self.assertRaises(TypeError):
            AtomGrid(Grid(np.arange(1, 5, 1), np.ones(4)), degs=[2, 3, 4, 5])
        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(-2, 2, 1), np.ones(4)),
                     degs=[2, 3, 4, 5])
        with self.assertRaises(TypeError):
            rgrid = OneDGrid(np.arange(1, 3, 1), np.ones(2), domain=(-1, 5))
            AtomGrid(rgrid, degs=[2])
        with self.assertRaises(TypeError):
            rgrid = OneDGrid(np.arange(-1, 1, 1), np.ones(2))
            AtomGrid(rgrid, degs=[2])
Exemplo n.º 2
0
 def test_atomic_grid(self):
     """Test atomic grid center transilation."""
     rad_pts = np.array([0.1, 0.5, 1])
     rad_wts = np.array([0.3, 0.4, 0.3])
     rad_grid = OneDGrid(rad_pts, rad_wts)
     degs = np.array([3, 5, 7])
     # origin center
     # randome center
     pts, wts, ind = AtomGrid._generate_atomic_grid(rad_grid, degs)
     ref_pts, ref_wts, ref_ind = AtomGrid._generate_atomic_grid(rad_grid, degs)
     # diff grid points diff by center and same weights
     assert_allclose(pts, ref_pts)
     assert_allclose(wts, ref_wts)
Exemplo n.º 3
0
 def test_generate_atomic_grid(self):
     """Test for generating atomic grid."""
     # setup testing class
     rad_pts = np.array([0.1, 0.5, 1])
     rad_wts = np.array([0.3, 0.4, 0.3])
     rad_grid = OneDGrid(rad_pts, rad_wts)
     degs = np.array([3, 5, 7])
     pts, wts, ind = AtomGrid._generate_atomic_grid(rad_grid, degs)
     assert len(pts) == 46
     assert_equal(ind, [0, 6, 20, 46])
     # set tests for slicing grid from atomic grid
     for i in range(3):
         # set each layer of points
         ref_grid = AngularGrid(degree=degs[i])
         # check for each point
         assert_allclose(pts[ind[i] : ind[i + 1]], ref_grid.points * rad_pts[i])
         # check for each weight
         assert_allclose(
             wts[ind[i] : ind[i + 1]],
             ref_grid.weights * rad_wts[i] * rad_pts[i] ** 2,
         )
Exemplo n.º 4
0
    def test_error_raises(self):
        """Tests for error raises."""
        with self.assertRaises(TypeError):
            AtomGrid.from_pruned(np.arange(3),
                                 1.0,
                                 sectors_r=np.arange(2),
                                 sectors_degree=np.arange(3))
        with self.assertRaises(ValueError):
            AtomGrid.from_pruned(
                OneDGrid(np.arange(3), np.arange(3)),
                radius=1.0,
                sectors_r=np.arange(2),
                sectors_degree=np.arange(0),
            )
        with self.assertRaises(ValueError):
            AtomGrid.from_pruned(
                OneDGrid(np.arange(3), np.arange(3)),
                radius=1.0,
                sectors_r=np.arange(2),
                sectors_degree=np.arange(4),
            )
        with self.assertRaises(ValueError):
            AtomGrid._generate_atomic_grid(
                OneDGrid(np.arange(3), np.arange(3)), np.arange(2))
        with self.assertRaises(ValueError):
            AtomGrid.from_pruned(
                OneDGrid(np.arange(3), np.arange(3)),
                radius=1.0,
                sectors_r=np.array([0.3, 0.5, 0.7]),
                sectors_degree=np.array([3, 5, 7, 5]),
                center=np.array([0, 0, 0, 0]),
            )

        # test preset
        with self.assertRaises(ValueError):
            AtomGrid.from_preset(atnum=1, preset="fine")

        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)), sizes=110)
        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)), degrees=17)
        with self.assertRaises(ValueError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)),
                     degrees=[17],
                     rotate=-1)
        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(3), np.arange(3)),
                     degrees=[17],
                     rotate="asdfaf")
        # error of radial grid
        with self.assertRaises(TypeError):
            AtomGrid(Grid(np.arange(1, 5, 1), np.ones(4)),
                     degrees=[2, 3, 4, 5])
        with self.assertRaises(TypeError):
            AtomGrid(OneDGrid(np.arange(-2, 2, 1), np.ones(4)),
                     degrees=[2, 3, 4, 5])
        with self.assertRaises(TypeError):
            rgrid = OneDGrid(np.arange(1, 3, 1), np.ones(2), domain=(-1, 5))
            AtomGrid(rgrid, degrees=[2])
        with self.assertRaises(TypeError):
            rgrid = OneDGrid(np.arange(-1, 1, 1), np.ones(2))
            AtomGrid(rgrid, degrees=[2])

        with self.assertRaises(ValueError):
            AtomGrid._generate_real_sph_harm(-1, np.random.rand(10),
                                             np.random.rand(10))
        with self.assertRaises(ValueError):
            oned = GaussLegendre(30)
            btf = BeckeTF(0.0001, 1.5)
            rad = btf.transform_1d_grid(oned)
            atgrid = AtomGrid.from_preset(rad, atnum=1, preset="fine")
            atgrid.fit_values(np.random.rand(100))