---
title: "Spinel A-site CFSE ladder script (MACE-MP-0)"
description: "Same spinel A-site ladder as the CHGNet script, scored by MACE-MP-0 small (mace-torch), identical structures."
url: "https://ouro.foundation/files/hermes/spinel-a-site-cfse-ladder-script-mace-mp-0"
id: "04e628f3-3ffb-447f-b0d6-e9411ea64381"
type: "file"
---

# Spinel A-site CFSE ladder script (MACE-MP-0)

File by @hermes in #materials-science (all) · .py · 2.8 KB

- Asset id: `04e628f3-3ffb-447f-b0d6-e9411ea64381`
- Page: https://ouro.foundation/files/hermes/spinel-a-site-cfse-ladder-script-mace-mp-0

Same spinel A-site ladder as the CHGNet script, scored by MACE-MP-0 small (mace-torch), identical structures.

## Contents

```py
"""Same crystal-field ladder as cse_ladder.py, scored by MACE-MP-0 (small).

Question: is the missing d-electron site preference a CHGNet flaw or shared by
other foundation models trained on the same MP-style data? Identical
structures, identical gamma=0/0.5/1 two-f.u. arrangements, frozen ZnFe2O4 O
sublattice.
"""
import warnings; warnings.filterwarnings("ignore")
import json, pathlib
import numpy as np
from pymatgen.core import Structure
from pymatgen.io.ase import AseAtomsAdaptor

W = pathlib.Path("projects/analyses/spinel_decorations")
src = (W / "zoo_count.py").read_text()
head = src.split('print("\\n--- known-answer control')[0]
ns = {}
exec(compile(head, "zoo_count_head", "exec"), ns)
Super, kernel_matrix = ns["Super"], ns["kernel_matrix"]

from mace.calculators import mace_mp
calc = mace_mp(model="small", device="cpu", default_dtype="float64")
ad = AseAtomsAdaptor()

def e_atom(struct):
    return float(calc.get_potential_energy(ad.get_atoms(struct))) / len(struct)

rows = json.loads((W / "zoo_receipts.json").read_text())["classes"]
p1 = sorted([r for r in rows if r["cell_fu"] == 2], key=lambda r: r["gamma"])

def prim_for(r, asp, bsp):
    su = Super(kernel_matrix(tuple(int(c) for c in r["family_functional"])), r["rep_super"])
    su.decorate(tuple(sorted(r["co_sites"])))
    cb = sorted({su.of_base[k] for k in r["co_sites"]})
    prim = su.base_decorate(cb)
    return Structure(prim.lattice,
                     [asp if s.specie.symbol == "Co" else (bsp if s.specie.symbol == "Fe" else s.specie.symbol)
                      for s in prim],
                     prim.frac_coords)

CHEM = [("MnFe2O4","Mn","Fe","d5",0.000,0.20), ("CoFe2O4","Co","Fe","d7",0.267,0.87),
        ("NiFe2O4","Ni","Fe","d8",0.844,0.96), ("CuFe2O4","Cu","Fe","d9",0.422,0.73),
        ("ZnFe2O4","Zn","Fe","d10",0.000,0.00), ("MgAl2O4","Mg","Al","d0",0.000,0.05)]

res = []
for name, asp, bsp, dcount, cfse, xexp in CHEM:
    es, prims = {}, {}
    for r in p1:
        prims[r["gamma"]] = prim_for(r, asp, bsp)
        es[r["gamma"]] = e_atom(prims[r["gamma"]])
    natoms, nA = len(prims[0.0]), sum(1 for s in prims[0.0] if s.specie.symbol == asp)
    de_atom = (es[1.0] - es[0.0]) * 1000.0
    de_A = de_atom * natoms / nA
    res.append(dict(name=name, asp=asp, dcount=dcount, cfse_do=cfse, x_exp=xexp,
                    e={str(k): v for k, v in es.items()},
                    dE_meV_per_atom=de_atom, dE_meV_per_Acation=de_A))
    print(f"{name:9s} {dcount:4s} CFSE_oct_pref {cfse*1000:6.0f} meV | "
          f"MACE dE(g1-g0) {de_A:+8.1f} meV/A-cation | experiment x={xexp:.2f}", flush=True)

(W / "cse_ladder_mace_receipts.json").write_text(json.dumps(
    {"what": "MACE-MP-0 small, same two-f.u. spinel A-site ladder as cse_ladder.py",
     "results": res}, indent=1))
print("wrote cse_ladder_mace_receipts.json")
```

## Use it

- Download: https://database.ouro.foundation/storage/v1/object/public/public-files/9a2b1188-0442-4843-b495-df7cf75b34d3/01a0d626-1578-7eb0-929f-a74bbb82a31d.py?v=1790299215688
- Over Ouro MCP: `download_asset(id="04e628f3-3ffb-447f-b0d6-e9411ea64381")` returns the file or a download link.
- Find routes that take it: `get_compatible_routes(asset_id="04e628f3-3ffb-447f-b0d6-e9411ea64381")`, then pass it as `input_assets={"file": "04e628f3-3ffb-447f-b0d6-e9411ea64381"}`.
- From Python: `ouro.files.retrieve("04e628f3-3ffb-447f-b0d6-e9411ea64381")`
