Calculator

class torchpme.Calculator(potential: Potential, full_neighbor_list: bool = False, prefactor: float = 1.0)[source]

Base calculator for the torch interface. Based on a Potential class, it computes the value of a potential by either directly summing over neighbor atoms, or by combining a local part computed in real space, and a long-range part computed in the Fourier domain. The class can be used directly to evaluate the real-space part of the potential, or subclassed providing a strategy to evalate the long-range contribution in k-space (see e.g. PMECalculator or EwaldCalculator). NB: typically a subclass should only provide an implementation of Calculator._compute_kspace().

Parameters:
  • potential (Potential) – a Potential class object containing the functions that are necessary to compute the various components of the potential, as well as the parameters that determine the behavior of the potential itself.

  • full_neighbor_list (bool) – parameter indicating whether the neighbor information will come from a full (True) or half (False, default) neighbor list.

  • prefactor (float) – electrostatics prefactor; see Prefactors for details and common values.

forward(charges: Tensor, cell: Tensor, positions: Tensor, neighbor_indices: Tensor, neighbor_distances: Tensor)[source]

Compute the potential “energy”.

It is calculated as

\[V_i = \frac{1}{2} \sum_{j} q_j\,v(r_{ij})\]

where \(v(r)\) is the pair potential defined by the potential parameter and \(q_j\) are atomic “charges” (corresponding to the electrostatic charge when using a Coulomb potential).

If the smearing of the potential is not set, the calculator evaluates only the real-space part of the potential. Otherwise, provided that the calculator implements a _compute_kspace method, it will also evaluate the long-range part using a Fourier-domain method.

Parameters:
  • charges (Tensor) – torch.tensor of shape (n_channels, len(positions)) containaing the atomic (pseudo-)charges. n_channels is the number of charge channels the potential should be calculated. For a standard potential n_channels = 1. If more than one “channel” is provided multiple potentials for the same position are computed depending on the charges and the potentials.

  • cell (Tensor) – torch.tensor of shape (3, 3), where cell[i] is the i-th basis vector of the unit cell

  • positions (Tensor) – torch.tensor of shape (N, 3) containing the Cartesian coordinates of the N particles within the supercell.

  • neighbor_indices (Tensor) – torch.tensor with the i,j indices of neighbors for which the potential should be computed in real space.

  • neighbor_distances (Tensor) – torch.tensor with the pair distances of the neighbors for which the potential should be computed in real space.