Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix a typo #3609

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pymatgen/analysis/interfaces/coherent_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _find_terminations(self):
film_slabs = film_sg.get_slabs()
sub_slabs = sub_sg.get_slabs()

film_shits = [s.shift for s in film_slabs]
film_shifts = [s.shift for s in film_slabs]
film_terminations = [label_termination(s) for s in film_slabs]

sub_shifts = [s.shift for s in sub_slabs]
Expand All @@ -138,7 +138,7 @@ def _find_terminations(self):
self._terminations = {
(film_label, sub_label): (film_shift, sub_shift)
for (film_label, film_shift), (sub_label, sub_shift) in product(
zip(film_terminations, film_shits), zip(sub_terminations, sub_shifts)
zip(film_terminations, film_shifts), zip(sub_terminations, sub_shifts)
)
}
self.terminations = list(self._terminations)
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,11 @@ def get_voronoi_polyhedra(self, structure: Structure, n: int):
cell_info = self._extract_cell_info(0, neighbors, targets, voro, self.compute_adj_neighbors)
break

except RuntimeError as e:
except RuntimeError as exc:
if cutoff >= max_cutoff:
if e.args and "vertex" in e.args[0]:
if exc.args and "vertex" in exc.args[0]:
# pass through the error raised by _extract_cell_info
raise e
raise exc
raise RuntimeError("Error in Voronoi neighbor finding; max cutoff exceeded")
cutoff = min(cutoff * 2, max_cutoff + 0.001)
return cell_info
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/analysis/magnetism/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ def _round_magmoms(magmoms: ArrayLike, round_magmoms_mode: float) -> np.ndarray:
# round magmoms to these extrema
magmoms = [extrema[(np.abs(extrema - m)).argmin()] for m in magmoms]

except Exception as e:
except Exception as exc:
# TODO: typically a singular matrix warning, investigate this
warnings.warn("Failed to round magmoms intelligently, falling back to simple rounding.")
warnings.warn(str(e))
warnings.warn(str(exc))

# and finally round roughly to the number of significant figures in our kde width
num_decimals = len(str(round_magmoms_mode).split(".")[1]) + 1
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/analysis/magnetism/jahnteller.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def is_jahn_teller_active(
op_threshold=op_threshold,
)
active = analysis["active"]
except Exception as e:
warnings.warn(f"Error analyzing {structure.composition.reduced_formula}: {e}")
except Exception as exc:
warnings.warn(f"Error analyzing {structure.composition.reduced_formula}: {exc}")

return active

Expand Down Expand Up @@ -326,8 +326,8 @@ def tag_structure(
jt_sites[index] = True
structure.add_site_property("possible_jt_active", jt_sites)
return structure
except Exception as e:
warnings.warn(f"Error analyzing {structure.composition.reduced_formula}: {e}")
except Exception as exc:
warnings.warn(f"Error analyzing {structure.composition.reduced_formula}: {exc}")
return structure

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/analysis/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,9 +1776,9 @@ def get_decomposition(self, comp: Composition) -> dict[PDEntry, float]:
try:
pd = self.get_pd_for_entry(comp)
return pd.get_decomposition(comp)
except ValueError as e:
except ValueError as exc:
# NOTE warn when stitching across pds is being used
warnings.warn(f"{e} Using SLSQP to find decomposition")
warnings.warn(f"{exc} Using SLSQP to find decomposition")
competing_entries = self._get_stable_entries_in_space(frozenset(comp.elements))
return _get_slsqp_decomp(comp, competing_entries)

Expand Down
4 changes: 2 additions & 2 deletions pymatgen/electronic_structure/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ def get_fermi_interextrapolated(
"""
try:
return self.get_fermi(concentration, temperature, **kwargs)
except ValueError as e:
except ValueError as exc:
if warn:
warnings.warn(str(e))
warnings.warn(str(exc))

if abs(concentration) < c_ref:
if abs(concentration) < 1e-10:
Expand Down
14 changes: 7 additions & 7 deletions pymatgen/ext/matproj_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,14 +992,14 @@ def query(
return self._make_request("/query", payload=payload, method="POST", mp_decode=mp_decode)

data = []
mids = [d["material_id"] for d in self.query(criteria, ["material_id"], chunk_size=0)]
mids = [dct["material_id"] for dct in self.query(criteria, ["material_id"], chunk_size=0)]
chunks = get_chunks(mids, size=chunk_size)
progress_bar = tqdm(total=len(mids), disable=not show_progress_bar)
for chunk in chunks:
chunk_criteria = criteria.copy()
chunk_criteria.update({"material_id": {"$in": chunk}})
num_tries = 0
while num_tries < max_tries_per_chunk:
n_tries = 0
while n_tries < max_tries_per_chunk:
try:
data += self.query(
chunk_criteria,
Expand All @@ -1008,12 +1008,12 @@ def query(
mp_decode=mp_decode,
)
break
except MPRestError as e:
match = re.search(r"error status code (\d+)", str(e))
except MPRestError as exc:
match = re.search(r"error status code (\d+)", str(exc))
if match:
if not match.group(1).startswith("5"):
raise e
num_tries += 1
raise exc
n_tries += 1
print(
"Unknown server error. Trying again in five "
f"seconds (will try at most {max_tries_per_chunk} times)..."
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/abinit/abitimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def parse(self, filenames):
self._read(file, filename)
read_ok.append(filename)

except self.Error as e:
logger.warning(f"exception while parsing file {filename}:\n{e}")
except self.Error as exc:
logger.warning(f"exception while parsing file {filename}:\n{exc}")
continue

finally:
Expand Down
12 changes: 6 additions & 6 deletions pymatgen/io/vasp/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def _try_reading(dtypes):
for dtype in dtypes:
try:
return Waveder.from_binary(f"{directory}/WAVEDER", data_type=dtype)
except ValueError as e:
if "reshape" in str(e):
except ValueError as exc:
if "reshape" in str(exc):
continue
raise e
raise exc
return None

vrun = Vasprun(f"{directory}/vasprun.xml")
Expand Down Expand Up @@ -386,10 +386,10 @@ def epsilon_imag(
try:
min_band0, max_band0 = np.min(np.where(cderm)[0]), np.max(np.where(cderm)[0])
min_band1, max_band1 = np.min(np.where(cderm)[1]), np.max(np.where(cderm)[1])
except ValueError as e:
if "zero-size array" in str(e):
except ValueError as exc:
if "zero-size array" in str(exc):
return egrid, np.zeros_like(egrid, dtype=np.complex_)
raise e
raise exc
_, _, nk, nspin = cderm.shape[:4]
iter_idx = [
range(min_band0, max_band0 + 1),
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,12 @@ def parse_atomic_symbol(symbol):
try:
return str(Element(symbol))
# vasprun.xml uses X instead of Xe for xenon
except ValueError as e:
except ValueError as exc:
if symbol == "X":
return "Xe"
if symbol == "r":
return "Zr"
raise e
raise exc

elem.clear()
return [parse_atomic_symbol(sym) for sym in atomic_symbols], potcar_symbols
Expand Down
10 changes: 5 additions & 5 deletions pymatgen/util/due.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def _donothing(self, *args, **kwargs):
def dcite(self, *args, **kwargs):
"""If I could cite I would."""

def nondecorating_decorator(func):
def non_decorating_decorator(func):
return func

return nondecorating_decorator
return non_decorating_decorator

active = False
activate = add = cite = dump = load = _donothing
Expand All @@ -49,9 +49,9 @@ def _donothing_func(*args, **kwargs):

if "due" in locals() and not hasattr(due, "cite"):
raise RuntimeError("Imported due lacks .cite. DueCredit is now disabled")
except Exception as e:
if not isinstance(e, ImportError):
logging.getLogger("duecredit").error("Failed to import duecredit due to %s" % str(e))
except Exception as exc:
if not isinstance(exc, ImportError):
logging.getLogger("duecredit").error("Failed to import duecredit due to %s" % str(exc))
# Initiate due stub
due = InactiveDueCreditCollector()
BibTeX = Doi = Url = Text = _donothing_func