xnn.common.models.les.EwaldSummation#
- class xnn.common.models.les.EwaldSummation(dl=2.0, sigma=1.0, exponent=1, remove_self_interaction=False)[source]#
Bases:
ModuleEwald energy of a (latent) per-atom variable
q(paper eqs 3-5).For periodic structures, the reciprocal-space sum over a k-grid limited by
|k| <= 2*pi/dl(upstream convention: the paper’sk_cequals2*pi/dl); for non-periodic structures (no cell), the equivalenterf-converged real-space direct sum. Both handle a multi-dimensionalq, summing the energies of the channels.- Parameters:
dl (float, optional) – Reciprocal grid resolution; the k-space cutoff is
2*pi/dl. By default 2.0 (k_c = pi, the paper’s bulk-water setting; its dimer/NaCl runs useddl = 3). It applies to periodic structures only: a structure without a cell takes the real-space branch, which is exact and readssigmabut neverdl, so on an all-molecular dataset this knob is inert (and is therefore untested by the fit, whatever it is set to). The cutoff is recomputed fromdlon every call, so it can be retuned on a loaded model.sigma (float, optional) – Gaussian smearing width in Angstrom, by default 1.0 (paper Methods: values between ~0.5 and 2 are reasonable; 1 was best for water).
exponent (int, optional) – Interaction exponent
pof1/r^p: 1 (electrostatics, default) or 6 (London dispersion, paper eq 5).remove_self_interaction (bool, optional) – Subtract the Gaussian self energy
sum q^2 / (sigma (2 pi)^{3/2})from the reciprocal sum, by defaultFalse(the reference training scripts keep it; the term is short-ranged and can be absorbed by the short-range model either way). Note: for multi-channelqupstream subtracts the totalsum q^2once per channel (ann_channels-fold over-subtraction); xnn subtracts it once. The two agree for 1-dimensionalqand always when the flag is off.
Notes
Charges are in scaled units (upstream
norm_factor = 1): a physical chargeQin e corresponds toq = Q * sqrt(90.0474)for energies in eV and distances in Angstrom.- reciprocal(pos, q, cell)[source]#
Reciprocal-space Ewald energy of one periodic structure.
- Parameters:
pos (Tensor) – Cartesian positions, shape
(n, 3).q (Tensor) – Hidden variable, shape
(n, n_channels).cell (Tensor) – Row-vector cell matrix, shape
(3, 3)(triclinic allowed).
- Returns:
Scalar long-range energy (summed over channels).
- Return type:
Tensor
- realspace(pos, q)[source]#
Direct-sum equivalent for a non-periodic structure.
The pair interaction is
erf(r / (sqrt(2) sigma)) / r– the potential of the Gaussian-smeared charges – normalized by1/(4 pi)exactly as upstream, so periodic and molecular structures share the same energy scale. Onlyexponent = 1is supported (as upstream).
- forward(q, pos, batch, num_graphs, cell, pbc=None)[source]#
Long-range energy per structure for a batched graph.
- Parameters:
q (Tensor) – Hidden variable, shape
(N,)or(N, n_channels).pos (Tensor) – Cartesian positions, shape
(N, 3).batch (Tensor) – Structure index of each atom, shape
(N,).num_graphs (int) – Number of structures
Bin the batch.cell (Tensor or None) – Cells of shape
(B, 3, 3), orNonefor molecular batches.pbc (Tensor or None, optional) – Per-structure periodic flags
(B, 3); a structure is treated as periodic when its cell is nonzero and any flag is set.
- Returns:
Long-range energies, shape
(B,).- Return type:
Tensor