torch-sim¶
Official website |
How is metatomic supported? |
|---|---|
Via the |
How to install the code¶
Install the integration package from PyPI:
pip install metatomic-torchsim
For the full TorchSim documentation, see https://torchsim.github.io/torch-sim/.
Supported model outputs¶
Only the energy output is supported. Forces and stresses are derived via autograd.
How to use the code¶
import ase.build
import torch_sim as ts
from metatomic_torchsim import MetatomicModel
model = MetatomicModel("model.pt", device="cpu")
atoms = ase.build.bulk("Si", "diamond", a=5.43, cubic=True)
sim_state = ts.initialize_state(atoms, device=model.device, dtype=model.dtype)
results = model(sim_state)
print(results["energy"]) # shape [1]
print(results["forces"]) # shape [n_atoms, 3]
print(results["stress"]) # shape [1, 3, 3]
API documentation¶
- class metatomic_torchsim.MetatomicModel(model: str | bytes | PurePath | AtomisticModel | RecursiveScriptModule, *, extensions_directory: str | bytes | PurePath | None = None, device: device | str | None = None, check_consistency: bool = False, compute_forces: bool = True, compute_stress: bool = True)[source]¶
Bases:
ModelInterfaceTorchSim wrapper for metatomic atomistic models.
Wraps a metatomic model to compute energies, forces, and stresses within the TorchSim framework. Handles the translation between TorchSim’s batched
SimStateand metatomic’s list-of-Systemconvention, and uses autograd for force/stress derivatives.Neighbor lists are computed with vesin, or with nvalchemiops on CUDA when available and the model requests full neighbor lists.
- Parameters:
model (str | bytes | PurePath | AtomisticModel | ForwardRef('torch.jit.RecursiveScriptModule')) – Model to use. Accepts a file path to a
.ptsaved model, a PythonAtomisticModelinstance, or a TorchScripttorch.jit.RecursiveScriptModule.extensions_directory (str | bytes | PurePath | None) – Directory containing compiled TorchScript extensions required by the model, if any.
device (device | str | None) – Torch device for evaluation. When
None, the best device is selected from the model’ssupported_devices.check_consistency (bool) – Run consistency checks during model evaluation. Useful for debugging but hurts performance.
compute_forces (bool) – Compute atomic forces via autograd.
compute_stress (bool) – Compute stress tensors via the strain trick.