CombinedPotential

class torchpme.CombinedPotential(potentials: list[Potential], initial_weights: Tensor | None = None, learnable_weights: bool | None = True, smearing: float | None = None, exclusion_radius: float | None = None)[source]

A potential that is a linear combination of multiple potentials.

A class representing a combined potential that aggregates multiple individual potentials with weights for use in long-range (LR) and short-range (SR) interactions.

The CombinedPotential class allows for flexible combination of potential functions with user-specified weights, which can be either fixed or trainable.

Parameters:
  • potentials (list[Potential]) – List of potential objects, each implementing a compatible interface with methods from_dist, lr_from_dist, lr_from_k_sq, self_contribution, and background_correction.

  • initial_weights (Tensor | None) – Initial weights for combining the potentials. If provided, the length must match the number of potentials. If None, weights are initialized to ones.

  • learnable_weights (bool | None) – If True, weights are trainable parameters, allowing optimization during training. If False, weights are fixed.

  • 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.

  • smearing (float | None)

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 (SR) part of the pair potential in real space.

Even though one can provide a custom version, this is usually evaluated as \(V_{\mathrm{SR}}(r)=V(r)-V_{\mathrm{LR}}(r)\), based on the full and long-range parts of the potential. If the parameter exclusion_radius is defined, it computes this part as \(V_{\mathrm{SR}}(r)=-V_{\mathrm{LR}}(r)*f_\mathrm{cut}(r)\) so that, when added to the part of the potential computed in the Fourier domain, the potential within the local region goes smoothly to zero.

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