Header Ads Widget

AI & Machine Learning for Materials Sciences

Last Posts

10/recent/ticker-posts

Post 21: A Research Roadmap — Fine-Tuning MACE for Transition Metal Compounds

A five-phase plan for bringing equivariant neural network potentials into your own MₓCᵧ research: read the right papers, run pretrained models, generate targeted DFT data, fine-tune, and validate — with installation instructions and concrete code for every major framework.

📖
Phase 1

Read the foundational papers

Phase 2

Run pretrained models zero-shot

🔬
Phase 3

Generate your own DFT data

🎯
Phase 4-5

Fine-tune MACE, then validate

This closing post of Module 6 turns everything from Posts 16–20 into an actionable plan. The central decision a researcher must make is not whether to use equivariant neural network potentials, but how far along this roadmap you actually need to go before the model is accurate enough for your specific transition metal compounds — and the honest answer, for many systems, is "not very far at all."

🎯
The core principle of this roadmap

Start at the cheapest, fastest phase (zero-shot foundation model) and only advance to the next phase if validation shows it's necessary. Fine-tuning is powerful but costs DFT calculation time, GPU time, and researcher time — never skip straight to it without first checking whether MACE-MP-0 is already good enough for your accuracy requirements.

Phase 1 — Read the Foundational Papers

Posts 16–18 already did the heavy lifting here. Read in this exact order, and don't skip Behler-Parrinello even though it's the oldest — it establishes vocabulary every later paper assumes you know.

OrderPaperLinkTime investment
1Behler & Parrinello (2007)PRL 98, 146401~1 hour
2Schütt et al. — SchNet (2017)arXiv:1712.06113~1.5 hours
3Batzner et al. — NequIP (2022)Nat. Commun. 13, 2453~2 hours
4Batatia et al. — MACE (2022)arXiv:2206.07697~2 hours

Phase 2 — Run Pretrained Models Zero-Shot

Before generating a single new DFT calculation, run MACE-MP-0 on the transition metal chalcogenides already in your dataset (Posts 1–8 of the research series) and compare directly against your own DFT-PBE/DFT+U results.

# pip install mace-torch ase
from mace.calculators import mace_mp
from ase.io import read

calc = mace_mp(model="medium", default_dtype="float64")

# Loop over your own DFT-relaxed CIF files (from Wien2k/VASP exports)
for cif_path in my_mxcy_structures:
    atoms = read(cif_path)
    atoms.calc = calc
    e_mace = atoms.get_potential_energy() / len(atoms) # eV/atom
    print(f"{cif_path.stem:12s} MACE: {e_mace:.4f} eV/atom")
    # Compare against the DFT energy you already have on file
🧪
Decision point — proceed or stop here?

If MACE-MP-0 reproduces your DFT relaxed structures, relative energies between polymorphs, and rough force magnitudes within an acceptable tolerance for your application (e.g. structure screening, rough phonon estimates), stop here — fine-tuning is unnecessary overhead. Move to Phase 4/5 only if zero-shot accuracy is insufficient for what you specifically need (e.g. precise magnetic energy differences between AFM/FM orderings, which foundation models are known to handle less reliably than simpler structural energetics).

Phase 3 — Generate Your Own DFT Data (If Needed)

If Phase 2 reveals systematic errors specific to your chemistry — common for strongly correlated MₓCᵧ compounds where DFT+U corrections matter — the next step is generating a small, targeted set of new DFT calculations rather than thousands of random structures.

  • Identify the failure mode first. Is MACE wrong about absolute energies, relative polymorph stability, or magnetic ordering specifically? This determines what new data is actually needed.
  • Use active learning, not random sampling (Post 16, Rung 6). Run MD with an ensemble of MACE models; flag configurations where ensemble disagreement is highest — those are the structures most worth computing with DFT.
  • Match your existing DFT settings. Use the same exchange-correlation functional, U values, and k-point density as your existing MₓCᵧ dataset (Post 2 of the research series) for consistency.
  • Aim for hundreds, not tens of thousands. NequIP's data-efficiency result (Post 18) means equivariant fine-tuning typically needs far less new data than training from scratch.

Phase 4 — Fine-Tune MACE on Your Data

# Fine-tuning starts from MACE-MP-0 weights rather than random initialisation —
# this is what makes it fast and data-efficient compared to training from scratch.

# 1. Prepare your data in extended XYZ format with energies + forces
# (ASE's write() with format='extxyz' handles this directly)

# 2. Fine-tune via the mace_run_train CLI
mace_run_train \
    --name="mxcy_finetuned" \
    --foundation_model="medium" \  # start from MACE-MP-0 weights
    --train_file="mxcy_train.xyz" \
    --valid_fraction=0.10 \
    --energy_weight=1.0 --forces_weight=100.0 \  # forces weighted heavily
    --lr=0.001 --max_num_epochs=200 \
    --device=cuda
