xnn.ffnn.models.classical_kernels#

Fused Triton kernels of the nonbonded pair terms of the classical force fields (OPLS, AMBER, CHARMM, DREIDING).

One program handles a block of pairs of a half neighbor list: the squared distance, the van der Waals energy from a table per pair of atom types, the Coulomb energy, the quintic switch, the exclusion weight and the cutoff, written as the per-atom halves of both energies with atomic adds into a float64 buffer. The backward kernel forms the gradient with respect to the pair vectors from the incoming per-atom gradients (no atomic adds), so forces and stress follow through the pair vectors’ own graph. The forms are those of the eager functions of the models:

  • FORM 0 (12-6): A (x^2 - B x) with x = (R^2 / (r^2 + tiny))^3: OPLS with A = 4 epsilon, B = 1 and R = sigma; AMBER, CHARMM and DREIDING with A = epsilon, B = 2 and R the minimum-energy distance.

  • FORM 1 (exponential-6): a exp(-c r) - b / (r^6 + tiny) with r = sqrt(r^2 + tiny) (DREIDING X6).

The Coulomb term is k q_i q_k / r; the switch 1 - x^3 (10 - 15 x + 6 x^2) over [cutoff - width, cutoff] multiplies both terms.

Imported only on CUDA devices, so that triton is needed only there.

Functions

available([device])

Whether the kernels can run (a CUDA device and Triton).

bonded_terms(pos, cell, batch, idx, shifts, ...)

The per-atom energies (N,) in dtype of one class of bonded terms (see BondedTerms); extra the squared cutoff and the cosine bound of the hydrogen bonds.

excluded(src, dst, exclusions, n_local)

Whether each pair (src, dst) (either order, atoms of a batch of one structure's copies) is one of the exclusions (ptr, cols, width) of exclusion_rows(), as (P,) bool.

pair_terms(pos, cell, batch, src, dst, ...)

The per-atom van der Waals and Coulomb energies (N,) each in dtype of PairTerms.

Classes

BondedTerms(*args, **kwargs)

The per-atom energies (N,) (float64) of one class of bonded terms (kind "bond", "morse", "angle", "torsion", "inversion" or "hbond") from the positions (N, 3), the cells (B, 3, 3), the atoms' structures, the term atoms idx (A, M), their image shifts (A - 1, M, 3) (or None without cells) and the term parameters params (see the kernels); the model's precision dtype.

PairTerms(*args, **kwargs)

The van der Waals and Coulomb energies per atom (N, 2) (float64) of the pairs i < k of a directed pair list (src, dst) with image shifts shifts (E, 3) (or None), from the positions and cells, without the pairs in the exclusion rows (ptr, cols, width) of one structure of n_local atoms (or None), with compact atom types t, charges q and the (T, T, 3) table of the form; differentiable once, in the positions and the cells.