Skip to content

Commit

Permalink
Added additional question, modified binning for histogram. Some text …
Browse files Browse the repository at this point in the history
…modifications.
  • Loading branch information
Taylor-96 committed Oct 10, 2023
1 parent 1994e04 commit 710f40c
Showing 1 changed file with 46 additions and 29 deletions.
75 changes: 46 additions & 29 deletions notebook/band-theory/density_of_states.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,21 @@
"1. Investigate the influence of the number of k-points on the resulting DOS.\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" In the right panel, the blue line is the analytical solution for the DOS. \n",
" By choosing different numbers of kpoints via the \"Number of kpoints slider\", we can investigate how \n",
" In the right panel, the plotted blue line is the analytical result for the DOS of the free electron model. \n",
" By choosing different numbers of k-points via the \"Number of k-points slider\", we can investigate how \n",
" the quality of the calculated results varies with the density of the k-point mesh. You will observe that the numerical results converge to the analytical result with increasing number of k-points. This can be attributed to the fact that the DOS can be interpreted as a probability density of electronic states as a function of energy. Since energy is generally related to the k-vector magnitude, the quality with which we resolve the range of energy eigenvalues is in turn directly controlled by how fine our sampling of the k-point mesh is.\n",
" </details> \n",
"\n",
"2. Which method gives most accurate results? Which method is fastest and why?\n",
"\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" The linear tetrahedra interpolation (LTI) method is an accurate numerical approach, \n",
" which interpolates the 3D kpoints grid. The LTI method can yield much better \n",
" results compared to a simple histogram. Gaussian smearing makes the \n",
" histogram plot much smoother, which is closer to the analytical \n",
" solution. The histogram method is a simple statistic of the eigenvalues, \n",
" which should be the fastest to compute, but which shall give results with poorer resolution.\n",
" The linear tetrahedra interpolation (LTI) method is an accurate numerical approach which linearly interpolates the 3D k-points grid within a set of tetrahedra into which reciprocal space has been subdivided (see the [background theory.](./theory/theory_density_of_states.ipynb) notebook). The LTI method can yield much better results compared to a simple histogram. Gaussian smearing renders the \n",
" histogram plot considerably smoother, and closer to the analytical \n",
" solution. The histogram method is a simple statistical representation of the eigenvalues (one simply represents the frequency with which a given range of eigenenergies occur). This latter approach is typically the fastest of those discussed, but shall also generally give results with the poorest level of resolution.\n",
" </details>\n",
"\n",
"3. Why do the calculated results start to diverge when the energy level is \n",
"higher than a certain value? Could you explain it with the k-space plot?\n",
"3. Why do the calculated results start to diverge when the energy level is higher than a certain value? Could you explain it with the k-space plot?\n",
"\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
Expand All @@ -78,6 +74,13 @@
" have a fixed length of the kpoints grid. When the energy is larger than \n",
" about 0.31, the kpoints grid cannot include the whole sphere (check it by \n",
" clicking on the right panel to move the isovalue above and below 0.31). \n",
" </details>\n",
" \n",
"4. Set the number of k-points to the maximum value and consider Gaussian smearing with a reasonable value for the smearing parameter (say $\\sigma=0.07$). Looking at the calculated DOS with the G-vector range set to $0$, how does it compare with the analytical result? Can you explain any discrepancies you notice? Increasing the G-vector range to $1$, how does the calculated DOS now compare?\n",
"\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" You will notice that even with a high number of k-points and an appropriate smearing parameter, the calculated DOS starts to deviate significantly from the analytical result above an energy of around . This discrepancy can be attributed to the fact that when we only consider the G-vector $G=0$, we are neglecting to include several bands in the electronic energy dispersion that still contribute energy eigenvalues that fall within the range we are interested in. That is, and you can verify the claim by increasing the G-vector slider to the value 1, several bands are folded back into the first Brillouin zone. You can see which bands undergo folding by tracking those which change from black to red upon incrementing the G- vector slider.\n",
" </details>"
]
},
Expand All @@ -93,9 +96,17 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 170,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:matplotlib.pyplot:Loaded backend module://ipympl.backend_nbagg version unknown.\n"
]
}
],
"source": [
"import numpy as np\n",
"import seekpath\n",
Expand All @@ -120,7 +131,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 171,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -138,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 172,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -159,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 173,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -216,7 +227,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 174,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -234,7 +245,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 175,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -258,6 +269,7 @@
"# nkpt = IntSlider(value=4, min=4, max=15,description=\"Number of kpoints per dimension\\n, $N_k$\" , display='flex',\n",
"# flex_flow='row', continuous_update=False)\n",
"grange = IntSlider(value=0, min=0, max=3, description=\"G-vector range:\", style=style)\n",
"grange_hint =HTML(value=f\"<b>Note that there may be a delay while the DOS is computed for G-vectors > 0.</b>\")\n",
"gcov = FloatSlider(value=0.5, min=0.1, max=1.0, description=\"Guassian covariance:\", style=style)\n",
"\n",
"def prettify(label):\n",
Expand Down Expand Up @@ -448,7 +460,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 176,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -540,14 +552,19 @@
" G = Cell(real_lattice_bohr).reciprocal()*2*np.pi\n",
" kpts = np.dot(monkhorst_pack(shape), G).reshape(shape + (3,))\n",
" eigs = _compute_dos(kpts, G, grange.value)\n",
" logging.debug(\"eigs max = {}\".format(eigs.max()))\n",
" num_bins=int((eigs.max()-eigs.min())*(nbin.value))\n",
" logging.debug(\"num bins = {}\".format(num_bins))\n",
" num_bins=nbin.value\n",
"\n",
" # num_bins=int(nbin.value/(eigs.max()-eigs.min()))\n",
" # with output:\n",
" # print(\"num_bins={}\".format(num_bins))\n",
"\n",
" hy, hx = np.histogram(eigs.ravel(),bins=num_bins )\n",
"\n",
" hy = hy/np.sum(hy*np.diff(hx))*np.shape(eigs)[-1]\n",
" \n",
" # with output:\n",
" # print(\"hx={}\".format(hx))\n",
" # print(\"hy={}\".format(hy))\n",
"\n",
" lhist = ax_dos.barh(hx[:-1]+np.diff(hx)[0], hy, color='yellow', edgecolor='black', \n",
" height=np.diff(hx), label=\"Add plot\")\n",
" ax_dos.legend(loc=1, bbox_to_anchor=(1.3, 1.0))\n",
Expand Down Expand Up @@ -583,7 +600,7 @@
" G = Cell(real_lattice_bohr).reciprocal()*2*np.pi\n",
" kpts = np.dot(monkhorst_pack(shape), G).reshape(shape + (3,))\n",
" eigs = _compute_dos(kpts, G, grange.value)\n",
" \n",
"\n",
" # gx = np.linspace(-0.03, 1.5, 70)\n",
" gx = np.linspace(-0.03, 0.5, 70)\n",
"\n",
Expand All @@ -592,7 +609,7 @@
" knum=nkpt.value\n",
" Gnum=grange.value\n",
" \n",
" start = time.time()\n",
" # start = time.time()\n",
"\n",
" # pdf_vals = norm(eigs.ravel().reshape(-1,1), scale=gstd).pdf(gx)\n",
" # gy = np.sum(pdf_vals, axis=0)\n",
Expand All @@ -603,7 +620,7 @@
" gy += norm(eig, gstd.value).pdf(gx)\n",
" # pdf_vals = np.array([norm(eigs.ravel(), scale=gstd).pdf(x) for x in gx])\n",
" # gy = np.sum(pdf_vals, axis=-1)\n",
" end = time.time()\n",
" # end = time.time()\n",
"# with output:\n",
"# print(\"(eigs.shape)={}. gy.shape={}\".format(eigs.shape,gy.shape))\n",
"\n",
Expand Down Expand Up @@ -711,7 +728,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 177,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -777,13 +794,13 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 178,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a4a49c9c9cfc4acbbc3594ca30efc807",
"model_id": "28af17027813409fbbffbc57dd9a625c",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -803,7 +820,7 @@
"method4 = HBox([btclear, Label(value=\"(Clear the calculated results)\")])\n",
"\n",
"label1 = HTML(value = f\"<b><font color='red'>Choose a method to calculate the DOS:</b>\")\n",
"display(VBox([output,VBox([ nkpt_box,grange, label1, method1, method2, method3])]))\n",
"display(VBox([output,VBox([ nkpt_box,VBox([grange,grange_hint]), label1, method1, method2, method3])]))\n",
"# display(HBox([VBox([output_bs, nkpt_box, label1, method1, method2, method3]), VBox([output, method4])]))"
]
},
Expand Down

0 comments on commit 710f40c

Please sign in to comment.