def _prepare_for_submission(self,tempfolder, inputdict):
try:<EOL><INDENT>code = inputdict.pop(self.get_linkname('<STR_LIT:code>'))<EOL><DEDENT>except KeyError:<EOL><INDENT>raise InputValidationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>parameters = inputdict.pop(self.get_linkname('<STR_LIT>'))<EOL><DEDENT>except KeyError:<EOL><INDENT>raise InputValidationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if not isinstance(parameters, ParameterData):<EOL><INDENT>raise InputValidationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>structure = inputdict.pop(self.get_linkname('<STR_LIT>'))<EOL><DEDENT>except KeyError:<EOL><INDENT>raise InputValidationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if not isinstance(structure,StructureData):<EOL><INDENT>raise InputValidationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>settings = inputdict.pop(self.get_linkname('<STR_LIT>'),None)<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>if settings is not None:<EOL><INDENT>if not isinstance(parameters, ParameterData):<EOL><INDENT>raise InputValidationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>try:<EOL><INDENT>kpoints = inputdict.pop(self.get_linkname('<STR_LIT>'),None)<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>if kpoints is not None:<EOL><INDENT>if not isinstance(kpoints, KpointsData):<EOL><INDENT>raise InputValidationError("<STR_LIT>")<EOL><DEDENT><DEDENT>default_atoms_getters = [ ["<STR_LIT>","<STR_LIT>"] ] <EOL>atoms = structure.get_ase()<EOL>atoms.write(tempfolder.get_abs_path(self._input_aseatoms))<EOL>parameters_dict = parameters.get_dict()<EOL>settings_dict = settings.get_dict() if settings is not None else {}<EOL>optimizer = parameters_dict.pop("<STR_LIT>",None)<EOL>if optimizer is not None:<EOL><INDENT>if not isinstance(optimizer,dict):<EOL><INDENT>raise InputValidationError("<STR_LIT>")<EOL><DEDENT>optimizer_name = optimizer.pop("<STR_LIT:name>",None)<EOL>if optimizer_name is None:<EOL><INDENT>raise InputValidationError("<STR_LIT>")<EOL><DEDENT>optimizer_argsstr = "<STR_LIT>" + convert_the_args(optimizer.pop("<STR_LIT:args>",[]))<EOL>optimizer_runargsstr = convert_the_args(optimizer.pop("<STR_LIT>",[]))<EOL>optimizer_import_string = get_optimizer_impstr(optimizer_name)<EOL><DEDENT>calculator = parameters_dict.pop("<STR_LIT>",{})<EOL>calculator_import_string = get_calculator_impstr(calculator.pop("<STR_LIT:name>",None))<EOL>read_calc_args = calculator.pop("<STR_LIT:args>",[])<EOL>if read_calc_args is None:<EOL><INDENT>calc_argsstr = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>calc_args = {}<EOL>for k,v in read_calc_args.iteritems():<EOL><INDENT>if isinstance(v, basestring):<EOL><INDENT>the_v = '<STR_LIT>'.format(v)<EOL><DEDENT>else:<EOL><INDENT>the_v = v<EOL><DEDENT>calc_args[k] = the_v<EOL><DEDENT>def return_a_function(v):<EOL><INDENT>try:<EOL><INDENT>has_magic = "<STR_LIT>" in v.keys()<EOL><DEDENT>except AttributeError:<EOL><INDENT>has_magic = False<EOL><DEDENT>if has_magic:<EOL><INDENT>args_dict = {}<EOL>for k2,v2 in v['<STR_LIT:args>'].iteritems():<EOL><INDENT>if isinstance(v2,basestring):<EOL><INDENT>the_v = '<STR_LIT>'.format(v2)<EOL><DEDENT>else:<EOL><INDENT>the_v = v2<EOL><DEDENT>args_dict[k2] = the_v<EOL><DEDENT>v2 = "<STR_LIT>".format(v['<STR_LIT>'],<EOL>"<STR_LIT:U+002CU+0020>".join(["<STR_LIT>".format(k_,v_) <EOL>for k_,v_ in args_dict.iteritems()]))<EOL>return v2<EOL><DEDENT>else:<EOL><INDENT>return v<EOL><DEDENT><DEDENT>tmp_list = [ "<STR_LIT>".format(k,return_a_function(v)) <EOL>for k,v in calc_args.iteritems() ]<EOL>calc_argsstr = "<STR_LIT:U+002CU+0020>".join( tmp_list )<EOL>if kpoints:<EOL><INDENT>try:<EOL><INDENT>mesh = kpoints.get_kpoints_mesh()[<NUM_LIT:0>]<EOL><DEDENT>except AttributeError:<EOL><INDENT>raise InputValidationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>calc_argsstr = "<STR_LIT:U+002CU+0020>".join( [calc_argsstr] + ["<STR_LIT>".format( *mesh )] )<EOL><DEDENT><DEDENT>atoms_getters = default_atoms_getters + convert_the_getters( parameters_dict.pop("<STR_LIT>",[]) )<EOL>calculator_getters = convert_the_getters( parameters_dict.pop("<STR_LIT>",[]) )<EOL>all_imports = ["<STR_LIT>", '<STR_LIT>', "<STR_LIT>",<EOL>"<STR_LIT>", calculator_import_string]<EOL>if optimizer is not None:<EOL><INDENT>all_imports.append(optimizer_import_string)<EOL><DEDENT>try:<EOL><INDENT>if "<STR_LIT>" in calc_args['<STR_LIT>'].values():<EOL><INDENT>all_imports.append("<STR_LIT>")<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>extra_imports = parameters_dict.pop("<STR_LIT>",[])<EOL>for i in extra_imports:<EOL><INDENT>if isinstance(i,basestring):<EOL><INDENT>all_imports.append("<STR_LIT>".format(i))<EOL><DEDENT>elif isinstance(i,(list,tuple)):<EOL><INDENT>if not all( [isinstance(j,basestring) for j in i] ):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(i)==<NUM_LIT:2>:<EOL><INDENT>all_imports.append("<STR_LIT>".format(*i))<EOL><DEDENT>elif len(i)==<NUM_LIT:3>:<EOL><INDENT>all_imports.append("<STR_LIT>".format(*i))<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if self.get_withmpi():<EOL><INDENT>all_imports.append( "<STR_LIT>" )<EOL><DEDENT>all_imports_string = "<STR_LIT:\n>".join(all_imports) + "<STR_LIT:\n>"<EOL>input_txt = "<STR_LIT>"<EOL>input_txt += get_file_header()<EOL>input_txt += "<STR_LIT>".format(self.pk)<EOL>input_txt += "<STR_LIT:\n>"<EOL>input_txt += all_imports_string<EOL>input_txt += "<STR_LIT:\n>"<EOL>pre_lines = parameters_dict.pop("<STR_LIT>",None)<EOL>if pre_lines is not None:<EOL><INDENT>if not isinstance(pre_lines,(list,tuple)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not all( [isinstance(_,basestring) for _ in pre_lines] ):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>input_txt += "<STR_LIT:\n>".join(pre_lines) + "<STR_LIT>"<EOL><DEDENT>input_txt += "<STR_LIT>".format(self._input_aseatoms)<EOL>input_txt += "<STR_LIT:\n>"<EOL>input_txt += "<STR_LIT>".format(calc_argsstr)<EOL>input_txt += "<STR_LIT>"<EOL>input_txt += "<STR_LIT:\n>"<EOL>if optimizer is not None:<EOL><INDENT>input_txt += "<STR_LIT>".format(optimizer_argsstr)<EOL>input_txt += "<STR_LIT>".format(optimizer_runargsstr)<EOL>input_txt += "<STR_LIT:\n>"<EOL><DEDENT>input_txt += "<STR_LIT>"<EOL>for getter,getter_args in atoms_getters:<EOL><INDENT>input_txt += "<STR_LIT>".format(getter,<EOL>getter,<EOL>getter_args)<EOL><DEDENT>input_txt += "<STR_LIT:\n>"<EOL>for getter,getter_args in calculator_getters:<EOL><INDENT>input_txt += "<STR_LIT>".format(getter,<EOL>getter,<EOL>getter_args) <EOL><DEDENT>input_txt += "<STR_LIT:\n>"<EOL>input_txt += "<STR_LIT>"<EOL>input_txt += "<STR_LIT>"<EOL>input_txt += "<STR_LIT>"<EOL>input_txt += "<STR_LIT:\n>"<EOL>post_lines = parameters_dict.pop("<STR_LIT>",None)<EOL>if post_lines is not None:<EOL><INDENT>if not isinstance(post_lines,(list,tuple)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not all( [isinstance(_,basestring) for _ in post_lines] ):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>input_txt += "<STR_LIT:\n>".join(post_lines) + "<STR_LIT>"<EOL><DEDENT>right_open = "<STR_LIT>" if self.get_withmpi() else "<STR_LIT>"<EOL>input_txt += "<STR_LIT>".format(right_open, self._OUTPUT_FILE_NAME)<EOL>input_txt += "<STR_LIT>"<EOL>input_txt += "<STR_LIT:\n>"<EOL>if optimizer is not None:<EOL><INDENT>input_txt += "<STR_LIT>".format(self._output_aseatoms)<EOL>input_txt += "<STR_LIT:\n>"<EOL><DEDENT>input_filename = tempfolder.get_abs_path(self._INPUT_FILE_NAME)<EOL>with open(input_filename,'<STR_LIT:w>') as infile:<EOL><INDENT>infile.write(input_txt)<EOL><DEDENT>local_copy_list = []<EOL>remote_copy_list = [] <EOL>additional_retrieve_list = settings_dict.pop("<STR_LIT>",[])<EOL>calcinfo = CalcInfo()<EOL>calcinfo.uuid = self.uuid<EOL>calcinfo.local_copy_list = local_copy_list<EOL>calcinfo.remote_copy_list = remote_copy_list<EOL>codeinfo = CodeInfo()<EOL>codeinfo.cmdline_params = [self._INPUT_FILE_NAME]<EOL>codeinfo.stdout_name = self._TXT_OUTPUT_FILE_NAME<EOL>codeinfo.code_uuid = code.uuid<EOL>calcinfo.codes_info = [codeinfo]<EOL>calcinfo.retrieve_list = []<EOL>calcinfo.retrieve_list.append(self._OUTPUT_FILE_NAME)<EOL>calcinfo.retrieve_list.append(self._output_aseatoms)<EOL>calcinfo.retrieve_list += additional_retrieve_list<EOL>return calcinfo<EOL>
This is the routine to be called when you want to create
the input files and related stuff with a plugin.

:param tempfolder: a aiida.common.folders.Folder subclass where
                   the plugin should put all its files.
:param inputdict: a dictionary with the input nodes, as they would
        be returned by get_inputdata_dict (without the Code!)