Skip to content

Commit

Permalink
adapt to latest mc-react-bands; cleaner interface; bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Apr 10, 2024
1 parent 57b5fd0 commit 63ea071
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 44 deletions.
34 changes: 16 additions & 18 deletions examples/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@
"outputs": [],
"source": [
"w1 = BandsPlotWidget(\n",
" bands=[si_bands],\n",
" dos=si_dos,\n",
" plot_fermilevel = True,\n",
" show_legend = True,\n",
" energy_range = {\"ymin\": -10.0, \"ymax\": 10.0})\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",
"display(w1)"
]
},
Expand All @@ -80,9 +83,7 @@
"w2 = BandsPlotWidget(\n",
" bands=[co_bands],\n",
" dos=co_dos,\n",
" plot_fermilevel = True,\n",
" show_legend = True,\n",
" energy_range = {\"ymin\": -10.0, \"ymax\": 10.0},\n",
" energy_range = [-10.0, 10.0],\n",
" bands_color = [[\"red\", \"blue\"]])\n",
"display(w2)"
]
Expand All @@ -102,9 +103,8 @@
"source": [
"w3 = BandsPlotWidget(\n",
" dos=co_dos,\n",
" plot_fermilevel = True,\n",
" show_legend = True,\n",
" energy_range = {\"ymin\": -10.0, \"ymax\": 10.0})\n",
" energy_range = [-10.0, 10.0]\n",
")\n",
"display(w3)"
]
},
Expand All @@ -123,9 +123,8 @@
"source": [
"w4 = BandsPlotWidget(\n",
" bands=[si_bands],\n",
" plot_fermilevel = True,\n",
" show_legend = True,\n",
" energy_range = {\"ymin\": -10.0, \"ymax\": 10.0})\n",
" energy_range = [-10.0, 10.0]\n",
")\n",
"display(w4)"
]
},
Expand All @@ -145,10 +144,9 @@
"w5 = BandsPlotWidget(\n",
" bands=[si_bands, si_bands_shifted],\n",
" dos=si_dos,\n",
" plot_fermilevel = True,\n",
" show_legend = True,\n",
" energy_range = {\"ymin\": -10.0, \"ymax\": 10.0},\n",
" bands_color=['red', 'yellow'])\n",
" energy_range = [-10.0, 10.0],\n",
" bands_color=['red', 'yellow']\n",
")\n",
"display(w5)"
]
},
Expand Down
24 changes: 12 additions & 12 deletions js/widget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ function isEmptyList(list) {
}

const render = createRender(() => {
const [bandsDatalist, setBandsDatalist] = useModelState("bands");
const [bandsDataList, setBandsDataList] = useModelState("bands");
const [dos, setDos] = useModelState("dos");
const [showFermi, setShowFermi] = useModelState("plot_fermilevel");
const [showLegend, setShowLegend] = useModelState("show_legend");
const [yLimit, setYLimit] = useModelState("energy_range");
const [colorInfo, setColorInfo] = useModelState("bands_color");
const [energyRange, setEnergyRange] = useModelState("energy_range");
const [dosRange, setDosRange] = useModelState("dos_range");
const [bandsColorInfo, setBandsColorInfo] = useModelState("bands_color");
const [formatSettings, setFormatSettings] = useModelState("format_settings");

return (
<BandsVisualizer
bandsDataList={bandsDatalist}
dosData={isEmptyObject(dos) ? undefined : dos}
showFermi={showFermi}
showLegend={showLegend}
yLimit={yLimit}
dosRange={[]}
colorInfo={isEmptyList(colorInfo) ? undefined : colorInfo}
bandsDataList={bandsDataList}
dosData={dos}
energyRange={energyRange}
dosRange={dosRange}
bandsColorInfo={bandsColorInfo}
formatSettings={formatSettings}
/>
);
});
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"chart.js": "^4.4.2",
"chartjs-plugin-annotation": "^3.0.1",
"chartjs-plugin-zoom": "^2.0.1",
"mc-react-bands": "^0.4.0",
"mc-react-bands": "^0.5.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
17 changes: 8 additions & 9 deletions src/widget_bandsplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ class BandsPlotWidget(anywidget.AnyWidget):
_esm = pathlib.Path(__file__).parent / "static" / "widget.js"
_css = pathlib.Path(__file__).parent / "static" / "widget.css"

# List of bandstructure data objects
bands = tl.List([]).tag(sync=True)
# DOS data object
dos = tl.Dict().tag(sync=True)
# Visiblity for the Fermi energy level
plot_fermilevel = tl.Bool(False).tag(sync=True)
# The Legend for the density of states
show_legend = tl.Bool(False).tag(sync=True)
# yLimit for the plot
energy_range = tl.Dict({"ymin": -10.0, "ymax": 10.0}).tag(sync=True)
# The colors for bands data
energy_range = tl.List([-10.0, 10.0]).tag(sync=True)
dos_range = tl.List([]).tag(sync=True)
bands_color = tl.List([]).tag(sync=True)

# Formatting settings:
# * showFermi
# * showLegend
# * bandsYlabel
format_settings = tl.Dict({}).tag(sync=True)

def __init__(
self,
**kwargs,
Expand Down

0 comments on commit 63ea071

Please sign in to comment.