def _get_econt_info(self, out_log): """ extract energy contour information from out_log file :param out_log: file that is parsed :retuns: econt (dict), dictionary containing the energy contour info :note: econt contains the following keys * 'emin', bottom of energy contour * 'Nepts', number of points in energy contour * 'epts', list of complex valued energy points * 'weights', list of complex valued weights for energy integration """ from aiida_kkr.tools.common_functions import search_string from numpy import array f = open(out_log) tmptxt = f.readlines() f.close() econt = {} itmp = search_string('[read_energy] number of energy points', tmptxt) if itmp >= 0: econt['Nepts'] = int(tmptxt.pop(itmp).split()[-1]) itmp = search_string('energies and weights are:', tmptxt) if itmp >= 0: tmp = [] for ie in range(econt['Nepts']): tmpline = tmptxt[itmp + 4 + ie].split()[1:] tmp.append([ float(tmpline[0]), float(tmpline[1]), float(tmpline[2]), float(tmpline[3]) ]) tmp = array(tmp) econt['epts'] = tmp[:, :2] econt['weights'] = tmp[:, 2:] econt['emin'] = tmp[0, 0] return econt
def test_set_rmtcore(self): #test rmtcore from numpy import array from aiida_kkr.tools.common_functions import search_string para_dict = dict([ (u'INS', 0), (u'RCLUSTZ', 1.69), (u'LMAX', 2), (u'GMAX', 65.0), (u'<RMTCORE>', [0.3535533906, 0.3535533906, 0.3535533906, 0.3535533906]), (u'RMAX', 7.0), (u'NSPIN', 1) ]) zatom = array([47., 47., 47., 47.]) alat = 7.8692316414074615 natom = 4 positions = array([[0., 0., 0.], [0., 0.5, 0.5], [0.5, 0., 0.5], [0.5, 0.5, 0.]]) bravais = array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) k = kkrparams(**para_dict) k.set_multiple_values(ZATOM=zatom, NAEZ=natom, ALATBASIS=alat, RBASIS=positions, BRAVAIS=bravais) k.fill_keywords_to_inputfile() txt = open('inputcard').readlines() naez = int(txt[search_string('NAEZ', txt)].split()[-1]) rmtcore = [] l_offset = search_string('RMTCORE', txt) for iatom in range(naez): rmtcore_at = float(txt[l_offset + 1 + iatom].split()[-1]) rmtcore.append(rmtcore_at) maxdiff = (max(abs(array(para_dict['<RMTCORE>']) - array(rmtcore)))) assert maxdiff < 10**-6
def get_symmetries(outfile_0init): f = open(outfile_0init) tmptxt = f.readlines() f.close() try: itmp = search_string('symmetries found for this lattice:', tmptxt) nsym = int(tmptxt[itmp].split(':')[1].split()[0]) except IndexError: itmp = search_string('< FINDGROUP > : Finding symmetry operations', tmptxt) tmptxt2 = tmptxt[itmp:] itmp = search_string('found for this lattice:', tmptxt2) nsym = int(tmptxt2[itmp].split(':')[1].split()[0]) itmp = search_string('symmetries will be used', tmptxt) nsym_used = int(tmptxt[itmp].split()[3]) itmp = search_string('<SYMTAUMAT>', tmptxt) tmpdict = {} for isym in range(nsym_used): tmpval = tmptxt[itmp+5+isym].replace('0-', '0 -').replace('1-', '1 -').split() # bugfix for -120 degree euler angle desc = tmpval[1] inversion = int(tmpval[2]) euler = [float(tmpval[3]), float(tmpval[4]), float(tmpval[5])] unitary = int(tmpval[6].replace('T', '1').replace('F', '0')) tmpdict[desc] = {'has_inversion':inversion, 'is_unitary':unitary, 'euler_angles':euler} desc = tmpdict return nsym, nsym_used, desc
def test_search_string(self): txt = open('files/kkr/kkr_run_dos_output/output.0.txt', 'r').readlines() alatline = search_string('ALAT', txt) noline = search_string('ALT', txt) assert alatline == 23 assert noline == -1
def get_alat(inpfile): f = open(inpfile) txt = f.readlines() f.close() itmp = search_string('ALATBASIS', txt) result = float(txt[itmp].split('ALATBASIS')[1].split('=')[1].split()[0]) return result
def get_spinmom_per_atom(outfile, natom, nonco_out_file=None): """ Extract spin moment information from outfile and nonco_angles_out (if given) """ from numpy import array f = open(outfile) tmptxt = f.readlines() f.close() itmp = 0 result = [] while itmp >= 0: itmp = search_string('m_spin', tmptxt) if itmp>=0: tmpline = tmptxt.pop(itmp) tmparray = [] for iatom in range(natom): tmpline = tmptxt.pop(itmp) tmparray.append(float(tmpline.split()[3])) result.append(tmparray) # if the file is there, i.e. NEWSOSOL is used, then extract also direction of spins (angles theta and phi) if nonco_out_file is not None and result != []: from numpy import loadtxt from numpy import shape angles = loadtxt(nonco_out_file) if len(shape(angles))==1: angles = array([angles]) vec = angles_to_vec(result[-1], angles[:,0], angles[:,1]) else: vec, angles = [],[] return array(result), vec, angles
def extract_timings(outfile): from numpy import array f = open(outfile) tmptxt = f.readlines() f.close() itmp = 0 res = [] search_keys = ['main0', 'main1a - tbref', 'main1a ', # two spaces to differentiate from following key 'main1b - calctref13', 'main1b ', # two spaces! 'main1c - serial part', 'main1c ',# two spaces! 'main2', 'Time in Iteration'] while itmp>=0: tmpvals = [] for isearch in search_keys: itmp = search_string(isearch, tmptxt) if itmp>=0: tmpval = [isearch, float(tmptxt.pop(itmp).split()[-1])] tmpvals.append(tmpval) if len(tmpvals)>0: res.append(tmpvals) #print(res) res = array(res[0]) #print(dict(res)) return dict(res)
def _extract_timings(self, outfile): """ Extract timings for the different parts in the KKRimp code :param outfile: timing file of the KKRimp run :returns: res (dict) timings in seconds, averaged over iterations """ from aiida_kkr.tools.common_functions import search_string f = open(outfile) tmptxt = f.readlines() f.close() search_keys = [ 'time until scf starts', 'vpot->tmat', 'gref->gmat', 'gonsite->density', 'energyloop', 'Iteration number', 'Total running time' ] res = {} for isearch in search_keys: tmpval = [] itmp = 0 while itmp >= 0: itmp = search_string(isearch, tmptxt) if itmp >= 0: tmpval.append(float(tmptxt.pop(itmp).split()[-1])) if len(tmpval) > 0: res[isearch] = tmpval # average over iterations niter = len(res.get(search_keys[-2], [])) if niter > 0: for key in search_keys[1:6]: res[key] = sum(res[key]) / niter for key in [search_keys[0], search_keys[-1]]: res[key] = res[key][0] return res
def get_alatinfo(outfile_0init): f = open(outfile_0init) tmptxt = f.readlines() f.close() itmp = search_string('Lattice constants :', tmptxt) alat = float(tmptxt[itmp].split(':')[1].split('=')[1].split()[0]) twopialat = float(tmptxt[itmp].split(':')[1].split('=')[2].split()[0]) return alat, twopialat
def startpot_jellium(outfile): f = open(outfile) tmptxt = f.readlines() f.close() itmp = search_string('JELLSTART POTENTIALS', tmptxt) if itmp ==-1: return False else: return True
def get_shape_array(outfile, atominfo): f = open(outfile) txt = f.readlines() f.close() #naez/natyp number of items either one number (=ishape without cpa or two =[iatom, ishape] with CPA) # read in naez and/or natyp and then find ishape array (1..natyp[=naez without CPA]) itmp = search_string('NAEZ= ', txt) if itmp>=0: tmp = txt[itmp] ipos = tmp.find('NAEZ=') naez = int(tmp[ipos+5:].split()[0]) else: naez = -1 itmp = search_string('NATYP= ', txt) if itmp>=0: tmp = txt[itmp] ipos = tmp.find('NATYP=') natyp = int(tmp[ipos+6:].split()[0]) else: natyp = -1 # consistency check if naez==-1 and natyp>0: naez = natyp elif natyp==-1 and naez>0: natyp = naez elif natyp==-1 and naez==-1: raise ValueError('Neither NAEZ nor NATYP found in %s'%outfile) # read shape index from atominfo file f = open(atominfo) tmptxt = f.readlines() f.close() itmp = search_string('<SHAPE>', tmptxt) + 1 ishape = [] for iatom in range(natyp): txt = tmptxt[itmp+iatom] if natyp>naez: #CPA option ishape.append(int(txt.split()[1])) else: ishape.append(int(txt.split()[0])) return natyp, naez, ishape
def get_nspin(outfile_0init): """ extract NSPIN value from output.0.txt """ f = open(outfile_0init) tmptxt = f.readlines() f.close() itmp = search_string('NSPIN', tmptxt) nspin = int(tmptxt[itmp+1].split()[0]) return nspin
def get_volumes(outfile): f = open(outfile) tmptxt = f.readlines() f.close() itmp = search_string('Total volume (alat^3)', tmptxt) if itmp>=0: Vtot = float(tmptxt.pop(itmp).split()[-1]) itmp = 0 results = [] while itmp>=0: itmp = search_string(' Volume(alat^3) :', tmptxt) if itmp>=0: tmpstr = tmptxt.pop(itmp) tmpstr = tmpstr.split() tmpstr = [int(tmpstr[2]), float(tmpstr[5])] results.append(tmpstr) return Vtot, results
def get_natom(outfile_0init): """ extract NATYP value from output.0.txt """ f = open(outfile_0init) tmptxt = f.readlines() f.close() itmp = search_string('NATYP', tmptxt) natom = int(tmptxt[itmp+1].split()[0]) return natom
def get_scfinfo(outfile_0init, outfile_000, outfile): f = open(outfile_000) tmptxt = f.readlines() f.close() itmp = search_string('ITERATION :', tmptxt) tmpval = tmptxt[itmp].split(':')[1].split() niter = int(tmpval[0]) nitermax = int(tmpval[3]) f = open(outfile) tmptxt = f.readlines() f.close() itmp1 = search_string('SCF ITERATION CONVERGED', tmptxt) itmp2 = search_string('NUMBER OF SCF STEPS EXHAUSTED', tmptxt) if itmp1>=0: converged = True else: converged = False if itmp2>=0: nmax_reached = True else: nmax_reached = False f = open(outfile_0init) tmptxt = f.readlines() f.close() itmp = search_string('STRMIX FCM QBOUND', tmptxt) tmpval = tmptxt[itmp+1].split() strmix = float(tmpval[0]) fcm = float(tmpval[1]) qbound = float(tmpval[2]) tmpval = tmptxt[itmp+4].split() brymix = float(tmpval[0]) itmp = search_string('IMIX IGF ICC', tmptxt) imix = int(tmptxt[itmp+1].split()[0]) idtbry = int(tmptxt[itmp+4].split()[0]) mixinfo = [imix, strmix, qbound, fcm, idtbry, brymix] return niter, nitermax, converged, nmax_reached, mixinfo
def use_newsosol(outfile_0init): """ extract NEWSOSOL info from output.0.txt """ f = open(outfile_0init) tmptxt = f.readlines() f.close() itmp = search_string('NEWSOSOL', tmptxt) newsosol = False if itmp>=0: newsosol = True return newsosol
def get_fpradius(naez, atominfo): f = open(atominfo) txt = f.readlines() f.close() itmp = search_string('<FPRADIUS>', txt) + 1 results = [] for iatom in range(naez): #ZAT LMXC KFG <CLS> <REFPOT> <NTC> FAC <IRNS> <RMTREF> <FPRADIUS> # 0.00 1 3 3 0 0 1 1 1 1. 199 2.3166000 0.4696902 tmpline = float(txt[itmp+iatom].split()[-1]) results.append(tmpline) return results
def get_econt_info(outfile_0init): f = open(outfile_0init) tmptxt = f.readlines() f.close() itmp = search_string('E min', tmptxt) emin = float(tmptxt[itmp].split('min')[1].split('=')[1].split()[0]) itmp = search_string('Temperature', tmptxt) tempr = float(tmptxt[itmp].split('Temperature')[1].split('=')[1].split()[0]) itmp = search_string('Number of energy points', tmptxt) Nepts = int(tmptxt[itmp].split(':')[1].split()[0]) doscalc = search_string('Density-of-States calculation', tmptxt) if doscalc == -1: # npol itmp = search_string('poles =', tmptxt) Npol = int(tmptxt[itmp].split('=')[1].split()[0]) # npt1, npt2, npt3 itmp = search_string('contour:', tmptxt) tmp = tmptxt[itmp].replace(',','').split(':')[1].split() N1 = int(tmp[2]) N2 = int(tmp[5]) N3 = int(tmp[8]) else: Npol, N1, N2, N3 = 0, 0, Nepts, 0 return emin, tempr, Nepts, Npol, N1, N2, N3
def _get_nspin(self, file): """ Extract nspin from file :param file: file that is parsed :returns: 1 if calculation is paramagnetic, 2 otherwise """ from aiida_kkr.tools.common_functions import search_string f = open(file) tmptxt = f.readlines() f.close() itmp = search_string('NSPIN', tmptxt) nspin = int(tmptxt.pop(itmp).split()[-1]) return nspin
def get_radial_meshpoints(potfile): f = open(potfile) txt = f.readlines() f.close() itmp = 0 result = [] while itmp >= 0: itmp = search_string('exc:', txt) if itmp >= 0: txt.pop(itmp)# remove header line tmp = txt.pop(itmp+3) # extract meshpoints result.append(float(tmp)) return result
def get_ewald(outfile_0init): f = open(outfile_0init) tmptxt = f.readlines() f.close() itmp = search_string('setting bulk Madelung coefficients', tmptxt) if itmp>=0: info = '3D' else: info = '2D' if info == '3D': itmp = search_string('< LATTICE3D >', tmptxt) tmpval = tmptxt[itmp+7].split()[2:] rsum = float(tmpval[2]), int(tmpval[0]), int(tmpval[1]) tmpval = tmptxt[itmp+8].split()[2:] gsum = float(tmpval[2]), int(tmpval[0]), int(tmpval[1]) else: itmp = search_string('< LATTICE2D >', tmptxt) tmpval = tmptxt[itmp+13].split()[2:] rsum = float(tmpval[2]), int(tmpval[0]), int(tmpval[1]) tmpval = tmptxt[itmp+14].split()[2:] gsum = float(tmpval[2]), int(tmpval[0]), int(tmpval[1]) return rsum, gsum, info
def _get_natom(self, file): """ Extract number of atoms in impurity cluster :param file: file that is parsed to find number of atoms :returns: natom (int), number of atoms in impurity cluster """ from aiida_kkr.tools.common_functions import search_string f = open(file) tmptxt = f.readlines() f.close() itmp = search_string('NATOM is', tmptxt) natom = int(tmptxt.pop(itmp).split()[-1]) return natom
def find_warnings(outfile): from numpy import array f = open(outfile) tmptxt = f.readlines() tmptxt_caps = [txt.upper() for txt in tmptxt] f.close() itmp = 0 res = [] while itmp>=0: itmp = search_string('WARNING', tmptxt_caps) if itmp>=0: tmpval = tmptxt_caps.pop(itmp) tmpval = tmptxt.pop(itmp) res.append(tmpval.strip()) return array(res)
def get_kmeshinfo(outfile_0init, outfile_000): """ Extract kmesh info from output.0.txt and output.000.txt """ # first get info from output.0.txt f = open(outfile_0init) tmptxt = f.readlines() f.close() nkmesh = [] itmp = search_string('number of different k-meshes', tmptxt) nkmesh.append( int(tmptxt[itmp].split(':')[1].split()[0]) ) itmp = search_string('k-mesh NofKs', tmptxt) nofks, nkx, nky, nkz = [],[],[],[] for ik in range(nkmesh[0]): tmpval = tmptxt[itmp+2+ik].split() nofks.append(int(tmpval[1])) nkx.append(int(tmpval[2])) nky.append(int(tmpval[3])) nkz.append(int(tmpval[4])) tmpdict = {'number_of_kpts':nofks, 'n_kx':nkx, 'n_ky':nky, 'n_kz':nkz} nkmesh.append(tmpdict) #next get kmesh_ie from output.000.txt f = open(outfile_000) tmptxt = f.readlines() f.close() kmesh_ie = [] itmp = 0 while itmp>=0: itmp = search_string('KMESH =', tmptxt) if itmp>=0: tmpval = int(tmptxt.pop(itmp).split()[-1]) kmesh_ie.append(tmpval) return nkmesh, kmesh_ie
def get_single_particle_energies(outfile_000): """ extracts single particle energies from outfile_000 (output.000.txt) returns the valence contribution of the single particle energies """ from numpy import array f = open(outfile_000) tmptxt = f.readlines() f.close() itmp = 0 res = [] while itmp>=0: itmp = search_string('band energy per atom', tmptxt) if itmp>=0: tmpval = float(tmptxt.pop(itmp).split()[-1]) res.append(tmpval) return array(res)
def _get_Etot(self, file): """ Extract total energy file :param file: file that is parsed :returns: Etot (list), values of the total energy in Ry for all iterations """ from aiida_kkr.tools.common_functions import search_string f = open(file) tmptxt = f.readlines() f.close() itmp = 0 Etot = [] while itmp >= 0: itmp = search_string('TOTAL ENERGY', tmptxt) if itmp >= 0: Etot.append(float(tmptxt.pop(itmp).split()[-1])) return Etot
def _get_newsosol(self, file): """ Check if spin orbit coupling solver is used :param file: absolute path to out_log.000.txt of KKRimp calculation :returns: True(False) if SOC solver is (not) used """ from aiida_kkr.tools.common_functions import search_string f = open(file) tmptxt = f.readlines() f.close() itmp = search_string('Spin orbit coupling used?', tmptxt) itmp = int(tmptxt.pop(itmp).split()[-1]) if itmp == 1: newsosol = True else: newsosol = False return newsosol
def get_cls_info(outfile): f = open(outfile) tmptxt = f.readlines() f.close() itmp = 0 Ncls = 0 Natom = 0 cls_all = [] results = [] while itmp>=0: itmp = search_string('CLSGEN_TB: Atom', tmptxt) if itmp>=0: tmpstr = tmptxt.pop(itmp) tmpstr = tmpstr.split() tmp = [int(tmpstr[2]), int(tmpstr[4]), float(tmpstr[6]), int(tmpstr[8]), int(tmpstr[10])] results.append(tmp) if int(tmpstr[8]) not in cls_all: Ncls += 1 cls_all.append(int(tmpstr[8])) Natom += 1 return Ncls, Natom, results
def get_orbmom(outfile, natom): """ read orbmom info from outfile and return array (iteration, atom)=orbmom """ from numpy import array f = open(outfile) tmptxt = f.readlines() f.close() itmp = 0 result = [] while itmp >= 0: itmp = search_string('m_spin', tmptxt) if itmp>=0: tmpline = tmptxt.pop(itmp) tmparray = [] for iatom in range(natom): tmpline = tmptxt.pop(itmp) tmparray.append(float(tmpline.split()[4])) result.append(tmparray) return array(result)#, vec, angles
def test_set_potname_empty(self): p = kkrparams() p.set_multiple_values(RMAX=1, GMAX=1, NSPIN=1, RBASIS=[0, 0, 0], LMAX=2, RCLUSTZ=1.2, NAEZ=1, ZATOM=[0], BRAVAIS=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], ALATBASIS=1, FILES=['', 'shapenew']) p.fill_keywords_to_inputfile() from aiida_kkr.tools.common_functions import search_string txt = open('inputcard').readlines() itmp = search_string('FILES', txt) potname = txt[itmp + 2].split()[0] shapename = txt[itmp + 4].split()[0] assert 'potential' == potname assert 'shapenew' == shapename