def test_get_corestates_from_potential(self): corestates = get_corestates_from_potential( 'files/kkr/kkr_run_dos_output/out_potential') ref = ([8, 8, 8, 8], [ np.array([ -1866.96096949, -275.8348967, -50.32089052, -6.5316706, -248.12312965, -41.13200278, -3.832432, -26.5129925 ]), np.array([ -1866.96096949, -275.8348967, -50.32089052, -6.5316706, -248.12312965, -41.13200278, -3.832432, -26.5129925 ]), np.array([ -1866.96096949, -275.8348967, -50.32089052, -6.5316706, -248.12312965, -41.13200278, -3.832432, -26.5129925 ]), np.array([ -1866.96096949, -275.8348967, -50.32089052, -6.5316706, -248.12312965, -41.13200278, -3.832432, -26.5129925 ]) ], [ np.array([0, 0, 0, 0, 1, 1, 1, 2]), np.array([0, 0, 0, 0, 1, 1, 1, 2]), np.array([0, 0, 0, 0, 1, 1, 1, 2]), np.array([0, 0, 0, 0, 1, 1, 1, 2]) ]) assert corestates[0] == ref[0] assert np.sum(abs(np.array(corestates[1]) - np.array(ref[1]))) < 10**-7 assert np.sum(abs(np.array(corestates[2]) - np.array(ref[2]))) < 10**-7
def check_voronoi_output(potfile, outfile, delta_emin_safety=0.1): """Read output from voronoi code and create guess of energy contour""" from numpy import zeros #analyse core levels, minimum of valence band and their difference ncore, ecore, lcore = get_corestates_from_potential(potfile=potfile) e_val_min = get_valence_min(outfile=outfile) #print a table that summarizes the result e_core_max = zeros(len(ncore)) print('pot Highest core-level low. val. state diff') for ipot in range(len(ncore)): if ncore[ipot] > 0: lval, emax, descr = get_highest_core_state(ncore[ipot], ecore[ipot], lcore[ipot]) e_core_max[ipot] = emax print('%3i %2s %10.6f %6.2f %6.2f' % (ipot + 1, descr, emax, e_val_min[ipot], e_val_min[ipot] - emax)) else: print('%3i << no core states >>' % (ipot + 1)) # set to some large negative number for check to not give false positive in case of empty cells e_core_max[ipot] = -1000 #get hint for energy integration: emin_guess = e_val_min.min() - delta_emin_safety # in Ry return emin_guess, e_core_max.max()
def kick_out_corestates(potfile, potfile_out, emin): """ Read potential file and kick out all core states that lie higher than emin. If no core state lies higher than emin then the output potential will be the same as the input potential :param potfile: input potential :param potfile_out: output potential where some core states are kicked out :param emin: minimal energy above which all core states are kicked out from potential :returns: number of lines that have been deleted """ from masci_tools.io.common_functions import get_corestates_from_potential from numpy import where, array # read core states nstates, energies, lmoments = get_corestates_from_potential(potfile) with open_general(potfile) as f: # read potential file txt = f.readlines() #get start of each potential part istarts = [ iline for iline in range(len(txt)) if 'POTENTIAL' in txt[iline] ] all_lines = list(range(len(txt))) # index array # change list of core states for ipot in range(len(nstates)): if nstates[ipot] > 0: m = where(energies[ipot] > emin) if len(m[0]) > 0: istart = istarts[ipot] # change number of core states in potential #print(txt[istart+6]) txt[istart + 6] = '%i 1\n' % (nstates[ipot] - len(m[0])) # now remove energy line accordingly for ie_out in m[0][::-1]: m_out = where( array(all_lines) == istart + 6 + ie_out + 1)[0][0] e_out = all_lines.pop(m_out) # find number of deleted lines num_deleted = len(txt) - len(all_lines) if num_deleted > 0: # write output potential with open_general(potfile_out, u'w') as f2: txt_new = [] for iline in all_lines: txt_new.append(str(txt[iline])) f2.writelines(txt_new) # return number of lines that were deleted return num_deleted
def get_core_states(potfile): ncore, energies, lmoments = get_corestates_from_potential(potfile=potfile) emax, lmax, descr_max = [], [], [] for ipot in range(len(ncore)): if ncore[ipot] > 0: lvalmax, energy_max, descr = get_highest_core_state( ncore[ipot], energies[ipot], lmoments[ipot]) else: lvalmax, energy_max, descr = None, None, 'no core states' emax.append(energy_max) lmax.append(lvalmax) descr_max.append(descr) return array(ncore), array(emax), array(lmax), array(descr_max)