Skip to content

Commit 5a11071

Browse files
committed
store _POT files
1 parent 96f8674 commit 5a11071

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/atomate2/abinit/jobs/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from atomate2 import SETTINGS
1616
from atomate2.abinit.files import write_abinit_input_set
1717
from atomate2.abinit.run import run_abinit
18-
from atomate2.abinit.schemas.calculation import TaskState
18+
from atomate2.abinit.schemas.calculation import PotFileBStr, TaskState
1919
from atomate2.abinit.schemas.mrgddb import DdbFileStr
2020
from atomate2.abinit.schemas.task import AbinitTaskDoc
2121
from atomate2.abinit.utils.common import UnconvergedError
@@ -110,6 +110,7 @@ def setup_job(
110110
# VolumetricData,
111111
# Trajectory,
112112
DdbFileStr,
113+
PotFileBStr,
113114
]
114115

115116

src/atomate2/abinit/schemas/calculation.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from abipy.flowtk.utils import File
1616
from emmet.core.math import Matrix3D, Vector3D
1717
from jobflow.utils import ValueEnum
18+
from monty.json import MSONable
1819
from pydantic import BaseModel, Field
1920
from pymatgen.core import Structure
2021
from typing_extensions import Self
@@ -30,6 +31,27 @@
3031
logger = logging.getLogger(__name__)
3132

3233

34+
class PotFileBStr(MSONable):
35+
"""Object storing the raw binary string of a POT file."""
36+
37+
def __init__(
38+
self, potfilepath: str | Path, potfilename: str, pot_as_bstr: bytes
39+
) -> None:
40+
self.potfilepath = potfilepath
41+
self.potfilename = potfilename
42+
self.pot_as_bstr = pot_as_bstr
43+
44+
@classmethod
45+
def from_potfilepath(cls, potfilepath: str | Path) -> Self:
46+
"""Create a PotFileBStr by directly reading the file."""
47+
with open(potfilepath, "rb") as f:
48+
pot_as_bstr = f.read()
49+
potfilename = Path(potfilepath).name
50+
return cls(
51+
potfilepath=potfilepath, potfilename=potfilename, pot_as_bstr=pot_as_bstr
52+
)
53+
54+
3355
class TaskState(ValueEnum):
3456
"""Abinit calculation state."""
3557

@@ -46,7 +68,8 @@ class AbinitObject(ValueEnum):
4668
ELECTRON_DENSITY = "electron_density" # e_density
4769
WFN = "wfn" # Wavefunction file
4870
TRAJECTORY = "trajectory"
49-
DDBFILESTR = "ddbfilestr" # DDB file as string
71+
DDBFILESTR = "ddb" # DDB file as string
72+
POTFILEBSTR = "potential" # POT file as b-string
5073

5174

5275
class CalculationOutput(BaseModel):
@@ -255,6 +278,7 @@ def from_abinit_files(
255278
abinit_abort_file: Path | str = MPIABORTFILE,
256279
abinit_out_file: Path | str = OUTPUT_FILE_NAME,
257280
abinit_outddb_file: Path | str = "out_DDB",
281+
abinit_outpot_file: Path | str = "out_POT",
258282
) -> tuple[Self, dict[AbinitObject, dict]]:
259283
"""
260284
Create an Abinit calculation document from a directory and file paths.
@@ -283,13 +307,18 @@ def from_abinit_files(
283307
abinit_abort_file = dir_name / abinit_abort_file
284308
abinit_out_file = dir_name / abinit_out_file
285309
abinit_outddb_file = dir_name / abinit_outddb_file
310+
abinit_outpot_file = dir_name / abinit_outpot_file
286311

287312
abinit_objects: dict[AbinitObject, Any] = {}
288313
if abinit_outddb_file.exists():
289314
abinit_outddb = DdbFile.from_file(abinit_outddb_file)
290315
abinit_objects[AbinitObject.DDBFILESTR] = DdbFileStr.from_ddbfile( # type: ignore[index]
291316
abinit_outddb
292317
)
318+
if abinit_outpot_file.exists():
319+
abinit_objects[AbinitObject.POTFILEBSTR] = PotFileBStr.from_potfilepath( # type: ignore[index]
320+
abinit_outpot_file
321+
)
293322

294323
output_doc = None
295324
if abinit_out_file.exists():

src/atomate2/abinit/schemas/mrgddb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def from_ddbfile(cls, ddbfile: DdbFile) -> Self:
5252
class MrgddbObject(ValueEnum):
5353
"""Types of Mrgddb data objects."""
5454

55-
DDBFILESTR = "ddbfilestr" # DDB file as string
55+
DDBFILESTR = "ddb" # DDB file as string
5656

5757

5858
class CalculationOutput(BaseModel):

src/atomate2/abinit/schemas/task.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ def _get_task_files(files: list[Path], suffix: str = "") -> dict:
381381
abinit_files["abinit_out_file"] = Path(file).relative_to(path)
382382
elif file.match(f"*outdata/out_DDB{suffix}*"):
383383
abinit_files["abinit_outddb_file"] = Path(file).relative_to(path)
384+
elif file.match(f"*outdata/out_POT{suffix}*"):
385+
abinit_files["abinit_outpot_file"] = Path(file).relative_to(path)
384386

385387
return abinit_files
386388

0 commit comments

Comments
 (0)