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
orEwaldCalculator
). NB: typically a subclass should only provide an implementation ofCalculator._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 thepotential
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, atomic (pseudo-)charges
cell (Tensor) – torch.Tensor, periodic supercell for the system
positions (Tensor) – torch.Tensor, Cartesian coordinates of the 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.