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
Potentialclass, 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.PMECalculatororEwaldCalculator). NB: typically a subclass should only provide an implementation ofCalculator._compute_kspace().- Parameters:
potential (Potential) – a
Potentialclass 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
potentialparameter and \(q_j\) are atomic “charges” (corresponding to the electrostatic charge when using a Coulomb potential).If the
smearingof thepotentialis not set, the calculator evaluates only the real-space part of the potential. Otherwise, provided that the calculator implements a_compute_kspacemethod, 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_channelsis the number of charge channels the potential should be calculated. For a standard potentialn_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), wherecell[i]is the i-th basis vector of the unit cellpositions (Tensor) – torch.tensor of shape
(N, 3)containing the Cartesian coordinates of theNparticles within the supercell.neighbor_indices (Tensor) – torch.tensor with the
i,jindices 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.