{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **A Jupyter widget to plot the bandstructure and density of states (DOS)**\n", "\n", "**Source code**: [https://github.com/aiidalab/widget-bandsplot](https://github.com/aiidalab/widget-bandsplot) \n", "\n", "
\n", " This widget facilitates the plotting of electronic bandstructure and density of states from supplied json files.\n", "
\n", "\n", "```{image} ./images/bands.png\n", ":alt: image bandstructure\n", ":class: bg-primary mb-1\n", ":width: 800px\n", ":height: 500px\n", ":align: center\n", "```\n", "\n", "\n", "## **Input json files**\n", "\n", "\n", " On the left, it plots the bandstructures. One can input several bandstructure json files as a list.\n", " The figure on the right shows the density of states, which can only show one DOS plot. The json files\n", " for the bandstructures can be generated from AiiDA with the verdi command:\n", "
\n", "\n", "```bash\n", "verdi data bands export --format json\n", " The json format for the DOS can be checked in the github repository.\n", "
\n", "\n", "\n", "https://raw.githubusercontent.com/osscar-org/widget-bandsplot/develop/example/Si_pdos_data.json\n", "\n", "\n", " Here, one needs to use the json package to load the json file and pass it to the widget.\n", "
\n", "\n", "```python\n", "with open('Si_bandsdata.json', 'r') as file:\n", " data1 = json.load(file)\n", " \n", "with open('Si_pdos_data.json', 'r') as file:\n", " data2 = json.load(file)\n", "```\n", "\n", "## **Fermi energy**\n", "\n", "\n", " The Fermi energy is read from the bands and DOS json files. The bandstructure and density \n", " of states plots have their origins aligned according to the provided Fermi energy (the Fermi energy is defined to be zero).\n", "
\n", "\n", "\n", " In the default plot for the DOS, there is a horizontal line to highlight the Fermi level. One \n", " can turn it off by setting plot_fermilevel = False. The legend of the DOS can be turned off\n", " by setting show_legend = False.\n", "
\n", "\n", "## **Usage of the widget**\n", "\n", "\n", " Remeber to pass the bandstructure data as a list of json objects. \"energy_range\" sets the \n", " energy range for the plots.\n", "
\n", "\n", "### **Plot both bandstructure and DOS**\n", "```python\n", "w1 = BandsPlotWidget(bands=[data1], dos=data2, plot_fermilevel = True, energy_range = {\"ymin\": -13.0, \"ymax\": 10.0})\n", "display(w1)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "from widget_bandsplot import *\n", "import json\n", "from copy import deepcopy" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "with open('Si_bands.json', 'r') as file:\n", " data1 = json.load(file)\n", " \n", "with open('Si_dos.json', 'r') as file:\n", " data2 = json.load(file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "w1 = BandsPlotWidget(bands=[data1], dos=data2, plot_fermilevel = True, show_legend = True, energy_range = {\"ymin\": -13.0, \"ymax\": 10.0})\n", "display(w1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12" }, "voila": { "authors": "Dou Du and Giovanni Pizzi" } }, "nbformat": 4, "nbformat_minor": 4 }