def _read_functions(fileobj, valence_orbitals): """ Read radial wave functions (R=u/r), self-consistent potentials, confinements, etc. from given file. """ default = np.array([[0,0],[1,0],[2,0],[3,0]]) functions = { 'unl': {}, 'Rnl': {} } for nl in valence_orbitals: m = mix.find_value(fileobj, 'u_%s' % nl, fmt='matrix', default=default) functions['unl'][nl]=Function('spline', m[:,0], m[:,1]) functions['Rnl'][nl]=Function('spline', m[:,0], m[:,1]/m[:,0]) m = mix.find_value(fileobj, 'effective_potential', fmt='matrix', default=default) functions['effective_potential'] = Function('spline', m[:,0], m[:,1]) m = mix.find_value(fileobj, 'confinement_potential', fmt='matrix', default=default) functions['confinement_potential'] = Function('spline', m[:,0], m[:,1]) return functions
def _read_functions(fileobj, valence_orbitals): """ Read radial wave functions (R=u/r), self-consistent potentials, confinements, etc. from given file. """ default = np.array([[1, 0], [2, 0], [3, 0], [4, 0]]) functions = {'unl': {}, 'Rnl': {}} for nl in valence_orbitals: m = mix.find_value(fileobj, 'u_%s' % nl, fmt='matrix', default=default) functions['unl'][nl] = Function('spline', m[:, 0], m[:, 1]) functions['Rnl'][nl] = Function('spline', m[:, 0], m[:, 1] / m[:, 0]) m = mix.find_value(fileobj, 'effective_potential', fmt='matrix', default=default) functions['effective_potential'] = Function('spline', m[:, 0], m[:, 1]) m = mix.find_value(fileobj, 'confinement_potential', fmt='matrix', default=default) functions['confinement_potential'] = Function('spline', m[:, 0], m[:, 1]) return functions
def read_table(parfile, s1, s2): """ Read parameter table from file parfile for elements with symbols s1 and s2. return list of tables [s1_s2_table,s2_s1_table] (or only other if s1==s2) """ if parfile.find('.skf') > 0: if not parfile != '%s%s.skf': raise NotImplementedError( 'Comparison assumes filename of type symbol1symbol2.skf.') rgrid, table12 = read_skf_table('%s%s.skf' % (s1, s2), s1, s2) rgrid, table21 = read_skf_table('%s%s.skf' % (s2, s1), s2, s1) table = [table12] if s1 != s2: table.append(table21) else: f = open(parfile) nel = [1, 2][s1 == s2] tab = mix.find_value(parfile, '%s_%s_table' % (s1, s2), fmt='matrix') rgrid = tab[:, 0] table = [tab[:, 1:]] if s1 != s2: tab = mix.find_value(parfile, '%s_%s_table' % (s2, s1), fmt='matrix') table.append(tab[:, 1:]) f.close() return rgrid, table
def read_elm(filename, orbitals): """ Read element data form .elm-file. """ f = open(filename, 'r') data = {} data['symbol'] = find_value(f, 'symbol') data['energies'] = [ float(find_value(f, 'epsilon_%s' % orb)) for orb in orbitals ] data['U'] = float(find_value(f, 'U')) data['FWHM'] = float(find_value(f, 'FWHM')) f.close() return data
def read_par(el1, el2, filename): """ Read parameter files. """ f = open(filename, 'r') tables = {} t12 = find_value(f, '%s_%s_table' % (el1, el2), fmt='matrix') t21 = find_value(f, '%s_%s_table' % (el2, el1), fmt='matrix') tables['N'] = len(t12[:, 0]) dr = t12[1, 0] - t12[0, 0] dr2 = t21[1, 0] - t21[0, 0] assert abs(dr - dr2) < 1E-13 tables['dr'] = dr tables['grid'] = t12[:, 0] tables['%s%s' % (el1, el2)] = t12[:, 1:] tables['%s%s' % (el2, el1)] = t21[:, 1:] rep = find_value(f, 'repulsion', fmt='matrix') return tables, rep
def read_HS_from_par(fileobj, symboli, symbolj): """ Read Hamiltonian and overlap data from Hotbit-style .par file. Parameters: ----------- fileobj: filename of file-object to read from symboli: chemical symbol of the first element symbolj: chemical symbol of the second element """ if mix.find_value(fileobj, 'X_X_table', fmt='test'): table = mix.find_value(fileobj, 'X_X_table' % ( symboli, symbolj ), fmt='matrix') else: table = mix.find_value(fileobj, '%s_%s_table' % ( symboli, symbolj ), fmt='matrix') return table[:, 0], table[:, 1:]
def read_HS_from_par(fileobj, symboli, symbolj): """ Read Hamiltonian and overlap data from Hotbit-style .par file. Parameters: ----------- fileobj: filename of file-object to read from symboli: chemical symbol of the first element symbolj: chemical symbol of the second element """ if mix.find_value(fileobj, 'X_X_table', fmt='test'): table = mix.find_value(fileobj, 'X_X_table' % (symboli, symbolj), fmt='matrix') else: table = mix.find_value(fileobj, '%s_%s_table' % (symboli, symbolj), fmt='matrix') return table[:, 0], table[:, 1:]
def read_element_from_elm(fileobj, symbol): """ Read element data from Hotbit-style .elm file. Parameters: ----------- fileobj: filename of file-object to read from symbol: chemical symbol of the element """ if isinstance(fileobj, str): fileobj = open(fileobj) symb = mix.find_value(fileobj, 'symbol').strip() assert symb == symbol data = copy(box_data[symbol]) data['U'] = float(mix.find_value(fileobj, 'U')) data['FWHM'] = float(mix.find_value(fileobj, 'FWHM')) data['epsilon'] = { } for orbital in data['valence_orbitals']: data['epsilon'][orbital] = float( mix.find_value(fileobj, 'epsilon_%s' % orbital) ) data['comment'] = mix.find_value(fileobj, 'comment', fmt='strings', default=['no comment']) functions = _read_functions(fileobj, data['valence_orbitals']) energies=[] for orbital in data['valence_orbitals']: eps = data['epsilon'][orbital] if 's' in orbital: n=1 elif 'p' in orbital: n=3 elif 'd' in orbital: n=5 energies.extend( [eps]*n ) data['onsite_energies'] = energies data['nr_basis_orbitals'] = len(energies) data['valence_energies'] = np.array(energies, dtype=float) # vdW correction data['C6'] = mix.find_value(fileobj, 'C6', default=-1.0) data['p'] = mix.find_value(fileobj, 'p', default=-1.0) data['R0'] = mix.find_value(fileobj, 'R0', default=-1.0) return data, functions
def read_element_from_elm(fileobj, symbol): """ Read element data from Hotbit-style .elm file. Parameters: ----------- fileobj: filename of file-object to read from symbol: chemical symbol of the element """ if isinstance(fileobj, str): fileobj = open(fileobj) symb = mix.find_value(fileobj, 'symbol').strip() assert symb == symbol data = copy(box_data[symbol]) data['U'] = float(mix.find_value(fileobj, 'U')) data['FWHM'] = float(mix.find_value(fileobj, 'FWHM')) data['epsilon'] = {} for orbital in data['valence_orbitals']: data['epsilon'][orbital] = float( mix.find_value(fileobj, 'epsilon_%s' % orbital)) data['comment'] = mix.find_value(fileobj, 'comment', fmt='strings', default=['no comment']) functions = _read_functions(fileobj, data['valence_orbitals']) energies = [] for orbital in data['valence_orbitals']: eps = data['epsilon'][orbital] if 's' in orbital: n = 1 elif 'p' in orbital: n = 3 elif 'd' in orbital: n = 5 energies.extend([eps] * n) data['onsite_energies'] = energies data['nr_basis_orbitals'] = len(energies) data['valence_energies'] = np.array(energies, dtype=float) # vdW correction data['C6'] = mix.find_value(fileobj, 'C6', default=-1.0) data['p'] = mix.find_value(fileobj, 'p', default=-1.0) data['R0'] = mix.find_value(fileobj, 'R0', default=-1.0) return data, functions
def greetings(self): """ Return the repulsion documentations. """ txt='Repulsions:\n' for i,s1 in enumerate(self.calc.el.present): for s2 in self.calc.el.present[i:]: file = self.files[s1+s2] if file==None: txt+=' %s%s: None\n' %(s1,s2) else: txt+=' %s%s in %s\n' %(s1,s2,file) doc=mix.find_value(file,'repulsion_comment',fmt='strings',default=['no repulsion doc']) for line in doc: txt+=' *'+line.lstrip()+'\n' return txt
def greetings(self): """ Return the interaction specifications """ txt='Interactions:\n' for i,s1 in enumerate(self.present): for s2 in self.present: file = self.files[s1+s2] if file==None: txt+=' %s%s: None\n' %(s1,s2) else: txt+=' %s%s in %s\n' %(s1,s2,file) doc=mix.find_value(file,'slako_comment',fmt='strings',default=['no slako doc']) for line in doc: txt+=' *'+line.lstrip()+'\n' return txt
def read_repulsion_from_par(fileobj): """ Read repulsion data from Hotbit-style .par file. Parameters: ----------- fileobj: filename of file-object to read from """ try: v = mix.find_value(fileobj, 'repulsion', fmt='matrix') except: v = np.array([[0,0],[1,0],[2,0],[3,0]]) return v[:, 0], v[:, 1]
def read_repulsion_from_par(fileobj): """ Read repulsion data from Hotbit-style .par file. Parameters: ----------- fileobj: filename of file-object to read from """ try: v = mix.find_value(fileobj, 'repulsion', fmt='matrix') except: v = np.array([[0, 0], [1, 0], [2, 0], [3, 0]]) return v[:, 0], v[:, 1]
def read_table(parfile,s1,s2): """ Read parameter table from file parfile for elements with symbols s1 and s2. return list of tables [s1_s2_table,s2_s1_table] (or only other if s1==s2) """ if parfile.find('.skf')>0: if not parfile!='%s%s.skf': raise NotImplementedError('Comparison assumes filename of type symbol1symbol2.skf.') rgrid, table12 = read_skf_table('%s%s.skf' %(s1,s2),s1,s2) rgrid, table21 = read_skf_table('%s%s.skf' %(s2,s1),s2,s1) table = [table12] if s1!=s2: table.append(table21) else: f=open(parfile) nel=[1,2][s1==s2] tab=mix.find_value(parfile,'%s_%s_table' %(s1,s2),fmt='matrix') rgrid=tab[:,0] table=[tab[:,1:]] if s1!=s2: tab=mix.find_value(parfile,'%s_%s_table' %(s2,s1),fmt='matrix') table.append(tab[:,1:]) f.close() return rgrid, table