xnn.common.models.dispersion_fast.d4_direct#

D4 on CPUs with its forces and stress formed without autograd, in PyTorch.

The reference (DFTD4) gets its forces from an autograd pass through every tensor operation of the evaluation. Here the derivatives are written out, as dftd4 does: the two coordination numbers with their slope per edge, the EEQ charges of each molecule from the dense linear system and, for the gradient, its adjoint solve, the dynamic polarizabilities with their derivatives in the coordination number and the charge, the two-body energies with their slope in the distance and in the polarizabilities, and the three-body term from the compiled tiles of atm_cpu with their gradient (C6 of the neutral atoms). For a cell the EEQ matrix is the reference’s Ewald sum; its derivative in the positions and the cell, contracted with the adjoint and the charges, is the one autograd pass left, over that matrix alone (the tail correction likewise over its own formula). Evaluation only: the outputs carry no autograd graph.

Molecules up to DENSE_ATOMS atoms in the dense EEQ regime take the dense path (d4_dense()): one EEQ system for the batch, the pairs i < j and the triangles of atoms, in one compiled call.

Module Attributes

DENSE_ATOMS

Most atoms of a molecule for the dense path (every pair and triangle of atoms in one compiled call).

Functions

d4_dense(term, data)

d4_direct() for a batch of molecules over every pair and triangle of atoms, in one compiled call: the outputs of evaluate_direct().

d4_direct(term, data)

D4 of a batch (molecules and cells of the dense EEQ regime) with its forces and stress: the energies per atom and per structure (B, 4) (total, two-body, three-body, tail; eV), the D4 coordination numbers, the EEQ charges, the dynamic polarizabilities (N, 23), the forces (N, 3) (eV / A) and dE / d(strain) (B, 3, 3) (eV).

dense_applies(term, data)

Whether d4_dense() serves data: molecules of at most DENSE_ATOMS atoms in the dense EEQ regime, where torch.compile produces CPU code.