Skip to content

Commit c72c9e9

Browse files
authored
Cleanup codespell ignore patterns (materialsproject#4175)
1 parent a09e7dd commit c72c9e9

30 files changed

+229
-217
lines changed

pyproject.toml

+10-5
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,17 @@ module = ["requests.*", "tabulate.*"]
293293
ignore_missing_imports = true
294294

295295
[tool.codespell]
296-
ignore-words-list = """
297-
titel,alls,ans,nd,mater,nwo,te,hart,ontop,ist,ot,fo,nax,coo,
298-
coul,ser,leary,thre,fase,rute,reson,titels,ges,scalr,strat,
299-
struc,hda,nin,ons,pres,kno,loos,lamda,lew,atomate,nempty
296+
# TODO: un-ignore "ist/nd/ot/ontop/CoO" once support file-level ignore with pattern
297+
ignore-words-list = """Nd, Te, titel, Mater,
298+
Hart, Lew, Rute, atomate,
299+
ist, nd, ot, ontop, CoO
300+
"""
301+
# TODO: un-skip lammps/test_inputs.py once support block ignore with pattern
302+
skip = """*.json,
303+
src/pymatgen/analysis/chemenv/coordination_environments/coordination_geometries_files/allcg.txt,
304+
src/pymatgen/entries/MPCompatibility.yaml,
305+
tests/io/lammps/test_inputs.py,
300306
"""
301-
skip = "pymatgen/analysis/aflow_prototypes.json"
302307
check-filenames = true
303308

304309
[tool.pyright]

src/pymatgen/analysis/bond_dissociation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BondDissociationEnergies(MSONable):
3030
fragments, or, in the case of a ring bond, from the energy of the molecule obtained from breaking
3131
the bond and opening the ring. This class should only be called after the energies of the optimized
3232
principle molecule and all relevant optimized fragments have been determined, either from quantum
33-
chemistry or elsewhere. It was written to provide the analysis after running an Atomate fragmentation
33+
chemistry or elsewhere. It was written to provide the analysis after running an `atomate` fragmentation
3434
workflow.
3535
"""
3636

src/pymatgen/analysis/chemenv/utils/graph_utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def _is_valid(self, check_strict_ordering=False):
175175
if check_strict_ordering:
176176
try:
177177
sorted_nodes = sorted(self.nodes)
178-
except TypeError as te:
179-
msg = te.args[0]
178+
except TypeError as exc:
179+
msg = exc.args[0]
180180
if "'<' not supported between instances of" in msg:
181181
return False, "The nodes are not sortable."
182182
raise
@@ -366,8 +366,8 @@ def _is_valid(self, check_strict_ordering=False):
366366
if check_strict_ordering:
367367
try:
368368
sorted_nodes = sorted(self.nodes)
369-
except TypeError as te:
370-
msg = te.args[0]
369+
except TypeError as exc:
370+
msg = exc.args[0]
371371
if "'<' not supported between instances of" in msg:
372372
return False, "The nodes are not sortable."
373373
raise

src/pymatgen/analysis/functional_groups.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ def get_special_carbon(self, elements=None):
169169

170170
neighbor_spec = [str(self.species[n]) for n in neighbors]
171171

172-
ons = sum(n in ["O", "N", "S"] for n in neighbor_spec)
173-
174-
if len(neighbors) == 4 and ons >= 2:
172+
if len(neighbors) == 4 and sum(n in ["O", "N", "S"] for n in neighbor_spec) >= 2:
175173
specials.add(node)
176174

177175
# Condition four: oxirane/aziridine/thiirane rings

src/pymatgen/analysis/graphs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,10 @@ def map_indices(grp: Molecule) -> dict[int, int]:
740740
else:
741741
if strategy_params is None:
742742
strategy_params = {}
743-
strat = strategy(**strategy_params)
743+
_strategy = strategy(**strategy_params)
744744

745745
for site in mapping.values():
746-
neighbors = strat.get_nn_info(self.structure, site)
746+
neighbors = _strategy.get_nn_info(self.structure, site)
747747

748748
for neighbor in neighbors:
749749
self.add_edge(

src/pymatgen/analysis/interface_reactions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def _reverse_convert(x: float, factor1: float, factor2: float):
528528
return x * factor1 / ((1 - x) * factor2 + x * factor1)
529529

530530
@classmethod
531-
def get_chempot_correction(cls, element: str, temp: float, pres: float):
531+
def get_chempot_correction(cls, element: str, temp: float, pres: float): # codespell:ignore pres
532532
"""Get the normalized correction term Δμ for chemical potential of a gas
533533
phase consisting of element at given temperature and pressure,
534534
referenced to that in the standard state (T_std = 298.15 K,
@@ -539,7 +539,7 @@ def get_chempot_correction(cls, element: str, temp: float, pres: float):
539539
Args:
540540
element: The string representing the element.
541541
temp: The temperature of the gas phase in Kelvin.
542-
pres: The pressure of the gas phase in Pa.
542+
pres: The pressure of the gas phase in Pa. # codespell:ignore pres
543543
544544
Returns:
545545
The correction of chemical potential in eV/atom of the gas
@@ -561,7 +561,7 @@ def get_chempot_correction(cls, element: str, temp: float, pres: float):
561561
cp_std = cp_dict[element]
562562
s_std = s_dict[element]
563563

564-
pv_correction = ideal_gas_const * temp * np.log(pres / std_pres)
564+
pv_correction = ideal_gas_const * temp * np.log(pres / std_pres) # codespell:ignore pres
565565
ts_correction = (
566566
-cp_std * (temp * np.log(temp) - std_temp * np.log(std_temp))
567567
+ cp_std * (temp - std_temp) * (1 + np.log(std_temp))

src/pymatgen/analysis/piezo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __new__(cls, input_array: ArrayLike, tol: float = 1e-3) -> Self:
4646
def from_vasp_voigt(cls, input_vasp_array: ArrayLike) -> Self:
4747
"""
4848
Args:
49-
input_vasp_array (nd.array): Voigt form of tensor.
49+
input_vasp_array (ArrayLike): Voigt form of tensor.
5050
5151
Returns:
5252
PiezoTensor

src/pymatgen/analysis/piezo_sensitivity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def get_piezo(BEC, IST, FCM, rcond=0.0001):
657657
)
658658

659659
K = np.reshape(K, (n_sites, 3, n_sites, 3)).swapaxes(1, 2)
660-
return np.einsum("ikl,ijlm,jmno->kno", BEC, K, IST) * 16.0216559424
660+
return np.einsum("ikl,ijlm,jmno->kno", BEC, K, IST) * 16.0216559424 # codespell:ignore kno
661661

662662

663663
@requires(Phonopy, "phonopy not installed!")

src/pymatgen/io/lmto.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def from_str(cls, data: str, sigfigs: int = 8) -> Self:
175175
"HEADER": [],
176176
"VERS": [],
177177
"SYMGRP": [],
178-
"STRUC": [],
178+
"STRUC": [], # codespell:ignore struc
179179
"CLASS": [],
180180
"SITE": [],
181181
}
@@ -200,7 +200,7 @@ def from_str(cls, data: str, sigfigs: int = 8) -> Self:
200200
}
201201

