nvalchemi.enhanced_sampling.pair_distance#

nvalchemi.enhanced_sampling.pair_distance(batch, atom_indices)[source]#

Return the displacement between two atoms per graph, shape [B, 3].

The vector r_j - r_i, minimum-image corrected when the batch is periodic. pair_distance() is its norm; the vector form is what a method needs when it works with the CV gradient rather than the value — adaptive biasing force projects atomic forces onto it.

The norm of pair_displacement(), which carries the validation, device handling, and minimum-image convention documented there.

Parameters:
Returns:

Pair distances in angstrom, shape [B, 1], differentiable with respect to batch.positions and batch.cell.

Return type:

Tensor

Raises:
  • IndexError – If an atom index is out of range for its graph.

  • ValueError – If atom_indices has the wrong shape or dtype, or if a periodic cell is not Minkowski-reduced (eager mode only).

Examples

>>> import torch
>>> from nvalchemi.enhanced_sampling import pair_distance
>>> from nvalchemi.data import AtomicData, Batch
>>> data = AtomicData(
...     positions=torch.tensor([[0.0, 0.0, 0.0], [3.0, 4.0, 0.0]]),
...     atomic_numbers=torch.ones(2, dtype=torch.long),
... )
>>> pair_distance(Batch.from_data_list([data]), torch.tensor([0, 1]))
tensor([[5.]])