I am trying to use mp-api and MPR.query(formula=‘Fe2O3’, fields=[…]) to query Fe2O3-related information from the Materials Project. May I ask how to retrieve the icsd_ids and corresponding BibTex Citation? They are displayed in the web app as follows but I didn’t find a relevant keyword to put in ‘fields’. Thanks!
Hi, I think the screenshot that you have shared is from the legacy site (legacy.materialsproject.org), while the mp-api is primarily designed to interact with the new Materials Project site (next-gen.materialsproject.org). Most of the information will likely be the same, but the new site is constantly being updated while the legacy site is now frozen.
Link to documentation for the API: Materials Project API - Swagger UI
For using the mp-api:
If you know the material project id (MP ID) for the Fe2O3 material of interest (for example, mp-19770), then you can query the provenance doc directly. The two key fields are “database_IDs” which will retrieve the ICSD IDs and the “references” field will retrieve the BibTex citations.
# Import from mp_api import MPRester with MPRester(API_KEY) as mpr: doc = mpr.provenance.get_data_by_id("mp-19770", field = ["database_IDs", "references"] ) # To get the ICSD ids doc.database_IDs # To get the BibTex citations doc.references
In the case that you don’t know the MP ID of the Fe2O3 material of interest, you can also use the mp-api to get all the MP IDs associated with Fe2O3 as shown below:
from mp_api import MPRester with MPRester(API_KEY) as mpr: # Query the summary doc to get the MP IDs of all Fe2O3 materials in the MP # You could filter by additional field arguments to reduce the amount entries returned # Fe2O3_docs is a list of SummaryDoc objects Fe2O3_docs = mpr.summary.search(formula="Fe2O3", fields = ["material_id"]) # Create a list of the ids mp_ids = [i.material_id for i in Fe2O3_docs] # To then get the icsd_ids and references, we would loop over the list of MP IDs, and get the provenance doc for each material # provenance_docs will be a list of ProvenanceDoc objects. with MPRester(API_KEY) as mpr: provenance_docs =[mpr.provenance.get_data_by_id(mp_id, fields =["material_id", "database_IDs", "references"]) for mp_id in mp_ids] # We could then look at one example from our query and print the MP ID, database IDs (if any) and references # Let's print out the first results from provenance_docs print(provenance_docs.material_id) print(provenance_docs.database_IDs) print(provenance_docs.references)
Hope my responses have helped!
Thank you very much! It is very clear!
Thanks @AntObi, great post!