Skip to content

Commit 8d57884

Browse files
authored
ruff fixes (#946)
1 parent 9c84108 commit 8d57884

File tree

20 files changed

+127
-142
lines changed

20 files changed

+127
-142
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33
exclude: ^(.github/|tests/test_data/abinit/)
44
repos:
55
- repo: https://github.com/charliermarsh/ruff-pre-commit
6-
rev: v0.5.2
6+
rev: v0.5.6
77
hooks:
88
- id: ruff
99
args: [--fix]
@@ -30,7 +30,7 @@ repos:
3030
- id: rst-directive-colons
3131
- id: rst-inline-touching-normal
3232
- repo: https://github.com/pre-commit/mirrors-mypy
33-
rev: v1.10.1
33+
rev: v1.11.1
3434
hooks:
3535
- id: mypy
3636
files: ^src/
@@ -48,8 +48,7 @@ repos:
4848
rev: 0.7.1
4949
hooks:
5050
- id: nbstripout
51-
args: [
52-
--drop-empty-cells,
53-
--strip-init-cells,
54-
--extra-keys=metadata.kernelspec,
55-
]
51+
args:
52+
- --drop-empty-cells
53+
- --strip-init-cells
54+
- --extra-keys=metadata.kernelspec

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ forcefields = [
5454
"calorine<=2.2.1",
5555
"chgnet>=0.2.2",
5656
"mace-torch>=0.3.3",
57-
"matgl>=1.1.1",
57+
"matgl>=1.1.3",
5858
"quippy-ase>=0.9.14",
5959
"sevenn>=0.9.3",
60-
"torch<=2.2.1", # incompatibility with dgl if newer versions are used
6160
]
6261
docs = [
6362
"FireWorks==2.0.3",
@@ -93,7 +92,7 @@ strict = [
9392
"jobflow==0.1.18",
9493
"lobsterpy==0.4.5",
9594
"mace-torch>=0.3.3",
96-
"matgl==1.1.2",
95+
"matgl==1.1.3",
9796
"monty==2024.7.30",
9897
"mp-api==0.41.2",
9998
"numpy",
@@ -198,7 +197,7 @@ ignore = [
198197
"S324", # use of insecure hash function
199198
"S507", # paramiko auto trust
200199
"S603", # use of insecure subprocess
201-
"TD", # TODOs
200+
"TD", # todos
202201
"TRY003", # long message outside exception class
203202
]
204203
pydocstyle.convention = "numpy"

src/atomate2/abinit/sets/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ def get_input_set(
387387
link_files=True,
388388
)
389389

390+
@staticmethod
390391
def check_format_prev_dirs(
391-
self, prev_dirs: str | tuple | list | Path | None
392+
prev_dirs: str | tuple | list | Path | None,
392393
) -> list[str] | None:
393394
"""Check and format the prev_dirs (restart or dependency)."""
394395
if prev_dirs is None:
@@ -437,9 +438,9 @@ def resolve_prev_inputs(
437438
abinit_inputs = {}
438439
for prev_dir in prev_dirs:
439440
abinit_input = load_abinit_input(prev_dir)
440-
for var_name, runlevels in prev_inputs_kwargs.items():
441+
for var_name, run_levels in prev_inputs_kwargs.items():
441442
if abinit_input.runlevel and abinit_input.runlevel.intersection(
442-
runlevels
443+
run_levels
443444
):
444445
if var_name in abinit_inputs:
445446
msg = (

src/atomate2/common/flows/gruneisen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def prev_calc_dir_argname(self) -> str | None:
201201
"""
202202

203203
def __post_init__(self) -> None:
204-
"""Test settings during the initialisation."""
204+
"""Test settings during the initialization."""
205205
if self.phonon_maker.bulk_relax_maker is not None:
206206
warnings.warn(
207207
"An additional bulk_relax_maker has been added "
@@ -218,6 +218,6 @@ def __post_init__(self) -> None:
218218
)
219219
if self.phonon_maker.static_energy_maker is not None:
220220
warnings.warn(
221-
"The static energy maker " "is not needed for " "this workflow.",
221+
"The static energy maker is not needed for this workflow.",
222222
stacklevel=2,
223223
)

src/atomate2/common/jobs/phonons.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def get_supercell_size(
7474
Additional parameters that can be set.
7575
"""
7676
kwargs.setdefault("force_diagonal", False)
77-
common_kwds = dict(
78-
min_length=min_length,
79-
min_atoms=kwargs.get("min_atoms"),
80-
force_diagonal=kwargs["force_diagonal"],
81-
)
77+
common_kwds = {
78+
"min_length": min_length,
79+
"min_atoms": kwargs.get("min_atoms"),
80+
"force_diagonal": kwargs["force_diagonal"],
81+
}
8282

8383
if not prefer_90_degrees:
8484
transformation = CubicSupercellTransformation(

src/atomate2/common/schemas/gruneisen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def from_phonon_yamls(
213213
kpath_dict, kpath_concrete = PhononBSDOSDoc.get_kpath(
214214
structure=structure, kpath_scheme=kpath_scheme, symprec=symprec
215215
)
216-
qpoints, connections = get_band_qpoints_and_path_connections(
216+
qpoints, _connections = get_band_qpoints_and_path_connections(
217217
kpath_concrete,
218218
npoints=compute_gruneisen_param_kwargs.get("npoints_band", 101),
219219
)

src/atomate2/cp2k/flows/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def __post_init__(self) -> None:
251251
}
252252
if self.initialize_with_pbe:
253253
updates["activate_hybrid"].update(
254-
{"screen_on_initial_p": True, "screen_p_forces": True}
254+
screen_on_initial_p=True, screen_p_forces=True
255255
)
256256
self.hybrid_maker.input_set_generator.user_input_settings = recursive_update(
257257
updates, self.hybrid_maker.input_set_generator.user_input_settings

src/atomate2/forcefields/schemas.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,9 @@ def from_ase_compatible_result(
255255
# include "magmoms" in :obj:`ionic_step` if the trajectory has "magmoms"
256256
if "magmoms" in trajectory.frame_properties[idx]:
257257
_ionic_step_data.update(
258-
{
259-
"magmoms": trajectory.frame_properties[idx]["magmoms"]
260-
if "magmoms" in ionic_step_data
261-
else None
262-
}
258+
magmoms=trajectory.frame_properties[idx]["magmoms"]
259+
if "magmoms" in ionic_step_data
260+
else None
263261
)
264262

265263
ionic_step = IonicStep(
@@ -287,17 +285,14 @@ def from_ase_compatible_result(
287285
)
288286

289287
# map force field name to its package name
290-
pkg_names = {
291-
str(k): v
292-
for k, v in {
293-
MLFF.M3GNet: "matgl",
294-
MLFF.CHGNet: "chgnet",
295-
MLFF.MACE: "mace-torch",
296-
MLFF.GAP: "quippy-ase",
297-
MLFF.Nequip: "nequip",
298-
}.items()
288+
model_to_pkg_map = {
289+
MLFF.M3GNet: "matgl",
290+
MLFF.CHGNet: "chgnet",
291+
MLFF.MACE: "mace-torch",
292+
MLFF.GAP: "quippy-ase",
293+
MLFF.Nequip: "nequip",
299294
}
300-
pkg_name = pkg_names.get(forcefield_name)
295+
pkg_name = {str(k): v for k, v in model_to_pkg_map.items()}.get(forcefield_name)
301296
if pkg_name:
302297
import importlib.metadata
303298

src/atomate2/forcefields/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ def ase_calculator(calculator_meta: str | dict, **kwargs: Any) -> Calculator | N
446446
calculator = NequIPCalculator.from_deployed_model(**kwargs)
447447

448448
elif calculator_name == MLFF.SevenNet:
449-
# pip install git+https://github.com/MDIL-SNU/SevenNet
450449
from sevenn.sevennet_calculator import SevenNetCalculator
451450

452451
calculator = SevenNetCalculator(**{"model": "7net-0"} | kwargs)

src/atomate2/lobster/schemas.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ def _get_strong_bonds(
13021302
else:
13031303
prop = "icohp"
13041304

1305-
bond_dict = {}
1305+
bond_dict: dict[str, dict[str, Union[float, str]]] = {}
13061306
for idx, lab in enumerate(bond_labels_unique):
13071307
label = lab.split("-")
13081308
label.sort()
@@ -1312,24 +1312,20 @@ def _get_strong_bonds(
13121312
if label == rel_bnd_list:
13131313
if prop == "icohp":
13141314
index = np.argmin(sep_icohp[idx])
1315-
bond_dict.update(
1316-
{
1317-
rel_bnd: {
1318-
"bond_strength": min(sep_icohp[idx]),
1319-
"length": sep_lengths[idx][index],
1320-
}
1315+
bond_dict |= {
1316+
rel_bnd: {
1317+
"bond_strength": min(sep_icohp[idx]),
1318+
"length": sep_lengths[idx][index],
13211319
}
1322-
)
1320+
}
13231321
else:
13241322
index = np.argmax(sep_icohp[idx])
1325-
bond_dict.update(
1326-
{
1327-
rel_bnd: {
1328-
"bond_strength": max(sep_icohp[idx]),
1329-
"length": sep_lengths[idx][index],
1330-
}
1323+
bond_dict |= {
1324+
rel_bnd: {
1325+
"bond_strength": max(sep_icohp[idx]),
1326+
"length": sep_lengths[idx][index],
13311327
}
1332-
)
1328+
}
13331329
return bond_dict
13341330

13351331

0 commit comments

Comments
 (0)