Skip to content

Commit

Permalink
ruff auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jan 30, 2024
1 parent a47d7a5 commit b5770cf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
21 changes: 12 additions & 9 deletions src/atomate2/common/schemas/defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from collections.abc import Sequence
from itertools import starmap
from typing import Any, Callable, Optional, Union

import numpy as np
Expand Down Expand Up @@ -237,7 +238,7 @@ def from_task_outputs(
UUID of relaxed calculation in charge state (q2).
"""

def get_ent(
def get_cs_entry(
struct: Structure,
energy: float,
dir_name: str,
Expand All @@ -249,14 +250,16 @@ def get_ent(
data={"dir_name": dir_name, "uuid": uuid},
)

entries1 = [
get_ent(s, e, d, u)
for s, e, d, u in zip(structures1, energies1, static_dirs1, static_uuids1)
]
entries2 = [
get_ent(s, e, d, u)
for s, e, d, u in zip(structures2, energies2, static_dirs2, static_uuids2)
]
entries1 = list(
starmap(
get_cs_entry, zip(structures1, energies1, static_dirs1, static_uuids1)
)
)
entries2 = list(
starmap(
get_cs_entry, zip(structures2, energies2, static_dirs2, static_uuids2)
)
)

return cls.from_entries(entries1, entries2, relaxed_uuid1, relaxed_uuid2)

Expand Down
27 changes: 11 additions & 16 deletions src/atomate2/lobster/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,7 @@ def from_directory(

# Do automatic bonding analysis with LobsterPy
condensed_bonding_analysis = None
sb_icobi = None
sb_icohp = None
sb_icoop = None
describe = None
sb_icobi = sb_icohp = sb_icoop = describe = None
struct = Structure.from_file(structure_path)

# will perform two condensed bonding analysis computations
Expand Down Expand Up @@ -1066,7 +1063,7 @@ def from_directory(
are_coops=False,
are_cobis=False,
)
doc.__setattr__("cohp_data", cohp_obj)
doc.cohp_data = cohp_obj

if coopcar_path.exists() and doc.coop_data is None:
coop_obj = CompleteCohp.from_file(
Expand All @@ -1076,7 +1073,7 @@ def from_directory(
are_coops=True,
are_cobis=False,
)
doc.__setattr__("coop_data", coop_obj)
doc.coop_data = coop_obj

if cobicar_path.exists() and doc.cobi_data is None:
cobi_obj = CompleteCohp.from_file(
Expand All @@ -1086,7 +1083,7 @@ def from_directory(
are_coops=False,
are_cobis=True,
)
doc.__setattr__("cobi_data", cobi_obj)
doc.cobi_data = cobi_obj
with gzip.open(
computational_data_json_save_dir, "wt", encoding="UTF-8"
) as file:
Expand All @@ -1099,7 +1096,7 @@ def from_directory(
# objects and other data json compatible dict format
data = {
attribute: jsanitize(
doc.__getattribute__(attribute),
getattr(doc, attribute),
allow_bson=False,
strict=True,
enum_values=True,
Expand All @@ -1113,9 +1110,9 @@ def from_directory(

# Again unset the cohp, cobi and coop data fields if not desired in the DB
if not add_coxxcar_to_task_document:
doc.__setattr__("cohp_data", None)
doc.__setattr__("coop_data", None)
doc.__setattr__("cobi_data", None)
doc.cohp_data = None
doc.coop_data = None
doc.cobi_data = None

return doc.model_copy(update=additional_fields)

Expand Down Expand Up @@ -1339,11 +1336,9 @@ def read_saved_json(
lobster_data[query_key] = MontyDecoder().process_decoded(value)
elif "lobsterpy_data" in query_key:
for field in lobster_data[query_key].__fields__:
lobster_data[query_key].__setattr__(
field,
MontyDecoder().process_decoded(
lobster_data[query_key].__getattribute__(field)
),
val = MontyDecoder().process_decoded(
getattr(lobster_data[query_key], field)
)
setattr(lobster_data[query_key], field, val)

return lobster_data
2 changes: 1 addition & 1 deletion src/atomate2/utils/file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def gzip(
path.unlink()
else:
ssh = self.get_ssh(host)
_, stdout, _ = ssh.exec_command(f"gzip -f {path!s}")
_, _stdout, _ = ssh.exec_command(f"gzip -f {path!s}")

def gunzip(
self,
Expand Down
6 changes: 2 additions & 4 deletions src/atomate2/vasp/flows/mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ class MPVaspLobsterMaker(VaspLobsterMaker):
"""

name: str = "lobster"
relax_maker: BaseVaspMaker | None = field(
default_factory=lambda: MPGGADoubleRelaxMaker()
)
relax_maker: BaseVaspMaker | None = field(default_factory=MPGGADoubleRelaxMaker)
lobster_static_maker: BaseVaspMaker = field(
default_factory=lambda: MPGGAStaticMaker(
input_set_generator=MPGGAStaticSetGenerator(
Expand All @@ -254,7 +252,7 @@ class MPVaspLobsterMaker(VaspLobsterMaker):
)
)
)
lobster_maker: LobsterMaker | None = field(default_factory=lambda: LobsterMaker())
lobster_maker: LobsterMaker | None = field(default_factory=LobsterMaker)
delete_wavecars: bool = True
address_min_basis: str | None = None
address_max_basis: str | None = None
2 changes: 1 addition & 1 deletion src/atomate2/vasp/sets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def write_input(
# write POSCAR with more significant figures
file.write(val.get_str(significant_figures=16))
else:
file.write(val.__str__())
file.write(str(val))
elif not overwrite and (directory / key).exists():
raise FileExistsError(f"{directory / key} already exists.")

Expand Down

0 comments on commit b5770cf

Please sign in to comment.