xnn.gnn.models.egt#

Edge-augmented graph transformer over the bonds of a molecule.

The edge-augmented graph transformer (EGT; Hussain, Zaki & Subramanian, KDD 2022, https://doi.org/10.1145/3534678.3539296) lets edge channels steer and gate the attention between nodes and updates the edges from the attention logits. Here the attention is local, between bonded atoms only, as in ByteFF (Zheng et al., Chem. Sci. 16, 2730 (2025)), where the network reads the two-dimensional molecular graph and its outputs parameterize a classical force field.

MolecularGraphTransformer embeds the integer atom and bond features of xnn.gnn.featurizers.molgraph, averages the embeddings over classes of equivalent atoms and bonds, runs the attention layers and returns per-atom and per-directed-edge hidden states (the two directions of a bond averaged).

Module Attributes

N_ELEMENTS

elements (atomic number - 1), neighbors, formal charges (-2..2), ring bonds, smallest ring size.

MAX_DEGREE

elements (atomic number - 1), neighbors, formal charges (-2..2), ring bonds, smallest ring size.

MAX_FORMAL_CHARGE

elements (atomic number - 1), neighbors, formal charges (-2..2), ring bonds, smallest ring size.

MAX_RING

elements (atomic number - 1), neighbors, formal charges (-2..2), ring bonds, smallest ring size.

N_BOND_RING

in ring (0/1), bond order (single, double, triple, aromatic).

N_BOND_ORDER

in ring (0/1), bond order (single, double, triple, aromatic).

Functions

class_mean(x, cls)

Each row of x replaced by the mean over the rows of its class cls (class labels index rows, the first member of each class).

Classes

EGTLayer(dim[, heads, head_dim, ffn, ...])

One local EGT layer: edge-biased, edge-gated multi-head attention between bonded atoms, pre-norm residual updates of nodes and edges.

GraphEmbedding([atom_dim, feature_dim, ...])

Embeddings of the atom and bond features, mixed by MLPs and averaged over equivalent atoms and bonds.

MolecularGraphTransformer([atom_dim, ...])

Atom and bond hidden states of molecules from their two-dimensional graphs.