xnn.trfnn.models.et#

ET, the equivariant transformer of TorchMD-Net (Thoelke & De Fabritiis, ICLR 2022).

An implementation of

  • P. Thoelke, G. De Fabritiis, “TorchMD-NET: Equivariant Transformers for Neural Network based Molecular Potentials”, ICLR 2022 (arXiv:2202.02541),

  • with the cutoff fix of TorchMD-Net 2.0 (Pelaez et al., J. Chem. Theory Comput. 20, 4076 (2024), section 2.1.2),

written from the papers on the xnn abstractions (ExpNormalSmearing, CosineCutoff, GatedEquivariantBlock, scatter_sum()) and consistent with the conventions of the authors’ code (torchmd/torchmd-net: feature layout, initialization, self-interaction, the vector_cutoff option), without copying it. Parameter names follow the reference so that weights transplant.

Representation. Every atom carries F scalar features x_i and F Cartesian vector features v_i (zero at the start). The embedding layer (eq 1 to 4) combines an intrinsic embedding of Z_i with a neighborhood embedding, a distance-filtered sum of the neighbors’ type embeddings:

x_i = W^C [embed(Z_i), sum_j embed_nbh(Z_j) o (W^F e_rbf(d_ij) + b) phi(d_ij)] + b^C

with the exponential-normal basis e_rbf of eq 1 and the cosine cutoff phi of eq 2. T residual update layers follow (eq 5 to 11): a layer-normed multi-head attention whose logits include a distance filter D^K and whose values are filtered by D^V:

A_ij = SiLU(sum_k Q_k(x_i) K_k(x_j) D^K_k(d_ij)) phi(d_ij)
s^1_ij, s^2_ij, s^3_ij = split(V(x_j) o D^V(d_ij))
y_i = O(sum_j A_ij s^3_ij),  split into q^1_i, q^2_i, q^3_i
dx_i = q^1_i + q^2_i o <U_1 v_i, U_2 v_i>
dv_i = sum_j (s^1_ij o v_j + s^2_ij o r_ij / |r_ij|) + q^3_i o U_3 v_i

The sums over j include j = i (the reference neighbor list carries self pairs at d_ii = 0); the model appends one self pair per atom to the pairs of the update layers (zero distance and direction, cutoff one). A final layer norm and two gated equivariant blocks (F -> F/2 -> 1) give the per-atom energy, standardized by energy_scale / energy_shift and shifted by the per-element reference atom_ref.

Conventions worth knowing:

  • r_ij = r_j - r_i points from the center atom to its neighbor, the negative of the xnn edge vector pos[dst] - pos[src]; the sign is only visible in node_vectors, not in the energy.

  • vector_cutoff=True (the default) applies the cutoff to the whole value pathway, split(phi(d_ij) V(x_j) o D^V(d_ij)), as TorchMD-Net 2.0 does, so that the energy is continuous at the cutoff. False is the original ICLR 2022 model, whose vector residuals are not weighted by the cutoff (the ET_old of the 2024 paper).

  • The reference standardizes with the dataset mean per structure and the standard deviation per atom; xnn applies both per atom.

Classes

EquivariantTransformer([n_features, ...])

The TorchMD-Net equivariant transformer (ET).