Exemplo n.º 1
0
    def test_match_degree(self):
        """Test match proper degree for random given values."""
        # test array 1
        num_list1 = [3, 4, 5, 6, 7, 8, 9, 10]
        result1 = match_degree(num_list1)
        assert_array_equal(result1, [3, 5, 5, 7, 7, 9, 9, 11])

        # test array 2
        num_list2 = [33, 34, 35, 36, 37, 38, 39, 40]
        result2 = match_degree(num_list2)
        assert_array_equal(result2, [35, 35, 35, 41, 41, 41, 41, 41])
Exemplo n.º 2
0
    def __init__(self,
                 radial_grid,
                 atomic_rad,
                 *,
                 scales,
                 degs,
                 center=np.array([0.0, 0.0, 0.0])):
        """Construct atomic grid for given arguments.

        Parameters
        ----------
        radial_grid : Grid
            Radial grid for x in xrange(1,10):
                pass each unit spherical shell
        atomic_rad : float
            Atomic radium for targit atom
        scales : np.ndarray(N,), keyword-only argument
            Scales for selecting different spherical grids.
        degs : np.ndarray(N+1, dtype=int), keyword-only argument
            Different magic number for each section of atomic radium region
        center : np.ndarray(3,), default to [0., 0., 0.], keyword-only argument
            Central cartesian coordinates of atomic grid

        Raises
        ------
        TypeError
            Radial_grid need to ba an instance of Grid class
        ValueError
            Length of degs should be one more than scales
        """
        scales = np.array(scales)
        degs = np.array(degs)
        # check stage
        if not isinstance(radial_grid, Grid):
            raise TypeError(
                f"Radial_grid is not an instance of Grid, got {type(radial_grid)}."
            )
        if len(degs) == 0:
            raise ValueError("rad_list can't be empty.")
        if len(degs) - len(scales) != 1:
            raise ValueError(
                "degs should have only one more element than scales.")
        if not isinstance(center, np.ndarray):
            raise TypeError(
                f"Center should be a numpy array with 3 entries, got {type(center)}."
            )
        if len(center) != 3:
            raise ValueError(
                f"Center should only have 3 entries, got {len(center)}.")
        # assign stage
        self._center = center
        self._radial_grid = radial_grid
        # initiate atomic grid property as None
        rad_degs = self._find_l_for_rad_list(self._radial_grid.points,
                                             atomic_rad, scales, degs)
        # set real degree to each rad point
        self._rad_degs = match_degree(rad_degs)
        self._points, self._weights, self._indices = self._generate_atomic_grid(
            self._radial_grid, self._rad_degs, center)
        self._size = len(self._weights)
Exemplo n.º 3
0
 def _generate_degree_from_radius(radial_grid, radius, scales, degs):
     """Generate proper degrees for radius."""
     scales = np.array(scales)
     degs = np.array(degs)
     if len(degs) == 0:
         raise ValueError("rad_list can't be empty.")
     if len(degs) - len(scales) != 1:
         raise ValueError(
             "degs should have only one more element than scales.")
     rad_degs = AtomicGrid._find_l_for_rad_list(radial_grid.points, radius,
                                                scales, degs)
     return match_degree(rad_degs)
Exemplo n.º 4
0
    def _generate_degree_from_radius(rgrid, radius, r_sectors, degs):
        """Generate proper degrees for radius.

        Parameters
        ----------
        rgrid : RadialGrid
            A radialgrid instance
        radius : float
            radius of interested atom
        r_sectors : list or np.ndarray
            a list of r_sectors number
        degs : list or np.ndarray
            a list of degs for each radius section

        Returns
        -------
        np.ndarray
            a numpy array of L degree value for each radial point

        Raises
        ------
        ValueError
            Description
        """
        r_sectors = np.array(r_sectors)
        degs = np.array(degs)
        if len(degs) == 0:
            raise ValueError("rad_list can't be empty.")
        if len(degs) - len(r_sectors) != 1:
            raise ValueError(
                "degs should have only one more element than r_sectors.")
        matched_deg = match_degree(degs)
        rad_degs = AtomGrid._find_l_for_rad_list(rgrid.points,
                                                 radius * r_sectors,
                                                 matched_deg)
        return rad_degs