-
Notifications
You must be signed in to change notification settings - Fork 4
/
opt_parser.py
92 lines (71 loc) · 2.52 KB
/
opt_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Geom optimisation parser.
"""
from pathlib import Path
from aiida.common import exceptions
from aiida.engine import ExitCode
from aiida.orm import SinglefileData
from aiida.orm.nodes.process.process import ProcessNode
from aiida.plugins import CalculationFactory
from aiida_mlip.helpers.converters import xyz_to_aiida_traj
from aiida_mlip.parsers.sp_parser import SPParser
geomoptCalculation = CalculationFactory("mlip.opt")
class GeomOptParser(SPParser):
"""
Parser class for parsing output of geometry optimisation calculation.
Inherits from SPParser.
Parameters
----------
node : aiida.orm.nodes.process.process.ProcessNode
ProcessNode of calculation.
Methods
-------
parse(**kwargs: Any) -> int:
Parse outputs, store results in the database.
Returns
-------
int
An exit code.
Raises
------
exceptions.ParsingError
If the ProcessNode being passed was not produced by a `GeomOpt`.
"""
def __init__(self, node: ProcessNode):
"""
Check that the ProcessNode being passed was produced by a `GeomOpt`.
Parameters
----------
node : aiida.orm.nodes.process.process.ProcessNode
ProcessNode of calculation.
"""
super().__init__(node)
if not issubclass(node.process_class, geomoptCalculation):
raise exceptions.ParsingError("Can only parse `GeomOpt` calculations")
def parse(self, **kwargs) -> ExitCode:
"""
Parse outputs, store results in the database.
Parameters
----------
**kwargs : Any
Any keyword arguments.
Returns
-------
int
An exit code.
"""
# Call the parent parse method to handle common parsing logic
exit_code = super().parse(**kwargs)
if exit_code == ExitCode(0):
traj_file = (self.node.inputs.traj).value
# Parse the trajectory file and save it as `SingleFileData`
with self.retrieved.open(traj_file, "rb") as handle:
self.out("traj_file", SinglefileData(file=handle, filename=traj_file))
# Parse trajectory and save it as `TrajectoryData`
opt, traj_output = xyz_to_aiida_traj(
Path(self.node.get_remote_workdir(), traj_file)
)
self.out("traj_output", traj_output)
# Parse the final structure of the trajectory to obtain the opt structure
self.out("final_structure", opt)
return exit_code