-
Notifications
You must be signed in to change notification settings - Fork 10
/
calculations.py
92 lines (79 loc) · 2.89 KB
/
calculations.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
"""
Calculations provided by aiida_diff.
Register calculations via the "aiida.calculations" entry point in setup.json.
"""
from aiida.common import datastructures
from aiida.engine import CalcJob
from aiida.orm import SinglefileData
from aiida.plugins import DataFactory
DiffParameters = DataFactory("diff")
class DiffCalculation(CalcJob):
"""
AiiDA calculation plugin wrapping the diff executable.
Simple AiiDA plugin wrapper for 'diffing' two files.
"""
@classmethod
def define(cls, spec):
"""Define inputs and outputs of the calculation."""
super().define(spec)
# set default values for AiiDA options
spec.inputs["metadata"]["options"]["resources"].default = {
"num_machines": 1,
"num_mpiprocs_per_machine": 1,
}
spec.inputs["metadata"]["options"]["parser_name"].default = "diff"
# new ports
spec.input(
"metadata.options.output_filename", valid_type=str, default="patch.diff"
)
spec.input(
"parameters",
valid_type=DiffParameters,
help="Command line parameters for diff",
)
spec.input(
"file1", valid_type=SinglefileData, help="First file to be compared."
)
spec.input(
"file2", valid_type=SinglefileData, help="Second file to be compared."
)
spec.output(
"diff",
valid_type=SinglefileData,
help="diff between file1 and file2.",
)
spec.exit_code(
300,
"ERROR_MISSING_OUTPUT_FILES",
message="Calculation did not produce all expected output files.",
)
def prepare_for_submission(self, folder):
"""
Create input files.
:param folder: an `aiida.common.folders.Folder` where the plugin should temporarily place all files
needed by the calculation.
:return: `aiida.common.datastructures.CalcInfo` instance
"""
codeinfo = datastructures.CodeInfo()
codeinfo.cmdline_params = self.inputs.parameters.cmdline_params(
file1_name=self.inputs.file1.filename, file2_name=self.inputs.file2.filename
)
codeinfo.code_uuid = self.inputs.code.uuid
codeinfo.stdout_name = self.metadata.options.output_filename
# Prepare a `CalcInfo` to be returned to the engine
calcinfo = datastructures.CalcInfo()
calcinfo.codes_info = [codeinfo]
calcinfo.local_copy_list = [
(
self.inputs.file1.uuid,
self.inputs.file1.filename,
self.inputs.file1.filename,
),
(
self.inputs.file2.uuid,
self.inputs.file2.filename,
self.inputs.file2.filename,
),
]
calcinfo.retrieve_list = [self.metadata.options.output_filename]
return calcinfo