# 3.5.3. horton.grid.cext – C++ extensions¶

class horton.grid.cext.Extrapolation

Bases: object

deriv_left()

Evaluate the extrapolation function derivative at the left of the cubic spline interval

deriv_right()

Evaluate the extrapolation function derivative at the right of the cubic spline interval

eval_left()

Evaluate the extrapolation function at the left of the cubic spline interval

eval_right()

Evaluate the extrapolation function at the right of the cubic spline interval

from_string()

Create an extrpolation object from a string description

to_string()

Return an extrapolation object in string respresentation

class horton.grid.cext.ZeroExtrapolation

Zero left and right of the cubic spline interval

deriv_left()

Evaluate the extrapolation function derivative at the left of the cubic spline interval

deriv_right()

Evaluate the extrapolation function derivative at the right of the cubic spline interval

eval_left()

Evaluate the extrapolation function at the left of the cubic spline interval

eval_right()

Evaluate the extrapolation function at the right of the cubic spline interval

from_string()

Create an extrpolation object from a string description

to_string()

Return an extrapolation object in string respresentation

class horton.grid.cext.CuspExtrapolation

Exponential extrapolation at the left side, zero at the right size

deriv_left()

Evaluate the extrapolation function derivative at the left of the cubic spline interval

deriv_right()

Evaluate the extrapolation function derivative at the right of the cubic spline interval

eval_left()

Evaluate the extrapolation function at the left of the cubic spline interval

eval_right()

Evaluate the extrapolation function at the right of the cubic spline interval

from_string()

Create an extrpolation object from a string description

to_string()

Return an extrapolation object in string respresentation

class horton.grid.cext.PowerExtrapolation

Zero at the right side, power law at the left side

deriv_left()

Evaluate the extrapolation function derivative at the left of the cubic spline interval

deriv_right()

Evaluate the extrapolation function derivative at the right of the cubic spline interval

eval_left()

Evaluate the extrapolation function at the left of the cubic spline interval

eval_right()

Evaluate the extrapolation function at the right of the cubic spline interval

from_string()

Create an extrpolation object from a string description

to_string()
power

The power parameter

class horton.grid.cext.PotentialExtrapolation

Zero at the right side, power law at the left side

deriv_left()

Evaluate the extrapolation function derivative at the left of the cubic spline interval

deriv_right()

Evaluate the extrapolation function derivative at the right of the cubic spline interval

eval_left()

Evaluate the extrapolation function at the left of the cubic spline interval

eval_right()

Evaluate the extrapolation function at the right of the cubic spline interval

from_string()

Create an extrpolation object from a string description

to_string()
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()

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()
to_hdf5()
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()

Return an rtransform with npoint number of grid points

The remaining grid points are such that they coincide with those from the old rtransform.

deriv()

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()

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()

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()

Construct a RTransform subclass from a string.

get_default_int1d()

Return the recommended 1D integrator for this rtransform

get_deriv()

Return an array with derivatives at the grid points

get_deriv2()

Return an array with second derivatives at the grid points

get_deriv3()

Return an array with third derivatives at the grid points

half()

Return an rtransform with half the number of grid points

The returned rtransform is such that old(2t+1) = new(t).

inv()

Return the indexes for given radial grid points

Arguments:

r
A number or an array of numbers for the radial grid points.

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()

Represent the rtransform object as a string

npoint
class horton.grid.cext.IdentityRTransform

For testing only

chop()
deriv()

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()

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()

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()

Construct a RTransform subclass from a string.

get_default_int1d()

Return the recommended 1D integrator for this rtransform

get_deriv()

Return an array with derivatives at the grid points

get_deriv2()

Return an array with second derivatives at the grid points

get_deriv3()

Return an array with third derivatives at the grid points

half()

Return an rtransform with half the number of grid points

The returned rtransform is such that old(2t+1) = new(t).

inv()

Return the indexes for given radial grid points

Arguments:

r
A number or an array of numbers for the radial grid points.

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()
npoint
class horton.grid.cext.LinearRTransform

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()
deriv()

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()

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()

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()

Construct a RTransform subclass from a string.

get_default_int1d()

Return the recommended 1D integrator for this rtransform

get_deriv()

Return an array with derivatives at the grid points

get_deriv2()

Return an array with second derivatives at the grid points

get_deriv3()

Return an array with third derivatives at the grid points

half()
inv()

Return the indexes for given radial grid points

Arguments:

r
A number or an array of numbers for the radial grid points.

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()
alpha
npoint
rmax
rmin
class horton.grid.cext.ExpRTransform

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()
deriv()

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()

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()

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()

Construct a RTransform subclass from a string.

get_default_int1d()

