Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean docstrings #243

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion examples/Atom_Grid.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"source": [
"## Construct Atomic Grid\n",
"\n",
"There are multiple ways to construct an atomic grid, for a complete description see the [Atomic_Grid_Construction.ipynb]().\n",
"There are multiple ways to construct an atomic grid, for a complete description see the [Atomic_Grid_Construction.ipynb](.https://grid.qcdevs.org/notebooks/notebooks/atom_grid_construction.html).\n",
"\n",
"Here we construct an atomic grid from a radial grid instance and the degrees of the angular grid centered at the position of $\\textbf{He}$ nucleus. The radial grid is constructed by specifying the number of radial grid points. For more details on the radial and angular grids see [One_dimensional_grids.ipynb](https://grid.qcdevs.org/notebooks/one_dimensional_grids.html) and [Angular_Grid.ipynb](https://grid.qcdevs.org/notebooks/angular_grid.html).\n"
]
Expand Down
34 changes: 21 additions & 13 deletions examples/Atom_Grid_Construction.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/Molecular_Grid.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"source": [
"### Integration\n",
"\n",
"##### Example: Electron Density\n",
"#### Example: Electron Density\n",
"\n",
"This example shows how to use molecular grids to integrate the electron density $\\rho(\\textbf{r})$. This should equal to the number of electrons 16 of Formaldehyde. This is calculated using the [gbasis](https://github.com/theochem/gbasis) package\n"
]
Expand Down
17 changes: 9 additions & 8 deletions src/grid/angular.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
and these are the comments from that translation.

This subroutine is part of a set of subroutines that generate
Lebedev grids [1-6]_ for integration on a sphere. The original
Lebedev grids [1]_ [2]_ [3]_ [4]_ [5]_ [6]_ for integration on a sphere. The original
C-code [1]_ was kindly provided by Dr. Dmitri N. Laikov and
translated into Fortran by Dr. Christoph van Wuellen.
This subroutine was translated from C to fortran77 by hand.
Expand Down Expand Up @@ -295,13 +295,14 @@ class AngularGrid(Grid):
d\theta d\phi \approx \sum_{i}^{N} w_i f(\phi_i, \theta_i),

where :math:`S^2` is the unit-sphere parameterized by the quadrature points
:math:`\theta_i \in [0, 2\pi]` and :math:`\phi_i \in [0, \pi)`, and
:math:`w^{ang}_i` are the weights of the :math:`N` quadrature points.
Just to clarify, the :math:`4\pi` is included in the integration weights.
:math:`\theta_i \in [0, 2\pi]` and :math:`\phi_i \in [0, \pi)`\, and
:math:`w_{i}` are the weights of the :math:`N` quadrature points. The
:math:`4\pi` normalization factor present in the original quadrature scheme
is included in the integration weights.

Two types of angular grids are supported: Lebedev-Laikov grid and symmetric
spherical t-design. Specifically, for spherical t-design, the weights are constant
value of :math:`4 \pi / N`, where :math:`N` is the number of points in the grid.
value of :math:`4 \pi / N`\, where :math:`N` is the number of points in the grid.
The weights are chosen so that the spherical harmonics are normalized.

"""
Expand All @@ -318,7 +319,7 @@ def __init__(

Parameters
----------
degree : int, optional
degree : int or None, optional
Maximum angular degree :math:`l` of spherical harmonics that the angular grid
can integrate accurately. If the angular grid corresponding to the given angular
degree is not supported, the next largest degree is used. If `size` is provided,
Expand All @@ -329,7 +330,7 @@ def __init__(
`size` is used for constructing the angular grid.
cache : bool, optional, keyword-only
If True, then store the points and weights of the AngularGrid in cache
to avoid duplicate grids that have the same `degree`.
to avoid duplicate grids that have the same `degree`\.
method: str, optional, keyword-only
Method for constructing the angular grid. Options are "lebedev" (for Lebedev-Laikov)
and "spherical" (for symmetric spherical t-design).
Expand Down Expand Up @@ -399,7 +400,7 @@ def degree(self):

@property
def method(self):
r"""str: Method used for constructing an angular grid."""
r"""str: Method used for constructing the angular grid."""
return self._method

@staticmethod
Expand Down
63 changes: 31 additions & 32 deletions src/grid/atomgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from __future__ import annotations

import warnings
from typing import Union

import numpy as np
import scipy.constants
Expand Down Expand Up @@ -84,7 +83,7 @@ def __init__(
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.
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
Expand Down Expand Up @@ -168,7 +167,7 @@ def from_preset(
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.
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.
Expand Down Expand Up @@ -235,16 +234,16 @@ def from_pruned(
r_sectors: list | np.ndarray,
d_sectors: list | np.ndarray | None = None,
*,
s_sectors: Union[list, np.ndarray] = None,
s_sectors: list | np.ndarray = None,
center: np.ndarray = None,
rotate: int = 0,
method: str = "lebedev",
):
r"""
Initialize AtomGrid class that splits radial sections into sectors which specified degrees.

