Ejemplo n.º 1
0
class DosPlotterTest(unittest.TestCase):
    def setUp(self):
        with open(os.path.join(test_dir, "complete_dos.json"), "r",
                  encoding='utf-8') as f:
            self.dos = CompleteDos.from_dict(json.load(f))
            self.plotter = DosPlotter(sigma=0.2, stack=True)

    def test_add_dos_dict(self):
        d = self.plotter.get_dos_dict()
        self.assertEqual(len(d), 0)
        self.plotter.add_dos_dict(self.dos.get_element_dos(),
                                  key_sort_func=lambda x: x.X)
        d = self.plotter.get_dos_dict()
        self.assertEqual(len(d), 4)

    def test_get_dos_dict(self):
        self.plotter.add_dos_dict(self.dos.get_element_dos(),
                                  key_sort_func=lambda x: x.X)
        d = self.plotter.get_dos_dict()
        for el in ["Li", "Fe", "P", "O"]:
            self.assertIn(el, d)

    # Minimal baseline testing for get_plot. not a true test. Just checks that
    # it can actually execute.
    def test_get_plot(self):
        # Disabling latex is needed for this test to work.
        from matplotlib import rc
        rc('text', usetex=False)
        self.plotter.add_dos_dict(self.dos.get_element_dos(),
                                  key_sort_func=lambda x: x.X)
        plt = self.plotter.get_plot()
        self.plotter.save_plot("dosplot.png")
        self.assertTrue(os.path.isfile("dosplot.png"))
        os.remove("dosplot.png")
Ejemplo n.º 2
0
 def get_odos(self, stack=True, xlim=[-10, 10], ylim=[0, 50], sigma=0.15):
     dos_vasprun = Vasprun(os.path.join(self.path, "vasprun.xml"), parse_projected_eigen=True)
     dos_data = dos_vasprun.complete_dos
     plotter = DosPlotter(stack=stack, sigma=sigma)
     o_dos = dos_data.get_spd_dos()
     plotter.add_dos_dict(o_dos)
     plotter.save_plot(f'{self.path}-odos.png', img_format=u'png', xlim=xlim, ylim=ylim)
Ejemplo n.º 3
0
class DosPlotterTest(unittest.TestCase):
    def setUp(self):
        with open(os.path.join(test_dir, "complete_dos.json"), "r",
                  encoding='utf-8') as f:
            self.dos = CompleteDos.from_dict(json.load(f))
            self.plotter = DosPlotter(sigma=0.2, stack=True)

    def test_add_dos_dict(self):
        d = self.plotter.get_dos_dict()
        self.assertEqual(len(d), 0)
        self.plotter.add_dos_dict(self.dos.get_element_dos(),
                                  key_sort_func=lambda x: x.X)
        d = self.plotter.get_dos_dict()
        self.assertEqual(len(d), 4)

    def test_get_dos_dict(self):
        self.plotter.add_dos_dict(self.dos.get_element_dos(),
                                  key_sort_func=lambda x: x.X)
        d = self.plotter.get_dos_dict()
        for el in ["Li", "Fe", "P", "O"]:
            self.assertIn(el, d)

    # Minimal baseline testing for get_plot. not a true test. Just checks that
    # it can actually execute.
    def test_get_plot(self):
        # Disabling latex is needed for this test to work.
        from matplotlib import rc
        rc('text', usetex=False)
        self.plotter.add_dos_dict(self.dos.get_element_dos(),
                                  key_sort_func=lambda x: x.X)
        plt = self.plotter.get_plot()
        self.plotter.save_plot("dosplot.png")
        self.assertTrue(os.path.isfile("dosplot.png"))
        os.remove("dosplot.png")
