Skip to content

Commit

Permalink
Merged textual changes from phonon1d branch. Set default k-point away…
Browse files Browse the repository at this point in the history
… from gamma in a way that works with workaround for voila. Made arrows a bit smaller.
  • Loading branch information
Taylor-96 committed May 20, 2024
1 parent b471b03 commit 97deb91
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 89 deletions.
15 changes: 8 additions & 7 deletions notebook/lattice-vibration/NGLTrajectoryClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion notebook/lattice-vibration/NGLUtilsClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
115 changes: 34 additions & 81 deletions notebook/lattice-vibration/Phonon_1D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -215,26 +241,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"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"
}
],
"outputs": [],
"source": [
"%%html\n",
"<style>\n",
Expand All @@ -246,67 +255,11 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d7b84f9985bc41639601a74613eceb9e",
"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": "1ab3a0ba628041beab40ecd5efee8549",
"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"
},
{
"ename": "TypeError",
"evalue": "loop() takes 1 positional argument but 2 were given",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[8], line 18\u001b[0m\n\u001b[1;32m 14\u001b[0m view\u001b[38;5;241m.\u001b[39m_run_on_another_thread(do)\n\u001b[1;32m 17\u001b[0m hv_thread\u001b[38;5;241m=\u001b[39mhandler\u001b[38;5;241m.\u001b[39mview\u001b[38;5;241m.\u001b[39m_run_on_another_thread(init_view)\n\u001b[0;32m---> 18\u001b[0m \u001b[43mloop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43mview\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: loop() takes 1 positional argument but 2 were given"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Exception in thread Thread-10 (init_view):\n",
"Traceback (most recent call last):\n",
" File \"/usr/lib/python3.10/threading.py\", line 1016, in _bootstrap_inner\n",
" self.run()\n",
" File \"/home/taylor/venvs/nb_testing/lib/python3.10/site-packages/ipykernel/ipkernel.py\", line 766, in run_closure\n",
" _threading_Thread_run(self)\n",
" File \"/usr/lib/python3.10/threading.py\", line 953, in run\n",
" self._target(*self._args, **self._kwargs)\n",
" File \"/tmp/ipykernel_27490/1732612826.py\", line 14, in init_view\n",
"NameError: name 'do' is not defined\n"
]
}
],
"outputs": [],
"source": [
"display(actions,HBox([handler.view],layout=layout).add_class(\"box_style\"))\n",
"stop = False\n",
Expand Down

0 comments on commit 97deb91

Please sign in to comment.