# Introduction¶

This notebook demonstrates how you can obtain various data from the Materials Project using pymatgen's interface to the Materials API.

In [2]:
from pymatgen import MPRester, Composition
import re
import pprint

# Make sure that you have the Materials API key. Put the key in the call to
# MPRester if needed, e.g, MPRester("MY_API_KEY")
mpr = MPRester()


# Getting structures with material ids¶

Let's say you want to find all structures with similar stoichiometry to Fe2O3.

In [3]:
comp = Composition("Fe2O3")
anon_formula = comp.anonymized_formula
# We need to convert the formula to the dict form used in the database.
anon_formula = {m.group(1): int(m.group(2))
for m in re.finditer(r"([A-Z]+)(\d+)", anon_formula)}

data = mpr.query({"anonymous_formula": anon_formula},
print(len(data))  #Should show ~600 data.

601

In [4]:
# data now contains a list of dict. This shows you what each dict has.
# Note that the mp id is named "task_id" in the database itself.
pprint.pprint(data[0])

{'pretty_formula': 'Gd2O3',
'structure': Structure Summary
Lattice
abc : 3.7465563099999999 3.7465563064877148 5.95228761
angles : 90.0 90.0 119.99999994271758
volume : 72.35675272229777
A : 3.7465563099999999 0.0 0.0
B : -1.87327815 3.2446129400000001 0.0
C : 0.0 0.0 5.95228761
PeriodicSite: O (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]
PeriodicSite: O (1.8733, 1.0815, 2.1102) [0.6667, 0.3333, 0.3545]
PeriodicSite: O (-0.0000, 2.1631, 3.8421) [0.3333, 0.6667, 0.6455]
PeriodicSite: Gd (1.8733, 1.0815, 4.4720) [0.6667, 0.3333, 0.7513]
PeriodicSite: Gd (-0.0000, 2.1631, 1.4803) [0.3333, 0.6667, 0.2487],


# Getting band structures¶

Band structures are fairly large objects. It is not recommended that you download large quantities of bandstructures in one shot, but rather just download the ones you need.

In [5]:
bs = mpr.get_bandstructure_by_material_id("mp-20470")

In [6]:
from pymatgen.electronic_structure.plotter import BSPlotter
%matplotlib inline

In [7]:
plotter = BSPlotter(bs)
plotter.show()