Skip to content

Commit 00a5405

Browse files
authored
fix ruff PLC0206 Extracting value from dict without calling .items() (#1009)
1 parent 480f75e commit 00a5405

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ default_language_version:
33
exclude: ^(.github/|tests/test_data/abinit/)
44
repos:
55
- repo: https://github.com/charliermarsh/ruff-pre-commit
6-
rev: v0.6.7
6+
rev: v0.6.9
77
hooks:
88
- id: ruff
99
args: [--fix]
1010
- id: ruff-format
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
12-
rev: v4.6.0
12+
rev: v5.0.0
1313
hooks:
1414
- id: check-yaml
1515
- id: fix-encoding-pragma

src/atomate2/ase/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ def as_dict(self) -> dict:
278278
if self._store_md_outputs:
279279
traj_dict.update(velocities=self.velocities, temperature=self.temperatures)
280280
# sanitize dict
281-
for key in traj_dict:
282-
if all(isinstance(val, np.ndarray) for val in traj_dict[key]):
283-
traj_dict[key] = [val.tolist() for val in traj_dict[key]]
284-
elif isinstance(traj_dict[key], np.ndarray):
285-
traj_dict[key] = traj_dict[key].tolist()
281+
for key, value in traj_dict.items():
282+
if all(isinstance(val, np.ndarray) for val in value):
283+
traj_dict[key] = [val.tolist() for val in value]
284+
elif isinstance(value, np.ndarray):
285+
traj_dict[key] = value.tolist()
286286
return traj_dict
287287

288288

src/atomate2/common/flows/eos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def make(self, structure: Structure, prev_dir: str | Path = None) -> Flow:
188188
jobs["utility"] += [post_process]
189189

190190
job_list = []
191-
for key in jobs:
192-
job_list += jobs[key]
191+
for val in jobs.values():
192+
job_list += val
193193

194194
return Flow(jobs=job_list, output=flow_output, name=self.name)

src/atomate2/common/jobs/gruneisen.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ def run_phonon_jobs(
7777
Phonon Jobs or Symmetry of the optimized structures.
7878
"""
7979
symmetry = []
80-
for st in opt_struct:
81-
sga = SpacegroupAnalyzer(opt_struct[st], symprec=symprec)
80+
for struct in opt_struct.values():
81+
sga = SpacegroupAnalyzer(struct, symprec=symprec)
8282
symmetry.append(int(sga.get_space_group_number()))
8383
set_symmetry = list(set(symmetry))
8484
if len(set_symmetry) == 1:
8585
jobs = []
8686
phonon_yaml_dirs = dict.fromkeys(("ground", "plus", "minus"), None)
8787
phonon_imaginary_modes = dict.fromkeys(("ground", "plus", "minus"), None)
88-
for st in opt_struct:
88+
for st, struct in opt_struct.items():
8989
# phonon run for all 3 optimized structures (ground state, expanded, shrunk)
9090
phonon_kwargs = {}
9191
if prev_calc_dir_argname is not None:
9292
phonon_kwargs[prev_calc_dir_argname] = prev_dir_dict[st]
93-
phonon_job = phonon_maker.make(structure=opt_struct[st], **phonon_kwargs)
93+
phonon_job = phonon_maker.make(structure=struct, **phonon_kwargs)
9494
phonon_job.append_name(f" {st}")
9595
# change default phonopy.yaml file name to ensure workflow can be
9696
# run without having to create folders, thus

src/atomate2/common/schemas/phonons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def from_forces_born(
407407
force_gamma=True,
408408
)
409409
phonon.run_mesh(kpoint.kpts[0])
410-
phonon_dos_sigma = kwargs.get("phonon_dos_sigma", None)
410+
phonon_dos_sigma = kwargs.get("phonon_dos_sigma")
411411
dos_use_tetrahedron_method = kwargs.get("dos_use_tetrahedron_method", True)
412412
phonon.run_total_dos(
413413
sigma=phonon_dos_sigma, use_tetrahedron_method=dos_use_tetrahedron_method

src/atomate2/cp2k/schemas/calculation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class CalculationInput(BaseModel):
8989
@classmethod
9090
def remove_unnecessary(cls, atomic_kind_info: dict) -> dict:
9191
"""Remove unnecessary entry from atomic_kind_info."""
92-
for key in atomic_kind_info:
93-
if "total_pseudopotential_energy" in atomic_kind_info[key]:
92+
for key, value in atomic_kind_info.items():
93+
if "total_pseudopotential_energy" in value:
9494
del atomic_kind_info[key]["total_pseudopotential_energy"]
9595
return atomic_kind_info
9696

@@ -524,9 +524,9 @@ def _get_volumetric_data(
524524
except Exception as err:
525525
raise ValueError(f"Failed to parse {file_type} at {file}.") from err
526526

527-
for file_type in volumetric_data:
527+
for file_type, data in volumetric_data.items():
528528
if file_type.name in __is_stored_in_Ha__:
529-
volumetric_data[file_type].scale(Ha_to_eV)
529+
data.scale(Ha_to_eV)
530530

531531
return volumetric_data
532532

0 commit comments

Comments
 (0)