xnn.gnn.models.schnet.SchNet#
- class xnn.gnn.models.schnet.SchNet(n_features=128, n_interactions=6, n_rbf=20, cutoff=5.0, radial_basis='gaussian', gamma=None, cutoff_fn='cosine', n_filters=None, filter_output_activation=False, interaction_input_bias=False, readout_activation='silu', shared_interactions=False, weight_init='xavier_uniform', zero_init_readout=False, energy_shift=0.0, energy_scale=1.0, species=None, atomic_energies=None)[source]#
Bases:
ExactFloat64Constants,InteratomicPotentialSchNet continuous-filter convolutional interatomic potential.
Faithful to the NIPS 2017 manuscript (see the module docstring for the equation-by-equation walk-through): embeds atoms by nuclear charge, refines their features through
Tresidual interaction blocks built around the continuous-filter convolution, and reads out a per-atom energy through a two-layer atom-wise network. Per-atom energies are standardized with the training-set statistics (E_i = energy_scale * E^hat_i + energy_shift, the DTNN convention) plus a per-element referenceatom_ref, then sum-pooled into the total energy. Works unchanged for molecules and periodic solids, since periodicity enters only through the edge vectors.The defaults and the paper’s options are listed in the module docstring; the paper’s grid is 301 Gaussians every 0.1 Angstrom from 0 to 30 Angstrom with
gamma = 10(“centers 0 <= mu_k <= 30 every 0.1 Angstrom”).- Parameters:
n_features (int, optional) – Dimension
Fof the per-atom feature vectors, by default 128 (the paper: 64).n_interactions (int, optional) – Number of stacked interaction blocks
T, by default 6 (the paper: 3).n_rbf (int, optional) – Number of radial basis functions expanding the distances, by default 20 (the paper: 301, a 0.1-Angstrom spacing on
[0, 30]).cutoff (float, optional) – Neighbor-list radius and upper end of the radial basis (Angstrom), by default 5.0. The paper uses no explicit cutoff; 30 Angstrom covers all pairs of its molecular datasets.
radial_basis (str, optional) – Any basis of
make_radial_basis(), by default"gaussian"(the paper’s).gamma (float or None, optional) – Exponent of the Gaussians,
exp(-gamma (r - mu)^2);None(default) ties the width to the center spacing (the paper: 10.0 per Angstrom^2).cutoff_fn (str or None, optional) –
"cosine"(default) multiplies the generated filters by a smoothCosineCutoffenvelope, which keeps the energy smooth at a finite cutoff;Noneis the paper’s unmodulated filter.n_filters (int or None, optional) – Width of the filters, by default
None(equal toF, the paper’s).filter_output_activation (bool, optional) – A shifted softplus after the second filter layer too (the paper’s two activated layers), by default
False.interaction_input_bias (bool, optional) – A bias in the first atom-wise layer of every block (the paper’s), by default
False.readout_activation (str, optional) – Activation of the readout network (any name of
make_activation()), by default"silu"(the paper:"ssp").shared_interactions (bool, optional) – One interaction block shared by all
T, by defaultFalse.weight_init (str, optional) – Initialization of every dense layer (a name of
WEIGHT_INITS; biases start at zero), by default"xavier_uniform";"torch"keeps PyTorch’s.zero_init_readout (bool, optional) – Start the last readout layer at zero, so that a fresh model predicts
energy_shift + atom_ref(the DTNN convention), by defaultFalse.energy_shift (float, optional) – Additive per-atom energy standardization
E_mu(the training-set mean energy per atom, DTNN Methods step 4), by default 0.0. Stored as a non-trainable buffer; seeset_energy_scale_shift().energy_scale (float, optional) – Multiplicative per-atom energy standardization
E_sigma(the training-set standard deviation of the energy per atom), by default 1.0.species (list of int or None, optional) – Only used to interpret
atomic_energies; the model itself handles all elements up to Z = 99.atomic_energies (array-like or None, optional) – Per-species reference energies loaded into
atom_ref(aligned withspecies).
- Variables:
cutoff (float) – Neighbor-list cutoff radius.
embedding (torch.nn.Embedding) – Nuclear-charge-to-feature embedding
a_Z(paper eq 3).rbf (torch.nn.Module) – Radial basis expansion of interatomic distances.
interactions (torch.nn.ModuleList) – Stack of
_Interactionblocks.cutoff_fn (CosineCutoff or None) – The filter envelope, or
Nonefor the paper’s unmodulated filter.readout (torch.nn.Sequential) – Atom-wise MLP (
F -> F/2 -> 1) mapping final features to the unstandardized per-atom energyE^hat_i(its last layer starts at zero withzero_init_readout).atom_ref (torch.nn.Embedding) – Learnable per-element energy reference (shift), initialized to zero.
- set_use_fast(use_fast)[source]#
Choose the implementation of the continuous-filter convolutions.
- Parameters:
use_fast (bool or str) –
"auto"(the default): the fused GPU kernels ofxnn.gnn.fast.schnetwhere they are available and faster for the input (a CUDA device, Triton, a graph above the size crossover measured for evaluation,AUTO_POLICY, or for training,AUTO_POLICY_TRAINING);True: wherever they are available;False: always the reference implementation. The kernels are twice differentiable and reach the weights, so force training takes them as well. In float32 the kernels agree with the reference to about 1e-6 relative, in float64 to about 1e-14.- Returns:
self.- Return type:
- set_energy_scale_shift(scale, shift)[source]#
Set the DTNN per-atom energy standardization from training stats.
- set_atomic_energies(species, values)[source]#
Initialize the per-element reference energies
atom_ref.- Parameters:
- Raises:
ValueError – If the number of values does not match the number of species.
- Return type:
None
- node_features_energy(atomic_numbers, edge_index, edge_vec)[source]#
TorchScript-compatible core: tensors in, features + energy out.
The single implementation reused by
node_energy()(the deploy entry point) andforward(), so it must avoid the AtomicGraph dataclass and any Python-only constructs.- Parameters:
atomic_numbers (Tensor) – Per-atom atomic numbers, shape
(N,).edge_index (Tensor) – Edge index of shape
(2, E); row 0 is the source (neighbor) and row 1 the destination (center) node of each edge.edge_vec (Tensor) – Edge displacement vectors, shape
(E, 3)(already accounting for any periodic cell shifts).
- Returns:
The invariant node features after the last interaction block
(N, node_feature_dim)and the per-atom energy(N,)(standardized and including the per-element reference shift).- Return type:
tuple of Tensor
- node_energy(atomic_numbers, edge_index, edge_vec)[source]#
Per-atom energy, shape
(N,)(thin wrapper overnode_features_energy(); the deploy wrappers call this).
- forward(data)[source]#
Compute per-atom and total energies for a batch of structures.
- Parameters:
data (AtomicGraph) – Batched atomic graph providing atomic numbers, edge index and edge vectors.
- Returns:
Dictionary with
"node_energy"(per-atom energy, shape(N,)),"energy"(per-structure total energy, the sum pooling of Fig. 2) and"node_features"(invariant per-atom features, shape(N, node_feature_dim)).- Return type:
- classmethod from_config(cfg)[source]#
Build a
SchNetfrom a configuration object.Core fields:
cfg.n_features->F,cfg.n_interactions->T,cfg.n_rbfandcfg.cutoff-> the RBF grid / neighbor-list radius. Everything else is read fromcfg.extra(radial_basis,gamma,cutoff_fn(nullfor none),n_filters,filter_output_activation,interaction_input_bias,readout_activation,shared_interactions,weight_init,zero_init_readout,energy_shift,energy_scale,species,atomic_energies); other codes’ key spellings are translated byxnn.common.config.translate.- Parameters:
cfg (xnn.common.config.schema.ModelConfig) – The core model config.
- Returns:
Instantiated model.
- Return type: