19
19
@click .option ('-m' , '--description' , type = str )
20
20
@cp2k_options .STRUCTURE ()
21
21
@cp2k_options .DAEMON ()
22
+ @cp2k_options .MAX_NUM_MACHINES ()
23
+ @cp2k_options .MAX_WALLCLOCK_SECONDS ()
22
24
@decorators .with_dbenv ()
23
- def cmd_launch_workflow (code , daemon , cp2k_input_file , label , description , structure ):
25
+ def cmd_launch_workflow (code , daemon , cp2k_input_file , label , description , structure , max_num_machines ,
26
+ max_wallclock_seconds ):
24
27
"""Run a CP2K calculation with a given input file through AiiDA"""
28
+ # pylint: disable=too-many-arguments,too-many-branches,too-many-statements
25
29
26
30
from aiida .orm import Dict
27
31
from aiida .plugins import WorkflowFactory
32
+ from aiida .orm .nodes .data .structure import StructureData
28
33
from cp2k_input_tools .parser import CP2KInputParserSimplified
29
34
30
35
parser = CP2KInputParserSimplified (key_trafo = str .upper ,
@@ -33,33 +38,62 @@ def cmd_launch_workflow(code, daemon, cp2k_input_file, label, description, struc
33
38
level_reduction_blacklist = ["KIND" ])
34
39
tree = parser .parse (cp2k_input_file )
35
40
36
- builder = WorkflowFactory ('cp2k.base' ).get_builder ()
41
+ try :
42
+ tree ["FORCE_EVAL" ]["SUBSYS" ].pop ("COORD" )
43
+ structure_in_config = True
44
+ except KeyError :
45
+ structure_in_config = False
46
+
47
+ try :
48
+ coord_file_from_config = tree ["FORCE_EVAL" ]["SUBSYS" ]["TOPOLOGY" ].pop ("COORD_FILE_NAME" )
49
+ except KeyError :
50
+ coord_file_from_config = None
37
51
52
+ builder = WorkflowFactory ('cp2k.base' ).get_builder ()
38
53
builder .cp2k .code = code
39
54
40
55
if structure :
41
56
builder .cp2k .structure = structure
42
57
43
- try :
44
- tree ["FORCE_EVAL" ]["SUBSYS" ]["TOPOLOGY" ].pop ("COORD_FILE_NAME" )
45
- echo .echo_info ("The explicitly given structure overrides the structure referenced in the input file" )
46
- except KeyError :
47
- pass
58
+ if coord_file_from_config :
59
+ echo .echo_info (
60
+ "The explicitly given structure will override the structure file referenced in the input file" )
48
61
49
- else :
62
+ if structure_in_config :
63
+ echo .echo_info ("The explicitly given structure will override the structure in the input file" )
64
+
65
+ elif structure_in_config :
50
66
try :
51
- with open ( cp2k_input_file .name , "r" ) as fhandle :
52
- builder .cp2k .structure = structure_from_cp2k_inp (fhandle )
67
+ cp2k_input_file .seek ( 0 )
68
+ builder .cp2k .structure = structure_from_cp2k_inp (cp2k_input_file )
53
69
builder .cp2k .structure .store ()
54
70
echo .echo ("Created StructureData<{}> from file {}]\n " .format (builder .cp2k .structure .pk ,
55
71
cp2k_input_file .name ))
56
72
except ValueError as err :
57
73
echo .echo_critical (str (err ))
58
74
75
+ elif coord_file_from_config :
76
+ try :
77
+ import ase .io
78
+ except ImportError :
79
+ echo .echo_critical ('You have not installed the package ase. \n You can install it with: pip install ase' )
80
+
81
+ try :
82
+ asecell = ase .io .read (coord_file_from_config )
83
+ builder .cp2k .structure = StructureData (ase = asecell )
84
+ builder .cp2k .structure .store ()
85
+ echo .echo ("Created StructureData<{}> from file {}]\n " .format (builder .cp2k .structure .pk ,
86
+ coord_file_from_config ))
87
+ except ValueError as err :
88
+ echo .echo_critical (str (err ))
89
+ else :
90
+ echo .echo_critical ("No structure found/referenced in the input file and not set explicitly" )
91
+
59
92
builder .cp2k .metadata .options = {
60
93
"resources" : {
61
- "num_machines" : 1 ,
94
+ "num_machines" : max_num_machines ,
62
95
},
96
+ 'max_wallclock_seconds' : int (max_wallclock_seconds ),
63
97
}
64
98
builder .cp2k .parameters = Dict (dict = tree )
65
99
0 commit comments