Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anywidgets and update deps #322

Merged
merged 33 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
aa2d9be
relax dependencies: latest nb, jupyterlab
eimrek Apr 8, 2024
76d2b7e
brillouin_zone nb: new widget; cleanup
eimrek Apr 8, 2024
fcc40ec
free electron nb: use widget-bandsplot; rm unused code
eimrek Apr 10, 2024
10307ea
requirements.txt: pin versions to pip freeze
eimrek Apr 10, 2024
58f899d
fix the pseudopotential bugs
Apr 27, 2024
bec1f61
Fixed matplotlib errors in one quantum well notebook.
Taylor-96 Apr 27, 2024
107f406
Fixed matplotlib errors in two quantum wells notebook.
Taylor-96 Apr 28, 2024
7a68b67
Fixed matplotlib issues in asymmetric well.
Taylor-96 Apr 28, 2024
e22b3f4
Fixed matplotlib errors in shooting method notebook. Resolved issue w…
Taylor-96 Apr 29, 2024
e5ebb90
Merging updates made to FFT and planewaves from earlier and bundling …
Taylor-96 Apr 30, 2024
e85fa94
Free electron band structure (#321)
giovannipizzi Apr 30, 2024
99e9155
Merge pull request #323 from osscar-org/pseudopotential
Taylor-96 May 4, 2024
267a898
Merge pull request #324 from osscar-org/1quantum_well
Taylor-96 May 4, 2024
59ced2e
Merge pull request #326 from osscar-org/2quantum_wells
Taylor-96 May 4, 2024
f91fc72
Merge pull request #327 from osscar-org/asymmetric_well_review
Taylor-96 May 4, 2024
e966bb1
Merge pull request #329 from osscar-org/shooting_method_review
Taylor-96 May 4, 2024
9c9350c
Merge pull request #330 from osscar-org/fft_review
Taylor-96 May 4, 2024
4c71401
Added missing fix to the shooting method notebook which allows proper…
Taylor-96 May 4, 2024
69d48b3
Merging changes from the dos branch (reworked the layout of the dos n…
Taylor-96 May 4, 2024
e6a9663
Merged msoft_review branch with improved functionality (otf plotting …
Taylor-96 May 6, 2024
2d78ad4
Merged updated BZ theory notebook from BZ_review branch.
Taylor-96 May 6, 2024
0778e0a
fix the bug of the voila with AppLayout (#331)
dou-du May 9, 2024
ce637b5
fix the warning info bug (#332)
dou-du May 9, 2024
dbb464f
Workaround for issue in which play box doesn't appear in Voila. Set a…
Taylor-96 May 12, 2024
247dc43
Made default selected k-point in 2d phonon notebook more illuminating…
Taylor-96 May 14, 2024
c139e7d
add sleep 3s
May 18, 2024
7a0d344
update the test figure
May 18, 2024
9a5fe08
sleep 3s
May 18, 2024
30f905a
update the workflow for PR to the matcloud.xyz
May 18, 2024
09bfbb3
Manually labeled equations in lattice vibration theory notebooks.
Taylor-96 May 20, 2024
b471b03
Merged textual changes from mol vibration branch. Also fixed some for…
Taylor-96 May 20, 2024
97deb91
Merged textual changes from phonon1d branch. Set default k-point away…
Taylor-96 May 20, 2024
5955e92
Switched to the classic tree page
Taylor-96 May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/dokku-dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ jobs:
with:
fetch-depth: 0

- name: Push to dokku
- name: Push to dokku (PR open)
uses: dokku/github-action@master
with:
git_remote_url: 'ssh://dokku@matcloud.xyz:22/osscar-quantum-mechanics'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
if: github.event_name == 'pull_request'
if: ${{ github.event_name == 'pull_request' && github.event.action == 'opened' }}

- name: Push to dokku (PR synchronize)
uses: dokku/github-action@master
with:
git_remote_url: 'ssh://dokku@matcloud.xyz:22/osscar-quantum-mechanics'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
if: ${{ github.event_name == 'pull_request' && github.event.action == 'synchronize' }}
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: voila --Voila.ip=0.0.0.0 --template=osscar --VoilaConfiguration.enable_nbextensions=True notebook/ --port=$PORT --no-browser --MappingKernelManager.cull_interval=60 --MappingKernelManager.cull_idle_timeout=120 --MappingKernelManager.cull_busy=True
web: voila --Voila.ip=0.0.0.0 --classic-tree --template=osscar --VoilaConfiguration.enable_nbextensions=True notebook/ --port=$PORT --no-browser --MappingKernelManager.cull_interval=60 --MappingKernelManager.cull_idle_timeout=120 --MappingKernelManager.cull_busy=True
103 changes: 80 additions & 23 deletions notebook/band-theory/FFT_and_planewaves.ipynb

Large diffs are not rendered by default.

195 changes: 24 additions & 171 deletions notebook/band-theory/brillouin_zone.ipynb

Large diffs are not rendered by default.

510 changes: 314 additions & 196 deletions notebook/band-theory/density_of_states.ipynb

Large diffs are not rendered by default.

197 changes: 78 additions & 119 deletions notebook/band-theory/free_electron.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
"\n",
"**Source code:** https://github.com/osscar-org/quantum-mechanics/blob/master/notebook/band-theory/free_electron.ipynb\n",
"\n",
" The main objective of this notebook is to demonstrate the bandstructure for the\n",
" free-electron model in a periodic lattice.\n",
" The main objective of this notebook is to demonstrate the electronic bandstructure within the free-electron model for a periodic crystalline lattice of a metal.\n",
" \n",
" \n",
"Throughout the notebook, we employ the empty lattice (free-electron) approximation for the electrons in a periodic \n",
"solid system. Using it, we compute and plot the electronic band structure for three \n",
"types of Bravais lattice: simple cubic (SC), face-centered cubic (FCC) and body-centered cubic (BCC). We get the path in reciprocal space for the band structure \n",
"from the <a href=\"https://seekpath.readthedocs.io/en/latest/index.html\">seekpath</a>\n",
"package.\n",
"\n",
"<hr style=\"height:1px;border:none;color:#cccccc;background-color:#cccccc;\" />"
]
Expand All @@ -29,8 +35,8 @@
"source": [
"## **Goals**\n",
"\n",
"* Familiarize oneself with the free-electron model.\n",
"* Examine the electronic band structure of the free electron model for different crystal structures.\n"
"* Familiarize yourself with the free-electron model of a metallic solid.\n",
"* Examine the electronic band structure of the free-electron model for different crystalline structures.\n"
]
},
{
Expand All @@ -52,19 +58,19 @@
" <li> Can you describe the shape of the band structure in the 1st Brillouin zone?\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" In the free electron model, the dispersion relation between electronic energy and wavevector is given by $E=\\frac{\\hbar^2k^2}{2m}$. Consequently, the shape of the bands is parabolic. \n",
" In the free electron model, the dispersion relation between electronic energy and wavevector is given by $E=\\frac{\\hbar^2k^2}{2m}$. Accordingly, the shape of the bands is parabolic. \n",
" </details> \n",
" </li>\n",
" <li> What properties of a material shall be best captured by the free electron model?\n",
" <li> What properties of a material shall be best captured by the free-electron model?\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" As the free-electron model neglects the effect of the ionic potential on the electrons, material properties which are primarily dependent on the kinetic energy of the conduction electrons are those which shall be best described by the model.\n",
" </details> \n",
" </li>\n",
" <li> Look at the bandstructure plots for different crystal structures by toggling the \"Cell type\" radio buttons. Why is the bandstructure associated with the BCC crystal structure much denser than that of the simple cubic cell (i.e., why is there so many more bands in the energy range considered for BCC compared to SC).\n",
" <li> Consider the simple cubic lattice, and consider the lowest energy band from Γ to the X point, from Γ to the R point, and from Γ to the M point. The curvature of those bands seem to be the same. Is this to be expected? What about the Γ-L, Γ-X, and Γ-K in the FCC case? Or the Γ-H, Γ-N, and Γ-P in the BCC case?\n",
" <details>\n",
" <summary style=\"color: red\">Solution</summary>\n",
" Recalling that the energy eigenvalues are given by $\\large E = \\frac{\\hbar^2(\\vec{k}+\\vec{G})^2}{2m}$, we can see that the origin of the increased density of bands for BCC is due to its Brillouin zone giving rise to a larger number of G-vectors with small magnitudes. This in turn increases the number of low-lying energy bands.\n",
" For a free electron case, the bands are isotropic (i.e., they are the same, independent of the direction in k space), and the effective mass is just the free-electron mass: $m^*=m_0$. Therefore, we expect all curvatures (of the lowest energy band starting from Γ) to be the same.\n",
" </details> \n",
" </li>\n",
"</ol>\n",
Expand All @@ -81,11 +87,6 @@
"import numpy as np\n",
"import seekpath\n",
"import re\n",
"import matplotlib\n",
"from ase.dft.dos import linear_tetrahedron_integration as lti\n",
"from ase.dft.kpoints import monkhorst_pack\n",
"from ase.cell import Cell\n",
"from scipy.stats import multivariate_normal\n",
"from widget_bzvisualizer import BZVisualizer"
]
},
Expand Down Expand Up @@ -166,8 +167,15 @@
"metadata": {},
"outputs": [],
"source": [
"def get_bands(real_lattice_bohr, reference_distance = 0.025, g_vectors_range = 3):\n",
"\n",
"def get_bands(real_lattice_bohr, reference_distance = 0.05, g_vectors_range = 3):\n",
" \"\"\"Function to return the band structure of a free-electron model.\n",
" \n",
" :param real_lattice_bohr: 3x3 lattice vectors of the crystal, in bohr\n",
" :param reference_distance: distance between consecutive k-points in the band structure.\n",
" :param g_vectors_range: integer indicating how many G vectors should be included\n",
" to compute the band structure.\n",
" \"\"\"\n",
" \n",
" # Simple way to get automatically the band path:\n",
" # I go back to real space, just put a single atom at the origin,\n",
" # then go back with seekpath.\n",
Expand Down Expand Up @@ -213,22 +221,18 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib widget\n",
"\n",
"import time\n",
"import matplotlib.pyplot as plt\n",
"from ipywidgets import Output, Button, RadioButtons, IntSlider, HBox, VBox, Checkbox, Label, FloatSlider\n",
"from ipywidgets import RadioButtons, HBox, VBox\n",
"\n",
"alat_bohr = 7.72\n",
"\n",
"lattices = np.zeros((3, 3, 3));\n",
"lattices = np.zeros((3, 3, 3))\n",
"\n",
"lattices[0] = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * alat_bohr / 2.0;\n",
"lattices[1] = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]]) * alat_bohr / 2.0;\n",
"lattices[2] = np.array([[-1, 1, 1], [1, -1, 1], [1, 1, -1]]) * alat_bohr / 2.0;\n",
"lattices[0] = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * alat_bohr / 2.0\n",
"lattices[1] = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]]) * alat_bohr / 2.0\n",
"lattices[2] = np.array([[-1, 1, 1], [1, -1, 1], [1, 1, -1]]) * alat_bohr / 2.0\n",
"\n",
"real_lattice_bohr = lattices[0]\n",
"bz = BZVisualizer(real_lattice_bohr, [[0.0, 0.0, 0.0]], [1], True, height='400px')"
"bz = BZVisualizer(real_lattice_bohr, [[0.0, 0.0, 0.0]], [1], height='400px', show_pathpoints = True, disable_interact_overlay = True)"
]
},
{
Expand All @@ -239,127 +243,82 @@
},
"outputs": [],
"source": [
"#G = Cell(real_lattice_bohr).reciprocal()*2*np.pi\n",
"def unicode_gamma(label):\n",
" if label == \"GAMMA\":\n",
" return 'Γ'\n",
" return label\n",
"\n",
"style = {'description_width': 'initial'}\n",
"def free_electron_aiida_bands(segments_data):\n",
" \"\"\"\n",
" Turns the free electron bandstructure segments data into\n",
" the AiiDA format that can be used with the widget-bandsplot\n",
" \"\"\"\n",
" path = []\n",
" paths = []\n",
" for seg in segments_data:\n",
" from_label = unicode_gamma(seg[\"start_label\"])\n",
" to_label = unicode_gamma(seg[\"end_label\"])\n",
" path.append([from_label, to_label])\n",
" paths.append({\n",
" \"length\": len(seg['kpoints_x']),\n",
" \"from\": from_label,\n",
" \"to\": to_label,\n",
" \"two_band_types\": False,\n",
" \"x\": seg[\"kpoints_x\"].tolist(),\n",
" \"values\": seg[\"energy_bands\"].tolist(),\n",
" })\n",
"\n",
"output = Output()\n",
" return {\n",
" \"label\": \"\",\n",
" \"path\": path,\n",
" \"paths\": paths,\n",
" #\"fermi_level\": 0,\n",
" }\n",
"\n",
"style = {'description_width': 'initial'}\n",
"cell_type = RadioButtons(options=['Simple cubic', 'FCC', 'BCC'], value='Simple cubic', description=\"Cell type:\")\n",
"nkpt = IntSlider(value=4, min=4, max=11, description=\"Number of k-point:\", style=style)\n",
"grange = IntSlider(value=0, min=0, max=3, description=\"Gvector range:\", style=style)\n",
"gcov = FloatSlider(value=0.5, min=0.1, max=1.0, description=\"Guassian covariance:\", style=style)\n",
"\n",
"def on_celltype_changed(c):\n",
" global real_lattice_bohr\n",
" real_lattice_bohr = lattices[cell_type.index]\n",
" ax.clear()\n",
"\n",
" plot_bandstructure('bands')\n",
" bz.cell = real_lattice_bohr.tolist()\n",
" print(\"test\")\n",
" \n",
" plot_bandstructure()\n",
"\n",
"cell_type.observe(on_celltype_changed, names='value');\n",
"\n",
"cell_type.observe(on_celltype_changed, names='value')\n",
"\n",
"def plot_bandstructure(c):\n",
" global G, segments_data, lbands\n",
" \n",
"def plot_bandstructure():\n",
" segments_data = get_bands(real_lattice_bohr)\n",
" G = np.array([segments_data[0]['b1'], segments_data[0]['b2'], segments_data[0]['b3']])\n",
" \n",
" x_ticks = []\n",
" x_labels = []\n",
" lbands = []\n",
"\n",
" for segment_data in segments_data:\n",
" if not x_labels:\n",
" x_labels.append(prettify(segment_data['start_label']))\n",
" x_ticks.append(segment_data['kpoints_x'][0])\n",
" else:\n",
" if x_labels[-1] != prettify(segment_data['start_label']):\n",
" x_labels[-1] += \"|\" + prettify(segment_data['start_label'])\n",
" x_labels.append(prettify(segment_data['end_label']))\n",
" x_ticks.append(segment_data['kpoints_x'][-1])\n",
"\n",
" for energy_band in segment_data['energy_bands']:\n",
" line, = ax.plot(segment_data['kpoints_x'], energy_band, 'k')\n",
" lbands.append(line)\n",
"\n",
" ax.set_ylim([0, 5])\n",
" ax.yaxis.tick_right()\n",
" ax.yaxis.set_label_position(\"right\")\n",
" ax.set_ylabel('Free-electron energy (eV)')\n",
" ax.set_xlim([np.min(x_ticks), np.max(x_ticks)])\n",
" ax.set_xticks(x_ticks)\n",
" ax.set_xticklabels(x_labels)\n",
" ax.grid(axis='x', color='red', linestyle='-', linewidth=0.5)\n",
" fig.tight_layout()\n",
" \n",
" update_bands_color('bands')\n",
" \n",
"def update_bands_color(c):\n",
" n = 3\n",
" \n",
" shape = (nkpt.value, nkpt.value, nkpt.value)\n",
" kpts = np.dot(monkhorst_pack(shape), G).reshape(shape + (3,))\n",
" eigs = _compute_dos(kpts, G, grange.value)\n",
" aiida_bands = free_electron_aiida_bands(segments_data)\n",
" bands_widget.bands = [aiida_bands]\n",
"\n",
" index = 0\n",
" \n",
" for segment_data in segments_data:\n",
" for i in range(-n, n+1):\n",
" for j in range(-n, n+1):\n",
" for k in range(-n, n+1): \n",
" if abs(i) <= grange.value and abs(j) <= grange.value and abs(k) <=grange.value:\n",
" lbands[index].set_color('r')\n",
" else:\n",
" lbands[index].set_color('k')\n",
" index+=1\n",
"\n",
"grange.observe(update_bands_color, names=\"value\")\n",
"\n",
" \n",
"with output:\n",
" global fig, ax\n",
" fig, ax = plt.subplots()\n",
" fig.set_size_inches(3.7, 5.0)\n",
" fig.canvas.header_visible = False\n",
" fig.canvas.layout.width = \"430px\"\n",
" plot_bandstructure('bands')\n",
" plt.show()\n",
"from widget_bandsplot import BandsPlotWidget\n",
"\n",
" \n",
"label1 = Label(value=\"Compute DOS by different methods:\")\n",
"label2 = Label(value=\"(the number of k-points in all three dimensions)\")\n",
"label3 = Label(value=\"(the number of G vector ranges in all three dimensions)\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(HBox([VBox([bz,cell_type]), output]))"
"bands_widget = BandsPlotWidget(\n",
" energy_range = [0.0, 5.0],\n",
" format_settings = {\"bandsYlabel\": \"Free electron energy (eV)\"}\n",
")\n",
"plot_bandstructure()\n",
"\n",
"display(HBox([VBox([bz,cell_type]), bands_widget]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details open>\n",
" <summary style=\"font-size: 22px;\"><b>Legend</b></summary>\n",
"## Legend\n",
"\n",
"<p style=\"text-align: justify;font-size:15px\">\n",
" The 1st Brillouin zone of the selected cell is shown on the left. \n",
" The path along which the band structure is calculated is indicated with blue vectors and sampled\n",
" k-points are shown with red dots.\n",
" \n",
" The figure on the right shows the calculated band structure. \n",
" \n",
" We provide three kinds of cell structure: simple cubic, \n",
" face-centered cubic (FCC) and body-centered cubic (BCC). Use the radio \n",
" button to select the cell type. The number of k-points and G-vector ranges \n",
" can be tuned with the sliders.\n",
" button to select the cell type.\n",
"</p>\n",
" "
]
Expand Down Expand Up @@ -388,7 +347,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
Loading
Loading