Skip to content

Commit aa8c735

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ad1f1d1 commit aa8c735

13 files changed

+72
-117
lines changed

docs/source/content/defect-finder.ipynb

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
"from pathlib import Path\n",
2626
"\n",
2727
"import numpy as np\n",
28-
"from pymatgen.io.vasp import Locpot\n",
2928
"\n",
3029
"TEST_FILES = Path(\"../../../tests/test_files\")\n",
31-
"import glob\n",
3230
"\n",
3331
"from pymatgen.analysis.defects.finder import DefectSiteFinder\n",
3432
"from pymatgen.core.structure import Structure\n",
@@ -37,11 +35,10 @@
3735
"finder = DefectSiteFinder()\n",
3836
"\n",
3937
"for q in range(-1, 3):\n",
40-
" fname = f\"{str(TEST_FILES)}/v_N_GaN/q={q}/CONTCAR.gz\"\n",
38+
" fname = f\"{TEST_FILES!s}/v_N_GaN/q={q}/CONTCAR.gz\"\n",
4139
" struct = Structure.from_file(fname)\n",
4240
" fpos = finder.get_defect_fpos(defect_structure=struct, base_structure=base_struct)\n",
43-
" fpos -= np.round(fpos)\n",
44-
" print(fpos)"
41+
" fpos -= np.round(fpos)"
4542
]
4643
},
4744
{

docs/source/content/defining-defects.ipynb

+8-12
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"if (\n",
5959
" bulk.lattice == bulk.get_primitive_structure().lattice\n",
6060
"): # check that you have the primitive structure\n",
61-
" print(\"The bulk unit cell is the unique primitive WS cell\")"
61+
" pass"
6262
]
6363
},
6464
{
@@ -92,7 +92,7 @@
9292
"mg_ga_defect0 = Substitution(structure=bulk, site=mg_site0)\n",
9393
"mg_ga_defect1 = Substitution(structure=bulk, site=mg_site1)\n",
9494
"if mg_ga_defect0 == mg_ga_defect1:\n",
95-
" print(\"The two Mg_Ga defects are equivalent.\")"
95+
" pass"
9696
]
9797
},
9898
{
@@ -125,14 +125,10 @@
125125
"vac_defect1 = Vacancy(structure=bulk, site=n_site0)\n",
126126
"vac_defect2 = Vacancy(structure=bulk, site=n_site1)\n",
127127
"if vac_defect0 != vac_defect1:\n",
128-
" print(\n",
129-
" f\"The two vacancies {vac_defect0.name} and {vac_defect1.name} are not equivalent.\"\n",
130-
" )\n",
128+
" pass\n",
131129
"\n",
132130
"if vac_defect2 == vac_defect1:\n",
133-
" print(\n",
134-
" f\"The two vacancies {vac_defect2.name} and {vac_defect1.name} are equivalent.\"\n",
135-
" )"
131+
" pass"
136132
]
137133
},
138134
{
@@ -260,8 +256,8 @@
260256
"\n",
261257
"chgcar = Chgcar.from_file(TEST_FILES / \"CHGCAR.Fe3O4.vasp\")\n",
262258
"cig = ChargeInterstitialGenerator()\n",
263-
"for defect in cig.generate(chgcar, insert_species=[\"H\"]):\n",
264-
" print(defect)"
259+
"for _defect in cig.generate(chgcar, insert_species=[\"H\"]):\n",
260+
" pass"
265261
]
266262
},
267263
{
@@ -279,8 +275,8 @@
279275
},
280276
"outputs": [],
281277
"source": [
282-
"for defect in generate_all_native_defects(chgcar):\n",
283-
" print(defect)"
278+
"for _defect in generate_all_native_defects(chgcar):\n",
279+
" pass"
284280
]
285281
},
286282
{

docs/source/content/formation-energy.ipynb

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
"outputs": [],
6060
"source": [
6161
"import warnings\n",
62+
"\n",
6263
"from monty.serialization import loadfn\n",
6364
"from pymatgen.analysis.defects.thermo import FormationEnergyDiagram\n",
64-
"from pymatgen.io.vasp import Vasprun\n",
6565
"\n",
6666
"warnings.filterwarnings(\"ignore\")\n",
6767
"\n",
@@ -129,10 +129,9 @@
129129
"metadata": {},
130130
"outputs": [],
131131
"source": [
132-
"for i, p in enumerate(fed.chempot_limits):\n",
133-
" print(f\"Limits for the chemical potential changes for point {i}\")\n",
134-
" for k,v in p.items():\n",
135-
" print(f\"Δμ_{k} = {v:.2f} eV\")"
132+
"for _i, p in enumerate(fed.chempot_limits):\n",
133+
" for _k, _v in p.items():\n",
134+
" pass"
136135
]
137136
},
138137
{
@@ -164,10 +163,11 @@
164163
"outputs": [],
165164
"source": [
166165
"from pymatgen.analysis.defects.corrections.freysoldt import plot_plnr_avg\n",
166+
"\n",
167167
"plot_data = fed.defect_entries[1].corrections_metadata[\"freysoldt\"][\"plot_data\"]\n",
168168
"plot_plnr_avg(plot_data[0], title=\"Lattice Direction 1\")\n",
169169
"plot_plnr_avg(plot_data[1], title=\"Lattice Direction 2\")\n",
170-
"plot_plnr_avg(plot_data[2], title=\"Lattice Direction 3\")\n"
170+
"plot_plnr_avg(plot_data[2], title=\"Lattice Direction 3\")"
171171
]
172172
}
173173
],

docs/source/content/freysoldt-correction.ipynb

+6-10
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,14 @@
7171
" defect_structure=defect_locpot.structure, base_structure=bulk_locpot.structure\n",
7272
" )\n",
7373
" center -= np.round(center)\n",
74-
" print(f\"Computing Freysoldt Correction for: q={q}\")\n",
75-
" print(f\"center={center}\")\n",
7674
" freysoldt_results[q] = get_freysoldt_correction(\n",
7775
" q=q,\n",
7876
" dielectric=5,\n",
7977
" bulk_locpot=bulk_locpot,\n",
8078
" defect_locpot=defect_locpot,\n",
8179
" defect_frac_coords=center,\n",
8280
" )\n",
83-
" align = np.mean(list(freysoldt_results[q].metadata[\"alignments\"].values()))\n",
84-
" print(f\"alignment correction: {align}\")\n"
81+
" align = np.mean(list(freysoldt_results[q].metadata[\"alignments\"].values()))"
8582
]
8683
},
8784
{
@@ -103,7 +100,7 @@
103100
"metadata": {},
104101
"outputs": [],
105102
"source": [
106-
"def plot_sxd_output(q, direction, C, ax):\n",
103+
"def plot_sxd_output(q, direction, C, ax) -> None:\n",
107104
" \"\"\"Read the vline-eV-a#.dat files computed by the `sxdefectalign` program.\n",
108105
"\n",
109106
" Args:\n",
@@ -114,7 +111,7 @@
114111
" \"\"\"\n",
115112
" v_line_file = DEFECT_DIR / f\"q={q}/vline-eV-a{direction}.dat\"\n",
116113
" # split the file into blocks based on the location of the string \"&\"\n",
117-
" with open(v_line_file, \"r\") as f:\n",
114+
" with open(v_line_file) as f:\n",
118115
" blocks = f.read().split(\"&\")\n",
119116
"\n",
120117
" # convert each block into a list of lines and convert to a numpy array\n",
@@ -134,7 +131,7 @@
134131
" ax.legend()\n",
135132
"\n",
136133
"\n",
137-
"def comparison_plots(q):\n",
134+
"def comparison_plots(q) -> None:\n",
138135
" \"\"\"\"\"\"\n",
139136
" fig, axs = plt.subplots(3, 2, figsize=(15, 15), sharey=True)\n",
140137
" for direction in range(3):\n",
@@ -210,7 +207,7 @@
210207
"outputs": [],
211208
"source": [
212209
"def get_sxd_result(q):\n",
213-
" \"\"\"Read the output of sxdefectalign\"\"\"\n",
210+
" \"\"\"Read the output of sxdefectalign.\"\"\"\n",
214211
" fname = str(DEFECT_DIR / f\"q={q}/corr_align.out\")\n",
215212
" gen = reverse_readfile(fname)\n",
216213
" line = next(gen)\n",
@@ -225,8 +222,7 @@
225222
"source": [
226223
"for q in range(-1, 3):\n",
227224
" python_res = freysoldt_results[q].correction_energy\n",
228-
" sxd_res = get_sxd_result(q)\n",
229-
" print(f\"python: {python_res:0.4f} / sxdefectalign: {sxd_res:0.4f}\")"
225+
" sxd_res = get_sxd_result(q)"
230226
]
231227
}
232228
],

docs/source/content/nonradiative.ipynb

+8-16
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"source": [
2222
"# disable warnings\n",
2323
"import warnings\n",
24+
"\n",
2425
"warnings.filterwarnings(\"ignore\", category=UserWarning)\n",
2526
"from pathlib import Path\n",
27+
"\n",
2628
"import numpy as np\n",
2729
"from matplotlib import pyplot as plt\n",
2830
"from pymatgen.analysis.defects.ccd import HarmonicDefect, get_SRH_coefficient"
@@ -63,12 +65,6 @@
6365
"hd0 = HarmonicDefect.from_directories(\n",
6466
" directories=dirs01,\n",
6567
" store_bandstructure=True,\n",
66-
")\n",
67-
"print(f\"The relaxed structure is in dirs01[{hd0.relaxed_index}]\")\n",
68-
"print(hd0)\n",
69-
"print(\n",
70-
" f\"The spin channel ({hd0.spin}) is also automaticalliy determined by the \"\n",
71-
" \"IPR, by taking the spin channel who's defect states have the lowest average IPR across the different k-points.\"\n",
7268
")"
7369
]
7470
},
@@ -184,9 +180,7 @@
184180
"outputs": [],
185181
"source": [
186182
"wswq_dir = TEST_FILES / \"ccd_0_-1\" / \"wswqs\"\n",
187-
"print(f\"The parsed WSWQ files are: {[f.name for f in wswq_dir.glob('WSWQ*')]}\")\n",
188-
"hd0.read_wswqs(TEST_FILES / \"ccd_0_-1\" / \"wswqs\")\n",
189-
"print(f\"Parsed {len(hd0.wswqs)} WSWQ files.\")\n"
183+
"hd0.read_wswqs(TEST_FILES / \"ccd_0_-1\" / \"wswqs\")"
190184
]
191185
},
192186
{
@@ -205,11 +199,7 @@
205199
"metadata": {},
206200
"outputs": [],
207201
"source": [
208-
"print(f\"The automatically determined defect electronic states are: {hd0.defect_band} \"\n",
209-
" \"(with [band, k-point, spin] indexing).\")\n",
210-
"epME = hd0.get_elph_me(defect_state=(138, 1, 1))\n",
211-
"print(f\"The resulting array of shape {epME.shape} contains the matrix elements from the \"\n",
212-
" \"defect state to all other states at the same k-point.\")\n"
202+
"epME = hd0.get_elph_me(defect_state=(138, 1, 1))"
213203
]
214204
},
215205
{
@@ -233,7 +223,7 @@
233223
"hd1 = HarmonicDefect.from_directories(\n",
234224
" directories=dirs10,\n",
235225
" store_bandstructure=True,\n",
236-
")\n"
226+
")"
237227
]
238228
},
239229
{
@@ -252,7 +242,9 @@
252242
"outputs": [],
253243
"source": [
254244
"T = np.linspace(100, 1000, 20)\n",
255-
"srh_c = get_SRH_coefficient(initial_state=hd0, final_state=hd1, defect_state=(138, 1, 1), T=T, dE=0.3)\n",
245+
"srh_c = get_SRH_coefficient(\n",
246+
" initial_state=hd0, final_state=hd1, defect_state=(138, 1, 1), T=T, dE=0.3\n",
247+
")\n",
256248
"plt.plot(T, srh_c)\n",
257249
"plt.xlabel(\"Temperature [K]\")\n",
258250
"plt.ylabel(\"SRH coefficient [cm$^{-3}$s$^{-1}$]\");"

docs/source/content/photo-conduct.ipynb

+33-27
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
"outputs": [],
2626
"source": [
2727
"# disable tqdm progress bar\n",
28-
"from tqdm import tqdm\n",
2928
"from functools import partialmethod\n",
29+
"\n",
30+
"from tqdm import tqdm\n",
31+
"\n",
3032
"tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)\n",
3133
"# disable warnings\n",
3234
"import warnings\n",
35+
"\n",
3336
"warnings.filterwarnings(\"ignore\", category=UserWarning)"
3437
]
3538
},
@@ -40,13 +43,15 @@
4043
"metadata": {},
4144
"outputs": [],
4245
"source": [
46+
"import bisect\n",
47+
"import collections\n",
4348
"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",
4650
"import numpy as np\n",
4751
"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",
5055
"TEST_FILES = Path(\"../../../tests/test_files/v_Ga/\")"
5156
]
5257
},
@@ -71,9 +76,7 @@
7176
"dir0 = TEST_FILES / \"ccd_0_-1\" / \"optics\"\n",
7277
"hd0 = HarmonicDefect.from_directories(directories=[dir0], store_bandstructure=True)\n",
7378
"# 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."
7780
]
7881
},
7982
{
@@ -96,36 +99,34 @@
9699
"metadata": {},
97100
"outputs": [],
98101
"source": [
99-
"\n",
100-
"def print_eigs(vr, bwind=5, defect_bands = ()):\n",
102+
"def print_eigs(vr, bwind=5, defect_bands=()) -> None:\n",
101103
" \"\"\"Print the eigenvalues in a small band window around the Fermi level.\n",
102104
"\n",
103105
" Args:\n",
104106
" vr (Vasprun): The Vasprun object.\n",
105107
" bwind (int): The number of bands above and below the Fermi level to print.\n",
106108
" defect_bands (list): A list of tuples of the form (band index, kpt index, spin index)\n",
107109
" \"\"\"\n",
108-
" def _get_spin_idx(spin):\n",
110+
"\n",
111+
" def _get_spin_idx(spin) -> int:\n",
109112
" if spin == Spin.up:\n",
110113
" return 0\n",
111114
" return 1\n",
115+
"\n",
112116
" 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",
114118
" output = collections.defaultdict(list)\n",
115119
" for k, spin_eigs in vr.eigenvalues.items():\n",
116120
" spin_idx = _get_spin_idx(k)\n",
117121
" for kpt in range(spin_eigs.shape[0]):\n",
118122
" for ib in range(fermi_idx - bwind, fermi_idx + bwind):\n",
119123
" e, o = spin_eigs[kpt, ib, :]\n",
120124
" 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",
125126
" 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",
129130
"\n",
130131
"print_eigs(vr=hd0.vrun, defect_bands=hd0.defect_band)"
131132
]
@@ -177,7 +178,7 @@
177178
"metadata": {},
178179
"outputs": [],
179180
"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",
181182
"# plotting\n",
182183
"plt.plot(energy, np.imag(eps_vbm), label=\"VBM\")\n",
183184
"plt.plot(energy, np.imag(eps_cbm), label=\"CBM\")\n",
@@ -216,15 +217,20 @@
216217
"metadata": {},
217218
"outputs": [],
218219
"source": [
219-
"from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n",
220220
"import matplotlib as mpl\n",
221+
"from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n",
222+
"\n",
221223
"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",
228234
"ax.set_xticklabels([\"Kpoint-0\", \"Kpoint-1\"])"
229235
]
230236
},

0 commit comments

Comments
 (0)