def test_from_string(self): """Test construction from string.""" cli = CliParameters.from_string(self.test_parameters_string) self.compare_dictionaries(cli.parameters, self.test_parameters_dict, exclude_keys=['fix-syntax-errors']) string = '--print-datablocks' cli = CliParameters.from_string(string) self.compare_dictionaries(cli.parameters, {'print-datablocks': True})
def test_get_string(self): """Test `get_string` method.""" cli = CliParameters(self.test_parameters_dict) parameters_string = cli.get_string() for key, value in cli.parameters.items(): if isinstance(value, bool): # If the value is a boolean, the key should only be in the string if the value is True assert (key in parameters_string) == value else: # For all other value types, the key and the string version of the value should be found in the string assert key in parameters_string assert str(value) in parameters_string
def launch_calculation(code, cif, parameters, daemon, dry_run): """Run any cod-tools calculation for the given ``CifData`` node. The ``-p/--parameters`` option takes a single string with any command line parameters that you want to be passed to the calculation, and by extension the cod-tools script. Example:: aiida-codtools calculation launch cod-tools -X cif-filter -N 95 -p '--use-c-parser --authors "Jane Doe"' The parameters will be parsed into a dictionary and passed as the ``parameters`` input node to the calculation. """ from aiida import orm from aiida.plugins import factories from aiida_codtools.cli.utils.parameters import CliParameters from aiida_codtools.common.resources import get_default_options parameters = CliParameters.from_string(parameters).get_dictionary() inputs = { 'cif': cif, 'code': code, 'metadata': { 'options': get_default_options(), 'dry_run': dry_run, 'store_provenance': not dry_run } } if parameters: inputs['parameters'] = orm.Dict(dict=parameters) launch.launch_process(factories.CalculationFactory(code.get_attribute('input_plugin')), daemon, **inputs)
def prepare_for_submission(self, folder): """This method is called prior to job submission with a set of calculation input nodes. The inputs will be validated and sanitized, after which the necessary input files will be written to disk in a temporary folder. A CalcInfo instance will be returned that contains lists of files that need to be copied to the remote machine before job submission, as well as file lists that are to be retrieved after job completion. :param folder: an aiida.common.folders.Folder to temporarily write files on disk :returns: CalcInfo instance """ from aiida_codtools.cli.utils.parameters import CliParameters try: parameters = self.inputs.parameters.get_dict() except AttributeError: parameters = {} # The input file should simply contain the relative filename that contains the CIF to be deposited with folder.open(self.options.input_filename, 'w') as handle: handle.write(u'{}\n'.format(self.filename_cif)) # Write parameters that relate to the config file to that file and remove them from the CLI parameters with folder.open(self.filename_config, 'w') as handle: for key in self._config_keys: if key in parameters: handle.write(u'{}={}\n'.format(key, parameters.pop(key))) cli_parameters = copy.deepcopy(self._default_cli_parameters) cli_parameters.update(parameters) codeinfo = datastructures.CodeInfo() codeinfo.code_uuid = self.inputs.code.uuid codeinfo.cmdline_params = CliParameters.from_dictionary(cli_parameters).get_list() codeinfo.stdin_name = self.options.input_filename codeinfo.stdout_name = self.options.output_filename codeinfo.stderr_name = self.options.error_filename calcinfo = datastructures.CalcInfo() calcinfo.uuid = str(self.uuid) calcinfo.codes_info = [codeinfo] calcinfo.retrieve_list = [self.options.output_filename, self.options.error_filename] calcinfo.local_copy_list = [(self.inputs.cif.uuid, self.inputs.cif.filename, self.filename_cif)] calcinfo.remote_copy_list = [] return calcinfo
def prepare_for_submission(self, folder): """This method is called prior to job submission with a set of calculation input nodes. The inputs will be validated and sanitized, after which the necessary input files will be written to disk in a temporary folder. A CalcInfo instance will be returned that contains lists of files that need to be copied to the remote machine before job submission, as well as file lists that are to be retrieved after job completion. :param folder: an aiida.common.folders.Folder to temporarily write files on disk :returns: CalcInfo instance """ from aiida_codtools.cli.utils.parameters import CliParameters try: parameters = self.inputs.parameters.get_dict() except AttributeError: parameters = {} self._validate_resources() cli_parameters = copy.deepcopy(self._default_cli_parameters) cli_parameters.update(parameters) codeinfo = datastructures.CodeInfo() codeinfo.code_uuid = self.inputs.code.uuid codeinfo.cmdline_params = CliParameters.from_dictionary(cli_parameters).get_list() codeinfo.stdin_name = self.options.input_filename codeinfo.stdout_name = self.options.output_filename codeinfo.stderr_name = self.options.error_filename calcinfo = datastructures.CalcInfo() calcinfo.uuid = str(self.uuid) calcinfo.codes_info = [codeinfo] calcinfo.retrieve_list = [self.options.output_filename, self.options.error_filename] calcinfo.local_copy_list = [(self.inputs.cif.uuid, self.inputs.cif.filename, self.options.input_filename)] calcinfo.remote_copy_list = [] return calcinfo
def test_get_dictionary(self): """Test `get_dictionary` method.""" cli = CliParameters(self.test_parameters_dict) self.compare_dictionaries(cli.get_dictionary(), self.test_parameters_dict)
def test_from_dictionary(self): """Test construction from dictionary.""" cli = CliParameters.from_dictionary(self.test_parameters_dict) self.compare_dictionaries(cli.parameters, self.test_parameters_dict)
def test_construction(self): """Test normal construction.""" cli = CliParameters(self.test_parameters_dict) self.compare_dictionaries(cli.parameters, self.test_parameters_dict)