
.. 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-33

.. 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 34-35

importing pyprocar and specify the local data_dir

.. GENERATED FROM PYTHON SOURCE LINES 35-43

.. code-block:: Python


    import os
    import numpy as np
    import pyprocar

    data_dir = f"{pyprocar.utils.ROOT}{os.sep}data{os.sep}examples{os.sep}Fe{os.sep}vasp{os.sep}non-spin-polarized{os.sep}fermi"









.. GENERATED FROM PYTHON SOURCE LINES 44-45

Initialize the parser object and get the ElectronicBandStructure 

.. GENERATED FROM PYTHON SOURCE LINES 45-54

.. 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)





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

 .. code-block:: none

    C:\Users\lllang\miniconda3\envs\pyprocar_dev\lib\site-packages\spglib\spglib.py:115: DeprecationWarning: dict interface (SpglibDataset['wyckoffs']) is deprecated.Use attribute interface ({self.__class__.__name__}.{key}) instead
      warnings.warn(




.. GENERATED FROM PYTHON SOURCE LINES 55-56

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

.. GENERATED FROM PYTHON SOURCE LINES 56-60

.. 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 61-62

Let's plot the kpoints

.. GENERATED FROM PYTHON SOURCE LINES 62-68

.. 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 69-74

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

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

.. GENERATED FROM PYTHON SOURCE LINES 74-82

.. 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 83-85

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

.. GENERATED FROM PYTHON SOURCE LINES 85-92

.. code-block:: Python

    print(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

    (3375, 8, 1, 1, 9, 1)




.. GENERATED FROM PYTHON SOURCE LINES 93-95

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

.. GENERATED FROM PYTHON SOURCE LINES 95-104

.. code-block:: Python

    print(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()



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

.. code-block:: pytb

    Traceback (most recent call last):
      File "C:\Users\lllang\Desktop\Current_Projects\pyprocar\examples\05-other\plot_ebs.py", line 99, in <module>
        arrows = kpoints.glyph(orient='band_0-gradients', scale=False, factor=0.08)
      File "C:\Users\lllang\miniconda3\envs\pyprocar_dev\lib\site-packages\pyvista\core\filters\data_set.py", line 2379, in glyph
        dataset.set_active_vectors(orient, preference=prefer)
      File "C:\Users\lllang\miniconda3\envs\pyprocar_dev\lib\site-packages\pyvista\core\dataset.py", line 703, in set_active_vectors
        raise ValueError(
    ValueError: Data field (band_0-gradients) with type (FieldAssociation.POINT) could not be set as the active vectors




.. GENERATED FROM PYTHON SOURCE LINES 105-107

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

.. GENERATED FROM PYTHON SOURCE LINES 107-118

.. code-block:: Python

    print(ebs.fermi_velocity.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()



.. GENERATED FROM PYTHON SOURCE LINES 119-121

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

.. GENERATED FROM PYTHON SOURCE LINES 121-129

.. code-block:: Python

    print(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()




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

   **Total running time of the script:** (0 minutes 1.349 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>`_
