15
15
from abipy .flowtk .utils import File
16
16
from emmet .core .math import Matrix3D , Vector3D
17
17
from jobflow .utils import ValueEnum
18
+ from monty .json import MSONable
18
19
from pydantic import BaseModel , Field
19
20
from pymatgen .core import Structure
20
21
from typing_extensions import Self
30
31
logger = logging .getLogger (__name__ )
31
32
32
33
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
+
33
55
class TaskState (ValueEnum ):
34
56
"""Abinit calculation state."""
35
57
@@ -46,7 +68,8 @@ class AbinitObject(ValueEnum):
46
68
ELECTRON_DENSITY = "electron_density" # e_density
47
69
WFN = "wfn" # Wavefunction file
48
70
TRAJECTORY = "trajectory"
49
- DDBFILESTR = "ddbfilestr" # DDB file as string
71
+ DDBFILESTR = "ddb" # DDB file as string
72
+ POTFILEBSTR = "potential" # POT file as b-string
50
73
51
74
52
75
class CalculationOutput (BaseModel ):
@@ -255,6 +278,7 @@ def from_abinit_files(
255
278
abinit_abort_file : Path | str = MPIABORTFILE ,
256
279
abinit_out_file : Path | str = OUTPUT_FILE_NAME ,
257
280
abinit_outddb_file : Path | str = "out_DDB" ,
281
+ abinit_outpot_file : Path | str = "out_POT" ,
258
282
) -> tuple [Self , dict [AbinitObject , dict ]]:
259
283
"""
260
284
Create an Abinit calculation document from a directory and file paths.
@@ -283,13 +307,18 @@ def from_abinit_files(
283
307
abinit_abort_file = dir_name / abinit_abort_file
284
308
abinit_out_file = dir_name / abinit_out_file
285
309
abinit_outddb_file = dir_name / abinit_outddb_file
310
+ abinit_outpot_file = dir_name / abinit_outpot_file
286
311
287
312
abinit_objects : dict [AbinitObject , Any ] = {}
288
313
if abinit_outddb_file .exists ():
289
314
abinit_outddb = DdbFile .from_file (abinit_outddb_file )
290
315
abinit_objects [AbinitObject .DDBFILESTR ] = DdbFileStr .from_ddbfile ( # type: ignore[index]
291
316
abinit_outddb
292
317
)
318
+ if abinit_outpot_file .exists ():
319
+ abinit_objects [AbinitObject .POTFILEBSTR ] = PotFileBStr .from_potfilepath ( # type: ignore[index]
320
+ abinit_outpot_file
321
+ )
293
322
294
323
output_doc = None
295
324
if abinit_out_file .exists ():
0 commit comments