P3MCalculator¶
- class torchpme.P3MCalculator(potential: Potential, mesh_spacing: float, interpolation_nodes: int = 4, full_neighbor_list: bool = False, prefactor: float = 1.0)[source]¶
Potential using a particle-particle particle-mesh based Ewald (P3M).
For getting reasonable values for the
smearing
of the potential class and themesh_spacing
based on a given accuracy for a specific structure you should usetorchpme.tuning.tune_p3m()
. 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_p3m()
for the largest system in your dataset.- Parameters:
potential (Potential) – A
Potential
object that implements the evaluation of short and long-range potential terms. Thesmearing
parameter of the potential determines the split between real and k-space regions. For atorchpme.lib.CoulombPotential
it corresponds to the smearing 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.mesh_spacing (float) – Value that determines the umber of Fourier-space grid points that will be used along each axis. If set to None, it will automatically be set to half of
smearing
.interpolation_nodes (int) – The number
n
of nodes used in the interpolation per coordinate axis. The total number of interpolation nodes in 3D will ben^3
. In general, forn
nodes, the interpolation will be performed by piecewise polynomials of degreen - 1
(e.g.n = 4
for cubic interpolation). Only the values1, 2, 3, 4, 5
are supported.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.
For an example on the usage for any calculator refer to Examples.
- 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.