202202
atom = None
203-
for cat in ("STRUC", "CLASS", "SITE"):
203+
for cat in ("STRUC", "CLASS", "SITE"): # codespell:ignore struc
204204
fields = struct_lines[cat].split("=")
205205
for idx, field in enumerate(fields):
206206
token = field.split()[-1]

src/pymatgen/io/lobster/outputs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,9 @@ def _parse_doscar(self):
768768
cdos = np.zeros((ndos, len(line)))
769769
cdos[0] = np.array(line)
770770

771-
for nd in range(1, ndos):
771+
for idx_dos in range(1, ndos):
772772
line_parts = file.readline().split()
773-
cdos[nd] = np.array(line_parts)
773+
cdos[idx_dos] = np.array(line_parts)
774774
dos.append(cdos)
775775

776776
line = file.readline() # Read the next line to continue the loop

src/pymatgen/io/qchem/outputs.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def __init__(self, filename: str):
481481
self.text,
482482
{
483483
"had": r"H_ad = (?:[\-\.0-9]+) \(([\-\.0-9]+) meV\)",
484-
"hda": r"H_da = (?:[\-\.0-9]+) \(([\-\.0-9]+) meV\)",
484+
"hda": r"H_da = (?:[\-\.0-9]+) \(([\-\.0-9]+) meV\)", # codespell:ignore hda
485485
"coupling": r"The (?:averaged )?electronic coupling: (?:[\-\.0-9]+) \(([\-\.0-9]+) meV\)",
486486
},
487487
)
@@ -490,10 +490,10 @@ def __init__(self, filename: str):
490490
self.data["fodft_had_eV"] = None
491491
else:
492492
self.data["fodft_had_eV"] = float(temp_dict["had"][0][0]) / 1000
493-
if temp_dict.get("hda") is None or len(temp_dict.get("hda", [])) == 0:
493+
if temp_dict.get("hda") is None or len(temp_dict.get("hda", [])) == 0: # codespell:ignore hda
494494
self.data["fodft_hda_eV"] = None
495495
else:
496-
self.data["fodft_hda_eV"] = float(temp_dict["hda"][0][0]) / 1000
496+
self.data["fodft_hda_eV"] = float(temp_dict["hda"][0][0]) / 1000 # codespell:ignore hda
497497
if temp_dict.get("coupling") is None or len(temp_dict.get("coupling", [])) == 0:
498498
self.data["fodft_coupling_eV"] = None
499499
else:
@@ -1523,7 +1523,7 @@ def _read_optimization_data(self):
15231523
self.data["errors"] += ["out_of_opt_cycles"]
15241524
elif read_pattern(
15251525
self.text,
1526-
{"key": r"UNABLE TO DETERMINE Lamda IN FormD"},
1526+
{"key": r"UNABLE TO DETERMINE Lamda IN FormD"}, # codespell:ignore lamda
15271527
terminate_on_match=True,
15281528
).get("key") == [[]]:
15291529
self.data["errors"] += ["unable_to_determine_lamda"]
@@ -1746,7 +1746,7 @@ def _read_scan_data(self):
17461746
self.data["errors"] += ["out_of_opt_cycles"]
17471747
elif read_pattern(
17481748
self.text,
1749-
{"key": r"UNABLE TO DETERMINE Lamda IN FormD"},
1749+
{"key": r"UNABLE TO DETERMINE Lamda IN FormD"}, # codespell:ignore lamda
17501750
terminate_on_match=True,
17511751
).get("key") == [[]]:
17521752
self.data["errors"] += ["unable_to_determine_lamda"]

src/pymatgen/io/res.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,13 @@ def _res_from_structure(cls, structure: Structure) -> Res:
305305
def _res_from_entry(cls, entry: ComputedStructureEntry) -> Res:
306306
"""Produce a res file structure from a pymatgen ComputedStructureEntry."""
307307
seed = entry.data.get("seed") or str(hash(entry))
308-
pres = float(entry.data.get("pressure", 0))
308+
pressure = float(entry.data.get("pressure", 0))
309309
isd = float(entry.data.get("isd", 0))
310310
iasd = float(entry.data.get("iasd", 0))
311311
spg, _ = entry.structure.get_space_group_info()
312312
rems = [str(x) for x in entry.data.get("rems", [])]
313313
return Res(
314-
AirssTITL(seed, pres, entry.structure.volume, entry.energy, isd, iasd, spg, 1),
314+
AirssTITL(seed, pressure, entry.structure.volume, entry.energy, isd, iasd, spg, 1),
315315
rems,
316316
cls._cell_from_lattice(entry.structure.lattice),
317317
cls._sfac_from_sites(list(entry.structure)),

src/pymatgen/io/vasp/outputs.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ def read_chemical_shielding(self) -> None:
24952495
List of chemical shieldings in the order of atoms from the OUTCAR. Maryland notation is adopted.
24962496
"""
24972497
header_pattern = (
2498-
r"\s+CSA tensor \(J\. Mason, Solid State Nucl\. Magn\. Reson\. 2, "
2498+
r"\s+CSA tensor \(J\. Mason, Solid State Nucl\. Magn\. Reson\. 2, " # codespell:ignore reson
24992499
r"285 \(1993\)\)\s+"
25002500
r"\s+-{50,}\s+"
25012501
r"\s+EXCLUDING G=0 CONTRIBUTION\s+INCLUDING G=0 CONTRIBUTION\s+"
@@ -3902,23 +3902,23 @@ class Procar(MSONable):
39023902
Attributes:
39033903
data (dict): The PROCAR data of the form below. It should VASP uses 1-based indexing,
39043904
but all indices are converted to 0-based here.
3905-
{ spin: nd.array accessed with (k-point index, band index, ion index, orbital index) }
3906-
weights (np.array): The weights associated with each k-point as an nd.array of length nkpoints.
3905+
{ spin: np.array accessed with (k-point index, band index, ion index, orbital index) }
3906+
weights (np.array): The weights associated with each k-point as an np.array of length nkpoints.
39073907
phase_factors (dict): Phase factors, where present (e.g. LORBIT = 12). A dict of the form:
3908-
{ spin: complex nd.array accessed with (k-point index, band index, ion index, orbital index) }
3908+
{ spin: complex np.array accessed with (k-point index, band index, ion index, orbital index) }
39093909
nbands (int): Number of bands.
39103910
nkpoints (int): Number of k-points.
39113911
nions (int): Number of ions.
39123912
nspins (int): Number of spins.
39133913
is_soc (bool): Whether the PROCAR contains spin-orbit coupling (LSORBIT = True) data.
3914-
kpoints (np.array): The k-points as an nd.array of shape (nkpoints, 3).
3914+
kpoints (np.array): The k-points as an np.array of shape (nkpoints, 3).
39153915
occupancies (dict): The occupancies of the bands as a dict of the form:
3916-
{ spin: nd.array accessed with (k-point index, band index) }
3916+
{ spin: np.array accessed with (k-point index, band index) }
39173917
eigenvalues (dict): The eigenvalues of the bands as a dict of the form:
3918-
{ spin: nd.array accessed with (k-point index, band index) }
3918+
{ spin: np.array accessed with (k-point index, band index) }
39193919
xyz_data (dict): The PROCAR projections data along the x,y and z magnetisation projection
39203920
directions, with is_soc = True (see VASP wiki for more info).
3921-
{ 'x'/'y'/'z': nd.array accessed with (k-point index, band index, ion index, orbital index) }
3921+
{ 'x'/'y'/'z': np.array accessed with (k-point index, band index, ion index, orbital index) }
39223922
"""
39233923

39243924
def __init__(self, filename: PathLike | list[PathLike]):

src/pymatgen/io/vasp/sets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ def incar_updates(self) -> dict[str, Any]:
20192019
SIGMA=0.01,
20202020
)
20212021
elif self.mode.lower() == "efg" and self.structure is not None:
2022-
isotopes = {ist.split("-")[0]: ist for ist in self.isotopes}
2022+
isotopes = {isotope.split("-")[0]: isotope for isotope in self.isotopes}
20232023
quad_efg = [
20242024
float(Species(sp.name).get_nmr_quadrupole_moment(isotopes.get(sp.name)))
20252025
for sp in self.structure.species

src/pymatgen/phonon/bandstructure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_reasonable_repetitions(n_atoms: int) -> Tuple3Ints:
3939

4040
def eigenvectors_from_displacements(disp: np.ndarray, masses: np.ndarray) -> np.ndarray:
4141
"""Calculate the eigenvectors from the atomic displacements."""
42-
return np.einsum("nax,a->nax", disp, masses**0.5)
42+
return np.einsum("nax,a->nax", disp, masses**0.5) # codespell:ignore nax
4343

4444

4545
def estimate_band_connection(prev_eigvecs, eigvecs, prev_band_order) -> list[int]:

src/pymatgen/phonon/thermal_displacements.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def visualize_directionality_quality_criterion(
352352
f"{structure.lattice.alpha} {structure.lattice.beta} {structure.lattice.gamma}\n"
353353
)
354354
file.write(" 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000\n") # error on parameters
355-
file.write("STRUC\n")
355+
file.write("STRUC\n") # codespell:ignore struc
356356

357357
for site_idx, site in enumerate(structure, start=1):
358358
file.write(

src/pymatgen/transformations/advanced_transformations.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -854,27 +854,27 @@ def apply_transformation(
854854

855855
trafo = EnumerateStructureTransformation(**enum_kwargs)
856856

857-
alls = trafo.apply_transformation(structure, return_ranked_list=return_ranked_list)
857+
all_structs = trafo.apply_transformation(structure, return_ranked_list=return_ranked_list)
858858

859859
# handle the fact that EnumerateStructureTransformation can either
860860
# return a single Structure or a list
861-
if isinstance(alls, Structure):
861+
if isinstance(all_structs, Structure):
862862
# remove dummy species and replace Spin.up or Spin.down
863863
# with spin magnitudes given in mag_species_spin arg
864-
alls = self._remove_dummy_species(alls)
865-
alls = self._add_spin_magnitudes(alls) # type: ignore[arg-type]
864+
all_structs = self._remove_dummy_species(all_structs)
865+
all_structs = self._add_spin_magnitudes(all_structs) # type: ignore[arg-type]
866866
else:
867-
for idx, struct in enumerate(alls):
868-
alls[idx]["structure"] = self._remove_dummy_species(struct["structure"]) # type: ignore[index]
869-
alls[idx]["structure"] = self._add_spin_magnitudes(struct["structure"]) # type: ignore[index, arg-type]
867+
for idx, struct in enumerate(all_structs):
868+
all_structs[idx]["structure"] = self._remove_dummy_species(struct["structure"]) # type: ignore[index]
869+
all_structs[idx]["structure"] = self._add_spin_magnitudes(struct["structure"]) # type: ignore[index, arg-type]
870870

871871
try:
872872
num_to_return = int(return_ranked_list)
873873
except ValueError:
874874
num_to_return = 1
875875

876876
if num_to_return == 1 or not return_ranked_list:
877-
return alls[0]["structure"] if num_to_return else alls # type: ignore[return-value, index]
877+
return all_structs[0]["structure"] if num_to_return else all_structs # type: ignore[return-value, index]
878878

879879
# Remove duplicate structures and group according to energy model
880880
matcher = StructureMatcher(comparator=SpinComparator())
@@ -883,7 +883,7 @@ def key(struct: Structure) -> int:
883883
return SpacegroupAnalyzer(struct, 0.1).get_space_group_number()
884884

885885
out = []
886-
for _, group in groupby(sorted((dct["structure"] for dct in alls), key=key), key): # type: ignore[arg-type, index]
886+
for _, group in groupby(sorted((dct["structure"] for dct in all_structs), key=key), key): # type: ignore[arg-type, index]
887887
group = list(group) # type: ignore[assignment]
888888
grouped = matcher.group_structures(group)
889889
out.extend([{"structure": g[0], "energy": self.energy_model.get_energy(g[0])} for g in grouped])

src/pymatgen/vis/structure_vtk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def add_partial_sphere(self, coords, radius, color, start=0, end=360, opacity=1.
357357
Adding a partial sphere (to display partial occupancies.
358358
359359
Args:
360-
coords (nd.array): Coordinates
360+
coords (np.array): Coordinates
361361
radius (float): Radius of sphere
362362
color (tuple): RGB color of sphere
363363
start (float): Starting angle.

tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_coordination_geometry(self):
212212
"PB:7",
213213
"ST:7",
214214
"ET:7",
215-
"FO:7",
215+
"FO:7", # codespell:ignore fo
216216
"C:8",
217217
"SA:8",
218218
"SBT:8",
@@ -389,9 +389,9 @@ def test_coordination_geometry(self):
389389
(0, 4, 2): ["T:6"],
390390
},
391391
7: {
392-
(1, 3, 3): ["ET:7", "FO:7"],
392+
(1, 3, 3): ["ET:7", "FO:7"], # codespell:ignore fo
393393
(2, 3, 2): ["PB:7", "ST:7", "ET:7"],
394-
(1, 4, 2): ["ST:7", "FO:7"],
394+
(1, 4, 2): ["ST:7", "FO:7"], # codespell:ignore fo
395395
(1, 5, 1): ["PB:7"],
396396
},
397397
8: {

0 commit comments

Comments
 (0)