Modules¶
Neural network modules and model components.
Core Modules¶
core
¶
SRRep(key_out='e_rep', cutoff_fn='none', rc=5.2, reduce_sum=True)
¶
Bases: Module
GFN1-stype short range repulsion function
Source code in aimnet/modules/core.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
MLP(n_in, n_out, hidden=None, activation_fn='torch.nn.GELU', activation_kwargs=None, weight_init_fn='torch.nn.init.xavier_normal_', bias=True, last_linear=True)
¶
Convenience function to build MLP from config
Source code in aimnet/modules/core.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
AEV and Convolution Modules¶
aev
¶
AEVSV(rmin=0.8, rc_s=5.0, nshifts_s=16, eta_s=None, rc_v=None, nshifts_v=None, eta_v=None, shifts_s=None, shifts_v=None)
¶
Bases: Module
AEV module to expand distances and vectors toneighbors over shifted Gaussian basis functions.
Parameters:¶
rmin : float, optional
Minimum distance for the Gaussian basis functions. Default is 0.8.
rc_s : float, optional
Cutoff radius for scalar features. Default is 5.0.
nshifts_s : int, optional
Number of shifts for scalar features. Default is 16.
eta_s : Optional[float], optional
Width of the Gaussian basis functions for scalar features. Will estimate reasonable default.
rc_v : Optional[float], optional
Cutoff radius for vector features. Default is same as rc_s.
nshifts_v : Optional[int], optional
Number of shifts for vector features. Default is same as nshifts_s
eta_v : Optional[float], optional
Width of the Gaussian basis functions for vector features. Will estimate reasonable default.
shifts_s : Optional[List[float]], optional
List of shifts for scalar features. Default equidistant between rmin and rc_s
shifts_v : Optional[List[float]], optional
List of shifts for vector features. Default equidistant between rmin and rc_v
Source code in aimnet/modules/aev.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
ConvSV(nshifts_s, nchannel, d2features=False, nshifts_v=None, ncomb_v=None)
¶
Bases: Module
AIMNet2 type convolution: encoding of local environment which combines geometry of local environment and atomic features.
Parameters:¶
nshifts_s : int Number of shifts (gaussian basis functions) for scalar convolution. nchannel : int Number of feature channels for atomic features. d2features : bool, optional Flag indicating whether to use 2D features. Default is False. nshifts_v : Optional[int], optional Number of shifts for vector convolution. If not provided, defaults to the value of nshifts_s. ncomb_v : Optional[int], optional Number of linear combinations for vector features. If not provided, defaults to the value of nshifts_v.
Source code in aimnet/modules/aev.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
Long-Range Modules¶
lr
¶
D3TS(a1, a2, s8, s6=1.0, key_in='disp_param', key_out='energy')
¶
Bases: Module
DFT-D3-like pairwise dispersion with TS combination rule
Source code in aimnet/modules/lr.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 | |
DFTD3(s8, a1, a2, s6=1.0, cutoff=15.0, smoothing_fraction=0.2, key_out='energy')
¶
Bases: Module
DFT-D3 implementation using nvalchemiops GPU-accelerated kernels.
BJ damping, C6 and C8 terms, without 3-body term.
This implementation uses nvalchemiops.torch.interactions.dispersion.dftd3 for GPU-accelerated computation of dispersion energies, forces, and virial. The embedded model path injects explicit forces/virial into autograd only when coordinate or strain gradients are requested; the external calculator path returns detached derivative terms.
Parameters¶
s8 : float Scaling factor for C8 term. a1 : float BJ damping parameter 1. a2 : float BJ damping parameter 2. s6 : float, optional Scaling factor for C6 term. Default is 1.0. cutoff : float, optional Cutoff distance in Angstroms for smoothing. Default is 15.0. smoothing_fraction : float, optional Fraction of cutoff distance used for smoothing window width. Smoothing starts at cutoff * (1 - smoothing_fraction) and ends at cutoff. Example: With cutoff=15.0 and smoothing_fraction=0.2: - Smoothing starts at 12.0 Ã… (15.0 * 0.8) - Smoothing ends at 15.0 Ã… Default is 0.2 (20% of cutoff as smoothing window). key_out : str, optional Key for output energy in data dict. Default is "energy". Attributes
smoothing_on : float Distance where smoothing starts (Angstroms). smoothing_off : float Distance where smoothing ends / cutoff (Angstroms). s6, s8, a1, a2 : float BJ damping parameters.
Notes¶
Neighbor list keys follow a suffix resolution pattern: methods first look for module-specific keys (e.g., nbmat_dftd3, shifts_dftd3), falling back to shared _lr suffix (nbmat_lr, shifts_lr) if not found.
Source code in aimnet/modules/lr.py
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 | |
forward(data, *, compute_forces=False, compute_virial=False, hessian=False, scaling=None, coord_unstrained=None, cell_unstrained=None)
¶
Compute DFT-D3 energy and optional explicit derivative terms.
The embedded path returns an autograd-capable energy only when the coordinate or explicit calculator strain inputs require it. Explicit derivative requests return detached energy and derivative terms. The strain-wrapper kwargs are for direct differentiable callers; the calculator uses explicit derivative terms for stress because DFT-D3 has no trainable parameters.
The returned virial follows the calculator-side external-derivative
convention: get_derivatives subtracts terms.virial.mT from the
strain gradient (the same path DSF uses). FD-validated against
dE/dscaling in :class:tests.test_dftd3.TestDFTD3ForwardTerms.
Source code in aimnet/modules/lr.py
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 | |
set_smoothing(cutoff, smoothing_fraction=0.2)
¶
Update smoothing parameters based on new cutoff and fraction.
Parameters¶
cutoff : float Cutoff distance in Angstroms. smoothing_fraction : float Fraction of cutoff used as smoothing window width. Smoothing occurs from cutoff * (1 - smoothing_fraction) to cutoff. Example: smoothing_fraction=0.2 means smoothing over last 20% of cutoff distance (from 0.8*cutoff to cutoff). Default is 0.2.
Source code in aimnet/modules/lr.py
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 | |
ExternalDerivativeTerms(forces=None, virial=None, hessian=None)
dataclass
¶
Explicit derivative terms returned by external nvalchemiops backends.
LRCoulomb(key_in='charges', key_out='e_h', rc=4.6, method='simple', dsf_alpha=0.2, dsf_rc=15.0, ewald_accuracy=1e-06, subtract_sr=True, envelope='exp')
¶
Bases: Module
Long-range Coulomb energy module.
Computes electrostatic energy using one of several methods:
simple (all pairs), DSF (damped shifted force), Ewald summation, or
Particle Mesh Ewald (PME). DSF, Ewald, and PME are backed by
nvalchemiops; Ewald and PME require periodic systems with a cell.
Parameters¶
key_in : str Key for input charges in data dict. Default is "charges". key_out : str Key for output energy in data dict. Default is "e_h". rc : float Short-range cutoff radius. Default is 4.6 Angstrom. method : str Coulomb method: "simple", "dsf", "ewald", or "pme". Default is "simple". dsf_alpha : float Alpha parameter for DSF method. Default is 0.2. dsf_rc : float Cutoff for DSF method. Default is 15.0. ewald_accuracy : float Target accuracy for Ewald and PME summation. Controls real-space and reciprocal-space cutoffs (and PME mesh dimensions). Lower values give higher accuracy at higher cost. Default is 1e-6. subtract_sr : bool Whether to subtract short-range contribution. Default is True. envelope : str Envelope function for SR cutoff: "exp" or "cosine". Default is "exp".
Notes¶
Energy accumulation uses float64 for numerical precision, particularly important for large systems where many small contributions can suffer from floating-point error accumulation.
Neighbor list keys follow a suffix resolution pattern: methods first look for module-specific keys (e.g., nbmat_coulomb, shifts_coulomb), falling back to shared _lr suffix (nbmat_lr, shifts_lr) if not found.
DSF uses nvalchemiops.torch.interactions.electrostatics.dsf_coulomb
for plain inference. DSF Hessian and force/stress training instead go
through a closed-form pure-PyTorch path (:meth:_coul_dsf_torch), which is
twice-differentiable by autograd and RELAXED-CHARGE: it differentiates
through the model-predicted charges, so its Hessian includes the
charge-response (the d^2E / (dq . dr) coupling).
Ewald/PME call nvalchemiops directly. Inference uses
hybrid_forces=True so energy remains differentiable through charges
and fixed-charge geometry derivatives are returned as explicit terms.
Training derivative paths use a small local autograd.Function wrapper
because the installed nvalchemiops coordinate backward kernels do not
currently provide a registered backward-of-backward. Ewald/PME Hessians are
provided by finite-difference of the analytic nvalchemiops forces
(:meth:_coul_nvalchemi_fd_hessian) and are FIXED-CHARGE: they omit the
d^2E / (dq . dr) charge-response coupling.
Because of this, DSF (relaxed-charge) and Ewald/PME (fixed-charge) Hessians differ slightly for an otherwise-equivalent system, which matters when comparing vibrational frequencies / IR across backends.
Source code in aimnet/modules/lr.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
coul_ewald(data)
¶
Per-system Ewald energy in eV. Requires cell and nbmat_lr/shifts_lr.
Source code in aimnet/modules/lr.py
891 892 893 894 | |
coul_pme(data)
¶
Per-system PME energy in eV. Requires cell and nbmat_lr/shifts_lr.
Source code in aimnet/modules/lr.py
896 897 898 899 | |
coul_simple(data)
¶
Compute pairwise Coulomb energy.
With subtract_sr=True (default): Returns LR only (FULL - SR) With subtract_sr=False: Returns FULL pairwise Coulomb
Source code in aimnet/modules/lr.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
SRCoulomb(rc=4.6, key_in='charges', key_out='energy', envelope='exp')
¶
Bases: Module
Subtract short-range Coulomb contribution from energy.
For models trained with "simple" Coulomb mode, the NN has implicitly learned the short-range Coulomb interaction. When using DSF or Ewald summation for the full Coulomb energy, we need to subtract this short-range contribution to avoid double-counting.
Parameters¶
rc : float Cutoff radius for short-range Coulomb. Default is 4.6 Angstrom. key_in : str Key for input charges in data dict. Default is "charges". key_out : str Key for output energy in data dict. Default is "energy". envelope : str Envelope function for cutoff: "exp" (mollifier) or "cosine". Default is "exp".
Source code in aimnet/modules/lr.py
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
forward(data)
¶
Subtract short-range Coulomb from energy.
Source code in aimnet/modules/lr.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
AIMNet2 Model¶
aimnet2
¶
Base Classes¶
base
¶
AIMNet2Base()
¶
Bases: Module
Base class for AIMNet2 models. Implements pre-processing data: converting to right dtype and device, setting nb mode, calculating masks.
Source code in aimnet/models/base.py
211 212 213 214 | |
metadata
property
¶
Return model metadata if available.
prepare_input(data)
¶
Common operations for input preparation.
Source code in aimnet/models/base.py
230 231 232 233 234 235 236 237 238 239 | |
ModelMetadata
¶
Bases: TypedDict
Metadata returned by load_model().
This TypedDict documents the structure of the metadata dictionary.
load_model(path, device='cpu')
¶
Load model from file, supporting both new and legacy formats.
Automatically detects format: - New format: state dict with embedded YAML config and metadata - Legacy format: JIT-compiled TorchScript model
Parameters¶
path : str Path to the model file (.pt or .jpt). device : str Device to load the model on. Default is "cpu".
Returns¶
model : nn.Module The loaded model with weights. metadata : ModelMetadata Dictionary containing model metadata. See ModelMetadata TypedDict for fields.
Notes¶
For legacy JIT models (format_version=1), needs_coulomb and needs_dispersion
are False because LR modules are already embedded in the TorchScript model.
Source code in aimnet/models/base.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |