def test_missing_potfile(self): """ Parse kkr output where out_potential is missing. Compares error messages """ out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, self.outfile, self.outfile_0init, self.outfile_000, self.timing_file, 'wrong_name', self.nonco_out_file) out_dict['parser_warnings'] = msg_list assert not success assert msg_list == ['Error parsing output of KKR: core_states']
def test_parse_3Dsymmetries(self, data_regression): """ Parse output of a dos calculation in 3D (used to fail due to symmetries reading) """ p = './files/kkr/parser_3Dsymmetries/' success, msg_list, out_dict = parse_kkr_outputfile( {}, p + 'out_kkr', p + 'output.0.txt', p + 'output.000.txt', p + 'out_timing.000.txt', p + 'out_potential', p + 'nonco_angle_out.dat') assert success assert msg_list == [] data_regression.check(out_dict)
def test_complete_kkr_output(self, data_regression): """ Parse complete output of kkr calculation """ out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, self.outfile, self.outfile_0init, self.outfile_000, self.timing_file, self.potfile_out, self.nonco_out_file) out_dict['parser_warnings'] = msg_list assert success assert msg_list == [] groups = [i for i in list(out_dict.keys()) if 'group' in i] assert set(groups) == set(self.grouping_ref) data_regression.check(out_dict)
def test_missing_outfile000(self): """ Parse kkr output where output.000.txt is missing. Compares error messages """ out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, self.outfile, self.outfile_0init, 'wrong_name', self.timing_file, self.potfile_out, self.nonco_out_file) out_dict['parser_warnings'] = msg_list assert not success assert set(msg_list) == set([ 'Error parsing output of KKR: rms-error', 'Error parsing output of KKR: single particle energies', 'Error parsing output of KKR: charges', 'Error parsing output of KKR: scfinfo', 'Error parsing output of KKR: kmesh' ])
def test_parse_dosout(self, data_regression): """ Parse output of dos calculation since ouput changes slightly (e.g. no ewald sum) """ path0 = './files/kkr/kkr_run_dos_output/' outfile = path0 + 'out_kkr' outfile_0init = path0 + 'output.0.txt' outfile_000 = path0 + 'output.000.txt' timing_file = path0 + 'out_timing.000.txt' potfile_out = path0 + 'out_potential' out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, outfile, outfile_0init, outfile_000, timing_file, potfile_out, 'wrong_name') out_dict['parser_warnings'] = msg_list assert success assert msg_list == [] data_regression.check(out_dict)
def test_mag_orbmom_kkr_output(self, data_regression): """ Parse complete output of kkr calculation with orbital moments """ path0 = './files/kkr/kkr_run_slab_soc_mag/' outfile = path0 + 'out_kkr' outfile_0init = path0 + 'output.0.txt' outfile_000 = path0 + 'output.000.txt' timing_file = path0 + 'out_timing.000.txt' potfile_out = path0 + 'out_potential' nonco_out_file = path0 + 'nonco_angle_out.dat' out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, outfile, outfile_0init, outfile_000, timing_file, potfile_out, nonco_out_file) out_dict['parser_warnings'] = msg_list assert success assert msg_list == [] data_regression.check(out_dict)
def test_missing_nonco_angles(self): """ Parse kkr output where out_potential is missing. Compares error messages """ path0 = './files/kkr/kkr_run_slab_soc_mag/' outfile = path0 + 'out_kkr' outfile_0init = path0 + 'output.0.txt' outfile_000 = path0 + 'output.000.txt' timing_file = path0 + 'out_timing.000.txt' potfile_out = path0 + 'out_potential' out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, outfile, outfile_0init, outfile_000, timing_file, potfile_out, 'wrong_name') out_dict['parser_warnings'] = msg_list assert not success assert msg_list == [ 'Error parsing output of KKR: spin moment per atom' ]
def test_missing_outfile0init(self): """ Parse kkr output where output.0.txt is missing. Compares error messages """ out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, self.outfile, 'wrong_name', self.outfile_000, self.timing_file, self.potfile_out, self.nonco_out_file) out_dict['parser_warnings'] = msg_list assert not success assert set(msg_list) == set([ 'Error parsing output of KKR: nspin/natom', 'Error parsing output of KKR: spin moment per atom', 'Error parsing output of KKR: orbital moment', 'Error parsing output of KKR: energy contour', 'Error parsing output of KKR: alat, 2*pi/alat', 'Error parsing output of KKR: scfinfo', 'Error parsing output of KKR: kmesh', 'Error parsing output of KKR: symmetries', 'Error parsing output of KKR: ewald summation for madelung poterntial', 'Error parsing output of KKR: lattice vectors (direct/reciprocal)', 'Error parsing output of KKR: noco angles rms value', 'Error parsing output of KKR: BdG', ])
def test_missing_outfile(self): """ Parse kkr output where out_kkr is missing. Compares error messages """ out_dict = {} success, msg_list, out_dict = parse_kkr_outputfile( out_dict, 'wrong_name', self.outfile_0init, self.outfile_000, self.timing_file, self.potfile_out, self.nonco_out_file) out_dict['parser_warnings'] = msg_list assert not success assert set(msg_list) == set([ 'Error parsing output of KKR: Version Info', 'Error parsing output of KKR: rms-error', 'Error parsing output of KKR: charge neutrality', 'Error parsing output of KKR: total magnetic moment', 'Error parsing output of KKR: spin moment per atom', 'Error parsing output of KKR: orbital moment', 'Error parsing output of KKR: EF', 'Error parsing output of KKR: DOS@EF', 'Error parsing output of KKR: total energy', 'Error parsing output of KKR: search for warnings', 'Error parsing output of KKR: charges', 'Error parsing output of KKR: scfinfo' ])
def parse(self, **kwargs): """ Parse output data folder, store results in database. :param retrieved: a dictionary of retrieved nodes, where the key is the link name :returns: a tuple with two values ``(bool, node_list)``, where: * ``bool``: variable to tell if the parsing succeeded * ``node_list``: list of new nodes to be stored in the db (as a list of tuples ``(link_name, node)``) """ success = False node_list = () # Get retrieved folders try: out_folder = self.retrieved except exceptions.NotExistent: return self.exit_codes.ERROR_NO_RETRIEVED_FOLDER # check what is inside the folder list_of_files = out_folder._repository.list_object_names() # we need at least the output file name as defined in calcs.py if KkrCalculation._DEFAULT_OUTPUT_FILE not in list_of_files: msg = "Output file '{}' not found in list of files: {}".format( KkrCalculation._DEFAULT_OUTPUT_FILE, list_of_files) if self.icrit == 0: # this check turns this off for the KKRimporter calculation self.logger.error(msg) return self.exit_codes.ERROR_NO_OUTPUT_FILE # determine whether or not everything should be parsed or not (e.g. qdos option) skip_mode = False only_000_present = False with out_folder.open(KkrCalculation._INPUT_FILE_NAME) as file: txt = file.readlines() itmp = search_string('RUNOPT', txt) if itmp >= 0: runopts = txt[itmp + 1] if 'qdos' in runopts: skip_mode = True if 'KKRFLEX' in runopts: only_000_present = True # now collect the rest of the files file_errors = [] # Parse output files of KKR calculation if KkrCalculation._DEFAULT_OUTPUT_FILE in out_folder.list_object_names( ): outfile = out_folder.open(KkrCalculation._DEFAULT_OUTPUT_FILE) else: file_errors.append((1 + self.icrit, msg)) outfile = None # get path to files and catch errors if files are not present # append tupels (error_category, error_message) where error_category is # 1: critical error, always leads to failing of calculation # 2: warning, is inspected and checked for consistency with read-in # out_dict values (e.g. nspin, newsosol, ...) fname = KkrCalculation._OUTPUT_0_INIT if fname in out_folder.list_object_names(): outfile_0init = out_folder.open(fname) else: file_errors.append( (1 + self.icrit, "Critical error! OUTPUT_0_INIT not found {}".format(fname))) outfile_0init = None fname = KkrCalculation._OUTPUT_000 if fname in out_folder.list_object_names(): outfile_000 = out_folder.open(fname) else: file_errors.append( (1 + self.icrit, "Critical error! OUTPUT_000 not found {}".format(fname))) outfile_000 = None fname = KkrCalculation._OUTPUT_2 if fname in out_folder.list_object_names(): outfile_2 = out_folder.open(fname) else: if not only_000_present: file_errors.append( (1 + self.icrit, "Critical error! OUTPUT_2 not found {}".format(fname))) outfile_2 = None else: outfile_2 = outfile_000 fname = KkrCalculation._OUT_POTENTIAL if fname in out_folder.list_object_names(): potfile_out = out_folder.open(fname) else: file_errors.append( (1 + self.icrit, "Critical error! OUT_POTENTIAL not found {}".format(fname))) potfile_out = None fname = KkrCalculation._OUT_TIMING_000 if fname in out_folder.list_object_names(): timing_file = out_folder.open(fname) else: file_errors.append( (1 + self.icrit, "Critical error! OUT_TIMING_000 not found {}".format(fname))) timing_file = None fname = KkrCalculation._NONCO_ANGLES_OUT if fname in out_folder.list_object_names(): nonco_out_file = out_folder.open(fname) else: file_errors.append( (2, "Error! NONCO_ANGLES_OUT not found {}".format(fname))) nonco_out_file = None out_dict = { 'parser_version': self._ParserVersion, 'calculation_plugin_version': KkrCalculation._CALCULATION_PLUGIN_VERSION } #TODO job title, compound description success, msg_list, out_dict = parse_kkr_outputfile( out_dict, outfile, outfile_0init, outfile_000, timing_file, potfile_out, nonco_out_file, outfile_2, skip_readin=skip_mode) # try to parse with other combinations of files to minimize parser errors if self.icrit != 0: self.logger.info('msg_list0: {}'.format(msg_list)) # try second combination of files out_dict2 = out_dict.copy() success2, msg_list2, out_dict2 = parse_kkr_outputfile( out_dict2, outfile_2, outfile_0init, outfile_000, timing_file, potfile_out, nonco_out_file, outfile_2, skip_readin=skip_mode) self.logger.info('msg_list1: {}'.format(msg_list2)) if len(msg_list2) < len( msg_list): # overwrite parser outputs if fewer errors self.logger.info('take output of parser run 1') success, msg_list, out_dict = success2, msg_list2, out_dict2 # try third combination of files out_dict2 = out_dict.copy() success2, msg_list2, out_dict2 = parse_kkr_outputfile( out_dict2, outfile_000, outfile_0init, outfile_000, timing_file, potfile_out, nonco_out_file, outfile_2, skip_readin=skip_mode) self.logger.info('msg_list2: {}'.format(msg_list2)) if len(msg_list2) < len( msg_list): # overwrite parser outputs if fewer errors self.logger.info('take output of parser run 2') success, msg_list, out_dict = success2, msg_list2, out_dict2 out_dict['parser_errors'] = msg_list # add file open errors to parser output of error messages for (err_cat, f_err) in file_errors: if err_cat == 1: msg_list.append(f_err) elif check_error_category(err_cat, f_err, out_dict): msg_list.append(f_err) else: if 'parser_warnings' not in list(out_dict.keys()): out_dict['parser_warnings'] = [] out_dict['parser_warnings'].append( f_err.replace('Error', 'Warning')) out_dict['parser_errors'] = msg_list #create output node and link self.out('output_parameters', Dict(dict=out_dict)) if self.icrit != 0 and not success: # overwrite behavior with KKRimporter success = True # set automatically to True even if only partial output was parsed msg = "Automatically returned success=True for KKR importer although some parsing errors occurred" self.logger.warning(msg) if not success: return self.exit_codes.ERROR_KKR_PARSING_FAILED else: # cleanup after parsing (only if parsing was successful) # delete completely parsed output files self.remove_unnecessary_files()