xnn.common.models.reciprocal#

Reciprocal-space sums through factorized phases (the Ewald fast paths).

An Ewald reciprocal sum needs the structure factors S(G) = sum_i v_i exp(i G . r_i) over a set of reciprocal vectors G = m_1 b_1 + m_2 b_2 + m_3 b_3 (integer m, b_k the rows of the reciprocal cell). Written directly they cost one sine and one cosine per atom and vector, (N, N_G) of each, which is what dominates (and, kept for the backward pass, fills the memory of) the large-system EEQ operator of D4 and the latent Ewald sum of LES. With theta_k = b_k . r the phase factorizes,

exp(i G . r) = exp(i (m_1 theta_1 + m_2 theta_2)) * exp(i m_3 theta_3),

so the vectors are grouped into columns of fixed (m_1, m_2) and the two factors tabulated, B (C, N) over the columns and P (N, 2 M_3 + 1) over m_3: the structure factors of every column are one complex matrix product B (v P), and the trigonometry drops from N N_G to N (C + 2 M_3 + 1) values. The phases are formed in float64, so float32 runs keep accurate phases even at large |G . r|.

PhaseColumns holds the grouping; the callers keep their own vector sets and weights, so the sums are the reference sums term by term.

Functions

complex_dtype(dtype)

The complex type of a real working precision.

half_space(grid)

Mask of the integer triples whose leading nonzero entry is positive.

structure_factors(columns, table, axis, v)

S[c, k, m] = sum_i B[c, i] v[i, k] P[i, m] for one column block, (c, K, 2 M_3 + 1).

unit(phase)

exp(i phase) (differentiable in phase).

Classes

PhaseColumns(grid)

Integer reciprocal-lattice triples grouped into columns of fixed (m_1, m_2).