Calculator

class torchpme.Calculator(potential: Potential, full_neighbor_list: bool = False)[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 or EwaldCalculator). NB: typically a subclass should only provide an implementation of Calculator._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.

forward(charges: Tensor, cell: Tensor, positions: Tensor, neighbor_indices: Tensor, neighbor_distances: Tensor, periodic: Tensor | None = None, node_mask: Tensor | None = None, pair_mask: Tensor | None = None, kvectors: Tensor | None = None)[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 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 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 potential n_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), where cell[i] is the i-th basis vector of the unit cell

  • positions (Tensor) – torch.tensor of shape (N, 3) containing the Cartesian coordinates of the N 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.

  • periodic (Tensor | None) – optional torch.tensor of shape (3,) indicating which directions are periodic (True) and which are not (False). If not provided, full periodicity is assumed.

  • node_mask (Tensor | None) – Optional torch.tensor of shape (len(positions),) that indicates which of the atoms are masked.

  • pair_mask (Tensor | None) – Optional torch.tensor containing a mask to be applied to the result.

  • kvectors (Tensor | None) – Optional precomputed k-vectors to be used in the Fourier space part of the calculation.

Examples using torchpme.Calculator

Computations with Multiple Charge Channels

Computations with Multiple Charge Channels

Advanced neighbor list usage

Advanced neighbor list usage

Computing LODE descriptors

Computing LODE descriptors

Optimizing a linear combination of potentials

Optimizing a linear combination of potentials

Atomistic model for molecular dynamics

Atomistic model for molecular dynamics

Parameter tuning for range-separated models

Parameter tuning for range-separated models

Batched Ewald Computation with Padding

Batched Ewald Computation with Padding

Basic Usage

Basic Usage