|
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 | }, |
|
96 | 101 | "metadata": {}, |
97 | 102 | "outputs": [], |
98 | 103 | "source": [ |
99 | | - "\n", |
100 | | - "def print_eigs(vr, bwind=5, defect_bands = ()):\n", |
| 104 | + "def print_eigs(vr, bwind=5, defect_bands=()):\n", |
101 | 105 | " \"\"\"Print the eigenvalues in a small band window around the Fermi level.\n", |
102 | 106 | "\n", |
103 | 107 | " Args:\n", |
104 | 108 | " vr (Vasprun): The Vasprun object.\n", |
105 | 109 | " bwind (int): The number of bands above and below the Fermi level to print.\n", |
106 | 110 | " defect_bands (list): A list of tuples of the form (band index, kpt index, spin index)\n", |
107 | 111 | " \"\"\"\n", |
108 | | - " def _get_spin_idx(spin):\n", |
| 112 | + "\n", |
| 113 | + " def _get_spin_idx(spin) -> int:\n", |
109 | 114 | " if spin == Spin.up:\n", |
110 | 115 | " return 0\n", |
111 | 116 | " return 1\n", |
| 117 | + "\n", |
112 | 118 | " occ = vr.eigenvalues[Spin.up][0, :, 1] * -1\n", |
113 | | - " fermi_idx = bisect.bisect_left(occ, -0.5) \n", |
| 119 | + " fermi_idx = bisect.bisect_left(occ, -0.5)\n", |
114 | 120 | " output = collections.defaultdict(list)\n", |
115 | 121 | " for k, spin_eigs in vr.eigenvalues.items():\n", |
116 | 122 | " spin_idx = _get_spin_idx(k)\n", |
117 | 123 | " for kpt in range(spin_eigs.shape[0]):\n", |
118 | 124 | " for ib in range(fermi_idx - bwind, fermi_idx + bwind):\n", |
119 | 125 | " e, o = spin_eigs[kpt, ib, :]\n", |
120 | 126 | " 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", |
| 127 | + " e_out = f\"{e:7.4f}*\" if idx in defect_bands else f\"{e:8.5f}\"\n", |
125 | 128 | " output[(ib)].append(e_out)\n", |
126 | 129 | " print(\"band s=0,k=0 s=0,k=1 s=1,k=0 s=1,k=1\")\n", |
127 | 130 | " for ib, eigs in output.items():\n", |
128 | 131 | " print(f\"{ib:3d} {' '.join(eigs)}\")\n", |
129 | 132 | "\n", |
| 133 | + "\n", |
130 | 134 | "print_eigs(vr=hd0.vrun, defect_bands=hd0.defect_band)" |
131 | 135 | ] |
132 | 136 | }, |
|
177 | 181 | "metadata": {}, |
178 | 182 | "outputs": [], |
179 | 183 | "source": [ |
180 | | - "energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0,jdir=0)\n", |
| 184 | + "energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0, jdir=0)\n", |
181 | 185 | "# plotting\n", |
182 | 186 | "plt.plot(energy, np.imag(eps_vbm), label=\"VBM\")\n", |
183 | 187 | "plt.plot(energy, np.imag(eps_cbm), label=\"CBM\")\n", |
|
216 | 220 | "metadata": {}, |
217 | 221 | "outputs": [], |
218 | 222 | "source": [ |
219 | | - "from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n", |
220 | 223 | "import matplotlib as mpl\n", |
| 224 | + "from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n", |
| 225 | + "\n", |
221 | 226 | "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", |
| 227 | + "cm_ax = fig.add_axes([0.8, 0.1, 0.02, 0.8])\n", |
| 228 | + "df_k0, cmap, norm = plot_optical_transitions(\n", |
| 229 | + " hd0, kpt_index=1, band_window=5, x0=3, ax=ax\n", |
| 230 | + ")\n", |
| 231 | + "df_k1, _, _ = plot_optical_transitions(\n", |
| 232 | + " hd0, kpt_index=0, band_window=5, x0=0, ax=ax, cmap=cmap, norm=norm\n", |
| 233 | + ")\n", |
| 234 | + "mpl.colorbar.ColorbarBase(cm_ax, cmap=cmap, norm=norm, orientation=\"vertical\")\n", |
| 235 | + "ax.set_ylabel(\"Energy (eV)\")\n", |
| 236 | + "ax.set_xticks([0, 3])\n", |
228 | 237 | "ax.set_xticklabels([\"Kpoint-0\", \"Kpoint-1\"])" |
229 | 238 | ] |
230 | 239 | }, |
|
0 commit comments