Manual web interface to materials project XRD

I am trying to use the interface at https://api.materialsproject.org/

I don’t understand how to get data that I viewed in the Materials Explorer.

For example, here is a query and response I did:

Compound: NaCl
Data: X-ray absorption spectra → XANES spectrum → absorbing element Cl

Server response

Code Details
200 ##### Response body

Unrecognized response type; displaying content as text.|

And,

Code: 200
Description: Search for a XASDoc
Links: No links

Although the Material Explorer had this spectrum (as an image plot only; I need the values), I cannot get the values from the web interface.

(Please note I did try using python but ran into many problems as I am on an office computer with no administrator access. The API route may end up being prohibitively difficult for a beginner to programming.)

Hi @lct,

Guessing you mean XAS not XRD, right? (the title)

The usability of the api docs that you linked as an actual data retrieval tool is pretty limited as that page is meant to be a reference to complement the mp_api python client, so you might have a hard time getting the info you want efficiently.

I’ll provide some code here that would start get you started with the python client to get where you want to be (I’m assuming you want the plots? edit: re-reading I see you just want the values, the code below still gets you where you want to be). And just picking mp-22862 as a representative of the Na-Cl chemsys.

from mp_api.client import MPRester
import plotly.graph_objects as go


with MPRester(api_key="YOUR_API_KEY") as mpr:
    xas_doc = mpr.materials.xas.search(material_ids=["mp-22862"], absorbing_element="Cl", spectrum_type="XANES")

traces = [
    go.Scatter(
        x=xas_doc[0].spectrum.x,
        y=xas_doc[0].spectrum.y,
        mode="lines",
        fill="tozeroy",
    )
]

go.Figure(traces)

If you run the above code in a Juptyer notebook the plot will render directly. You’ll have to consult Plotly’s documentation for further plot customization/exporting the plots.

Now, if you are strictly unable to use the mp_api and you are okay with retrieving a few results at a time from the demo functionality in the api docs, try adding “spectrum” to the _fields entry in the Materials XAS section, you’ll get the following json in that Response Body section of the results (some data omitted for brevity):

  data: [
    {
      spectrum: {
        "@module": "pymatgen.analysis.xas.spectrum",
        "@class": "XAS",
        "@version": "2020.4.29",
        x: [
          2815.947, ...
        ],
        y: [
          0.0196335, ...
        ],
        structure: ...

those x and y arrays are the same used in the above python code (and in the Material Explorer)

@tsmathis
Thank you! I see now that I was missing “spectrum” in the _fields entry.
I also tried the code and saw that it outputs the XAS (I meant XAS) values. (I managed to get the python working on my home computer at least.)