From 97deb91f843b666a57651a22c7fa2b2429e82c18 Mon Sep 17 00:00:00 2001 From: Taylor Date: Mon, 20 May 2024 10:42:00 +0200 Subject: [PATCH] Merged textual changes from phonon1d branch. Set default k-point away from gamma in a way that works with workaround for voila. Made arrows a bit smaller. --- .../lattice-vibration/NGLTrajectoryClass.py | 15 +-- notebook/lattice-vibration/NGLUtilsClass.py | 2 +- notebook/lattice-vibration/Phonon_1D.ipynb | 115 ++++++------------ 3 files changed, 43 insertions(+), 89 deletions(-) diff --git a/notebook/lattice-vibration/NGLTrajectoryClass.py b/notebook/lattice-vibration/NGLTrajectoryClass.py index c44f385..ec1fec4 100644 --- a/notebook/lattice-vibration/NGLTrajectoryClass.py +++ b/notebook/lattice-vibration/NGLTrajectoryClass.py @@ -22,7 +22,7 @@ def __init__(self, trajectory): r"Oscillations amplitude", layout=self.layout_description ) self.slider_amplitude = widgets.FloatSlider( - value=0.12, + value=0.04, min=0.01, max=0.24, step=0.01, @@ -70,13 +70,14 @@ def __init__(self, trajectory): # Output to show slider_M self.output_ratio = widgets.Output() - # Point is initialized at (0,0), and in acoustic mode + # Point is initialized at x=pi/2 and in acoustic mode self.x = 0 self.y = 0 self.ka = 0 - #target_k=np.pi/2 + target_k=np.pi/2 self.ka_array = np.linspace(-2 * np.pi, 2 * np.pi, 101) - self.idx = 50 # idx corresponding to ka=0 + self.idx = int(101*(target_k+2*np.pi)/(4*np.pi)) # idx corresponding to ka=0 + #self.idx = 50 # idx corresponding to ka=0 self.optic = False self.init_delay = 20 @@ -469,7 +470,7 @@ def band_dispersion(self, *args): self.x=np.pi/2 self.idx = (np.abs(self.ka_array - self.x)).argmin() self.ka = self.ka_array[self.idx] - + self.y=self.ka w = self.w[self.idx] self.point.set_data((self.ka, w)) @@ -519,8 +520,8 @@ def band_dispersion(self, *args): def onclick(self, event): if event==None: - self.x=0.0 - self.y=0.0 + self.x=self.x + self.y=self.y else: self.x = event.xdata self.y = event.ydata diff --git a/notebook/lattice-vibration/NGLUtilsClass.py b/notebook/lattice-vibration/NGLUtilsClass.py index 243c7c7..38c9b9b 100644 --- a/notebook/lattice-vibration/NGLUtilsClass.py +++ b/notebook/lattice-vibration/NGLUtilsClass.py @@ -477,7 +477,7 @@ def on_orientation_change(self, *args): with self.output_camera_position: self.output_camera_position.clear_output() position = [round(x, 1) for x in self.view._camera_orientation] - print(position) + #print(position) def change_camera_position(self, *args): """ diff --git a/notebook/lattice-vibration/Phonon_1D.ipynb b/notebook/lattice-vibration/Phonon_1D.ipynb index aa3d72f..a30d9a3 100644 --- a/notebook/lattice-vibration/Phonon_1D.ipynb +++ b/notebook/lattice-vibration/Phonon_1D.ipynb @@ -70,9 +70,22 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ff2fca2da3f648a48d4eced11b3509ef", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib widget\n", @@ -91,9 +104,22 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "metadata": {}, - "outputs": [], + "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" + ] + } + ], "source": [ "traj=Trajectory('dummy.traj','w')\n", "traj.write(Atoms(2*'C',[[0,0,0],[1,1,1]]))\n", @@ -215,26 +241,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "%%html\n", "