Skip to content

Commit 97deb91

Browse files
committed
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.
1 parent b471b03 commit 97deb91

File tree

3 files changed

+43
-89
lines changed

3 files changed

+43
-89
lines changed

notebook/lattice-vibration/NGLTrajectoryClass.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, trajectory):
2222
r"Oscillations amplitude", layout=self.layout_description
2323
)
2424
self.slider_amplitude = widgets.FloatSlider(
25-
value=0.12,
25+
value=0.04,
2626
min=0.01,
2727
max=0.24,
2828
step=0.01,
@@ -70,13 +70,14 @@ def __init__(self, trajectory):
7070
# Output to show slider_M
7171
self.output_ratio = widgets.Output()
7272

73-
# Point is initialized at (0,0), and in acoustic mode
73+
# Point is initialized at x=pi/2 and in acoustic mode
7474
self.x = 0
7575
self.y = 0
7676
self.ka = 0
77-
#target_k=np.pi/2
77+
target_k=np.pi/2
7878
self.ka_array = np.linspace(-2 * np.pi, 2 * np.pi, 101)
79-
self.idx = 50 # idx corresponding to ka=0
79+
self.idx = int(101*(target_k+2*np.pi)/(4*np.pi)) # idx corresponding to ka=0
80+
#self.idx = 50 # idx corresponding to ka=0
8081
self.optic = False
8182
self.init_delay = 20
8283

@@ -469,7 +470,7 @@ def band_dispersion(self, *args):
469470
self.x=np.pi/2
470471
self.idx = (np.abs(self.ka_array - self.x)).argmin()
471472
self.ka = self.ka_array[self.idx]
472-
473+
self.y=self.ka
473474
w = self.w[self.idx]
474475
self.point.set_data((self.ka, w))
475476

@@ -519,8 +520,8 @@ def band_dispersion(self, *args):
519520
def onclick(self, event):
520521
if event==None:
521522

522-
self.x=0.0
523-
self.y=0.0
523+
self.x=self.x
524+
self.y=self.y
524525
else:
525526
self.x = event.xdata
526527
self.y = event.ydata

notebook/lattice-vibration/NGLUtilsClass.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def on_orientation_change(self, *args):
477477
with self.output_camera_position:
478478
self.output_camera_position.clear_output()
479479
position = [round(x, 1) for x in self.view._camera_orientation]
480-
print(position)
480+
#print(position)
481481

482482
def change_camera_position(self, *args):
483483
"""

notebook/lattice-vibration/Phonon_1D.ipynb

+34-81
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,22 @@
7070
},
7171
{
7272
"cell_type": "code",
73-
"execution_count": 5,
73+
"execution_count": 1,
7474
"metadata": {},
75-
"outputs": [],
75+
"outputs": [
76+
{
77+
"data": {
78+
"application/vnd.jupyter.widget-view+json": {
79+
"model_id": "ff2fca2da3f648a48d4eced11b3509ef",
80+
"version_major": 2,
81+
"version_minor": 0
82+
},
83+
"text/plain": []
84+
},
85+
"metadata": {},
86+
"output_type": "display_data"
87+
}
88+
],
7689
"source": [
7790
"import matplotlib.pyplot as plt\n",
7891
"%matplotlib widget\n",
@@ -91,9 +104,22 @@
91104
},
92105
{
93106
"cell_type": "code",
94-
"execution_count": 6,
107+
"execution_count": 2,
95108
"metadata": {},
96-
"outputs": [],
109+
"outputs": [
110+
{
111+
"ename": "NameError",
112+
"evalue": "name 'target_k' is not defined",
113+
"output_type": "error",
114+
"traceback": [
115+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
116+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
117+
"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",
118+
"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",
119+
"\u001b[0;31mNameError\u001b[0m: name 'target_k' is not defined"
120+
]
121+
}
122+
],
97123
"source": [
98124
"traj=Trajectory('dummy.traj','w')\n",
99125
"traj.write(Atoms(2*'C',[[0,0,0],[1,1,1]]))\n",
@@ -215,26 +241,9 @@
215241
},
216242
{
217243
"cell_type": "code",
218-
"execution_count": 7,
244+
"execution_count": null,
219245
"metadata": {},
220-
"outputs": [
221-
{
222-
"data": {
223-
"text/html": [
224-
"<style>\n",
225-
".box_style{\n",
226-
" border : 2px solid red;\n",
227-
"}\n",
228-
"</style>\n"
229-
],
230-
"text/plain": [
231-
"<IPython.core.display.HTML object>"
232-
]
233-
},
234-
"metadata": {},
235-
"output_type": "display_data"
236-
}
237-
],
246+
"outputs": [],
238247
"source": [
239248
"%%html\n",
240249
"<style>\n",
@@ -246,67 +255,11 @@
246255
},
247256
{
248257
"cell_type": "code",
249-
"execution_count": 8,
258+
"execution_count": null,
250259
"metadata": {
251260
"scrolled": true
252261
},
253-
"outputs": [
254-
{
255-
"data": {
256-
"application/vnd.jupyter.widget-view+json": {
257-
"model_id": "d7b84f9985bc41639601a74613eceb9e",
258-
"version_major": 2,
259-
"version_minor": 0
260-
},
261-
"text/plain": [
262-
"VBox(children=(Tab(children=(HBox(children=(VBox(children=(HBox(children=(HTMLMath(value='Atomic chain type', …"
263-
]
264-
},
265-
"metadata": {},
266-
"output_type": "display_data"
267-
},
268-
{
269-
"data": {
270-
"application/vnd.jupyter.widget-view+json": {
271-
"model_id": "1ab3a0ba628041beab40ecd5efee8549",
272-
"version_major": 2,
273-
"version_minor": 0
274-
},
275-
"text/plain": [
276-
"HBox(children=(NGLWidget(max_frame=50),), layout=Layout(align_items='center', display='flex', flex_flow='colum…"
277-
]
278-
},
279-
"metadata": {},
280-
"output_type": "display_data"
281-
},
282-
{
283-
"ename": "TypeError",
284-
"evalue": "loop() takes 1 positional argument but 2 were given",
285-
"output_type": "error",
286-
"traceback": [
287-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
288-
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
289-
"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",
290-
"\u001b[0;31mTypeError\u001b[0m: loop() takes 1 positional argument but 2 were given"
291-
]
292-
},
293-
{
294-
"name": "stderr",
295-
"output_type": "stream",
296-
"text": [
297-
"Exception in thread Thread-10 (init_view):\n",
298-
"Traceback (most recent call last):\n",
299-
" File \"/usr/lib/python3.10/threading.py\", line 1016, in _bootstrap_inner\n",
300-
" self.run()\n",
301-
" File \"/home/taylor/venvs/nb_testing/lib/python3.10/site-packages/ipykernel/ipkernel.py\", line 766, in run_closure\n",
302-
" _threading_Thread_run(self)\n",
303-
" File \"/usr/lib/python3.10/threading.py\", line 953, in run\n",
304-
" self._target(*self._args, **self._kwargs)\n",
305-
" File \"/tmp/ipykernel_27490/1732612826.py\", line 14, in init_view\n",
306-
"NameError: name 'do' is not defined\n"
307-
]
308-
}
309-
],
262+
"outputs": [],
310263
"source": [
311264
"display(actions,HBox([handler.view],layout=layout).add_class(\"box_style\"))\n",
312265
"stop = False\n",

0 commit comments

Comments
 (0)