EwaldCalculator¶
- class torchpme.EwaldCalculator(potential: Potential, lr_wavelength: float, full_neighbor_list: bool = False, prefactor: float = 1.0)[source]¶
Potential computed using the Ewald sum.
Scaling as \(\mathcal{O}(N^2)\) with respect to the number of particles \(N\).
For getting reasonable values for the
smaring
of the potential class and thelr_wavelength
based on a given accuracy for a specific structure you should usetorchpme.tuning.tune_ewald()
. This function will also find the optimalcutoff
for the neighborlist.Hint
For a training exercise it is recommended only run a tuning procedure with
torchpme.tuning.tune_ewald()
for the largest system in your dataset.For a \(\mathcal{O}(N^{1.5})\) scaling, one can set the parameters as following:
\[ \begin{align}\begin{aligned}\mathrm{smearing} &= 1.3 \cdot N^{1 / 6} / \sqrt{2}\\\mathrm{lr\_wavelength} &= 2 \pi \cdot \mathrm{smearing} / 2.2\\\mathrm{r_c} &= 2.2 \cdot \mathrm{smearing}\end{aligned}\end{align} \]where \(N\) is the number of particles. The magic numbers \(1.3\) and \(2.2\) above result from tests on a CsCl system, whose unit cell is repeated 16 times in each direction, resulting in a system of 8192 atoms.
- Parameters:
potential (Potential) – the two-body potential that should be computed, implemented as a
torchpme.potentials.Potential
object. Thesmearing
parameter of the potential determines the split between real and k-space regions. For atorchpme.CoulombPotential
it corresponds to the width of the atom-centered Gaussian used to split the Coulomb potential into the short- and long-range parts. A reasonable value for most systems is to set it to1/5
times the neighbor list cutoff.lr_wavelength (float) – Spatial resolution used for the long-range (reciprocal space) part of the Ewald sum. More concretely, all Fourier space vectors with a wavelength >= this value will be kept. If not set to a global value, it will be set to half the smearing parameter to ensure convergence of the long-range part to a relative precision of 1e-5.
full_neighbor_list (bool) – If set to
True
, a “full” neighbor list is expected as input. This means that each atom pair appears twice. If set toFalse
, a “half” neighbor list is expected.prefactor (float) – electrostatics prefactor; see Prefactors for details and common values.
- forward(charges: Tensor, cell: Tensor, positions: Tensor, neighbor_indices: Tensor, neighbor_distances: Tensor)¶
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 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 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 theN
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.