forked from stfc/aiida-mlip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptors.py
104 lines (84 loc) · 3.09 KB
/
descriptors.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
93
94
95
96
97
98
99
100
101
102
103
104
"""Class to run descriptors calculations."""
from aiida.common import datastructures
import aiida.common.folders
from aiida.engine import CalcJobProcessSpec
import aiida.engine.processes
from aiida.orm import Bool
from aiida_mlip.calculations.singlepoint import Singlepoint
class Descriptors(Singlepoint): # numpydoc ignore=PR01
"""
Calcjob implementation to calculate MLIP descriptors.
Methods
-------
define(spec: CalcJobProcessSpec) -> None:
Define the process specification, its inputs, outputs and exit codes.
prepare_for_submission(folder: Folder) -> CalcInfo:
Create the input files for the `CalcJob`.
"""
@classmethod
def define(cls, spec: CalcJobProcessSpec) -> None:
"""
Define the process specification, its inputs, outputs and exit codes.
Parameters
----------
spec : aiida.engine.CalcJobProcessSpec
The calculation job process spec to define.
"""
super().define(spec)
# Define inputs
# Remove unused singlepoint input
del spec.inputs["properties"]
spec.input(
"invariants_only",
valid_type=Bool,
required=False,
help="Only calculate invariant descriptors.",
)
spec.input(
"calc_per_element",
valid_type=Bool,
required=False,
help="Calculate mean descriptors for each element.",
)
spec.input(
"calc_per_atom",
valid_type=Bool,
required=False,
help="Calculate descriptors for each atom.",
)
spec.inputs["metadata"]["options"][
"parser_name"
].default = "mlip.descriptors_parser"
def prepare_for_submission(
self, folder: aiida.common.folders.Folder
) -> datastructures.CalcInfo:
"""
Create the input files for the `Calcjob`.
Parameters
----------
folder : aiida.common.folders.Folder
Folder where the calculation is run.
Returns
-------
aiida.common.datastructures.CalcInfo
An instance of `aiida.common.datastructures.CalcInfo`.
"""
# Call the parent class method to prepare common inputs
calcinfo = super().prepare_for_submission(folder)
codeinfo = calcinfo.codes_info[0]
# Adding command line params for when we run janus
# descriptors is overwriting the placeholder "calculation" from the base.py file
codeinfo.cmdline_params[0] = "descriptors"
cmdline_options = {
key.replace("_", "-"): getattr(self.inputs, key).value
for key in ("invariants_only", "calc_per_element", "calc_per_atom")
if key in self.inputs
}
for flag, value in cmdline_options.items():
if isinstance(value, bool):
# Add boolean flags without value if True
if value:
codeinfo.cmdline_params.append(f"--{flag}")
else:
codeinfo.cmdline_params += [f"--{flag}", value]
return calcinfo