diff --git a/docs/source/content/defect-finder.ipynb b/docs/source/content/defect-finder.ipynb index 823d79e6..5ca67389 100644 --- a/docs/source/content/defect-finder.ipynb +++ b/docs/source/content/defect-finder.ipynb @@ -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", @@ -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)" ] }, { diff --git a/docs/source/content/defining-defects.ipynb b/docs/source/content/defining-defects.ipynb index 3e07479e..e99395fc 100644 --- a/docs/source/content/defining-defects.ipynb +++ b/docs/source/content/defining-defects.ipynb @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { diff --git a/docs/source/content/formation-energy.ipynb b/docs/source/content/formation-energy.ipynb index bc39f938..7119b060 100644 --- a/docs/source/content/formation-energy.ipynb +++ b/docs/source/content/formation-energy.ipynb @@ -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", @@ -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" ] }, { @@ -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\")" ] } ], diff --git a/docs/source/content/freysoldt-correction.ipynb b/docs/source/content/freysoldt-correction.ipynb index 988b943b..0dacba89 100644 --- a/docs/source/content/freysoldt-correction.ipynb +++ b/docs/source/content/freysoldt-correction.ipynb @@ -71,8 +71,6 @@ " 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", @@ -80,8 +78,7 @@ " 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()))" ] }, { @@ -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", @@ -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", @@ -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", @@ -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", @@ -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)" ] } ], diff --git a/docs/source/content/nonradiative.ipynb b/docs/source/content/nonradiative.ipynb index 5ee2f6d5..4020cc91 100644 --- a/docs/source/content/nonradiative.ipynb +++ b/docs/source/content/nonradiative.ipynb @@ -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" @@ -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", ")" ] }, @@ -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\")" ] }, { @@ -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))" ] }, { @@ -233,7 +223,7 @@ "hd1 = HarmonicDefect.from_directories(\n", " directories=dirs10,\n", " store_bandstructure=True,\n", - ")\n" + ")" ] }, { @@ -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}$]\");" diff --git a/docs/source/content/photo-conduct.ipynb b/docs/source/content/photo-conduct.ipynb index 95dd157b..7a6f1220 100644 --- a/docs/source/content/photo-conduct.ipynb +++ b/docs/source/content/photo-conduct.ipynb @@ -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)" ] }, @@ -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/\")" ] }, @@ -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." ] }, { @@ -96,8 +99,7 @@ "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", @@ -105,12 +107,14 @@ " 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", @@ -118,14 +122,11 @@ " 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)" ] @@ -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", @@ -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\"])" ] }, diff --git a/docs/source/content/quickstart.ipynb b/docs/source/content/quickstart.ipynb index a7933acc..a2be52d6 100644 --- a/docs/source/content/quickstart.ipynb +++ b/docs/source/content/quickstart.ipynb @@ -21,15 +21,6 @@ "To ensure that the namespace is installed properly run" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from pymatgen.analysis.defects.core import __file__" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -79,8 +70,7 @@ " species=Species(\"Mg\"), coords=ga_site.frac_coords, lattice=gan_struct.lattice\n", ")\n", "# instantiate the defect object\n", - "mg_ga = Substitution(structure=gan_struct, site=mg_site)\n", - "print(mg_ga)" + "mg_ga = Substitution(structure=gan_struct, site=mg_site)" ] }, { @@ -127,7 +117,6 @@ "\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", diff --git a/pymatgen/analysis/defects/plotting/thermo.py b/pymatgen/analysis/defects/plotting/thermo.py index ee372a8a..0903c636 100644 --- a/pymatgen/analysis/defects/plotting/thermo.py +++ b/pymatgen/analysis/defects/plotting/thermo.py @@ -25,7 +25,7 @@ from labellines import labelLines except ImportError: - def labelLines(*args, **kwargs) -> None: # noqa: ARG001, ANN002 + def labelLines(*args, **kwargs) -> None: # noqa: ANN002 """Dummy function if labellines is not installed.""" diff --git a/pymatgen/analysis/defects/recombination.py b/pymatgen/analysis/defects/recombination.py index 8764338a..ad96fccb 100644 --- a/pymatgen/analysis/defects/recombination.py +++ b/pymatgen/analysis/defects/recombination.py @@ -278,7 +278,7 @@ def pchip_eval( return ( interp_func(x) * np.sum(y_coarse) - / np.trapz(np.nan_to_num(interp_func(interp_domain)), x=interp_domain) + / np.trapezoid(np.nan_to_num(interp_func(interp_domain)), x=interp_domain) ) diff --git a/tutorials/1-quickstart.ipynb b/tutorials/1-quickstart.ipynb index 3916f4f1..c10f2d18 100644 --- a/tutorials/1-quickstart.ipynb +++ b/tutorials/1-quickstart.ipynb @@ -21,15 +21,6 @@ "To ensure that the namespace is installed properly run" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from pymatgen.analysis.defects.core import __file__" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -78,8 +69,7 @@ " species=Species(\"Mg\"), coords=ga_site.frac_coords, lattice=gan_struct.lattice\n", ")\n", "# instantiate the defect object\n", - "mg_ga = Substitution(structure=gan_struct, site=mg_site)\n", - "print(mg_ga)" + "mg_ga = Substitution(structure=gan_struct, site=mg_site)" ] }, { @@ -126,7 +116,6 @@ "\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", diff --git a/tutorials/2-defining-defects.ipynb b/tutorials/2-defining-defects.ipynb index 85ca19fd..15ca89aa 100644 --- a/tutorials/2-defining-defects.ipynb +++ b/tutorials/2-defining-defects.ipynb @@ -54,7 +54,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" ] }, { @@ -88,7 +88,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" ] }, { @@ -122,14 +122,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" ] }, { diff --git a/tutorials/3-nonradiative-capture.ipynb b/tutorials/3-nonradiative-capture.ipynb index 189b5569..3a4aba89 100644 --- a/tutorials/3-nonradiative-capture.ipynb +++ b/tutorials/3-nonradiative-capture.ipynb @@ -57,12 +57,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 with the lowest average IPR.\"\n", ")" ] },