nitrogen.basis¶
Basis set functions including discrete-variable
representations (DVRs) and finite-basis representations
(FBRs). The main objects are the GriddedBasis class
and its sub-classes GenericDVR and NDBasis.
See Discrete-variable representation (DVR) bases for a tutorial.
General gridded bases |
|
|---|---|
General quadrature grid basis. |
|
Direct sum of |
|
Discrete-variable representation bases |
|
Parent DVR basis class. |
|
Simple one-dimensional DVRs. |
|
Contracted DVR. |
|
FBR quadrature bases |
|
Parent class for \(n\)-d quadrature bases |
|
A sine-cosine (real Fourier) basis. |
|
Associated Legendre polynomials. |
|
Real spherical harmonics. |
|
Two-dimensional harmonic oscillator. |
|
Radial HO basis in \(d\) dimensions. |
|
- class nitrogen.basis.ConcatenatedBasis(bases)¶
Bases:
nitrogen.basis.genericbasis.GriddedBasisA concatenated set of GriddedBasis basis sets. It is assumed these have compatible grid methods.
Create a GriddedBasis
- Parameters
gridpts ((nd, ng) array_like) – The ng grid points for each of the nd coordinates.
nb (int) – The number of basis functions.
wgtfun (DFun, optional) – The integration weight function
- class nitrogen.basis.Contracted(U, prim_dvr)¶
Bases:
nitrogen.basis.dvr.GenericDVRA contracted basis DVR class (usually for PO-DVRs).
- prim_dvr¶
The primitive basis
- Type
- W¶
The transformation matrix from the contracted DVR to the primitive DVR
- Type
ndarray
- Parameters
U ((n,m) ndarray) – A unitary operator defining the contracted basis. n is the size of the primitive basis. m is the size of the contracted basis.
prim_dvr (GenericDVR) – The primitive DVR
- class nitrogen.basis.GenericDVR(grid, D, D2)¶
Bases:
nitrogen.basis.genericbasis.GriddedBasisA super-class for generic 1D DVRs.
- num¶
The number of DVR grid points
- Type
int
- grid¶
The DVR grid points
- Type
ndarray
- D¶
First derivative operator.
- Type
ndarray
- D2¶
Second derivative operator.
- Type
ndarray
Create a GriddedBasis
- Parameters
gridpts ((nd, ng) array_like) – The ng grid points for each of the nd coordinates.
nb (int) – The number of basis functions.
wgtfun (DFun, optional) – The integration weight function
- matchfun(f)¶
Calculate DVR coefficients to match a function at DVR grid points.
- Parameters
f (function) – The function to be matched.
- Returns
coeff – A (num,1) array with the DVR basis function coefficients.
- Return type
ndarray
- class nitrogen.basis.GriddedBasis(gridpts, nb, wgtfun=None)¶
Bases:
objectA generic super-class for gridded basis sets, including DVRs and FBRs equipped with quadrature grids.
- nb¶
The number of basis functions
- Type
int
- nd¶
The number of grid coordinates
- Type
int
- ng¶
The number of grid points
- Type
int
- gridpts¶
The grid points
- Type
(nd,ng) ndarray
Create a GriddedBasis
- Parameters
gridpts ((nd, ng) array_like) – The ng grid points for each of the nd coordinates.
nb (int) – The number of basis functions.
wgtfun (DFun, optional) – The integration weight function
- getDQuadOp(var)¶
calculate the explicit basis-to-quadrature derivative grid transformation matrix
- getQuadOp()¶
calculate the explicit basis-to-quadrature grid transformation matrix
- class nitrogen.basis.LegendreLMCosBasis(m, lmax, Nq=None)¶
Bases:
nitrogen.basis.ndbasis.NDBasisAssociated Legendre polynomials with cosine argument, \(F_\ell^m(\theta) \propto P_\ell^m(\cos\theta)\). See
LegendreLMCos.Quadrature is performed with a Gauss-Legendre grid.
These functions are eigenfunctions of the differential operator
\[-\frac{\partial^2}{\partial \theta^2} - \cot \theta \frac{\partial}{\partial \theta} + \frac{m^2}{\sin^2\theta}\]with eigenvalue \(\ell(\ell+1)\).
- m¶
The associated Legendre order.
- Type
int
- l¶
A list of l-indices of the basis functions.
- Type
ndarray
See also
nitrogen.special.LegendreLMCosDFun sub-class for associated Legendre functions.
Create a LegendreLMCosBasis.
- Parameters
m (int) – The associated Legendre order.
lmax (int) – The maximum l index.
Nq (int, optional) – The number of quadrature points. The default is 2*lmax + 1.
- class nitrogen.basis.NDBasis(basisfun, wgtfun, qgrid, wgt)¶
Bases:
nitrogen.basis.genericbasis.GriddedBasisA generic multi-dimensional finite basis representation supporting quadrature integration/transformation.
NDBasisobjects define a set of \(N_b\) basis functions, \(\phi_i(\vec{x})\), \(i = 0,\ldots,N_b - 1\), where \(\vec{x}\) is an \(n_d\)-dimensional coordinate vector. Matrix elements with these functions are defined with respect to a weighted integral,\[\langle \phi_i \vert \phi_j \rangle = \int d\vec{x}\,\Omega(\vec{x}) \phi_i(\vec{x}) \phi_j(\vec{x}),\]where \(\Omega(\vec{x})\) is the weight function (
NDBasis.wgtfun).These integrals can be approximated with a quadrature over \(N_q\) (possibly scattered) grid points \(\vec{x}_k\),
\[\int d\vec{x}\, \Omega(\vec{x}) f(\vec{x}) \approx \sum_{k=0}^{N_q-1} w_k f(\vec{x}_k),\]where \(w_k\) are the quadrature weights (
NDBasis.wgt).- nd¶
The number of dimensions (i.e. coordinates)
- Type
int
- Nb¶
The number of basis functions
- Type
int
- Nq¶
The number of quadrature points
- Type
int
- qgrid¶
The quadrature grid.
- Type
(nd,`Nq`) ndarray
- wgt¶
The quadrature weights.
- Type
(Nq,) ndarray
- bas¶
The basis functions evaluated on the quadrature grid.
- Type
(Nb,`Nq`) ndarray
Initialize a generic NDBasis.
- Parameters
- fbrToQuad(v, axis=0)¶
Transform an axis from the FBR to the quadrature grid representation.
- Parameters
v ((...,`Nb`,...) ndarray) – An array with the axis index spanned by this basis.
- Returns
w – The transformed array.
- Return type
(…, Nq, …) ndarray
- quadD(x, var, axis=0)¶
Apply the quadrature representation derivative operator.
- Parameters
x ((...,`Nq`,...) ndarray) – The quadrature representation array.
var (int) – The coordinate of the derivative.
axis (int, optional) – The quadrature axis. The default is 0.
- Returns
y – The result.
- Return type
(…,`Nq`,…) ndarray
- quadDH(x, var, axis=0)¶
Apply the quadrature representation D^dagger operator.
- Parameters
x ((...,`Nq`,...) ndarray) – The quadrature representation array.
var (int) – The coordinate of the derivative.
axis (int, optional) – The quadrature axis. The default is 0.
- Returns
y – The result.
- Return type
(…,`Nq`,…) ndarray
- quadToFbr(w, axis=0)¶
Transform an axis from the quadrature representation to the FBR.
- Parameters
w ((...,`Nq`,...) ndarray) – An array with the axis index spanned by this quadrature.
- Returns
v – The transformed array.
- Return type
(…, Nb, …) ndarray
- class nitrogen.basis.RadialHOBasis(vmax, rmax, ell, d=2, Nr=None)¶
Bases:
nitrogen.basis.ndbasis.NDBasisA radial basis for a harmonic oscillator in \(d\) dimensions.
Create a RadialHO basis.
- Parameters
vmax (int) – The number of basis functions is vmax - ell + 1. This is not the conventional vibrational quantum number.
rmax (float) – The radial extent of the basis.
ell (scalar) – The generalized angular momentum quantum number.
d (int) – The dimension, \(d\).
Nr (int, optional) – The number of quadrature points over \(r\). The default is vmax + 3.
- class nitrogen.basis.Real2DHOBasis(vmax, rmax, ell=None, Nr=None, Nphi=None, angle='rad')¶
Bases:
nitrogen.basis.ndbasis.NDBasisReal 2-D isotropic harmonic oscillator basis functions in cylindrical coordinates. \(\chi_n^{\ell}(r,\phi) = R_n^{\ell}(r)f_{\ell}(\phi)\). See
Real2DHO.Quadrature is performed with a direct product of a Gauss-Laguerre-type grid over \(r\) and a uniform Fourier grid over \(\phi\).
The integration weight function is \(\Omega(r,\phi) = r\).
- v¶
The \(v\) quantum numbers, where \(v = 2n + \vert \ell \vert\).
- Type
ndarray
- ell¶
The \(\ell\) quantum numbers.
- Type
ndarray
- n¶
The \(n\) Laguerre degree.
- Type
ndarray
- rmax¶
The radial extent of the basis.
- Type
float
- alpha¶
The radial scaling parameter, \(\alpha\), corresponding to radial extent R.
- Type
float
- angle¶
The angular units.
- Type
{‘rad’, ‘deg’}
See also
nitrogen.special.Real2DHODFun sub-class real 2-D harmonic oscillator wavefunctions.
nitrogen.special.RadialHODFun sub-class for d-dimensional radial harmonic oscillator wavefunctions.
nitrogen.special.SinCosDFunDFun sub-class for sine-cosine basis.
Create a Real2DHO basis.
- Parameters
vmax (int) – The maximum vibrational quantum number \(v\), in the conventional sum-of-modes sense.
rmax (float) – The radial extent of the basis.
ell (scalar or 1-D array_like, optional) – The angular momentum quantum number. If scalar, then all \(\ell\) with \(|\ell| \leq\) abs(ell) will be included. If array_like, then ell lists all (signed) \(\ell\) values to be included. A value of None is equivalent to ell = vmax. The default is None.
Nr (int, optional) – The number of quadrature points over \(r\). The default is vmax + 1.
Nphi (int, optional) – The number of quadrature points over \(\phi\). The default is \(2(\ell_{max} + 1)\).
angle ({'rad', 'deg'}) – The angular unit. The default is ‘rad’.
- class nitrogen.basis.RealSphericalHBasis(m, lmax, Ntheta=None, Nphi=None)¶
Bases:
nitrogen.basis.ndbasis.NDBasisReal spherical harmonics, \(\Phi_\ell^m(\theta,\phi) = F_\ell^m(\theta)f_m(\phi)\). See
RealSphericalH.The integration weight function is \(\Omega(\theta,\phi) = \sin(\theta)\). Quadrature is performed with a direct product of a Gauss-Legendre grid over \(\theta\) and a uniform Fourier grid over \(\phi\).
These functions are eigenfunctions of the differential operator
\[-\frac{\partial^2}{\partial \theta^2} - \cot \theta \frac{\partial}{\partial \theta} - \frac{\partial_\phi^2}{\sin^2\theta}\]with eigenvalue \(\ell(\ell+1)\).
- m¶
The projection quantum number \(m\).
- Type
ndarray
- l¶
The azimuthal quantum number \(\ell\).
- Type
ndarray
See also
nitrogen.special.RealSphericalHDFun sub-class real spherical harmonics.
nitrogen.special.LegendreLMCosDFun sub-class for associated Legendre polynomials.
nitrogen.special.SinCosDFunDFun sub-class for sine-cosine basis.
Create a RealSphericalH basis.
- Parameters
m (int or array_like) – The associated Legendre order(s).
lmax (int) – The maximum \(\ell\) quantum number.
Ntheta (int, optional) – The number of quadrature points over \(\theta\). The default is 2*`lmax` + 1.
Nphi (int, optional) – The number of quadrature points over \(\phi\). The default is 2(mmax+1).
- class nitrogen.basis.SimpleDVR(start=0, stop=1, num=10, basis='sinc')¶
Bases:
nitrogen.basis.dvr.GenericDVRStandard 1D DVRs.
- start¶
The DVR grid starting value.
- Type
float
- stop¶
The DVR grid stopping value.
- Type
float
- basis¶
The DVR basis type.
- Type
{‘sinc’,’ho’,’fourier’, ‘legendre’}
Create a DVR object.
- Parameters
start (float, optional) – The DVR grid starting value. The default is 0.
stop (float, optional) – The DVR grid stopping value. The default is 1.
num (int, optional) – The number of DVR grid points. The default is 10.
basis ({'sinc','ho','fourier','legendre'}, optional) – The DVR basis type. The default is ‘sinc’. See Notes for details.
Notes
Each basis option constructs a one-dimensional DVR over a grid defined by start, stop, and num. All basis types have a simple \(dq\) volume element. Descriptions for each follow:
basis value
Description
'sinc'\(\text{sinc}\) basis
'ho'Harmonic oscillator DVR.
'fourier'Fourier DVR (a periodic version of
'sinc').'legendre'Legendre polynomial DVR.
- class nitrogen.basis.SinCosBasis(m=10, Nq=None, angle='rad')¶
Bases:
nitrogen.basis.ndbasis.NDBasisA 1-D, real sine/cosine basis set,
\[\begin{split}f_m(\phi) &= 1/\sqrt{\pi} \sin(|m|\phi) &\ldots m < 0\\ &= 1/\sqrt{2\pi} &\ldots m = 0\\ &= 1/\sqrt{\pi} \cos(m \phi) &\ldots m > 0\end{split}\]- m¶
The m quantum number of each basis function.
- Type
ndarray
- angle¶
The angular unit.
- Type
{‘rad’, ‘deg’}
See also
nitrogen.special.SinCosDFunDFun sub-class for sine-cosine basis set.
A real sine-cosine Fourier basis.
- Parameters
m (int or 1-D array_like of int, optional) – If scalar, the \(2|m|+1\) basis functions with index \(\leq |m|\) will be included. If array_like, then m lists all m-indices to be included. The default is m = 10.
Nq (int, optional) – The number of quadrature points. The default is 2*max(abs(m)) + 3
angle ({'rad', 'deg'}) – The angular unit. The default is ‘rad’.
- class nitrogen.basis.StructuredBasis(bases, structure)¶
Bases:
nitrogen.basis.ndbasis.NDBasisMulti-dimensional bases that have a structured product form, such as spherical harmonics, D-matrices, etc, and direct product quadrature grids.
Initialize a generic StructuredBasis.
- Parameters
bases (list of NDBasis objects) – The basis function factors
structure ((Nb, nfs) array_like) – The product structure of each basis function in terms of the indices of each factor basis in bases.
Notes
Currently only 1-dimensional factor bases are supported. This may be expanded in the future.
- nitrogen.basis.basisShape(bases)¶
Determine the direct-product shape of a set of GriddedBasis and/or scalars.
- Parameters
bases (list of GriddedBasis and scalar) – The direct-product factors. Scalars become singleton dimensions.
- Returns
shape (tuple) – The basis shape.
size (int) – The total size.
- nitrogen.basis.basisVar(bases)¶
Return the list of active coordinates (i.e. non-scalar entries) represented by a list of GriddedBasis or scalars
- Parameters
bases (list of GriddedBasis and scalar) – The direct-product factors. Scalars become singleton dimensions.
- Returns
var – The ordered list of active coordinates.
- Return type
list
- nitrogen.basis.coordAxis(bases)¶
Determine the direct-product axis to which each coordinate belongs
- Parameters
bases (list of GriddedBasis and scalar) – The direct-product factors. Scalars become singleton dimensions.
- Returns
axis_of_coord – The direct-product axis of each coordinate.
- Return type
list
- nitrogen.basis.coordSubcoord(bases)¶
Determine the intra-basis coordinate index of each coordinate represented by the complete basis. Scalar singletons will just take 0.
- Parameters
bases (list of GriddedBasis and scalar) – The direct-product factors. Scalars become singleton dimensions.
- Returns
axis_of_coord – The intra-basis coordinate sub-index of each coordinate.
- Return type
list
- nitrogen.basis.sameGrid(A, B)¶
Check whether GriddedBases A and B have the same grid. This also handles scalar input, in which case simple equality is checked.
A, B : GriddedBasis or scalar
- Returns
True if equal grids, otherwise False.
- Return type
bool
nitrogen.basis.ops¶
DVR grid operations
- nitrogen.basis.ops.opDD_grid(x, f, h, G, Dlist)¶
Evaluate the matrix-vector operation for \(\sum_{k,\ell} f \partial_k^\dagger G^{kl} h \partial_\ell f\)
- Parameters
x (ndarray) – Input grid
f (ndarray) – Weighting functions evaluated over grid.
h (ndarray) – Weighting functions evaluated over grid.
G (ndarray) – Inverse metric grids in packed storage for active coordinates only.
Dlist (list of ndarrays) – List of the D operator for each dimension. An entry of None will be skipped.
- Returns
y – The result grid
- Return type
ndarray
- nitrogen.basis.ops.opD_grid(x, f, Dlist)¶
Evaluate the matrix-vector operation for \(\sum_{k} -\partial_k^\dagger f_k + f_k \partial_k\)
- Parameters
x (ndarray) – Input grid
f (ndarray) – Weighting functions evaluated over grid for each active vibrational index k.
Dlist (list of ndarrays) – List of the D operator for each dimension. An entry of None for inactive coordinates will be skipped.
- Returns
y – The result grid
- Return type
ndarray
- nitrogen.basis.ops.opO(x, O, axis)¶
Apply matrix operator O to a single axis
- Parameters
x (ndarray) – Input grid
O (ndarray) – An (m,n) matrix
axis (int) – The axis O acts on. x.shape[axis] must equal n.
- Returns
y – The result array, with y.shape[axis] equal to m.
- Return type
ndarray
- nitrogen.basis.ops.opO_coeff(x, Olist, c=None)¶
Evaluate the matrix-vector operation for \(\sum_{k} c_k \hat{O}_k\)
- Parameters
x (ndarray) – Input grid
Olist (list of ndarrays) – List of the matrix operator for each dimension. An entry of None for inactive coordinates will be skipped.
c (array_like, optional) – Coefficients for each term in sum, including inactive operators (whose values are ignored). If None, this is ignored.
- Returns
y – The result grid
- Return type
ndarray
- nitrogen.basis.ops.opTensorO(x, Os)¶
Apply a sequence of matrix operators to each axis.
- Parameters
x (ndarray) – Input grid
Os (list of ndarray) – The operator matrix for each axis. An entry of None is the same as identity.
- Returns
y – The result array.
- Return type
ndarray