Skip to content

Commit

Permalink
Set the default k-point to something more illuminating. Loop by defau…
Browse files Browse the repository at this point in the history
…lt. Reduce arrow size and animation speed.
  • Loading branch information
Taylor-96 committed Oct 8, 2023
1 parent 2345c8b commit 6d6c0ae
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
30 changes: 25 additions & 5 deletions notebook/lattice-vibration/NGLTrajectoryClass.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import numpy as np
import os


import matplotlib.pyplot as plt
import ipywidgets as widgets
from IPython.display import display
from ase import Atoms
from ase.io.trajectory import Trajectory
from sympy import *
from NGLUtilsClass import NGLWidgets
from ipywidgets import Output


class NGLTrajectory(NGLWidgets):
Expand Down Expand Up @@ -68,11 +70,12 @@ def __init__(self, trajectory):
self.output_ratio = widgets.Output()

# Point is initialized at (0,0), and in acoustic mode
self.x = 0
self.y = 0
self.ka = 0
self.x = np.pi/2
self.y = 1
self.ka = 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.optic = False

self.init_delay = 20
Expand Down Expand Up @@ -428,6 +431,7 @@ def initialize_dispersion_plot(self, *args):

# Selected frequency point
(self.point,) = self.ax.plot([], [], ".", c="crimson", markersize=15)
self.point.set_data((np.pi/2, 1)) # default to non-trivial k-point

self.ax.set_xlabel("k")
self.ax.set_ylabel("$\omega$")
Expand Down Expand Up @@ -458,6 +462,15 @@ def band_dispersion(self, *args):
self.lines_op.set_data(([], []))
self.lines_ac_out.set_data(([], []))
self.lines_op_out.set_data(([], []))

# set default k point for monatomic chain
self.x=np.pi/2
self.idx = (np.abs(self.ka_array - self.x)).argmin()
self.ka = self.ka_array[self.idx]

w = self.w[self.idx]
self.point.set_data((self.ka, w))


elif self.button_chain.value == "diatomic":
# Reduce figure width to "half" the size, since x axis is half as big now.
Expand All @@ -480,6 +493,13 @@ def band_dispersion(self, *args):
# Remove monoatomic chain lines
self.lines.set_data(([], []))
self.lines_out.set_data(([], []))

# set default k point for diatomic chain
self.x=np.pi/2
self.idx = (np.abs(self.ka_array - self.x)).argmin()
self.ka = self.ka_array[self.idx]
w= self.w_ac[self.idx]
self.point.set_data((self.ka, w))

# First BZ limit
self.ax.plot([-np.pi, -np.pi], [0, 2.2], "k--", linewidth=1)
Expand All @@ -490,7 +510,7 @@ def band_dispersion(self, *args):
# 2.2 works well for initial height
self.ax.set_ybound(0, 2.2)

self.point.set_data((0, 0))
# set default point on dispersion
self.fig.canvas.mpl_connect("button_press_event", self.onclick)
plt.ion()

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 @@ -95,7 +95,7 @@ def __init__(self, trajectory) -> None:
r"Arrow amplitude", layout=self.layout_description
)
self.slider_amp_arrow = widgets.FloatSlider(
value=2.0,
value=0.5,
min=0.1,
max=5.01,
step=0.1,
Expand Down
39 changes: 26 additions & 13 deletions notebook/lattice-vibration/Phonon_1D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
"3. Visualize the phonon dispersion for a diatomic chain. What is the difference between the acoustic and optical branch at $k=0$ and $k=\\pm\\frac{\\pi}{2a}$ ? How do the atoms displacements relate to frequency ?\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" At $k=0$, in the acoustic branch, as in the monoatomic chain, the atoms do not move. Instead, in the optical branch the two atoms are moving out-of-phase. The latter one has therefore a high frequency.\n",
" At $k=0$, in the acoustic branch, as in the monoatomic chain, the atoms do not move. Instead, in the optical branch the two atoms are moving out-of-phase. The latter therefore has a high frequency.\n",
" \n",
" At $k=\\pm\\frac{\\pi}{2a}$, in the acoustic branch the light atoms stand still whearas the heavier atoms move. In the optical branch, the opposite is observed. Since frequency is proportional to $\\sqrt{1/M}$, the frequency is higher when lighter atoms move. \n",
" At $k=\\pm\\frac{\\pi}{2a}$, in the acoustic branch, the light atoms stand still whearas the heavier atoms move. In the optical branch, the opposite is observed. Since frequency is proportional to $\\sqrt{1/M}$, the frequency is higher when lighter atoms move. \n",
" </details>\n",
" \n",
" \n",
"4. Adjust the mass ratio of the molecules. What happens when the ratio is high ? When the ratio is close to unity ? How does the band dispersion evolve ?\n",
"4. Adjust the mass ratio of the molecules. What happens when the ratio is high ? How about when the ratio is close to unity ? How does the band dispersion change ?\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" As the ratio grows, the forbidden frequencies gap grows as well. At $k=\\pm\\frac{\\pi}{2a}$, the gap is proportional to $\\sqrt{1/M_{gray}}-\\sqrt{1/M_{red}}$.\n",
" As the ratio grows, the gap of forbidden frequencies grows as well. At $k=\\pm\\frac{\\pi}{2a}$, the gap is proportional to $\\sqrt{1/M_{gray}}-\\sqrt{1/M_{red}}$.\n",
" \n",
" Furthermore, at $k=0$, we have $\\frac{u_{red}}{u_{gray}}=\\frac{-M_{gray}}{M_{red}}$, and thus the heavier atom amplitude decreases as it gets heavier.\n",
" Furthermore, at $k=0$, we have $\\frac{u_{red}}{u_{gray}}=\\frac{-M_{gray}}{M_{red}}$, and thus the oscillation amplitude of the heavier atom decreases as it gets heavier.\n",
" </details>\n",
" \n",
" \n",
Expand All @@ -70,9 +70,22 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d7013e3d8e4e48b5bd47310cd0d4742b",
"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 @@ -90,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -132,7 +145,7 @@
" handler.widgetList.append(widget)\n",
"\n",
"handler.slider_atom_radius.value=0.1\n",
"handler.slider_arrow_radius.value=0.1\n",
"handler.slider_arrow_radius.value=0.05\n",
"handler.tick_box_arrows.value=True\n",
"handler.addArrows() # add arrows by default\n",
"handler.set_player_parameters(delay=handler.init_delay)\n",
Expand Down Expand Up @@ -223,7 +236,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -254,13 +267,13 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5fcc7dc436fc4fb49e968f36b35ce6ec",
"model_id": "60c1818f30a54bc0b04cb1a03675b7d9",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -274,7 +287,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b58c0b65f41e420f953144a81ec71577",
"model_id": "98bc1ac74b5c4af680e96b3f5fdd1b1d",
"version_major": 2,
"version_minor": 0
},
Expand Down

0 comments on commit 6d6c0ae

Please sign in to comment.