def readfile(self,filepath): x = readxml(filepath,contract_names=True) x.convert_numeric() x.condense() x.remove_hidden() pp = x.pseudo self.pp = pp h = pp.header self.element = h.symbol self.type = h.flavor self.Z = h.zval vps = self.pp.semilocal.vps if not isinstance(vps,list): vps = [vps] #end if g = vps[0].radfunc.grid if g.type=='linear': r = linspace(g.ri,g.rf,g.npts) self.r = r[1:] else: self.error('functionality for '+g.type+' grids has not yet been implemented') #end if p = obj() r = self.r ldict = dict(s=0,p=1,d=2,f=3) for vp in vps: l = vp.l v = 1./r*vp.radfunc.data[1:] p[ldict[l]]= convert(v,'Ha',self.energy_units) #end for self.potentials = p
def readfile(self, filepath): x = readxml(filepath, contract_names=True) x.convert_numeric() x.condense() x.remove_hidden() pp = x.pseudo self.pp = pp h = pp.header self.element = h.symbol self.type = h.flavor self.Z = h.zval vps = self.pp.semilocal.vps if not isinstance(vps, list): vps = [vps] #end if g = vps[0].radfunc.grid if g.type == 'linear': r = linspace(g.ri, g.rf, g.npts) self.r = r[1:] else: self.error('functionality for ' + g.type + ' grids has not yet been implemented') #end if p = obj() r = self.r ldict = dict(s=0, p=1, d=2, f=3) for vp in vps: l = vp.l v = 1. / r * vp.radfunc.data[1:] p[ldict[l]] = convert(v, 'Ha', self.energy_units) #end for self.potentials = p
def readfile(self, filepath): text = open(filepath, 'r').read() if '<UPF' not in text: upf_format = 'old' lines = text.split('\n') xml = '<upf>\n' for l in lines: if l.find('/>') != -1: ln = l.replace('/>', '>').replace('<', '</') else: ln = l #end if xml += ln + '\n' #end for xml += '</upf>\n' tmppath = filepath + '_tmp' open(tmppath, 'w').write(xml) x = readxml(tmppath, contract_names=True, strip_prefix='pp_') os.system('rm ' + tmppath) x.convert_numeric() x.condense() x.remove_hidden() pp = x.upf else: upf_format = 'new' #x = readxml(filepath,contract_names=True,strip_prefix='pp_') #x.convert_numeric() #x.condense() #x.remove_hidden() #pp = x.upf pp = obj() pp_contents = open(filepath, 'r').read() #end if if upf_format == 'old': lines = pp.header.split('\n') h = obj() i = 0 h.version = string2val(lines[i].split()[0]) i += 1 h.element = string2val(lines[i].split()[0]) i += 1 h.type = string2val(lines[i].split()[0]) i += 1 ncc = string2val(lines[i].split()[0]) i += 1 h.nonlinear_cc = dict(T=True, F=False)[ncc] h.functional = lines[i].split()[0:4] i += 1 h.Z = string2val(lines[i].split()[0]) i += 1 h.total_energy = string2val(lines[i].split()[0]) i += 1 h.wfc_cutoff, h.rho_cutoff = array(lines[i].split()[0:2], dtype=float) i += 1 h.lmax = string2val(lines[i].split()[0]) i += 1 h.npts = string2val(lines[i].split()[0]) i += 1 h.nwfc = string2val(lines[i].split()[0]) i += 1 pp.header = h if 'beta' in pp. nonlocal: beta = pp. nonlocal .beta if isinstance(beta, str): beta = [beta] #end if b = obj() for i in range(len(beta)): sections = beta[i].split('\n', 2) p = string2val(sections[0].split()[0]) v = string2val(sections[2]) b[p] = v #end for pp. nonlocal .beta = b #end if dij = pp. nonlocal .dij d = obj() lines = dij.split('\n')[1:] for l in lines: t = l.split() d[int(t[0]), int(t[1])] = string2val(t[2]) #end for pp. nonlocal .dij = d pswfc = pp.pswfc tokens = pswfc.split() nwfc = pp.header.nwfc npts = pp.header.npts wf = [] for n in range(nwfc): i = n * (4 + npts) label = tokens[i] l = int(tokens[i + 1]) ws = [] for v in tokens[i + 4:i + 4 + npts]: ws.append(float(v)) #end for orb = obj() orb.label = label orb.l = l orb.wfc = array(ws) wf.append(orb) #end for pp.pswfc = wf #fill in standard fields self.pp = pp self.r = pp.mesh.r[1:] self.local = convert(pp.local, 'Ry', self.energy_units)[1:] nl = obj() vnl = zeros(self.local.shape) if 'beta' in pp. nonlocal: beta = pp. nonlocal .beta for t, d in pp. nonlocal .dij.iteritems(): bi = beta[t[0]] bj = beta[t[1]] if not isinstance(bi, str) and not isinstance(bj, str): bb = d * bi * bj else: # the file is being misread, fix later bb = 0 * pp.mesh.r #end if naftcut = len(pp.mesh.r) - len(bb) if naftcut > 0: bb = append(bb, zeros((naftcut, ))) #end if vnl += bb[1:] / self.r**2 #end for #end if vnl = convert(vnl, 'Ry', self.energy_units) nl[0] = vnl self. nonlocal = nl h = pp.header p = obj() p[0] = self.local p[1] = self.local + self. nonlocal [0] self.potentials = p self.element = h.element self.type = h.type self.Z = h.Z
def readfile(self,filepath): text = open(filepath,'r').read() if '<UPF' not in text: upf_format = 'old' lines = text.split('\n') xml = '<upf>\n' for l in lines: if l.find('/>')!=-1: ln = l.replace('/>','>').replace('<','</') else: ln = l #end if xml+=ln+'\n' #end for xml += '</upf>\n' tmppath = filepath+'_tmp' open(tmppath,'w').write(xml) x = readxml(tmppath,contract_names=True,strip_prefix='pp_') os.system('rm '+tmppath) x.convert_numeric() x.condense() x.remove_hidden() pp = x.upf else: upf_format = 'new' #x = readxml(filepath,contract_names=True,strip_prefix='pp_') #x.convert_numeric() #x.condense() #x.remove_hidden() #pp = x.upf pp = obj() #end if if upf_format=='old': lines = pp.header.split('\n') h = obj() i=0 h.version = string2val(lines[i].split()[0]); i+=1 h.element = string2val(lines[i].split()[0]); i+=1 h.type = string2val(lines[i].split()[0]); i+=1 ncc = string2val(lines[i].split()[0]); i+=1 h.nonlinear_cc = dict(T=True,F=False)[ncc] h.functional = lines[i].split()[0:4]; i+=1 h.Z = string2val(lines[i].split()[0]); i+=1 h.total_energy = string2val(lines[i].split()[0]); i+=1 h.wfc_cutoff,h.rho_cutoff = array(lines[i].split()[0:2],dtype=float); i+=1 h.lmax = string2val(lines[i].split()[0]); i+=1 h.npts = string2val(lines[i].split()[0]); i+=1 h.nwfc = string2val(lines[i].split()[0]); i+=1 pp.header = h if 'beta' in pp.nonlocal: beta = pp.nonlocal.beta if isinstance(beta,str): beta = [beta] #end if b = obj() for i in range(len(beta)): sections = beta[i].split('\n',2) p = string2val(sections[0].split()[0]) v = string2val(sections[2]) b[p]=v #end for pp.nonlocal.beta = b #end if dij = pp.nonlocal.dij d = obj() lines = dij.split('\n')[1:] for l in lines: t = l.split() d[int(t[0]),int(t[1])] = string2val(t[2]) #end for pp.nonlocal.dij = d pswfc = pp.pswfc tokens = pswfc.split() nwfc= pp.header.nwfc npts= pp.header.npts wf = [] for n in range(nwfc): i = n*(4+npts) label = tokens[i] l = int(tokens[i+1]) ws = [] for v in tokens[i+4:i+4+npts]: ws.append(float(v)) #end for orb = obj() orb.label = label orb.l = l orb.wfc = array(ws) wf.append(orb) #end for pp.pswfc = wf #fill in standard fields self.pp = pp self.r = pp.mesh.r[1:] self.local = convert(pp.local,'Ry',self.energy_units)[1:] nl = obj() vnl = zeros(self.local.shape) if 'beta' in pp.nonlocal: beta = pp.nonlocal.beta for t,d in pp.nonlocal.dij.iteritems(): bi = beta[t[0]] bj = beta[t[1]] if not isinstance(bi,str) and not isinstance(bj,str): bb = d*bi*bj else: # the file is being misread, fix later bb = 0*pp.mesh.r #end if naftcut = len(pp.mesh.r)-len(bb) if naftcut>0: bb=append(bb,zeros((naftcut,))) #end if vnl += bb[1:]/self.r**2 #end for #end if vnl = convert(vnl,'Ry',self.energy_units) nl[0] = vnl self.nonlocal = nl h = pp.header p = obj() p[0] = self.local p[1] = self.local+self.nonlocal[0] self.potentials = p self.element = h.element self.type = h.type self.Z = h.Z
def test_read(): from generic import obj from xmlreader import readxml, XMLelement ref = obj( simulation = obj( project = obj( id = 'vmc', series = '0', application = obj( class_ = 'serial', name = 'qmcpack', role = 'molecu', version = '1.0', ) ), qmc = obj( method = 'vmc', move = 'pbyp', parameter1 = obj( name = 'walkers', text = '1', ), parameter2 = obj( name = 'warmupSteps', text = '20', ), parameter3 = obj( name = 'blocks', text = '200', ), parameter4 = obj( name = 'steps', text = '10', ), parameter5 = obj( name = 'subSteps', text = '2', ), parameter6 = obj( name = 'timestep', text = '0.4', ), ), qmcsystem = obj( hamiltonian = obj( name = 'h0', target = 'e', type = 'generic', estimator = obj( name = 'KEcorr', psi = 'psi0', source = 'e', type = 'chiesa', ), pairpot1 = obj( name = 'ElecElec', source = 'e', target = 'e', type = 'coulomb', ), pairpot2 = obj( name = 'IonIon', source = 'ion0', target = 'ion0', type = 'coulomb', ), pairpot3 = obj( format = 'xml', name = 'PseudoPot', source = 'ion0', type = 'pseudo', wavefunction = 'psi0', pseudo = obj( elementType = 'C', href = 'C.BFD.xml', ), ), pairpot4 = obj( ecut = '60.0', name = 'MPC', physical = 'no', source = 'e', target = 'e', type = 'MPC', ), ), particleset1 = obj( name = 'e', random = 'yes', group1 = obj( mass = '1.0', name = 'u', size = '32', parameter1 = obj( name = 'charge', text = '-1', ), parameter2 = obj( name = 'mass', text = '1.0', ), ), group2 = obj( mass = '1.0', name = 'd', size = '32', parameter1 = obj( name = 'charge', text = '-1', ), parameter2 = obj( name = 'mass', text = '1.0', ), ), ), particleset2 = obj( name = 'ion0', group = obj( mass = '21894.7135906', name = 'C', size = '16', attrib = obj( condition = '0', datatype = 'posArray', name = 'position', text = \ '''6.74632230 6.74632230 0.00000000 1.68658057 1.68658057 1.68658058 3.37316115 3.37316115 0.00000000 5.05974173 5.05974172 1.68658058 0.00000000 3.37316115 3.37316115 1.68658058 5.05974172 5.05974173 3.37316115 6.74632230 3.37316115 5.05974173 8.43290287 5.05974173 3.37316115 0.00000000 3.37316115 5.05974172 1.68658057 5.05974173 6.74632230 3.37316115 3.37316115 8.43290287 5.05974172 5.05974173 10.11948345 10.11948345 6.74632230 5.05974173 5.05974172 8.43290287 6.74632230 6.74632230 6.74632230 8.43290287 8.43290287 8.43290287''', ), parameter1 = obj( name = 'charge', text = '4', ), parameter2 = obj( name = 'valence', text = '4', ), parameter3 = obj( name = 'atomicnumber', text = '6', ), parameter4 = obj( name = 'mass', text = '21894.7135906', ), ), ), simulationcell = obj( parameter1 = obj( name = 'lattice', text = \ '''6.74632230 6.74632230 0.00000000 0.00000000 6.74632230 6.74632230 6.74632230 0.00000000 6.74632230''', units = 'bohr', ), parameter2 = obj( name = 'bconds', text = 'p p p', ), parameter3 = obj( name = 'LR_dim_cutoff', text = '15', ), ), wavefunction = obj( name = 'psi0', target = 'e', determinantset = obj( slaterdeterminant = obj( determinant1 = obj( group = 'u', id = 'updet', size = '32', sposet = 'spo_ud', ), determinant2 = obj( group = 'd', id = 'downdet', size = '32', sposet = 'spo_ud', ), ), ), sposet_builder = obj( href = 'MISSING.h5', meshfactor = '1.0', precision = 'float', source = 'ion0', tilematrix = '2 0 0 0 2 0 0 0 2', truncate = 'no', twistnum = '0', type = 'bspline', version = '0.10', sposet = obj( name = 'spo_ud', size = '32', spindataset = '0', type = 'bspline', ), ), ), ), ), ) files = get_files() x = readxml(files['vmc.in.xml']) assert (isinstance(x, XMLelement)) x.remove_hidden() o = x.to_obj() assert (object_eq(o, ref))