3.4.3. horton.grid.cext
– C++ extensions¶
-
class
horton.grid.cext.
Extrapolation
¶ Bases:
object
-
deriv_left
(self, double x)¶ Evaluate the extrapolation function derivative at the left of the cubic spline interval
-
deriv_right
(self, double x)¶ Evaluate the extrapolation function derivative at the right of the cubic spline interval
-
eval_left
(self, double x)¶ Evaluate the extrapolation function at the left of the cubic spline interval
-
eval_right
(self, double x)¶ Evaluate the extrapolation function at the right of the cubic spline interval
-
from_string
(type cls, s)¶ Create an extrpolation object from a string description
-
to_string
(self)¶ Return an extrapolation object in string respresentation
-
-
class
horton.grid.cext.
ZeroExtrapolation
¶ Bases:
horton.grid.cext.Extrapolation
Zero left and right of the cubic spline interval
-
deriv_left
(self, double x)¶ Evaluate the extrapolation function derivative at the left of the cubic spline interval
-
deriv_right
(self, double x)¶ Evaluate the extrapolation function derivative at the right of the cubic spline interval
-
eval_left
(self, double x)¶ Evaluate the extrapolation function at the left of the cubic spline interval
-
eval_right
(self, double x)¶ Evaluate the extrapolation function at the right of the cubic spline interval
-
from_string
(type cls, s)¶ Create an extrpolation object from a string description
-
to_string
(self)¶ Return an extrapolation object in string respresentation
-
-
class
horton.grid.cext.
CuspExtrapolation
¶ Bases:
horton.grid.cext.Extrapolation
Exponential extrapolation at the left side, zero at the right size
-
deriv_left
(self, double x)¶ Evaluate the extrapolation function derivative at the left of the cubic spline interval
-
deriv_right
(self, double x)¶ Evaluate the extrapolation function derivative at the right of the cubic spline interval
-
eval_left
(self, double x)¶ Evaluate the extrapolation function at the left of the cubic spline interval
-
eval_right
(self, double x)¶ Evaluate the extrapolation function at the right of the cubic spline interval
-
from_string
(type cls, s)¶ Create an extrpolation object from a string description
-
to_string
(self)¶ Return an extrapolation object in string respresentation
-
-
class
horton.grid.cext.
PowerExtrapolation
¶ Bases:
horton.grid.cext.Extrapolation
Zero at the right side, power law at the left side
-
deriv_left
(self, double x)¶ Evaluate the extrapolation function derivative at the left of the cubic spline interval
-
deriv_right
(self, double x)¶ Evaluate the extrapolation function derivative at the right of the cubic spline interval
-
eval_left
(self, double x)¶ Evaluate the extrapolation function at the left of the cubic spline interval
-
eval_right
(self, double x)¶ Evaluate the extrapolation function at the right of the cubic spline interval
-
from_string
(type cls, s)¶ Create an extrpolation object from a string description
-
to_string
(self)¶
-
power
¶ The power parameter
-
-
class
horton.grid.cext.
PotentialExtrapolation
¶ Bases:
horton.grid.cext.Extrapolation
Zero at the right side, power law at the left side
-
deriv_left
(self, double x)¶ Evaluate the extrapolation function derivative at the left of the cubic spline interval
-
deriv_right
(self, double x)¶ Evaluate the extrapolation function derivative at the right of the cubic spline interval
-
eval_left
(self, double x)¶ Evaluate the extrapolation function at the left of the cubic spline interval
-
eval_right
(self, double x)¶ Evaluate the extrapolation function at the right of the cubic spline interval
-
from_string
(type cls, s)¶ Create an extrpolation object from a string description
-
to_string
(self)¶
-
amp_left
¶ The amplitude of the polynomial on the left side
-
amp_right
¶ The amplitude of the polynomial on the right side
-
l
¶ The angular momentum parameter
-
-
class
horton.grid.cext.
CubicSpline
¶ Bases:
object
A cubic spline object
Arguments:
- y
- The function values at the 1D grid.
Optional arguments:
- dx
- The derivative of the function values at the 1D grid. If not given, they are determined such that the second derivative of the cubic spline is continuous at the grid points.
- rtransform
- The transformation object that specifies the 1D grid. If not given, an identity transform is used
- extrapolation
- The extrapolation object that specifies the spline function outside the interval determined by the 1D grid. By default, CuspExtrapolation() is used.
-
deriv
(self, ndarray new_x, ndarray new_dx=None)¶ Evaluate the derivative of the spline (towards x) on a grid
Arguments:
- new_x
- A numpy array with the x-values at which the spline must be evaluated.
Optional arguments:
- new_dx
- When given, it is used as output argument. This array must have the same size of new_x.
Returns: new_dx
-
from_hdf5
(type cls, grp)¶
-
to_hdf5
(self, grp)¶
-
dt
¶ Array with derivatives (towards t) at the grid points
-
dx
¶ Array with derivatives (towards x) at the grid points
-
extrapolation
¶ The extrapolation object used for this spline
-
rtransform
¶ The RTransform object used for this spline
-
y
¶ Array with function values at the grid points
-
class
horton.grid.cext.
RTransform
¶ Bases:
object
A definition of (radial) grid points by means of a transformation.
The definition starts from a uniform 1D grid with spacing 1 and starting point 0: 0, 1, 2, 3, ... npoint-1. These values are defined on the so-called t-axis. The transformation is a function r=f(t) that defines the actual grid points on the r-axis: f(0), f(1), f(2), ... f(npoint-1). Different implementation for the function f are available.
-
chop
(self, npoint)¶ Return an rtransform with
npoint
number of grid pointsThe remaining grid points are such that they coincide with those from the old rtransform.
-
deriv
(self, t, output=None)¶ Return the derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv2
(self, t, output=None)¶ Return the second derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv3
(self, t, output=None)¶ Return the third of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
from_string
(type cls, s)¶ Construct a RTransform subclass from a string.
-
get_default_int1d
(self)¶ Return the recommended 1D integrator for this rtransform
-
get_deriv
(self)¶ Return an array with derivatives at the grid points
-
get_deriv2
(self)¶ Return an array with second derivatives at the grid points
-
get_deriv3
(self)¶ Return an array with third derivatives at the grid points
-
get_radii
(self)¶ Return an array with radii
-
half
(self)¶ Return an rtransform with half the number of grid points
The returned rtransform is such that old(2t+1) = new(t).
-
inv
(self, r, output=None)¶ Return the indexes for given radial grid points
Arguments:
- r
- A number or an array of numbers for the radial grid points.
-
radius
(self, t, output=None)¶ Return the 1D grid points for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
to_string
(self)¶ Represent the rtransform object as a string
-
npoint
¶
-
-
class
horton.grid.cext.
IdentityRTransform
¶ Bases:
horton.grid.cext.RTransform
For testing only
-
chop
(self, npoint)¶
-
deriv
(self, t, output=None)¶ Return the derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv2
(self, t, output=None)¶ Return the second derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv3
(self, t, output=None)¶ Return the third of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
from_string
(type cls, s)¶ Construct a RTransform subclass from a string.
-
get_default_int1d
(self)¶ Return the recommended 1D integrator for this rtransform
-
get_deriv
(self)¶ Return an array with derivatives at the grid points
-
get_deriv2
(self)¶ Return an array with second derivatives at the grid points
-
get_deriv3
(self)¶ Return an array with third derivatives at the grid points
-
get_radii
(self)¶ Return an array with radii
-
half
(self)¶ Return an rtransform with half the number of grid points
The returned rtransform is such that old(2t+1) = new(t).
-
inv
(self, r, output=None)¶ Return the indexes for given radial grid points
Arguments:
- r
- A number or an array of numbers for the radial grid points.
-
radius
(self, t, output=None)¶ Return the 1D grid points for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
to_string
(self)¶
-
npoint
¶
-
-
class
horton.grid.cext.
LinearRTransform
¶ Bases:
horton.grid.cext.RTransform
A linear grid.
The grid points are distributed as follows:
\[r_i = \alpha i + r_0\]with
\[\alpha = (r_{N-1} -r_0)/(N-1).\]-
chop
(self, npoint)¶
-
deriv
(self, t, output=None)¶ Return the derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv2
(self, t, output=None)¶ Return the second derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv3
(self, t, output=None)¶ Return the third of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
from_string
(type cls, s)¶ Construct a RTransform subclass from a string.
-
get_default_int1d
(self)¶ Return the recommended 1D integrator for this rtransform
-
get_deriv
(self)¶ Return an array with derivatives at the grid points
-
get_deriv2
(self)¶ Return an array with second derivatives at the grid points
-
get_deriv3
(self)¶ Return an array with third derivatives at the grid points
-
get_radii
(self)¶ Return an array with radii
-
half
(self)¶
-
inv
(self, r, output=None)¶ Return the indexes for given radial grid points
Arguments:
- r
- A number or an array of numbers for the radial grid points.
-
radius
(self, t, output=None)¶ Return the 1D grid points for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
to_string
(self)¶
-
alpha
¶
-
npoint
¶
-
rmax
¶
-
rmin
¶
-
-
class
horton.grid.cext.
ExpRTransform
¶ Bases:
horton.grid.cext.RTransform
An exponential grid.
The grid points are distributed as follows:
\[r_i = r_0 \exp(\alpha i)\]with
\[\alpha = \log(r_{N-1}/r_0)/(N-1).\]-
chop
(self, npoint)¶
-
deriv
(self, t, output=None)¶ Return the derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv2
(self, t, output=None)¶ Return the second derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv3
(self, t, output=None)¶ Return the third of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
from_string
(type cls, s)¶ Construct a RTransform subclass from a string.
-
get_default_int1d
(self)¶ Return the recommended 1D integrator for this rtransform
-
get_deriv
(self)¶ Return an array with derivatives at the grid points
-
get_deriv2
(self)¶ Return an array with second derivatives at the grid points
-
get_deriv3
(self)¶ Return an array with third derivatives at the grid points
-
get_radii
(self)¶ Return an array with radii
-
half
(self)¶
-
inv
(self, r, output=None)¶ Return the indexes for given radial grid points
Arguments:
- r
- A number or an array of numbers for the radial grid points.
-
radius
(self, t, output=None)¶ Return the 1D grid points for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
to_string
(self)¶
-
alpha
¶
-
npoint
¶
-
rmax
¶
-
rmin
¶
-
-
class
horton.grid.cext.
PowerRTransform
¶ Bases:
horton.grid.cext.RTransform
A power grid.
The grid points are distributed as follows:
\[r_i = r_0 i^{\alpha}\]with
\[\alpha = \frac{\ln r_{N-1} - \ln r_0}{\ln N-1}\]-
chop
(self, npoint)¶
-
deriv
(self, t, output=None)¶ Return the derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv2
(self, t, output=None)¶ Return the second derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv3
(self, t, output=None)¶ Return the third of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
from_string
(type cls, s)¶ Construct a RTransform subclass from a string.
-
get_default_int1d
(self)¶
-
get_deriv
(self)¶ Return an array with derivatives at the grid points
-
get_deriv2
(self)¶ Return an array with second derivatives at the grid points
-
get_deriv3
(self)¶ Return an array with third derivatives at the grid points
-
get_radii
(self)¶ Return an array with radii
-
half
(self)¶
-
inv
(self, r, output=None)¶ Return the indexes for given radial grid points
Arguments:
- r
- A number or an array of numbers for the radial grid points.
-
radius
(self, t, output=None)¶ Return the 1D grid points for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
to_string
(self)¶
-
npoint
¶
-
power
¶
-
rmax
¶
-
rmin
¶
-
-
class
horton.grid.cext.
HyperbolicRTransform
¶ Bases:
horton.grid.cext.RTransform
A Hyperbolic grid (as in the GPAW program).
The grid points are distributed as follows:
\[r_i = \frac{ai}{1 - bi}\]-
chop
(self, npoint)¶ Return an rtransform with
npoint
number of grid pointsThe remaining grid points are such that they coincide with those from the old rtransform.
-
deriv
(self, t, output=None)¶ Return the derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv2
(self, t, output=None)¶ Return the second derivative of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
deriv3
(self, t, output=None)¶ Return the third of the transformation for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
from_string
(type cls, s)¶ Construct a RTransform subclass from a string.
-
get_default_int1d
(self)¶
-
get_deriv
(self)¶ Return an array with derivatives at the grid points
-
get_deriv2
(self)¶ Return an array with second derivatives at the grid points
-
get_deriv3
(self)¶ Return an array with third derivatives at the grid points
-
get_radii
(self)¶ Return an array with radii
-
half
(self)¶ Return an rtransform with half the number of grid points
The returned rtransform is such that old(2t+1) = new(t).
-
inv
(self, r, output=None)¶ Return the indexes for given radial grid points
Arguments:
- r
- A number or an array of numbers for the radial grid points.
-
radius
(self, t, output=None)¶ Return the 1D grid points for the given index(es)
Arguments:
- t
- A number or an array of numbers for the indexes. t may be fractional or integer.
-
to_string
(self)¶
-
a
¶
-
b
¶
-
npoint
¶
-
-
class
horton.grid.cext.
UniformGrid
(self, ndarray origin, ndarray grid_rvecs, ndarray shape, ndarray pbc)¶ Bases:
object
Initialize a UniformGrid instance.
Parameters: - origin (np.ndarray[double, ndim=1]) – The origin of the uniform grid, where the first grid point is located. shape=(3,)
- grid_rvecs (np.ndarray[double, ndim=2]) – The rows are real-space basis vectors that define the spacings. between the grids. shape=(3,3)
- shape (np.ndarray[long, ndim=1]) – The shape of the uniform grid, i.e. number of points along each basis.
- pbc (np.ndarray[long, ndim=1]) – Three flags (0 or 1) for periodicity along each row in grid_rvecs.
-
delta_grid_point
(self, ndarray center, ndarray indexes)¶ Return the vector from a center to a grid point
Arguments:
- center
- The center
- indexes
- The integer indexes of the grid point (may fall outside of shape)
-
dist_grid_point
(self, ndarray center, ndarray indexes)¶ Return the distance between a center and a grid point
Arguments:
- center
- The center
- indexes
- The integer indexes of the grid point (may fall outside of shape)
-
from_hdf5
(type cls, grp)¶
-
get_cell
(self)¶
-
get_grid_cell
(self)¶
-
get_ranges_rcut
(self, ndarray center, double rcut)¶ Return the ranges if indexes that lie within the cutoff sphere.
Arguments:
- center
- The center of the cutoff sphere
- rcut
- The radius of the cutoff sphere
The ranges are trimmed to avoid points that fall of non-periodic boundaries of the grid.
-
integrate
(self, *args)¶ Integrate the product of all arguments
Arguments:
- data1, data2, ...
- All arguments must be arrays with the same size as the number of grid points. The arrays contain the functions, evaluated at the grid points, that must be multiplied and integrated.
-
to_hdf5
(self, grp)¶
-
zeros
(self)¶
-
grid_rvecs
¶
-
origin
¶
-
pbc
¶
-
shape
¶
-
size
¶
-
horton.grid.cext.
lebedev_laikov_sphere
(ndarray points, ndarray weights)¶ lebedev_laikov_sphere(grid)
Fill the grid with a Lebedev Laikov grid points of a given size.
Arguments:
- points
- The output array for the grid points, shape (npoint,3).
- weights
- The output array for the grid weights, shape (npoint,).
-
horton.grid.cext.
becke_helper_atom
(ndarray points, ndarray weights, ndarray radii, ndarray centers, int select, int order)¶ beck_helper_atom(points, weights, radii, centers, i, k)
Compute the Becke weights for a given atom an a grid.
Arguments:
- points
- The Cartesian coordinates of the grid points. Numpy array with shape (npoint, 3)
- weights
- The output array where the Becke partitioning weights are written. Numpy array with shape (npoint,)
- radii
- The covalent radii used to shrink/enlarge basins in the Becke scheme.
- centers
- The positions of the nuclei.
- select
- The selected atom for which the weights should be created.
- order
- The order of the switching functions. (That is k in Becke’s paper.)
See Becke’s paper for the details: http://dx.doi.org/10.1063/1.454033
-
horton.grid.cext.
tridiagsym_solve
(ndarray diag_mid, ndarray diag_up, ndarray right, ndarray solution)¶
-
horton.grid.cext.
compute_cubic_spline_int_weights
(ndarray weights)¶
-
horton.grid.cext.
index_wrap
(long i, long high)¶
-
horton.grid.cext.
eval_spline_grid
(CubicSpline spline, ndarray center, ndarray output, ndarray points, Cell cell)¶ Evaluate a spherically symmetric function on a general grid
Arguments:
- spline
- The cubic spline that contains the radial dependence of the spherically symmetric function.
- center
- The center of the spherically symmetric function.
- points
- An array with grid points, with shape (N, 3)
- output
- The output array in which the result is stored.
- cell
- A specification of the periodic boundary conditions.
-
horton.grid.cext.
eval_decomposition_grid
(splines, ndarray center, ndarray output, ndarray points, Cell cell)¶ Evaluate a sphericall decomposition on a general grid
Arguments:
- splines
- The splines with the spherical decomposition. These are usually generated with AtomicGrid.get_spherical_decomposition.
- center
- The center of the spherically symmetric function.
- points
- An array with grid points, with shape (N, 3)
- output
- The output array in which the result is stored.
- cell
- A specification of the periodic boundary conditions.
-
horton.grid.cext.
hermite_overlap2
(long xmax, long i0, bool deriv0, long i1, bool deriv1)¶
-
horton.grid.cext.
hermite_overlap3
(long xmax, long i0, bool deriv0, long i1, bool deriv1, long i2, bool deriv2)¶
-
horton.grid.cext.
hermite_node
(long x, long center, bool kind, bool deriv)¶
-
horton.grid.cext.
hermite_product2
(long x, long i0, bool deriv0, long i1, bool deriv1)¶
-
horton.grid.cext.
build_ode2
(ndarray by, ndarray bd, ndarray ay, ndarray ad, ndarray fy, ndarray fd, bcs)¶ Build set of equations for a second order ODE problem
The ODE has the following form:
\[u''(x) + b(x) u'(x) + a(x) u(x) = f(x)\]A linear system is constructed to approximate the solution for this equation on an equidistant grid with spacing 1. The function values and the derivatives of the known functions must be given, together with the boundary conditions, i.e. the function value of u(x) at the first and last grid point.
Arguments:
- by
- An array with function values of b(x) at the grid points.
- bd
- An array with the first derivatives of b(x) at the grid points.
- ay
- An array with function values of a(x) at the grid points.
- ad
- An array with the first derivatives of a(x) at the grid points.
- fy
- An array with function values of f(x) at the grid points.
- fd
- An array with the first derivatives of f(x) at the grid points.
- bcs
- A four-tuple with boundary condition specifications: (uyfirst, udfirst, uylast, ydlast). Excatly two of these four values must be None, with the two other ones fixing the boundary conditions.
The arrays by, bd, ay, ad, fy and fd must have the same length.
-
horton.grid.cext.
index_wrap
(long i, long high)
-
horton.grid.cext.
dot_multi
(*integranda, ndarray segments=None)¶ Multiply the arguments piecewise and sum up the products
Arguments:
- data1, data2, ...
- Arrays of the same size, whose elements will be multiplied piecewise and then added.
Optional arguments:
- segments
- An array with segment sizes (integer). If given, the summation is carried out in segments of the given sizes and the return value is an array with the same size as segments.
-
horton.grid.cext.
dot_multi_moments_cube
(integranda, UniformGrid ugrid, ndarray center, long lmax, long mtype)¶ Multiply the arguments piecewise, including one of a series of multipole functions at a time, and sum up the products.
Arguments:
- data1, data2, ...
- Arrays of the same size, whose elements will be multiplied piecewise and then added.
- center
- The origin for the multipole functions
- lmax
- The maximum angular momentum for the moments
- mtype
- The type of moments: 1=``cartesian``, 2=``pure``, 3=``radial``, 4=``surface``.
Returns: an array where the number of elements matches the number of multipole moments for the given combiantion of lmax and mtype.
-
horton.grid.cext.
dot_multi_moments
(integranda, ndarray points, ndarray center, long lmax, long mtype, ndarray segments)¶ Multiply the arguments piecewise, including one of a series of multipole functions at a time, and sum up the products.
Arguments:
- data1, data2, ...
- Arrays of the same size, whose elements will be multiplied piecewise and then added.
- center
- The origin for the multipole functions
- lmax
- The maximum angular momentum for the moments
- mtype
- The type of moments: 1=``cartesian``, 2=``pure``, 3=``radial``, 4=``surface``.
- segments
- An array with segment sizes (integer). If given, the summation is carried out in segments of the given sizes.
Returns: an array where the number of elements matches the number of multipole moments for the given combiantion of lmax and mtype. If
segments
is given, the return array has two indices, the first one running over the segments and the second one running over the moments.