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.
- 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.
- 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, model name/path, device, dtype, dispersion setting,
element coverage, and license/provenance.
- Print formula, atom count, cell, PBC, and calculator class before inference.
- 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
Optimization Candidate Notes
- Prefer the documented pretrained or foundation-model calculator path
(
mace_mp or MACECalculator) before discussing training a new model.
- In examples, show the ASE bridge explicitly: read or build
Atoms, attach the
calculator, run optimization/MD/inference, then inspect energy, forces, and
stress or cell behavior when relevant.
- Record model name/path, model family, device, dtype, cutoff/default settings,
MACE version, ASE version, units, and whether the structure cell/PBC are
appropriate for the selected model.
1---2name: mace-33description: 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- Use ASE for the orchestration layer: reading structures, attaching the MACE21 calculator, optimizers, MD, trajectories, and file I/O.22- Use pymatgen for Materials Project queries, phase diagrams, and structure23 analysis before converting to ASE for MACE inference.24- Use DFT codes when the user needs first-principles reference data; MACE25 predicts a learned approximation to the training level of theory.26- Do not replace MACE with generic PyTorch/sklearn regression unless the user is27 explicitly developing a new MLIP model. MACE already encodes equivariance,28 neighbor cutoffs, training losses, and ASE calculator integration.2930## Canonical workflow3132For inference, pick the appropriate MACE calculator, attach it to an ASE33`Atoms`, and use standard ASE optimizers or MD.3435```python36from ase import units37from ase.io import read, write38from ase.md.langevin import Langevin39from ase.md.velocitydistribution import MaxwellBoltzmannDistribution40from ase.optimize import BFGS41from mace.calculators import mace_mp4243atoms = read("structure.cif")44calc = mace_mp(model="medium-mpa-0", device="cuda", default_dtype="float64")45atoms.calc = calc4647opt = BFGS(atoms, trajectory="mace_relax.traj", logfile="mace_relax.log")48opt.run(fmax=0.03)49print("energy_eV", atoms.get_potential_energy())50print("max_force_eV_per_A", abs(atoms.get_forces()).max())51write("relaxed.xyz", atoms)5253MaxwellBoltzmannDistribution(atoms, temperature_K=300)54dyn = Langevin(atoms, timestep=0.5 * units.fs, temperature_K=300, friction=0.001)55dyn.run(200)56```5758For local trained checkpoints:5960```python61from mace.calculators import MACECalculator6263atoms = read("input.xyz")64atoms.calc = MACECalculator(model_paths="MACE_model.model", device="cuda")65energy = atoms.get_potential_energy()66forces = atoms.get_forces()67```6869For deeper examples, read:7071- Foundation models:72 https://mace-docs.readthedocs.io/en/latest/guide/foundation_models.html73- ASE calculator:74 https://mace-docs.readthedocs.io/en/latest/guide/ase.html75- Training:76 https://mace-docs.readthedocs.io/en/latest/guide/training.html77- Troubleshooting:78 https://mace-docs.readthedocs.io/en/latest/guide/troubleshooting.html7980## Key conventions and gotchas8182- MACE calculators are ASE calculators. Attach them with `atoms.calc = calc`83 before asking ASE for energies, forces, stresses, descriptors, optimizations,84 or MD.85- Units follow ASE conventions: energies in eV, forces in eV/Angstrom, and86 distances in Angstrom. Training data should use eV and eV/Angstrom.87- Foundation-model defaults change. In MACE >=0.3.10, `mace_mp()` defaults to a88 newer MPA model; specify `model=...` when reproducibility matters.89- Choose the pretrained model for the domain: MACE-MP/MPA/OMAT/MATPES for90 materials, MACE-OFF for organic force fields, MACE-MDP for dipoles and91 polarizabilities only, not energies/forces.92- Check element coverage and license before using a foundation model. Some93 models have more restrictive licenses or limited element sets.94- `device="cuda"` needs a compatible PyTorch/CUDA environment. Fall back to95 `device="cpu"` only after acknowledging the speed cost.96- `default_dtype="float64"` is the conservative accuracy choice; `float32` is97 faster but should be validated for the user's system.98- Training expects energy/force keys in extended XYZ or explicit99 `--energy_key`/`--forces_key`. If the initial output reports zero energies or100 forces loaded, the data keys are wrong.101- E0 atomic reference energies matter. Use isolated atom energies from the same102 reference settings, recompute for fine-tuning, or use `--E0s=average` when103 appropriate; mismatched E0s are a common source of large errors.104105## Anti-patterns106107- Do not call a MACE model directly on raw coordinate arrays for normal108 workflows. Use ASE `Atoms` so species, cell, PBC, units, and calculator109 properties are handled correctly.110- Do not run MD with a foundation model before checking whether the model covers111 the elements, chemistry, pressure/temperature regime, charge state, and112 boundary conditions.113- Do not use MACE-MDP for energies or forces; it is for dipole moments and114 polarizabilities.115- Do not fine-tune from a foundation model while reusing stale E0s, wrong data116 keys, or mixed spin-polarization/reference settings.117- Do not trust a trained MLIP because training loss decreased. Evaluate on a118 held-out test set and inspect energy/force/stress errors by configuration119 type.120- Do not mix structures from pymatgen/RDKit/ASE without validating atom order,121 cell, PBC, units, and chemical state before MACE inference.122123## Diagnostic checks124125Before trusting outputs, the agent should:126127- Log MACE package version, model name/path, device, dtype, dispersion setting,128 element coverage, and license/provenance.129- Print formula, atom count, cell, PBC, and calculator class before inference.130- For relaxations, report final max force and save trajectory/log files.131- For MD, record timestep, thermostat/barostat, temperature, friction, ensemble,132 number of steps, and energy/temperature drift checks.133- For training, verify counts of loaded configurations, energies, forces, and134 stresses; inspect initial RMSE ranges; and save the full command/config.135- For fine-tuning, compare initial loss to expected ranges and confirm E0s and136 data keys match the new reference calculations.137138## Pointers to deeper material139140- Documentation: https://mace-docs.readthedocs.io/141- Foundation models: https://mace-docs.readthedocs.io/en/latest/guide/foundation_models.html142- Training guide: https://mace-docs.readthedocs.io/en/latest/guide/training.html143- Troubleshooting: https://mace-docs.readthedocs.io/en/latest/guide/troubleshooting.html144- Source repository: https://github.com/ACEsuit/mace145- Paper: Batatia et al. (2022), "MACE: Higher Order Equivariant Message Passing146 Neural Networks for Fast and Accurate Force Fields".147 https://arxiv.org/abs/2206.07697148149150## Optimization Candidate Notes151152- Prefer the documented pretrained or foundation-model calculator path153 (`mace_mp` or `MACECalculator`) before discussing training a new model.154- In examples, show the ASE bridge explicitly: read or build `Atoms`, attach the155 calculator, run optimization/MD/inference, then inspect energy, forces, and156 stress or cell behavior when relevant.157- Record model name/path, model family, device, dtype, cutoff/default settings,158 MACE version, ASE version, units, and whether the structure cell/PBC are159 appropriate for the selected model.