Return the recommended 1D integrator for this rtransform

get_deriv()

Return an array with derivatives at the grid points

get_deriv2()

Return an array with second derivatives at the grid points

get_deriv3()

Return an array with third derivatives at the grid points

half()
inv()

Return the indexes for given radial grid points

Arguments:

r
A number or an array of numbers for the radial grid points.

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()
alpha
npoint
rmax
rmin
class horton.grid.cext.ShiftedExpRTransform

A shifted exponential grid.

The grid points are distributed as follows:

$r_i = r_0 \alpha^i - r_s$

with

$r_0 = r_{N-1} + r_s$
$\alpha = \log\left(\frac{r_{N-1}+r_s}{r_0}\right)/(N-1).$
chop()
deriv()

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()

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()

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()

Construct a RTransform subclass from a string.

get_default_int1d()

Return the recommended 1D integrator for this rtransform

get_deriv()

Return an array with derivatives at the grid points

get_deriv2()

Return an array with second derivatives at the grid points

get_deriv3()

Return an array with third derivatives at the grid points

half()

Return an rtransform with half the number of grid points

The returned rtransform is such that old(2t+1) = new(t).

inv()

Return the indexes for given radial grid points

Arguments:

r
A number or an array of numbers for the radial grid points.

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()
alpha
npoint
r0
rmax
rmin
rshift
class horton.grid.cext.PowerRTransform

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()
deriv()

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()

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()

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()

Construct a RTransform subclass from a string.

get_default_int1d()
get_deriv()

Return an array with derivatives at the grid points

get_deriv2()

Return an array with second derivatives at the grid points

get_deriv3()

Return an array with third derivatives at the grid points

half()
inv()

Return the indexes for given radial grid points

Arguments:

r
A number or an array of numbers for the radial grid points.

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()
npoint
power
rmax
rmin
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.
compute_weight_corrections()

Computes corrections to the integration weights.

Arguments:

funcs

A collection of functions that must integrate exactly with the corrected weights. The format is as follows. funcs is a list with tuples that contain three items:

• center: the center for a set of spherically symmetric functions. In pracice, this will always coincide with th position of a nucleus.
• Radial functions specified as a list of splines.

Optional arguments:

rcut_scale
For center (of a spherical function), radii of non-overlapping spheres are determined by setting the radius of each sphere at 0.5*rcut_scale*(distance to nearest atom or periodic image).
rcut_max
To avoid gigantic cutoff spheres, one may use rcut_max to set the maximum radius of the cutoff sphere.
rcond
The regulatization strength for the weight correction equations. This should not be too low. Current value is a compromise between accuracy and transferability of the weight corrections.

Return value:

The return value is a data array that can be provided as an additional argument to the integrate method. This should improve the accuracy of the integration for data that is similar to a linear combination of the provided sphericall functions.

delta_grid_point()

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()

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)
eval_spline()
from_hdf5()
get_cell()
get_grid_cell()
get_ranges_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.

get_window()
integrate()

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()
zeros()
grid_rvecs
origin
pbc
shape
size
class horton.grid.cext.UniformGridWindow

Bases: object

compute_weight_corrections()
eval_spline()
extend()

Copy a periodic repetation of the cell function to the local grid

get_window_ugrid()
integrate()

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.

Optional arguments:

center=None
When given, multipole moments are computed with respect to this center instead of a plain integral.
lmax=0
The maximum angular momentum to consider when computing multipole moments
mtype=1
The type of multipole moments: 1=cartesian, 2=pure, 3=radial, 4=surface.
wrap()

Write the local function to the periodic array, wrapping around the edges

zeros()
begin
end
shape
size
ugrid
class horton.grid.cext.Block3Iterator

Bases: object

Wrapper for testing only

block_begin
block_end
horton.grid.cext.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()

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,)
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()
horton.grid.cext.compute_cubic_spline_int_weights()
horton.grid.cext.index_wrap()
horton.grid.cext.eval_spline_cube()

Evaluate a spherically symmetric function on a uniform grid

Arguments:

spline
The cubic spline that contains the radial dependence of the spherically symmetric function.
center
The center of the spherically symmetric function.
output
The output array in which the result is stored.
ugrid
An instance of UniformGrid that specifies the grid points.

Note that, in case of periodic boundary conditions in the ugrid object, and when the spline as a non-zero tail, this routine may give inaccurate/incorrect results.

horton.grid.cext.eval_spline_grid()

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()

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()
horton.grid.cext.hermite_overlap3()
horton.grid.cext.hermite_node()
horton.grid.cext.hermite_product2()
horton.grid.cext.build_ode2()

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.
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()
horton.grid.cext.dot_multi()

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()

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()

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.