SplinePotential

class torchpme.SplinePotential(r_grid: Tensor, y_grid: Tensor, k_grid: Tensor | None = None, yhat_grid: Tensor | None = None, reciprocal: bool | None = False, y_at_zero: float | None = None, yhat_at_zero: float | None = None, smearing: float | None = None, exclusion_radius: float | None = None)[source]

Potential built from a spline interpolation.

The potential is assumed to have only a long-range part, but one can also add a short-range part if needed, by inheriting and redefining sr_from_dist. The real-space potential is computed based on a cubic spline built at initialization time. The Fourier-domain kernel is computed numerically as a spline, too. Assumes the infinite-separation value of the potential to be zero.

Parameters:
  • r_grid (Tensor) – radial grid for the real-space evaluation

  • y_grid (Tensor) – potential values for the real-space evaluation

  • k_grid (Tensor | None) – radial grid for the k-space evaluation; computed automatically from r_grid if absent.

  • yhat_grid (Tensor | None) – potential values for the k-space evaluation; computed automatically from y_grid if absent.

  • reciprocal (bool | None) – flag that determines if the splining should be performed on a \(1/r\) axis; suitable to describe long-range potentials. r_grid should contain only stricty positive values.

  • y_at_zero (float | None) – value to be used for \(r\rightarrow 0\) when using a reciprocal spline

  • yhat_at_zero (float | None) – value to be used for \(k\rightarrow 0\) in the k-space kernel

  • smearing (float | None) – The length scale associated with the switching between \(V_{\mathrm{SR}}(r)\) and \(V_{\mathrm{LR}}(r)\)

  • exclusion_radius (float | None) – A length scale that defines a local environment within which the potential should be smoothly zeroed out, as it will be described by a separate model.

from_dist(dist: Tensor) Tensor[source]

Computes a pair potential given a tensor of interatomic distances.

Parameters:

dist (Tensor) – torch.tensor containing the distances at which the potential is to be evaluated.

Return type:

Tensor

sr_from_dist(dist: Tensor) Tensor[source]

Short-range part of the range-separated potential.

Parameters:

dist (Tensor) – torch.tensor containing the distances at which the potential is to be evaluated.

Return type:

Tensor

lr_from_dist(dist: Tensor) Tensor[source]

Computes the long-range part of the pair potential \(V_\mathrm{LR}(r)\). in real space, given a tensor of interatomic distances.

Parameters:

dist (Tensor) – torch.tensor containing the distances at which the potential is to be evaluated.

Return type:

Tensor

lr_from_k_sq(k_sq: Tensor) Tensor[source]

Computes the Fourier-domain version of the long-range part of the pair potential \(\hat{V}_\mathrm{LR}(k)\). The function is expressed in terms of \(k^2\), as that avoids, in several important cases, an unnecessary square root operation. :param k_sq: torch.tensor containing the squared norm of the Fourier domain vectors at which \(\hat{V}_\mathrm{LR}\) must be evaluated.

Parameters:

k_sq (Tensor)

Return type:

Tensor

self_contribution() Tensor[source]

A correction that depends exclusively on the “charge” on every particle and on the range splitting parameter. Foe example, in the case of a Coulomb potential, this is the potential generated at the origin by the fictituous Gaussian charge density in order to split the potential into a SR and LR part.

Return type:

Tensor

background_correction() Tensor[source]

A correction designed to compensate for the presence of divergent terms. For instance, the energy of a periodic electrostatic system is infinite when the cell is not charge-neutral. This term then implicitly assumes that a homogeneous background charge of the opposite sign is present to make the cell neutral.

Return type:

Tensor