Skip to content

Instantly share code, notes, and snippets.

@computron
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computron/e2d317ae214eb326b500 to your computer and use it in GitHub Desktop.
Save computron/e2d317ae214eb326b500 to your computer and use it in GitHub Desktop.
Print all corrections applied on a Materials Project entry
"""
This example prints out the corrections applied by a Compatibility scheme
(e.g., MaterialsProjectCompatibility) in order to improve the accuracy of reaction energies
and phase diagrams.
To run this example, you should:
* have pymatgen (www.pymatgen.org) installed
* obtain a Materials Project API key (https://www.materialsproject.org/open)
* paste that API key in the MAPI_KEY variable below, e.g. MAPI_KEY = "foobar1234"
as well as:
* update MP_ID with the Materials Project id of the compound
For citation, see https://www.materialsproject.org/citing
"""
from __future__ import division
from pymatgen import MPRester
from pymatgen.entries.compatibility import MaterialsProjectCompatibility
if __name__ == "__main__":
MAPI_KEY = None # You must change this to your Materials API key! (or set MAPI_KEY env variable)
MP_ID = "mp-19017" # You must change this to the mp-id of your compound of interest
mpr = MPRester(MAPI_KEY) # object for connecting to MP Rest interface
compat = MaterialsProjectCompatibility() # sets energy corrections and +U/pseudopotential choice
my_entry = mpr.get_entry_by_material_id(MP_ID)
corrections_dict = compat.get_corrections_dict(my_entry)
pretty_corrections = ["{}:{}".format(k, round(v, 3)) for k, v in corrections_dict.iteritems()]
print "We are applying the following corrections (eV) to the user entry: {}".format(pretty_corrections)
my_entry.correction = sum(corrections_dict.values())
print "The sum of corrections is %.3f eV/atom so the new energy is %.3f eV/atom." % (my_entry.correction/my_entry.composition.num_atoms, my_entry.energy_per_atom)
print "Note that corrections often cancel when computing reaction energies, so you must determine which corrections are non-cancelling for your reaction of interest."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment