From bbcd7655fa7729ff8a38b678d7937b9dea52f5e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20R=C3=BC=C3=9Fmann?= <10085427+PhilippRue@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:33:16 +0000 Subject: [PATCH] pylint fixes --- aiida_kkr/calculations/kkrimp.py | 1 + aiida_kkr/calculations/kkrnano.py | 4 ++-- aiida_kkr/calculations/voro.py | 8 ++++---- aiida_kkr/parsers/kkrnano.py | 2 +- aiida_kkr/tools/imp_cluster_tools.py | 2 +- aiida_kkr/tools/ldau.py | 12 ++++++------ aiida_kkr/tools/plot_kkr.py | 4 ++-- aiida_kkr/tools/tools_kkrimp.py | 4 +++- aiida_kkr/workflows/_combine_imps.py | 12 ++++++------ aiida_kkr/workflows/bs.py | 5 ++--- aiida_kkr/workflows/kkr_imp_dos.py | 3 ++- aiida_kkr/workflows/kkr_imp_sub.py | 4 ++-- aiida_kkr/workflows/kkr_scf.py | 14 +++++++------- aiida_kkr/workflows/voro_start.py | 4 ++-- 14 files changed, 41 insertions(+), 38 deletions(-) diff --git a/aiida_kkr/calculations/kkrimp.py b/aiida_kkr/calculations/kkrimp.py index 86819dc3..83e0a414 100644 --- a/aiida_kkr/calculations/kkrimp.py +++ b/aiida_kkr/calculations/kkrimp.py @@ -316,6 +316,7 @@ def _get_and_verify_hostfiles(self, tempfolder): parent_calc = parent_calcs.first().node # extract impurity_info found_impurity_inputnode = False + found_host_parent = False if 'impurity_info' in self.inputs: imp_info_inputnode = self.inputs.impurity_info if not isinstance(imp_info_inputnode, Dict): diff --git a/aiida_kkr/calculations/kkrnano.py b/aiida_kkr/calculations/kkrnano.py index 2764ad74..ec85baf1 100644 --- a/aiida_kkr/calculations/kkrnano.py +++ b/aiida_kkr/calculations/kkrnano.py @@ -278,7 +278,7 @@ def prepare_for_submission(self, tempfolder): if noco: with tempfolder.open(self._DEFAULT_NOCO_INPUT_FILE, u'w') as nonco_angles_handle: - self._write_nonco_angles(nonco_angles_handle, nonco_angles, structure) + self._write_nonco_angles(nonco_angles_handle, nonco_angles, structure) # pylint: disable=possibly-used-before-assignment # Prepare rbasis.xyz and input.conf from Structure and input parameter data unless convert mode if not convert: @@ -288,7 +288,7 @@ def prepare_for_submission(self, tempfolder): self._write_rbasis(rbasis_handle, structure, passed_lattice_const) if write_efermi: with tempfolder.open(self._DEFAULT_EFERMI_FILE, u'w') as efermi_file_handle: - self._write_efermi_file(efermi_file_handle, fermi) + self._write_efermi_file(efermi_file_handle, fermi) # pylint: disable=used-before-assignment # Prepare potential and shapefun file from strucwithpot, if necessary if use_strucwithpot: diff --git a/aiida_kkr/calculations/voro.py b/aiida_kkr/calculations/voro.py index 3437b370..ac6cad5c 100644 --- a/aiida_kkr/calculations/voro.py +++ b/aiida_kkr/calculations/voro.py @@ -107,7 +107,7 @@ def prepare_for_submission(self, tempfolder): vca_structure = False if found_structure: # for VCA: check if input structure and parameter node define VCA structure - vca_structure = vca_check(structure, parameters) + vca_structure = vca_check(structure, parameters) # pylint: disable=used-before-assignment code = self.inputs.code @@ -120,7 +120,7 @@ def prepare_for_submission(self, tempfolder): if found_parent: # check if parent is either Voronoi or previous KKR calculation - overwrite_potential, parent_calc = self._check_valid_parent(parent_calc_folder) + overwrite_potential, parent_calc = self._check_valid_parent(parent_calc_folder) # pylint: disable=possibly-used-before-assignment #cross check if no structure was given and extract structure from parent if found_structure and not vca_structure: @@ -188,7 +188,7 @@ def prepare_for_submission(self, tempfolder): outfolder = parent_calc.outputs.retrieved # copy from remote folder copylist = [parent_calc.process_class._OUT_POTENTIAL] elif has_potfile_overwrite: - outfolder = potfile_overwrite # copy from potential sfd + outfolder = potfile_overwrite # copy from potential sfd # pylint: disable=possibly-used-before-assignment copylist = [potfile_overwrite.filename] else: copylist = [] @@ -197,7 +197,7 @@ def prepare_for_submission(self, tempfolder): filename = file1 if (found_parent or has_potfile_overwrite) and file1 == copylist[0]: filename = self._POTENTIAL_IN_OVERWRITE - local_copy_list.append((outfolder.uuid, file1, filename)) + local_copy_list.append((outfolder.uuid, file1, filename)) # pylint: disable=possibly-used-before-assignment # add shapefun to overwrite if 'shapefun_overwrite' in self.inputs: diff --git a/aiida_kkr/parsers/kkrnano.py b/aiida_kkr/parsers/kkrnano.py index e0c37e7f..7f40bf09 100644 --- a/aiida_kkr/parsers/kkrnano.py +++ b/aiida_kkr/parsers/kkrnano.py @@ -81,7 +81,7 @@ def _findSimpleEntries(self, string2find, retrieved_folder, output_file_name, li array = np.genfromtxt(StringIO(keyvalue.replace('D', 'e')), delimiter=' ', dtype=None) #[0] try: - returnlist.append(array.item()[0]) + returnlist.append(array.item()[0]) # pylint: disable=possibly-used-before-assignment except TypeError: returnlist.append(array.item()) diff --git a/aiida_kkr/tools/imp_cluster_tools.py b/aiida_kkr/tools/imp_cluster_tools.py index de01f1e7..775a56e9 100644 --- a/aiida_kkr/tools/imp_cluster_tools.py +++ b/aiida_kkr/tools/imp_cluster_tools.py @@ -183,7 +183,7 @@ def create_combined_imp_info( # set zimp in scoef file (not used by the code but makes it easier to read the files / debug) if single_single: - clust1[0][4] = zimp1 + clust1[0][4] = zimp1 # pylint: disable=possibly-used-before-assignment clust2[0][4] = zimp2 #if debug: # print('cls1:', clust1) diff --git a/aiida_kkr/tools/ldau.py b/aiida_kkr/tools/ldau.py index 6fd9cd94..e6bf9954 100644 --- a/aiida_kkr/tools/ldau.py +++ b/aiida_kkr/tools/ldau.py @@ -119,9 +119,9 @@ def get_ldaumatrices(retrieved): iphi = ii ii += 1 # save matrices to output dict - txt_dict_ldaumats['wldau'] = txt[iwldau + 1:iuldau] - txt_dict_ldaumats['uldau'] = txt[iuldau + 1:iphi] - txt_dict_ldaumats['phi'] = txt[iphi + 1:] + txt_dict_ldaumats['wldau'] = txt[iwldau + 1:iuldau] # pylint: disable=possibly-used-before-assignment + txt_dict_ldaumats['uldau'] = txt[iuldau + 1:iphi] # pylint: disable=possibly-used-before-assignment + txt_dict_ldaumats['phi'] = txt[iphi + 1:] # pylint: disable=possibly-used-before-assignment return has_ldaupot_file, txt_dict_ldaumats @@ -164,8 +164,8 @@ def get_LDAU_initmatrices_dict(txts_ldaumat1, offset=0): # Fill the dictionary with atom-wise information for iatom in range(len(iatoms)): LDAU_initmatrices_dict[f'iatom={int(iatoms[iatom])-1+offset}'] = {} - LDAU_initmatrices_dict[f'iatom={int(iatoms[iatom])-1+offset}']['wldau'] = wldaumat[iatom] - LDAU_initmatrices_dict[f'iatom={int(iatoms[iatom])-1+offset}']['uldau'] = uldaumat[iatom] - LDAU_initmatrices_dict[f'iatom={int(iatoms[iatom])-1+offset}']['phi'] = phimat[iatom] + LDAU_initmatrices_dict[f'iatom={int(iatoms[iatom])-1+offset}']['wldau'] = wldaumat[iatom] # pylint: disable=possibly-used-before-assignment + LDAU_initmatrices_dict[f'iatom={int(iatoms[iatom])-1+offset}']['uldau'] = uldaumat[iatom] # pylint: disable=used-before-assignment + LDAU_initmatrices_dict[f'iatom={int(iatoms[iatom])-1+offset}']['phi'] = phimat[iatom] # pylint: disable=used-before-assignment return LDAU_initmatrices_dict diff --git a/aiida_kkr/tools/plot_kkr.py b/aiida_kkr/tools/plot_kkr.py index 63a1d6ea..0759edce 100644 --- a/aiida_kkr/tools/plot_kkr.py +++ b/aiida_kkr/tools/plot_kkr.py @@ -1307,7 +1307,7 @@ def plot_kkrimp_dos_wc(self, node, **kwargs): from aiida_kkr.tools import find_parent_structure natoms = get_natyp(find_parent_structure(calcnode)) self.dosplot( - d, + d, # pylint: disable=possibly-used-before-assignment natoms, nofig, all_atoms, @@ -1536,7 +1536,7 @@ def plot_kkr_startpot(self, node, **kwargs): tit_add = '' if emin is not None: axvline(emin, color='r', ls='--', label='emin') - if ef_Ry is not None and len(ecore_max) > 0: + if ef_Ry is not None and len(ecore_max) > 0: # pylint: disable=possibly-used-before-assignment if abs((ecore_max[0] - ef_Ry) * get_Ry2eV() - emin) < 20: axvline((ecore_max[0] - ef_Ry) * get_Ry2eV(), color='b', ls='--', label='ecore_max') else: diff --git a/aiida_kkr/tools/tools_kkrimp.py b/aiida_kkr/tools/tools_kkrimp.py index 2ba5e914..f5d21efc 100644 --- a/aiida_kkr/tools/tools_kkrimp.py +++ b/aiida_kkr/tools/tools_kkrimp.py @@ -418,10 +418,12 @@ def find_neighbors(structure, structure_array, i, radius, clust_shape='spherical box_1 = int(maxval / structure.cell_lengths[0] + 3) box_2 = int(maxval / structure.cell_lengths[1] + 3) box_3 = int(maxval / sl3 + 3) + else: + raise ValueError("clust_shape needs to be either 'sperical' or 'cylindrical'") #================================================================================================================ #create array of all the atoms in an expanded system - box = max(box_1, box_2, box_3) + box = max(box_1, box_2, box_3) #pylint: disable=possibly-used-before-assignment cell = np.array(structure.cell) cell[2] = c3 for j in range(len(x)): diff --git a/aiida_kkr/workflows/_combine_imps.py b/aiida_kkr/workflows/_combine_imps.py index ee47ff2d..899b3ec6 100644 --- a/aiida_kkr/workflows/_combine_imps.py +++ b/aiida_kkr/workflows/_combine_imps.py @@ -365,7 +365,7 @@ def extract_imps_info_exact_cluster(self): imp2_impurity_info = self.ctx.imp2.inputs.impurity_info try: - imps_info_in_exact_cluster = out_workflow_info.get_dict()['imps_info_in_exact_cluster'] + imps_info_in_exact_cluster = out_workflow_info.get_dict()['imps_info_in_exact_cluster'] # pylint: disable=possibly-used-before-assignment except KeyError: parent_input_imp1 = parent_combine_wc.inputs.impurity1_output_node # TODO: rename combine_wc to the parent_combine_wc parent_input_imp2 = parent_combine_wc.inputs.impurity2_output_node @@ -654,7 +654,7 @@ def run_gf_writeout(self): print('DEBUG:', self.ctx.imp1, list(self.ctx.imp1.inputs)) imp1_sub = self.ctx.imp1.get_outgoing(node_class=kkr_imp_sub_wc).first().node if gf_writeout_calc is None: - gf_writeout_calc = imp1_sub.inputs.remote_data.get_incoming(node_class=KkrCalculation).first().node + gf_writeout_calc = imp1_sub.inputs.remote_data.get_incoming(node_class=KkrCalculation).first().node # pylint: disable=possibly-used-before-assignment builder.remote_data = gf_writeout_calc.inputs.parent_folder # set label and description of the calc @@ -888,10 +888,10 @@ def get_ldau_combined(self): if imp1_has_ldau and imp2_has_ldau: # combine LDA+U settings of the two imps settings_LDAU_combined = combine_settings_ldau( - settings_LDAU1=settings_LDAU1, - retrieved1=retrieved1, - settings_LDAU2=settings_LDAU2, - retrieved2=retrieved2, + settings_LDAU1=settings_LDAU1, # pylint: disable=used-before-assignment + retrieved1=retrieved1, # pylint: disable=used-before-assignment + settings_LDAU2=settings_LDAU2, # pylint: disable=used-before-assignment + retrieved2=retrieved2, # pylint: disable=used-before-assignment kickout_info=self.ctx.kickout_info ) elif imp1_has_ldau: diff --git a/aiida_kkr/workflows/bs.py b/aiida_kkr/workflows/bs.py index 0a95c0a7..43f672d0 100644 --- a/aiida_kkr/workflows/bs.py +++ b/aiida_kkr/workflows/bs.py @@ -617,9 +617,8 @@ def parse_BS_data(retrieved_folder, fermi_level, kpoints): qdos_file_list = [i for i in retrieved_list if 'qdos.' in i] q_vec_file = 'qvec.dat' - if q_vec_file in retrieved_list: - with retrieved_folder.open(q_vec_file) as file_opened: - q_vec = np.loadtxt(file_opened, skiprows=1) + with retrieved_folder.open(q_vec_file) as file_opened: + q_vec = np.loadtxt(file_opened, skiprows=1) for icount, fname in enumerate(qdos_file_list): with retrieved_folder.open(fname) as _f: diff --git a/aiida_kkr/workflows/kkr_imp_dos.py b/aiida_kkr/workflows/kkr_imp_dos.py index a8f33425..2ddf23cc 100644 --- a/aiida_kkr/workflows/kkr_imp_dos.py +++ b/aiida_kkr/workflows/kkr_imp_dos.py @@ -495,7 +495,8 @@ def run_imp_dos(self): }) kkrimp_params = self.ctx.kkrimp_params_dict label_imp = 'KKRimp DOS (GF: {}, imp_pot: {}, Zimp: {}, ilayer_cent: {})'.format( - gf_writeout_calc.pk, impurity_pot_or_remote.pk, + gf_writeout_calc.pk, + impurity_pot_or_remote.pk, # pylint: disable=possibly-used-before-assignment imps.get_dict().get('Zimp'), imps.get_dict().get('ilayer_center') ) diff --git a/aiida_kkr/workflows/kkr_imp_sub.py b/aiida_kkr/workflows/kkr_imp_sub.py index 7441e68a..a13bdea1 100644 --- a/aiida_kkr/workflows/kkr_imp_sub.py +++ b/aiida_kkr/workflows/kkr_imp_sub.py @@ -851,7 +851,7 @@ def run_kkrimp(self): # add LDA+U input node if it was set in parent calculation of last kkrimp_remote or from input port if self.ctx.settings_LDAU is not None: - inputs['settings_LDAU'] = self.ctx.settings_LDAU + inputs['settings_LDAU'] = self.ctx.settings_LDAU # pylint: disable=possibly-used-before-assignment # set nonco angles if given if 'initial_noco_angles' in self.inputs: @@ -990,7 +990,7 @@ def inspect_kkrimp(self): for name, val in { 'isteps': isteps, 'imix': self.ctx.last_mixing_scheme, - 'mixfac': mixfac, + 'mixfac': mixfac, # pylint: disable=possibly-used-before-assignment 'qbound': qbound, 'high_sett': self.ctx.kkr_higher_accuracy, 'first_rms': first_rms, diff --git a/aiida_kkr/workflows/kkr_scf.py b/aiida_kkr/workflows/kkr_scf.py index b0334b78..3c780487 100644 --- a/aiida_kkr/workflows/kkr_scf.py +++ b/aiida_kkr/workflows/kkr_scf.py @@ -1898,14 +1898,14 @@ def create_scf_result_node(**kwargs): outdict = {} if has_last_outpara: - outputnode = outpara + outputnode = outpara # pylint: disable=possibly-used-before-assignment outputnode.label = 'workflow_Results' outputnode.description = ('Contains self-consistency results and ' 'information of an kkr_scf_wc run.') outdict['output_kkr_scf_wc_ParameterResults'] = outputnode if has_last_calc_out_dict: - outputnode = last_calc_out_dict + outputnode = last_calc_out_dict # pylint: disable=used-before-assignment outputnode.label = 'last_calc_out' outputnode.description = ( 'Contains the Results Parameter node from the output ' @@ -1914,7 +1914,7 @@ def create_scf_result_node(**kwargs): outdict['last_calc_out'] = outputnode if has_last_RemoteData: - outputnode = last_RemoteData_dict + outputnode = last_RemoteData_dict # pylint: disable=used-before-assignment outputnode.label = 'last_RemoteData' outputnode.description = ( 'Contains a link to the latest remote data node ' @@ -1923,7 +1923,7 @@ def create_scf_result_node(**kwargs): outdict['last_RemoteData'] = outputnode if has_last_InputParameters: - outputnode = last_InputParameters_dict + outputnode = last_InputParameters_dict # pylint: disable=used-before-assignment outputnode.label = 'last_InputParameters' outputnode.description = ( 'Contains the latest parameter data node ' @@ -1932,7 +1932,7 @@ def create_scf_result_node(**kwargs): outdict['last_InputParameters'] = outputnode if has_vorostart_output: - outputnode = vorostart_output_dict + outputnode = vorostart_output_dict # pylint: disable=used-before-assignment outputnode.label = 'results_vorostart' outputnode.description = ( 'Contains the results parameter data node ' @@ -1941,14 +1941,14 @@ def create_scf_result_node(**kwargs): outdict['results_vorostart'] = outputnode if has_starting_dos: - outputnode = start_dosdata_interpol_dict + outputnode = start_dosdata_interpol_dict # pylint: disable=used-before-assignment outputnode.label = 'starting_dosdata_interpol' outputnode.description = ('Contains the interpolated DOS data note, computed ' 'from the starting portential.') outdict['starting_dosdata_interpol'] = outputnode if has_final_dos: - outputnode = final_dosdata_interpol_dict + outputnode = final_dosdata_interpol_dict # pylint: disable=used-before-assignment outputnode.label = 'final_dosdata_interpol' outputnode.description = ('Contains the interpolated DOS data note, computed ' 'from the converged potential.') diff --git a/aiida_kkr/workflows/voro_start.py b/aiida_kkr/workflows/voro_start.py index bde4b105..a16f9857 100644 --- a/aiida_kkr/workflows/voro_start.py +++ b/aiida_kkr/workflows/voro_start.py @@ -547,10 +547,10 @@ def run_voronoi(self): kkr_para.set_value('RCLUSTZ', self.ctx.r_cls) self.report(f'INFO: setting RCLUSTZ to {self.ctx.r_cls}') if 'RMAX' in update_list: - kkr_para.set_value('RMAX', rmax_input) + kkr_para.set_value('RMAX', rmax_input) # pylint: disable=possibly-used-before-assignment self.report(f'INFO: setting RMAX to {rmax_input} (needed for DOS check with KKRcode)') if 'GMAX' in update_list: - kkr_para.set_value('GMAX', gmax_input) + kkr_para.set_value('GMAX', gmax_input) # pylint: disable=possibly-used-before-assignment self.report(f'INFO: setting GMAX to {gmax_input} (needed for DOS check with KKRcode)') if 'EMIN' in update_list: kkr_para.set_value('EMIN', emin_new)