Given a sequence of radial sectors :math:`\{a_i\}_{i=1}^Q`, a radius number :math:`R`
and angular degree sectors :math:`\{L_i \}_{i=1}^{Q+1}`. This assigned the degrees
Given a sequence of radial sectors :math:`\{a_i\}_{i=1}^Q`\, a radius number :math:`R`
and angular degree sectors :math:`\{L_i \}_{i=1}^{Q+1}`\. This assigned the degrees
to the following radial points:

.. math::
Expand All @@ -264,8 +263,8 @@ def from_pruned(
(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.
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.
Expand Down Expand Up @@ -434,11 +433,11 @@ def convert_cartesian_to_spherical(self, points: np.ndarray = None, center: np.n
\phi &= arc\cos(\frac{z}{r})
\end{align}

with the canonical choice :math:`r=0`, then :math:`\theta,\phi = 0`.
with the canonical choice :math:`r=0`\, then :math:`\theta,\phi = 0`\.
If the `points` attribute is not specified, then atomic grid points are used
and the canonical choice when :math:`r=0`, is the points
and the canonical choice when :math:`r=0`\, is the points
:math:`(r=0, \theta_j, \phi_j)` where :math:`(\theta_j, \phi_j)` come
from the Angular grid with the degree at :math:`r=0`.
from the Angular grid with the degree at :math:`r=0`\.

Parameters
----------
Expand All @@ -453,7 +452,7 @@ def convert_cartesian_to_spherical(self, points: np.ndarray = None, center: np.n
-------
ndarray(N, 3)
Spherical coordinates of points respect to the center denoted as
(radius :math:`r`, azimuthal :math:`\theta`, polar :math:`\phi`).
(radius :math:`r`\, azimuthal :math:`\theta`\, polar :math:`\phi`).

"""
is_atomic = False
Expand All @@ -480,7 +479,7 @@ def convert_cartesian_to_spherical(self, points: np.ndarray = None, center: np.n
def integrate_angular_coordinates(self, func_vals: np.ndarray):
r"""Integrate the angular coordinates of a sequence of functions.

Given a series of functions :math:`f_k \in L^2(\mathbb{R}^3)`, this returns the values
Given a series of functions :math:`f_k \in L^2(\mathbb{R}^3)`\, this returns the values

.. math::
f_k(r_i) = \int \int f(r_i, \theta, \phi) sin(\phi) d\theta d\phi
Expand Down Expand Up @@ -537,7 +536,7 @@ def spherical_average(self, func_vals: np.ndarray):
f_{avg}(r) := \frac{\int \int f(r, \theta, \phi) \sin(\phi) d\theta d\phi}{4 \pi}.

The definition is chosen such that :math:`\int f_{avg}(r) 4\pi r^2 dr`
matches the full integral :math:`\int \int \int f(x,y,z)dxdydz`.
matches the full integral :math:`\int \int \int f(x,y,z)dxdydz`\.

Parameters
----------
Expand All @@ -547,7 +546,7 @@ def spherical_average(self, func_vals: np.ndarray):
Returns
-------
CubicSpline:
Cubic spline with input r in the positive real axis and output :math:`f_{avg}(r)`.
Cubic spline with input r in the positive real axis and output :math:`f_{avg}(r)`\.

"""
# Integrate f(r, theta, phi) sin(phi) d\theta d\phi
Expand All @@ -561,17 +560,17 @@ def radial_component_splines(self, func_vals: np.ndarray):
r"""
Return spline to interpolate radial components wrt to expansion in real spherical harmonics.

For each pt :math:`r_i` of the atomic grid with associated angular degree :math:`l_i`,
For each pt :math:`r_i` of the atomic grid with associated angular degree :math:`l_i`\,
the function :math:`f(r_i, \theta, \phi)` is projected onto the spherical
harmonic expansion:

.. math::
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 :math:`Y^m_l` is the real Spherical harmonic of degree :math:`l` and order :math:`m`.
where :math:`Y^m_l` is the real Spherical harmonic of degree :math:`l` and order :math:`m`\.
The radial components :math:`\rho^{lm}(r_i)` are calculated via integration on
the :math:`i`th Lebedev/angular grid of the atomic grid:
the :math:`i`\th Lebedev/angular grid of the atomic grid:

.. math::
\rho^{lm}(r_i) = \int \int f(r_i, \theta, \phi) Y^m_l(\theta, \phi) \sin(\phi)
Expand All @@ -588,9 +587,9 @@ def radial_component_splines(self, func_vals: np.ndarray):
-------
list[scipy.PPoly]
A list of size :math:`(l_{max}/2 + 1)^2` of CubicSpline object for interpolating the
coefficients :math:`\rho^{lm}(r)`. The input of spline is array
of :math:`N` points on :math:`[0, \infty)` and the output is :math:`\{\rho^{lm}(r_i)\}`.
The list starts with degrees :math:`l=0,\cdots l_{max}`, and the for each degree,
coefficients :math:`\rho^{lm}(r)`\. The input of spline is array
of :math:`N` points on :math:`[0, \infty)` and the output is :math:`\{\rho^{lm}(r_i)\}`\.
The list starts with degrees :math:`l=0,\cdots l_{max}`\, and the for each degree,
the zeroth order spline is first, followed by positive orders then negative.

"""
Expand All @@ -616,7 +615,7 @@ def radial_component_splines(self, func_vals: np.ndarray):
num_nonzero_sph = (self.degrees[i] // 2 + 1) ** 2
radial_components[num_nonzero_sph:, i] = 0.0

# Return a spline for each spherical harmonic with maximum degree `self.l_max // 2`.
# Return a spline for each spherical harmonic with maximum degree `self.l_max // 2`\.
return [CubicSpline(x=self.rgrid.points, y=sph_val) for sph_val in radial_components]

def interpolate(self, func_vals: np.ndarray):
Expand All @@ -628,7 +627,7 @@ def interpolate(self, func_vals: np.ndarray):
.. math::
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 :math:`\sum_i \rho_{ilm}(r)`.
A cubic spline is used to interpolate the radial functions :math:`\sum_i \rho_{ilm}(r)`\.
This is then multiplied by the corresponding spherical harmonics at all
:math:`(\theta_j, \phi_j)` angles and summed to obtain the equation above.

Expand All @@ -649,10 +648,10 @@ def interpolate(self, func_vals: np.ndarray):
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`\=2,3) are supported for the derivatives wrt to radial components.
deriv_spherical : bool
If True, then returns the derivatives with respect to spherical coordinates
:math:`(r, \theta, \phi)`. Default False.
:math:`(r, \theta, \phi)`\. Default False.
only_radial_deriv : bool
If true, then the derivative wrt to radius :math:`r` is returned.

Expand Down Expand Up @@ -681,7 +680,7 @@ def interpolate_low(points, deriv=0, deriv_spherical=False, only_radial_deriv=Fa
for the derivatives wrt to radial components. `deriv=3` only returns a constant.
deriv_spherical : bool
If True, then returns the derivatives with respect to spherical coordinates
:math:`(r, \theta, \phi)`. Default False.
:math:`(r, \theta, \phi)`\. Default False.
only_radial_deriv : bool
If true, then the derivative wrt to radius :math:`r` is returned.

Expand Down Expand Up @@ -769,8 +768,8 @@ def _input_type_check(rgrid: OneDGrid, center: np.ndarray):
def _generate_degree_from_radius(
rgrid: OneDGrid,
radius: float,
r_sectors: Union[list, np.ndarray],
d_sectors: Union[list, np.ndarray],
r_sectors: list | np.ndarray,
d_sectors: list | np.ndarray,
method: str = "lebedev",
):
"""
Expand All @@ -784,8 +783,8 @@ def _generate_degree_from_radius(
Radius of interested atom in atomic units.
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.
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)
Sequence of angular degrees for each radial sector of `r_sectors` in the pruned grid.
method: str, optional
Expand Down Expand Up @@ -830,8 +829,8 @@ def _find_degrees_for_radial_points(
Radial grid points in angstrom.
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.
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)
Sequence of angular degrees for each radial sector of `r_sectors` in the pruned grid.

Expand Down
8 changes: 4 additions & 4 deletions src/grid/basegrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def integrate(self, *value_arrays):
)

def get_localgrid(self, center, radius):
"""Create a grid contain points within the given radius of center.
"""Create a grid containing points within the given radius of center.

Parameters
----------
Expand Down Expand Up @@ -202,7 +202,7 @@ def moments(
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 :math:`\textbf{R}_c = (X_c, Y_c, Z_c)` is the center of the moment,
:math:`\f(r)` is the density, and :math:`(n_x, n_y, n_z)` are the Cartesian orders.
:math:`f(r)` is the function, and :math:`(n_x, n_y, n_z)` are the Cartesian orders.

The spherical/pure moments with :math:`(l, m)` parameter are:

Expand All @@ -227,7 +227,7 @@ def moments(
----------
orders : int
Generates all orders with Horton order depending on the type of the multipole
moment `type_mom`.
moment `\type_mom`\.
centers : ndarray(M, 3)
The centers :math:`\textbf{R}_c` of the moments to compute from.
func_vals : ndarray(N,)
Expand All @@ -242,7 +242,7 @@ def moments(
Returns
-------
ndarray(L, M), or (ndarray(L, M), list)
Computes the moment integral of the function on the `m`th center for all orders.
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) ,...].

Expand Down
Loading
Loading