MACE
What this library is for
MACE is a machine-learning interatomic potential framework based on equivariant
message passing. It is used as an ASE calculator for energies, forces, stresses,
descriptors, geometry optimization, and molecular dynamics, and it can also
train or fine-tune MLIPs from reference energies and forces.
When to use this vs. alternatives
- Use MACE when the task needs a pretrained or trained MLIP for atomistic
energies, forces, stresses, MD, relaxation, descriptors, or active-learning
loops.
- For ordinary relaxation, MD, descriptor, or screening prompts, start with the
documented pretrained/foundation-model calculator path (
mace_mp or
MACECalculator) before discussing training a new model.
- Use ASE for the orchestration layer: reading structures, attaching the MACE
calculator, optimizers, MD, trajectories, and file I/O.
- Use pymatgen for Materials Project queries, phase diagrams, and structure
analysis before converting to ASE for MACE inference.
- Use DFT codes when the user needs first-principles reference data; MACE
predicts a learned approximation to the training level of theory.
- Do not replace MACE with generic PyTorch/sklearn regression unless the user is
explicitly developing a new MLIP model. MACE already encodes equivariance,
neighbor cutoffs, training losses, and ASE calculator integration.
Canonical workflow
For inference, pick the appropriate MACE calculator, attach it to an ASE
Atoms, and use standard ASE optimizers or MD.
from ase import units
from ase.io import read, write
from ase.md.langevin import Langevin
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
from ase.optimize import BFGS
from mace.calculators import mace_mp
atoms = read("structure.cif")
calc = mace_mp(model="medium-mpa-0", device="cuda", default_dtype="float64")
atoms.calc = calc
opt = BFGS(atoms, trajectory="mace_relax.traj", logfile="mace_relax.log")
opt.run(fmax=0.03)
print("energy_eV", atoms.get_potential_energy())
print("max_force_eV_per_A", abs(atoms.get_forces()).max())
write("relaxed.xyz", atoms)
MaxwellBoltzmannDistribution(atoms, temperature_K=300)
dyn = Langevin(atoms, timestep=0.5 * units.fs, temperature_K=300, friction=0.001)
dyn.run(200)
For local trained checkpoints:
from mace.calculators import MACECalculator
atoms = read("input.xyz")
atoms.calc = MACECalculator(model_paths="MACE_model.model", device="cuda")
energy = atoms.get_potential_energy()
forces = atoms.get_forces()
For deeper examples, read:
Key conventions and gotchas
- MACE calculators are ASE calculators. Attach them with
atoms.calc = calc
before asking ASE for energies, forces, stresses, descriptors, optimizations,
or MD.
- Make the ASE bridge explicit in examples: read or build
Atoms, attach the
calculator, run optimization/MD/inference, then inspect energy, forces, and
stress or cell behavior when relevant.
- Units follow ASE conventions: energies in eV, forces in eV/Angstrom, and
distances in Angstrom. Training data should use eV and eV/Angstrom.
- Foundation-model defaults change. In MACE >=0.3.10,
mace_mp() defaults to a
newer MPA model; specify model=... when reproducibility matters.
- Choose the pretrained model for the domain: MACE-MP/MPA/OMAT/MATPES for
materials, MACE-OFF for organic force fields, MACE-MDP for dipoles and
polarizabilities only, not energies/forces.
- Check element coverage and license before using a foundation model. Some
models have more restrictive licenses or limited element sets.
device="cuda" needs a compatible PyTorch/CUDA environment. Fall back to
device="cpu" only after acknowledging the speed cost.
default_dtype="float64" is the conservative accuracy choice; float32 is
faster but should be validated for the user's system.
- Training expects energy/force keys in extended XYZ or explicit
--energy_key/--forces_key. If the initial output reports zero energies or
forces loaded, the data keys are wrong.
- E0 atomic reference energies matter. Use isolated atom energies from the same
reference settings, recompute for fine-tuning, or use
--E0s=average when
appropriate; mismatched E0s are a common source of large errors.
Anti-patterns
- Do not call a MACE model directly on raw coordinate arrays for normal
workflows. Use ASE
Atoms so species, cell, PBC, units, and calculator
properties are handled correctly.
- Do not run MD with a foundation model before checking whether the model covers
the elements, chemistry, pressure/temperature regime, charge state, and
boundary conditions.
- Do not use MACE-MDP for energies or forces; it is for dipole moments and
polarizabilities.
- Do not fine-tune from a foundation model while reusing stale E0s, wrong data
keys, or mixed spin-polarization/reference settings.
- Do not trust a trained MLIP because training loss decreased. Evaluate on a
held-out test set and inspect energy/force/stress errors by configuration
type.
- Do not mix structures from pymatgen/RDKit/ASE without validating atom order,
cell, PBC, units, and chemical state before MACE inference.
Diagnostic checks
Before trusting outputs, the agent should:
- Log MACE package version, ASE version, model name/path, model family, device,
dtype, cutoff/default settings, dispersion setting, element coverage, and
license/provenance.
- Print formula, atom count, cell, PBC, and calculator class before inference.
- Confirm the structure cell and PBC are appropriate for the selected model.
- For relaxations, report final max force and save trajectory/log files.
- For MD, record timestep, thermostat/barostat, temperature, friction, ensemble,
number of steps, and energy/temperature drift checks.
- For training, verify counts of loaded configurations, energies, forces, and
stresses; inspect initial RMSE ranges; and save the full command/config.
- For fine-tuning, compare initial loss to expected ranges and confirm E0s and
data keys match the new reference calculations.
Pointers to deeper material
1---2name: mace3description: Use when the user is working with MACE machine-learning interatomic potentials (MLIPs), equivariant force fields, MACE-MP/MPA/OMAT/MATPES/OFF foundation models, ASE calculators from mace.calculators, MLIP geometry optimization, molecular dynamics, descriptors, fine-tuning, or training from extended XYZ energies and forces. Prefer MACE over generic neural-network or sklearn code when the task is atomic energy/force prediction with equivariant ML potentials.4---56# MACE78## What this library is for910MACE is a machine-learning interatomic potential framework based on equivariant11message passing. It is used as an ASE calculator for energies, forces, stresses,12descriptors, geometry optimization, and molecular dynamics, and it can also13train or fine-tune MLIPs from reference energies and forces.1415## When to use this vs. alternatives1617- Use MACE when the task needs a pretrained or trained MLIP for atomistic18 energies, forces, stresses, MD, relaxation, descriptors, or active-learning19 loops.20- For ordinary relaxation, MD, descriptor, or screening prompts, start with the21 documented pretrained/foundation-model calculator path (`mace_mp` or22 `MACECalculator`) before discussing training a new model.23- Use ASE for the orchestration layer: reading structures, attaching the MACE24 calculator, optimizers, MD, trajectories, and file I/O.25- Use pymatgen for Materials Project queries, phase diagrams, and structure26 analysis before converting to ASE for MACE inference.27- Use DFT codes when the user needs first-principles reference data; MACE28 predicts a learned approximation to the training level of theory.29- Do not replace MACE with generic PyTorch/sklearn regression unless the user is30 explicitly developing a new MLIP model. MACE already encodes equivariance,31 neighbor cutoffs, training losses, and ASE calculator integration.3233## Canonical workflow3435For inference, pick the appropriate MACE calculator, attach it to an ASE36`Atoms`, and use standard ASE optimizers or MD.3738```python39from ase import units40from ase.io import read, write41from ase.md.langevin import Langevin42from ase.md.velocitydistribution import MaxwellBoltzmannDistribution43from ase.optimize import BFGS44from mace.calculators import mace_mp4546atoms = read("structure.cif")47calc = mace_mp(model="medium-mpa-0", device="cuda", default_dtype="float64")48atoms.calc = calc4950opt = BFGS(atoms, trajectory="mace_relax.traj", logfile="mace_relax.log")51opt.run(fmax=0.03)52print("energy_eV", atoms.get_potential_energy())53print("max_force_eV_per_A", abs(atoms.get_forces()).max())54write("relaxed.xyz", atoms)5556MaxwellBoltzmannDistribution(atoms, temperature_K=300)57dyn = Langevin(atoms, timestep=0.5 * units.fs, temperature_K=300, friction=0.001)58dyn.run(200)59```6061For local trained checkpoints:6263```python64from mace.calculators import MACECalculator6566atoms = read("input.xyz")67atoms.calc = MACECalculator(model_paths="MACE_model.model", device="cuda")68energy = atoms.get_potential_energy()69forces = atoms.get_forces()70```7172For deeper examples, read:7374- Foundation models:75 https://mace-docs.readthedocs.io/en/latest/guide/foundation_models.html76- ASE calculator:77 https://mace-docs.readthedocs.io/en/latest/guide/ase.html78- Training:79 https://mace-docs.readthedocs.io/en/latest/guide/training.html80- Troubleshooting:81 https://mace-docs.readthedocs.io/en/latest/guide/troubleshooting.html8283## Key conventions and gotchas8485- MACE calculators are ASE calculators. Attach them with `atoms.calc = calc`86 before asking ASE for energies, forces, stresses, descriptors, optimizations,87 or MD.88- Make the ASE bridge explicit in examples: read or build `Atoms`, attach the89 calculator, run optimization/MD/inference, then inspect energy, forces, and90 stress or cell behavior when relevant.91- Units follow ASE conventions: energies in eV, forces in eV/Angstrom, and92 distances in Angstrom. Training data should use eV and eV/Angstrom.93- Foundation-model defaults change. In MACE >=0.3.10, `mace_mp()` defaults to a94 newer MPA model; specify `model=...` when reproducibility matters.95- Choose the pretrained model for the domain: MACE-MP/MPA/OMAT/MATPES for96 materials, MACE-OFF for organic force fields, MACE-MDP for dipoles and97 polarizabilities only, not energies/forces.98- Check element coverage and license before using a foundation model. Some99 models have more restrictive licenses or limited element sets.100- `device="cuda"` needs a compatible PyTorch/CUDA environment. Fall back to101 `device="cpu"` only after acknowledging the speed cost.102- `default_dtype="float64"` is the conservative accuracy choice; `float32` is103 faster but should be validated for the user's system.104- Training expects energy/force keys in extended XYZ or explicit105 `--energy_key`/`--forces_key`. If the initial output reports zero energies or106 forces loaded, the data keys are wrong.107- E0 atomic reference energies matter. Use isolated atom energies from the same108 reference settings, recompute for fine-tuning, or use `--E0s=average` when109 appropriate; mismatched E0s are a common source of large errors.110111## Anti-patterns112113- Do not call a MACE model directly on raw coordinate arrays for normal114 workflows. Use ASE `Atoms` so species, cell, PBC, units, and calculator115 properties are handled correctly.116- Do not run MD with a foundation model before checking whether the model covers117 the elements, chemistry, pressure/temperature regime, charge state, and118 boundary conditions.119- Do not use MACE-MDP for energies or forces; it is for dipole moments and120 polarizabilities.121- Do not fine-tune from a foundation model while reusing stale E0s, wrong data122 keys, or mixed spin-polarization/reference settings.123- Do not trust a trained MLIP because training loss decreased. Evaluate on a124 held-out test set and inspect energy/force/stress errors by configuration125 type.126- Do not mix structures from pymatgen/RDKit/ASE without validating atom order,127 cell, PBC, units, and chemical state before MACE inference.128129## Diagnostic checks130131Before trusting outputs, the agent should:132133- Log MACE package version, ASE version, model name/path, model family, device,134 dtype, cutoff/default settings, dispersion setting, element coverage, and135 license/provenance.136- Print formula, atom count, cell, PBC, and calculator class before inference.137- Confirm the structure cell and PBC are appropriate for the selected model.138- For relaxations, report final max force and save trajectory/log files.139- For MD, record timestep, thermostat/barostat, temperature, friction, ensemble,140 number of steps, and energy/temperature drift checks.141- For training, verify counts of loaded configurations, energies, forces, and142 stresses; inspect initial RMSE ranges; and save the full command/config.143- For fine-tuning, compare initial loss to expected ranges and confirm E0s and144 data keys match the new reference calculations.145146## Pointers to deeper material147148- Documentation: https://mace-docs.readthedocs.io/149- Foundation models: https://mace-docs.readthedocs.io/en/latest/guide/foundation_models.html150- Training guide: https://mace-docs.readthedocs.io/en/latest/guide/training.html151- Troubleshooting: https://mace-docs.readthedocs.io/en/latest/guide/troubleshooting.html152- Source repository: https://github.com/ACEsuit/mace153- Paper: Batatia et al. (2022), "MACE: Higher Order Equivariant Message Passing154 Neural Networks for Fast and Accurate Force Fields".155 https://arxiv.org/abs/2206.07697