class BSPlotterProjectedTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "Cu2O_361_bandstructure.json"), "r", encoding='utf-8') as f: d = json.load(f) self.bs = BandStructureSymmLine.from_dict(d) self.plotter = BSPlotterProjected(self.bs) warnings.simplefilter("ignore") def tearDown(self): warnings.resetwarnings() # Minimal baseline testing for get_plot. not a true test. Just checks that # it can actually execute. def test_methods(self): self.plotter.get_elt_projected_plots().close() self.plotter.get_elt_projected_plots_color().close() self.plotter.get_projected_plots_dots({'Cu': ['d', 's'], 'O': ['p']}) self.plotter.get_projected_plots_dots_patom_pmorb( { 'Cu': ['dxy', 's', 'px'], 'O': ['px', 'py', 'pz'] }, { 'Cu': [3, 5], 'O': [1] })
class BSPlotterProjectedTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "Cu2O_361_bandstructure.json"), "r", encoding="utf-8") as f: d = json.load(f) self.bs = BandStructureSymmLine.from_dict(d) self.plotter = BSPlotterProjected(self.bs) warnings.simplefilter("ignore") def tearDown(self): warnings.simplefilter("default") # Minimal baseline testing for get_plot. not a true test. Just checks that # it can actually execute. def test_methods(self): self.plotter.get_elt_projected_plots().close() self.plotter.get_elt_projected_plots_color().close() self.plotter.get_projected_plots_dots({ "Cu": ["d", "s"], "O": ["p"] }).close() self.plotter.get_projected_plots_dots_patom_pmorb( { "Cu": ["dxy", "s", "px"], "O": ["px", "py", "pz"] }, { "Cu": [3, 5], "O": [1] }, ).close()
class BSPlotterProjectedTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "Cu2O_361_bandstructure.json"), "r", encoding='utf-8') as f: d = json.load(f) self.bs = BandStructureSymmLine.from_dict(d) self.plotter = BSPlotterProjected(self.bs) # Minimal baseline testing for get_plot. not a true test. Just checks that # it can actually execute. def test_methods(self): self.plotter.get_elt_projected_plots() self.plotter.get_elt_projected_plots_color() self.plotter.get_projected_plots_dots({'Cu': ['d', 's'], 'O': ['p']})
class BSPlotterProjectedTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "Cu2O_361_bandstructure.json"), "r", encoding='utf-8') as f: d = json.load(f) self.bs = BandStructureSymmLine.from_dict(d) self.plotter = BSPlotterProjected(self.bs) # Minimal baseline testing for get_plot. not a true test. Just checks that # it can actually execute. def test_methods(self): self.plotter.get_elt_projected_plots() self.plotter.get_elt_projected_plots_color() self.plotter.get_projected_plots_dots({'Cu': ['d', 's'], 'O': ['p']})
class BSPlotterProjectedTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "Cu2O_361_bandstructure.json"), "r", encoding='utf-8') as f: d = json.load(f) self.bs = BandStructureSymmLine.from_dict(d) self.plotter = BSPlotterProjected(self.bs) warnings.simplefilter("ignore") def tearDown(self): warnings.resetwarnings() # Minimal baseline testing for get_plot. not a true test. Just checks that # it can actually execute. def test_methods(self): self.plotter.get_elt_projected_plots().close() self.plotter.get_elt_projected_plots_color().close() self.plotter.get_projected_plots_dots({'Cu': ['d', 's'], 'O': ['p']}) self.plotter.get_projected_plots_dots_patom_pmorb( {'Cu': ['dxy', 's', 'px'], 'O': ['px', 'py', 'pz']}, {'Cu': [3, 5], 'O': [1]} )
def plot_bs_elt_projected(bs, **kwargs): """ Get element projected BS color plot with pymatgen. Note that vasprun.xml needs to be parsed with parse_projected_eigen set to True. Parameters ---------- bs : BandStructureSymmLine object, most likely generated from Vasprun or BSVasprun. **kwargs : (dict) Arguments for the get_elt_projected_plots_color function in BSPlotter in pymatgen. Returns ------- plt : Matplotlib object. """ plotter = BSPlotterProjected(bs) plt = plotter.get_elt_projected_plots_color(**kwargs) return plt
def plot_color_projected_bands(ylim=(-5, 5), fmt='pdf'): """ Plot a single band structure where the color of the band indicates the elemental character of the eigenvalue. Args: ylim (tuple): minimum and maximum energies for the plot's y-axis. fmt (str): matplotlib format style. Check the matplotlib docs for options. """ vasprun = Vasprun('vasprun.xml', parse_projected_eigen=True) bs = vasprun.get_band_structure('KPOINTS', line_mode=True) bspp = BSPlotterProjected(bs) plot = bspp.get_elt_projected_plots_color() fig = plot.gcf() ax = fig.gca() ax.set_xticklabels([r'$\mathrm{%s}$' % t for t in ax.get_xticklabels()]) ax.set_ylim(ylim) fig.savefig('color_projected_bands.{}'.format(fmt)) plt.close()
def plot_color_projected_bands(ylim=(-5, 5), fmt="pdf"): """ Plot a single band structure where the color of the band indicates the elemental character of the eigenvalue. Args: ylim (tuple): minimum and maximum energies for the plot's y-axis. fmt (str): matplotlib format style. Check the matplotlib docs for options. """ vasprun = Vasprun("vasprun.xml", parse_projected_eigen=True) bs = vasprun.get_band_structure("KPOINTS", line_mode=True) bspp = BSPlotterProjected(bs) plot = bspp.get_elt_projected_plots_color() fig = plot.gcf() ax = fig.gca() ax.set_xticklabels([r"$\mathrm{%s}$" % t for t in ax.get_xticklabels()]) ax.set_ylim(ylim) fig.savefig("color_projected_bands.{}".format(fmt)) plt.close()
def plot_color_projected_bands(ylim=(-5, 5), fmt='pdf'): """ Plot a single band structure where the color of the band indicates the elemental character of the eigenvalue. Args: ylim (tuple): minimum and maximum energies for the plot's y-axis. fmt (str): matplotlib format style. Check the matplotlib docs for options. """ vasprun = Vasprun('vasprun.xml', parse_projected_eigen=True) bs = vasprun.get_band_structure('KPOINTS', line_mode=True) bspp = BSPlotterProjected(bs) ax = bspp.get_elt_projected_plots_color().gcf().gca() ax.set_xticklabels([r'$\mathrm{%s}$' % t for t in ax.get_xticklabels()]) ax.set_yticklabels([r'$\mathrm{%s}$' % t for t in ax.get_yticklabels()]) ax.set_ylim(ylim) if fmt == "None": return ax else: plt.savefig('color_projected_bands.{}'.format(fmt)) plt.close()
from pymatgen.electronic_structure.plotter import BSPlotterProjected from pymatgen.io.vasp.outputs import BSVasprun, Element path = '/home/jinho93/interface/pzt-bso/loose/opti/band/' vrun = BSVasprun(path + 'vasprun.xml', True, True) bs = vrun.get_band_structure(path + 'KPOINTS') plotter = BSPlotterProjected(bs) #plt = plotter.get_elt_projected_plots_color(elt_ordered=[Element.O, Element.Hf]) #plt = plotter.get_plot(ylim=(-8, 5), vbm_cbm_marker=True) plt = plotter.get_elt_projected_plots_color( elt_ordered=[Element.Ti, Element.Sn, Element.O]) plt.ylim((-5, 6)) plt.show()