Skip to content

Commit

Permalink
Ruff fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Aug 15, 2024
1 parent 1a4c538 commit 74befc8
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 137 deletions.
21 changes: 0 additions & 21 deletions .devcontainer/devcontainer.json

This file was deleted.

84 changes: 0 additions & 84 deletions .devcontainer/repro_template.ipynb

This file was deleted.

3 changes: 1 addition & 2 deletions src/pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4184,8 +4184,7 @@ def __init__(self, cut_off_dict: dict | None = None) -> None:
for (sp1, sp2), dist in self.cut_off_dict.items():
lookup_dict[sp1][sp2] = dist
lookup_dict[sp2][sp1] = dist
if dist > self._max_dist:
self._max_dist = dist
self._max_dist = max(dist, self._max_dist)
self._lookup_dict = lookup_dict

@property
Expand Down
3 changes: 1 addition & 2 deletions src/pymatgen/analysis/molecule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ def _virtual_molecule(self, mol, ilabels, eq_atoms):
for idx in range(1, vmol.NumAtoms() + 1):
va = vmol.GetAtom(idx)
distance = math.sqrt((c1x - va.x()) ** 2 + (c1y - va.y()) ** 2 + (c1z - va.z()) ** 2)
if distance < min_distance:
min_distance = distance
min_distance = min(distance, min_distance)
if min_distance > 0.2:
a1 = vmol.NewAtom()
a1.SetAtomicNum(9)
Expand Down
3 changes: 1 addition & 2 deletions src/pymatgen/analysis/surface_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,7 @@ def monolayer_vs_BE(self, plot_eads=False):
if ads_entry.get_monolayer not in ml_be_dict:
ml_be_dict[ads_entry.get_monolayer] = 1000
be = ads_entry.gibbs_binding_energy(eads=plot_eads)
if be < ml_be_dict[ads_entry.get_monolayer]:
ml_be_dict[ads_entry.get_monolayer] = be
ml_be_dict[ads_entry.get_monolayer] = min(be, ml_be_dict[ads_entry.get_monolayer])
# sort the binding energies and monolayers
# in order to properly draw a line plot
vals = sorted(ml_be_dict.items())
Expand Down
3 changes: 1 addition & 2 deletions src/pymatgen/cli/pmg_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def get_magnetizations(dirc: str, ion_list: list[int]):
for ion in all_ions:
row.append(str(_mags[ion]))
data.append(row)
if len(all_ions) > max_row:
max_row = len(all_ions)
max_row = max(len(all_ions), max_row)
except Exception:
pass

Expand Down
3 changes: 1 addition & 2 deletions src/pymatgen/core/molecular_orbitals.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def max_electronegativity(self) -> float:
"""
maximum: float = 0.0
for e1, e2 in combinations(self.elements, 2):
if abs(Element(e1).X - Element(e2).X) > maximum:
maximum = abs(Element(e1).X - Element(e2).X)
maximum = max(abs(Element(e1).X - Element(e2).X), maximum)
return maximum

def aos_as_list(self) -> list[tuple[str, str, float]]:
Expand Down
3 changes: 1 addition & 2 deletions src/pymatgen/electronic_structure/boltztrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@ def run(
run_type = self.run_type
if run_type in ("BANDS", "DOS", "FERMI"):
convergence = False
if self.lpfac > max_lpfac:
max_lpfac = self.lpfac
max_lpfac = max(self.lpfac, max_lpfac)

if run_type == "BANDS" and self.bs.is_spin_polarized:
print(
Expand Down
6 changes: 2 additions & 4 deletions src/pymatgen/electronic_structure/cohp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,14 +1344,12 @@ def extremum_icohpvalue(
for value in self._icohplist.values():
if not value.is_spin_polarized or not summed_spin_channels:
if not self._are_coops and not self._are_cobis:
if value.icohpvalue(spin) < extremum:
extremum = value.icohpvalue(spin)
extremum = min(value.icohpvalue(spin), extremum)
elif value.icohpvalue(spin) > extremum:
extremum = value.icohpvalue(spin)

elif not self._are_coops and not self._are_cobis:
if value.summed_icohp < extremum:
extremum = value.summed_icohp
extremum = min(value.summed_icohp, extremum)

elif value.summed_icohp > extremum:
extremum = value.summed_icohp
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/io/abinit/pseudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import traceback
from collections import defaultdict
from typing import TYPE_CHECKING, NamedTuple
from xml.etree import ElementTree as Et
from xml.etree import ElementTree as ET

import numpy as np
from monty.collections import AttrDict, Namespace
Expand Down Expand Up @@ -1242,7 +1242,7 @@ def __getstate__(self):
@lazy_property
def root(self):
"""Root tree of XML."""
tree = Et.parse(self.filepath)
tree = ET.parse(self.filepath)
return tree.getroot()

@property
Expand Down
6 changes: 3 additions & 3 deletions src/pymatgen/io/cp2k/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ def activate_fast_minimization(self, on) -> None:
algorithm="IRAC",
linesearch="2PNT",
)
self |= {"FORCE_EVAL": {"DFT": {"SCF": {"OT": ot}}}} # type: ignore[assignment]
self.update({"FORCE_EVAL": {"DFT": {"SCF": {"OT": ot}}}}) # type: ignore[assignment]

def activate_robust_minimization(self) -> None:
"""Modify the set to use more robust SCF minimization technique."""
Expand All @@ -1190,7 +1190,7 @@ def activate_robust_minimization(self) -> None:
algorithm="STRICT",
linesearch="3PNT",
)
self |= {"FORCE_EVAL": {"DFT": {"SCF": {"OT": ot}}}} # type: ignore[assignment]
self.update({"FORCE_EVAL": {"DFT": {"SCF": {"OT": ot}}}}) # type: ignore[assignment]

def activate_very_strict_minimization(self) -> None:
"""Method to modify the set to use very strict SCF minimization scheme."""
Expand All @@ -1200,7 +1200,7 @@ def activate_very_strict_minimization(self) -> None:
algorithm="STRICT",
linesearch="GOLD",
)
self |= {"FORCE_EVAL": {"DFT": {"SCF": {"OT": ot}}}} # type: ignore[assignment]
self.update({"FORCE_EVAL": {"DFT": {"SCF": {"OT": ot}}}}) # type: ignore[assignment]

def activate_nonperiodic(self, solver="ANALYTIC") -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion src/pymatgen/io/lobster/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def write_lobsterin(
overwritedict (dict): dict that can be used to update lobsterin, e.g. {"skipdos": True}
"""
# Update previous entries
self |= {} if overwritedict is None else overwritedict
if overwritedict is not None:
self.update(overwritedict)

with open(path, mode="w", encoding="utf-8") as file:
for key in self:
Expand Down
3 changes: 1 addition & 2 deletions src/pymatgen/io/nwchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,7 @@ def get_excitation_spectrum(self, width=0.1, npoints=2000):
de = (emax - emin) / npoints

# Use width of at least two grid points
if width < 2 * de:
width = 2 * de
width = max(width, 2 * de)

energies = [emin + ie * de for ie in range(npoints)]

Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2742,9 +2742,9 @@ def __init__(
"""
super().__init__(**kwargs)
self._potcar_filename = "POTCAR" + (".spec" if potcar_spec else "")
self |= {"INCAR": incar, "KPOINTS": kpoints, "POSCAR": poscar, self._potcar_filename: potcar}
self.update({"INCAR": incar, "KPOINTS": kpoints, "POSCAR": poscar, self._potcar_filename: potcar})
if optional_files is not None:
self |= optional_files
self.update(optional_files)

def __str__(self) -> str:
output: list = []
Expand Down
8 changes: 4 additions & 4 deletions tests/io/exciting/test_inputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from xml.etree import ElementTree
from xml.etree import ElementTree as ET

from numpy.testing import assert_allclose

Expand Down Expand Up @@ -102,7 +102,7 @@ def test_writebandstr(self):
[0.5, 0.5, 0.5],
]
label_ref = ["GAMMA", "X", "S", "Y", "GAMMA", "Z", "U", "R", "T", "Z", "Y", "T", "U", "X", "S", "R"]
root = ElementTree.fromstring(band_str)
root = ET.fromstring(band_str)
for plot1d in root.iter("plot1d"):
for point in plot1d.iter("point"):
coord.append([float(i) for i in point.get("coord").split()])
Expand Down Expand Up @@ -140,8 +140,8 @@ def test_param_dict(self):

# read reference file
filepath = f"{TEST_DIR}/input_exciting2.xml"
tree = ElementTree.parse(filepath)
tree = ET.parse(filepath)
root = tree.getroot()
ref_str = ElementTree.tostring(root, encoding="unicode")
ref_str = ET.tostring(root, encoding="unicode")

assert ref_str.strip() == test_str.strip()
4 changes: 2 additions & 2 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from io import StringIO
from pathlib import Path
from shutil import copyfile, copyfileobj
from xml.etree import ElementTree
from xml.etree import ElementTree as ET

import numpy as np
import pytest
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_vasprun_with_more_than_two_unlabelled_dielectric_functions(self):
Vasprun(f"{VASP_OUT_DIR}/vasprun.dielectric_bad.xml.gz")

def test_bad_vasprun(self):
with pytest.raises(ElementTree.ParseError):
with pytest.raises(ET.ParseError):
Vasprun(f"{VASP_OUT_DIR}/vasprun.bad.xml.gz")

with pytest.warns(
Expand Down

0 comments on commit 74befc8

Please sign in to comment.