xnn.ffnn.models.geometry#

Shared bonded-term geometry for fixed-topology force fields.

Minimum-image displacement vectors, the dihedral cosine and a differentiable-at-zero geometric mean, used by every fixed-topology model (OPLS, DREIDING). All functions operate on a batched AtomicGraph plus explicit atom-index tensors, so bonded terms are correct for molecules wrapped across periodic boundaries while gradients still flow to positions and cell.

The minimum image of a displacement is found in two steps: round its fractional coordinates to the nearest lattice point, and, for a cell with non-orthogonal axes, pick the shortest of the 27 images around that point. Rounding alone is exact for vectors shorter than half the smallest spacing between lattice planes; the 27-image search is exact for every vector on a reduced cell (the Wigner-Seitz cell of a Minkowski-reduced lattice lies inside the +-1 shell of its parallelepiped). Cells must therefore be reduced once at the data level (ase.geometry.minkowski_reduce), the convention of every molecular-dynamics code, rather than searched in every evaluation.

Functions

dihedral_cos(data, idx[, shifts])

Cosine of the dihedral angle over each atom quadruple.

dihedral_cos_sin(data, idx[, vectors, shifts])

Cosine and sine of the signed dihedral angle over each atom quadruple.

excluded_pairs(i, k, excl_index, n, B, module)

Whether each pair (i, k) of a batch of B copies of a topology of n atoms is one of its excluded pairs excl_index (2, E) (in either order), looked up in their sorted keys (made once per batch size and device, cached on module).

geometric_mean(x, y)

Geometric mean with a differentiable zero (for zero-LJ hydrogens).

half_edges(data, excl_index, n, module)

The neighbor list's pairs once each, with the exclusions of a bound topology.

minimum_image_vectors(vec, cell[, pbc])

Minimum-image displacements in one, possibly triclinic, cell.

pair_image_shifts(data, a, b)

The integer image shifts (M, 3) that pair_vectors() adds to pos[b] - pos[a], or None for a batch without cells.

pair_vectors(data, a, b[, shift])

Minimum-image displacement vectors pos[b] - pos[a].