Beispiel #1
0
 def test_cubicspline_and_interp_mol(self):
     """Test cubicspline interpolation values."""
     odg = OneDGrid(np.arange(10) + 1, np.ones(10), (0, np.inf))
     rad = IdentityRTransform().transform_1d_grid(odg)
     atgrid = AtomGrid.from_pruned(rad, 1, sectors_r=[], sectors_degree=[7])
     values = self.helper_func_power(atgrid.points)
     result = spline_with_atomic_grid(atgrid, values)
     sph_coor = atgrid.convert_cart_to_sph()
     semi_sph_c = sph_coor[atgrid.indices[5] : atgrid.indices[6]]
     interp = interpolate(result, rad.points[5], semi_sph_c[:, 1], semi_sph_c[:, 2])
     # same result from points and interpolation
     assert_allclose(interp, values[atgrid.indices[5] : atgrid.indices[6]])
Beispiel #2
0
 def test_interpolate_given_splines(self):
     """Test points to interpolate to is the same as original function values."""
     # Construct grid
     odg = OneDGrid(np.arange(10) + 1, np.ones(10), (0, np.inf))
     rad = IdentityRTransform().transform_1d_grid(odg)
     atgrid = AtomGrid.from_pruned(rad, 1, sectors_r=[], sectors_degree=[7])
     # Construct the function values and splies.
     values = self.helper_func_power(atgrid.points)
     result = spline_with_atomic_grid(atgrid, values)
     # Obtain the spherical coordinates and interpolate from indices[5] to indices[6]
     sph_coor = atgrid.convert_cart_to_sph()
     semi_sph_c = sph_coor[atgrid.indices[5]:atgrid.indices[6]]
     interp = interpolate_given_splines(result, rad.points[5],
                                        semi_sph_c[:, 1], semi_sph_c[:, 2])
     # same result from points and interpolation
     assert_allclose(interp, values[atgrid.indices[5]:atgrid.indices[6]])
Beispiel #3
0
 def test_cubicspline_and_interp_gauss(self):
     """Test cubicspline interpolation values."""
     oned = GaussLegendre(30)
     btf = BeckeRTransform(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)
     result = spline_with_atomic_grid(atgrid, value_array)
     # 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)
         inters = interpolate_given_splines(result, r, theta, phi)
         x = r * np.sin(phi) * np.cos(theta)
         y = r * np.sin(phi) * np.sin(theta)
         z = r * np.cos(phi)
         assert_allclose(self.helper_func_gauss(np.array([x, y, z]).T),
                         inters,
                         atol=1e-4)
Beispiel #4
0
    def test_poisson_proj(self):
        """Test the project function."""
        oned = GaussChebyshev(30)
        btf = BeckeRTransform(0.0001, 1.5)
        rad = btf.transform_1d_grid(oned)
        l_max = 7
        atgrid = AtomGrid(rad, degrees=[l_max])
        value_array = self.helper_func_gauss(atgrid.points)
        spl_res = spline_with_atomic_grid(atgrid, value_array)
        # test for random, r, theta, phi
        for _ in range(20):
            r = np.random.rand(1)[0] * 2
            theta = np.random.rand(10) * 3.14
            phi = np.random.rand(10) * 3.14
            result = interpolate(spl_res, r, theta, phi)
            x = r * np.sin(phi) * np.cos(theta)
            y = r * np.sin(phi) * np.sin(theta)
            z = r * np.cos(phi)
            result_ref = self.helper_func_gauss(np.array([x, y, z]).T)
            # assert similar value less than 1e-4 discrepancy
            assert_allclose(result, result_ref, atol=1e-4)

        sph_coor = atgrid.convert_cart_to_sph()[:, 1:3]
        spls_mt = Poisson._proj_sph_value(
            atgrid.rgrid,
            sph_coor,
            l_max // 2,
            value_array,
            atgrid.weights,
            atgrid.indices,
        )
        # test each point is the same
        for _ in range(20):
            r = np.random.rand(1)[0] * 2
            # random spherical point
            int_res = np.zeros((l_max, l_max // 2 + 1), dtype=float)
            for j in range(l_max // 2 + 1):
                for i in range(-j, j + 1):
                    int_res[i, j] += spls_mt[i, j](r)
            assert_allclose(spl_res(r), int_res)