55from aiida .common import datastructures
66import aiida .common .folders
77from aiida .engine import CalcJobProcessSpec
8- import aiida .engine .processes
98from aiida .orm import (
109 Bool ,
1110 Dict ,
1211 Float ,
1312 Int ,
1413 SinglefileData ,
15- Str ,
1614 StructureData ,
1715 TrajectoryData ,
1816)
17+ from aiida .orm .utils .managers import NodeLinksManager
18+ from plumpy .utils import AttributesFrozendict
1919
2020from aiida_mlip .calculations .singlepoint import Singlepoint
2121
@@ -48,13 +48,6 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
4848 super ().define (spec )
4949
5050 # Additional inputs for geometry optimisation
51- spec .input (
52- "traj" ,
53- valid_type = Str ,
54- required = False ,
55- default = lambda : Str (cls .DEFAULT_TRAJ_FILE ),
56- help = "Path to save optimisation frames to" ,
57- )
5851 spec .input (
5952 "opt_cell_fully" ,
6053 valid_type = Bool ,
@@ -82,10 +75,10 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
8275 )
8376
8477 spec .input (
85- "opt_kwargs " ,
78+ "minimize_kwargs " ,
8679 valid_type = Dict ,
8780 required = False ,
88- help = "Other optimisation keywords " ,
81+ help = "All other keyword arguments to pass to geometry optimizer " ,
8982 )
9083
9184 spec .inputs ["metadata" ]["options" ]["parser_name" ].default = "mlip.opt_parser"
@@ -114,17 +107,12 @@ def prepare_for_submission(
114107 calcinfo = super ().prepare_for_submission (folder )
115108 codeinfo = calcinfo .codes_info [0 ]
116109
117- minimize_kwargs = (
118- f"{{'traj_kwargs': {{'filename': '{ self .inputs .traj .value } '}}}}"
119- )
110+ minimize_kwargs = self .set_minimize_kwargs (self .inputs )
120111
121112 geom_opt_cmdline = {
122113 "minimize-kwargs" : minimize_kwargs ,
123114 "write-traj" : True ,
124115 }
125- if "opt_kwargs" in self .inputs :
126- opt_kwargs = self .inputs .opt_kwargs .get_dict ()
127- geom_opt_cmdline ["opt-kwargs" ] = opt_kwargs
128116 if "opt_cell_fully" in self .inputs :
129117 geom_opt_cmdline ["opt-cell-fully" ] = self .inputs .opt_cell_fully .value
130118 if "opt_cell_lengths" in self .inputs :
@@ -146,6 +134,36 @@ def prepare_for_submission(
146134 else :
147135 codeinfo .cmdline_params += [f"--{ flag } " , value ]
148136
149- calcinfo .retrieve_list .append (self . inputs . traj . value )
137+ calcinfo .retrieve_list .append (minimize_kwargs [ "traj_kwargs" ][ "filename" ] )
150138
151139 return calcinfo
140+
141+ @classmethod
142+ def set_minimize_kwargs (
143+ cls , inputs : AttributesFrozendict | NodeLinksManager
144+ ) -> dict [str , dict [str , str ]]:
145+ """
146+ Set minimize kwargs from CalcJob inputs.
147+
148+ Parameters
149+ ----------
150+ inputs : x
151+ CalcJob inputs.
152+
153+ Returns
154+ -------
155+ dict[str, dict[str, str]]
156+ Set minimize_kwargs dict with trajectory filename extracted from `traj`,
157+ the config file, or set as the default.
158+ """
159+ if "minimize_kwargs" in inputs :
160+ minimize_kwargs = inputs .minimize_kwargs .get_dict ()
161+ elif "config" in inputs :
162+ minimize_kwargs = inputs .config .as_dictionary .get ("minimize_kwargs" , {})
163+ else :
164+ minimize_kwargs = {}
165+
166+ minimize_kwargs .setdefault ("traj_kwargs" , {})
167+ minimize_kwargs ["traj_kwargs" ].setdefault ("filename" , cls .DEFAULT_TRAJ_FILE )
168+
169+ return minimize_kwargs
0 commit comments