xnn.ffnn.models.amoeba_ewald#

Ewald and particle-mesh Ewald sums for atomic multipoles and r^-6 dispersion.

The periodic electrostatics of the AMOEBA / HIPPO models (amoeba.py):

  • the real-space ladder of the screened Coulomb kernel erfc(alpha R) / R (ewald_ladder()), in the same D_n = (1/R d/dR)^n g form as the plain Coulomb ladder, so every pair term of the vacuum model carries over by swapping the kernel; a zero alpha gives the Coulomb ladder, which is how molecular structures of a mixed batch keep their vacuum terms;

  • the reciprocal-space part on a B-spline mesh after Essmann et al., J. Chem. Phys. 103, 8577 (1995): the multipoles are spread with the cardinal B-splines and their first and second derivatives (a point dipole is the derivative of a point charge), the mesh potential is formed with the same influence function as for point charges, and the potential, the field and the field gradient are interpolated back onto the atoms with the same splines, so that the reciprocal energy is 1/2 sum_i [q_i phi + d_i . grad phi + Q_i : grad grad phi] and the reciprocal field drives the induced dipoles (multipole_pme()); the influence function carries the least-squares spline moduli (least_squares_moduli()) rather than the Euler exponential-spline ones of the paper, which at coarse meshes leaves a far smaller mean error in the energies and reproduces Tinker’s;

  • the self-interaction terms of Gaussian-smeared multipoles, half the interaction of a multipole with its own smeared kernel erf(alpha R) / R at zero separation, -alpha / sqrt(pi) [q^2 + 2 alpha^2 / 3 |d|^2 + 8 alpha^4 / 5 Q:Q] for the quadrupole convention of the model, and the self field 4 alpha^3 / (3 sqrt(pi)) d that the mesh field of a dipole at its own site must be corrected by;

  • the Ewald sum of the -c_i c_j / R^6 dispersion (Essmann et al., eq. 5.1 and following): the real-space kernel g(alpha R) / R^6 with g(x) = e^{-x^2} (1 + x^2 + x^4 / 2), the reciprocal kernel pi^(3/2) alpha^3 / 3 [(1 - 2 b^2) e^{-b^2} + 2 b^3 sqrt(pi) erfc(b)], b = k / (2 alpha), including the k = 0 term, and the self term alpha^6 / 12 sum c_i^2 (dispersion_pme());

  • the C2 polynomial switch between a taper distance and a cutoff (switching()): the unique quintic with unit value and zero first and second derivatives at the taper, and zero value and derivatives at the cutoff, 1 - 10 x^3 + 15 x^4 - 6 x^5 in the reduced distance;

  • Tinker-compatible defaults: the Ewald coefficient that makes erfc(alpha r_c) / r_c equal 1e-8 at the real-space cutoff (ewald_coefficient()) and the mesh of at least 1.2 points per Angstrom (0.8 for dispersion) rounded up to an even size with prime factors 2, 3 and 5, at least 16 (pme_grid_size()).

Everything is written in differentiable tensor operations: forces follow from the positions through the spline weights, the stress from the cell through the reciprocal vectors, the volume and the fractional coordinates.

Functions

bspline_with_derivatives(t, order)

Cardinal B-spline weights M_p(t + j) and their first and second derivatives with respect to the scaled coordinate, for j from 0 to p - 1.

cell_jacobian(fn, cells)

The derivative of fn(cells) (G, ...) with respect to the nine entries of every structure's own cell (G, 3, 3), (9, G, ...), by forward-mode differentiation (one pass over the nine directions).

dispersion_pme(c, pos, cell, alpha, mesh, order)

Per-atom reciprocal energies of the -c_i c_j / R^6 Ewald sum of one periodic structure, self term included: -[1/2 c_i phi6(r_i) - alpha^6 / 12 c_i^2] with phi6 the mesh potential of the r^-6 kernel (k = 0 included).

dispersion_real_kernel(R, alpha)

g(alpha R) = e^{-x^2} (1 + x^2 + x^4 / 2), the real-space share of 1 / R^6 (one for a zero alpha).

ewald_coefficient(cutoff[, accuracy])

The Ewald coefficient for a real-space cutoff.

ewald_ladder(R, alpha, order)

The ladder D_n = (1/R d/dR)^n [erfc(alpha R) / R] for n from 0 to order.

fft_mesh_size(n[, minimum])

The smallest even size of at least n and minimum whose prime factors are 2, 3 and 5 (Tinker rounds a requested mesh up the same way).

first_stencils(w, dw)

The 3D spline weights "0" and their first derivatives "a_", each (N, p^3), from the per-axis weights and derivatives (N, 3, p).

fusable(fn)

Mark a pure function of per-pair tensors for the fused path.

fused(active)

Evaluate the fusable() functions called inside compiled (or not).

fused_active()

Whether the fusable() functions run compiled here (inside fused()).

jacobian_gradient(parts, jac_inv, batch, groups)

The gradient of a mesh sum with respect to the Jacobians J (G, 3, 3) of its structures, at fixed scaled coordinates: the Cartesian multipoles and derivatives enter and leave the mesh through J alone, so it is (sum_n X_n Y_n) J^-T over parts, pairs (X, Y) of a Cartesian quantity (N, 3, m) and the gradient of the sum with respect to it (N, m, 3) (a dipole and the gradient at it, a symmetrized quadrupole and the Hessian at it).

matmul3(A, B)

A B for stacks of 3 x 3 matrices (M, 3, 3), as matvec.

