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
198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
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
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 64 | |
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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
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
907 908 909 910 911 912 913 914 915 916 | |
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
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 | |
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
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 | |
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
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
ExternalDerivativeTerms(forces=None, virial=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 and PME call nvalchemiops (>=0.4.1) energy-only with
positions, charges, and cell left in the autograd graph: forces, stress,
dense Hessians, and HVPs come from the calculator's total-energy
autograd and are RELAXED-CHARGE (they include the d^2E / (dq . dr)
charge-response coupling), the same contract as the DSF torch path.
Selecting PME raises on nvalchemiops < 0.4.1: on 0.4.0 the PME
charge-gradient backward silently corrupts train-mode forces inside the
full calculator graph (create_graph=True), fixed upstream in 0.4.1.
Source code in aimnet/modules/lr.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
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
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
forward(data, *, compute_forces=False, compute_virial=False, training_derivatives=False, hessian=False)
¶
Add the long-range Coulomb energy to data[self.key_out].
The mode flags select between explicit-terms and differentiable paths
for simple/dsf. ewald/pme are energy-graph-only and
ignore all four flags: they never return explicit terms (terms is
None), and every derivative comes from autograd of the energy.
Source code in aimnet/modules/lr.py
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
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
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
forward(data)
¶
Subtract short-range Coulomb from energy.
Source code in aimnet/modules/lr.py
813 814 815 816 817 818 819 820 821 822 | |
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
262 263 264 265 | |
metadata
property
¶
Return model metadata if available.
prepare_input(data)
¶
Common operations for input preparation.
Source code in aimnet/models/base.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
ModelMetadata
¶
Bases: TypedDict
Metadata returned by load_model().
This TypedDict documents the structure of the metadata dictionary.
assemble_v2_model(model_config, state_dict, metadata, *, policy, device, source, unexpected)
¶
Construct and populate a validated v2 model under an explicit policy.
Source code in aimnet/models/base.py
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 | |
load_legacy_jit(path, device='cpu')
¶
Load a legacy TorchScript model from a trusted .jpt source.
TorchScript is format-specific but is not a sandbox. Only load .jpt
files from sources whose code and provenance the caller trusts.
Source code in aimnet/models/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
load_model(path, device='cpu', *, model_import_paths=None, model_import_mode='extend')
¶
Load a v2 model or explicitly routed legacy .jpt model.
Files ending in .jpt (case-insensitive) are loaded with
:func:torch.jit.load and therefore must come from a trusted source.
Every other suffix is loaded exactly once with restricted
torch.load(weights_only=True).
Parameters¶
path : str
Path to a v2 .pt or trusted legacy .jpt model.
device : str
Device on which to load the model.
model_import_paths : Collection[str] | None
Python imports trusted when loading a v2 file. Entries are exact dotted
paths or namespaces ending in .*, such as
{"my_package.models.CustomModel", "my_package.layers.*"}.
model_import_mode : {"extend", "replace", "unsafe"}
extend adds model_import_paths to the default trusted paths;
replace requires a nonempty collection and uses only those paths.
unsafe cannot be combined with paths and permits arbitrary imported
constructors. No mode relaxes restricted deserialization or artifact
validation.
Returns¶
model : nn.Module The loaded model with weights. metadata : ModelMetadata Validated model metadata.
Use unsafe only for locally trusted artifacts. Legacy .jpt files
accept only model_import_paths=None and model_import_mode="extend".
Source code in aimnet/models/base.py
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 | |
load_registry_model(path, device='cpu')
¶
Load a registry artifact with its immutable import policy.
Source code in aimnet/models/base.py
203 204 205 206 207 208 209 210 211 | |