Accessing XAS spectra through endpoint

Hi there,

I am relatively new to computational material science and to using the MP API. I have been trying to access all the XANES K-edge spectra for zinc and the silver compounds. So far, I have tried using the ‘direct route’ (i.e., using the endpoint) but it seems I have to specify elements as in:

with MPRester(MP_API_KEY) as mpr:
    XAS_doc = = Edge.K,
                           absorbing_element = "Zn",
                           elements = ["Zn", "O"])

What I would like to do is more general, i.e., I would like to access all the Ag and Zn K-edge XANES spectra available in the database. Thus, I have attempted the following code:

from mp_api.client import MPRester
from emmet.core.summary import HasProps

req_fields = ["composition", "formula_pretty", "density_atomic", "symmetry", "structure","is_stable", "xas", "band_gap", "efermi", "bandstructure", "dos_energy_up"]

with MPRester(MP_API_KEY) as mpr:
    docs =
        has_props = [HasProps.xas], fields = req_fields)
    XAS_doc = [doc.xas for doc in docs]
    Struct_doc = [doc.structure for doc in docs]
    ch_formula = [doc.formula_pretty for doc in docs]

However, using this end point, I am not able to access the K-edge spectra at all. So far, this is what I have been able to do:

E_1 = D[0].absorbing_element

E_2 = D[0].edge.K

E = D[0].spectrum_type.XANES

Is there any way that I can access the spectra using this end point? Alternatively, is there a way I can parse the end point so that it can return all compounds containing Zn and all compounds containing Ag?

Hi @rmngunji, you should be able to get all of the spectra data from the XAS endpoint. Here are two queries you can make to get all of the Ag and Zn K-edge XANES spectra alongside the relevant material_id and xas_id values:

from emmet.core.xas import Edge, Type
with MPRester(use_document_model=False, monty_decode=False) as mpr:
    zn_docs =, 
                          fields=["material_id", "xas_id", "spectrum"])

    ag_docs =, 
                          fields=["material_id", "xas_id", "spectrum"])

In getting this snippet, I realize there is an issue with the XAS document model validation. I will fix this, but for now the use_document_model=False, monty_decode=False arguments to MPRester bypass the issue and allow the data to be pulled.

– Jason

Hi Jason,

Thank you for your response! I was able to retrieve the documents!