Retrieve computed x-ray absorption spectra (XAS) through MPRester

FEFF-calculated XAS XANES K-edge spectra are available for many structures. At this time, the data is not stored as pymatgen objects, but one may obtain data and transform it to pymatgen objects as in the below examples. We do intend to eventually provide convenience methods for MPRester that yield pymatgen spectra objects.

Raw spectra

from pymatgen import MPRester
from pymatgen.analysis.xas.spectrum import XANES

m = MPRester()

data = m.get_data("mp-3748", data_type="feff", prop="xas")

spectra = []
for material in data:
    for xas_doc in material['xas']:
        x, y = xas_doc['spectrum']
        structure = xas_doc["structure"]
        absorption_specie = xas_doc['structure'].species[xas_doc['absorbing_atom']]
        edge = xas_doc["edge"]
        spectra.append(XANES(x, y, structure, absorption_specie, edge=edge))

Site-averaged spectra (e.g. as displayed on material detail pages and in XAS app)

import json

from pymatgen import MPRester
from pymatgen.analysis.xas.spectrum import XANES

mp_id = "mp-3748"
element = "O"

m = MPRester()

# Only XANES K-edge available at this time
data = m._make_request('/xas/spectra_for',
        "material_ids": json.dumps([mp_id]),
        "elements": json.dumps([element]), # required argument
        "smoothingFWHM": 2, # in eV, default 0

structure = m.get_structure_by_material_id(mp_id)

absorption_specie = next(
    specie for specie in structure.species
    if getattr(specie, 'element', specie).symbol == element)

x, y = data[0]['spectrum']
spectrum = XANES(x, y, structure, absorption_specie, edge="K")