def load_data_local(self): info = self.info if info.load_jastrow: self.load_jastrow_data() elif 'filepath' in info: qxml = QmcpackInput(info.filepath) wavefunction = qxml.get('wavefunction') wavefunction = wavefunction.get_single('psi0') self.info.wfn_xml = wavefunction #end if if not info.load_jastrow: self.info.wfn_xml.pluralize()
def load_data_local(self): info = self.info if info.load_jastrow: self.load_jastrow_data() elif 'filepath' in info: try: qxml = QmcpackInput(info.filepath) wavefunction = qxml.get('wavefunction') wavefunction = wavefunction.get_single('psi0') info.wfn_xml = wavefunction except: info.wfn_xml = None info.fail = True #end try #end if if not info.load_jastrow and not info.fail: info.wfn_xml.pluralize()
def incorporate_result(self, result_name, result, sim): input = self.input system = self.system if result_name == 'orbitals': if isinstance(sim, Pw2qmcpack): h5file = result.h5file wavefunction = input.get('wavefunction') if isinstance(wavefunction, collection): wavefunction = wavefunction.get_single('psi0') #end if wf = wavefunction if 'sposet_builder' in wf and wf.sposet_builder.type == 'bspline': orb_elem = wf.sposet_builder elif 'sposet_builders' in wf and 'bspline' in wf.sposet_builders: orb_elem = wf.sposet_builders.bspline elif 'sposet_builders' in wf and 'einspline' in wf.sposet_builders: orb_elem = wf.sposet_builders.einspline elif 'determinantset' in wf and wf.determinantset.type in ( 'bspline', 'einspline'): orb_elem = wf.determinantset else: self.error( 'could not incorporate pw2qmcpack orbitals\nbspline sposet_builder and determinantset are both missing' ) #end if if 'href' in orb_elem and isinstance( orb_elem.href, str) and os.path.exists(orb_elem.href): # user specified h5 file for orbitals, bypass orbital dependency orb_elem.href = os.path.relpath(orb_elem.href, self.locdir) else: orb_elem.href = os.path.relpath(h5file, self.locdir) if system.structure.folded_structure != None: orb_elem.tilematrix = array(system.structure.tmatrix) #end if #end if defs = obj( #twistnum = 0, meshfactor=1.0) for var, val in defs.items(): if not var in orb_elem: orb_elem[var] = val #end if #end for has_twist = 'twist' in orb_elem has_twistnum = 'twistnum' in orb_elem if not has_twist and not has_twistnum: orb_elem.twistnum = 0 #end if system = self.system structure = system.structure nkpoints = len(structure.kpoints) if nkpoints == 0: self.error('system must have kpoints to assign twistnums') #end if if not os.path.exists(h5file): self.error('wavefunction file not found:\n' + h5file) #end if twistnums = list(range(len(structure.kpoints))) if self.should_twist_average: self.twist_average(twistnums) elif not has_twist and orb_elem.twistnum is None: orb_elem.twistnum = twistnums[0] #end if elif isinstance(sim, Convert4qmc): res = QmcpackInput(result.location) qs = input.simulation.qmcsystem oldwfn = qs.wavefunction newwfn = res.qmcsystem.wavefunction dset = newwfn.determinantset if 'jastrows' in newwfn: del newwfn.jastrows #end if if 'jastrows' in oldwfn: newwfn.jastrows = oldwfn.jastrows #end if if input.cusp_correction(): dset.cuspcorrection = True #end if if 'orbfile' in result: orb_h5file = result.orbfile if not os.path.exists(orb_h5file) and 'href' in dset: orb_h5file = os.path.join(sim.locdir, dset.href) #end if if not os.path.exists(orb_h5file): self.error( 'orbital h5 file from convert4qmc does not exist\nlocation checked: {}' .format(orb_h5file)) #end if orb_path = os.path.relpath(orb_h5file, self.locdir) dset.href = orb_path detlist = dset.get('detlist') if detlist is not None and 'href' in detlist: detlist.href = orb_path #end if #end if qs.wavefunction = newwfn else: self.error('incorporating orbitals from ' + sim.__class__.__name__ + ' has not been implemented') #end if elif result_name == 'jastrow': if isinstance(sim, Qmcpack): opt_file = result.opt_file opt = QmcpackInput(opt_file) wavefunction = input.get('wavefunction') optwf = opt.qmcsystem.wavefunction def process_jastrow(wf): if 'jastrow' in wf: js = [wf.jastrow] elif 'jastrows' in wf: js = list(wf.jastrows.values()) else: js = [] #end if jd = dict() for j in js: jtype = j.type.lower().replace('-', '_').replace(' ', '_') key = jtype # take care of multiple jastrows of the same type if key in jd: # use name to distinguish key += j.name if key in jd: # if still duplicate then error out msg = 'duplicate jastrow in ' + self.__class__.__name__ self.error(msg) #end if #end if jd[key] = j #end for return jd #end def process_jastrow if wavefunction == None: qs = input.get('qmcsystem') qs.wavefunction = optwf.copy() else: jold = process_jastrow(wavefunction) jopt = process_jastrow(optwf) jnew = list(jopt.values()) for jtype in jold.keys(): if not jtype in jopt: jnew.append(jold[jtype]) #end if #end for if len(jnew) == 1: wavefunction.jastrow = jnew[0].copy() else: wavefunction.jastrows = collection(jnew) #end if #end if del optwf elif result_name == 'particles': if isinstance(sim, Convert4qmc): ptcl_file = result.location qi = QmcpackInput(ptcl_file) self.input.simulation.qmcsystem.particlesets = qi.qmcsystem.particlesets else: self.error('incorporating particles from ' + sim.__class__.__name__ + ' has not been implemented') # end if elif result_name == 'structure': relstruct = result.structure.copy() relstruct.change_units('B') self.system.structure = relstruct self.system.remove_folded() self.input.incorporate_system(self.system) elif result_name == 'cuspcorr': ds = self.input.get('determinantset') ds.cuspcorrection = True try: # multideterminant ds.sposets['spo-up'].cuspinfo = os.path.relpath( result.spo_up_cusps, self.locdir) ds.sposets['spo-dn'].cuspinfo = os.path.relpath( result.spo_dn_cusps, self.locdir) except: # single determinant sd = ds.slaterdeterminant sd.determinants['updet'].cuspinfo = os.path.relpath( result.updet_cusps, self.locdir) sd.determinants['downdet'].cuspinfo = os.path.relpath( result.dndet_cusps, self.locdir) #end try elif result_name == 'wavefunction': if isinstance(sim, Qmcpack): opt = QmcpackInput(result.opt_file) qs = input.get('qmcsystem') qs.wavefunction = opt.qmcsystem.wavefunction.copy() elif isinstance(sim, PyscfToAfqmc): if not self.input.is_afqmc_input(): self.error( 'incorporating wavefunction from {} is only supported for AFQMC calculations' .format(sim.__class__.__name__)) #end if h5_file = os.path.relpath(result.h5_file, self.locdir) wfn = self.input.simulation.wavefunction ham = self.input.simulation.hamiltonian wfn.filename = h5_file wfn.filetype = 'hdf5' if 'filename' not in ham or ham.filename == 'MISSING.h5': ham.filename = h5_file ham.filetype = 'hdf5' #end if if 'xml' in result: xml = QmcpackInput(result.xml) info_new = xml.simulation.afqmcinfo.copy() info = self.input.simulation.afqmcinfo info.set_optional(**info_new) # override particular inputs set by default if 'generation_info' in input._metadata: g = input._metadata.generation_info if 'walker_type' not in g: walker_type = xml.get('walker_type') walkerset = input.get('walkerset') if walker_type is not None and walkerset is not None: walkerset.walker_type = walker_type #end if #end if #end if #end if else: self.error('incorporating wavefunction from ' + sim.__class__.__name__ + ' has not been implemented') #end if elif result_name == 'gc_occupation': from pwscf import Pwscf from qmcpack_converters import gcta_occupation if not isinstance(sim, Pw2qmcpack): msg = 'grand-canonical occupation require Pw2qmcpack' self.error(msg) #endif # step 1: extract Fermi energy for each spin from nscf nscf = None npwdep = 0 for dep in sim.dependencies: if isinstance(dep.sim, Pwscf): nscf = dep.sim npwdep += 1 if npwdep != 1: msg = 'need exactly 1 scf/nscf calculation for Fermi energy' msg += '\n found %d' % npwdep self.error(msg) #end if na = nscf.load_analyzer_image() Ef_list = na.fermi_energies # step 2: analyze ESH5 file for states below Fermi energy pa = sim.load_analyzer_image() if 'wfh5' not in pa: pa.analyze(Ef_list=Ef_list) sim.save_analyzer_image(pa) #end if # step 3: count the number of up/dn electrons at each supertwist s1 = self.system.structure ntwist = len(s1.kpoints) nelecs_at_twist = gcta_occupation(pa.wfh5, ntwist) self.nelecs_at_twist = nelecs_at_twist else: self.error('ability to incorporate result ' + result_name + ' has not been implemented')
def init_sub_analyzers(self,request=None): own_request = request==None if request==None: request = self.info.request #end if group_num = request.group_num #determine if the run was bundled if request.source.endswith('.xml'): self.info.type = 'single' else: self.info.type = 'bundled' self.bundle(request.source) return #end if self.vlog('reading input file: '+request.source,n=1) input = QmcpackInput(request.source) input.pluralize() input.unroll_calculations() calculations = input.simulation.calculations self.info.set( input = input, ordered_input = input.read_xml(request.source) ) project,wavefunction = input.get('project','wavefunction') wavefunction = wavefunction.get_single('psi0') subindent = self.subindent() self.wavefunction = WavefunctionAnalyzer(wavefunction,nindent=subindent) self.vlog('project id: '+project.id,n=1) file_prefix = project.id if group_num!=None: group_ext = '.g'+str(group_num).zfill(3) if not file_prefix.endswith(group_ext): file_prefix += group_ext #end if elif self.info.type=='single': resdir,infile = os.path.split(request.source) ifprefix = infile.replace('.xml','') ls = os.listdir(resdir) for filename in ls: if filename.startswith(ifprefix) and filename.endswith('.qmc'): group_tag = filename.split('.')[-2] #file_prefix = 'qmc.'+group_tag file_prefix = project.id+'.'+group_tag break #end if #end for #end if if 'series' in project: series_start = int(project.series) else: series_start = 0 #end if self.vlog('data file prefix: '+file_prefix,n=1) run_info = obj( file_prefix = file_prefix, series_start = series_start, source_path = os.path.split(request.source)[0], group_num = group_num, system = input.return_system() ) self.info.transfer_from(run_info) self.set_global_info() if len(request.calculations)==0: request.calculations = set(series_start+arange(len(calculations))) #end if method_aliases = dict() for method in self.opt_methods: method_aliases[method]='opt' #end for for method in self.vmc_methods: method_aliases[method]='vmc' #end for for method in self.dmc_methods: method_aliases[method]='dmc' #end for method_objs = ['qmc','opt','vmc','dmc'] for method in method_objs: self[method] = QAanalyzerCollection() #end for for index,calc in calculations.iteritems(): method = calc.method if method in method_aliases: method_type = method_aliases[method] else: self.error('method '+method+' is unrecognized') #end if if method_type in request.methods: series = series_start + index if series in request.calculations: if method in self.opt_methods: qma = OptAnalyzer(series,calc,input,nindent=subindent) self.opt[series] = qma elif method in self.vmc_methods: qma = VmcAnalyzer(series,calc,input,nindent=subindent) self.vmc[series] = qma elif method in self.dmc_methods: qma = DmcAnalyzer(series,calc,input,nindent=subindent) self.dmc[series] = qma #end if self.qmc[series] = qma #end if #end if #end for for method in method_objs: if len(self[method])==0: del self[method] #end if #end for #Check for multi-qmc results such as # optimization or timestep studies results = QAanalyzerCollection() if 'opt' in self and len(self.opt)>0: optres = OptimizationAnalyzer(input,self.opt,nindent=subindent) results.optimization = optres #end if if 'dmc' in self and len(self.dmc)>1: maxtime = 0 times = dict() for series,dmc in self.dmc.iteritems(): blocks,steps,timestep = dmc.info.method_input.list('blocks','steps','timestep') times[series] = blocks*steps*timestep maxtime = max(times[series],maxtime) #end for dmc = QAanalyzerCollection() for series,time in times.iteritems(): if abs(time-maxtime)/maxtime<.5: dmc[series] = self.dmc[series] #end if #end for if len(dmc)>1: results.timestep_study = TimestepStudyAnalyzer(dmc,nindent=subindent) #end if #end if if len(results)>0: self.results = results #end if self.unset_global_info()
def init_sub_analyzers(self, request=None): own_request = request == None if request == None: request = self.info.request #end if group_num = request.group_num #determine if the run was bundled if request.source.endswith('.xml'): self.info.type = 'single' else: self.info.type = 'bundled' self.bundle(request.source) return #end if self.vlog('reading input file: ' + request.source, n=1) input = QmcpackInput(request.source) input.pluralize() input.unroll_calculations() calculations = input.simulation.calculations self.info.set(input=input, ordered_input=input.read_xml(request.source)) project, wavefunction = input.get('project', 'wavefunction') wavefunction = wavefunction.get_single('psi0') subindent = self.subindent() self.wavefunction = WavefunctionAnalyzer(wavefunction, nindent=subindent) self.vlog('project id: ' + project.id, n=1) file_prefix = project.id if group_num != None: group_ext = '.g' + str(group_num).zfill(3) if not file_prefix.endswith(group_ext): file_prefix += group_ext #end if elif self.info.type == 'single': resdir, infile = os.path.split(request.source) #ifprefix = infile.replace('.xml','') ifprefix = infile.replace('.xml', '.') ls = os.listdir(resdir) for filename in ls: if filename.startswith(ifprefix) and filename.endswith('.qmc'): group_tag = filename.split('.')[-2] #file_prefix = 'qmc.'+group_tag file_prefix = project.id + '.' + group_tag break #end if #end for #end if if 'series' in project: series_start = int(project.series) else: series_start = 0 #end if self.vlog('data file prefix: ' + file_prefix, n=1) run_info = obj(file_prefix=file_prefix, series_start=series_start, source_path=os.path.split(request.source)[0], group_num=group_num, system=input.return_system()) self.info.transfer_from(run_info) self.set_global_info() if len(request.calculations) == 0: request.calculations = set(series_start + arange(len(calculations))) #end if method_aliases = dict() for method in self.opt_methods: method_aliases[method] = 'opt' #end for for method in self.vmc_methods: method_aliases[method] = 'vmc' #end for for method in self.dmc_methods: method_aliases[method] = 'dmc' #end for method_objs = ['qmc', 'opt', 'vmc', 'dmc'] for method in method_objs: self[method] = QAanalyzerCollection() #end for for index, calc in calculations.iteritems(): method = calc.method if method in method_aliases: method_type = method_aliases[method] else: self.error('method ' + method + ' is unrecognized') #end if if method_type in request.methods: series = series_start + index if series in request.calculations: if method in self.opt_methods: qma = OptAnalyzer(series, calc, input, nindent=subindent) primary = self.opt elif method in self.vmc_methods: qma = VmcAnalyzer(series, calc, input, nindent=subindent) primary = self.vmc elif method in self.dmc_methods: qma = DmcAnalyzer(series, calc, input, nindent=subindent) primary = self.dmc #end if primary[series] = qma self.qmc[series] = qma #end if #end if #end for for method in method_objs: if len(self[method]) == 0: del self[method] #end if #end for #Check for multi-qmc results such as # optimization or timestep studies results = QAanalyzerCollection() if 'opt' in self and len(self.opt) > 0: optres = OptimizationAnalyzer(input, self.opt, nindent=subindent) results.optimization = optres #end if if 'dmc' in self and len(self.dmc) > 1: maxtime = 0 times = dict() for series, dmc in self.dmc.iteritems(): blocks, steps, timestep = dmc.info.method_input.list( 'blocks', 'steps', 'timestep') times[series] = blocks * steps * timestep maxtime = max(times[series], maxtime) #end for dmc = QAanalyzerCollection() for series, time in times.iteritems(): if abs(time - maxtime) / maxtime < .5: dmc[series] = self.dmc[series] #end if #end for if len(dmc) > 1: results.timestep_study = TimestepStudyAnalyzer( dmc, nindent=subindent) #end if #end if if len(results) > 0: self.results = results #end if self.unset_global_info()