xnn.gnn.models.aimnet2.AIMNet2#
- class xnn.gnn.models.aimnet2.AIMNet2(species, cutoff=5.0, n_features=16, n_rbf=16, rbf_start=0.8, gaussian_width=None, hidden=None, n_passes=3, n_vector_combinations=12, aim_size=256, readout_hidden=(128, 128), charge_channels=1, coulomb='simple', coulomb_sr_cutoff=4.6, coulomb_sr_envelope='exp', lr_cutoff=15.0, dsf_alpha=0.2, ewald_accuracy=1e-06, pme_spline_order=4, atomic_energies=None)[source]#
Bases:
GNNPotentialThe AIMNet2 potential (Anstine et al. 2025); see the module docstring.
Subclasses
GNNPotentialfor the species bookkeeping and the per-element reference energyatom_ref(the paper’s atomic energy shifts, kept in float64 whatever the model dtype).- Parameters:
species (list of int) – Atomic numbers of the supported elements, in channel order.
cutoff (float, optional) – Radius of the local environment (the Gaussian basis and its cosine cutoff), by default 5.0 Angstrom. The neighbor-list radius
self.cutoffis this, orlr_cutoffwith a long-range Coulomb method ("dsf","ewald","pme").n_features (int, optional) – Embedding channels
dper radial shell, by default 16.n_rbf (int, optional) – Gaussian basis functions (radial shells
s), by default 16.rbf_start (float, optional) – Center of the first Gaussian, by default 0.8 Angstrom; the centers are
rbf_start + s (cutoff - rbf_start) / n_rbf.gaussian_width (float or None, optional) – Exponent
etaof the Gaussians;None(default) uses the reference choice(n_rbf / (cutoff - rbf_start))^2(the inverse squared spacing).hidden (sequence of sequences of int or None, optional) – Hidden widths of the MLP of each message pass; the number of passes is their count (at least two: the first pass predicts the charges, the last the AIM vector).
Nonegives the published architecture[[512, 380], [512, 380], [512, 380, 380]]forn_passes.n_passes (int, optional) – Number of message passes when
hiddenisNone, by default 3.n_vector_combinations (int, optional) – Learned shell combinations
hof the vector features, by default 12.aim_size (int, optional) – Width of the AIM vector (the
node_features), by default 256.readout_hidden (sequence of int, optional) – Hidden widths of the energy MLP, by default
(128, 128).charge_channels (int, optional) – 1 (closed shell, default) or 2 (AIMNet2-NSE: one channel per spin).
coulomb (str or None, optional) –
"simple"(default): the all-pairs Coulomb energy of molecular structures;"dsf": the damped shifted-force truncation atlr_cutoffover the neighbor list (periodic structures, large molecules);"ewald"/"pme": the Ewald sum of periodic structures, its real-space part over the neighbor list withinlr_cutoffand its reciprocal part over the lattice vectors or on a particle mesh (non-periodic structures of the batch get the all-pairs sum);None: no electrostatics (AIMNet2-Pd).coulomb_sr_cutoff (float, optional) – Radius within which the implicitly learned Coulomb energy is subtracted, by default 4.6 Angstrom.
coulomb_sr_envelope (str, optional) – Its envelope,
"exp"(the mollifier, default) or"cosine".lr_cutoff (float, optional) – Real-space cutoff of the long-range methods, by default 15.0 Angstrom.
dsf_alpha (float, optional) – Damping parameter of
coulomb="dsf", by default 0.2 per Angstrom.ewald_accuracy (float, optional) – Target relative accuracy of the Ewald and PME sums, by default
1e-6; sets the splitting parameter and the reciprocal cutoff (ewald_parameters()) and the PME mesh.pme_spline_order (int, optional) – B-spline order of the PME charge assignment, by default 4 (cubic).
atomic_energies (array-like or None, optional) – Per-element energy shifts, one per entry of
species.
- Raises:
ValueError – For fewer than two passes, an unknown
coulombmethod or envelope,charge_channelsoutside{1, 2}, an accuracy outside(0, 1)or a spline order below 3.
- equilibrate(charges, weights, total, batch, num_graphs, eps=1e-06)[source]#
Neural charge equilibration (paper eq 6).
- Parameters:
charges (Tensor) – Charges before equilibration
(N, C).weights (Tensor) – Non-negative weights
f(N, C).total (Tensor) – Target total per structure and channel
(B, C).batch (Tensor) – Structure index per atom
(N,).num_graphs (int) – Number of structures
B.eps (float, optional) – Regularization of the weight sum, by default
NQE_EPSILON.
- Returns:
Charges
(N, C)whose structure sums equaltotal(up to the regularization of the weight sum).- Return type:
Tensor
- channel_totals(total_charge, spin_multiplicity)[source]#
The net charge of every structure split over the charge channels,
(B, C).One channel carries
Q; two channels carry(Q +- (M - 1)) / 2.- Parameters:
total_charge (Tensor) – Net charges
(B,).spin_multiplicity (Tensor) – Multiplicities
(B,)(read by the two-channel models only).
- Return type:
- node_features_energy_charges(atomic_numbers, edge_index, edge_vec, pos, cell, pbc, total_charge, spin_multiplicity)[source]#
TorchScript core of one structure: AIM features, atomic energies and charges.
The entry point
TorchScriptPotentialexports; the net charge and spin multiplicity are fixed at export.- Parameters:
atomic_numbers (Tensor) –
(N,).edge_index (Tensor) –
(2, E)withinself.cutoff.edge_vec (Tensor) –
(E, 3).pos (Tensor) –
(N, 3).cell (Tensor) –
(3, 3)(ignored unlesspbchas a true entry).pbc (Tensor) –
(3,)bool.total_charge (float) – Net charge of the structure.
spin_multiplicity (float) – Its spin multiplicity (two-channel models).
- Returns:
node_features (N, aim_size),node_energy (N,)(float64, Coulomb energy included) andcharges (N,).- Return type:
tuple of Tensor
- forward(data)[source]#
Predict energies, partial charges and the dipole of a (batched) graph.
- Parameters:
data (xnn.common.data.AtomicGraph) – The input graph, built with
self.cutoff.total_charge(None= neutral) sets the net charge the partial charges sum to;spin_multiplicity(None= 1) is read by the two-channel (NSE) models.- Returns:
"node_energy"(N,)and"energy"(B,)in float64 (as every xnn model),"node_features"(N, aim_size)(the AIM vector),"charges"(N,),"dipole"(B, 3)in e Angstrom,"energy_coulomb"(B,)(the electrostatic part of the energy; zeros without a Coulomb term) and, for the two-channel models,"spin_charges"(N,).- Return type:
dict of str to torch.Tensor
- Raises:
ValueError – For an element outside
species, a periodic structure withcoulomb="simple"(use"dsf","ewald"or"pme"), or a partially periodic structure with"ewald"/"pme".
- classmethod from_config(cfg)[source]#
Construct an
AIMNet2from a core model config.Core fields:
cfg.cutoff(the local cutoff),cfg.n_features(embedding channels),cfg.n_rbf(radial shells) andcfg.n_interactions(message passes, whenextra["hidden"]does not list the MLP widths of every pass). The remaining options are the constructor arguments, read fromcfg.extra; the reference code’s spellings (nfeature,nshifts_s,rc_s,ncomb_v,num_charge_channels) are translated at config-load time byxnn.common.config.translate.Alternatively
extra["foundation"]names a published AIMNet2 checkpoint (seefrom_foundation()); the bare network is returned and every architecture key comes from the checkpoint, while the Coulomb options (coulomb,lr_cutoff,dsf_alpha,ewald_accuracy,pme_spline_order) may be overridden.- Parameters:
cfg (xnn.common.config.schema.ModelConfig) – The core model config.
- Returns:
The instantiated model.
- Return type:
- Raises:
ValueError – If
cfg.cutoffdiffers from a foundation checkpoint’s neighbor-list cutoff.
- classmethod from_foundation(source, dtype=None, cache_dir=None, dispersion=None, **model_options)[source]#
Load a published AIMNet2 model.
Downloads (and caches) the requested checkpoint if needed and converts it weight for weight into this implementation; see
xnn.gnn.models.aimnet2_foundationfor the registry and the conversion. The published models are served with the D3(BJ) dispersion they were trained without, so by default the returned potential is the network wrapped in the sharedD3Dispersionterm.- Parameters:
source (str, Path or Mapping) – A registered name or alias (
"aimnet2","aimnet2-nse","aimnet2-wb97m-d3-2", …; seeFOUNDATION_MODELS), a checkpoint URL or local path (the reference.ptartifact, or a directory ofconfig.json+ensemble_<k>.safetensors), or an already-loaded artifact mapping.dtype (torch.dtype or str, optional) – Final dtype;
Nonekeeps the checkpoint’s float32 (the per-element shifts stay float64 either way).cache_dir (str or Path, optional) – Model hub cache directory.
dispersion (dict, str, bool or None, optional) –
None(default) adds the D3(BJ) term recorded for the model,Falsereturns the bareAIMNet2; seeload_pretrained().**model_options – Deployment knobs applied before the model is built, e.g.
coulomb="dsf"withlr_cutoff=15.0, orcoulomb="ewald"/"pme"withewald_accuracy=1e-6, for periodic structures.
- Returns:
The
AIMNet2model, inside its dispersion term unlessdispersion=False.- Return type: