Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 7, 2024
1 parent 793dda0 commit ba1e2b0
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 116 deletions.
7 changes: 2 additions & 5 deletions docs/source/content/defect-finder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"from pymatgen.io.vasp import Locpot\n",
"\n",
"TEST_FILES = Path(\"../../../tests/test_files\")\n",
"import glob\n",
"\n",
"from pymatgen.analysis.defects.finder import DefectSiteFinder\n",
"from pymatgen.core.structure import Structure\n",
Expand All @@ -37,11 +35,10 @@
"finder = DefectSiteFinder()\n",
"\n",
"for q in range(-1, 3):\n",
" fname = f\"{str(TEST_FILES)}/v_N_GaN/q={q}/CONTCAR.gz\"\n",
" fname = f\"{TEST_FILES!s}/v_N_GaN/q={q}/CONTCAR.gz\"\n",
" struct = Structure.from_file(fname)\n",
" fpos = finder.get_defect_fpos(defect_structure=struct, base_structure=base_struct)\n",
" fpos -= np.round(fpos)\n",
" print(fpos)"
" fpos -= np.round(fpos)"
]
},
{
Expand Down
20 changes: 8 additions & 12 deletions docs/source/content/defining-defects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"if (\n",
" bulk.lattice == bulk.get_primitive_structure().lattice\n",
"): # check that you have the primitive structure\n",
" print(\"The bulk unit cell is the unique primitive WS cell\")"
" pass"
]
},
{
Expand Down Expand Up @@ -92,7 +92,7 @@
"mg_ga_defect0 = Substitution(structure=bulk, site=mg_site0)\n",
"mg_ga_defect1 = Substitution(structure=bulk, site=mg_site1)\n",
"if mg_ga_defect0 == mg_ga_defect1:\n",
" print(\"The two Mg_Ga defects are equivalent.\")"
" pass"
]
},
{
Expand Down Expand Up @@ -125,14 +125,10 @@
"vac_defect1 = Vacancy(structure=bulk, site=n_site0)\n",
"vac_defect2 = Vacancy(structure=bulk, site=n_site1)\n",
"if vac_defect0 != vac_defect1:\n",
" print(\n",
" f\"The two vacancies {vac_defect0.name} and {vac_defect1.name} are not equivalent.\"\n",
" )\n",
" pass\n",
"\n",
"if vac_defect2 == vac_defect1:\n",
" print(\n",
" f\"The two vacancies {vac_defect2.name} and {vac_defect1.name} are equivalent.\"\n",
" )"
" pass"
]
},
{
Expand Down Expand Up @@ -260,8 +256,8 @@
"\n",
"chgcar = Chgcar.from_file(TEST_FILES / \"CHGCAR.Fe3O4.vasp\")\n",
"cig = ChargeInterstitialGenerator()\n",
"for defect in cig.generate(chgcar, insert_species=[\"H\"]):\n",
" print(defect)"
"for _defect in cig.generate(chgcar, insert_species=[\"H\"]):\n",
" pass"
]
},
{
Expand All @@ -279,8 +275,8 @@
},
"outputs": [],
"source": [
"for defect in generate_all_native_defects(chgcar):\n",
" print(defect)"
"for _defect in generate_all_native_defects(chgcar):\n",
" pass"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions docs/source/content/formation-energy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
"outputs": [],
"source": [
"import warnings\n",
"\n",
"from monty.serialization import loadfn\n",
"from pymatgen.analysis.defects.thermo import FormationEnergyDiagram\n",
"from pymatgen.io.vasp import Vasprun\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
Expand Down Expand Up @@ -129,10 +129,9 @@
"metadata": {},
"outputs": [],
"source": [
"for i, p in enumerate(fed.chempot_limits):\n",
" print(f\"Limits for the chemical potential changes for point {i}\")\n",
" for k,v in p.items():\n",
" print(f\"Δμ_{k} = {v:.2f} eV\")"
"for _i, p in enumerate(fed.chempot_limits):\n",
" for _k, _v in p.items():\n",
" pass"
]
},
{
Expand Down Expand Up @@ -164,10 +163,11 @@
"outputs": [],
"source": [
"from pymatgen.analysis.defects.corrections.freysoldt import plot_plnr_avg\n",
"\n",
"plot_data = fed.defect_entries[1].corrections_metadata[\"freysoldt\"][\"plot_data\"]\n",
"plot_plnr_avg(plot_data[0], title=\"Lattice Direction 1\")\n",
"plot_plnr_avg(plot_data[1], title=\"Lattice Direction 2\")\n",
"plot_plnr_avg(plot_data[2], title=\"Lattice Direction 3\")\n"
"plot_plnr_avg(plot_data[2], title=\"Lattice Direction 3\")"
]
}
],
Expand Down
16 changes: 6 additions & 10 deletions docs/source/content/freysoldt-correction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@
" defect_structure=defect_locpot.structure, base_structure=bulk_locpot.structure\n",
" )\n",
" center -= np.round(center)\n",
" print(f\"Computing Freysoldt Correction for: q={q}\")\n",
" print(f\"center={center}\")\n",
" freysoldt_results[q] = get_freysoldt_correction(\n",
" q=q,\n",
" dielectric=5,\n",
" bulk_locpot=bulk_locpot,\n",
" defect_locpot=defect_locpot,\n",
" defect_frac_coords=center,\n",
" )\n",
" align = np.mean(list(freysoldt_results[q].metadata[\"alignments\"].values()))\n",
" print(f\"alignment correction: {align}\")\n"
" align = np.mean(list(freysoldt_results[q].metadata[\"alignments\"].values()))"
]
},
{
Expand All @@ -103,7 +100,7 @@
"metadata": {},
"outputs": [],
"source": [
"def plot_sxd_output(q, direction, C, ax):\n",
"def plot_sxd_output(q, direction, C, ax) -> None:\n",
" \"\"\"Read the vline-eV-a#.dat files computed by the `sxdefectalign` program.\n",
"\n",
" Args:\n",
Expand All @@ -114,7 +111,7 @@
" \"\"\"\n",
" v_line_file = DEFECT_DIR / f\"q={q}/vline-eV-a{direction}.dat\"\n",
" # split the file into blocks based on the location of the string \"&\"\n",
" with open(v_line_file, \"r\") as f:\n",
" with open(v_line_file) as f:\n",
" blocks = f.read().split(\"&\")\n",
"\n",
" # convert each block into a list of lines and convert to a numpy array\n",
Expand All @@ -134,7 +131,7 @@
" ax.legend()\n",
"\n",
"\n",
"def comparison_plots(q):\n",
"def comparison_plots(q) -> None:\n",
" \"\"\"\"\"\"\n",
" fig, axs = plt.subplots(3, 2, figsize=(15, 15), sharey=True)\n",
" for direction in range(3):\n",
Expand Down Expand Up @@ -210,7 +207,7 @@
"outputs": [],
"source": [
"def get_sxd_result(q):\n",
" \"\"\"Read the output of sxdefectalign\"\"\"\n",
" \"\"\"Read the output of sxdefectalign.\"\"\"\n",
" fname = str(DEFECT_DIR / f\"q={q}/corr_align.out\")\n",
" gen = reverse_readfile(fname)\n",
" next(gen)\n",
Expand All @@ -226,8 +223,7 @@
"source": [
"for q in range(-1, 3):\n",
" python_res = freysoldt_results[q].correction_energy\n",
" sxd_res = get_sxd_result(q)\n",
" print(f\"python: {python_res:0.4f} / sxdefectalign: {sxd_res:0.4f}\")"
" sxd_res = get_sxd_result(q)"
]
}
],
Expand Down
24 changes: 8 additions & 16 deletions docs/source/content/nonradiative.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
"source": [
"# disable warnings\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\", category=UserWarning)\n",
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from pymatgen.analysis.defects.ccd import HarmonicDefect, get_SRH_coefficient"
Expand Down Expand Up @@ -63,12 +65,6 @@
"hd0 = HarmonicDefect.from_directories(\n",
" directories=dirs01,\n",
" store_bandstructure=True,\n",
")\n",
"print(f\"The relaxed structure is in dirs01[{hd0.relaxed_index}]\")\n",
"print(hd0)\n",
"print(\n",
" f\"The spin channel ({hd0.spin}) is also automaticalliy determined by the \"\n",
" \"IPR, by taking the spin channel who's defect states have the lowest average IPR across the different k-points.\"\n",
")"
]
},
Expand Down Expand Up @@ -184,9 +180,7 @@
"outputs": [],
"source": [
"wswq_dir = TEST_FILES / \"ccd_0_-1\" / \"wswqs\"\n",
"print(f\"The parsed WSWQ files are: {[f.name for f in wswq_dir.glob('WSWQ*')]}\")\n",
"hd0.read_wswqs(TEST_FILES / \"ccd_0_-1\" / \"wswqs\")\n",
"print(f\"Parsed {len(hd0.wswqs)} WSWQ files.\")\n"
"hd0.read_wswqs(TEST_FILES / \"ccd_0_-1\" / \"wswqs\")"
]
},
{
Expand All @@ -205,11 +199,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(f\"The automatically determined defect electronic states are: {hd0.defect_band} \"\n",
" \"(with [band, k-point, spin] indexing).\")\n",
"epME = hd0.get_elph_me(defect_state=(138, 1, 1))\n",
"print(f\"The resulting array of shape {epME.shape} contains the matrix elements from the \"\n",
" \"defect state to all other states at the same k-point.\")\n"
"epME = hd0.get_elph_me(defect_state=(138, 1, 1))"
]
},
{
Expand All @@ -233,7 +223,7 @@
"hd1 = HarmonicDefect.from_directories(\n",
" directories=dirs10,\n",
" store_bandstructure=True,\n",
")\n"
")"
]
},
{
Expand All @@ -252,7 +242,9 @@
"outputs": [],
"source": [
"T = np.linspace(100, 1000, 20)\n",
"srh_c = get_SRH_coefficient(initial_state=hd0, final_state=hd1, defect_state=(138, 1, 1), T=T, dE=0.3)\n",
"srh_c = get_SRH_coefficient(\n",
" initial_state=hd0, final_state=hd1, defect_state=(138, 1, 1), T=T, dE=0.3\n",
")\n",
"plt.plot(T, srh_c)\n",
"plt.xlabel(\"Temperature [K]\")\n",
"plt.ylabel(\"SRH coefficient [cm$^{-3}$s$^{-1}$]\");"
Expand Down
60 changes: 33 additions & 27 deletions docs/source/content/photo-conduct.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
"outputs": [],
"source": [
"# disable tqdm progress bar\n",
"from tqdm import tqdm\n",
"from functools import partialmethod\n",
"\n",
"from tqdm import tqdm\n",
"\n",
"tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)\n",
"# disable warnings\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\", category=UserWarning)"
]
},
Expand All @@ -40,13 +43,15 @@
"metadata": {},
"outputs": [],
"source": [
"import bisect\n",
"import collections\n",
"from pathlib import Path\n",
"from pymatgen.analysis.defects.ccd import HarmonicDefect, get_SRH_coefficient\n",
"from pymatgen.io.vasp.optics import DielectricFunctionCalculator, Spin, Vasprun, Waveder\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"import bisect\n",
"import collections\n",
"from pymatgen.analysis.defects.ccd import HarmonicDefect\n",
"from pymatgen.io.vasp.optics import Spin, Waveder\n",
"\n",
"TEST_FILES = Path(\"../../../tests/test_files/v_Ga/\")"
]
},
Expand All @@ -71,9 +76,7 @@
"dir0 = TEST_FILES / \"ccd_0_-1\" / \"optics\"\n",
"hd0 = HarmonicDefect.from_directories(directories=[dir0], store_bandstructure=True)\n",
"# Note the `store_bandstructure=True` argument is required for the matrix element plotting later in the notebook.\n",
"# but not required for the dielectric function calculation.\n",
"print(f\"The defect band is {hd0.defect_band}\")\n",
"print(f\"The vibrational frequency is omega={hd0.omega} in this case is gibberish.\")"
"# but not required for the dielectric function calculation."
]
},
{
Expand All @@ -96,36 +99,34 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"def print_eigs(vr, bwind=5, defect_bands = ()):\n",
"def print_eigs(vr, bwind=5, defect_bands=()) -> None:\n",
" \"\"\"Print the eigenvalues in a small band window around the Fermi level.\n",
"\n",
" Args:\n",
" vr (Vasprun): The Vasprun object.\n",
" bwind (int): The number of bands above and below the Fermi level to print.\n",
" defect_bands (list): A list of tuples of the form (band index, kpt index, spin index)\n",
" \"\"\"\n",
" def _get_spin_idx(spin):\n",
"\n",
" def _get_spin_idx(spin) -> int:\n",
" if spin == Spin.up:\n",
" return 0\n",
" return 1\n",
"\n",
" occ = vr.eigenvalues[Spin.up][0, :, 1] * -1\n",
" fermi_idx = bisect.bisect_left(occ, -0.5) \n",
" fermi_idx = bisect.bisect_left(occ, -0.5)\n",
" output = collections.defaultdict(list)\n",
" for k, spin_eigs in vr.eigenvalues.items():\n",
" spin_idx = _get_spin_idx(k)\n",
" for kpt in range(spin_eigs.shape[0]):\n",
" for ib in range(fermi_idx - bwind, fermi_idx + bwind):\n",
" e, o = spin_eigs[kpt, ib, :]\n",
" idx = (ib, kpt, spin_idx)\n",
" if idx in defect_bands:\n",
" e_out = f\"{e:7.4f}*\"\n",
" else:\n",
" e_out = f\"{e:8.5f}\"\n",
" e_out = f\"{e:7.4f}*\" if idx in defect_bands else f\"{e:8.5f}\"\n",
" output[(ib)].append(e_out)\n",
" print(\"band s=0,k=0 s=0,k=1 s=1,k=0 s=1,k=1\")\n",
" for ib, eigs in output.items():\n",
" print(f\"{ib:3d} {' '.join(eigs)}\")\n",
" for ib in output:\n",
" pass\n",
"\n",
"\n",
"print_eigs(vr=hd0.vrun, defect_bands=hd0.defect_band)"
]
Expand Down Expand Up @@ -177,7 +178,7 @@
"metadata": {},
"outputs": [],
"source": [
"energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0,jdir=0)\n",
"energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0, jdir=0)\n",
"# plotting\n",
"plt.plot(energy, np.imag(eps_vbm), label=\"VBM\")\n",
"plt.plot(energy, np.imag(eps_cbm), label=\"CBM\")\n",
Expand Down Expand Up @@ -216,15 +217,20 @@
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n",
"import matplotlib as mpl\n",
"from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n",
"\n",
"fig, ax = plt.subplots()\n",
"cm_ax = fig.add_axes([0.8,0.1,0.02,0.8])\n",
"df_k0, cmap, norm = plot_optical_transitions(hd0, kpt_index=1, band_window=5, x0=3, ax=ax)\n",
"df_k1, _, _ = plot_optical_transitions(hd0, kpt_index=0, band_window=5, x0=0, ax=ax, cmap=cmap, norm=norm)\n",
"mpl.colorbar.ColorbarBase(cm_ax,cmap=cmap,norm=norm,orientation='vertical')\n",
"ax.set_ylabel(\"Energy (eV)\");\n",
"ax.set_xticks([0,3])\n",
"cm_ax = fig.add_axes([0.8, 0.1, 0.02, 0.8])\n",
"df_k0, cmap, norm = plot_optical_transitions(\n",
" hd0, kpt_index=1, band_window=5, x0=3, ax=ax\n",
")\n",
"df_k1, _, _ = plot_optical_transitions(\n",
" hd0, kpt_index=0, band_window=5, x0=0, ax=ax, cmap=cmap, norm=norm\n",
")\n",
"mpl.colorbar.ColorbarBase(cm_ax, cmap=cmap, norm=norm, orientation=\"vertical\")\n",
"ax.set_ylabel(\"Energy (eV)\")\n",
"ax.set_xticks([0, 3])\n",
"ax.set_xticklabels([\"Kpoint-0\", \"Kpoint-1\"])"
]
},
Expand Down
Loading

0 comments on commit ba1e2b0

Please sign in to comment.