torchref.base.coordinates.periodic_boundary module

Periodic boundary condition handling functions.

These functions compute minimum image distances with periodic boundary conditions, essential for crystallographic calculations where atoms wrap around the unit cell boundaries.

torchref.base.coordinates.periodic_boundary.smallest_diff(diff, inv_frac_matrix, frac_matrix)[source]

Compute minimum image squared distances with periodic boundary conditions.

Parameters:
  • diff (torch.Tensor) – Difference vectors of shape (…, 3).

  • inv_frac_matrix (torch.Tensor) – Inverse fractionalization matrix of shape (3, 3).

  • frac_matrix (torch.Tensor) – Fractionalization matrix of shape (3, 3).

Returns:

Squared distances with shape (…).

Return type:

torch.Tensor

torchref.base.coordinates.periodic_boundary.smallest_diff_aniso(diff, inv_frac_matrix, frac_matrix)[source]

Compute minimum image difference vectors for anisotropic calculations.

Parameters:
  • diff (torch.Tensor) – Difference vectors of shape (…, 3).

  • inv_frac_matrix (torch.Tensor) – Inverse fractionalization matrix of shape (3, 3).

  • frac_matrix (torch.Tensor) – Fractionalization matrix of shape (3, 3).

Returns:

Signed difference vectors with shape (…, 3). Note: For anisotropic calculations, the signed vectors are needed to correctly compute the quadratic form r^T × B^(-1) × r with off-diagonal U tensor terms.

Return type:

torch.Tensor