Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Phase stability using the Materials API + pymatgen.
#!/usr/bin/env python
from pymatgen.matproj.rest import MPRester
from pymatgen.phasediagram.pdmaker import PhaseDiagram
from pymatgen.phasediagram.plotter import PDPlotter
#This initializes the REST adaptor. Put your own API key in.
a = MPRester("YOUR_API_KEY")
#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)
plotter = PDPlotter(pd)
plotter.show()
#!/usr/bin/env python
__author__ = "Shyue Ping Ong"
__maintainer__ = "Shyue Ping Ong"
__email__ = "shyue@mit.edu"
__status__ = "Production"
__version__ = "1.0"
__date__ = "Sep 21, 2012"
import argparse
import sys
from pymatgen.matproj.rest import MPRester
from pymatgen.phasediagram.pdmaker import PhaseDiagram
from pymatgen.apps.borg.hive import VaspToComputedEntryDrone
from pymatgen.phasediagram.pdanalyzer import PDAnalyzer
from pymatgen.entries.compatibility import MaterialsProjectCompatibility
def calculate_phase_stability(args):
#This initializes the REST adaptor.
a = MPRester(args.api_key)
drone = VaspToComputedEntryDrone()
entry = drone.assimilate(args.directory)
compat = MaterialsProjectCompatibility()
entry = compat.process_entry(entry)
if not entry:
print "Calculation parameters are not consistent with Materials " + \
"Project parameters."
sys.exit()
syms = [el.symbol for el in entry.composition.elements]
#This gets all entries belonging to the relevant system.
entries = a.get_entries_in_chemsys(syms)
entries.append(entry)
#Process entries with Materials Project compatibility.
entries = compat.process_entries(entries)
pd = PhaseDiagram(entries)
analyzer = PDAnalyzer(pd)
ehull = analyzer.get_e_above_hull(entry) * 1000
print "Run contains formula {} with corrected energy {:.3f} eV.".format(
entry.composition, entry.energy
)
print "Energy above convex hull = {:.1f} meV".format(ehull)
if ehull < 1:
print "Entry is stable."
elif ehull < 30:
print "Entry is metastable and could be stable at finite temperatures."
elif ehull < 50:
print "Entry has a low probability of being stable."
else:
print "Entry is very unlikely to be stable."
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="""
This is a simple phase stability estimation script which utilizes the
Materials API and pymatgen to calculate the phase stability of a single
material.""",
epilog="""
Author: Shyue Ping Ong
Version: {}
Last updated: {}""".format(__version__, __date__))
parser.add_argument("directory", metavar="dir", type=str,
help="directory containing vasp run to process")
parser.add_argument("-k", "--key", dest="api_key", type=str, required=True,
help="User's Materials API key.")
args = parser.parse_args()
calculate_phase_stability(args)
@machel7

This comment has been minimized.

Copy link

machel7 commented May 16, 2018

I am happy to find you at Git. Because I'm in china, where Twitter&Google is shielded, so that it is not convenient to get access to you by the other routht.
Pymatgen looks like very powerful, so I wonder to know if pymaten can be used for steel-making, for some calculations for the equilibrium between steel(Fe,C,Si,Mn,P,S....) and slag (CaO,SiO2,MgO....).
There is already a software named FactSage that contains professional database for oxides, But the price is too high. Thus I have an idea to build functions with python myself, but I know some others must have done some work. so I find pymatgen and come here。

@kaifengz007

This comment has been minimized.

Copy link

kaifengz007 commented Mar 4, 2019

Dear researcher,
I'm using the powerful Pymatgen tool. There are some outdates import-codes still in the codes above, Could you help to change.
MPRester is in pymatgen.ext.matproj and PhaseDiagram, PDPlotter are in pymatgen.analysis.phase_diagram now. My version of pymatgen is 2019.2.24.
I tried those lines:
from pymatgen.ext.matproj import MPRester
from pymatgen.analysis.phase_diagram import PhaseDiagram,PDPlotter
Best,

@aziziph

This comment has been minimized.

Copy link

aziziph commented Jun 19, 2019

Dear pymatgen users,

It seems the library 'pdanalyzer' no longer exists, since I face to error while using 'from pymatgen.phasediagram.pdanalyzer import PDAnalyzer'. Any comment from where to import this library?

Regards

@shyuep

This comment has been minimized.

Copy link
Owner Author

shyuep commented Jun 19, 2019

It is now integrated into the PhaseDiagram class

@aziziph

This comment has been minimized.

Copy link

aziziph commented Jun 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.