def plot_dos_dict(complete_dos, d, xlim=(-3, 3), **kwargs): """ Plot DOS dict with pymatgen. The dict is most likely generated with the methods of the pymatgen CompleteDos class. Parameters ---------- complete_dos : CompleteDos object. d : TYPE Dict of DOS. xlim : (tuple), optional Limits for x axis. The default is (-3,3). **kwargs : (dict) Arguments for DosPlotter in pymatgen. Returns ------- plt : Matplotlib object. """ dos_plotter = DosPlotter(**kwargs) for k in d: dos_plotter.add_dos(k, d[k]) eg = complete_dos.get_gap() plt = dos_plotter.get_plot(xlim=(xlim[0], eg + xlim[1])) return plt
def get_dos(self, dos): task_id = dos['task_id'] dos_obj = self.vaspdb.get_dos(task_id) energies = dos_obj.energies efermi = dos_obj.efermi gap = dos_obj.get_gap() densities_up = dos_obj.densities[Spin.up] densities_dn = dos_obj.densities[Spin.down] #densities = densities_up + densities_dn densities = dos_obj.get_densities() #print('Fermi energy: {}'.format(efermi)) #print('gap: {}'.format(gap)) tdos = np.vstack((energies, densities)) #print(tdos) #print(type(densities)) plotter = DosPlotter() # Adds a DOS with a label. #plotter.add_dos("Total DOS", dos) # Alternatively, you can add a dict of DOSs. This is the typical # form returned by CompleteDos.get_spd/element/others_dos(). #plotter.add_dos_dict({"dos1": dos1, "dos2": dos2}) dosplot = plotter.add_dos_dict(dos_obj.get_element_dos()) #dosplot = plotter.add_dos_dict(dos_obj.get_spd_dos()) #plotter.show() self.head = [ 'energies', 'total_dos', 'total_dos_spin_up', 'total_dos_spin_down' ] self.unit = ['eV', '', '', ''] self.data = np.vstack( (energies, densities, densities_up, -densities_dn)).T self.parameter = dos['input']['incar']
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) warnings.simplefilter("ignore")
def get_dos_plot(args): v = Vasprun(args.dos_file) dos = v.complete_dos all_dos = OrderedDict() all_dos["Total"] = dos structure = v.final_structure if args.site: for i in range(len(structure)): site = structure[i] all_dos["Site " + str(i) + " " + site.specie.symbol] = \ dos.get_site_dos(site) if args.element: syms = [tok.strip() for tok in args.element[0].split(",")] all_dos = {} for el, dos in dos.get_element_dos().items(): if el.symbol in syms: all_dos[el] = dos if args.orbital: all_dos = dos.get_spd_dos() plotter = DosPlotter() plotter.add_dos_dict(all_dos) return plotter.get_plot()
def get_dos_plot(args): v = Vasprun(args.dos_file) dos = v.complete_dos all_dos = OrderedDict() all_dos["Total"] = dos structure = v.final_structure if args.site: for i in range(len(structure)): site = structure[i] all_dos["Site " + str(i) + " " + site.specie.symbol] = \ dos.get_site_dos(site) if args.element: syms = [tok.strip() for tok in args.element[0].split(",")] all_dos = {} for el, dos in dos.get_element_dos().items(): if el.symbol in syms: all_dos[el] = dos if args.orbital: all_dos = dos.get_spd_dos() plotter = DosPlotter() plotter.add_dos_dict(all_dos) return plotter.get_plot()
def setUp(self): with open(os.path.join(PymatgenTest.TEST_FILES_DIR, "complete_dos.json"), encoding="utf-8") as f: self.dos = CompleteDos.from_dict(json.load(f)) self.plotter = DosPlotter(sigma=0.2, stack=True) warnings.simplefilter("ignore")
def get_dos_plot(args): """ Plot DOS. Args: args (dict): Args from argparse. """ v = Vasprun(args.dos_file) dos = v.complete_dos all_dos = OrderedDict() all_dos["Total"] = dos structure = v.final_structure if args.site: for i, site in enumerate(structure): all_dos["Site " + str(i) + " " + site.specie.symbol] = dos.get_site_dos(site) if args.element: syms = [tok.strip() for tok in args.element[0].split(",")] all_dos = {} for el, dos in dos.get_element_dos().items(): if el.symbol in syms: all_dos[el] = dos if args.orbital: all_dos = dos.get_spd_dos() plotter = DosPlotter() plotter.add_dos_dict(all_dos) return plotter.get_plot()
def plot_dos(self, sigma=0.05): """ plot dos Args: sigma: a smearing Returns: a matplotlib object """ plotter = DosPlotter(sigma=sigma) plotter.add_dos("t", self._bz.dos) return plotter.get_plot()
def plot_dos(self, T=None, npoints=10000): """ Plot the total Dos using DosPlotter() """ if self.bzt_interp is None: raise BoltztrapError("BztInterpolator not present") tdos = self.bzt_interp.get_dos(T=T, npts_mu=npoints) # print(npoints) dosPlotter = DosPlotter() dosPlotter.add_dos("Total", tdos) return dosPlotter
def plot_dos(self, T=None, npoints=10000): """ Plot the total Dos using DosPlotter() """ if self.bzt_interp is None: raise BoltztrapError("BztInterpolator not present") tdos = self.bzt_interp.get_dos(T=T,npts_mu=npoints) #print(npoints) dosPlotter = DosPlotter() dosPlotter.add_dos('Total',tdos) return dosPlotter
def __init__(self, vasp): self.vasp = vasp self.z = self.getGCD() self.formula = self.getElem() self.full_formula = self.getElem(False) self.elem_List = self.elList() self.mass = Mass(vasp.atomic_symbols) self.volume = vasp.final_structure.volume self.density = self.mass / self.volume * 1.66054 self.neighbors = nearNeighbors(vasp) self.latConst = self.getLatConst() self.plot = DosPlotter()
def plot_dos(self, sigma=0.05): """ plot dos Args: sigma: a smearing Returns: a matplotlib object """ plotter = DosPlotter(sigma=sigma) plotter.add_dos("t", self._bz.dos) return plotter.get_plot()
def setUp(self): try: import scipy except ImportError: raise SkipTest("scipy not present. Skipping...") with open(os.path.join(test_dir, "complete_dos.json"), "r") as f: self.dos = CompleteDos.from_dict(json.load(f)) self.plotter = DosPlotter(sigma=0.2, stack=True)
class DosPlotterTest(unittest.TestCase): def setUp(self): try: import scipy except ImportError: raise SkipTest("scipy not present. Skipping...") with open(os.path.join(test_dir, "complete_dos.json"), "r") as f: self.dos = CompleteDos.from_dict(json.load(f)) self.plotter = DosPlotter(sigma=0.2, stack=True) def test_add_dos_dict(self): try: import scipy except ImportError: raise SkipTest("scipy not present. Skipping...") 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): try: import scipy except ImportError: raise SkipTest("scipy not present. Skipping...") 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)
class MyDynamicMplCanvas(MyMplCanvas): """A canvas that updates itself every second with a new plot.""" def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) self.dsp = DosPlotter() def update_figure(self, txt): # Build a list of 4 random integers between 0 and 10 (both inclusive) self.axes.clear() with open(txt) as f: ef = float(f.readline().split()[-2]) arr = [r.split() for r in f.readlines()] arr = np.array(arr) arr = arr.astype(np.float) self.dos = Dos(ef, arr[:, 0], {Spin.up: arr[:, 1]}) self.dsp.add_dos('tdos', self.dos) self.dsp.get_plot(plt=self.axes) self.draw()
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)
def main(): parser = argparse.ArgumentParser(description='''Convenient DOS Plotter for Feff runs. Author: Alan Dozier Version: 1.0 Last updated: April, 2013''') parser.add_argument('filename', metavar='filename', type=str, nargs=1, help='ldos%% file set to plot') parser.add_argument('filename1', metavar='filename1', type=str, nargs=1, help='feff.inp input file ') parser.add_argument('-s', '--site', dest='site', action='store_const', const=True, help='plot site projected DOS') parser.add_argument('-e', '--element', dest='element', action='store_const', const=True, help='plot element projected DOS') parser.add_argument('-o', '--orbital', dest="orbital", action='store_const', const=True, help='plot orbital projected DOS') args = parser.parse_args() f = LDos.from_file(args.filename1[0], args.filename[0]) dos = f.complete_dos all_dos = OrderedDict() all_dos['Total'] = dos structure = f.complete_dos.structure if args.site: for i, site in enumerate(structure): all_dos['Site ' + str(i) + " " + site.specie.symbol] = \ dos.get_site_dos(site) if args.element: all_dos.update(dos.get_element_dos()) if args.orbital: all_dos.update(dos.get_spd_dos()) plotter = DosPlotter() plotter.add_dos_dict(all_dos) plotter.show()
def main(): parser = argparse.ArgumentParser( description="""Convenient DOS Plotter for Feff runs. Author: Alan Dozier Version: 1.0 Last updated: April, 2013""" ) parser.add_argument("filename", metavar="filename", type=str, nargs=1, help="ldos%% file set to plot") parser.add_argument("filename1", metavar="filename1", type=str, nargs=1, help="feff.inp input file ") parser.add_argument("-s", "--site", dest="site", action="store_const", const=True, help="plot site projected DOS") parser.add_argument( "-e", "--element", dest="element", action="store_const", const=True, help="plot element projected DOS" ) parser.add_argument( "-o", "--orbital", dest="orbital", action="store_const", const=True, help="plot orbital projected DOS" ) args = parser.parse_args() f = LDos.from_file(args.filename1[0], args.filename[0]) dos = f.complete_dos all_dos = OrderedDict() all_dos["Total"] = dos structure = f.complete_dos.structure if args.site: for i, site in enumerate(structure): all_dos["Site " + str(i) + " " + site.specie.symbol] = dos.get_site_dos(site) if args.element: all_dos.update(dos.get_element_dos()) if args.orbital: all_dos.update(dos.get_spd_dos()) plotter = DosPlotter() plotter.add_dos_dict(all_dos) plotter.show()
def main(): parser = argparse.ArgumentParser( description='''Convenient DOS Plotter for Feff runs. Author: Alan Dozier Version: 1.0 Last updated: April, 2013''') parser.add_argument('filename', metavar='filename', type=str, nargs=1, help='ldos%% file set to plot') parser.add_argument('filename1', metavar='filename1', type=str, nargs=1, help='feff.inp input file ') parser.add_argument('-s', '--site', dest='site', action='store_const', const=True, help='plot site projected DOS') parser.add_argument('-e', '--element', dest='element', action='store_const', const=True, help='plot element projected DOS') parser.add_argument('-o', '--orbital', dest="orbital", action='store_const', const=True, help='plot orbital projected DOS') args = parser.parse_args() f = LDos.from_file(args.filename1[0], args.filename[0]) dos = f.complete_dos all_dos = OrderedDict() all_dos['Total'] = dos structure = f.complete_dos.structure if args.site: for i, site in enumerate(structure): all_dos['Site ' + str(i) + " " + site.specie.symbol] = \ dos.get_site_dos(site) if args.element: all_dos.update(dos.get_element_dos()) if args.orbital: all_dos.update(dos.get_spd_dos()) plotter = DosPlotter() plotter.add_dos_dict(all_dos) plotter.show()
def plot_dos(vasprun_path: str): try: v = Vasprun(vasprun_path) except xml.etree.ElementTree.ParseError: print("\tskipped due to parse error") return tdos = v.tdos plt = DosPlotter() plt.add_dos("Total DOS", tdos) plt.show()
class DosPlotterTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "complete_dos.json"), "r") 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)
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")
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)
def pdos(vasprun): # Load the vasprun.xml file out = Vasprun(os.path.abspath(vasprun)) # Extract the types of species in the structure species = out.initial_structure.types_of_specie # Extract the complete DOS element_dos = out.complete_dos.get_element_dos() # Initialize the DosPlotter plotter = DosPlotter() # Add the element projected DOS to the DOSplotter for specie in species: plotter.add_dos(specie.name, element_dos[specie]) plotter.show()
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) warnings.simplefilter("ignore") def tearDown(self): warnings.resetwarnings() 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")
from pymatgen.io.vasp import Vasprun, Element from pymatgen.electronic_structure.plotter import DosPlotter v = Vasprun('AgTe_dos/vasprun.xml') cdos = v.complete_dos element_dos = cdos.get_element_dos() element_orbital = cdos.get_element_spd_dos(el=Element("Ag")) plotter = DosPlotter() plotter.add_dos_dict(element_orbital) plotter.show(xlim=[-4, 4], ylim=[0, 10])
def plot_dos(self): plotter = DosPlotter(sigma=0.05) plotter.add_dos("t", self._bz.dos) plotter.get_plot().show()
def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) self.dsp = DosPlotter()
def main(): """ Main function. """ parser = argparse.ArgumentParser( description="""Convenient DOS Plotter for Feff runs. Author: Alan Dozier Version: 1.0 Last updated: April, 2013""") parser.add_argument( "filename", metavar="filename", type=str, nargs=1, help="ldos%% file set to plot", ) parser.add_argument("filename1", metavar="filename1", type=str, nargs=1, help="feff.inp input file ") parser.add_argument( "-s", "--site", dest="site", action="store_const", const=True, help="plot site projected DOS", ) parser.add_argument( "-e", "--element", dest="element", action="store_const", const=True, help="plot element projected DOS", ) parser.add_argument( "-o", "--orbital", dest="orbital", action="store_const", const=True, help="plot orbital projected DOS", ) args = parser.parse_args() f = LDos.from_file(args.filename1[0], args.filename[0]) dos = f.complete_dos all_dos = {} all_dos["Total"] = dos structure = f.complete_dos.structure if args.site: for i, site in enumerate(structure): all_dos["Site " + str(i) + " " + site.specie.symbol] = dos.get_site_dos(site) if args.element: all_dos.update(dos.get_element_dos()) if args.orbital: all_dos.update(dos.get_spd_dos()) plotter = DosPlotter() plotter.add_dos_dict(all_dos) plotter.show()
from pymatgen.io.vasp import Vasprun, Element from pymatgen.electronic_structure.plotter import DosPlotter v = Vasprun('AgTe_dos/vasprun.xml') cdos = v.complete_dos element_dos = cdos.get_element_dos() element_orbital = cdos.get_element_spd_dos(el=Element("Te")) #print(cdos.pdos) #px = cdos.get_site_orbital_dos(site=v.final_structure.sites[0],orbital=0) #py = cdos.get_site_orbital_dos(site=v.final_structure.sites[0],orbital=2) #pz = cdos.get_site_orbital_dos(site=v.final_structure.sites[0],orbital=1) plotter = DosPlotter(zero_at_efermi=True) plotter.add_dos_dict(element_dos) #plotter.add_dos_dict(px) #plotter.add_dos_dict(py) #plotter.add_dos_dict(pz) plotter.show(xlim=[-4, 4], ylim=[0, 10])
raise """ 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')
#!/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])
# 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('../')
from pymatgen.electronic_structure.plotter import DosPlotter from optparse import OptionParser parser = OptionParser() parser.add_option("-v", action="store_true", dest="verbose", help="plot w.r.t Vacuum level, this needs \ CONTACR and LOCPOT files.") (options, args) = parser.parse_args() v = Vasprun('vasprun.xml') cdos = v.complete_dos element_dos = cdos.get_element_dos() plotter = DosPlotter() efermi = v.efermi if options.verbose: from pymatgen.core import Element from pymatgen.io.vasp.outputs import Locpot, Poscar from pymatgen.analysis.surface_analysis import WorkFunctionAnalyzer l = Locpot.from_file('LOCPOT') s = Poscar.from_file('CONTCAR') wf = WorkFunctionAnalyzer(s.structure, l.get_average_along_axis(1), efermi, shift=0) loc_vac = wf.vacuum_locpot
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)
#print cdos.get_densities() tdos = vasp.tdos #Total dos calculated at the end of run idos = vasp.idos # Integrated dos calculated at the end of run pdos = vasp.pdos # List of list of PDos objects. Access as pdos[atomindex][orbitalindex] efermi = vasp.efermi eigenvalues = vasp.eigenvalues projected_eigenvalues = vasp.projected_eigenvalues bs = bsvasp.get_band_structure(line_mode=True) total_dos = tdos pdoss = pdos #CDOS = CompleteDos(structure,total_dos,pdoss) spd_dos = cdos.get_spd_dos #print spd_dos element_dos = cdos.get_element_dos #element_spd_dos = cdos.get_element_spd_dos(el) dosplotter = DosPlotter() Totaldos = dosplotter.add_dos('Total DOS', tdos) Integrateddos = dosplotter.add_dos('Integrated DOS', idos) #Pdos = dosplotter.add_dos('Partial DOS',pdos) #Spd_dos = dosplotter.add_dos('spd DOS',spd_dos) #Element_dos = dosplotter.add_dos('Element DOS',element_dos) #Element_spd_dos = dosplotter.add_dos('Element_spd DOS',element_spd_dos) dos_dict = { 'Total DOS': tdos, 'Integrated DOS': idos } #'Partial DOS':pdos,'spd DOS':spd_dos,'Element DOS':element_dos}#'Element_spd DOS':element_spd_dos add_dos_dict = dosplotter.add_dos_dict(dos_dict) get_dos_dict = dosplotter.get_dos_dict() dos_plot = dosplotter.get_plot() ##dosplotter.save_plot("MAPbI3_dos",img_format="png") ##dos_plot.show()
# 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')
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")
help='feff.inp input file ') parser.add_argument('-s', '--site', dest='site', action='store_const', const=True, help='plot site projected DOS') parser.add_argument('-e', '--element', dest='element', action='store_const', const=True, help='plot element projected DOS') parser.add_argument('-o', '--orbital', dest="orbital", action='store_const', const=True, help='plot orbital projected DOS') args = parser.parse_args() f = FeffLdos.from_file(args.filename1[0], args.filename[0]) dos = f.complete_dos all_dos = OrderedDict() all_dos['Total'] = dos structure = f.complete_dos.structure if args.site: for i in xrange(len(structure)): site = structure[i] all_dos['Site ' + str(i) + " " + site.specie.symbol] = \ dos.get_site_dos(site) if args.element: all_dos.update(dos.get_element_dos()) if args.orbital: all_dos.update(dos.get_spd_dos()) plotter = DosPlotter() plotter.add_dos_dict(all_dos) plotter.show()
from pymatgen.io.vasp.outputs import Vasprun, Element from pymatgen.electronic_structure.plotter import DosPlotter import os os.chdir('/home/jinho93/oxides/perobskite/lanthanum-aluminate/slab/14/asym') os.chdir( '/home/jinho93/oxides/perobskite/lanthanum-aluminate/periodic_step/vasp/stengel/001/vca/AlO2' ) os.chdir( '/home/jinho93/oxides/perobskite/lanthanum-aluminate/slab/14/asym/to_Al') # os.chdir('/home/jinho93/new/oxides/perobskite/lanthanum-aluminate/slab/7') vrun = Vasprun('vasprun.xml') cdos = vrun.complete_dos s = vrun.final_structure dsp = DosPlotter() dos_dict = {} i: Site for n, i in enumerate(s.sites): if i.species_string == 'La': dos_dict[f'{n}'] = cdos.get_site_dos(i) dsp.add_dos_dict(dos_dict) dsp.show(xlim=(-10, 5), ylim=(0, 2)) # %% aldos = cdos.get_site_dos(s.sites[0]) dx = aldos.energies[1] - aldos.energies[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")
def setUp(self): with open(os.path.join(test_dir, "complete_dos.json"), "r") as f: self.dos = CompleteDos.from_dict(json.load(f)) self.plotter = DosPlotter(sigma=0.2, stack=True)
import os from collections import OrderedDict from pymatgen.core.periodic_table import Element vasp_dir = os.path.dirname(os.path.abspath(__file__)) vasp_run = Vasprun(os.path.join(vasp_dir, "vasprun.xml")) dos = vasp_run.complete_dos all_dos = OrderedDict() all_dos["Total"] = dos elem = dos.get_element_dos() print elem.keys() from copy import deepcopy AgSe = elem[Element('Ag')].__add__(elem[Element('Se')]) CH = elem[Element('C')].__add__(elem[Element('H')]) all_dos.update({'Ag+Se':AgSe,'C+H':CH}) plotter = DosPlotter(sigma=0.05) plotter.add_dos_dict(all_dos) plotter.get_plot(xlim=[-3,4],ylim=[0,30],width=12,height=6).savefig(filename="orgo_inorg_dos.pdf",img_format="pdf")
@Author : Xu-Shan Zhao @Filename: pymatgenPlotBSDOS202005091027.py @IDE : PyCharm @Time1 : 2020-05-09 10:27:36 @Time2 : 2020/5/9 10:27 @Month1 : 5月 @Month2 : 五月 """ from pymatgen.electronic_structure.plotter import DosPlotter, BSPlotter, BSDOSPlotter from pymatgen.io.vasp import Vasprun, BSVasprun vasprun_file = './AlEuO3_Perovskite_DOS/vasprun.xml' vasprun = Vasprun(vasprun_file) tdos = vasprun.tdos plotter = DosPlotter() plotter.add_dos('Total DOS', tdos) # plotter.show(xlim=[-20, 20], ylim=[-6, 6]) plotter.show() completeDos = vasprun.complete_dos element_dos = completeDos.get_element_dos() plotter = DosPlotter() plotter.add_dos_dict(element_dos) plotter.add_dos('Total DOS', tdos) plotter.show() spd_dos = completeDos.get_spd_dos() plotter = DosPlotter() plotter.add_dos_dict(spd_dos) plotter.add_dos('Total DOS', tdos)