xnn.ffnn.models.amoeba_ewald.MeshPlan#

class xnn.ffnn.models.amoeba_ewald.MeshPlan(pos, cells, batch, mesh, order, kernels=False, influence_cache=None)[source]#

Bases: object

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

The spline weights, their derivative stencils and the Jacobian of the scaled fractional coordinates depend on the positions and the cells only; the influence functions on the cells, the mesh, the spline order and the Ewald coefficient. A plan computes each of them once, so the permanent multipole terms, every iteration of the induced-dipole solve and the adjoint solve of the backward pass share them. The structures of a group sit side by side, each on its own mesh, and one batched real FFT serves them all. Everything stays differentiable with respect to the positions and the cells.

Parameters:
  • pos (Tensor) – Positions (N, 3) of the atoms of the group.

  • cells (Tensor) – Lattice vectors as rows (G, 3, 3), one per structure.

  • batch (Tensor) – Structure of every atom (N,), from zero to G - 1.

  • mesh (list of int) – Mesh dimensions (K_1, K_2, K_3), shared by the structures.

  • order (int) – B-spline order.

  • kernels (bool, optional) – Run the spreading, interpolation and their adjoint as fused kernels (amoeba_kernels) on spline tables made once, instead of the (N, p^3) stencils; the result is the same to round-off, with first derivatives.

  • influence_cache (Optional[dict])

kept(key, fn, derivative=None)[source]#

fn(cells), a quantity of the cells alone (G, ...): with a step plan’s cache it is kept across evaluations, and for cells that carry a gradient it is kept with its Jacobian, through which the gradient reaches the cells (_CellTerm). derivative(cells) gives the quantity and its Jacobian (9, G, ...) in closed form; without it forward-mode differentiation gives the Jacobian (cell_jacobian()). The Jacobian is not made while a CUDA graph is recorded; the quantity is then differentiated as it is.

Parameters:

key (tuple)

Return type:

Tensor

stencils(second=False)[source]#

The 3D spline weights "0", their first derivatives "a_" and, with second, the second derivatives "ab", each (N, p^3).

Parameters:

second (bool)

Return type:

dict

influence(alpha, kind)[source]#

The influence function of every structure on the half spectrum of the real FFT, (G, K_1, K_2, K_3 // 2 + 1) (see _influence()).

Parameters:
Return type:

Tensor

convolve(coeff, influence)[source]#

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

Parameters:
Return type:

Tensor

potential(q, d, Q, alpha, hessian=True)[source]#

The mesh potential, its gradient and (with hessian) its Hessian at the atoms of the group, for multipoles q, d, Q (any of which may be None); see multipole_pme().

Parameters:
Return type:

Tuple[Tensor, Tensor, Tensor | None]

field_into(d, alpha, acc, coef, guard=None)[source]#

acc += coef d - grad(mesh potential of the dipoles d) in place, the mesh part of the induction solve’s field on the kernels (no graph: the solve runs without gradients; the Jacobians constants). One spread, two FFTs and one gather, no intermediate per atom. With the scalars guard of a conjugate-gradient iteration the spread and the gather do nothing once the solve has converged.

Parameters:
Return type:

Tensor

paired_field_into(d, alpha, acc, coef, guard=None)[source]#

field_into() for two sets of dipoles stacked (2 N, 3) (the paired solve of the induction): the second set spreads into a second batch of grids, both are transformed together, and one gather serves both. The doubled tables are made once per plan.

Parameters:
Return type:

Tensor

dipole_adjoint(mu, lam, alpha, scale=None, cell=False)[source]#

The gradient with respect to the scaled coordinates of sum(lam . E(mu)), the mesh field of dipoles mu probed by lam (the mesh part of the induction’s implicit backward), as the backward of the mesh convolution forms it but without the gathers that term does not need: the potentials of mu and of the probes, then one adjoint kernel. With lam equal to scale times mu one spread and FFT pair serves both. With cell the gradients with respect to the Jacobians jac_g and to the influence function are returned too (the cell’s part of the term), from one more gather per potential.

Parameters:
dispersion(c, alpha)[source]#

Per-atom reciprocal energies of the -c_i c_j / R^6 sum, self term included (see dispersion_pme()).

Parameters:
Return type:

Tensor

self_moments(alpha, kind, max_rank=4)[source]#

mesh_self_moments() of every structure, stacked: (G,), (G, 3, 3) and (G, 3, 3, 3, 3) (None beyond max_rank).

Parameters: