|
25 | 25 | "outputs": [],
|
26 | 26 | "source": [
|
27 | 27 | "# disable tqdm progress bar\n",
|
28 |
| - "from tqdm import tqdm\n", |
29 | 28 | "from functools import partialmethod\n",
|
| 29 | + "\n", |
| 30 | + "from tqdm import tqdm\n", |
| 31 | + "\n", |
30 | 32 | "tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)\n",
|
31 | 33 | "# disable warnings\n",
|
32 | 34 | "import warnings\n",
|
| 35 | + "\n", |
33 | 36 | "warnings.filterwarnings(\"ignore\", category=UserWarning)"
|
34 | 37 | ]
|
35 | 38 | },
|
|
40 | 43 | "metadata": {},
|
41 | 44 | "outputs": [],
|
42 | 45 | "source": [
|
| 46 | + "import bisect\n", |
| 47 | + "import collections\n", |
43 | 48 | "from pathlib import Path\n",
|
44 |
| - "from pymatgen.analysis.defects.ccd import HarmonicDefect, get_SRH_coefficient\n", |
45 |
| - "from pymatgen.io.vasp.optics import DielectricFunctionCalculator, Spin, Vasprun, Waveder\n", |
| 49 | + "\n", |
46 | 50 | "import numpy as np\n",
|
47 | 51 | "from matplotlib import pyplot as plt\n",
|
48 |
| - "import bisect\n", |
49 |
| - "import collections\n", |
| 52 | + "from pymatgen.analysis.defects.ccd import HarmonicDefect\n", |
| 53 | + "from pymatgen.io.vasp.optics import Spin, Waveder\n", |
| 54 | + "\n", |
50 | 55 | "TEST_FILES = Path(\"../../../tests/test_files/v_Ga/\")"
|
51 | 56 | ]
|
52 | 57 | },
|
|
71 | 76 | "dir0 = TEST_FILES / \"ccd_0_-1\" / \"optics\"\n",
|
72 | 77 | "hd0 = HarmonicDefect.from_directories(directories=[dir0], store_bandstructure=True)\n",
|
73 | 78 | "# Note the `store_bandstructure=True` argument is required for the matrix element plotting later in the notebook.\n",
|
74 |
| - "# but not required for the dielectric function calculation.\n", |
75 |
| - "print(f\"The defect band is {hd0.defect_band}\")\n", |
76 |
| - "print(f\"The vibrational frequency is omega={hd0.omega} in this case is gibberish.\")" |
| 79 | + "# but not required for the dielectric function calculation." |
77 | 80 | ]
|
78 | 81 | },
|
79 | 82 | {
|
|
96 | 99 | "metadata": {},
|
97 | 100 | "outputs": [],
|
98 | 101 | "source": [
|
99 |
| - "\n", |
100 |
| - "def print_eigs(vr, bwind=5, defect_bands = ()):\n", |
| 102 | + "def print_eigs(vr, bwind=5, defect_bands=()) -> None:\n", |
101 | 103 | " \"\"\"Print the eigenvalues in a small band window around the Fermi level.\n",
|
102 | 104 | "\n",
|
103 | 105 | " Args:\n",
|
104 | 106 | " vr (Vasprun): The Vasprun object.\n",
|
105 | 107 | " bwind (int): The number of bands above and below the Fermi level to print.\n",
|
106 | 108 | " defect_bands (list): A list of tuples of the form (band index, kpt index, spin index)\n",
|
107 | 109 | " \"\"\"\n",
|
108 |
| - " def _get_spin_idx(spin):\n", |
| 110 | + "\n", |
| 111 | + " def _get_spin_idx(spin) -> int:\n", |
109 | 112 | " if spin == Spin.up:\n",
|
110 | 113 | " return 0\n",
|
111 | 114 | " return 1\n",
|
| 115 | + "\n", |
112 | 116 | " occ = vr.eigenvalues[Spin.up][0, :, 1] * -1\n",
|
113 |
| - " fermi_idx = bisect.bisect_left(occ, -0.5) \n", |
| 117 | + " fermi_idx = bisect.bisect_left(occ, -0.5)\n", |
114 | 118 | " output = collections.defaultdict(list)\n",
|
115 | 119 | " for k, spin_eigs in vr.eigenvalues.items():\n",
|
116 | 120 | " spin_idx = _get_spin_idx(k)\n",
|
117 | 121 | " for kpt in range(spin_eigs.shape[0]):\n",
|
118 | 122 | " for ib in range(fermi_idx - bwind, fermi_idx + bwind):\n",
|
119 | 123 | " e, o = spin_eigs[kpt, ib, :]\n",
|
120 | 124 | " idx = (ib, kpt, spin_idx)\n",
|
121 |
| - " if idx in defect_bands:\n", |
122 |
| - " e_out = f\"{e:7.4f}*\"\n", |
123 |
| - " else:\n", |
124 |
| - " e_out = f\"{e:8.5f}\"\n", |
| 125 | + " e_out = f\"{e:7.4f}*\" if idx in defect_bands else f\"{e:8.5f}\"\n", |
125 | 126 | " output[(ib)].append(e_out)\n",
|
126 |
| - " print(\"band s=0,k=0 s=0,k=1 s=1,k=0 s=1,k=1\")\n", |
127 |
| - " for ib, eigs in output.items():\n", |
128 |
| - " print(f\"{ib:3d} {' '.join(eigs)}\")\n", |
| 127 | + " for ib in output:\n", |
| 128 | + " pass\n", |
| 129 | + "\n", |
129 | 130 | "\n",
|
130 | 131 | "print_eigs(vr=hd0.vrun, defect_bands=hd0.defect_band)"
|
131 | 132 | ]
|
|
177 | 178 | "metadata": {},
|
178 | 179 | "outputs": [],
|
179 | 180 | "source": [
|
180 |
| - "energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0,jdir=0)\n", |
| 181 | + "energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0, jdir=0)\n", |
181 | 182 | "# plotting\n",
|
182 | 183 | "plt.plot(energy, np.imag(eps_vbm), label=\"VBM\")\n",
|
183 | 184 | "plt.plot(energy, np.imag(eps_cbm), label=\"CBM\")\n",
|
|
216 | 217 | "metadata": {},
|
217 | 218 | "outputs": [],
|
218 | 219 | "source": [
|
219 |
| - "from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n", |
220 | 220 | "import matplotlib as mpl\n",
|
| 221 | + "from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n", |
| 222 | + "\n", |
221 | 223 | "fig, ax = plt.subplots()\n",
|
222 |
| - "cm_ax = fig.add_axes([0.8,0.1,0.02,0.8])\n", |
223 |
| - "df_k0, cmap, norm = plot_optical_transitions(hd0, kpt_index=1, band_window=5, x0=3, ax=ax)\n", |
224 |
| - "df_k1, _, _ = plot_optical_transitions(hd0, kpt_index=0, band_window=5, x0=0, ax=ax, cmap=cmap, norm=norm)\n", |
225 |
| - "mpl.colorbar.ColorbarBase(cm_ax,cmap=cmap,norm=norm,orientation='vertical')\n", |
226 |
| - "ax.set_ylabel(\"Energy (eV)\");\n", |
227 |
| - "ax.set_xticks([0,3])\n", |
| 224 | + "cm_ax = fig.add_axes([0.8, 0.1, 0.02, 0.8])\n", |
| 225 | + "df_k0, cmap, norm = plot_optical_transitions(\n", |
| 226 | + " hd0, kpt_index=1, band_window=5, x0=3, ax=ax\n", |
| 227 | + ")\n", |
| 228 | + "df_k1, _, _ = plot_optical_transitions(\n", |
| 229 | + " hd0, kpt_index=0, band_window=5, x0=0, ax=ax, cmap=cmap, norm=norm\n", |
| 230 | + ")\n", |
| 231 | + "mpl.colorbar.ColorbarBase(cm_ax, cmap=cmap, norm=norm, orientation=\"vertical\")\n", |
| 232 | + "ax.set_ylabel(\"Energy (eV)\")\n", |
| 233 | + "ax.set_xticks([0, 3])\n", |
228 | 234 | "ax.set_xticklabels([\"Kpoint-0\", \"Kpoint-1\"])"
|
229 | 235 | ]
|
230 | 236 | },
|
|
0 commit comments