Exemplo n.º 1
0
 def test_get_atomic_radii(self):
     """Test get_cov_radii function for all atoms."""
     # fmt: off
     Bragg_Slater = np.array([
         np.nan, 0.25, np.nan, 1.45, 1.05, 0.85, 0.7, 0.65, 0.6, 0.5, np.nan,
         1.8, 1.5, 1.25, 1.1, 1., 1., 1., np.nan, 2.2, 1.8, 1.6, 1.4, 1.35,
         1.4, 1.4, 1.4, 1.35, 1.35, 1.35, 1.35, 1.3, 1.25, 1.15, 1.15, 1.15,
         np.nan, 2.35, 2., 1.8, 1.55, 1.45, 1.45, 1.35, 1.3, 1.35, 1.4, 1.6,
         1.55, 1.55, 1.45, 1.45, 1.4, 1.4, np.nan, 2.6, 2.15, 1.95, 1.85,
         1.85, 1.85, 1.85, 1.85, 1.85, 1.8, 1.75, 1.75, 1.75, 1.75, 1.75,
         1.75, 1.75, 1.55, 1.45, 1.35, 1.35, 1.3, 1.35, 1.35, 1.35, 1.5,
         1.9, 1.8, 1.6, 1.9, np.nan, np.nan
     ])
     Cambridge = np.array([
         np.nan, 0.31, 0.28, 1.28, 0.96, 0.84, 0.76, 0.71, 0.66, 0.57, 0.58,
         1.66, 1.41, 1.21, 1.11, 1.07, 1.05, 1.02, 1.06, 2.03, 1.76, 1.7, 1.6,
         1.53, 1.39, 1.39, 1.32, 1.26, 1.24, 1.32, 1.22, 1.22, 1.20, 1.19,
         1.20, 1.20, 1.16, 2.20, 1.95, 1.9, 1.75, 1.64, 1.54, 1.47, 1.46,
         1.42, 1.39, 1.45, 1.44, 1.42, 1.39, 1.39, 1.38, 1.39, 1.40, 2.44,
         2.15, 2.07, 2.04, 2.03, 2.01, 1.99, 1.98, 1.98, 1.96, 1.94, 1.92,
         1.92, 1.89, 1.90, 1.87, 1.87, 1.75, 1.7, 1.62, 1.51, 1.44, 1.41,
         1.36, 1.36, 1.32, 1.45, 1.46, 1.48, 1.40, 1.5, 1.5,
     ])
     # fmt: on
     all_index = np.arange(1, 87)
     bragg = get_cov_radii(all_index, type="bragg")
     assert_allclose(bragg, Bragg_Slater[1:] * 1.8897261339213)
     bragg = get_cov_radii(all_index, type="cambridge")
     assert_allclose(bragg, Cambridge[1:] * 1.8897261339213)
Exemplo n.º 2
0
    def __init__(self, radii=None, order=3):
        r"""Initialize class.

        Parameters
        ----------
        radii : dict, optional
            Dictionary of atomic number and corresponding atomic radius.
            If None, Bragg-Slater empirically measured covalent radii are used.
        order : int, optional
            Order of iteration for switching function.

        """
        if not isinstance(order, int):
            raise ValueError(f"order should be an integer, got {type(order)}")
        self._order = order
        # make dictionary of covalent radius for elements up to Z=86
        data = get_cov_radii(np.arange(1, 87, 1), "bragg")
        self._radii = dict([(i + 1, radius) for i, radius in enumerate(data)])
        # update given covalent radii
        if radii is not None:
            if not isinstance(radii, dict):
                raise TypeError(
                    f"radii should be a dictionary, got {type(radii)}")
            if not np.all([isinstance(k, int) for k in radii.keys()]):
                raise TypeError("radii keys have non-integers value")
            self._radii.update(radii)
Exemplo n.º 3
0
 def test_raise_errors(self):
     """Test raise proper errors."""
     with self.assertRaises(ValueError):
         get_cov_radii(3, type="random")
     with self.assertRaises(ValueError):
         get_cov_radii(0)
     with self.assertRaises(ValueError):
         get_cov_radii([3, 5, 0])
