Skip to content

Commit

Permalink
fix ruff PLC0206 Extracting value from dict without calling .items() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh authored Oct 6, 2024
1 parent 480f75e commit 00a5405
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ default_language_version:
exclude: ^(.github/|tests/test_data/abinit/)
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.6.7
rev: v0.6.9
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: fix-encoding-pragma
Expand Down
10 changes: 5 additions & 5 deletions src/atomate2/ase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ def as_dict(self) -> dict:
if self._store_md_outputs:
traj_dict.update(velocities=self.velocities, temperature=self.temperatures)
# sanitize dict
for key in traj_dict:
if all(isinstance(val, np.ndarray) for val in traj_dict[key]):
traj_dict[key] = [val.tolist() for val in traj_dict[key]]
elif isinstance(traj_dict[key], np.ndarray):
traj_dict[key] = traj_dict[key].tolist()
for key, value in traj_dict.items():
if all(isinstance(val, np.ndarray) for val in value):
traj_dict[key] = [val.tolist() for val in value]
elif isinstance(value, np.ndarray):
traj_dict[key] = value.tolist()
return traj_dict


Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/common/flows/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def make(self, structure: Structure, prev_dir: str | Path = None) -> Flow:
jobs["utility"] += [post_process]

job_list = []
for key in jobs:
job_list += jobs[key]
for val in jobs.values():
job_list += val

return Flow(jobs=job_list, output=flow_output, name=self.name)
8 changes: 4 additions & 4 deletions src/atomate2/common/jobs/gruneisen.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ def run_phonon_jobs(
Phonon Jobs or Symmetry of the optimized structures.
"""
symmetry = []
for st in opt_struct:
sga = SpacegroupAnalyzer(opt_struct[st], symprec=symprec)
for struct in opt_struct.values():
sga = SpacegroupAnalyzer(struct, symprec=symprec)
symmetry.append(int(sga.get_space_group_number()))
set_symmetry = list(set(symmetry))
if len(set_symmetry) == 1:
jobs = []
phonon_yaml_dirs = dict.fromkeys(("ground", "plus", "minus"), None)
phonon_imaginary_modes = dict.fromkeys(("ground", "plus", "minus"), None)
for st in opt_struct:
for st, struct in opt_struct.items():
# phonon run for all 3 optimized structures (ground state, expanded, shrunk)
phonon_kwargs = {}
if prev_calc_dir_argname is not None:
phonon_kwargs[prev_calc_dir_argname] = prev_dir_dict[st]
phonon_job = phonon_maker.make(structure=opt_struct[st], **phonon_kwargs)
phonon_job = phonon_maker.make(structure=struct, **phonon_kwargs)
phonon_job.append_name(f" {st}")
# change default phonopy.yaml file name to ensure workflow can be
# run without having to create folders, thus
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/common/schemas/phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def from_forces_born(
force_gamma=True,
)
phonon.run_mesh(kpoint.kpts[0])
phonon_dos_sigma = kwargs.get("phonon_dos_sigma", None)
phonon_dos_sigma = kwargs.get("phonon_dos_sigma")
dos_use_tetrahedron_method = kwargs.get("dos_use_tetrahedron_method", True)
phonon.run_total_dos(
sigma=phonon_dos_sigma, use_tetrahedron_method=dos_use_tetrahedron_method
Expand Down
8 changes: 4 additions & 4 deletions src/atomate2/cp2k/schemas/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class CalculationInput(BaseModel):
@classmethod
def remove_unnecessary(cls, atomic_kind_info: dict) -> dict:
"""Remove unnecessary entry from atomic_kind_info."""
for key in atomic_kind_info:
if "total_pseudopotential_energy" in atomic_kind_info[key]:
for key, value in atomic_kind_info.items():
if "total_pseudopotential_energy" in value:
del atomic_kind_info[key]["total_pseudopotential_energy"]
return atomic_kind_info

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

for file_type in volumetric_data:
for file_type, data in volumetric_data.items():
if file_type.name in __is_stored_in_Ha__:
volumetric_data[file_type].scale(Ha_to_eV)
data.scale(Ha_to_eV)

return volumetric_data

Expand Down

0 comments on commit 00a5405

Please sign in to comment.