Skip to content

Commit

Permalink
update bandsplot notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Dou Du committed Jun 6, 2024
1 parent f1e01c0 commit 1af8153
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 284 deletions.
57 changes: 34 additions & 23 deletions widgets/.ipynb_checkpoints/widget_bandsplot-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# **A Jupyter widget to plot the bandstructure and density of states (DOS)**\n",
"\n",
"**Source code**: https://github.com/aiidalab/widget-bandsplot\n",
"**Source code**: [https://github.com/aiidalab/widget-bandsplot](https://github.com/aiidalab/widget-bandsplot) \n",
"\n",
"<hr style=\"height:1px;border:none;color:#cccccc;background-color:#cccccc;\" />"
]
Expand All @@ -19,13 +19,6 @@
" This widget facilitates the plotting of electronic bandstructure and density of states from supplied json files.\n",
"</p>\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",
Expand All @@ -44,8 +37,8 @@
" 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/Si_pdos_data.json\">\n",
"https://raw.githubusercontent.com/osscar-org/widget-bandsplot/develop/example/Si_pdos_data.json</a>\n",
"<a href=\"https://github.com/osscar-org/widget-bandsplot/blob/main/example/data/Si_dos.json\">\n",
"https://github.com/osscar-org/widget-bandsplot/blob/main/example/data/Si_dos.json</a>\n",
"\n",
"<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",
Expand Down Expand Up @@ -94,7 +87,7 @@
},
"outputs": [],
"source": [
"from widget_bandsplot import *\n",
"from widget_bandsplot import BandsPlotWidget\n",
"import json\n",
"from copy import deepcopy"
]
Expand All @@ -107,11 +100,14 @@
},
"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)"
"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(\"./Si_bands.json\")\n",
"si_dos = load_file(\"./Si_dos.json\")\n"
]
},
{
Expand All @@ -122,16 +118,31 @@
},
"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)"
"widget = 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",
"\n",
"display(widget)"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"```{image} ./images/bands.png\n",
":alt: image bandstructure\n",
":class: bg-primary mb-1\n",
":width: 800px\n",
":height: 500px\n",
":align: center\n",
"```"
]
}
],
"metadata": {
Expand All @@ -150,7 +161,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.11.5"
},
"voila": {
"authors": "Dou Du and Giovanni Pizzi"
Expand Down
139 changes: 19 additions & 120 deletions widgets/.ipynb_checkpoints/widget_periodictable-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"# `widget-periodictable`: A Jupyter Widget to Create Interactive Periodic Table\n",
"\n",
"**Source code**:https://github.com/osscar-org/widget-periodictable\n",
"**Source code**:[https://github.com/osscar-org/widget-periodictable](https://github.com/osscar-org/widget-periodictable) \n",
"\n",
"**Introduction**: The periodic table is an important tool for chemistry and physics \n",
"education and research. This is a Jupyter widget to create an interactive periodic \n",
Expand Down Expand Up @@ -47,7 +47,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -71,24 +71,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c59bf12be17a454c89589d7b154857dc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"PTableWidget(allElements=['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', '…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"widget = PTableWidget(states = 3, selected_elements = {\"C\": 0, \"Si\": 1, \"Ge\": 2}, \n",
" selected_colors = ['red', 'green', 'blue'], \n",
Expand All @@ -111,7 +96,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -128,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -144,20 +129,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['La', 'Nd']"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"widget.get_elements_by_state(0)"
]
Expand All @@ -178,24 +152,9 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f658caea21644cbba8d8c05a099079d5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Button(button_style='success', description='Get the currently selected values', layout=Layout(w…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"output = widgets.Output()\n",
"\n",
Expand Down Expand Up @@ -225,24 +184,9 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1b169901f3fd42b59182d7772e0f0384",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Checkbox(value=False, description='Disable oxygen')"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"toggle_disabled = widgets.Checkbox(\n",
" value=\"O\" in widget.disabled_elements,\n",
Expand Down Expand Up @@ -277,24 +221,9 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fc3d79d12d76454a8250a602de665f81",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Checkbox(value=False, description='Freeze periodic table:')"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"toggle_freeze = widgets.Checkbox(\n",
" value= False,\n",
Expand All @@ -321,24 +250,9 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f29cb7d4e8fc49ed9aefc9e1ae8761d6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(button_style='success', description='Select only Li and H (from python)', layout=Layout(width='300px'),…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"def on_set_from_python(event):\n",
" # NOTE! If you put an element which does not exist, it will stay forever in the list, but it's ignored\n",
Expand All @@ -364,24 +278,9 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b61605d0b08345f19f8344d3761b9677",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(button_style='success', description='Make noble gases bold', layout=Layout(width='300px'), style=Button…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"def get_noble_gases_state():\n",
" label_deactivate = \"Make noble gases bold\"\n",
Expand Down Expand Up @@ -444,7 +343,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.11.5"
},
"voila": {
"authors": "Dou Du, Casper Welzel Andersen and Giovanni Pizzi"
Expand Down
Loading

0 comments on commit 1af8153

Please sign in to comment.