xnn.gnn.models.tensornet#

TensorNet (Simeon & De Fabritiis, NeurIPS 2023), the Cartesian-tensor model of TorchMD-Net 2.0.

An implementation of

  • G. Simeon, G. De Fabritiis, “TensorNet: Cartesian Tensor Representations for Efficient Learning of Molecular Potentials”, NeurIPS 2023 (arXiv:2306.06482), as released and described in TorchMD-Net 2.0 (Pelaez et al., J. Chem. Theory Comput. 20, 4076 (2024), section 2.1.1),

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

Representation. Every atom carries F rank-2 Cartesian tensors X_i in R^{3 x 3}, each the sum of its irreducible parts: a scalar I_i times the identity, a skew-symmetric A_i (a vector) and a symmetric traceless S_i. The embedding builds them from the neighbors:

I_i = sum_j f_ij W^I e_rbf(d_ij),  A_i = [sum_j f_ij W^A e_rbf(d_ij) r_ij / |r_ij|]_x,
S_i = sum_j f_ij W^S e_rbf(d_ij) (r_ij r_ij^T / |r_ij|^2 - 1/3 1)

with f_ij = phi(d_ij) W^Z [z_i, z_j] (the cutoff times a pair-type embedding), then rescales each part by an MLP of the layer-normed Frobenius norms. Every interaction layer normalizes X_i by 1 + |X_i|^2, mixes the parts linearly into Y_i, passes messages M_i = sum_j f_ij o (I_j, A_j, S_j) with edge-wise filters f_ij (an MLP of e_rbf(d_ij) times the cutoff), forms the tensor products C_i = Y_i M_i + M_i Y_i (the O(3) model) or C_i = 2 Y_i M_i (SO(3), sensitive to chirality), normalizes, mixes again into dX_i and updates X_i <- X_i + dX_i + dX_i^2. A total charge q scales the two products by 1 + 0.1 q. The readout concatenates 3 I_i^2, |A_i|^2 and |S_i|^2, applies a layer norm, a linear layer and a two-layer MLP, standardized by energy_scale / energy_shift and shifted by the per-element reference atom_ref.

Conventions worth knowing:

  • the sums over neighbors include j = i (the reference neighbor list carries self pairs at d_ii = 0), which contribute to I in the embedding and to every message; the model appends one self pair per atom (zero distance and direction, cutoff one) to the pairs of the graph;

  • r_ij points from the neighbor to the center atom, which is the xnn edge vector pos[dst] - pos[src]; the sign only matters for the SO(3) variant;

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

Module Attributes

RECOMPUTE_MIN_PAIRS

Pairs (self pairs included) from which an interaction layer in evaluation mode recomputes its filter network in the backward pass instead of keeping its activations (recompute="auto", see set_recompute_radial()).

Functions

axial_vector(tensor)

The vector v with [v]_x = A of a skew tensor, (N, 3, 3, F) -> (N, 3, F).

compose(scalar, skew, symmetric)

Rebuild (N, 3, 3, F) tensors from their irreducible parts.

decompose(tensor)

Split (N, 3, 3, F) tensors into the scalar (N, F), skew and symmetric traceless parts.

frobenius(tensor)

Squared Frobenius norm of every 3 x 3 tensor, (N, 3, 3, F) -> (N, F).

skew_tensor(vector)

The skew-symmetric tensor [v]_x of a vector, (N, 3, F) -> (N, 3, 3, F).

tensor_matmul(a, b)

Feature-wise matrix product of two (N, 3, 3, F) tensors.

Classes

TensorNet([n_features, n_interactions, ...])

TensorNet interatomic potential (rank-2 Cartesian tensor features).