Examples
API query examples with the MPRester client.
Summary Queries
Structure data for silicon (mp-149)
from mp_api.client import MPRester
with MPRester("your_api_key_here") as mpr:
docs = mpr.materials.summary.search(material_ids=["mp-149"], fields=["structure"])
structure = docs[0].structure
# -- Shortcut for a single Materials Project ID:
structure = mpr.get_structure_by_material_id("mp-149")Querying ICSD ID
For structures tagged with at least one ICSD entry, the simplest way to query structure with ICSD ID is this:
from mp_api.client import MPRester
with MPRester("your_api_key_here") as mpr:
mp_docs = mpr.materials.summary.search(fields=["material_id", "database_IDs"])
icsd_to_mpid = {}
for mp_doc in mp_docs:
mpid = str(mp_doc.material_id)
for icsd_id in mp_doc.database_IDs.get("icsd",[]):
if icsd_id not in icsd_to_mpid:
icsd_to_mpid[icsd_id] = []
icsd_to_mpid[icsd_id].append(mpid)Then the keys of icsd_to_mpid will be all ICSD IDs currently matched to at least one entry in MP, and its values will be the MP IDs which structurally match to that ICSD ID.
NOTE: Not every ICSD entry is included in Materials Project - some of them we’re working on adding, others we do not plan to add (e.g., if they are disordered with a complex disordering ratio). Furthermore, many ICSD entries can structure match to the same MP ID. We use the pymatgen StructureMatcher to determine structural similarity
Find all Materials Project IDs for entries with dielectric data
Calculation (task) IDs and types for silicon (mp-149)
Band gaps for all materials containing only Si and O
Chemical formulas for all materials containing at least Si and O
Material IDs for all ternary oxides with the form ABC3
Stable materials (on the GGA/GGA+U hull) with large band gaps (>3eV)
Electronic Structure
Band structures for silicon (mp-149)
Density of states for silicon (mp-149)
VASP Input Parameters (e.g. NELECT)
To get NELECT (or any other INCAR parameters) is by getting the task_id for the entry and then querying the tasks endpoint directly.
Suppose you want the value of NELECT for mp-149:
NOTE: Be aware that the POTCARs we use in calculations has changed over time, the value of
NELECTis not always determined by theMPRelaxSet. If a DOS was generated with r2SCAN, then the right set to use isMPScanRelaxSet. The method above circumvents this by letting you directly retrieve the value ofNELECT.
Get task-id associated with DOS (mp-149)
The task-id can indicate what functional was used to generate the DOS.
Phonons
Band structure for silicon (mp-149)
Density of states for silicon (mp-149)
XAS
XAS for TiO2 element O K edge:
Charge Density
Charge density for silicon (mp-149)
Phase Diagram
Phase diagram for the Li-Fe-O chemical system
Querying amorphous materials
There are some caveats with representing amorphous structures as small ordered unit cells, and the resulting structures may be phase separated or not representative of a true amorphous phase. Nevertheless, the Materials Project has "amorphous" entries for some compositions, which can be queried and filtered. The following is an example of how to obtain the Materials Project IDs for all SiO2 "amorphous" solids:
Searching by Crystal Prototype: Example — Perovskite
Searching for materials by formula (e.g., ABC₃) can miss important structure types like perovskites with non-standard formulas (e.g., Cs₃Sb₂I₉). Instead, you can search by crystal prototype or structure type using the Materials Project API.
1. Search by Robocrystallographer Description
Robocrystallographer generates structure descriptions, including the term "perovskite" for relevant materials:
2. Search by Provenance Tags and Remarks
Many materials have "perovskite" in their tags or remarks fields:
3. Combine Results
Merge both lists for a comprehensive set of perovskite materials:
4. (Optional) Fetch Structures
Querying specialized calculations like DFPT
MP contains specialized calculations to compute various materials properties. Sometimes it's of interest to find those calculations. A full list of valid such "task types" are given in our builder software, emmet.
DFPT outputs and data only exist for parts of our database. The following code snippet will take only relevant task (single DFT calculation) data from our database and check to see if it’s a DFPT calculation:
dfpt_tasks will contain a set of task IDs which you can then query like mpr.materials.tasks.search(task_ids=dfpt_tasks)
Identifying Materials with Specific Structural Dimensionalities
Though the Materials Project does not store structure dimension as a formal property, it is possible to categorize entries by their structure dimension (1D, 2D, and 3D) by parsing robocrystallographer analyses, which are generated for most materials in the Materials Project.
Finding Materials by Dimension in a Chemical System
Here's an example for the Mo-S system. Note how separate queries are used to retrieve material documents and robocrystallographer entries. These two entities must be associated with each other manually.
Searching for All Dimensional Forms
To find chemical systems with materials existing in all three forms (1D, 2D, and 3D):
Last updated
Was this helpful?