Quick Introduction Question

Hello!

I just started learning how to use MPRester and call certain endpoints from the Materials Project Database. Using the “Getting Started” page of the MPD, I came up with the following line to call adsorption data from the MPD. Generally speaking, could someone explain why this line isn’t working? Is the problem simply that I haven’t specified a certain crystal structure from the MPD yet? Does the endpoint need be on the last line of my code? I haven’t coded in a long time, so I apologize in advance if this is a super basic problem. Thanks!

with MPRester ([“<API_KEY>”,materials/absorption]) as mpr:
# do stuff with mpr…
pass

Hello @MitchellAtMATSCI,

First thing, you should treat your API key as a secret key and not post it in plain text anywhere. You should go to your user dashboard on the Materials Project website and rotate your API key → button with “Get a new API key”.

As for using the MPRester, you’re very close. Some slight modifications:

with MPRester("<API_KEY">) as mpr:
   docs = mpr.materials.absorption.search(material_ids=["mp-149"])

If you’re in a repl you can call help on the search method to see what arguments are available to search by:

help(mpr.materials.absorption.search)

Hello @tsmathis

Totally fair, I realized I should’ve excluded my API key like seconds after I made my post.

1 Like