grid.atomgrid module
Atomic Grid Module.
- class AtomGrid(rgrid, degrees=[50], *, sizes=None, center=None, rotate=0, method='lebedev')[source]
Bases:
Grid
Atomic grid construction class for integrating three-dimensional functions.
Atomic grid is composed of a radial grid \(\{(r_i, w_i)\}_{i=1}^{N}\) meant to integrate the radius coordinate in spherical coordinates. Further, each radial point is associated with an Angular (Lebedev or Symmetric spherical t-design) grid \(\{(\theta^i_j, \phi^i_j, w_j^i)\}_{j=1}^{M_i}\) that integrates over a sphere (angles in spherical coordinates). The atomic grid points can also be centered at a given location.
- __init__(rgrid, degrees=[50], *, sizes=None, center=None, rotate=0, method='lebedev')[source]
Construct atomic grid for given arguments.
- Parameters
rgrid (OneDGrid) – The (one-dimensional) radial grid representing the radius of spherical grids.
degrees (ndarray(N, dtype=int) or list, optional) – Sequence of angular grid degrees used for constructing spherical grids at each radial grid point. If only one degree is given, the specified degree is used for all spherical grids. If the given degree is not supported, the next largest degree is used.
sizes (ndarray(N, dtype=int) or list, keyword-only) – Sequence of angular grid sizes used for constructing spherical grids at each radial grid point. If only one size is given, the specified size is used for all spherical grids. If the given size is not supported, the next largest size is used. If both degrees and sizes are given, size are used for constructing the angular grid.
center (ndarray(3,), optional, keyword-only) – Cartesian coordinates of the grid center. If None, the origin is used.
rotate (int, optional, keyword-only) – Integer used as a seed for generating random rotation matrices to rotate the angular spherical grids at each radial grid point. If the integer is zero, then no rotate is used.
method (str, optional, keyword-only) – Method for constructing the angular grid. Options are “lebedev” (for Lebedev-Laikov) and “spherical” (for symmetric spherical t-design).
- property basis
Generate spherical harmonic basis evaluated on atomic grid points.
- Type
ndarray(N, 3)
- property center
Cartesian coordinates of the grid center.
- Type
ndarray(3,)
- convert_cartesian_to_spherical(points=None, center=None)[source]
Convert a set of points from Cartesian to spherical coordinates.
\[\begin{split}\begin{align} r &= \sqrt{x^2 + y^2 + z^2}\\ \theta &= arc\tan (\frac{y}{x})\\ \phi &= arc\cos(\frac{z}{r}) \end{align}\end{split}\]with the canonical choice \(r=0\), then \(\theta,\phi = 0\). If the points attribute is not specified, then atomic grid points are used and the canonical choice when \(r=0\), is the points \((r=0, \theta_j, \phi_j)\) where \((\theta_j, \phi_j)\) come from the Angular grid with the degree at \(r=0\).
- Parameters
points (ndarray(N, 3), optional) – Three-dimensions Cartesian coordinates of points in atomic units. If None, the atomic grid points will be used.
center (ndarray(3,), optional) – Three-dimensional Cartesian coordinates of the center of coordinate system in atomic units. If None, the atomic grid center will be used.
- Returns
Spherical coordinates of points respect to the center denoted as (radius \(r\), azimuthal \(\theta\), polar \(\phi\)).
- Return type
ndarray(N, 3)
- property degrees
Return the degree of each angular grid at each radial point.
- Type
ndarray(L,)
- classmethod from_preset(atnum, preset, rgrid=None, center=None, rotate=0, method='lebedev')[source]
Construct an atomic grid with pre-defined angular grids for a given atomic number.
- Parameters
atnum (int) – The atomic number.
preset (str, optional) – The name of pre-defined grid specifying the radial sectors and their corresponding number of angular grid points. Supported options include our custom presets: ‘coarse’, ‘medium’, ‘fine’, ‘veryfine’, ‘ultrafine’, and ‘insane’, as well as, other standard pre-defined grids including: ‘sg_0’, ‘sg_1’, ‘sg_2’, and ‘sg_3’, and the Ochsenfeld grids: ‘g1’, ‘g2’, ‘g3’, ‘g4’, ‘g5’, ‘g6’, and ‘g7’, with higher number indicating greater accuracy but denser grid. See Notes for more information.
rgrid (OneDGrid, optional) – The 1D radial grid representing the radius of spherical grids. If None, a default radial grid (PowerRTransform of UniformInteger grid) for the give atnum is constructed.
center (ndarray(3,), optional) – Cartesian coordinates of the grid center. If None, the origin is used.
rotate (int, optional) – Integer used as a seed for generating random rotation matrices to rotate the angular spherical grids at each radial grid point. If 0, then no rotate is made.
method (str, optional) – Method for constructing the angular grid. Options are “lebedev” (for Lebedev-Laikov) and “spherical” (for symmetric spherical t-design).
Notes
The standard and Ochsenfeld presets were not designed with symmetric spherical t-design in mind.
The “standard grids” 1 “SG-0” and “SG-1” are designed for large molecules with LDA (GGA) functionals, whereas “SG-2” and “SG-3” are designed for Meta-GGA functionals and B95/Minnesota functionals, respectively.
The Ochsenfeld pruned grids 2 are obtained based on the paper.
References
- 1
Y. Shao, et al. Advances in molecular quantum chemistry contained in the Q-Chem 4 program package. Mol. Phys. 113, 184-215 (2015)
- 2
Laqua, H., Kussmann, J., & Ochsenfeld, C. (2018). An improved molecular partitioning scheme for numerical quadratures in density functional theory. The Journal of Chemical Physics, 149(20).
- classmethod from_pruned(rgrid, radius, r_sectors, d_sectors=None, *, s_sectors=None, center=None, rotate=0, method='lebedev')[source]
Initialize AtomGrid class that splits radial sections into sectors which specified degrees.
Given a sequence of radial sectors \(\{a_i\}_{i=1}^Q\), a radius number \(R\) and angular degree sectors \(\{L_i \}_{i=1}^{Q+1}\). This assigned the degrees to the following radial points:
\[\begin{split}\begin{align*} &L_1 \text{ when } r < R a_1 \\ &L_2 \text{ when } R a_1 \leq r < R a_2 \vdots \\ &L_{Q+1} \text{ when } R a_{Q} < r. \end{align*}\end{split}\]- Parameters
rgrid (OneDGrid) – The (one-dimensional) radial grid representing the radius of spherical grids.
radius (float) – The atomic radius to be multiplied with r_sectors in atomic units (to make the radial sectors atom specific).
r_sectors (list or ndarray(S,)) – Sequence of boundary radius (in atomic units) specifying sectors of the pruned radial grid. The first sector is
(0, radius*r_sectors[0])
, then(radius*r_sectors[0], radius*r_sectors[1])
, and so on.d_sectors (list or ndarray(S + 1, dtype=int) or None) – Sequence of angular degrees for each radial sector of r_sectors in the pruned grid. If None, then s_sectors should be given.
s_sectors (list or ndarray(S + 1, dtype=int) or None, optional, keyword-only) – Sequence of angular sizes for each radial sector of r_sectors in the pruned grid. If both d_sectors and s_sectors are given, s_sectors is used.
center (ndarray(3,), optional) – Three-dimensional Cartesian coordinates of the grid center in atomic units. If None, the origin is used.
rotate (int, optional) – Integer used as a seed for generating random rotation matrices to rotate the angular spherical grids at each radial grid point. If the integer is zero, then no rotate is used.
method (str, optional) – Method for constructing the angular grid. Options are “lebedev” (for Lebedev-Laikov) and “spherical” (for symmetric spherical t-design).
- Returns
Generated AtomGrid instance for this special init method.
- Return type
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- get_shell_grid(index, r_sq=True)[source]
Get the spherical integral grid at radial point from specified index.
The spherical integration grid has points scaled with the ith radial point and weights multiplied by the ith weight of the radial grid.
Note that when \(r=0\) then the Cartesian points are all zeros.
- Parameters
index (int) – Index of radial points.
r_sq (bool, default True) – If true, multiplies the angular grid weights with r**2.
- Returns
Instance of AngularGrid for the given radial index position and weights.
- Return type
- property indices
Indices saved for each spherical shell.
- Type
ndarray(M+1,)
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- integrate_angular_coordinates(func_vals)[source]
Integrate the angular coordinates of a sequence of functions.
Given a series of functions \(f_k \in L^2(\mathbb{R}^3)\), this returns the values
\[f_k(r_i) = \int \int f(r_i, \theta, \phi) sin(\phi) d\theta d\phi\]on each radial point \(r_i\) in the atomic grid.
- Parameters
func_vals (ndarray(..., N)) – The function values evaluated on all \(N\) points on the atomic grid for many types of functions. This can also be one-dimensional.
- Returns
The function \(f_{...}(r_i)\) on each \(M\) radial points.
- Return type
ndarray(…, M)
- interpolate(func_vals)[source]
Return function that interpolates (and its derivatives) from function values.
Any real-valued function \(f(r, \theta, \phi)\) can be decomposed as
\[f(r, \theta, \phi) = \sum_l \sum_{m=-l}^l \sum_i \rho_{ilm}(r) Y_{lm}(\theta, \phi)\]A cubic spline is used to interpolate the radial functions \(\sum_i \rho_{ilm}(r)\). This is then multiplied by the corresponding spherical harmonics at all \((\theta_j, \phi_j)\) angles and summed to obtain the equation above.
- Parameters
func_vals (ndarray(N,)) – The function values evaluated on all \(N\) points on the atomic grid.
- Returns
Callable function that interpolates the function and its derivative provided. The function takes the following attributes:
- pointsndarray(N, 3)
Cartesian coordinates of \(N\) points to evaluate the splines on.
- derivint, optional
If deriv is zero, then only returns function values. If it is one, then returns the first derivative of the interpolated function with respect to either Cartesian or spherical coordinates. Only higher-order derivatives (`deriv`=2,3) are supported for the derivatives wrt to radial components.
- deriv_sphericalbool
If True, then returns the derivatives with respect to spherical coordinates \((r, \theta, \phi)\). Default False.
- only_radial_derivbool
If true, then the derivative wrt to radius \(r\) is returned.
This function returns the following.
- ndarray(M,…):
The interpolated function values or its derivatives with respect to Cartesian \((x,y,z)\) or if deriv_spherical then \((r, \theta, \phi)\) or if only_radial_derivs then derivative wrt to \(r\) is only returned.
- Return type
Callable[[ndarray(M, 3), int] -> ndarray(M)]
- property l_max
Largest angular degree L value in angular grids.
- Type
int
- property method
Method used for constructing an angular grid.
- Type
str
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- property n_shells
Number of shells in radial points.
- Type
int
- property points
3D Cartesian coordinates of the grid points in atomic units.
- Type
ndarray(N, 3)
- radial_component_splines(func_vals)[source]
Return spline to interpolate radial components wrt to expansion in real spherical harmonics.
For each pt \(r_i\) of the atomic grid with associated angular degree \(l_i\), the function \(f(r_i, \theta, \phi)\) is projected onto the spherical harmonic expansion:
\[f(r_i, \theta, \phi) \approx \sum_{l=0}^{l_i} \sum_{m=-l}^l \rho^{lm}(r_i) Y^m_l(\theta, \phi)\]where \(Y^m_l\) is the real Spherical harmonic of degree \(l\) and order \(m\). The radial components \(\rho^{lm}(r_i)\) are calculated via integration on the :math:`i`th Lebedev/angular grid of the atomic grid:
\[\rho^{lm}(r_i) = \int \int f(r_i, \theta, \phi) Y^m_l(\theta, \phi) \sin(\phi) d\theta d\phi,\]and then interpolated using a cubic spline over all radial points of the atomic grid.
- Parameters
func_vals (ndarray(N,)) – The function values evaluated on all \(N\) points on the atomic grid.
- Returns
A list of size \((l_{max}/2 + 1)^2\) of CubicSpline object for interpolating the coefficients \(\rho^{lm}(r)\). The input of spline is array of \(N\) points on \([0, \infty)\) and the output is \(\{\rho^{lm}(r_i)\}\). The list starts with degrees \(l=0,\cdots l_{max}\), and the for each degree, the zeroth order spline is first, followed by positive orders then negative.
- Return type
list[scipy.PPoly]
- property rotate
Integer representing the seed for rotating the angular grid.
- Type
int
- save(filename)[source]
Save atomic grid attributes as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- spherical_average(func_vals)[source]
Return spline of the spherical average of a function.
This function takes a function \(f\) evaluated on the atomic grid points and returns the spherical average of it defined as:
\[f_{avg}(r) := \frac{\int \int f(r, \theta, \phi) \sin(\phi) d\theta d\phi}{4 \pi}.\]The definition is chosen such that \(\int f_{avg}(r) 4\pi r^2 dr\) matches the full integral \(\int \int \int f(x,y,z)dxdydz\).
- Parameters
func_vals (ndarray(N,)) – The function values evaluated on all \(N\) points on the atomic grid.
- Returns
Cubic spline with input r in the positive real axis and output \(f_{avg}(r)\).
- Return type
CubicSpline
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)