
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples\05-other\plot_ebs.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_05-other_plot_ebs.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_05-other_plot_ebs.py:


.. _ref_example_ebs:

Example of finding the bandgap
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ElectronicBandStructure is used to handle the information 
related to the electronic band structure.

.. code-block::
   :caption: General Format

   import pyprocar
   pyprocar.io.Parser(code="vasp", dir=data_dir)

.. code-block::
   :caption: Downloading example

    data_dir = pyprocar.download_example(save_dir='', 
                                material='Fe',
                                code='vasp', 
                                spin_calc_type='non-spin-polarized',
                                calc_type='bands')

.. GENERATED FROM PYTHON SOURCE LINES 26-35

.. code-block:: Python


    # sphinx_gallery_thumbnail_number = 1

    import pyvista as pv

    # You do not need this. This is to ensure an image is rendered off screen when generating exmaple gallery.
    pv.OFF_SCREEN = True









.. GENERATED FROM PYTHON SOURCE LINES 36-37

importing pyprocar and specify the local data_dir

.. GENERATED FROM PYTHON SOURCE LINES 37-48

.. code-block:: Python


    import os

    import numpy as np

    import pyprocar

    data_dir = os.path.join(
        pyprocar.utils.DATA_DIR, "examples", "Fe", "vasp", "non-spin-polarized", "fermi"
    )








.. GENERATED FROM PYTHON SOURCE LINES 49-50

Initialize the parser object and get the ElectronicBandStructure

.. GENERATED FROM PYTHON SOURCE LINES 50-59

.. code-block:: Python


    parser = pyprocar.io.Parser(code="vasp", dir=data_dir)
    ebs = parser.ebs
    e_fermi = parser.ebs.efermi
    structure = parser.structure
    # Apply symmetry to get a full kmesh
    if structure.rotations is not None:
        ebs.ibz2fbz(structure.rotations)








.. GENERATED FROM PYTHON SOURCE LINES 60-61

You can print the object to see some information about the Band Structure

.. GENERATED FROM PYTHON SOURCE LINES 61-65

.. code-block:: Python


    print(ebs)






.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Enectronic Band Structure     
    ------------------------     
    Total number of kpoints  = 3375
    Total number of bands    = 8
    Total number of atoms    = 1
    Total number of orbitals = 9





.. GENERATED FROM PYTHON SOURCE LINES 66-67

Let's plot the kpoints

.. GENERATED FROM PYTHON SOURCE LINES 67-73

.. code-block:: Python


    p = pv.Plotter()
    p.add_mesh(ebs.kpoints, color="blue", render_points_as_spheres=True)
    p.show()





.. image-sg:: /examples/05-other/images/sphx_glr_plot_ebs_001.png
   :alt: plot ebs
   :srcset: /examples/05-other/images/sphx_glr_plot_ebs_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 74-79

Other properties
+++++++++++++++++++++++++++

Bands
+++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 79-93

.. code-block:: Python

    kpoints = pv.PolyData(ebs.kpoints)
    kpoints["band_0"] = ebs.bands[:, 0, 0]

    p = pv.Plotter()
    p.add_mesh(
        kpoints,
        color="blue",
        scalars="band_0",
        render_points_as_spheres=True,
        point_size=10,
    )
    p.show()





.. image-sg:: /examples/05-other/images/sphx_glr_plot_ebs_002.png
   :alt: plot ebs
   :srcset: /examples/05-other/images/sphx_glr_plot_ebs_002.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 94-96

Projections
+++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 96-109

.. code-block:: Python

    print(f"Electron projected shape: {ebs.projected.shape}")
    kpoints["band_0-atom_0-orbital_5-spin-0"] = ebs.projected[:, 0, 0, 0, 4, 0]

    p = pv.Plotter()
    p.add_mesh(
        kpoints,
        color="blue",
        scalars="band_0-atom_0-orbital_5-spin-0",
        render_points_as_spheres=True,
        point_size=10,
    )
    p.show()




.. image-sg:: /examples/05-other/images/sphx_glr_plot_ebs_003.png
   :alt: plot ebs
   :srcset: /examples/05-other/images/sphx_glr_plot_ebs_003.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Electron projected shape: (3375, 8, 1, 1, 9, 1)




.. GENERATED FROM PYTHON SOURCE LINES 110-112

Gradients
+++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 112-121

.. code-block:: Python

    print(f"Band gradient shape: {ebs.bands_gradient.shape}")
    kpoints["band_0-gradients"] = ebs.bands_gradient[:, 0, 0, :]

    # Use the Glyph filter to generate arrows for the vectors
    arrows = kpoints.glyph(orient="band_0-gradients", scale=False, factor=0.08)
    p = pv.Plotter()
    p.add_mesh(arrows, scalar_bar_args={"title": "band_0-band_velocity"})
    p.show()




.. image-sg:: /examples/05-other/images/sphx_glr_plot_ebs_004.png
   :alt: plot ebs
   :srcset: /examples/05-other/images/sphx_glr_plot_ebs_004.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    ij,uvwabj->uvwabi
    Band gradient shape: (3375, 8, 1, 3)




.. GENERATED FROM PYTHON SOURCE LINES 122-124

Band/Fermi velocities
+++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 124-142

.. code-block:: Python

    print(f"Fermi velocity shape: {ebs.fermi_velocity.shape}")
    print(f"Fermi speed shape: {ebs.fermi_speed.shape}")
    kpoints["band_0-band_velocity"] = ebs.fermi_velocity[:, 0, 0, :]
    kpoints["band_0-band_speed"] = ebs.fermi_speed[:, 0, 0]

    arrows = kpoints.glyph(orient="band_0-band_velocity", scale=False, factor=0.08)
    p = pv.Plotter()
    p.add_mesh(
        kpoints,
        scalars="band_0-band_speed",
        render_points_as_spheres=True,
        point_size=0.1,
        show_scalar_bar=False,
    )
    p.add_mesh(arrows, scalar_bar_args={"title": "band_0-band_velocity"})
    p.show()





.. image-sg:: /examples/05-other/images/sphx_glr_plot_ebs_005.png
   :alt: plot ebs
   :srcset: /examples/05-other/images/sphx_glr_plot_ebs_005.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Fermi velocity shape: (3375, 8, 1, 3)
    Fermi speed shape: (3375, 8, 1)




.. GENERATED FROM PYTHON SOURCE LINES 143-145

Effective mass
+++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 145-160

.. code-block:: Python

    print(
        f"Harmonic average effective mass shape: {ebs.harmonic_average_effective_mass.shape}"
    )
    kpoints["band_0-harmonic_average_effective_mass"] = ebs.harmonic_average_effective_mass[
        :, 0, 0
    ]

    p = pv.Plotter()
    p.add_mesh(
        kpoints,
        scalars="band_0-harmonic_average_effective_mass",
        render_points_as_spheres=True,
        point_size=10,
    )
    p.show()



.. image-sg:: /examples/05-other/images/sphx_glr_plot_ebs_006.png
   :alt: plot ebs
   :srcset: /examples/05-other/images/sphx_glr_plot_ebs_006.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    ij,uvwabcj->uvwabci
    Harmonic average effective mass shape: (3375, 8, 1)





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 2.069 seconds)


.. _sphx_glr_download_examples_05-other_plot_ebs.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_ebs.ipynb <plot_ebs.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_ebs.py <plot_ebs.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_ebs.zip <plot_ebs.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
