{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Unfolding Band Structure\n\nUnfolding Band Structure example.\n\nFirst download the example files with the code below. Then replace data_dir below.\n\n.. code-block::\n   :caption: Downloading example\n\n    supercell_dir = pyprocar.download_example(save_dir='', \n                                material='MgB2',\n                                code='vasp', \n                                spin_calc_type='non-spin-polarized',\n                                calc_type='supercell_bands')\n\n    primitive_dir = pyprocar.download_example(save_dir='', \n                                material='MgB2',\n                                code='vasp', \n                                spin_calc_type='non-spin-polarized',\n                                calc_type='primitive_bands')\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "importing pyprocar and specifying local data_dir\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import os\n\nimport numpy as np\n\nimport pyprocar\n\nsupercell_dir = os.path.join(\n    pyprocar.utils.DATA_DIR,\n    \"examples\",\n    \"MgB2_unfold\",\n    \"vasp\",\n    \"non-spin-polarized\",\n    \"supercell_bands\",\n)\nprimitive_dir = os.path.join(\n    pyprocar.utils.DATA_DIR,\n    \"examples\",\n    \"MgB2_unfold\",\n    \"vasp\",\n    \"non-spin-polarized\",\n    \"primitive_bands\",\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Plotting primitive bands\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pyprocar.bandsplot(\n    code=\"vasp\", mode=\"plain\", fermi=4.993523, elimit=[-15, 5], dirname=primitive_dir\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Unfolding of the supercell bands\n\nHere we do unfolding of the supercell bands. In this calculation,\nthe POSCAR and KPOINTS will be different from the primitive cell\nFor the POSCAR, we create a 2 2 2 supercell from the primitive.\nFor the KPOINTS, the paths need to be changed to reflect the change in the unitcell\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pyprocar.unfold(\n    code=\"vasp\",\n    mode=\"plain\",\n    unfold_mode=\"both\",\n    fermi=5.033090,\n    dirname=supercell_dir,\n    elimit=[-15, 5],\n    supercell_matrix=np.diag([2, 2, 2]),\n)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.20"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}