Exemplo n.º 4
0
    def test_raise_errors(self):
        """Test raise proper errors."""
        with self.assertRaises(ValueError):
            get_cov_radii(3, type="random")
        with self.assertRaises(ValueError):
            get_cov_radii(0)
        with self.assertRaises(ValueError):
            get_cov_radii([3, 5, 0])

        with self.assertRaises(ValueError):
            pts = np.random.rand(10)
            convert_cart_to_sph(pts, np.zeros(3))
        with self.assertRaises(ValueError):
            pts = np.random.rand(10, 3, 1)
            convert_cart_to_sph(pts, np.zeros(3))
        with self.assertRaises(ValueError):
            pts = np.random.rand(10, 2)
            convert_cart_to_sph(pts, np.zeros(3))
        with self.assertRaises(ValueError):
            pts = np.random.rand(10, 3)
            convert_cart_to_sph(pts, np.zeros(2))
Exemplo n.º 5
0
from gbasis.wrappers import from_iodata

molecule = load_one("h2o.fchk")
basis = from_iodata(molecule)
q = np.array([0.1])
R = np.array([[2.574156, -0.181816, -2.453822]])
alc_hf = Alchemical_tools(
    basis,
    molecule,
    point_charge_positions=R,
    point_charges_values=q,
    coord_type="cartesian",
    k="HF",
)
r0 = 1e-10
radii = get_cov_radii(molecule.atnums)
n_rad_points = 100
deg = 5
onedgrid = GaussChebyshev(n_rad_points)
molecule_at_grid = []
for i in range(len(molecule.atnums)):
    Rad = BeckeTF.find_parameter(onedgrid.points, r0, radii[i])
    rad_grid = BeckeTF(r0, Rad).transform_grid(onedgrid)
    molecule_at_grid = molecule_at_grid + [
        AtomicGrid.special_init(rad_grid, radii[i], degs=[deg], scales=[])
    ]
molgrid = MolGrid(molecule_at_grid, molecule.atnums)
alc_lda = Alchemical_tools(
    basis,
    molecule,
    point_charge_positions=R,
Exemplo n.º 6
0
    def __init__(self,
                 atomic_grids,
                 numbers,
                 aim_weights="becke",
                 store=False):
        """Initialize molgrid class.

        Parameters
        ----------
        atomic_grids : list[AtomicGrid]
            list of atomic grid
        radii : np.ndarray(N,)
            Radii for each atom in the molecular grid
        aim_weights : str or np.ndarray(K,), default to "becke"
            Atoms in molecule weights. If str, certain function will be called
            to compute aim_weights, if np.ndarray, it will be treated as the
            aim_weights
        """
        # initialize these attributes
        numbers = np.array(numbers)
        radii = get_cov_radii(numbers)
        self._coors = np.zeros((len(radii), 3))
        self._indices = np.zeros(len(radii) + 1, dtype=int)
        self._size = np.sum([atomgrid.size for atomgrid in atomic_grids])
        self._points = np.zeros((self._size, 3))
        self._weights = np.zeros(self._size)
        self._atomic_grids = atomic_grids if store else None

        for i, atom_grid in enumerate(atomic_grids):
            self._coors[i] = atom_grid.center
            self._indices[i + 1] += self._indices[i] + atom_grid.size
            self._points[self._indices[i]:self._indices[i +
                                                        1]] = atom_grid.points
            self._weights[self._indices[i]:self.
                          _indices[i + 1]] = atom_grid.weights

        if isinstance(aim_weights, str):
            if aim_weights == "becke":
                # Becke weights are computed for "chunks" of grid points
                # to counteract the scaling of the memory usage of the
                # vectorized implementation of the Becke partitioning.
                chunk_size = max(1,
                                 (10 * self._size) // self._coors.shape[0]**2)
                self._aim_weights = np.concatenate([
                    BeckeWeights.generate_becke_weights(
                        self._points[ibegin:ibegin + chunk_size],
                        radii,
                        self._coors,
                        pt_ind=(self._indices - ibegin).clip(min=0),
                    ) for ibegin in range(0, self._size, chunk_size)
                ])
            else:
                raise NotImplementedError(
                    f"Given aim_weights is not supported, got {aim_weights}")
        elif isinstance(aim_weights, np.ndarray):
            if aim_weights.size != self.size:
                raise ValueError(
                    "aim_weights is not the same size as grid.\n"
                    f"aim_weights.size: {aim_weights.size}, grid.size: {self.size}."
                )
            self._aim_weights = aim_weights

        else:
            raise TypeError(
                f"Not supported aim_weights type, got {type(aim_weights)}.")