Skip to content

Commit 96f8674

Browse files
committed
store DDB + add LDA PSP
1 parent 8c49db9 commit 96f8674

File tree

12 files changed

+10071
-29
lines changed

12 files changed

+10071
-29
lines changed

src/atomate2/abinit/jobs/base.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
from atomate2.abinit.files import write_abinit_input_set
1717
from atomate2.abinit.run import run_abinit
1818
from atomate2.abinit.schemas.calculation import TaskState
19+
from atomate2.abinit.schemas.mrgddb import DdbFileStr
1920
from atomate2.abinit.schemas.task import AbinitTaskDoc
2021
from atomate2.abinit.utils.common import UnconvergedError
2122
from atomate2.abinit.utils.history import JobHistory
2223

2324
if TYPE_CHECKING:
2425
from collections.abc import Sequence
26+
from typing import Callable
2527

2628
from abipy.flowtk.events import AbinitCriticalWarning
2729
from pymatgen.core.structure import Structure
@@ -99,6 +101,53 @@ def setup_job(
99101
)
100102

101103

104+
_DATA_OBJECTS = [ # either str (TaskDoc fields) or MSONable class
105+
# BandStructure,
106+
# BandStructureSymmLine,
107+
# DOS,
108+
# Dos,
109+
# CompleteDos,
110+
# VolumetricData,
111+
# Trajectory,
112+
DdbFileStr,
113+
]
114+
115+
116+
def abinit_job(method: Callable) -> job:
117+
"""
118+
Decorate the ``make`` method of CP2K job makers.
119+
120+
This is a thin wrapper around :obj:`~jobflow.core.job.job` that configures common
121+
settings for all CP2K jobs. For example, it ensures that large data objects
122+
(band structures, density of states, Cubes, etc) are all stored in the
123+
atomate2 data store. It also configures the output schema to be a CP2K
124+
:obj:`.TaskDocument`.
125+
126+
Any makers that return CP2K jobs (not flows) should decorate the ``make`` method
127+
with @cp2k_job. For example:
128+
129+
.. code-block:: python
130+
131+
class MyCp2kMaker(BaseCp2kMaker):
132+
@cp2k_job
133+
def make(structure):
134+
# code to run Cp2k job.
135+
pass
136+
137+
Parameters
138+
----------
139+
method : callable
140+
A BaseCp2kMaker.make method. This should not be specified directly and is
141+
implied by the decorator.
142+
143+
Returns
144+
-------
145+
callable
146+
A decorated version of the make function that will generate Cp2k jobs.
147+
"""
148+
return job(method, data=_DATA_OBJECTS, output_schema=AbinitTaskDoc)
149+
150+
102151
@dataclass
103152
class BaseAbinitMaker(Maker):
104153
"""
@@ -136,7 +185,7 @@ def calc_type(self) -> str:
136185
"""Get the type of calculation for this maker."""
137186
return self.input_set_generator.calc_type
138187

139-
@job
188+
@abinit_job
140189
def make(
141190
self,
142191
structure: Structure | None = None,

src/atomate2/abinit/jobs/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
RelaxConvergenceWarning,
1313
ScfConvergenceWarning,
1414
)
15-
from jobflow import Job, job
1615

17-
from atomate2.abinit.jobs.base import BaseAbinitMaker
16+
from atomate2.abinit.jobs.base import BaseAbinitMaker, abinit_job
1817
from atomate2.abinit.sets.core import (
1918
LineNonSCFSetGenerator,
2019
NonSCFSetGenerator,
@@ -27,6 +26,7 @@
2726
if TYPE_CHECKING:
2827
from collections.abc import Sequence
2928

29+
from jobflow import Job
3030
from pymatgen.core.structure import Structure
3131

3232
from atomate2.abinit.sets.base import AbinitInputGenerator
@@ -114,7 +114,7 @@ class NonSCFMaker(BaseAbinitMaker):
114114
NscfConvergenceWarning,
115115
)
116116

117-
@job
117+
@abinit_job
118118
def make(
119119
self,
120120
structure: Structure | None = None,

src/atomate2/abinit/jobs/mrgddb.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
from atomate2.abinit.jobs.base import setup_job
1717
from atomate2.abinit.run import run_mrgddb
1818
from atomate2.abinit.schemas.calculation import TaskState
19-
from atomate2.abinit.schemas.mrgddb import MrgddbTaskDoc
19+
from atomate2.abinit.schemas.mrgddb import DdbFileStr, MrgddbTaskDoc
2020
from atomate2.abinit.sets.mrgddb import MrgddbInputGenerator
2121

2222
if TYPE_CHECKING:
23+
from typing import Callable
24+
2325
from atomate2.abinit.utils.history import JobHistory
2426

2527
logger = logging.getLogger(__name__)
@@ -28,6 +30,45 @@
2830
"MrgddbMaker",
2931
]
3032

33+
_MRGDDB_DATA_OBJECTS = [
34+
DdbFileStr,
35+
]
36+
37+
38+
def mrgddb_job(method: Callable) -> job:
39+
"""
40+
Decorate the ``make`` method of CP2K job makers.
41+
42+
This is a thin wrapper around :obj:`~jobflow.core.job.job` that configures common
43+
settings for all CP2K jobs. For example, it ensures that large data objects
44+
(band structures, density of states, Cubes, etc) are all stored in the
45+
atomate2 data store. It also configures the output schema to be a CP2K
46+
:obj:`.TaskDocument`.
47+
48+
Any makers that return CP2K jobs (not flows) should decorate the ``make`` method
49+
with @cp2k_job. For example:
50+
51+
.. code-block:: python
52+
53+
class MyCp2kMaker(BaseCp2kMaker):
54+
@cp2k_job
55+
def make(structure):
56+
# code to run Cp2k job.
57+
pass
58+
59+
Parameters
60+
----------
61+
method : callable
62+
A BaseCp2kMaker.make method. This should not be specified directly and is
63+
implied by the decorator.
64+
65+
Returns
66+
-------
67+
callable
68+
A decorated version of the make function that will generate Cp2k jobs.
69+
"""
70+
return job(method, data=_MRGDDB_DATA_OBJECTS, output_schema=MrgddbTaskDoc)
71+
3172

3273
@dataclass
3374
class MrgddbMaker(Maker):
@@ -54,7 +95,7 @@ def calc_type(self) -> str:
5495
"""Get the type of calculation for this maker."""
5596
return self.input_set_generator.calc_type
5697

57-
@job
98+
@mrgddb_job
5899
def make(
59100
self,
60101
prev_outputs: list[str] | None = None,

src/atomate2/abinit/jobs/response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from jobflow import Flow, Job, Response, job
1616

17-
from atomate2.abinit.jobs.base import BaseAbinitMaker
17+
from atomate2.abinit.jobs.base import BaseAbinitMaker, abinit_job
1818
from atomate2.abinit.powerups import update_user_abinit_settings
1919
from atomate2.abinit.sets.response import (
2020
DdeSetGenerator,
@@ -65,7 +65,7 @@ class ResponseMaker(BaseAbinitMaker):
6565
ScfConvergenceWarning,
6666
)
6767

68-
@job
68+
@abinit_job
6969
def make(
7070
self,
7171
structure: Structure | None = None,

src/atomate2/abinit/schemas/calculation.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import os
77
from datetime import datetime, timezone
88
from pathlib import Path
9-
from typing import Optional, Union
9+
from typing import Any, Optional, Union
1010

1111
from abipy.abio.outputs import AbinitOutputFile
12+
from abipy.dfpt.ddb import DdbFile
1213
from abipy.electrons.gsr import GsrFile
1314
from abipy.flowtk import events
1415
from abipy.flowtk.utils import File
@@ -18,6 +19,7 @@
1819
from pymatgen.core import Structure
1920
from typing_extensions import Self
2021

22+
from atomate2.abinit.schemas.mrgddb import DdbFileStr
2123
from atomate2.abinit.utils.common import (
2224
LOG_FILE_NAME,
2325
MPIABORTFILE,
@@ -44,6 +46,7 @@ class AbinitObject(ValueEnum):
4446
ELECTRON_DENSITY = "electron_density" # e_density
4547
WFN = "wfn" # Wavefunction file
4648
TRAJECTORY = "trajectory"
49+
DDBFILESTR = "ddbfilestr" # DDB file as string
4750

4851

4952
class CalculationOutput(BaseModel):
@@ -251,6 +254,7 @@ def from_abinit_files(
251254
abinit_log_file: Path | str = LOG_FILE_NAME,
252255
abinit_abort_file: Path | str = MPIABORTFILE,
253256
abinit_out_file: Path | str = OUTPUT_FILE_NAME,
257+
abinit_outddb_file: Path | str = "out_DDB",
254258
) -> tuple[Self, dict[AbinitObject, dict]]:
255259
"""
256260
Create an Abinit calculation document from a directory and file paths.
@@ -278,6 +282,14 @@ def from_abinit_files(
278282
abinit_log_file = dir_name / abinit_log_file
279283
abinit_abort_file = dir_name / abinit_abort_file
280284
abinit_out_file = dir_name / abinit_out_file
285+
abinit_outddb_file = dir_name / abinit_outddb_file
286+
287+
abinit_objects: dict[AbinitObject, Any] = {}
288+
if abinit_outddb_file.exists():
289+
abinit_outddb = DdbFile.from_file(abinit_outddb_file)
290+
abinit_objects[AbinitObject.DDBFILESTR] = DdbFileStr.from_ddbfile( # type: ignore[index]
291+
abinit_outddb
292+
)
281293

282294
output_doc = None
283295
if abinit_out_file.exists():
@@ -329,4 +341,4 @@ def from_abinit_files(
329341
event_report=report,
330342
)
331343

332-
return instance, None # abinit_objects,
344+
return (instance, abinit_objects)

0 commit comments

Comments
 (0)