xnn.common.deploy.ase_calculator.XNNCalculator#
- class xnn.common.deploy.ase_calculator.XNNCalculator(model, cutoff, device='cpu', **kwargs)[source]#
Bases:
CalculatorASE Calculator wrapping a trained xnn model.
This is an ase.calculators.calculator.Calculator subclass that lets a trained model drive standard ASE workflows (energy, force and stress evaluation, dynamics, optimization, etc.). It converts an
Atomsobject into the model’s graph representation, runs the model and stores the results in the ASE-expected units and layout.Requires
aseto be installed (optional extra:pip install "xnn[ase]"); constructing an instance raisesImportErrorif ASE is not available.- Parameters:
model (torch.nn.Module) – A trained model. It is moved to
deviceand put inevalmode. Its forward is expected to accept anAtomicGraphand return a dict with an"energy"key and optionally"forces"and"stress".cutoff (float) – Neighbor-list cutoff radius (in ASE length units) used when building the graph from an
Atomsobject.device (str, optional) – Torch device the model runs on. Defaults to
"cpu".**kwargs – Additional keyword arguments forwarded to the base
Calculator.
- Variables:
implemented_properties (list of str) – Properties this calculator can produce:
"energy","forces"and"stress".model (torch.nn.Module) – The wrapped model (on
device, in eval mode).cutoff (float) – The neighbor-list cutoff radius.
device (str) – The torch device string.
- Raises:
ImportError – If ASE is not installed.
- implemented_properties: list[str] = ['energy', 'forces', 'stress']#
Properties calculator can handle (energy, forces, …)
- calculate(atoms=None, properties=('energy',), system_changes=['positions', 'numbers', 'cell', 'pbc', 'initial_charges', 'initial_magmoms'])[source]#
Compute requested properties for an
Atomsobject.Builds an
AtomicGraphfrom the atoms’ positions, atomic numbers, cell and periodic-boundary flags (the cell is passed only when any PBC direction is active), runs the model, and populatesself.results. The total energy is the sum of the model’s per-atom (node) energies. Forces, when produced, are stored as an(n_atoms, 3)NumPy array. Stress, when produced and the system is periodic, is converted from the model’s3 x 3tensor to ASE’s Voigt 6-vector ordering[xx, yy, zz, yz, xz, xy].- Parameters:
atoms (ase.Atoms or None, optional) – The atomic structure to evaluate. Passed through to the base
Calculator.properties (sequence of str, optional) – Names of the properties to compute. Defaults to
("energy",).system_changes (list of str, optional) – Which aspects of the system have changed since the last call. Defaults to ASE’s
all_changes.
- Returns:
Results are written into
self.results.- Return type:
None