Skip to content

Instantly share code, notes, and snippets.

@computron
Created February 24, 2016 19:24
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/63724d585138a5dd69fb to your computer and use it in GitHub Desktop.
Save computron/63724d585138a5dd69fb to your computer and use it in GitHub Desktop.
Helps convert a DOS to tab-delimited. Useful for experimentalists working in Excel
from pymatgen import MPRester, Spin, Element
def print_dos_data(dos):
print("The Fermi energy is {}".format(dos.efermi))
cols = ["energy", "total_dos", "up_dos", "down_dos"]
energies = dos.energies
total_dos = dos.get_densities() # note that you can also get smeaered densities using a different function
up_dos = dos.get_densities(Spin.up)
down_dos = dos.get_densities(Spin.up)
element_dos = dos.get_element_dos()
element_symbols = [e.symbol for e in element_dos]
cols.extend(["{}_dos".format(e) for e in element_symbols])
orbital_dos = dos.get_spd_dos()
orbital_symbols = [o for o in orbital_dos]
cols.extend(["{}_dos".format(o) for o in orbital_symbols])
print '\t'.join(cols)
for idx, energy in enumerate(energies):
data = [energy, total_dos[idx], up_dos[idx], down_dos[idx]]
for e in element_symbols:
data.append(element_dos[Element(e)].get_densities()[idx]) # note that you can also specify a Spin in get_densities
for o in orbital_symbols:
data.append(orbital_dos[o].get_densities()[idx]) # note that you can also specify a Spin in get_densities
print '\t'.join([str(d) for d in data])
if __name__ == "__main__":
# get the CompleteDos object
API_KEY = None # put your MAPI_KEY here if env variable not set
material_id = "mp-945184"
mpr = MPRester(API_KEY)
dos = mpr.get_dos_by_material_id(material_id)
print_dos_data(dos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment