This notebook shows how to plot and analyze a phase diagram.
# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.
# !pip install pymatgen==2022.7.19
from pymatgen.analysis.phase_diagram import PDPlotter, PhaseDiagram
from pymatgen.ext.matproj import MPRester
%matplotlib inline
To generate a phase diagram, we obtain entries from the Materials Project and call the PhaseDiagram class in pymatgen.
# This initializes the REST adaptor. You may need to put your own API key in as an arg.
a = MPRester()
# Entries are the basic unit for thermodynamic and other analyses in pymatgen.
# This gets all entries belonging to the Ca-C-O system.
entries = a.get_entries_in_chemsys(["Ca", "C", "O"])
# With entries, you can do many sophisticated analyses, like creating phase diagrams.
pd = PhaseDiagram(entries)
To plot a phase diagram, we send our phase diagram object into the PDPlotter class.
# Let's show all phases, including unstable ones
plotter = PDPlotter(pd, show_unstable=0.2, backend="matplotlib")
plotter.show()
import collections
data = collections.defaultdict(list)
for e in entries:
decomp, ehull = pd.get_decomp_and_e_above_hull(e)
data["Materials ID"].append(e.entry_id)
data["Composition"].append(e.composition.reduced_formula)
data["Ehull"].append(ehull)
data["Decomposition"].append(
" + ".join([f"{v:.2f} {k.composition.formula}" for k, v in decomp.items()])
)
from pandas import DataFrame
df = DataFrame(data, columns=["Materials ID", "Composition", "Ehull", "Decomposition"])
print(df.head(30))
Materials ID Composition Ehull Decomposition 0 mp-611448 C 0.142597 1.00 C4 1 mp-1097832 C 2.605766 1.00 C4 2 mp-1205283 C 0.697407 1.00 C4 3 mp-24 C 0.833079 1.00 C4 4 mp-1078845 C 0.265893 1.00 C4 5 mp-1244913 C 0.993796 1.00 C4 6 mp-1008374 C 0.436517 1.00 C4 7 mp-579909 C 0.943112 1.00 C4 8 mp-1181996 C 2.634925 1.00 C4 9 mp-1194362 C 1.502474 1.00 C4 10 mp-1188817 C 0.763339 1.00 C4 11 mp-1182684 C 1.527767 1.00 C4 12 mp-1197903 C 1.408604 1.00 C4 13 mp-568286 C 0.006294 1.00 C4 14 mp-683919 C 0.348517 1.00 C4 15 mp-1008395 C 0.333186 1.00 C4 16 mp-569416 C 0.028760 1.00 C4 17 mp-568806 C 0.010042 1.00 C4 18 mp-606949 C 0.008344 1.00 C4 19 mp-611426 C 0.145803 1.00 C4 20 mp-1147718 C 0.386797 1.00 C4 21 mp-570002 C 0.763687 1.00 C4 22 mp-616440 C 0.141158 1.00 C4 23 mp-1018088 C 1.305495 1.00 C4 24 mp-1040425 C 0.007888 1.00 C4 25 mp-937760 C 0.004164 1.00 C4 26 mp-990448 C 0.007545 1.00 C4 27 mp-1096869 C 0.115975 1.00 C4 28 mp-568028 C 0.528968 1.00 C4 29 mp-66 C 0.136419 1.00 C4