Skip to content

Commit

Permalink
Fixed issue where dispersion plot wasn't showing when switching to a …
Browse files Browse the repository at this point in the history
…diatomic chain.
  • Loading branch information
Taylor-96 committed Jun 17, 2024
1 parent c77e74a commit 1aede50
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
12 changes: 8 additions & 4 deletions notebook/lattice-vibration/NGLTrajectoryClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ase.io.trajectory import Trajectory
from sympy import *
from NGLUtilsClass import NGLWidgets
from ipywidgets import Output
from ipywidgets import Output, AppLayout
import sys
sys.stdout = open('/dev/stdout', 'w')

Expand Down Expand Up @@ -62,10 +62,12 @@ def __init__(self, trajectory):
value="monoatomic",
disabled=False,
)
self.button_chain.observe(self.show_slider_M, "value")
self.button_chain.observe(self.compute_dispersion, "value")
self.button_chain.observe(self.compute_trajectory_1D, "value")

self.button_chain.observe(self.band_dispersion, "value")
self.button_chain.observe(self.show_slider_M, "value")


# Output to show slider_M
self.output_ratio = widgets.Output()
Expand Down Expand Up @@ -526,7 +528,6 @@ def onclick(self, event):
self.x = event.xdata
self.y = event.ydata


"""
Determine frequency and k point upon click on band dispersion figure
"""
Expand Down Expand Up @@ -588,4 +589,7 @@ def show_slider_M(self, *args):
self.output_ratio.clear_output()
elif self.button_chain.value == "diatomic":
with self.output_ratio:
display(widgets.HBox([self.slider_M_description, self.slider_M]))
full_layout= AppLayout(left_sidebar=widgets.HBox([self.slider_M_description,self.slider_M]))

display(full_layout)
#display(widgets.HBox([self.slider_M_description, self.slider_M]))
78 changes: 56 additions & 22 deletions notebook/lattice-vibration/Phonon_1D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ff2fca2da3f648a48d4eced11b3509ef",
"model_id": "f0b65bc10a6f44ff9a4160c1703cb6b9",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -106,20 +106,7 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'target_k' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m traj\u001b[38;5;241m=\u001b[39mTrajectory(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdummy.traj\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 2\u001b[0m traj\u001b[38;5;241m.\u001b[39mwrite(Atoms(\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mC\u001b[39m\u001b[38;5;124m'\u001b[39m,[[\u001b[38;5;241m0\u001b[39m,\u001b[38;5;241m0\u001b[39m,\u001b[38;5;241m0\u001b[39m],[\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m1\u001b[39m]]))\n\u001b[0;32m----> 3\u001b[0m handler\u001b[38;5;241m=\u001b[39m\u001b[43mNGLTrajectory\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtrajectory\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mTrajectory\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mdummy.traj\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4\u001b[0m handler\u001b[38;5;241m.\u001b[39mview\u001b[38;5;241m.\u001b[39mstage\u001b[38;5;241m.\u001b[39mset_parameters(mouse_preset\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpymol\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 6\u001b[0m handler\u001b[38;5;241m.\u001b[39mview\u001b[38;5;241m.\u001b[39m_js(\u001b[38;5;124m\"\"\"\u001b[39m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;124mthis.mouseOverDisplay(\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mblock\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m)\u001b[39m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;124mvar container = this.stage.viewer.container\u001b[39m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;124m }, false);\u001b[39m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;124m\"\"\"\u001b[39m)\n",
"File \u001b[0;32m~/osscar_ssh_v2/quantum-mechanics/notebook/lattice-vibration/NGLTrajectoryClass.py:79\u001b[0m, in \u001b[0;36mNGLTrajectory.__init__\u001b[0;34m(self, trajectory)\u001b[0m\n\u001b[1;32m 77\u001b[0m \u001b[38;5;66;03m#target_k=np.pi/2\u001b[39;00m\n\u001b[1;32m 78\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mka_array \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mlinspace(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m2\u001b[39m \u001b[38;5;241m*\u001b[39m np\u001b[38;5;241m.\u001b[39mpi, \u001b[38;5;241m2\u001b[39m \u001b[38;5;241m*\u001b[39m np\u001b[38;5;241m.\u001b[39mpi, \u001b[38;5;241m101\u001b[39m)\n\u001b[0;32m---> 79\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39midx \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[38;5;241m101\u001b[39m\u001b[38;5;241m*\u001b[39m(\u001b[43mtarget_k\u001b[49m\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39mnp\u001b[38;5;241m.\u001b[39mpi)\u001b[38;5;241m/\u001b[39m(\u001b[38;5;241m4\u001b[39m\u001b[38;5;241m*\u001b[39mnp\u001b[38;5;241m.\u001b[39mpi)) \u001b[38;5;66;03m# idx corresponding to ka=0\u001b[39;00m\n\u001b[1;32m 80\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39midx \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m50\u001b[39m \u001b[38;5;66;03m# idx corresponding to ka=0\u001b[39;00m\n\u001b[1;32m 81\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptic \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n",
"\u001b[0;31mNameError\u001b[0m: name 'target_k' is not defined"
]
}
],
"outputs": [],
"source": [
"traj=Trajectory('dummy.traj','w')\n",
"traj.write(Atoms(2*'C',[[0,0,0],[1,1,1]]))\n",
Expand Down Expand Up @@ -176,9 +163,10 @@
"chain= HBox([handler.button_chain_description,handler.button_chain])\n",
"mass_ratio=handler.output_ratio\n",
"click=HTMLMath(value='''Click on the plot to get the corresponding phonon''')\n",
"phonon = HBox(\n",
" [VBox([chain,mass_ratio]), VBox([click,handler.fig.canvas])]\n",
")\n",
"# phonon = HBox(\n",
"# [VBox([chain,mass_ratio]), VBox([click,handler.fig.canvas])]\n",
"# )\n",
"phonon= AppLayout(left_sidebar=VBox([chain,mass_ratio]),center=VBox([click,handler.fig.canvas]),right=None)\n",
"\n",
"camera_orientation=HBox([handler.camera_orientation_description,handler.output_camera_position])\n",
"camera_text_orientation=handler.text_orientation\n",
Expand Down Expand Up @@ -241,9 +229,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
".box_style{\n",
" border : 2px solid red;\n",
"}\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"<style>\n",
Expand All @@ -255,11 +260,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "546ceb73714c49eda44588698ece25b7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Tab(children=(HBox(children=(VBox(children=(HBox(children=(HTMLMath(value='Atomic chain type', …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "54e9045ba2714f91b1b621812b162fb5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(NGLWidget(max_frame=50),), layout=Layout(align_items='center', display='flex', flex_flow='colum…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(actions,HBox([handler.view],layout=layout).add_class(\"box_style\"))\n",
"stop = False\n",
Expand Down

0 comments on commit 1aede50

Please sign in to comment.