grid.cubic module#
Hyper Rectangular Grid In Either Two or Three Dimensions.
- class grid.cubic.Tensor1DGrids(oned_x, oned_y, oned_z=None)#
Bases:
_HyperRectangleGridTensor product of two/three one-dimensional grids.
- property origin#
Cartesian coordinates of the grid origin.
- class grid.cubic.UniformGrid(origin, axes, shape, weight='Trapezoid')#
Bases:
_HyperRectangleGridUniform grid (a.k.a. rectilinear grid) with evenly-spaced points in each axes.
- property axes#
Return the axes of the uniform grid.
- closest_point(point, which='closest')#
Identify the index of the closest grid point to a given point.
Imagine a point inside a small sub-cube. If closest is selected, it will pick the corner in the sub-cube that is closest to that point. if origin is selected, it will pick the corner that is the bottom, left-most, down-most in the sub-cube.
Parameters#
- pointnp.ndarray, shape (3,)
Point in \([-1,1]^3\).
- whichstr
If “closest”, returns the closest index of the grid point. If “origin”, return the left-most, down-most closest index of the grid point.
Returns#
- indexint
Index of the point in points closest to the grid point.
- classmethod from_cube(fname, weight='Trapezoid', return_data=False)#
Initialize
UniformGridclass based on the grid specifications of a cube file.Parameters#
- fnamestr
Cube file name with *.cube extension.
- weightstr
Scheme for computing the weights of the grid. See the acceptable values in the
__init__()method.- return_databool
If False, only the grid is returned. If True a tuple with the grid and the cube data is returned. The cube data is a dictionary with the following keys:
atnums: atomic numbers of the atoms in the molecule.atcorenums: Pseudo-number of \(M\) atoms in the molecule.atcoords: Cartesian coordinates of \(M\) atoms in the molecule.data: the grid data stored in a flattened one-dimensional array.
- classmethod from_molecule(atcorenums, atcoords, spacing=0.2, extension=5.0, rotate=True, weight='Trapezoid')#
Construct a uniform grid given the molecular pseudo-numbers and coordinates.
Parameters#
- atcorenumsnp.ndarray, shape (M,)
Pseudo-number of \(M\) atoms in the molecule.
- atcoordsnp.ndarray, shape (M, 3)
Cartesian coordinates of \(M\) atoms in the molecule.
- spacingfloat, optional
Increment between grid points along \(x\), \(y\), and \(z\) direction.
- extensionfloat, optional
The extension of the length of the cube on each side of the molecule.
- rotatebool, optional
When True, the molecule is rotated so the axes of the cube file are aligned with the principle axes of rotation of the molecule. If False, generates axes based on the x,y,z-axis and the spacing parameter, and the origin is defined by the maximum/minimum of the atomic coordinates.
- weightstr, optional
String indicating weighting function. Denoting the volume/area of the uniform grid by \(V\), the weighting function can be:
- Rectangle :
The weights are the standard Riemannian weights,
\[w_{ijk} = \frac{V}{M_x\cdot M_y \cdot M_z}\]- Trapezoid :
Equivalent to rectangle rule with the assumption function is zero on the boundaries.
\[w_{ijk} = \frac{V}{(M_x + 1) \cdot (M_y + 1) \cdot (M_z + 1)}\]- Fourier1 :
Assumes function can be expanded in a Fourier series, and then use Gaussian quadrature. Assumes the function is zero at the boundary of the cube.
\[\begin{split}\begin{align*} w_{ijk} =& \frac{2^3}{(M_x + 1) \cdot (M_y + 1) \cdot (M_z + 1)} \cdot\\ & \bigg[ \bigg(\sum_{p=1}^{M_x} \frac{\sin(ip \pi/(M_x + 1)) (1 - \cos(p\pi)}{p\pi} \bigg) \\ & \bigg(\sum_{p=1}^{M_y} \frac{\sin(jp \pi/(M_y + 1)) (1 - \cos(p\pi)}{p\pi} \bigg) \\ & \bigg(\sum_{p=1}^{M_z} \frac{\sin(kp \pi/(M_z + 1)) (1 - \cos(p\pi)}{p\pi} \bigg) \bigg] \end{align*}\end{split}\]- Fourier2 :
Alternative weights based on Fourier series. Assumes the function is zero at the boundary of the cube.
\[\begin{split}\begin{align*} w_{ijk} =& V^\prime \cdot w_i w_j w_k,\\ w_i =& \bigg(\frac{2\sin((j - 0.5)\pi) \sin^2(M_x\pi/2)}{M_x^2 \pi} + \\ & \frac{4}{M_x \pi} \sum_{p=1}^{M_x - 1} \frac{\sin((2j-1)p\pi /n_x) sin^2(p \pi)}{\pi} \bigg) \end{align*}\end{split}\]- Alternative :
This does not assume function is zero at the boundary.
\[w_{ijk} = V \cdot \frac{M_x - 1}{M_x} \frac{M_y - 1}{M_y} \frac{M_z - 1}{M_z}\]
- generate_cube(fname, data, atcoords, atnums, pseudo_numbers=None)#
Write the data evaluated on grid points into a cube file.
Parameters#
- fnamestr
Cube file name with *.cube extension.
- datanp.ndarray, shape=(npoints,)
An array containing the evaluated scalar property on the grid points.
- atcoordsnp.ndarray, shape (M, 3)
Cartesian coordinates of \(M\) atoms in the molecule.
- atnumsnp.ndarray, shape (M,)
Atomic numbers of \(M\) atoms in the molecule.
- pseudo_numbersnp.ndarray, shape (M,), optional
Pseudo-numbers (core charges) of \(M\) atoms in the molecule.
- property origin#
Return the Cartesian coordinates of the uniform grid origin.