def test_becke_integral(self): """Test transform integral.""" oned = GaussLegendre(20) btf = BeckeTF(0.00001, 1.0) rad = btf.transform_1d_grid(oned) def gauss(x): return np.exp(-(x**2)) result = rad.integrate(gauss(rad.points)) ref_result = np.sqrt(np.pi) / 2 assert_almost_equal(result, ref_result, decimal=5) oned = GaussChebyshev(20) rad = btf.transform_1d_grid(oned) result = rad.integrate(gauss(rad.points)) assert_almost_equal(result, ref_result, decimal=3)
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)
def test_cubicspline_and_interp_gauss(self): """Test cubicspline interpolation values.""" oned = GaussLegendre(30) btf = BeckeTF(0.0001, 1.5) rad = btf.transform_1d_grid(oned) atgrid = AtomGrid.from_pruned(rad, 1, sectors_r=[], sectors_degree=[7]) value_array = self.helper_func_gauss(atgrid.points) # random test points on gauss function for _ in range(20): r = np.random.rand(1)[0] * 2 theta = np.random.rand(10) phi = np.random.rand(10) x = r * np.sin(phi) * np.cos(theta) y = r * np.sin(phi) * np.sin(theta) z = r * np.cos(phi) inters = atgrid.interpolate(np.array((x, y, z)).T, value_array) assert_allclose(self.helper_func_gauss(np.array([x, y, z]).T), inters, atol=1e-4)
def test_errors_raise(self): """Test errors raise.""" with self.assertRaises(ValueError): GaussLaguerre(10, -1) with self.assertRaises(ValueError): GaussLaguerre(0, 1) with self.assertRaises(ValueError): GaussLegendre(-10) with self.assertRaises(ValueError): GaussChebyshev(-10) with self.assertRaises(ValueError): HortonLinear(-10) with self.assertRaises(ValueError): TanhSinh(10, 1) with self.assertRaises(ValueError): Simpson(4) with self.assertRaises(ValueError): GaussChebyshevType2(-10) with self.assertRaises(ValueError): GaussChebyshevLobatto(-10) with self.assertRaises(ValueError): Trapezoidal(-10) with self.assertRaises(ValueError): RectangleRuleSineEndPoints(-10) with self.assertRaises(ValueError): RectangleRuleSine(-10) with self.assertRaises(ValueError): TanhSinh(-11, 1) with self.assertRaises(ValueError): Simpson(-11) with self.assertRaises(ValueError): MidPoint(-10) with self.assertRaises(ValueError): ClenshawCurtis(-10) with self.assertRaises(ValueError): FejerFirst(-10) with self.assertRaises(ValueError): FejerSecond(-10)
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))
def test_gausslengendre(self): """Test Guass Lengendre polynomial grid.""" points, weights = roots_legendre(10) grid = GaussLegendre(10) assert_allclose(grid.points, points) assert_allclose(grid.weights, weights)