⚠️
Force weighting reflects the F = −∂E/∂r relation

Notice forces are weighted 100× more heavily than energy in the loss function above. This is standard practice across SchNet, NequIP, and MACE training — because forces are local, per-atom quantities providing far more learning signal per structure than a single scalar energy value, and because accurate forces (not just energies) are what makes molecular dynamics trajectories physically trustworthy.

Installing the major frameworks

FrameworkInstall commandBest for
MACEpip install mace-torchRecommended default — foundation models + fine-tuning
NequIPpip install nequipTraining fully custom equivariant models from scratch
SchNetPackpip install schnetpackInvariant baseline, architecture teaching/comparison
n2p2 / aenetCompile from source (C++)Classic Behler-Parrinello-style potentials, large-scale MD

Phase 5 — Validate Against DFT and Materials Project

Validation closes the loop back to Post 20's methodology — the same five checks (equation of state, lattice parameters, phonons, defect energies, Materials Project cross-check) apply equally to a fine-tuned model, with one addition specific to magnetic transition metal compounds.

# Validate fine-tuned model against held-out DFT structures
from mace.calculators import MACECalculator

calc_ft = MACECalculator(model_paths="mxcy_finetuned.model", device="cuda")

errors_E, errors_F = [], []
for atoms_dft in held_out_test_set:
    atoms_pred = atoms_dft.copy(); atoms_pred.calc = calc_ft
    e_err = abs(atoms_pred.get_potential_energy()/len(atoms_dft)
            - atoms_dft.get_potential_energy()/len(atoms_dft))
    f_err = np.abs(atoms_pred.get_forces() - atoms_dft.get_forces()).mean()
    errors_E.append(e_err); errors_F.append(f_err)

print(f"MAE energy: {np.mean(errors_E)*1000:.1f} meV/atom")
print(f"MAE forces: {np.mean(errors_F):.3f} eV/Å")
# Target: < 5-10 meV/atom energy, < 0.05 eV/Å forces — "chemical accuracy"
🔬
Validation step specific to magnetic TM compounds

Beyond the standard checks, explicitly compare the energy difference between AFM and FM orderings of the same structure predicted by the fine-tuned model against your DFT+U values (Post 6 of the research series). This energy difference — not just the total energy of either state alone — is what determines whether the potential correctly predicts magnetic ground states, and is historically one of the harder quantities for any neural network potential to get right.

Summary — The Complete Roadmap

Five-phase decision path

Phase 1: Read the four foundational papers (Post 16-18)
Phase 2: Run MACE-MP-0 zero-shot on existing MₓCᵧ structures
↓ Accurate enough?
YES → Stop here. Use zero-shot MACE-MP-0 for your application.
↓ NO — specific failure mode identified
Phase 3: Generate targeted DFT data via active learning
Phase 4: Fine-tune MACE starting from foundation-model weights
Phase 5: Validate — energy/force MAE, AFM/FM energy difference, Materials Project cross-check
🗺️
App 21 — Research Roadmap Planner
Answer a few questions about your system and accuracy needs, and get a personalised recommendation for which phase to start at and which framework to install.
Open App →

Quick Check

1. According to this roadmap, when should a researcher move past Phase 2 (zero-shot MACE-MP-0) into fine-tuning?

  • A. Always — fine-tuning should be the default starting point for any project
  • B. Only after zero-shot validation reveals a specific, identified failure mode (e.g. inaccurate magnetic ordering energies) that matters for the intended application — not as a default first step
  • C. Never — fine-tuning is never worth the computational cost
  • D. Only if the researcher has access to a supercomputer

2. Why does fine-tuning start from MACE-MP-0's pretrained weights rather than random initialisation?

  • A. Random initialisation is not supported by the MACE training code
  • B. Starting from foundation-model weights makes fine-tuning faster and far more data-efficient, since the model has already learned general chemical bonding patterns and only needs to adapt to the specific system rather than learn everything from scratch
  • C. Pretrained weights are required for the loss function to converge at all
  • D. It has no effect on training speed or data requirements

3. Why is the AFM-vs-FM energy difference singled out as a specific validation check for transition metal compounds, beyond standard energy/force MAE?

  • A. AFM and FM structures cannot be represented in ASE
  • B. Correctly predicting which magnetic ordering is the ground state requires the small energy difference between orderings to be accurate, not just each total energy individually — a quantity that foundation models trained mostly on non-magnetic relaxation data may not capture reliably
  • C. Magnetic compounds always have zero force on every atom
  • D. This check is only relevant for ionic compounds like NaCl
Research Roadmap Fine-Tuning MACE Active Learning Transition Metal Compounds DFT+U Magnetic Ordering Module 6 Complete