In [1]:
from pymatgen.matproj.rest import MPRester
from pymatgen.phasediagram.maker import PhaseDiagram

%matplotlib inline

Generating the phase diagram

To generate a phase diagram, we obtain entries from the Materials Project and call the PhaseDiagram class in pymatgen.

In [2]:
#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)

Plotting the phase diagram

To plot a phase diagram, we send our phase diagram object into the PDPlotter class.

In [3]:
from pymatgen.phasediagram.plotter import PDPlotter
#Let's show all phases, including unstable ones
plotter = PDPlotter(pd, show_unstable=True)
plotter.show()

Calculating energy above hull and other phase equilibria properties

To perform more sophisticated analyses, use the PDAnalyzer object.

In [4]:
from pymatgen.phasediagram.analyzer import PDAnalyzer
a = PDAnalyzer(pd)
In [5]:
import collections

data = collections.defaultdict(list)
for e in entries:
    decomp, ehull = a.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(["%.2f %s" % (v, k.composition.formula) for k, v in decomp.items()]))

from pandas import DataFrame
df = DataFrame(data, columns=["Materials ID", "Composition", "Ehull", "Decomposition"])

print(df)
   Materials ID Composition     Ehull                           Decomposition
0         mp-45          Ca  0.000508                                1.00 Ca2
1      mp-10683          Ca  0.396161                                1.00 Ca2
2         mp-21          Ca  0.013583                                1.00 Ca2
3        mp-166          Ca  0.013329                                1.00 Ca2
4        mp-132          Ca  0.000000                                1.00 Ca2
5    mp-1008498          Ca  0.152771                                1.00 Ca2
6     mp-990424           C  0.004827                                1.00 C16
7        mp-169           C  0.004413                                1.00 C16
8     mp-632329           C  0.110332                                1.00 C16
9         mp-66           C  0.135631                                1.00 C16
10        mp-47           C  0.160479                                1.00 C16
11    mp-569416           C  0.028801                                1.00 C16
12    mp-569304           C  0.029940                                1.00 C16
13    mp-568806           C  0.006175                                1.00 C16
14        mp-48           C  0.002697                                1.00 C16
15    mp-616440           C  0.140564                                1.00 C16
16    mp-611426           C  0.145308                                1.00 C16
17    mp-611448           C  0.142026                                1.00 C16
18    mp-569517           C  0.145186                                1.00 C16
19        mp-24           C  0.832340                                1.00 C16
20    mp-990448           C  0.003052                                1.00 C16
21    mp-579909           C  0.944071                                1.00 C16
22    mp-568410           C  0.506378                                1.00 C16
23    mp-570002           C  0.762539                                1.00 C16
24   mp-1008395           C  0.331788                                1.00 C16
25    mp-630227           C  0.393490                                1.00 C16
26    mp-998866           C  2.756837                                1.00 C16
27    mp-667273           C  0.388760                                1.00 C16
28    mp-997182           C  0.003585                                1.00 C16
29    mp-680372           C  0.407085                                1.00 C16
..          ...         ...       ...                                     ...
49   mp-1009653        CaC2  0.204859                     0.33 Ca2 + 0.67 C16
50    mp-684668        CaC2  0.068324                     0.33 Ca2 + 0.67 C16
51    mp-642822        CaC2  0.024576                     0.33 Ca2 + 0.67 C16
52   mp-1009655        CaC2  0.743834                     0.33 Ca2 + 0.67 C16
53    mp-545512         CaO  0.065085                             1.00 Ca1 O1
54      mp-2605         CaO  0.000000                             1.00 Ca1 O1
55    mp-634859        CaO2  0.007227                   0.67 Ca1 O1 + 0.33 O8
56    mp-995183          CO  0.559450                   0.25 C16 + 0.75 C4 O8
57     mp-20066         CO2  0.000000                              1.00 C4 O8
58    mp-556660          CO  0.692016                   0.25 C16 + 0.75 C4 O8
59     mp-11875          CO  0.668938                   0.25 C16 + 0.75 C4 O8
60    mp-995196         CO3  3.078212                    0.25 O8 + 0.75 C4 O8
61    mp-561848        C3O2  0.513353                   0.40 C16 + 0.60 C4 O8
62   mp-1001594        C4O3  0.241118                   0.36 C16 + 0.64 C4 O8
63    mp-556034         CO2  0.028775                              1.00 C4 O8
64     mp-11725         CO2  0.025395                              1.00 C4 O8
65    mp-644607         CO2  0.028281                              1.00 C4 O8
66    mp-995198         CO2  0.323686                              1.00 C4 O8
67    mp-995224         CO2  0.302425                              1.00 C4 O8
68      mp-4626       CaCO3  0.024281                          1.00 Ca2 C2 O6
69      mp-3205       CaCO3  0.169799                          1.00 Ca2 C2 O6
70    mp-558543    Ca(CO2)2  0.046302  0.07 C16 + 0.71 Ca2 C2 O6 + 0.21 C4 O8
71      mp-3953       CaCO3  0.000000                          1.00 Ca2 C2 O6
72    mp-561412       CaCO3  0.007359                          1.00 Ca2 C2 O6
73    mp-556235       CaCO3  0.002015                          1.00 Ca2 C2 O6
74    mp-553939       CaCO3  0.013584                          1.00 Ca2 C2 O6
75    mp-641635       CaCO3  1.368847                          1.00 Ca2 C2 O6
76    mp-548403       CaCO3  0.312190                          1.00 Ca2 C2 O6
77    mp-696740       CaCO3  1.683982                          1.00 Ca2 C2 O6
78    mp-560265       CaCO3  0.008073                          1.00 Ca2 C2 O6

[79 rows x 4 columns]
In [ ]: