Skip to content

Commit b74a5df

Browse files
authored
Ruff fixes (#3564)
* fix ruff SIM300 Yoda asserts ruff ignore ANN101 COM812 NPY002 PTH PLC1901 PLW1514 ruff ignore ANN201 S101 for tests/ rename f->file * fix ruff F841 local var assigned but never used * fix ruff SIM113 use enumerate() for index variable * fix ruff RUF021 parenthesize `a and b` when chaining `and` and `or` together * fix likely unintentional operator precedence in LobsterEnv._find_relevant_atoms_additional_condition() (val1 < 0.0 < val2) or (val2 < 0.0 < val1) was not evaluated together * fix ruff E226 missing whitespace around arithmetic op * fix super.__init__() call missing parens * fix ZeroDivisionError in > self.logger.debug(f"Average time per combi = {(now - start_time) / idx} seconds")
1 parent e502e33 commit b74a5df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+241
-257
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ci:
88

99
repos:
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.1.13
11+
rev: v0.1.14
1212
hooks:
1313
- id: ruff
1414
args: [--fix, --unsafe-fixes]

dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def get_weights(self, weights_options):
269269
"+-------------------------------------------------------------+\n"
270270
)
271271

272-
with open("ce_pairs.json") as f:
273-
ce_pairs = json.load(f)
272+
with open("ce_pairs.json") as file:
273+
ce_pairs = json.load(file)
274274
self_weight_max_csms: dict[str, list[float]] = {}
275275
self_weight_max_csms_per_cn: dict[str, list[float]] = {}
276276
all_self_max_csms = []

pymatgen/alchemy/filters.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,11 @@ def get_sg(s):
265265

266266
for s in self.existing_structures:
267267
if (
268-
self.structure_matcher._comparator.get_hash(structure.composition)
269-
== self.structure_matcher._comparator.get_hash(s.composition)
270-
and self.symprec is None
268+
(
269+
self.structure_matcher._comparator.get_hash(structure.composition)
270+
== self.structure_matcher._comparator.get_hash(s.composition)
271+
and self.symprec is None
272+
)
271273
or get_sg(s) == get_sg(structure)
272274
) and self.structure_matcher.fit(s, structure):
273275
return False

pymatgen/analysis/adsorption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def substitute(site, i):
582582

583583
for idx, site in enumerate(sym_slab):
584584
if dist - range_tol < site.frac_coords[2] < dist + range_tol and (
585-
target_species and site.species_string in target_species or not target_species
585+
(target_species and site.species_string in target_species) or not target_species
586586
):
587587
substituted_slabs.append(substitute(site, idx))
588588

pymatgen/analysis/chemenv/coordination_environments/chemenv_strategies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ def __init__(
10621062
:param max_csm:
10631063
:param symmetry_measure_type:
10641064
"""
1065-
super.__init__(
1065+
super().__init__(
10661066
self,
10671067
structure_environments,
10681068
additional_condition=additional_condition,

pymatgen/analysis/chemenv/coordination_environments/structure_environments.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,10 +1763,8 @@ def get_site_info_for_specie_allces(self, specie, min_fraction=0):
17631763
oxi_state = specie.oxi_state
17641764
for isite, site in enumerate(self.structure):
17651765
if (
1766-
element in [sp.symbol for sp in site.species]
1767-
and self.valences == "undefined"
1768-
or oxi_state == self.valences[isite]
1769-
):
1766+
element in [sp.symbol for sp in site.species] and self.valences == "undefined"
1767+
) or oxi_state == self.valences[isite]:
17701768
if self.coordination_environments[isite] is None:
17711769
continue
17721770
for ce_dict in self.coordination_environments[isite]:

pymatgen/analysis/diffraction/tem.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
if TYPE_CHECKING:
2121
from pymatgen.core import Structure
2222

23-
with open(os.path.join(os.path.dirname(__file__), "atomic_scattering_params.json")) as f:
24-
ATOMIC_SCATTERING_PARAMS = json.load(f)
25-
2623
__author__ = "Frank Wan, Jason Liang"
2724
__copyright__ = "Copyright 2020, The Materials Project"
2825
__version__ = "0.22"
@@ -31,13 +28,18 @@
3128
__date__ = "03/31/2020"
3229

3330

31+
module_dir = os.path.dirname(__file__)
32+
with open(f"{module_dir}/atomic_scattering_params.json") as file:
33+
ATOMIC_SCATTERING_PARAMS = json.load(file)
34+
35+
3436
class TEMCalculator(AbstractDiffractionPatternCalculator):
3537
"""
3638
Computes the TEM pattern of a crystal structure for multiple Laue zones.
3739
Code partially inspired from XRD calculation implementation. X-ray factor to electron factor
3840
conversion based on the International Table of Crystallography.
3941
#TODO: Could add "number of iterations", "magnification", "critical value of beam",
40-
"twin direction" for certain materials, "sample thickness", and "excitation error s".
42+
"twin direction" for certain materials, "sample thickness", and "excitation error s".
4143
"""
4244

4345
def __init__(

pymatgen/analysis/local_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,9 +1211,9 @@ def __init__(
12111211

12121212
# Load elemental radii table
12131213
bonds_file = f"{module_dir}/bonds_jmol_ob.yaml"
1214-
with open(bonds_file) as f:
1214+
with open(bonds_file) as file:
12151215
yaml = YAML()
1216-
self.el_radius = yaml.load(f)
1216+
self.el_radius = yaml.load(file)
12171217

12181218
# Update any user preference elemental radii
12191219
if el_radius_updates:

pymatgen/analysis/magnetism/heisenberg.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,9 @@ def _get_unique_sites(structure):
146146
unique_site_ids = {}
147147
wyckoff_ids = {}
148148

149-
i = 0
150-
for indices, symbol in zip(equivalent_indices, wyckoff_symbols):
151-
unique_site_ids[tuple(indices)] = i
152-
wyckoff_ids[i] = symbol
153-
i += 1
149+
for idx, (indices, symbol) in enumerate(zip(equivalent_indices, wyckoff_symbols)):
150+
unique_site_ids[tuple(indices)] = idx
151+
wyckoff_ids[idx] = symbol
154152
for index in indices:
155153
wyckoff[index] = symbol
156154

pymatgen/apps/borg/hive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def assimilate(self, path):
224224
else:
225225
for filename in filenames:
226226
files = sorted(glob(os.path.join(path, filename + "*")))
227-
if len(files) == 1 or filename in ("INCAR", "POTCAR") or len(files) == 1 and filename == "DYNMAT":
227+
if len(files) == 1 or filename in ("INCAR", "POTCAR") or (len(files) == 1 and filename == "DYNMAT"):
228228
files_to_parse[filename] = files[0]
229229
elif len(files) > 1:
230230
# Since multiple files are ambiguous, we will always

0 commit comments

Comments
 (0)