diff --git a/aiida_quantumespresso/calculations/pp.py b/aiida_quantumespresso/calculations/pp.py index 317c714b9..d351a1dd2 100644 --- a/aiida_quantumespresso/calculations/pp.py +++ b/aiida_quantumespresso/calculations/pp.py @@ -75,6 +75,8 @@ def define(cls, spec): help='Output folder of a completed `PwCalculation`') spec.input('parameters', valid_type=orm.Dict, required=True, validator=validate_parameters, help='Use a node that specifies the input parameters for the namelists') + spec.input('settings', valid_type=orm.Dict, required=False, + help='Optional parameters to affect the way the calculation job is performed.') spec.input('metadata.options.input_filename', valid_type=str, default=cls._DEFAULT_INPUT_FILE) spec.input('metadata.options.output_filename', valid_type=str, default=cls._DEFAULT_OUTPUT_FILE) spec.input('metadata.options.parser_name', valid_type=str, default='quantumespresso.pp') @@ -130,6 +132,12 @@ def prepare_for_submission(self, folder): # pylint: disable=too-many-branches,t parameters = _uppercase_dict(self.inputs.parameters.get_dict(), dict_name='parameters') parameters = {k: _lowercase_dict(v, dict_name=k) for k, v in parameters.items()} + # Same for settings. + if 'settings' in self.inputs: + settings = _uppercase_dict(self.inputs.settings.get_dict(), dict_name='settings') + else: + settings = {} + # Set default values. NOTE: this is different from PW/CP for blocked in self._blocked_keywords: namelist = blocked[0].upper() @@ -204,6 +212,7 @@ def prepare_for_submission(self, folder): # pylint: disable=too-many-branches,t )) codeinfo = datastructures.CodeInfo() + codeinfo.cmdline_params = settings.pop('CMDLINE', []) codeinfo.stdin_name = self.inputs.metadata.options.input_filename codeinfo.stdout_name = self.inputs.metadata.options.output_filename codeinfo.code_uuid = self.inputs.code.uuid diff --git a/tests/calculations/test_pp.py b/tests/calculations/test_pp.py index 80e0a6826..1e4bdfad8 100644 --- a/tests/calculations/test_pp.py +++ b/tests/calculations/test_pp.py @@ -11,7 +11,7 @@ def generate_inputs(fixture_localhost, fixture_sandbox, fixture_code, generate_remote_data): """Return only those inputs that the parser will expect to be there.""" - def _generate_inputs(parameters=None): + def _generate_inputs(parameters=None, settings=None): from aiida_quantumespresso.utils.resources import get_default_options if parameters is None: @@ -24,6 +24,8 @@ def _generate_inputs(parameters=None): generate_remote_data(fixture_localhost, fixture_sandbox.abspath, 'quantumespresso.pw'), 'parameters': orm.Dict(dict=parameters), + 'settings': + orm.Dict(dict=settings), 'metadata': { 'options': get_default_options() } @@ -79,6 +81,14 @@ def test_pp_keep_plot_file(aiida_profile, fixture_sandbox, generate_calc_job, ge assert element in calc_info.retrieve_list +def test_pp_cmdline_setting(aiida_profile, fixture_sandbox, generate_calc_job, generate_inputs): + """Test a `PpCalculation` with user-defined cmdline settings.""" + entry_point_name = 'quantumespresso.pp' + inputs = generate_inputs(settings={'cmdline': ['-npools', '2']}) + calc_info = generate_calc_job(fixture_sandbox, entry_point_name, inputs) + assert calc_info.codes_info[0].cmdline_params == ['-npools', '2'] + + @pytest.mark.parametrize( ('parameters', 'message'), (