Ejemplo n.º 4
0
    def get_sdos(self, dos_dict, stack=True, xlim=[-10, 10], ylim=None, sigma=0.15):
        dos_vasprun = Vasprun(os.path.join(self.path, "vasprun.xml"), parse_projected_eigen=True)
        dos_data = dos_vasprun.complete_dos
        plotter = DosPlotter(stack=stack, sigma=sigma)
        edos = dos_data.get_element_dos()
        for key in dos_dict:
            if type(dos_dict[key]) is list:
                for index, item in enumerate(dos_dict[key]):
                    if index == 0:
                        temp = dos_data.get_site_dos(dos_data.structure[item])
                    else:
                        temp = temp + dos_data.get_site_dos(dos_data.structure[item])
                plotter.add_dos(key, temp)
            elif type(dos_dict[key]) is str:
                temp = edos[Element(dos_dict[key])]
                plotter.add_dos(key, temp)
            elif type(dos_dict[key]) is int:
                temp = dos_data.get_site_dos(dos_data.structure[dos_dict[key]])
                plotter.add_dos(key, temp)
            else:
                print('Warning: invalid value')

        if ylim is not None:
            plotter.save_plot(f'{self.path}-dos.png', img_format=u'png', xlim=xlim, ylim=ylim)
        else:
            plotter.save_plot(f'{self.path}-dos.png', img_format=u'png', xlim=xlim)
Ejemplo n.º 5
0
def get_mp_banddos():
    check_matplotlib()
    mpr = check_apikey()
    print("input the mp-ID")
    wait_sep()
    in_str = wait()
    mp_id = in_str
    step_count = 1
    proc_str = "Reading Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')
    data = mpr.get_entry_by_material_id(mp_id)
    sepline()
    print(data)
    sepline()
    step_count += 1
    proc_str = "Reading Band Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')

    band = mpr.get_bandstructure_by_material_id(mp_id)
    if band is None:
        print("No data obtained online, stop now!")
        os.exit(0)

    step_count += 1
    filename = mp_id + '_band.png'
    proc_str = "Writing Data to " + filename + " File..."
    bsp = BSPlotter(band)
    procs(proc_str, step_count, sp='-->>')
    bsp.save_plot(filename=filename, img_format="png")

    step_count += 1
    proc_str = "Reading DOS Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')
    dos = mpr.get_dos_by_material_id(mp_id)
    if dos is None:
        print("No data obtained online, stop now!")

    step_count += 1
    filename = mp_id + '_dos.png'
    proc_str = "Writing Data to " + filename + " File..."
    dsp = DosPlotter()
    dsp.add_dos('Total', dos)
    procs(proc_str, step_count, sp='-->>')
    dsp.save_plot(filename=filename, img_format="png")
Ejemplo n.º 6
0
def total_dos():
   check_matplotlib()
   filename='vasprun.xml'
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,1,sp='-->>')
   vsr=Vasprun(filename,parse_eigen=False)
   tdos=vsr.tdos
   idos=vsr.idos
   E=tdos.energies-tdos.efermi
   if vsr.is_spin:
      proc_str="This Is a Spin-polarized Calculation."
      procs(proc_str,0,sp='-->>')
      proc_str="Writting TDOS.dat File ..."
      TDOSUP=tdos.densities[Spin.up]
      TDOSDOWN=tdos.densities[Spin.down]
      ETDOS=np.vstack((E,TDOSUP,TDOSDOWN))
      head_line="#%(key1)+12s%(key2)+12s%(key3)+12s"%{'key1':'Energy(eV)','key2':'SpinUp','key3':'SpinDown'}
      write_col_data('TDOS.dat',ETDOS.T,head_line)

      proc_str="Writting IDOS.dat File ..."
      procs(proc_str,3,sp='-->>')
      IDOSUP=idos.densities[Spin.up]
      IDOSDOWN=idos.densities[Spin.down]
      EIDOS=np.vstack((E,IDOSUP,IDOSDOWN))
      head_line="#%(key1)+12s%(key2)+12s%(key3)+12s"%{'key1':'Energy(eV)','key2':'IntSpinUp','key3':'IntSpinDown'}
      write_col_data('IDOS.dat',EIDOS.T,head_line)

      plt1=DosPlotter()
      plt2=DosPlotter()
      plt1.add_dos('Total DOS',tdos)
      plt2.add_dos('Total DOS',idos)
      try:
       # plt1.show()
        plt1.save_plot('TotalDOS.png', img_format="png")
       # plt2.show()
        plt2.save_plot('IntegratedDOS.png', img_format="png")
      except:
        print("pls use gnuplot to plot TDOS.dat and IDOS.dat")
   else:
      if vsr.parameters['LNONCOLLINEAR']:
         proc_str="This Is a Non-Collinear Calculation."
      else:
          proc_str="This Is a Non-Spin Calculation."
      procs(proc_str,0,sp='-->>')
      proc_str="Writting TDOS.dat File ..."
      procs(proc_str,2,sp='-->>')
      
      TDOS=tdos.densities[Spin.up]
      ETDOS=np.vstack((E,TDOS))
      head_line="#%(key1)+12s%(key2)+12s"%{'key1':'Energy(eV)','key2':'TotalDOS'}
      write_col_data('TDOS.dat',ETDOS.T,head_line)

      proc_str="Writting IDOS.dat File ..."
      procs(proc_str,3,sp='-->>')
      IDOS=idos.densities[Spin.up]
      EIDOS=np.vstack((E,IDOS))
      head_line="#%(key1)+12s%(key2)+13s"%{'key1':'Energy(eV)','key2':'IntegratedDOS'}
      write_col_data('IDOS.dat',EIDOS.T,head_line)

      plt1=DosPlotter()
      plt2=DosPlotter()
      plt1.add_dos('Total DOS',tdos)
      plt2.add_dos('Integrated DOS',idos)
      filename4="TotalDOS.png IntegratedDOS.png"
      proc_str="Saving Plot to "+ filename4 +" File ..."
      procs(proc_str,4,sp='-->>')

      try:
       # plt1.show()
        plt1.save_plot('TotalDOS.png', img_format="png")
       # plt2.show()
        plt2.save_plot('IntegratedDOS.png', img_format="png")
      except:
        print("pls use gnuplot to plot TDOS.dat and IDOS.dat")
