xnn.dnn.models.base.DescriptorPotential#

class xnn.dnn.models.base.DescriptorPotential(featurizer, species, hidden=(64, 64), activation='silu', bias=True, atomic_energies=None, extra_inputs=0)[source]#

Bases: InteratomicPotential

Shared body for descriptor-based potentials (HDNNP, ANI).

Composition: featurizer (AtomicGraph -> per-atom descriptor) + per-element atomic networks (+ optional per-species self atomic energies). Reuse by passing any invariant Featurizer; HDNNP and ANI are thin subclasses that differ in the featurizer and per-element architecture.

Parameters:
  • featurizer (Featurizer) – Invariant featurizer mapping an AtomicGraph to a per-atom descriptor of shape (N, featurizer.output_dim). Its cutoff sets the model’s neighbour-list cutoff. A featurizer with an n_features {Z: width} dict (the atom-centered symmetry functions) gives every element a network on its own leading columns.

  • species (sequence of int) – Atomic numbers to build per-element networks for.

  • hidden (sequence of int or dict[int, sequence of int], optional) – Hidden-layer widths of each per-element MLP (shared sequence or per-Z dict), by default (64, 64).

  • activation (str, torch.nn.Module, sequence or dict, optional) – Hidden-layer activation, by default "silu", or the per-layer list of _ElementNetworks.

  • bias (bool, optional) – Whether the linear layers carry a bias, by default True.

  • atomic_energies (sequence of float or None, optional) – Per-species self atomic energy added to each atom’s contribution (aligned with species). None (default) adds nothing.

  • extra_inputs (int, optional) – Per-atom inputs appended to the descriptor of the element networks, by default 0.

Variables:
  • featurizer (Featurizer) – The composed featurizer.

  • cutoff (float) – Neighbour-list cutoff, taken from featurizer.cutoff.

  • species (list[int]) – The elements handled.

  • element_nets (_ElementNetworks) – Per-element atomic MLPs.

set_use_fast(use_fast)[source]#

Choose the implementation of the featurizer.

Parameters:

use_fast (bool or str) – "auto" (the default): the fused GPU kernels of the featurizer (the AEV of xnn.dnn.fast.aev) where 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, so force training takes them as well. The HDNNP symmetry functions have GPU kernels and, in evaluation, a compiled CPU path and optional C++ kernels (xnn.dnn.fast.acsf).

Returns:

self.

Return type:

DescriptorPotential

fast_policies()[source]#

The "auto" policies (evaluation, training): the featurizer’s (None: always fast).

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

Tensor core (TorchScript-compatible): the descriptor (N, D) and the per-atom energies (N,) including the self energies, from atomic numbers (N,), edges (2, E) and edge vectors (E, 3). The featurizer must offer compute.

Parameters:
Return type:

Tuple[Tensor, Tensor]

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

Per-atom energies (N,) (the deploy entry point, node_features_energy()).

Parameters:
Return type:

Tensor

forward(data)[source]#

Compute per-atom and total energies for a batch of structures.

Parameters:

data (AtomicGraph) – Batched atomic graph passed to the featurizer.

Returns:

Dictionary with "node_energy" (per-atom energy including the self-energy shift, shape (N,)), "energy" (per-structure total from aggregate_energy) and "node_features" (the descriptor).

Return type:

dict[str, Tensor]