2
2
"""``CalcJob`` plugin for PySCF."""
3
3
from __future__ import annotations
4
4
5
+ import copy
5
6
import io
6
7
import numbers
7
8
import pathlib
@@ -128,14 +129,15 @@ def define(cls, spec: CalcJobProcessSpec): # type: ignore[override]
128
129
)
129
130
130
131
@classmethod
131
- def validate_parameters (cls , value : Dict | None , _ ) -> str | None : # pylint: disable=too-many-return-statements,too-many-branches
132
+ def validate_parameters (cls , value : Dict | None , _ ) -> str | None : # pylint: disable=too-many-return-statements,too-many-branches,too-many-locals
132
133
"""Validate the parameters input."""
133
134
if not value :
134
135
return None
135
136
136
- parameters = value .get_dict ()
137
+ parameters = copy . deepcopy ( value .get_dict () )
137
138
138
- mean_field_method = parameters .get ('mean_field' , {}).get ('method' )
139
+ mean_field = parameters .pop ('mean_field' , {})
140
+ mean_field_method = mean_field .pop ('method' , None )
139
141
valid_methods = ['RKS' , 'RHF' , 'DKS' , 'DHF' , 'GKS' , 'GHF' , 'HF' , 'KS' , 'ROHF' , 'ROKS' , 'UKS' , 'UHF' ]
140
142
options = ' ' .join (valid_methods )
141
143
@@ -145,24 +147,24 @@ def validate_parameters(cls, value: Dict | None, _) -> str | None: # pylint: di
145
147
if mean_field_method not in valid_methods :
146
148
return f'Specified mean field method { mean_field_method } is not supported, choose from: { options } '
147
149
148
- if 'chkfile' in parameters . get ( ' mean_field' , {}) :
150
+ if 'chkfile' in mean_field :
149
151
return (
150
152
'The `chkfile` cannot be specified in the `mean_field` parameters. It is set automatically by the '
151
153
'plugin if the `checkpoint` input is provided.'
152
154
)
153
155
154
- if 'optimizer' in parameters :
156
+ if ( optimizer := parameters . pop ( 'optimizer' , None )) is not None :
155
157
valid_solvers = ('geometric' , 'berny' )
156
- solver = parameters [ ' optimizer' ] .get ('solver' )
158
+ solver = optimizer .get ('solver' )
157
159
158
160
if solver is None :
159
161
return f'No solver specified in `optimizer` parameters. Choose from: { valid_solvers } '
160
162
161
163
if solver .lower () not in valid_solvers :
162
164
return f'Invalid solver `{ solver } ` specified in `optimizer` parameters. Choose from: { valid_solvers } '
163
165
164
- if 'cubegen' in parameters :
165
- orbitals = parameters [ ' cubegen' ] .get ('orbitals' )
166
+ if ( cubegen := parameters . pop ( 'cubegen' , None )) is not None :
167
+ orbitals = cubegen .get ('orbitals' )
166
168
indices = orbitals .get ('indices' ) if orbitals is not None else None
167
169
168
170
if orbitals is not None and indices is None :
@@ -174,9 +176,9 @@ def validate_parameters(cls, value: Dict | None, _) -> str | None: # pylint: di
174
176
if indices is not None and (not isinstance (indices , list ) or any (not isinstance (e , int ) for e in indices )):
175
177
return f'The `cubegen.orbitals.indices` parameter should be a list of integers, but got: { indices } '
176
178
177
- if 'fcidump' in parameters :
178
- active_spaces = parameters [ ' fcidump' ] .get ('active_spaces' )
179
- occupations = parameters [ ' fcidump' ] .get ('occupations' )
179
+ if ( fcidump := parameters . pop ( 'fcidump' , None )) is not None :
180
+ active_spaces = fcidump .get ('active_spaces' )
181
+ occupations = fcidump .get ('occupations' )
180
182
arrays = []
181
183
182
184
for key , data in (('active_spaces' , active_spaces ), ('occupations' , occupations )):
@@ -193,6 +195,13 @@ def validate_parameters(cls, value: Dict | None, _) -> str | None: # pylint: di
193
195
if arrays [0 ].shape != arrays [1 ].shape :
194
196
return 'The `fcipdump.active_spaces` and `fcipdump.occupations` arrays have different shapes.'
195
197
198
+ # Remove other known arguments
199
+ for key in ('hessian' , 'results' , 'structure' ):
200
+ parameters .pop (key , None )
201
+
202
+ if unknown_keys := list (parameters .keys ()):
203
+ return f'The following arguments are not supported: { ", " .join (unknown_keys )} '
204
+
196
205
def get_template_environment (self ) -> Environment :
197
206
"""Return the template environment that should be used for rendering.
198
207
0 commit comments