xnn.trfnn.models.equiformer_v2.EquiformerV2#
- class xnn.trfnn.models.equiformer_v2.EquiformerV2(n_features=96, n_interactions=6, cutoff=5.0, n_rbf=128, l_max=4, m_max=4, num_heads=4, attn_hidden_channels=48, attn_alpha_channels=64, attn_value_channels=24, ffn_hidden_channels=96, edge_channels=64, norm_type='layer_norm_sh', activation='sep_s2', use_grid_mlp=True, use_attn_renorm=True, use_atom_edge_embedding=True, share_atom_edge_embedding=False, use_m_share_rad=False, grid_resolution=18, alpha_drop=0.0, drop_path_rate=0.0, proj_drop=0.0, avg_degree=15.57930850982666, avg_num_nodes=18.03065905448718, direct_forces=False, smooth_cutoff=False, weight_init='normal', n_elements=100, energy_shift=0.0, energy_scale=1.0, species=None, atomic_energies=None)[source]#
Bases:
TransformerPotentialEquiformerV2: equivariant graph attention on eSCN convolutions.
See the module docstring for the architecture. The defaults are the QM9 model of the paper (Table 13): six blocks of
C = 96channels up to degree 4, four heads (64 attention scalars and 24 value channels each), hidden widths 48 (attention) and 96 (feed-forward), separable S2 activations on an 18 x 18 grid, separable layer norm, attention re-normalization, and a 5 Angstrom cutoff with 128 Gaussians and edge channels of width 64. The OC20 models arel_max = 6,m_max = 2(or 3),C = 128, 12 to 20 blocks, eight heads.- Parameters:
n_features (int, optional) – Channels per coefficient
C(sphere_channels), by default 96.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 Gaussians of the distance basis, by default 128.
l_max (int, optional) – Highest degree, and highest order kept in the edge frames, by default 4 and 4.
m_max (int, optional) – Highest degree, and highest order kept in the edge frames, by default 4 and 4.
num_heads (int, optional) – Attention heads, by default 4.
attn_hidden_channels (int, optional) – Channels of the first SO(2) convolution, by default 48.
attn_alpha_channels (int, optional) – Per-head widths of the attention scalars and values, by default 64 and 24.
attn_value_channels (int, optional) – Per-head widths of the attention scalars and values, by default 64 and 24.
ffn_hidden_channels (int, optional) – Hidden channels of the feed-forward networks, by default 96.
edge_channels (int, optional) – Hidden width of the radial functions, by default 64.
norm_type (str, optional) –
"layer_norm_sh"(default),"layer_norm"or"rms_norm_sh".activation (str, optional) –
"sep_s2"(default),"s2"or"gate".use_grid_mlp (bool, optional) – Grid MLP in the feed-forward networks, by default True.
use_attn_renorm (bool, optional) – Attention re-normalization, by default True.
use_atom_edge_embedding (bool, optional) – Element embeddings in the radial inputs, by default True.
share_atom_edge_embedding (bool, optional) – One pair of element embeddings for all blocks, by default False.
use_m_share_rad (bool, optional) – Radial weights shared by the orders of a degree, by default False.
grid_resolution (int, optional) – Sphere samples per angle of the S2 activations, by default 18.
alpha_drop (float, optional) – Attention dropout, stochastic depth and channel dropout, all 0 by default.
drop_path_rate (float, optional) – Attention dropout, stochastic depth and channel dropout, all 0 by default.
proj_drop (float, optional) – Attention dropout, stochastic depth and channel dropout, 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).
direct_forces (bool, optional) – Predict the forces with a final attention block (not conservative), by default False.
smooth_cutoff (bool, optional) – Make the energy continuous at the cutoff, by default False.
weight_init (str, optional) –
"normal"(default) or"uniform"initialization of the linear layers.n_elements (int, optional) – Size of the element embeddings, 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_v2'#
the module of the model’s fast path (its
AUTO_POLICYandAUTO_POLICY_TRAINING)
- node_features_energy(atomic_numbers, edge_index, edge_vec)[source]#
TorchScript-compatible core: degree-0 features and per-atom energies.
- Parameters:
atomic_numbers (Tensor) – Per-atom atomic numbers
(N,).edge_index (Tensor) – Edge index
(2, E); row 0 the neighborj, row 1 the centeri.edge_vec (Tensor) – Edge vectors
r_i - r_j(with any periodic image shift),(E, 3).
- Returns:
The degree-0 channels of the final features
(N, C)and the per-atom energies(N,).- Return type:
tuple of Tensor
- Raises:
RuntimeError – For a model with direct forces, whose forces are not the gradient of its energy.
- node_energy(atomic_numbers, edge_index, edge_vec)[source]#
Per-atom energy
(N,)(the LAMMPS / TorchScript entry point).
- forward(data)[source]#
Energies (and, with
direct_forces, forces) of a batched graph.- Parameters:
data (AtomicGraph) – Batched atomic graph.
- Returns:
"node_energy"(N,),"energy"(B,),"node_features"(the degree-0 channels of the final features) and, withdirect_forces,"forces"(N, 3).- Return type:
dict of str to Tensor
- classmethod from_config(cfg)[source]#
Build an
EquiformerV2from a configuration object.Core fields:
cfg.n_features(C),cfg.n_interactions,cfg.n_rbf,cfg.cutoff. Everything else is a keyword argument of the class read fromcfg.extra; the reference code’s spellings (sphere_channels,lmax_list,max_radius, …) are translated byxnn.common.config.translate.- Parameters:
cfg (xnn.common.config.schema.ModelConfig) – The core model config.
- Returns:
Instantiated model.
- Return type: