88from aiida .common .folders import Folder
99from aiida .engine import CalcJob
1010from aiida .engine .processes .process_spec import CalcJobProcessSpec
11- from aiida .orm import ArrayData , Dict , Float , Int , List , SinglefileData , Str
11+ from aiida .orm import Dict , Float , Int , List , SinglefileData , Str
1212from h5py import File as h5File
1313
14+ from aiida_fans .helpers import make_input_dict
15+
1416
1517class FansCalcBase (CalcJob ):
1618 """Base class of all calculations using FANS."""
@@ -20,9 +22,8 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
2022 """Define inputs, outputs, and exit codes of the calculation."""
2123 super ().define (spec )
2224
23- # Metadata
25+ # Default Metadata
2426 spec .inputs ["metadata" ]["label" ].default = "FANS"
25- # spec.inputs["metadata"]["dry_run"].default = True
2627 ## Processing Power
2728 spec .inputs ["metadata" ]["options" ]["withmpi" ].default = True
2829 spec .inputs ["metadata" ]["options" ]["resources" ].default = {
@@ -35,6 +36,10 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
3536 ## Parser
3637 spec .inputs ["metadata" ]["options" ]["parser_name" ].default = "fans"
3738
39+ # Custom Metadata
40+ spec .input ("metadata.options.results_prefix" , valid_type = str , default = "" )
41+ spec .input ("metadata.options.results" , valid_type = list , default = [])
42+
3843 # Input Ports
3944 ## Microstructure Definition
4045 spec .input_namespace ("microstructure" )
@@ -53,9 +58,7 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
5358 spec .input ("error_parameters.type" , valid_type = Str )
5459 spec .input ("error_parameters.tolerance" , valid_type = Float )
5560 ## Macroscale Loading Conditions
56- spec .input ("macroscale_loading" , valid_type = ArrayData )
57- ## Results Specification
58- spec .input ("results" , valid_type = List )
61+ spec .input ("macroscale_loading" , valid_type = List )
5962
6063 # Output Ports
6164 spec .output ("output" , valid_type = SinglefileData )
@@ -107,28 +110,8 @@ def prepare_for_submission(self, folder: Folder) -> CalcInfo:
107110 copyfileobj (source , target )
108111
109112 # input.json as dict
110- input_dict = {
111- ## Microstructure Definition
112- "ms_filename" : str (ms_filepath ), # path to stashed microstructure
113- "ms_datasetname" : self .inputs .microstructure .datasetname .value ,
114- "ms_L" : self .inputs .microstructure .L .get_list (),
115- ## Problem Type and Material Model
116- "problem_type" : self .inputs .problem_type .value ,
117- "matmodel" : self .inputs .matmodel .value ,
118- "material_properties" : self .inputs .material_properties .get_dict (),
119- ## Solver Settings
120- "method" : self .inputs .method .value ,
121- "n_it" : self .inputs .n_it .value ,
122- "error_parameters" : {
123- "measure" : self .inputs .error_parameters .measure .value ,
124- "type" : self .inputs .error_parameters .type .value ,
125- "tolerance" : self .inputs .error_parameters .tolerance .value
126- },
127- ## Macroscale Loading Conditions
128- "macroscale_loading" : [a [1 ].tolist () for a in self .inputs .macroscale_loading .get_iterarrays ()],
129- ## Results Specification
130- "results" : self .inputs .results .get_list ()
131- }
113+ input_dict = make_input_dict (self )
114+ input_dict ["microstructure" ]["filepath" ] = str (ms_filepath )
132115 # write input.json to working directory
133116 with folder .open (self .options .input_filename , "w" , "utf8" ) as json :
134117 dump (input_dict , json , indent = 4 )
@@ -154,28 +137,8 @@ def prepare_for_submission(self, folder: Folder) -> CalcInfo:
154137 h5_src .copy (datasetname , h5_dest , name = datasetname )
155138
156139 # input.json as dict
157- input_dict = {
158- ## Microstructure Definition
159- "ms_filename" : "microstructure.h5" , # path to fragmented microstructure
160- "ms_datasetname" : self .inputs .microstructure .datasetname .value ,
161- "ms_L" : self .inputs .microstructure .L .get_list (),
162- ## Problem Type and Material Model
163- "problem_type" : self .inputs .problem_type .value ,
164- "matmodel" : self .inputs .matmodel .value ,
165- "material_properties" : self .inputs .material_properties .get_dict (),
166- ## Solver Settings
167- "method" : self .inputs .method .value ,
168- "n_it" : self .inputs .n_it .value ,
169- "error_parameters" : {
170- "measure" : self .inputs .error_parameters .measure .value ,
171- "type" : self .inputs .error_parameters .type .value ,
172- "tolerance" : self .inputs .error_parameters .tolerance .value
173- },
174- ## Macroscale Loading Conditions
175- "macroscale_loading" : [a [1 ].tolist () for a in self .inputs .macroscale_loading .get_iterarrays ()],
176- ## Results Specification
177- "results" : self .inputs .results .get_list ()
178- }
140+ input_dict = make_input_dict (self )
141+ input_dict ["microstructure" ]["filepath" ] = "microstructure.h5"
179142 # write input.json to working directory
180143 with folder .open (self .options .input_filename , "w" , "utf8" ) as json :
181144 dump (input_dict , json , indent = 4 )
0 commit comments