{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Example of kpath_generator \n\nIn order to plot a band structure, one must define a set of $k$-points following a desired $k$-path in momentum space. \nPyProcar's $k$-path generation utility enables a the user to automatically generate \na suitable and sufficient $k$-path given the crystal structure, typically read from the POSCAR file (VASP). \n\n\n.. code-block::\n   :caption: General Format\n\n   pyprocar.kpath(infile, outfile, grid-size, with-time-reversal, recipe, threshold, symprec, angle-tolerance,supercell_matrix)\n\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    data_dir = pyprocar.download_example(save_dir='', \n                                material='Fe',\n                                code='vasp', \n                                spin_calc_type='non-spin-polarized',\n                                calc_type='bands')\n\nThis information is automatically written to a KPOINTS file. The retrieved $k$-path can be used for other DFT codes with slight modifications.\n\nMore details regarding these parameters can be found in the [SeeK-path manual](https://seekpath.readthedocs.io/en/latest/module_guide/index.html).\nThe $k$-path generation utility within PyProcar is based on the Python library **seekpath** developed by Hinuma et al::\n\n        Y. Hinuma, G. Pizzi, Y. Kumagai, F. Oba, I. Tanaka, Band structure diagram paths based on crystallography, Computational Materials Science 128 (2017) 140\u2013184.doi:10.1016/j.commatsci.2016.10.015.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# sphinx_gallery_thumbnail_number = 1"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Plotting K Path\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pyvista\n\n# You do not need this. This is to ensure an image is rendered off screen when generating exmaple gallery.\npyvista.OFF_SCREEN = True"
      ]
    },
    {
      "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\ndata_dir = os.path.join(\n    pyprocar.utils.DATA_DIR,\n    \"examples\",\n    \"Fe\",\n    \"vasp\",\n    \"spin-polarized-colinear\",\n    \"bands\",\n)\n\nposcar = os.path.join(data_dir, \"POSCAR\")\n\nk_path, k_labels = pyprocar.kpath(\n    poscar, \"KPOINTS\", 40, True, \"hpkot\", 1e-07, 1e-05, -1.0, np.eye(3)\n)\n\n\n# Getting unique points for plotting\nunique_labels = []\nunique_kpath = []\nfor i, k_label in enumerate(k_labels):\n    if k_label not in unique_labels:\n        unique_labels.append(k_label)\n        unique_kpath.append(k_path[i])\n\n\nplotter = pyvista.Plotter()\n\n# plotting connecting lines\nfor ik, points in enumerate(k_path):\n    if ik == len(k_path) - 1:\n        plotter.add_lines(np.array([k_path[ik - 1], k_path[ik]]), color=\"red\", width=10)\n    else:\n        plotter.add_lines(np.array([k_path[ik], k_path[ik + 1]]), color=\"red\", width=10)\n\n# plotting points and labels\nplotter.add_point_labels(\n    unique_kpath,\n    unique_labels,\n    point_color=\"blue\",\n    text_color=\"blue\",\n    render_points_as_spheres=True,\n    point_size=20,\n    font_size=36,\n    always_visible=True,\n)\nplotter.show_axes()\nplotter.show_grid()\nplotter.view_yz()\nplotter.show()"
      ]
    }
  ],
  "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
}