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 the mesh_spacing based on a given accuracy for a specific structure you should use torchpme.utils.tuning.tune_p3m(). This function will also find the optimal cutoff for the neighborlist.

Hint

For a training exercise it is recommended only run a tuning procedure with torchpme.utils.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. The smearing parameter of the potential determines the split between real and k-space regions. For a torchpme.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 to 1/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 be n^3. In general, for n nodes, the interpolation will be performed by piecewise polynomials of degree n - 1 (e.g. n = 4 for cubic interpolation). Only the values 1, 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 to False, 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 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, 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.

Examples using torchpme.P3MCalculator

Atomistic model for molecular dynamics

Atomistic model for molecular dynamics