Skip to content

Commit

Permalink
update the example notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Dou Du committed Jun 13, 2024
1 parent 9070fee commit 5e1535d
Showing 1 changed file with 102 additions and 72 deletions.
174 changes: 102 additions & 72 deletions example/example.ipynb
Original file line number Diff line number Diff line change
@@ -1,15 +1,83 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"source": [
"# **A Jupyter widget to plot the bandstructure and density of states (DOS)**\n",
"\n",
"<hr style=\"height:1px;border:none;color:#cccccc;background-color:#cccccc;\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"# This cell is only needed for development.\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"%env ANYWIDGET_HMR=1"
"<p style=\"text-align: justify;font-size:15px\">\n",
" This is a Jupyter widget, which plots the bandstructure and density of states from given json files.\n",
"</p>\n",
"\n",
"## **Input json files**\n",
"\n",
"<p style=\"text-align: justify;font-size:15px\">\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",
"</p>\n",
"\n",
"```bash\n",
"verdi data bands export --format json <IDENTIFIER>\n",
"```\n",
"\n",
"<p style=\"text-align: justify;font-size:15px\">\n",
" The json format for the DOS can be checked in the github repository.\n",
"</p>\n",
"\n",
"<a href=\"https://raw.githubusercontent.com/osscar-org/widget-bandsplot/develop/example/data/Si_dos.json\">\n",
"https://raw.githubusercontent.com/osscar-org/widget-bandsplot/develop/example/data/Si_dos.json</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"paramsparams<p style=\"text-align: justify;font-size:15px\">\n",
" Here, one needs to use the json package to load the json file and pass it to the widget.\n",
"</p>\n",
"\n",
"```python\n",
"with open('./data/Si_bands.json', 'r') as file:\n",
" band_Si = json.load(file)\n",
" \n",
"with open('./data/Si_dos.json', 'r') as file:\n",
" dos_Si = json.load(file)\n",
"```\n",
"\n",
"## **Fermi energy**\n",
"\n",
"<p style=\"text-align: justify;font-size:15px\">\n",
" The Fermi energy is reading from the bands and DOS json files. And bandstructure and density \n",
" of states plots are aligned to the Fermi energy (shift the Fermi energy to zero).\n",
"</p>\n",
"\n",
"<p style=\"text-align: justify;font-size:15px\">\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 set show_legend = False.\n",
"</p>\n",
"\n",
"## **Usage of the widget**\n",
"\n",
"<p style=\"text-align: justify;font-size:15px\">\n",
" Remeber to pass the bandstructure data as a list of json objects. \"energy_range\" sets the \n",
" energy range for the plots.\n",
"</p>\n",
"\n",
"### **Plot both bandstructure and DOS**\n",
"```python\n",
"w1 = BandsPlotWidget(bands=[band_Si], dos=dos_Si, plot_fermilevel = True, energy_range = {\"ymin\": -10.0, \"ymax\": 10.0})\n",
"display(w1)\n",
"```"
]
},
{
Expand All @@ -18,17 +86,9 @@
"metadata": {},
"outputs": [],
"source": [
"from widget_bandsplot import BandsPlotWidget\n",
"import json\n",
"\n",
"def load_file(filename):\n",
" with open(filename, 'r') as fhandle:\n",
" return json.load(fhandle)\n",
"\n",
"si_bands = load_file(\"./data/Si_bands.json\")\n",
"si_dos = load_file(\"./data/Si_dos.json\")\n",
"co_bands = load_file(\"./data/Co_bands.json\")\n",
"co_dos = load_file(\"./data/Co_dos.json\")\n",
"si_bands_shifted = load_file(\"./data/Si_bands_Shifted.json\")"
"from copy import deepcopy"
]
},
{
Expand All @@ -37,16 +97,27 @@
"metadata": {},
"outputs": [],
"source": [
"from widget_bandsplot import BandsPlotWidget\n",
"# Note: the widget might not work in the vscode jupyter visualizer\n",
"# Jupyter notebook and lab seem to work fine."
"with open('./data/Si_bands.json', 'r') as file:\n",
" band_Si = json.load(file)\n",
" \n",
"with open('./data/Si_dos.json', 'r') as file:\n",
" dos_Si = json.load(file)\n",
" \n",
"with open('./data/Co_bands.json', 'r') as file:\n",
" band_Co = json.load(file)\n",
" \n",
"with open('./data/Co_dos.json', 'r') as file:\n",
" dos_Co = json.load(file)\n",
" \n",
"with open('./data/Si_bands_Shifted.json', 'r') as file:\n",
" band_Si_shifted = json.load(file)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot Si bandstructure and density of states"
"## Plot the Si bandstructure and density of states"
]
},
{
Expand All @@ -55,23 +126,15 @@
"metadata": {},
"outputs": [],
"source": [
"w1 = BandsPlotWidget(\n",
" bands = [si_bands],\n",
" dos = si_dos,\n",
" energy_range = [-8.0, 8.0],\n",
" format_settings = {\n",
" \"showFermi\": True,\n",
" \"showLegend\": True,\n",
" }\n",
")\n",
"w1 = BandsPlotWidget(bands=[band_Si], dos=dos_Si, plot_fermilevel = True, show_legend = True, energy_range = [-10.0, 10.0])\n",
"display(w1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot Co bandstructure and density of states (spin polarized)"
"## Plot the Co bandstructure and density of states (spin polarized)"
]
},
{
Expand All @@ -80,11 +143,7 @@
"metadata": {},
"outputs": [],
"source": [
"w2 = BandsPlotWidget(\n",
" bands=[co_bands],\n",
" dos=co_dos,\n",
" energy_range = [-10.0, 10.0],\n",
" bands_color = [[\"red\", \"blue\"]])\n",
"w2 = BandsPlotWidget(bands=[band_Co], dos=dos_Co, plot_fermilevel = True, show_legend = True, energy_range = [-10.0, 10.0], bands_color = [[\"red\", \"blue\"]])\n",
"display(w2)"
]
},
Expand All @@ -101,10 +160,7 @@
"metadata": {},
"outputs": [],
"source": [
"w3 = BandsPlotWidget(\n",
" dos=co_dos,\n",
" energy_range = [-10.0, 10.0]\n",
")\n",
"w3 = BandsPlotWidget(dos=dos_Co, plot_fermilevel = True, show_legend = True, energy_range = [-10,10])\n",
"display(w3)"
]
},
Expand All @@ -121,18 +177,15 @@
"metadata": {},
"outputs": [],
"source": [
"w4 = BandsPlotWidget(\n",
" bands=[si_bands],\n",
" energy_range = [-10.0, 10.0]\n",
")\n",
"w4 = BandsPlotWidget(bands=[band_Si], plot_fermilevel = True, show_legend = True, energy_range = [-10.0, 10.0])\n",
"display(w4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot two bandstructures"
"## Plot two bandstructure data"
]
},
{
Expand All @@ -141,36 +194,10 @@
"metadata": {},
"outputs": [],
"source": [
"w5 = BandsPlotWidget(\n",
" bands=[si_bands, si_bands_shifted],\n",
" dos=si_dos,\n",
" energy_range = [-10.0, 10.0],\n",
" bands_color=['red', 'yellow']\n",
")\n",
"w5 = BandsPlotWidget(bands=[band_Si, band_Si_shifted], dos=dos_Si, plot_fermilevel = True, show_legend = True, energy_range = [-10.0, 10.0], bands_color=['red', 'yellow'])\n",
"display(w5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -196,6 +223,9 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
},
"voila": {
"authors": "Dou Du and Giovanni Pizzi"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 5e1535d

Please sign in to comment.