From 1aede50df1962719c4e1cf4f62053e2d111ab193 Mon Sep 17 00:00:00 2001 From: Taylor Date: Mon, 17 Jun 2024 20:18:07 +0200 Subject: [PATCH] Fixed issue where dispersion plot wasn't showing when switching to a diatomic chain. --- .../lattice-vibration/NGLTrajectoryClass.py | 12 ++- notebook/lattice-vibration/Phonon_1D.ipynb | 78 +++++++++++++------ 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/notebook/lattice-vibration/NGLTrajectoryClass.py b/notebook/lattice-vibration/NGLTrajectoryClass.py index ec1fec4..fd47348 100644 --- a/notebook/lattice-vibration/NGLTrajectoryClass.py +++ b/notebook/lattice-vibration/NGLTrajectoryClass.py @@ -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') @@ -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() @@ -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 """ @@ -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])) diff --git a/notebook/lattice-vibration/Phonon_1D.ipynb b/notebook/lattice-vibration/Phonon_1D.ipynb index a30d9a3..27be46f 100644 --- a/notebook/lattice-vibration/Phonon_1D.ipynb +++ b/notebook/lattice-vibration/Phonon_1D.ipynb @@ -76,7 +76,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "ff2fca2da3f648a48d4eced11b3509ef", + "model_id": "f0b65bc10a6f44ff9a4160c1703cb6b9", "version_major": 2, "version_minor": 0 }, @@ -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", @@ -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", @@ -241,9 +229,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "%%html\n", "