xnn.trfnn.models.equiformer.Equiformer#

class xnn.trfnn.models.equiformer.Equiformer(irreps_node_embedding='128x0e+64x1e+32x2e', n_interactions=6, cutoff=5.0, n_rbf=32, radial_basis='expnorm', radial_hidden=None, irreps_sh=None, irreps_feature='512x0e', irreps_head='32x0e+16x1e+8x2e', num_heads=4, irreps_pre_attn=None, irreps_mlp_mid='384x0e+192x1e+96x2e', attention='mlp', nonlinear_message=True, rescale_degree=False, alpha_drop=0.0, proj_drop=0.0, out_drop=0.0, drop_path_rate=0.0, avg_degree=15.57930850982666, avg_num_nodes=18.03065905448718, smooth_cutoff=False, n_elements=100, energy_shift=0.0, energy_scale=1.0, species=None, atomic_energies=None)[source]#

Bases: TransformerPotential

Equiformer, the equivariant graph attention transformer.

See the module docstring for the architecture. The defaults are the MD17 model of the paper with l_max = 2 (Table 11, 3.5 M parameters): six blocks of irreps 128x0e+64x1e+32x2e, four heads of 32x0e+16x1e+8x2e, a feed-forward width 384x0e+192x1e+96x2e, 32 exponential-normal radial functions at a 5 Angstrom cutoff, MLP attention with non-linear messages. paper_irreps() gives the irreps of the other architectures of the paper.

Parameters:
  • irreps_node_embedding (str, optional) – Irreps of the node features (d_embed); starts with the even scalars.

  • n_interactions (int, optional) – Number of Transformer blocks, by default 6.

  • cutoff (float, optional) – Neighbor-list radius (Angstrom), by default 5.0.

  • n_rbf (int, optional) – Number of radial basis functions, by default 32.

  • radial_basis (str, optional) – "expnorm" (default), "gaussian" or "bessel".

  • radial_hidden (list of int, optional) – Hidden widths of the radial functions, by default [64, 64].

  • irreps_sh (str, optional) – Spherical-harmonic irreps; by default every degree of the embedding, with the parity convention of the embedding (all even for SE(3)).

  • irreps_feature (str, optional) – Irreps after the last block, by default "512x0e".

  • irreps_head (str, optional) – Value irreps of one attention head, by default "32x0e+16x1e+8x2e".

  • num_heads (int, optional) – Number of attention heads, by default 4.

  • irreps_pre_attn (str, optional) – Irreps of the merged edge feature, by default the embedding irreps.

  • irreps_mlp_mid (str, optional) – Hidden irreps of the feed-forward networks.

  • attention (str, optional) – "mlp" (default) or "dot_product".

  • nonlinear_message (bool, optional) – Non-linear message passing, by default True.

  • rescale_degree (bool, optional) – Multiply the aggregated messages by the number of neighbors, by default False.

  • alpha_drop (float, optional) – Dropout of the attention weights, of the block outputs, of the final features, and the stochastic depth rate; all 0 by default.

  • proj_drop (float, optional) – Dropout of the attention weights, of the block outputs, of the final features, and the stochastic depth rate; all 0 by default.

  • out_drop (float, optional) – Dropout of the attention weights, of the block outputs, of the final features, and the stochastic depth rate; all 0 by default.

  • drop_path_rate (float, optional) – Dropout of the attention weights, of the block outputs, of the final features, and the stochastic depth rate; all 0 by default.

  • avg_degree (float, optional) – Average number of neighbors (normalizes the degree embedding).

  • avg_num_nodes (float, optional) – Average number of atoms (normalizes the energy).

  • smooth_cutoff (bool, optional) – Make the energy continuous at the cutoff, by default False (the paper’s model).

  • n_elements (int, optional) – Size of the atom-type embedding, indexed by Z, by default 100.

  • energy_shift (float, optional) – Per-atom energy standardization, by default 0 and 1.

  • energy_scale (float, optional) – Per-atom energy standardization, by default 0 and 1.

  • species (list of int, optional) – Only used to interpret atomic_energies.

  • atomic_energies (array-like, optional) – Per-species reference energies loaded into atom_ref.

fast_path = 'xnn.trfnn.fast.equiformer'#

the module of the model’s fast path (its AUTO_POLICY and AUTO_POLICY_TRAINING)

node_features_energy(atomic_numbers, edge_index, edge_vec)[source]#

TorchScript-compatible core: scalar features and per-atom energies.

Parameters:
  • atomic_numbers (Tensor) – Per-atom atomic numbers (N,).

  • edge_index (Tensor) – Edge index (2, E); row 0 the neighbor j, row 1 the center i.

  • edge_vec (Tensor) – Edge vectors r_i - r_j (with any periodic image shift), (E, 3).

Returns:

The even scalars of the final features (N, node_feature_dim) and the per-atom energies (N,).

Return type:

tuple of Tensor

node_energy(atomic_numbers, edge_index, edge_vec)[source]#

Per-atom energy (N,) (the LAMMPS / TorchScript entry point).

Parameters:
Return type:

Tensor

forward(data)[source]#

Energies of a batched graph.

Parameters:

data (AtomicGraph) – Batched atomic graph.

Returns:

"node_energy" (N,), "energy" (B,) and "node_features" (the even scalars of the final features).

Return type:

dict of str to Tensor

classmethod from_config(cfg)[source]#

Build an Equiformer from a configuration object.

Core fields: cfg.n_interactions, cfg.n_rbf, cfg.cutoff, and cfg.n_features, the number of even scalars of the paper architecture chosen by extra.l_max (1, 2 or 3, default 2) and extra.e3 (default false), see paper_irreps(). Explicit irreps in extra (irreps_node_embedding, irreps_head, num_heads, irreps_mlp_mid, irreps_sh, irreps_feature, irreps_pre_attn) take precedence. The other options are the keyword arguments of the class, read from cfg.extra.

Parameters:

cfg (xnn.common.config.schema.ModelConfig) – The core model config.

Returns:

Instantiated model.

Return type:

Equiformer