Ejemplo n.º 7
0
Plot DOS
"""

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

from pymatgen.io.vasp import Vasprun
from pymatgen.electronic_structure.plotter import DosPlotter

v = Vasprun('./vasprun.xml', parse_dos=True)
cdos = v.complete_dos
element_dos = cdos.get_element_dos()
plotter = DosPlotter()
plotter.add_dos_dict(element_dos)
plotter.save_plot('plots/dos.pdf', img_format='pdf', xlim=None, ylim=None)
# plotter.save_plot('spin-up_dos.pdf', img_format='pdf', xlim= None, ylim = [0,None])   # up-spin dos
"""
Plot Band
"""

from pymatgen.io.vasp import BSVasprun
from pymatgen.electronic_structure.plotter import BSPlotter

v = BSVasprun('./vasprun.xml', parse_projected_eigen=True)
bs = v.get_band_structure(kpoints_filename='./KPOINTS', line_mode=True)
bsplot = BSPlotter(bs)

bsplot.get_plot(zero_to_efermi=True, ylim=[-5, 5]).savefig('plots/band.pdf')

# add some features
Ejemplo n.º 8
0
        # 3rd run to obtain Band structure
        band = MPNonSCFSet.from_prev_calc(static_dir,
                                          mode="line",
                                          standardize=True,
                                          user_incar_settings=myset)
        band.write_input(band_dir)
        run_vasp(cmd, band_dir)
        os.system('cp ' + band_dir + '/vasprun.xml  ./band-vasprun.xml')
        os.system('cp ' + band_dir + '/KPOINTS  ./')

        v = BSVasprun("band-vasprun.xml")
        bs = v.get_band_structure(kpoints_filename='KPOINTS', line_mode=True)
        plt = BSPlotter(bs)
        plt.get_plot(vbm_cbm_marker=True)
        plt.save_plot(Name + '-band.png', ylim=[-4, 4], img_format='png')

        v = Vasprun('dos-vasprun.xml')
        tdos = v.tdos
        cdos = v.complete_dos
        spd_dos = cdos.get_spd_dos()
        plotter = DosPlotter(sigma=0.1)
        plotter.add_dos("Total DOS", tdos)
        # plotter.add_dos("spd_dos", spd_dos)
        plotter.save_plot(Name + '-dos.png', img_format='png', xlim=[-4, 4])

        shutil.rmtree(band_dir)
        shutil.rmtree(dos_dir)
        shutil.rmtree(static_dir)

    os.chdir('../')
Ejemplo n.º 9
0
    wf = WorkFunctionAnalyzer(s.structure,
                              l.get_average_along_axis(1),
                              efermi,
                              shift=0)
    loc_vac = wf.vacuum_locpot

    for i in element_dos:
        element_dos[i].efermi = loc_vac

    plotter.add_dos_dict(element_dos)
    plt = plotter.get_plot(xlim=[-9, 1])
    plt.plot([efermi - loc_vac, efermi - loc_vac],
             plt.ylim(),
             'b--',
             linewidth=2,
             label='EF')

    plt.xlabel('Energies - Vac(eV)')
    plt.legend()
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize=30)
    plt.tight_layout()
    plt.savefig('dos.png')
    plt.show()

else:
    plotter.add_dos_dict(element_dos)
    plotter.show()
    plotter.save_plot('vasp_dos.png', xlim=[-8, 7], img_format='png')
Ejemplo n.º 10
0
#!/nfshome/villa/anaconda3/bin/python

from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.electronic_structure.plotter import BSPlotter, DosPlotter

vaspout = Vasprun("./vasprun.xml")

# Initializes plotter with some optional args. Defaults are usually
# fine,
complete_dos = vaspout.complete_dos
plt = DosPlotter()
plt.add_dos_dict(complete_dos.get_spd_dos())
tdos = vaspout.tdos
# Adds a DOS with a label.
plt.add_dos("Total", tdos)
#plt.get_plot()

plt.save_plot('dos_mg.pdf', img_format='pdf', xlim=[-7, 6], ylim=[0, 20])
Ejemplo n.º 11
0
# coding: utf-8
# Copyright (c) Henniggroup.
# Distributed under the terms of the MIT License.

from __future__ import division, print_function, unicode_literals, \
    absolute_import

"""
reads in vasprun.xml file and plots the density of states 
"""

# To use matplotlib on Hipergator, uncomment the following 2 lines:
# import matplotlib
# matplotlib.use('Agg')

from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.electronic_structure.plotter import DosPlotter

if __name__ == "__main__":
    # readin the density of states from vasprun.xml file
    run = Vasprun("vasprun.xml", parse_projected_eigen=True)
    complete_dos = run.complete_dos
    print('cbm and vbm ', complete_dos.get_cbm_vbm())
    print('gap = ', complete_dos.get_gap())
    # get orbital projected DOS.    
    spd_dos = complete_dos.get_spd_dos()
    plotter = DosPlotter()
    plotter.add_dos_dict(spd_dos)
    plotter.save_plot('dos.eps')
Ejemplo n.º 12
0
import os
import sys
import datetime
import time
import pandas as pd

sys.path.append('/Volumes/kaswat200GB/GitHub/pyVASP/')
os.system('clear')
print("Current date and time: ",
      datetime.datetime.now().strftime("%d-%m-%Y %H-%M-%S"))
print("")

from pymatgen.io.vasp import Vasprun
from pymatgen.electronic_structure.plotter import DosPlotter

localDir = os.getcwd()
temp = os.path.join(localDir, 'vasprun.xml')
v = Vasprun(temp)
tdos = v.tdos
plotter = DosPlotter()
plotter.add_dos("Total DOS", tdos)
## plotter.show()
plotter.save_plot('TDOS.eps')

cdos = v.complete_dos
element_dos = cdos.get_element_dos()
plotter = DosPlotter()
plotter.add_dos_dict(element_dos)
## plotter.show()
plotter.save_plot('PDOS.eps')
Ejemplo n.º 13
0
# coding: utf-8
# Copyright (c) Henniggroup.
# Distributed under the terms of the MIT License.

from __future__ import division, print_function, unicode_literals, \
    absolute_import
"""
reads in vasprun.xml file and plots the density of states 
"""

# To use matplotlib on Hipergator, uncomment the following 2 lines:
# import matplotlib
# matplotlib.use('Agg')

from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.electronic_structure.plotter import DosPlotter

if __name__ == "__main__":
    # readin the density of states from vasprun.xml file
    run = Vasprun("vasprun.xml", parse_projected_eigen=True)
    complete_dos = run.complete_dos
    print('cbm and vbm ', complete_dos.get_cbm_vbm())
    print('gap = ', complete_dos.get_gap())
    # get orbital projected DOS.
    spd_dos = complete_dos.get_spd_dos()
    plotter = DosPlotter()
    plotter.add_dos_dict(spd_dos)
    plotter.save_plot('dos.eps')