How to run this route from Python with the Ouro SDK.
API access requires an API key. Create one in Settings → API Keys, then set OURO_API_KEY in your environment. Install the SDK with pip install ouro-py.
POST /dft/magnetic/maeParameters and request body schema for this route.
perturbationforce_theoremtotal_energyHow the anisotropy is computed. perturbation (default) and force_theorem use the same two DFT runs on the collinear density: perturbation expands the spin–orbit band energy to second order, force_theorem diagonalises the full spin–orbit Hamiltonian at every k-point and direction instead (no expansion, a few times slower). total_energy runs a self-consistent spin–orbit SCF for each direction, each on its own worker, and compares their total energies: no fixed density and no force theorem, the reference the other two approximate. It costs about one full SCF per direction on the kspacing mesh (an hour or more each for a 26-atom Fe cell) and does not take hubbard_u. Run force_theorem first when a result disagrees with experiment, and total_energy when that still does.
SCF convergence threshold on the charge-density residual (ABACUS scf_thr; not an energy). The default is ABACUS's own LCAO default and what forces and stress need: at 1e-6 a relaxation already ends at a different volume. Loosen to 1e-4 only for quick screening of energies. Force and stress checks (relax, MAE's relaxed-geometry check) always run at 1e-7 or tighter.
Range: 0.05 to 1
K-point spacing in 1/Å. The default is finer than the other routes' 0.3. This is the mesh of the self-consistent run; the spin–orbit energy is summed on sum_kspacing.
Turn on DFT+U with an effective U in eV per element, e.g. {"Ni": 6.2}. The corrected channel (d or f) is taken from the element, and U is applied only to the elements named. Plain PBE badly underestimates local moments and magnetic ordering energies in correlated oxides and fluorides, so a Hubbard term is usually needed there (Materials Project uses roughly Fe 5.3, Co 3.32, Ni 6.2, Mn 3.9, Cr 3.7, V 3.25, Cu 4.0). Setting this also softens the default mixing_beta to 0.2 and allows more SCF iterations, which correlated oxides need; an explicit mixing_beta still wins. Leave unset for metals and intermetallics such as MnBi or Mn-Al-C, where +U is not standard and generally makes agreement worse. The scheme is Dudarev, so this is U minus Hund J, not bare U.
SZDZPTZDPLCAO basis size: SZ (fastest), DZP (balanced), TZDP (most accurate)
001100010110111Magnetization directions to test, named in the crystal's frame: 001 is the unique axis of a tetragonal, hexagonal or trigonal crystal and 100 and 010 lie in the plane normal to it. A cell whose own axes already are the symmetry axes is read as written. Any other cell, such as a primitive body-centered one, is read in the frame of its conventional cell (c along z, a along x). Monoclinic and triclinic cells keep their own Cartesian axes. The response's direction_frame gives the frame used and each direction as a Cartesian vector.
Range: to 1
Charge mixing step (0–1). Left unset, it is 0.2 for structures with magnetic elements (Fe, Co, Ni, Mn, Cr, rare earths) and 0.4 otherwise. An SCF that does not converge is continued once from its own density at half this value before the run fails; if it still fails, try a quarter (0.05 for a magnet). Frustrated Mn compounds whose moment keeps changing between iterations need a different initial_magmoms seed rather than smaller mixing.
Range: 0.03 to 1
K-point spacing in 1/Å for the sum of the spin–orbit energy over the Brillouin zone, which sets the anisotropy and converges far more slowly than the self-consistent run. It reuses that run's Hamiltonian, so a finer value costs no extra DFT. Never coarser than kspacing. Lower it to 0.08 to check a result that matters, above all with W or Ta. Not used by method total_energy.
PBEPBEsolLDASCANXC functional
If false (default), reject CIFs whose DFT max force or stress exceeds the relax thresholds so MAE is for a DFT energy minimum. Run /dft/structure/relax first, or set true to evaluate the uploaded geometry as-is. The gate reads forces on this route's kspacing mesh (0.2 by default), finer than the relax route's (0.3), so a cell that route converged can still read above the force threshold here; set true for a cell it relaxed.
Hold the cell's spin moment N↑ − N↓ at this value, in μB per cell (the cell the response's n_atoms and total_magnetic_moment_uB refer to), instead of letting the calculation choose it. For Fe-rich weak ferromagnets PBE gives too large a moment and the anisotropy with it can have the wrong sign: YFe11Ti reads −0.22 MJ/m³ at its free 46.1 μB per 26-atom cell and +2.02 at the measured spin moment, 38.7, against +2.07 measured. Run once without it, compare total_magnetic_moment_uB with a measured or all-electron moment, and rerun at that moment if it is more than a few percent high. The response's fixed_moment gives the moment held, the uniform field that holds it, and the energy it costs. Each moment is its own self-consistent run. Works with method perturbation and force_theorem; not with total_energy or hubbard_u.
Signed starting moments in µB, one per atom, in the order the CIF is read: sites grouped by element, elements sorted by electronegativity (pymatgen's sorted order), which is the file's own order only if the file is already written that way. The response's magnetic_sublattice lists the seeds as applied, with the element of each, so check them there. Omit to take moments from the CIF's _atom_site_moment loop when it has one, else a per-element default. Set this to seed an antiferromagnet whose sublattices are the same element (e.g. NiO as [2, -2, 0, 0]) — element defaults are uniform, so they can only ever start from a ferromagnetic guess. Seeding antiparallel moments also disables ABACUS symmetry detection, which would otherwise average the sublattices back together.
Range: to 0.5
Width in eV of the Gaussian occupations in the spin–orbit sum. 0.1 is converged in k-points by sum_kspacing 0.1 and shifts a large anisotropy by a few percent, but it can erase or reverse a small one that rests on states at the Fermi level (Fe3P reads +0.02 MJ/m³ at 0.1 eV and -0.12 at 0.03, against -0.85 measured). The sum is therefore always repeated at half this width from the same diagonalisations, and the response's smearing_check gives that second value, the shift, and sensitive: true with a note when the easy axis changes or the anisotropy moves by more than 0.05 MJ/m³ and 10%. When it is flagged, rerun at the narrower widths it names and extrapolate; the DFT runs are reused, so only the sum is redone. Widths under 0.03 eV need a finer sum_kspacing. Not used by method total_energy.
Range: to 1
Occupation smearing width in eV (converted to Rydberg for ABACUS). Typical metals: 0.05–0.10 eV. Gaps need ~0.05 eV or smaller.
Evaluate the primitive cell instead of the cell as uploaded. A file that carries moments (a relaxation's magCIF) is reduced too: moments of one element within 0.05 µB of each other count as one sublattice. Cheaper, but it folds an antiferromagnetic sublattice onto one site — a conventional NiO cell reduces to a single Ni, where no ordering other than ferromagnetic can exist. Leave false for any magnetic ordering question.
Pass the ID of an Ouro asset for each of these in input_assets. Ouro loads the asset and sends it to the route.
execute returns an action: the record of this run, with its status, response, and any assets it created.
This route is long-running. Start it without waiting, then collect the result when it's done.
By default a failed run comes back as an action with status error. Pass raise_on_error=True to raise an exception instead.
Every run is saved as an action. List yours, or read the logs of a single run. See the Python SDK reference for everything an action carries.
import os
from ouro import Ouro
ouro = Ouro(api_key=os.environ.get("OURO_API_KEY"))
# The ID also works, and stays the same if the route is renamed: "331d9faf-4b44-4679-a958-5a9a816036e1"
route = ouro.routes.retrieve("mmoderwell/magnetic-anisotropy-energy")
action = route.execute(
body={
"method": "perturbation",
"scf_thr": 1e-7,
"kspacing": 0.2,
"hubbard_u": {},
"basis_size": "DZP",
"directions": [
"001",
"100",
"010",
],
"mixing_beta": 0,
"sum_kspacing": 0.1,
"dft_functional": "PBE",
"allow_unrelaxed": False,
"fixed_moment_uB": 0,
"initial_magmoms": [],
"sum_smearing_ev": 0.1,
"smearing_sigma_ev": 0.05,
"reduce_to_primitive": False,
},
input_assets={
"file": "your-file-id",
},
)
print(action.status) # "success" or "error"
print(action.final_data)# Returns as soon as the run is accepted
action = route.execute(
body={
"method": "perturbation",
"scf_thr": 1e-7,
"kspacing": 0.2,
"hubbard_u": {},
"basis_size": "DZP",
"directions": [
"001",
"100",
"010",
],
"mixing_beta": 0,
"sum_kspacing": 0.1,
"dft_functional": "PBE",
"allow_unrelaxed": False,
"fixed_moment_uB": 0,
"initial_magmoms": [],
"sum_smearing_ev": 0.1,
"smearing_sigma_ev": 0.05,
"reduce_to_primitive": False,
},
input_assets={
"file": "your-file-id",
},
wait=False,
)
print(action.id, action.status)
# Later, even from another process
action = ouro.routes.poll_action(str(action.id), poll_interval=5, timeout=1800)
print(action.final_data)from ouro import ExternalServiceError, RouteExecutionError
try:
action = route.execute(
body={
"method": "perturbation",
"scf_thr": 1e-7,
"kspacing": 0.2,
"hubbard_u": {},
"basis_size": "DZP",
"directions": [
"001",
"100",
"010",
],
"mixing_beta": 0,
"sum_kspacing": 0.1,
"dft_functional": "PBE",
"allow_unrelaxed": False,
"fixed_moment_uB": 0,
"initial_magmoms": [],
"sum_smearing_ev": 0.1,
"smearing_sigma_ev": 0.05,
"reduce_to_primitive": False,
},
input_assets={
"file": "your-file-id",
},
raise_on_error=True,
)
except ExternalServiceError as exc:
# The API behind this route failed
print(exc.status_code, exc.retryable)
except RouteExecutionError as exc:
print(exc.action_id, exc.status, exc.response)
except TimeoutError as exc:
# Still running on Ouro; pick it up again later
action = ouro.routes.poll_action(exc.action_id, timeout=None)route = ouro.routes.retrieve("mmoderwell/magnetic-anisotropy-energy")
# Your runs of this route
actions = route.read_actions()
for action in actions:
print(action.id, action.status, action.created_at)
# One run and its logs
action = ouro.routes.retrieve_action("your-action-id")
for entry in action.read_logs(chronological=True):
print(entry.level, entry.message)Part of service
Ouro DFT (ABACUS)
Estimate magnetic anisotropy energy (MAE) across magnetization directions. By default, rejects DFT-unrelaxed inputs (force/stress above threshold); run /dft/structure/relax first or set allow_unrelaxed=true. Useful for permanent-magnet screening and ranking how strongly a material prefers a particular easy axis.
Pricing
USDYou pay for the seconds a run takes, up to a cancel. The most it can cost is held while it runs and the rest is returned. Failed runs are free.
Median and 95th percentile of the last 200 successful runs.
Execution
Usage
913 callsView history