Skip to content

Commit 55c5dd6

Browse files
committed
linting
1 parent bfda61a commit 55c5dd6

File tree

10 files changed

+62
-31
lines changed

10 files changed

+62
-31
lines changed

src/atomate2/abinit/flows/dfpt.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ def make(
225225
@dataclass
226226
class ShgFlowMaker(DfptFlowMaker):
227227
"""
228-
Maker to generate a DFPT flow to compute the static nonlinear optical
229-
susceptibility tensor for the second-harmonic generation with abinit.
228+
Maker to compute the static NLO SHG tensor.
230229
231230
The classmethods allow to tailor the flow for specific configurations.
232231

src/atomate2/abinit/jobs/anaddb.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
)
2323

2424
if TYPE_CHECKING:
25+
from pymatgen.core.structure import Structure
26+
2527
from atomate2.abinit.utils.history import JobHistory
2628

2729
logger = logging.getLogger(__name__)
@@ -153,8 +155,7 @@ def get_response(
153155

154156
@dataclass
155157
class AnaddbDfptDteMaker(AnaddbMaker):
156-
"""Maker to create a job to analyze a DDB file with the utility anaddb
157-
to get info from DFPT calculations with the DTE.
158+
"""Maker to get info from DFPT calculations (with DTE) from a merged DDB file.
158159
159160
Parameters
160161
----------

src/atomate2/abinit/jobs/response.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@
4747

4848
@dataclass
4949
class ResponseMaker(BaseAbinitMaker):
50-
"""Maker to create a job with a Response Function ABINIT calculation.
51-
The type of RF is defined by the self.calc_type attribute.
50+
"""Maker for a Response Function ABINIT calculation job.
5251
5352
Parameters
5453
----------
54+
calc_type : str
55+
The type of RF.
5556
name : str
5657
The job name.
5758
"""
@@ -258,9 +259,7 @@ def generate_dte_perts(
258259
@job
259260
def run_rf(
260261
perturbations: list[dict],
261-
rf_maker: BaseAbinitMaker = field(
262-
default_factory=BaseAbinitMaker
263-
), # TODO: change to generic ResponseMaker
262+
rf_maker: ResponseMaker,
264263
prev_outputs: list[str] | None = None,
265264
) -> Flow:
266265
"""

src/atomate2/abinit/run.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from atomate2 import SETTINGS
1212
from atomate2.abinit.utils.common import (
13-
ANADDB_INPUT_FILE_NAME,
1413
INPUT_FILE_NAME,
1514
LOG_FILE_NAME,
1615
MRGDDB_INPUT_FILE_NAME,
@@ -142,7 +141,7 @@ def run_anaddb(
142141
max_end_time = start_time + wall_time
143142

144143
with (
145-
open(ANADDB_INPUT_FILE_NAME) as stdin,
144+
# open(ANADDB_INPUT_FILE_NAME) as stdin,
146145
open(LOG_FILE_NAME, "w") as stdout,
147146
open(STDERR_FILE_NAME, "w") as stderr,
148147
):

src/atomate2/abinit/schemas/anaddb.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import logging
66
import os
7-
from datetime import datetime
7+
from datetime import datetime, timezone
88
from pathlib import Path
99

1010
# from typing import Type, TypeVar, Union, Optional, List
@@ -13,6 +13,7 @@
1313
import abipy.core.abinit_units as abu
1414
import numpy as np
1515
from abipy.dfpt.anaddbnc import AnaddbNcFile
16+
from abipy.dfpt.ddb import AnaddbError
1617
from abipy.flowtk import events
1718
from abipy.flowtk.utils import File
1819
from emmet.core.structure import StructureMetadata
@@ -152,7 +153,9 @@ def from_abinit_files(
152153
output_doc = CalculationOutput.from_abinit_anaddb(abinit_anaddb)
153154

154155
completed_at = str(
155-
datetime.fromtimestamp(os.stat(abinit_anaddb_file).st_mtime)
156+
datetime.fromtimestamp(
157+
os.stat(abinit_anaddb_file).st_mtime, tz=timezone.utc
158+
)
156159
)
157160

158161
report = None
@@ -166,7 +169,7 @@ def from_abinit_files(
166169
# report.run_completed is False even when it completed...
167170
has_anaddb_completed = TaskState.SUCCESS
168171

169-
except Exception as exc:
172+
except (AnaddbError, Exception) as exc:
170173
msg = f"{cls} exception while parsing event_report:\n{exc}"
171174
logger.critical(msg)
172175

src/atomate2/abinit/schemas/calculation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def from_abinit_files(
292292
update_data = output_doc_gsr.model_dump(exclude_unset=True)
293293
output_doc = output_doc.model_copy(update=update_data, deep=True)
294294
if not output_doc:
295-
raise Exception(f"Neither {abinit_out_file} nor {abinit_gsr_file}\
295+
raise FileNotFoundError(f"Neither {abinit_out_file} nor {abinit_gsr_file}\
296296
exists. This means that there is no output, \
297297
which is not normal.")
298298

src/atomate2/abinit/schemas/mrgddb.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
import logging
66
import os
7-
from datetime import datetime
7+
from datetime import datetime, timezone
88
from pathlib import Path
99

1010
# from typing import Type, TypeVar, Union, Optional, List
1111
from typing import Any, Optional, Union
1212

13-
from abipy.dfpt.ddb import DdbFile
13+
from abipy.dfpt.ddb import DdbError, DdbFile
1414
from abipy.flowtk import events
1515
from abipy.flowtk.utils import File
1616
from emmet.core.structure import StructureMetadata
@@ -139,7 +139,9 @@ def from_abinit_files(
139139
output_doc = CalculationOutput.from_abinit_outddb(abinit_outddb)
140140

141141
completed_at = str(
142-
datetime.fromtimestamp(os.stat(abinit_outddb_file).st_mtime)
142+
datetime.fromtimestamp(
143+
os.stat(abinit_outddb_file).st_mtime, tz=timezone.utc
144+
)
143145
)
144146

145147
report = None
@@ -153,7 +155,7 @@ def from_abinit_files(
153155
# report.run_completed is False even when it completed...
154156
has_mrgddb_completed = TaskState.SUCCESS
155157

156-
except Exception as exc:
158+
except (DdbError, Exception) as exc:
157159
msg = f"{cls} exception while parsing event_report:\n{exc}"
158160
logger.critical(msg)
159161

src/atomate2/abinit/sets/anaddb.py

+35-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import logging
88
import os
99
from dataclasses import dataclass, field
10-
from pathlib import Path
1110
from typing import TYPE_CHECKING, Any, Callable
1211

1312
from abipy.abio.inputs import AnaddbInput
1413
from abipy.flowtk.utils import Directory
1514
from monty.json import MontyEncoder, jsanitize
16-
from pymatgen.io.abinit.abiobjects import KSampling
1715
from pymatgen.io.core import InputSet
1816

1917
from atomate2.abinit.files import out_to_in
@@ -28,8 +26,10 @@
2826

2927
if TYPE_CHECKING:
3028
from collections.abc import Iterable
29+
from pathlib import Path
3130

3231
from pymatgen.core.structure import Structure
32+
from pymatgen.io.abinit.abiobjects import KSampling
3333

3434

3535
logger = logging.getLogger(__name__)
@@ -341,13 +341,41 @@ def get_anaddb_input(
341341
return generated_input
342342

343343

344-
def anaddbinp_dfpt_dte(structure, anaddb_kwargs=None):
345-
anaddb_input = AnaddbInput.dfpt(
346-
structure=structure, dte=True, anaddb_kwargs=anaddb_kwargs
347-
)
348-
return anaddb_input
344+
def anaddbinp_dfpt_dte(
345+
structure: Structure, anaddb_kwargs: None | dict = None
346+
) -> AnaddbInput:
347+
"""
348+
Generate the AnaddbInput to retrieve information from the DTE.
349+
350+
Parameters
351+
----------
352+
structure
353+
A structure.
354+
anaddb_kwargs
355+
A dictionary with additional anaddb keywords to set.
356+
357+
Returns
358+
-------
359+
An AnaddbInput
360+
361+
"""
362+
return AnaddbInput.dfpt(structure=structure, dte=True, anaddb_kwargs=anaddb_kwargs)
349363

350364

351365
@dataclass
352366
class AnaddbDfptDteInputGenerator(AnaddbInputGenerator):
367+
"""
368+
A class to generate the AnaddbInput to retrieve information from the DTE.
369+
370+
Parameters
371+
----------
372+
factory
373+
A callable to generate the AnaddbInput for DTE DFPT.
374+
375+
Returns
376+
-------
377+
An AnaddbInput
378+
379+
"""
380+
353381
factory: Callable = anaddbinp_dfpt_dte

src/atomate2/abinit/sets/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AbiBroadInputGenerator(InputGenerator):
6767
"""
6868

6969
calc_type: str
70-
prev_outputs_deps: tuple
70+
prev_outputs_deps: str | tuple | None
7171

7272
def check_format_prev_dirs(
7373
self, prev_dirs: str | tuple | list | Path | None
@@ -134,7 +134,7 @@ def resolve_dep_exts(prev_dir: str, exts: list[str]) -> tuple:
134134
raise RuntimeError("Should not occur.")
135135
if files is not None:
136136
inp_files = [
137-
(f.path, AbinitInputGenerator._get_in_file_name(f.path))
137+
(f.path, AbiBroadInputGenerator._get_in_file_name(f.path))
138138
for f in files
139139
]
140140
irdvars = irdvars_for_ext(ext)
@@ -148,7 +148,7 @@ def resolve_dep_exts(prev_dir: str, exts: list[str]) -> tuple:
148148
if os.path.exists(out_den):
149149
irdvars = irdvars_for_ext("DEN")
150150
inp_files.append(
151-
(out_den, AbinitInputGenerator._get_in_file_name(out_den))
151+
(out_den, AbiBroadInputGenerator._get_in_file_name(out_den))
152152
)
153153
break
154154
last_timden = prev_outdir.find_last_timden_file()
@@ -165,7 +165,7 @@ def resolve_dep_exts(prev_dir: str, exts: list[str]) -> tuple:
165165
irdvars = irdvars_for_ext(ext)
166166
if out_file:
167167
inp_files.append(
168-
(out_file, AbinitInputGenerator._get_in_file_name(out_file))
168+
(out_file, AbiBroadInputGenerator._get_in_file_name(out_file))
169169
)
170170
break
171171
else:

src/atomate2/abinit/sets/mrgddb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import os
88
import time
99
from dataclasses import dataclass
10-
from pathlib import Path
1110
from typing import TYPE_CHECKING
1211

1312
from abipy.abio.input_tags import DDE, DTE
@@ -24,6 +23,7 @@
2423

2524
if TYPE_CHECKING:
2625
from collections.abc import Iterable
26+
from pathlib import Path
2727

2828
__all__ = ["MrgddbInputSet", "MrgddbInputGenerator"]
2929

0 commit comments

Comments
 (0)