Example #1
0
def plot_orb_projected_bands(orbitals, fmt='pdf', ylim=(-5, 5)):
    """
    Plot a separate band structure for each orbital of each element in
    orbitals.

    Args:
        orbitals (dict): dictionary of the form
            {element: [orbitals]},
            e.g. {'Mo': ['s', 'p', 'd'], 'S': ['p']}
        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_projected_plots_dots(orbitals, ylim=ylim).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()])
    if fmt == "None":
        return ax
    else:
        plt.savefig('orb_projected_bands.{}'.format(fmt))
    plt.close()
Example #2
0
 def setUp(self):
     with open(os.path.join(PymatgenTest.TEST_FILES_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")
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]
            })
Example #4
0
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()
Example #6
0
 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")
Example #7
0
 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")
Example #8
0
def plot_elt_projected_bands(ylim=(-5, 5), fmt="pdf"):
    """
    Plot separate band structures for each element where the size of the
    markers 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)
    bspp.get_elt_projected_plots(ylim=ylim).savefig("elt_projected_bands.{}".format(fmt))
    plt.close()
Example #9
0
def plot_elt_projected_bands(ylim=(-5, 5), fmt='pdf'):
    """
    Plot separate band structures for each element where the size of the
    markers 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)
    bspp.get_elt_projected_plots(ylim=ylim).savefig(
        'elt_projected_bands.{}'.format(fmt))
    plt.close()
Example #10
0
def plot_orb_projected_bands(orbitals, fmt="pdf", ylim=(-5, 5)):
    """
    Plot a separate band structure for each orbital of each element in
    orbitals.

    Args:
        orbitals (dict): dictionary of the form
            {element: [orbitals]},
            e.g. {'Mo': ['s', 'p', 'd'], 'S': ['p']}
        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)
    bspp.get_projected_plots_dots(orbitals, ylim=ylim).savefig("orb_projected_bands.{}".format(fmt))
    plt.close()
Example #11
0
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
Example #12
0
def plot_orb_projected_bands(orbitals, fmt='pdf', ylim=(-5, 5)):
    """
    Plot a separate band structure for each orbital of each element in
    orbitals.

    Args:
        orbitals (dict): dictionary of the form
            {element: [orbitals]},
            e.g. {'Mo': ['s', 'p', 'd'], 'S': ['p']}
        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)
    bspp.get_projected_plots_dots(orbitals, ylim=ylim).savefig(
        'orb_projected_bands.{}'.format(fmt))
    plt.close()
Example #13
0
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()
Example #14
0
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()
Example #15
0
def plot_elt_projected_bands(ylim=(-5, 5), fmt='pdf'):
    """
    Plot separate band structures for each element where the size of the
    markers 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(ylim=ylim).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()])
    if fmt == "None":
        return ax
    else:
        plt.savefig('elt_projected_bands.{}'.format(fmt))
    plt.close()
Example #16
0
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]}
        )
from pymatgen.io.vasp.outputs import BSVasprun
from pymatgen.electronic_structure.plotter import BSPlotterProjected

import os
import pickle

vasp_dir = os.path.dirname(os.path.abspath(__file__))
vasp_run = BSVasprun(os.path.join(vasp_dir,"vasprun.xml"),parse_projected_eigen=True)

bs = vasp_run.get_band_structure(line_mode=True)

bsp = BSPlotterProjected(bs)

p = bsp.get_color_grouped([{'elements':['Ag','Se'],'color':[255,140,0]},
                           {'elements':['C','H'],'color':[0,0,0]}],ylim=[-3,4])
p.savefig('color_band.pdf')

#pickle.dump(bs, open("band_structure.dat", "w"))
Example #18
0
 def test_proj_bandstructure_plot(self):
     # make sure that it can be plotted!
     BSPlotterProjected(self.bs_spin).get_elt_projected_plots()
     BSPlotterProjected(self.bs_spin).get_projected_plots_dots({"Si": ["3s"]})
Example #19
0
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()
bsplotter = BSPlotter(bs)
bsplotterprojected = BSPlotterProjected(bs)
bs_plot_data = bsplotter.bs_plot_data()
#bs_plot = bsplotter.get_plot()
#bsplotter.save_plot("MAPbI3_bs",img_format="png")
#bsplotter.show()
ticks = bsplotter.get_ticks()
#print ticks
bsdos = BSDOSPlotter(
    tick_fontsize=10,
    egrid_interval=20,
    legend_fontsize=28,
    dos_projection="orbitals",
    bs_legend=None,
    fig_size=(110, 85))  #bs_projection="HPbCIN",dos_projection="HPbCIN")
#projected_plots_dots = bsplotterprojected.get_projected_plots_dots({'Pb':['s','p'],'I':['s','p']})
elements = bsplotterprojected.get_elt_projected_plots(vbm_cbm_marker=True)
    v = BSVasprun("./vasprun.xml", parse_projected_eigen=True)
    bs = v.get_band_structure(line_mode=True)
    #print (bs.is_metal())
    #print (bs.get_band_gap())
    #print (bs.get_direct_band_gap())

    #print (bs.get_projections_on_elements_and_orbitals({'As':['s','p','d']}))
    #promenade = HighSymmKpath.get_kpoints
    #print promenade
    #get_kpoints(bs,line_density=20, coords_are_cartesian=True)
    BSPlotter(bs).show()

    #BSPlotter(bs).plot_brillouin()
    #BSPlotter(bs).save_plot(filename="normal-bandstructure.pdf",img_format="pdf",zero_to_efermi=True)

    bsproj = BSPlotterProjected(bs).get_projected_plots_dots_patom_pmorb(
        dictio={'As': ['px', 'py', 'pz']},
        dictpa={'As': [5, 6, 7, 8]},
        sum_atoms={'As': [5, 6, 7, 8]},
        sum_morbs={'As': ['px', 'py', 'pz']})
    bsproj.show()

    # trying new things here

    #bandstruct = BSDOSPlotter(bs_projection="As", dos_projection=None, vb_energy_range=2, cb_energy_range=2, egrid_interval=0.5, rgb_legend=True)

    #BSDOSPlotterProjected(bandstruct)

    # #plt.show()
    # plt.savefig(sys.argv[1] + ".pdf", format="pdf")
Example #21
0
#!/bin/env python3
"""Alexandre Olivieri ([email protected])

Simple plot generation from the vasprun.xml and KPOINTS files."""

from pymatgen.io.vasp import BSVasprun
from pymatgen.electronic_structure.plotter import BSPlotterProjected
from matplotlib import pyplot as plt

VRUN = BSVasprun('vasprun.xml', parse_projected_eigen=True)
BS = VRUN.get_band_structure(kpoints_filename='KPOINTS', line_mode=True)
BANDPLOTTER = BSPlotterProjected(BS)
plot = BANDPLOTTER.get_projected_plots_dots_patom_pmorb(
        {'O':['p'], 'Nb':['dyz', 'dx2', 'dz2']},
        {'O':['all'], 'Nb':['all']},
        sum_atoms={'O':['all'], 'Nb':['all']},
        sum_morbs={'O':['p']},
        num_column=3
)
plot.savefig('bandstructure.pdf', dpi=1000)
Example #22
0
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()