Question about how to download, plot and use a XANES spectrum

Hello! I am new to Materials Project and also kind of new to python. I was trying to download the XANES spectrum of the Zn L23 edge (the material is ZnO). I have tried with this code:

with MPRester("myAPIkey") as mpr:
    xas = mpr.xas.search(spectrum_type=Type.XANES, formula = "ZnO", absorbing_element = 'Zn', edge = Edge.L2_3)

But “xas” is an element which I don’t know how to treat. How can I extract the spectrum data (energy,Intensity values) from it?

Thanks!

Hi @alebreeds, check out mpr.xas.available_fields to get a list of attributes available for each xas document. The response to your search query is a list of XASDocs. To access the spectrum for the first entry in the list, use xas[0].spectrum.x and xas[0].spectrum.y. @munrojm might have additional guidance if needed.

@tschaume is right. The data in the spectrum field of the document is an XAS spectrum object from pymatgen. You can see its attributes and methods here, and what data you can access: pymatgen.analysis.xas.spectrum module — pymatgen 2023.5.10 documentation

– Jason

Thanks, it works perfectly fine now!