MatterSim

1.2.2 · active · verified Thu Apr 16

MatterSim is a deep learning atomistic model developed by Microsoft, designed for simulating materials across various elements, temperatures, and pressures. It provides a flexible framework for energy, force, and stress calculations, and integrates with the Atomic Simulation Environment (ASE). The library is actively maintained with frequent patch releases addressing compatibility and bug fixes, typically on major versions like 1.x.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a pre-trained MatterSim model, initialize a calculator, attach it to an ASE Atoms object, and perform a basic energy minimization. It relies on `torch.hub.load` for convenient model retrieval.

import torch
from ase import Atoms
from ase.optimize import LBFGS
from mattersim.models import MatterSimModel
from mattersim.calc import MatterSimCalculator

# 1. Load a pre-trained MatterSim model
# Using torch.hub.load handles model downloading automatically
model = torch.hub.load("microsoft/mattersim", "mattersim_model_v1_0")

# 2. Initialize MatterSimCalculator
# Use 'cuda' if a GPU is available, otherwise 'cpu'
calculator = MatterSimCalculator(model=model, device="cpu")

# 3. Create an ASE Atoms object and set the calculator
atoms = Atoms("H2O", positions=[[0, 0, 0], [0, 1, 0], [0.5, -0.5, 0]], cell=[10,10,10], pbc=False)
atoms.set_calculator(calculator)

# 4. Perform an energy minimization using an ASE optimizer
print(f"Initial energy: {atoms.get_potential_energy():.4f} eV")

optimizer = LBFGS(atoms)
optimizer.run(fmax=0.01) # Relax until forces are below 0.01 eV/Å

print(f"Final energy: {atoms.get_potential_energy():.4f} eV")
print(f"Relaxed positions:\n{atoms.get_positions()}")

view raw JSON →