matvec(A, v)

A v for stacks of 3 x 3 matrices (M, 3, 3) and vectors (M, 3).

mesh_convolve(coeff, flat, influence, ...)

Spread the stencil coefficients (N, p^3) onto the groups meshes at the indices flat (mesh_layout()), apply the influence function and return the mesh potential at the stencil points.

mesh_influence(inv, volume, mesh, order, ...)

The influence function of structures with the inverse cells inv (G, 3, 3) and volumes volume (G,) on the half spectrum of the real FFT, (G, K_1, K_2, K_3 // 2 + 1), with the 1 / (K_1 K_2 K_3) of the unscaled inverse transform folded in (kind "coulomb" or "r6", see MeshPlan.influence()).

mesh_influence_jacobian(cells, mesh, order, ...)

mesh_influence() of the cells (G, 3, 3) and its derivative with respect to the nine entries of every structure's cell, (9, G, K_1, K_2, K_3 // 2 + 1), in closed form: the function depends on the cell h through the volume and the squared wave vectors, with d k^2 / d h_ab = -2 k_b (k h^-1)_a and d (1 / V) / d h_ab = -(h^-1)_ba / V; its derivative with respect to k^2 is elementwise (_influence_slope()).

mesh_influence_of(inv, volume, mesh, moduli, ...)

mesh_influence() with the spline moduli moduli (K_1, K_2, K_3) given (a scriptable form).

mesh_irfftn(spectrum, mesh)

The inverse of mesh_rfftn() onto the mesh mesh with norm="forward" (the influence function carries the scaling), the groups one at a time on a CPU.

mesh_layout(u, sizes, batch, mesh, order)

The spline stencils of atoms at the scaled fractional coordinates u (N, 3) (sizes the mesh dimensions as a tensor, batch each atom's structure): the per-axis weights and their first and second derivatives (N, 3, p), each stencil point's index into the meshes of the group laid side by side (N, p^3), and the stencil starts (N, 3).

mesh_rfftn(grid)

rfftn of the mesh groups (G, K1, K2, K3) over their three axes.

mesh_self_energy(q, d, Q, moments)

Per-atom spurious mesh self-interaction of the multipoles, S0 q^2 - 2 q Q:S2 + d.S2.d + Q:S4:Q, to be subtracted from the mesh energy in addition to the analytic self energy.

mesh_self_moments(cell, alpha, mesh, order, kind)

Moments of the spurious, position-averaged mesh self-interaction.

multipole_pme(q, d, Q, pos, cell, alpha, ...)

Reciprocal-space potential of Gaussian-smeared multipoles at the atoms, with its gradient and (optionally) its Hessian.

multipole_reciprocal_energy(q, d, Q, pos, ...)

Per-atom reciprocal energies 1/2 [q phi + d.grad phi + Q:grad grad phi] of one periodic structure, in e^2 / Angstrom (without the self terms).

multipole_self_energy(q, d, Q, alpha)

Per-atom self energies -alpha / sqrt(pi) [q^2 + 2 alpha^2 / 3 |d|^2 + 8 alpha^4 / 5 Q:Q] in e^2 / Angstrom: half the interaction of the multipole with its own smeared kernel erf(alpha R) / R at zero separation, whose ladder there is 2 alpha / sqrt(pi), -4 alpha^3 / (3 sqrt(pi)), 8 alpha^5 / (5 sqrt(pi)).

pme_grid_size(lengths[, density, minimum])

Mesh dimensions from the cell lengths: at least density points per Angstrom along each axis, rounded up to an even size whose prime factors are 2, 3 and 5, and at least minimum.

refresh_cell_terms(cache, cells, batch[, ...])

Bring the cell terms a step plan keeps for one mesh group (the influence_cache of MeshPlan: inverse cells, volumes, per-atom inverses and influence functions) to the cells cells (G, 3, 3), in place, so that a recorded step that reads them follows a changed cell (constant-pressure dynamics).

region(name)

Mark a function as a named region of the PyTorch profiler, which also becomes an NVTX range in Nsight timelines under torch.autograd.profiler.emit_nvtx; it costs a few microseconds per call when no profiler runs.

second_stencils(w, dw, d2w)

The second derivatives "ab" of the 3D spline weights, each (N, p^3).

self_field_coefficient(alpha)

4 alpha^3 / (3 sqrt(pi)): the mesh field of a Gaussian dipole at its own site is - this times the dipole, so the correction adds it back.

stencil_coefficients(q, d, Q, jac, st)

The mesh coefficients (N, p^3) of multipoles q, d, Q (any of which may be None) on the stencils st of their atoms; jac maps Cartesian to fractional mesh derivatives.

stencil_potential(at, jac, st, hessian)

The potential (N,), its Cartesian gradient (N, 3) and, with hessian, its Hessian (N, 3, 3) at the atoms, from the mesh potential at (N, p^3) at their stencil points.

switching(R, taper, cutoff)

The C2 switch S(R): one below taper, zero beyond cutoff, 1 - 10 x^3 + 15 x^4 - 6 x^5 with x = (R - taper) / (cutoff - taper) in between (unit value and zero first and second derivatives at the taper, zero value and derivatives at the cutoff).

vecmat(v, A)

v^T A for stacks of vectors (M, 3) and matrices (M, 3, 3), as matvec.

Classes

MeshPlan(pos, cells, batch, mesh, order[, ...])

The fixed particle-mesh data of a group of periodic structures on one mesh.