Skip to main content

TorchSim

CI codecov This project supports Python 3.12+ PyPI Zenodo

TorchSim is a next-generation open-source atomistic simulation engine for the MLIP era. By rewriting the core primitives of atomistic simulation in Pytorch, it allows orders of magnitude acceleration of popular machine learning potentials.

  • Automatic batching and GPU memory management allowing significant simulation speedup
  • Support for MACE, Fairchem, SevenNet, ORB, MatterSim, metatomic, and Nequix MLIP models
  • Support for classical lennard jones, morse, and soft-sphere potentials
  • Molecular dynamics integration schemes like NVE, NVT Langevin, and NPT Langevin
  • Relaxation of atomic positions and cell with gradient descent and FIRE
  • Swap monte carlo and hybrid swap monte carlo algorithm
  • An extensible binary trajectory writing format with support for arbitrary properties
  • A simple and intuitive high-level API for new users
  • Integration with ASE, Pymatgen, and Phonopy
  • and more: differentiable simulation, elastic properties, custom workflows...

Quick Start

Here is a quick demonstration of many of the core features of TorchSim: native support for GPUs, MLIP models, ASE integration, simple API, autobatching, and trajectory reporting, all in under 40 lines of code.

Running batched MD

import torch
import torch_sim as ts

# run natively on gpus
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# easily load the model from mace-mp
from mace.calculators.foundations_models import mace_mp
from torch_sim.models.mace import MaceModel
mace = mace_mp(model="small", return_raw_model=True)
mace_model = MaceModel(model=mace, device=device)

from ase.build import bulk
cu_atoms = bulk("Cu", "fcc", a=3.58, cubic=True).repeat((2, 2, 2))
many_cu_atoms = [cu_atoms] * 50
trajectory_files = [f"Cu_traj_{i}.h5md" for i in range(len(many_cu_atoms))]

# run them all simultaneously with batching
final_state = ts.integrate(
    system=many_cu_atoms,
    model=mace_model,
    n_steps=50,
    timestep=0.002,
    temperature=1000,
    integrator=ts.Integrator.nvt_langevin,
    trajectory_reporter=dict(filenames=trajectory_files, state_frequency=10),
)
final_atoms_list = final_state.to_atoms()

# extract the final energy from the trajectory file
final_energies = []
for filename in trajectory_files:
    with ts.TorchSimTrajectory(filename) as traj:
        final_energies.append(traj.get_array("potential_energy")[-1])

print(final_energies)

Running batched relaxation

To then relax those structures with FIRE is just a few more lines.

# relax all of the high temperature states
relaxed_state = ts.optimize(
    system=final_state,
    model=mace_model,
    optimizer=ts.Optimizer.fire,
    autobatcher=True,
    init_kwargs=dict(cell_filter=ts.CellFilter.frechet),
)

print(relaxed_state.energy)

Speedup

TorchSim achieves up to 100x speedup compared to ASE with popular MLIPs.

Speedup comparison

This figure compares the time per atom of ASE and torch_sim. Time per atom is defined as the number of atoms / total time. While ASE can only run a single system of n_atoms (on the $x$ axis), torch_sim can run as many systems as will fit in memory. On an H100 80 GB card, the max atoms that could fit in memory was ~8,000 for EGIP, ~10,000 for MACE-MPA-0, ~22,000 for Mattersim V1 1M, ~2,500 for SevenNet, and ~9000 for PET-MAD. This metric describes model performance by capturing speed and memory usage simultaneously.

Installation

PyPI Installation

pip install torch-sim-atomistic

Installing from source

git clone https://github.com/TorchSim/torch-sim
cd torch-sim
pip install .

Examples

To understand how TorchSim works, start with the comprehensive tutorials in the documentation.

Core Modules

TorchSim's package structure is summarized in the API reference documentation and drawn as a treemap below.

TorchSim package treemap

Contributing

If you are interested in contributing, please join our slack and check out the contributing.md.

License

TorchSim is released under an MIT license.

Citation

If you use TorchSim in your research, please cite our publication.

@article{cohen2025torchsim,
  title={TorchSim: An efficient atomistic simulation engine in PyTorch},
  author={Cohen, Orion and Riebesell, Janosh and Goodall, Rhys and Kolluru, Adeesh and Falletta, Stefano and Krause, Joseph and Colindres, Jorge and Ceder, Gerbrand and Gangan, Abhijeet S},
  journal={AI for Science},
  volume={1},
  number={2},
  pages={025003},
  year={2025},
  publisher={IOP Publishing},
  doi={10.1088/3050-287X/ae1799}
}

Due Credit

We aim to recognize all duecredit for the decades of work that TorchSim builds on top of, an automated list of references can be obtained for the package by running DUECREDIT_ENABLE=yes uv run --with-editable . --extra docs --extra test python -m duecredit <(printf 'import pytest\nraise SystemExit(pytest.main(["-q"]))\n'). This list is incomplete and we welcome PRs to help improve our citation coverage.

To collect citations for a specific tutorial run, for example autobatching, use:

DUECREDIT_ENABLE=yes uv run --with-editable . --extra docs --extra test python -m duecredit examples/tutorials/autobatching_tutorial.py

Release files for torch-sim-atomistic 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torch-sim-atomistic 0.6.2
File Size Uploaded
torch_sim_atomistic-0.6.2.tar.gz 219.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torch-sim-atomistic 0.6.2
File Interpreter ABI Platform
torch_sim_atomistic-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 471.9 kB

Release files / torch_sim_atomistic-0.6.2.tar.gz

Download URL torch_sim_atomistic-0.6.2.tar.gz
Size 219.5 kB
Tags Source
SHA-256 checksum
How to use checksums
575f58f5c02beab2ed1d1f3490fcf0963c0224227251cc48cf94f0408124cd65
BLAKE2b-256 checksum
How to use checksums
b8aab1ad6dc1bfcd4ba96960abf79c31c557096039a7671ace242c39e746a99f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / torch_sim_atomistic-0.6.2-py3-none-any.whl

Download URL torch_sim_atomistic-0.6.2-py3-none-any.whl
Size 252.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
feeb1c70a536e29d5660d185da797051a7952bd917f27251075e3966f66c0235
BLAKE2b-256 checksum
How to use checksums
8e3ef379b91cd0af60a5c7961eb5baf804642e04872bcf285c5d0677179dca90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page