Examples
API query examples with the MPRester client.

Summary Queries

Structure data for silicon (mp-149)

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
structure = mpr.get_structure_by_material_id("mp-149")
5
6
# -- General search alternative:
7
doc = mpr.summary.get_data_by_id("mp-149", fields=["structure"])
8
structure = doc.structure
Copied!

Calculation (task) IDs for silicon (mp-149)

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
task_ids = mpr.get_task_ids_associated_with_material_id("mp-149")
5
6
# -- General search alternative:
7
doc = mpr.materials.get_data_by_id("mp-149", fields=["calc_types"])
8
task_ids = doc.calc_types.keys()
9
task_types = doc.calc_types.values()
Copied!

Band gaps for all materials containing only Si and O

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
docs = mpr.summary.search(chemsys="Si-O",
5
fields=["material_id", "band_gap"])
6
mpid_bgap_dict = {doc.material_id: doc.band_gap for doc in docs}
Copied!

Chemical formulas for all materials containing at least Si and O

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
docs = mpr.summary.search(elements=["Si", "O"],
5
fields=["material_id", "band_gap"])
6
mpid_formula_dict = {doc.material_id: doc.pretty_formula for doc in docs}
Copied!

Stable materials (on the hull) with large band gaps (>3eV)

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
docs = mpr.summary.search(band_gap=(3,None),
5
is_stable=True,
6
fields=["material_id"])
7
stable_mpids = [doc.material_id for doc in docs]
8
9
## -- Alternative directly using energy above hull:
10
docs = mpr.summary.search(band_gap=(3,None),
11
energy_above_hull=(0,0),
12
fields=["material_id"])
13
stable_mpids = [doc.material_id for doc in docs]
Copied!

Electronic Structure

Band structures for silicon (mp-149)

1
from mp_api import MPRester
2
from emmet.core.electronic_structure import BSPathType
3
4
with MPRester("your_api_key_here") as mpr:
5
# -- line-mode, Setyawan-Curtarolo (default):
6
bs_sc = mpr.get_bandstructure_by_material_id("mp-149")
7
8
# -- line-mode, Hinuma et al.:
9
bs_hin = mpr.get_bandstructure_by_material_id("mp-149", path_type=BSPathType.hinuma)
10
11
# -- line-mode, Latimer-Munro:
12
bs_hin = mpr.get_bandstructure_by_material_id("mp-149", path_type=BSPathType.latimer_munro)
13
14
# -- uniform:
15
bs_uniform = mpr.get_bandstructure_by_material_id("mp-149", line_mode=False)
Copied!

Density of states for silicon (mp-149)

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
dos = mpr.get_dos_by_material_id("mp-149")
Copied!

Phonons

Band structure for silicon (mp-149)

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
ph_bs = mpr.get_phonon_bandstructure_by_material_id("mp-149")
Copied!

Density of states for silicon (mp-149)

1
from mp_api import MPRester
2
from emmet.core.electronic_structure import BSPathType
3
4
with MPRester("your_api_key_here") as mpr:
5
ph_dos = mpr.get_phonon_dos_by_material_id("mp-149")
Copied!

Charge Density

Charge density for silicon (mp-149)

1
from mp_api import MPRester
2
3
with MPRester("your_api_key_here") as mpr:
4
chgcar = mpr.get_charge_density_from_material_id("mp-149")
Copied!