Skip to content

Commit 1af8153

Browse files
author
Dou Du
committed
update bandsplot notebook
1 parent f1e01c0 commit 1af8153

4 files changed

+79
-284
lines changed

widgets/.ipynb_checkpoints/widget_bandsplot-checkpoint.ipynb

+34-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# **A Jupyter widget to plot the bandstructure and density of states (DOS)**\n",
88
"\n",
9-
"**Source code**: https://github.com/aiidalab/widget-bandsplot\n",
9+
"**Source code**: [https://github.com/aiidalab/widget-bandsplot](https://github.com/aiidalab/widget-bandsplot) \n",
1010
"\n",
1111
"<hr style=\"height:1px;border:none;color:#cccccc;background-color:#cccccc;\" />"
1212
]
@@ -19,13 +19,6 @@
1919
" This widget facilitates the plotting of electronic bandstructure and density of states from supplied json files.\n",
2020
"</p>\n",
2121
"\n",
22-
"```{image} ./images/bands.png\n",
23-
":alt: image bandstructure\n",
24-
":class: bg-primary mb-1\n",
25-
":width: 800px\n",
26-
":height: 500px\n",
27-
":align: center\n",
28-
"```\n",
2922
"\n",
3023
"\n",
3124
"## **Input json files**\n",
@@ -44,8 +37,8 @@
4437
" The json format for the DOS can be checked in the github repository.\n",
4538
"</p>\n",
4639
"\n",
47-
"<a href=\"https://raw.githubusercontent.com/osscar-org/widget-bandsplot/develop/example/Si_pdos_data.json\">\n",
48-
"https://raw.githubusercontent.com/osscar-org/widget-bandsplot/develop/example/Si_pdos_data.json</a>\n",
40+
"<a href=\"https://github.com/osscar-org/widget-bandsplot/blob/main/example/data/Si_dos.json\">\n",
41+
"https://github.com/osscar-org/widget-bandsplot/blob/main/example/data/Si_dos.json</a>\n",
4942
"\n",
5043
"<p style=\"text-align: justify;font-size:15px\">\n",
5144
" Here, one needs to use the json package to load the json file and pass it to the widget.\n",
@@ -94,7 +87,7 @@
9487
},
9588
"outputs": [],
9689
"source": [
97-
"from widget_bandsplot import *\n",
90+
"from widget_bandsplot import BandsPlotWidget\n",
9891
"import json\n",
9992
"from copy import deepcopy"
10093
]
@@ -107,11 +100,14 @@
107100
},
108101
"outputs": [],
109102
"source": [
110-
"with open('Si_bands.json', 'r') as file:\n",
111-
" data1 = json.load(file)\n",
112-
" \n",
113-
"with open('Si_dos.json', 'r') as file:\n",
114-
" data2 = json.load(file)"
103+
"import json\n",
104+
"\n",
105+
"def load_file(filename):\n",
106+
" with open(filename, 'r') as fhandle:\n",
107+
" return json.load(fhandle)\n",
108+
"\n",
109+
"si_bands = load_file(\"./Si_bands.json\")\n",
110+
"si_dos = load_file(\"./Si_dos.json\")\n"
115111
]
116112
},
117113
{
@@ -122,16 +118,31 @@
122118
},
123119
"outputs": [],
124120
"source": [
125-
"w1 = BandsPlotWidget(bands=[data1], dos=data2, plot_fermilevel = True, show_legend = True, energy_range = {\"ymin\": -13.0, \"ymax\": 10.0})\n",
126-
"display(w1)"
121+
"widget = BandsPlotWidget(\n",
122+
" bands = [si_bands],\n",
123+
" dos = si_dos,\n",
124+
" energy_range = [-8.0, 8.0],\n",
125+
" format_settings = {\n",
126+
" \"showFermi\": True,\n",
127+
" \"showLegend\": True,\n",
128+
" }\n",
129+
")\n",
130+
"\n",
131+
"display(widget)"
127132
]
128133
},
129134
{
130-
"cell_type": "code",
131-
"execution_count": null,
135+
"cell_type": "markdown",
132136
"metadata": {},
133-
"outputs": [],
134-
"source": []
137+
"source": [
138+
"```{image} ./images/bands.png\n",
139+
":alt: image bandstructure\n",
140+
":class: bg-primary mb-1\n",
141+
":width: 800px\n",
142+
":height: 500px\n",
143+
":align: center\n",
144+
"```"
145+
]
135146
}
136147
],
137148
"metadata": {
@@ -150,7 +161,7 @@
150161
"name": "python",
151162
"nbconvert_exporter": "python",
152163
"pygments_lexer": "ipython3",
153-
"version": "3.9.12"
164+
"version": "3.11.5"
154165
},
155166
"voila": {
156167
"authors": "Dou Du and Giovanni Pizzi"

widgets/.ipynb_checkpoints/widget_periodictable-checkpoint.ipynb

+19-120
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"source": [
99
"# `widget-periodictable`: A Jupyter Widget to Create Interactive Periodic Table\n",
1010
"\n",
11-
"**Source code**:https://github.com/osscar-org/widget-periodictable\n",
11+
"**Source code**:[https://github.com/osscar-org/widget-periodictable](https://github.com/osscar-org/widget-periodictable) \n",
1212
"\n",
1313
"**Introduction**: The periodic table is an important tool for chemistry and physics \n",
1414
"education and research. This is a Jupyter widget to create an interactive periodic \n",
@@ -47,7 +47,7 @@
4747
},
4848
{
4949
"cell_type": "code",
50-
"execution_count": 3,
50+
"execution_count": null,
5151
"metadata": {},
5252
"outputs": [],
5353
"source": [
@@ -71,24 +71,9 @@
7171
},
7272
{
7373
"cell_type": "code",
74-
"execution_count": 4,
74+
"execution_count": null,
7575
"metadata": {},
76-
"outputs": [
77-
{
78-
"data": {
79-
"application/vnd.jupyter.widget-view+json": {
80-
"model_id": "c59bf12be17a454c89589d7b154857dc",
81-
"version_major": 2,
82-
"version_minor": 0
83-
},
84-
"text/plain": [
85-
"PTableWidget(allElements=['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', '…"
86-
]
87-
},
88-
"metadata": {},
89-
"output_type": "display_data"
90-
}
91-
],
76+
"outputs": [],
9277
"source": [
9378
"widget = PTableWidget(states = 3, selected_elements = {\"C\": 0, \"Si\": 1, \"Ge\": 2}, \n",
9479
" selected_colors = ['red', 'green', 'blue'], \n",
@@ -111,7 +96,7 @@
11196
},
11297
{
11398
"cell_type": "code",
114-
"execution_count": 5,
99+
"execution_count": null,
115100
"metadata": {},
116101
"outputs": [],
117102
"source": [
@@ -128,7 +113,7 @@
128113
},
129114
{
130115
"cell_type": "code",
131-
"execution_count": 6,
116+
"execution_count": null,
132117
"metadata": {},
133118
"outputs": [],
134119
"source": [
@@ -144,20 +129,9 @@
144129
},
145130
{
146131
"cell_type": "code",
147-
"execution_count": 7,
132+
"execution_count": null,
148133
"metadata": {},
149-
"outputs": [
150-
{
151-
"data": {
152-
"text/plain": [
153-
"['La', 'Nd']"
154-
]
155-
},
156-
"execution_count": 7,
157-
"metadata": {},
158-
"output_type": "execute_result"
159-
}
160-
],
134+
"outputs": [],
161135
"source": [
162136
"widget.get_elements_by_state(0)"
163137
]
@@ -178,24 +152,9 @@
178152
},
179153
{
180154
"cell_type": "code",
181-
"execution_count": 8,
155+
"execution_count": null,
182156
"metadata": {},
183-
"outputs": [
184-
{
185-
"data": {
186-
"application/vnd.jupyter.widget-view+json": {
187-
"model_id": "f658caea21644cbba8d8c05a099079d5",
188-
"version_major": 2,
189-
"version_minor": 0
190-
},
191-
"text/plain": [
192-
"VBox(children=(Button(button_style='success', description='Get the currently selected values', layout=Layout(w…"
193-
]
194-
},
195-
"metadata": {},
196-
"output_type": "display_data"
197-
}
198-
],
157+
"outputs": [],
199158
"source": [
200159
"output = widgets.Output()\n",
201160
"\n",
@@ -225,24 +184,9 @@
225184
},
226185
{
227186
"cell_type": "code",
228-
"execution_count": 9,
187+
"execution_count": null,
229188
"metadata": {},
230-
"outputs": [
231-
{
232-
"data": {
233-
"application/vnd.jupyter.widget-view+json": {
234-
"model_id": "1b169901f3fd42b59182d7772e0f0384",
235-
"version_major": 2,
236-
"version_minor": 0
237-
},
238-
"text/plain": [
239-
"Checkbox(value=False, description='Disable oxygen')"
240-
]
241-
},
242-
"metadata": {},
243-
"output_type": "display_data"
244-
}
245-
],
189+
"outputs": [],
246190
"source": [
247191
"toggle_disabled = widgets.Checkbox(\n",
248192
" value=\"O\" in widget.disabled_elements,\n",
@@ -277,24 +221,9 @@
277221
},
278222
{
279223
"cell_type": "code",
280-
"execution_count": 10,
224+
"execution_count": null,
281225
"metadata": {},
282-
"outputs": [
283-
{
284-
"data": {
285-
"application/vnd.jupyter.widget-view+json": {
286-
"model_id": "fc3d79d12d76454a8250a602de665f81",
287-
"version_major": 2,
288-
"version_minor": 0
289-
},
290-
"text/plain": [
291-
"Checkbox(value=False, description='Freeze periodic table:')"
292-
]
293-
},
294-
"metadata": {},
295-
"output_type": "display_data"
296-
}
297-
],
226+
"outputs": [],
298227
"source": [
299228
"toggle_freeze = widgets.Checkbox(\n",
300229
" value= False,\n",
@@ -321,24 +250,9 @@
321250
},
322251
{
323252
"cell_type": "code",
324-
"execution_count": 11,
253+
"execution_count": null,
325254
"metadata": {},
326-
"outputs": [
327-
{
328-
"data": {
329-
"application/vnd.jupyter.widget-view+json": {
330-
"model_id": "f29cb7d4e8fc49ed9aefc9e1ae8761d6",
331-
"version_major": 2,
332-
"version_minor": 0
333-
},
334-
"text/plain": [
335-
"Button(button_style='success', description='Select only Li and H (from python)', layout=Layout(width='300px'),…"
336-
]
337-
},
338-
"metadata": {},
339-
"output_type": "display_data"
340-
}
341-
],
255+
"outputs": [],
342256
"source": [
343257
"def on_set_from_python(event):\n",
344258
" # NOTE! If you put an element which does not exist, it will stay forever in the list, but it's ignored\n",
@@ -364,24 +278,9 @@
364278
},
365279
{
366280
"cell_type": "code",
367-
"execution_count": 12,
281+
"execution_count": null,
368282
"metadata": {},
369-
"outputs": [
370-
{
371-
"data": {
372-
"application/vnd.jupyter.widget-view+json": {
373-
"model_id": "b61605d0b08345f19f8344d3761b9677",
374-
"version_major": 2,
375-
"version_minor": 0
376-
},
377-
"text/plain": [
378-
"Button(button_style='success', description='Make noble gases bold', layout=Layout(width='300px'), style=Button…"
379-
]
380-
},
381-
"metadata": {},
382-
"output_type": "display_data"
383-
}
384-
],
283+
"outputs": [],
385284
"source": [
386285
"def get_noble_gases_state():\n",
387286
" label_deactivate = \"Make noble gases bold\"\n",
@@ -444,7 +343,7 @@
444343
"name": "python",
445344
"nbconvert_exporter": "python",
446345
"pygments_lexer": "ipython3",
447-
"version": "3.9.7"
346+
"version": "3.11.5"
448347
},
449348
"voila": {
450349
"authors": "Dou Du, Casper Welzel Andersen and Giovanni Pizzi"

0 commit comments

Comments
 (0)