Splines

class torchpme.lib.CubicSpline(x_points: Tensor, y_points: Tensor)[source]

Cubic spline calculator.

Class implementing a cubic spline for a real-valued function.

Parameters:
  • x_points (Tensor) – Abscissas of the splining points for the real-space function

  • y_points (Tensor) – Ordinates of the splining points for the real-space function

forward(x: Tensor)[source]

Evaluates the spline at the points provided.

Parameters:

x (Tensor) – One or more positions to evaluate the splined function.

class torchpme.lib.CubicSplineReciprocal(x_points: Tensor, y_points: Tensor, y_at_zero: Tensor | None = None)[source]

Reciprocal-axis cubic spline calculator.

Computes a spline on a \(1/x\) grid, “extending” it so that it converges smoothly to zero as \(x\rightarrow\infty\). The function parameters are still provided as (x,y) points, but the interpolation is performed internally using \(1/x\), so the radial grid should only contain strictly-positive values.

Parameters:
  • x_points (Tensor) – Abscissas of the splining points for the real-space function. Must be strictly larger than zero. It is recommended for the smaller value to be much smaller than the minimum expected distance between atoms.

  • y_points (Tensor) – Ordinates of the splining points for the real-space function

  • y_at_zero (Tensor | None) – Value to be returned when called for an argument of zero. Also uses a direct interpolation to “fill in the blanks”. Defaults to the value of y_points[0].

forward(x: Tensor)[source]

Computes by reversing the inputs, checking for safety.

Parameters:

x (Tensor)

torchpme.lib.compute_second_derivatives(x_points: Tensor, y_points: Tensor)[source]

Computes second derivatives given the grid points of a cubic spline.

Parameters:
  • x_points (Tensor) – Abscissas of the splining points for the real-space function

  • y_points (Tensor) – Ordinates of the splining points for the real-space function

Returns:

The second derivatives for the spline points

torchpme.lib.compute_spline_ft(k_points: Tensor, x_points: Tensor, y_points: Tensor, d2y_points: Tensor)[source]

Computes the Fourier transform of a splined radial function.

Evaluates the integral

\[\hat{f}(k) =4\pi\int \mathrm{d}r \frac{\sin k r}{k} r f(r)\]

where \(f(r)\) is expressed as a cubic spline. The function also includes a tail correction to continue the integral beyond the last splined point, assuming that the function converges to zero at infinity.

Parameters:
  • k_points (Tensor) – Points on which the Fourier kernel should be computed. It is a good idea to take them to be \(2\pi/x\) based on the real-space x_points

  • x_points (Tensor) – Abscissas of the splining points for the real-space function

  • y_points (Tensor) – Ordinates of the splining points for the real-space function

  • d2y_points (Tensor) – Second derivatives for the spline points

Returns:

The radial Fourier transform \(\hat{f}(k)\) computed at the k_points provided.