void GamesXmlParser::getEigVectors(vector<xmlNodePtr>& ePtrList) { vector<xmlNodePtr> a; //vector<int> numorb(ePtrList.size()); for(int i=0; i<ePtrList.size(); i++) { xmlNodePtr cur=ePtrList[i]->children; int n=0; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "ORB") { a.push_back(cur); n++; } cur=cur->next; } } //adhoc //if(ePtrList.size()>1) SpinRestricted=false; cout << "Size of eig vectors " << a.size() << " x " << SizeOfBasisSet << endl; EigVal_alpha.resize(SizeOfBasisSet); EigVal_beta.resize(SizeOfBasisSet); EigVec.resize(a.size()*SizeOfBasisSet); int ii=0; double x; for(int i=0; i<a.size(); i++) { xmlNodePtr cur=a[i]->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname== "EIGENVALUE") { if(i<SizeOfBasisSet) { putContent(x,cur); EigVal_alpha[i]=x; } else { putContent(x,cur); EigVal_beta[i-SizeOfBasisSet]=x; } } else if(cname == "BASIS_COEFF") { putContent(x,cur); EigVec[ii]=x; ii++; } cur=cur->next; } } if(SpinRestricted) EigVal_beta=EigVal_alpha; }
void GamesXmlParser::getGeometry(vector<xmlNodePtr>& aPtrList) { NumberOfAtoms = aPtrList.size(); IonSystem.create(NumberOfAtoms); GroupName.resize(NumberOfAtoms); Qv.resize(NumberOfAtoms); double nel=0; for(int i=0; i<NumberOfAtoms; i++) { xmlNodePtr cur=aPtrList[i]->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "ATOM_NAME") { string aname; putContent(aname,cur); IonSystem.GroupID[i]=IonSystem.getSpeciesSet().addSpecies(aname); GroupName[i]=aname; } else if(cname == "ATOMIC_NUMBER") { putContent(Qv[i],cur); nel+=Qv[i]; } else if(cname == "ATOM_POSITION") { xmlNodePtr tcur=cur->children; while(tcur!=NULL) { string tname((const char*)tcur->name); double x,y,z; if(tname == "XCOORD") putContent(x,tcur); else if(tname == "YCOORD") putContent(y,tcur); else if(tname == "ZCOORD") putContent(z,tcur); IonSystem.R[i]=SingleParticlePos_t(x,y,z); tcur=tcur->next; } } cur=cur->next; }//loop-cur }//i NumberOfEls=static_cast<int>(nel); NumberOfBeta=(NumberOfEls-NumberOfAlpha)/2; NumberOfAlpha=NumberOfEls-NumberOfBeta; cout << "Number of atoms " << NumberOfAtoms << endl; cout << "Number of electrons " << NumberOfEls << endl; cout << "Number of electrons (ALPHA) " << NumberOfAlpha << endl; cout << "Number of electrons (BETA) " << NumberOfBeta << endl; cout << "Group ID " << endl; std::copy(IonSystem.GroupID.begin(), IonSystem.GroupID.end(), ostream_iterator<int>(cout, " ")); cout << endl; }
WMConstraints::InFuncType* WMConstraints::createCorrelation(xmlNodePtr cur,BasisSetType* basis) { int nc=0; InFuncType* acombo=new InFuncType; cur=cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == "parameter") { string id("0"); string ref("0"); RealType c=1.0; OhmmsAttributeSet aAttrib; aAttrib.add(id,"id"); aAttrib.add(ref,"ref"); aAttrib.put(cur); putContent(c,cur); if(nc <basis->size()) acombo->add((*basis)[nc++],c,id); } cur=cur->next; } if(nc) return acombo; else { delete acombo; return 0; } }
void GamesXmlParser::getControlParameters(xmlNodePtr cur) { string a; cur=cur->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "SCFTYP") { putContent(a,cur); if(a == "RHF" || a == "ROHF") SpinRestricted=true; else if(a == "URHF" || a == "UHF") SpinRestricted=false; } else if(cname == "MULT") { putContent(SpinMultiplicity,cur); } cur=cur->next; } }
bool SlaterDetBuilder::put(xmlNodePtr cur) { ReportEngine PRE(ClassName,"put(xmlNodePtr)"); ///save the current node xmlNodePtr curRoot=cur; bool success=true; cur = cur->children; string cname, tname; while(cur != NULL) { getNodeName(cname,cur); if(cname == basisset_tag) { if(myBasisSetFactory == 0) { myBasisSetFactory = new BasisSetFactory(targetPtcl,targetPsi, ptclPool); myBasisSetFactory->setReportLevel(ReportLevel); } myBasisSetFactory->createBasisSet(cur,curRoot); //Children.push_back(bsFactory); } else if(cname == sd_tag) { int is=SlaterDetSet.size(); //add a new SlaterDeterminant SlaterDetSet.push_back(new SlaterDeterminant_t); sdet_coeff.push_back(1.0); int firstIndex = 0; xmlNodePtr tcur = cur->children; while(tcur != NULL) { getNodeName(tname,tcur); if(tname == param_tag) { putContent(sdet_coeff[is],tcur); } else if(tname == det_tag) { firstIndex = putDeterminant(tcur, firstIndex); } tcur = tcur->next; } } cur = cur->next; } if(SlaterDetSet.empty()) { //fatal PRE.error("Failed to create a SlaterDeterminant.",true); return false; } if(SlaterDetSet.size()>1) buildMultiSlaterDetermiant(); else buildSlaterDetermiant(); return success; }
Content* Hashtable::insertListContent(Content* mycon, hashtype hash) { List* mylist = dynamic_cast<List*>(getContent(hash)); // If there are few hash collisions, this is often NULL if( NULL == mylist ) { putContent(new List(mycon), hash); } else { // Hash collision - we hope this is rare unless same content // Search through doubly linked, lexicographically sorted list // Find "before" list item of smaller or equal content List* beflist = mylist->findBef(mycon); if( NULL == beflist ) { // First item is greater than mycon, insert mycon in front of // existing items, we know mylist != NULL List* newlist = new List(mycon); mylist->putPrev(newlist); newlist->putNext(mylist); // register newlist as first list element with hash table putContent(newlist, hash); } else { // Check if we have a match if( 0 == mycon->compare(beflist->getContent()) ) { // delete redundant mycon and return existing Content delete mycon; mycon = beflist->getContent(); } else { // We are somewhere in the middle or at the end. Get next list element. mylist = beflist->getNext(); List* newlist = new List(mycon); // If we are at the end, append. if( NULL != mylist ) { // Connect forwards mylist->putPrev(newlist); newlist->putNext(mylist); } // Always connect backwards beflist->putNext(newlist); newlist->putPrev(beflist); } } } return mycon; }
void OrbitalConstraintsBase::getParam(xmlNodePtr cur) { const xmlChar* a=xmlGetProp(cur,(const xmlChar*)"id"); const xmlChar* b=xmlGetProp(cur,(const xmlChar*)"name"); if(a == NULL || b == NULL) return; RealType val; string vname((const char*)b); putContent(val,cur); map<string,pair<string,RealType> >::iterator vit(inVars.find(vname)); if(vit == inVars.end()) { inVars[vname]=pair<string,RealType>((const char*)a,val); } }
bool LatticeParser::put(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur) { double a0 = 1.0; cur = cur->xmlChildrenNode; vector<SingleParticleIndex_t> grid(3,SingleParticleIndex_t(1)); TinyVector<string,OHMMS_DIM> bconds("p"); while (cur != NULL) { if(!xmlStrcmp(cur->name, (const xmlChar *)"PARAMETER")) { string aname = (const char*)(xmlGetProp(cur, (const xmlChar *) "name")); if(aname == "scale") { putContent(a0,cur); } else if(aname == "lattice") { putContent(ref_.R,cur); } else if(aname == "grid") { putContent(grid[2],cur); } else if(aname == "omgrid") { putContent(grid[1],cur); } else if(aname == "mpigrid") { putContent(grid[0],cur); } else if(aname == "bconds") { putContent(bconds,cur); } } cur = cur->next; } for(int idir=0; idir<OHMMS_DIM; idir++) { char b = bconds[idir][0]; if(b == 'n' || b == 'N') { ref_.BConds[idir] = ParticleNoBCond; ref_.BConds.wrapper(idir) = ParticleNoBCond; ref_.BoxBConds[idir] = false; } } ref_.R *= a0; ref_.reset(); PartitionGrid(ref_,grid); return true; }
void Hashtable::evictListitem(List* mylist, hashtype ehash) { List* prevlist = mylist->getPrev(); List* nextlist = mylist->getNext(); // First item in list? if( NULL == prevlist ) { // This may be NULL, which is fine putContent(nextlist, ehash); if( NULL != nextlist ) { nextlist->putPrev(NULL); } } else { // connect up previous prevlist->putNext(nextlist); if( NULL != nextlist ) { nextlist->putPrev(prevlist); } } // Next line could go into destructor of List class but then we'd rely on // having each element referenced only once, making reuse of code harder. delete mylist->getContent(); delete mylist; }
ECPComponentBuilder::GridType* ECPComponentBuilder::createGrid(xmlNodePtr cur, bool useLinear) { RealType ri = 1e-6; RealType rf = 100.0; RealType ascale = -1.0e0; RealType astep = -1.0; //RealType astep = 1.25e-2; int npts = 1001; string gridType("log"); string gridID("global"); OhmmsAttributeSet radAttrib; radAttrib.add(gridType,"type"); radAttrib.add(gridID,"grid_id"); radAttrib.add(gridID,"grid_def"); radAttrib.add(gridID,"name"); radAttrib.add(gridID,"id"); radAttrib.add(npts,"npts"); radAttrib.add(ri,"ri"); radAttrib.add(rf,"rf"); radAttrib.add(ascale,"ascale"); radAttrib.add(astep,"astep"); radAttrib.add(ascale,"scale"); radAttrib.add(astep,"step"); radAttrib.put(cur); map<string,GridType*>::iterator git(grid_inp.find(gridID)); if(git != grid_inp.end()) { return (*git).second; //use the same grid } //overwrite the grid type to linear starting at 0.0 if(useLinear) { gridType="linear"; ri=0.0; } GridType *agrid=0; if(gridType == "log") { if(ascale>0.0) { app_log() << " Log grid scale=" << ascale << " step=" << astep << " npts=" << npts << endl; agrid = new LogGridZero<RealType>; agrid->set(astep,ascale,npts); } else { if(ri<numeric_limits<RealType>::epsilon()) { ri=numeric_limits<RealType>::epsilon(); } agrid = new LogGrid<RealType>; agrid->set(ri,rf,npts); } } else if(gridType == "linear") { agrid = new LinearGrid<RealType>; if(astep>0.0) { npts = static_cast<int>((rf-ri)/astep)+1; } agrid->set(ri,rf,npts); app_log() << " Linear grid ri=" << ri << " rf=" << rf << " npts = " << npts << endl; } else //accept numerical data { xmlNodePtr cur1=cur->children; while(cur1 != NULL) { string cname((const char*)cur1->name); if(cname == "data") { std::vector<double> gIn(npts); putContent(gIn,cur1); agrid = new NumericalGrid<RealType>(gIn); app_log() << " Numerical grid npts = " << gIn.size() << endl; } cur1 = cur1->next; } } return agrid; }
/** create a SlaterDeterminant * @param cur xmlnode containing \<slaterdeterminant\> * @return a SlaterDeterminant * * @warning MultiSlaterDeterminant is not working yet. */ SPOSetBase* SplineSetBuilder::createSPOSet(xmlNodePtr cur) { string hrefname("NONE"); int norb(0); int degeneracy(1); OhmmsAttributeSet aAttrib; aAttrib.add(norb,"orbitals"); aAttrib.add(degeneracy,"degeneracy"); aAttrib.add(hrefname,"href"); aAttrib.put(cur); if(norb ==0) { app_error() << "SplineSetBuilder::createSPOSet failed. Check the attribte orbitals." << endl; return 0; } app_log() << " Degeneracy = " << degeneracy << endl; std::vector<int> npts(3); npts[0]=GridXYZ->nX; npts[1]=GridXYZ->nY; npts[2]=GridXYZ->nZ; std::vector<RealType> inData(npts[0]*npts[1]*npts[2]); SPOSetType* psi= new SPOSetType(norb); vector<int> occSet(norb); for(int i=0; i<norb; i++) occSet[i]=i; cur=cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == "occupation") { string occ_mode("ground"); const xmlChar* o=xmlGetProp(cur,(const xmlChar*)"mode"); if(o!= NULL) occ_mode = (const char*)o; //Do nothing if mode == ground if(occ_mode == "excited") { vector<int> occ_in, occRemoved; putContent(occ_in,cur); for(int k=0; k<occ_in.size(); k++) { if(occ_in[k]<0) occRemoved.push_back(-occ_in[k]-1); } int kpopd=0; for(int k=0; k<occ_in.size(); k++) { if(occ_in[k]>0) occSet[occRemoved[kpopd++]]=occ_in[k]-1; } } hid_t h_file = H5Fopen(hrefname.c_str(),H5F_ACC_RDWR,H5P_DEFAULT); const xmlChar* h5path = xmlGetProp(cur,(const xmlChar*)"h5path"); string hroot("/eigenstates_3/twist_0"); if(h5path != NULL) hroot=(const char*)h5path; char wfname[128],wfshortname[16]; for(int iorb=0; iorb<norb; iorb++) { sprintf(wfname,"%s/band_%d/eigenvector",hroot.c_str(),occSet[iorb]/degeneracy); sprintf(wfshortname,"b%d",occSet[iorb]/degeneracy); SPOType* neworb=0; map<string,SPOType*>::iterator it(NumericalOrbitals.find(wfshortname)); if(it == NumericalOrbitals.end()) { neworb=new SPOType(GridXYZ); HDFAttribIO<std::vector<RealType> > dummy(inData,npts); dummy.read(h_file,wfname); //neworb->reset(inData.begin(), inData.end(), targetPtcl.Lattice.BoxBConds[0]); neworb->reset(inData.begin(), inData.end(), targetPtcl.Lattice.SuperCellEnum); NumericalOrbitals[wfshortname]=neworb; app_log() << " Reading spline function " << wfname << endl; } else { neworb = (*it).second; app_log() << " Reusing spline function " << wfname << endl; } psi->add(neworb); } H5Fclose(h_file); } cur=cur->next; } SPOType* aorb=(*NumericalOrbitals.begin()).second; string fname("spline3d.vti"); std::ofstream dfile(fname.c_str()); dfile.setf(ios::scientific, ios::floatfield); dfile.setf(ios::left,ios::adjustfield); dfile.precision(10); dfile << "<?xml version=\"1.0\"?>" << endl; dfile << "<VTKFile type=\"ImageData\" version=\"0.1\">" << endl; dfile << " <ImageData WholeExtent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\" Origin=\"0 0 0\" Spacing=\"1 1 1\">"<< endl; dfile << " <Piece Extent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\">" << endl; dfile << " <PointData Scalars=\"wfs\">" << endl; dfile << " <DataArray type=\"Float32\" Name=\"wfs\">" << endl; int ng=0; GradType grad; ValueType lap; for(int ix=0; ix<npts[0]-1; ix++) { double x(GridXYZ->gridX->operator()(ix)); for(int iy=0; iy<npts[1]-1; iy++) { double y(GridXYZ->gridY->operator()(iy)); for(int iz=0; iz<npts[2]-1; iz++, ng++) { PosType p(x,y,GridXYZ->gridZ->operator()(iz)); //aorb.setgrid(p); //Timing with the ofstream is not correct. //Uncomment the line below and comment out the next two line. //double t=aorb.evaluate(p,grad,lap); dfile << setw(20) << aorb->evaluate(p,grad,lap); if(ng%5 == 4) dfile << endl; } } } dfile << " </DataArray>" << endl; dfile << " </PointData>" << endl; dfile << " </Piece>" << endl; dfile << " </ImageData>" << endl; dfile << "</VTKFile>" << endl; abort(); return psi; }
bool PadeJastrowBuilder::put(xmlNodePtr cur) { ReportEngine PRE(ClassName,"put()"); string sourceOpt=targetPtcl.getName(); string jname="PadeJastrow"; string spin="no"; string id_b="jee_b"; RealType pade_b=1.0; OhmmsAttributeSet pattrib; pattrib.add(jname,"name"); pattrib.add(spin,"spin"); pattrib.add(sourceOpt,"source"); pattrib.put(cur); cur=cur->children; while(cur != NULL) { {//just to hide this string pname="0"; OhmmsAttributeSet aa; aa.add(pname,"name"); aa.add(id_b,"id"); aa.put(cur); if(pname[0]=='B') putContent(pade_b,cur); } xmlNodePtr cur1=cur->children; while(cur1!= NULL) { string pname="0"; OhmmsAttributeSet aa; aa.add(pname,"name"); aa.add(id_b,"id"); aa.put(cur1); if(pname[0]=='B') putContent(pade_b,cur1); cur1=cur1->next; } cur=cur->next; } app_log() << "PadeJastrowBuilder " << id_b << " = " << pade_b << endl; typedef PadeFunctor<RealType> FuncType; typedef TwoBodyJastrowOrbital<FuncType> JeeType; JeeType *J2 = new JeeType(targetPtcl); SpeciesSet& species(targetPtcl.getSpeciesSet()); RealType q=species(0,species.addAttribute("charge")); if(spin == "no") { RealType cusp=-0.5*q*q; FuncType *func=new FuncType(cusp,pade_b); func->setIDs("jee_cusp",id_b);//set the ID's J2->addFunc("pade_uu",0,0,func); //DerivFuncType *dfunc=new DerivFuncType(cusp,B); //dJ2->addFunc("pade_uu",0,0,dfunc); //dFuncList.push_back(dfunc); app_log() << " Adding Spin-independent Pade Two-Body Jastrow Cusp " << cusp<< "\n"; } else { //build uu functor RealType cusp_uu=-0.25*q*q; FuncType *funcUU=new FuncType(cusp_uu,pade_b); funcUU->setIDs("pade_uu",id_b);//set the ID's //build ud functor RealType cusp_ud=-0.5*q*q; FuncType *funcUD=new FuncType(cusp_ud,pade_b); funcUD->setIDs("pade_ud",id_b);//set the ID's J2->addFunc("pade_uu",0,0,funcUU); //DerivFuncType *dfuncUU=new DerivFuncType(cusp_uu,B); //DerivFuncType *dfuncUD=new DerivFuncType(cusp_ud,B); //dJ2->addFunc("pade_uu",0,0,dfuncUU); //dJ2->addFunc("pade_ud",0,1,dfuncUD); app_log() << " Adding Spin-dependent Pade Two-Body Jastrow " << "\n"; app_log() << " parallel spin " << cusp_uu << "\n"; app_log() << " antiparallel spin " << cusp_ud << "\n"; } targetPsi.addOrbital(J2,"J2_pade"); if(sourceOpt != targetPtcl.getName()) { map<string,ParticleSet*>::iterator pa_it(ptclPool.find(sourceOpt)); if(pa_it == ptclPool.end()) { PRE.warning("PadeJastrowBuilder::put failed. "+sourceOpt+" does not exist."); return true; } ParticleSet& sourcePtcl= (*(*pa_it).second); app_log() << " PadeBuilder::Adding Pade One-Body Jastrow with effective ionic charges." << endl; typedef OneBodyJastrowOrbital<FuncType> JneType; JneType* J1 = new JneType(sourcePtcl,targetPtcl); //typedef OneBodyJastrowOrbital<DerivFuncType> DerivJneType; //DerivJneType* dJ1=new DerivJneType(sourcePtcl,targetPtcl); SpeciesSet& Species(sourcePtcl.getSpeciesSet()); int ng=Species.getTotalNum(); int icharge = Species.addAttribute("charge"); for(int ig=0; ig<ng; ++ig) { RealType zeff=Species(icharge,ig); ostringstream j1id; j1id<<"pade_"<<Species.speciesName[ig]; RealType sc=std::pow(2*zeff,0.25); FuncType *func=new FuncType(-zeff,pade_b,sc); func->setIDs(j1id.str(),id_b); J1->addFunc(ig,func); //DerivFuncType *dfunc=new DerivFuncType(-zeff,B,sc); //dJ1->addFunc(ig,dfunc); //dFuncList.push_back(dfunc); app_log() << " " << Species.speciesName[ig] << " Zeff = " << zeff << " B= " << pade_b*sc << endl; } targetPsi.addOrbital(J1,"J1_pade"); } return true; }
void GamesXmlParser::parse(const std::string& fname) { xmlDocPtr m_doc = xmlParseFile(fname.c_str()); if (m_doc == NULL) { ERRORMSG("File " << fname << " is invalid") xmlFreeDoc(m_doc); return; } xmlNodePtr cur = xmlDocGetRootElement(m_doc); if(!xmlStrEqual(cur->name,(const xmlChar*)"GAMESS")) { ERRORMSG("File " << fname << " does not have GAMESS as its root. Invalid") xmlFreeDoc(m_doc); return; } //xmlNodePtr for atoms vector<xmlNodePtr> aPtrList; //xmlNodePtr for eigvectors vector<xmlNodePtr> ePtrList; //xmlNodePtr for gaussian basis vector<xmlNodePtr> bPtrList; cur=cur->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "IN") { xmlNodePtr cur1=cur->children; while(cur1 != NULL) { string cname1((const char*)cur1->name); if(cname1 == "RUN_TITLE") { string atitle; putContent(atitle,cur1); string::size_type wh=atitle.find("..."); if(wh<atitle.size()) atitle.erase(wh,atitle.size()-wh); Title = atitle; } else if(cname1 == "CONTRL") { getControlParameters(cur1); } cur1=cur1->next; }//everything within IN } else if(cname == "OUT") { xmlNodePtr cur1=cur->children; while(cur1 != NULL) { string cname1((const char*)cur1->name); if(cname1 == "SYSTEM_STATE") { //Unit needs to be generalized!! string unitL((const char*)xmlGetProp(cur1,(const xmlChar*)"UNITS")); if(unitL == "ANGS") BohrUnit=false; xmlNodePtr cur2 = cur1->children; while(cur2 != NULL) { string cname2((const char*)cur2->name); if(cname2 == "ATOM") { aPtrList.push_back(cur2); } else if(cname2 == "VEC") { ePtrList.push_back(cur2); } cur2=cur2->next; } } else if(cname1 == "PDATA") { xmlNodePtr cur2 = cur1->children; while(cur2 != NULL) { string cname2((const char*)cur2->name); if(cname2 == "PATOMIC_BASIS_SET") { bPtrList.push_back(cur2); } cur2=cur2->next; } } cur1=cur1->next; }//everything within OUT } cur=cur->next; } //xmlXPathContextPtr m_context = xmlXPathNewContext(m_doc); getGeometry(aPtrList); getGaussianCenters(bPtrList); getEigVectors(ePtrList); //xmlXPathFreeContext(m_context); xmlFreeDoc(m_doc); }
SPOSetBase* EinsplineSetBuilder::createSPOSet(xmlNodePtr cur) { //use 2 bohr as the default when truncated orbitals are used based on the extend of the ions BufferLayer=2.0; OhmmsAttributeSet attribs; int numOrbs = 0; qafm=0; int sortBands(1); string sourceName; string spo_prec("double"); string truncate("no"); #if defined(QMC_CUDA) string useGPU="yes"; #else string useGPU="no"; #endif attribs.add (H5FileName, "href"); attribs.add (TileFactor, "tile"); attribs.add (sortBands, "sort"); attribs.add (qafm, "afmshift"); attribs.add (TileMatrix, "tilematrix"); attribs.add (TwistNum, "twistnum"); attribs.add (givenTwist, "twist"); attribs.add (sourceName, "source"); attribs.add (MeshFactor, "meshfactor"); attribs.add (useGPU, "gpu"); attribs.add (spo_prec, "precision"); attribs.add (truncate, "truncate"); attribs.add (BufferLayer, "buffer"); attribs.put (XMLRoot); attribs.add (numOrbs, "size"); attribs.add (numOrbs, "norbs"); attribs.put (cur); /////////////////////////////////////////////// // Read occupation information from XML file // /////////////////////////////////////////////// cur = cur->children; int spinSet = -1; vector<int> Occ_Old(0,0); Occ.resize(0,0); bool NewOcc(false); while (cur != NULL) { string cname((const char*)(cur->name)); if(cname == "occupation") { string occ_mode("ground"); occ_format="energy"; particle_hole_pairs=0; OhmmsAttributeSet oAttrib; oAttrib.add(occ_mode,"mode"); oAttrib.add(spinSet,"spindataset"); oAttrib.add(occ_format,"format"); oAttrib.add(particle_hole_pairs,"pairs"); oAttrib.put(cur); if(occ_mode == "excited") { putContent(Occ,cur); } else if(occ_mode != "ground") { app_error() << "Only ground state occupation currently supported " << "in EinsplineSetBuilder.\n"; APP_ABORT("EinsplineSetBuilder::createSPOSet"); } } cur = cur->next; } if (Occ != Occ_Old) { NewOcc=true; Occ_Old = Occ; } else NewOcc=false; #if defined(QMC_CUDA) app_log() << "\t QMC_CUDA=1 Overwriting the precision of the einspline storage on the host.\n"; spo_prec="double"; //overwrite #endif H5OrbSet aset(H5FileName, spinSet, numOrbs); std::map<H5OrbSet,SPOSetBase*,H5OrbSet>::iterator iter; iter = SPOSetMap.find (aset); if ((iter != SPOSetMap.end() ) && (!NewOcc) && (qafm==0)) { qafm=0; app_log() << "SPOSet parameters match in EinsplineSetBuilder: " << "cloning EinsplineSet object.\n"; return iter->second->makeClone(); } // The tiling can be set by a simple vector, (e.g. 2x2x2), or by a // full 3x3 matrix of integers. If the tilematrix was not set in // the input file... bool matrixNotSet = true; for (int i=0; i<3; i++) for (int j=0; j<3; j++) matrixNotSet = matrixNotSet && (TileMatrix(i,j) == 0); // then set the matrix to what may have been specified in the // tiling vector if (matrixNotSet) for (int i=0; i<3; i++) for (int j=0; j<3; j++) TileMatrix(i,j) = (i==j) ? TileFactor(i) : 0; if (myComm->rank() == 0) fprintf (stderr, " [ %2d %2d %2d\n %2d %2d %2d\n %2d %2d %2d ]\n", TileMatrix(0,0), TileMatrix(0,1), TileMatrix(0,2), TileMatrix(1,0), TileMatrix(1,1), TileMatrix(1,2), TileMatrix(2,0), TileMatrix(2,1), TileMatrix(2,2)); if (numOrbs == 0) { app_error() << "You must specify the number of orbitals in the input file.\n"; APP_ABORT("EinsplineSetBuilder::createSPOSet"); } else app_log() << " Reading " << numOrbs << " orbitals from HDF5 file.\n"; Timer mytimer; mytimer.restart(); ///////////////////////////////////////////////////////////////// // Read the basic orbital information, without reading all the // // orbitals themselves. // ///////////////////////////////////////////////////////////////// if (myComm->rank() == 0) if (!ReadOrbitalInfo()) { app_error() << "Error reading orbital info from HDF5 file. Aborting.\n"; APP_ABORT("EinsplineSetBuilder::createSPOSet"); } app_log() << "TIMER EinsplineSetBuilder::ReadOrbitalInfo " << mytimer.elapsed() << endl; myComm->barrier(); mytimer.restart(); BroadcastOrbitalInfo(); app_log() << "TIMER EinsplineSetBuilder::BroadcastOrbitalInfo " << mytimer.elapsed() << endl; app_log().flush(); /////////////////////////////////////////////////////////////////// // Now, analyze the k-point mesh to figure out the what k-points // // are needed // /////////////////////////////////////////////////////////////////// PrimCell.set(Lattice); SuperCell.set(SuperLattice); for (int iat=0; iat<AtomicOrbitals.size(); iat++) AtomicOrbitals[iat].Lattice = Lattice; // Copy supercell into the ParticleSets // app_log() << "Overwriting XML lattice with that from the ESHDF file.\n"; // PtclPoolType::iterator piter; // for(piter = ParticleSets.begin(); piter != ParticleSets.end(); piter++) // piter->second->Lattice.copy(SuperCell); AnalyzeTwists2(); ////////////////////////////////// // Create the OrbitalSet object ////////////////////////////////// if (HaveLocalizedOrbs) OrbitalSet = new EinsplineSetLocal; #ifdef QMC_CUDA else if (AtomicOrbitals.size() > 0) { if (UseRealOrbitals) OrbitalSet = new EinsplineSetHybrid<double>; else OrbitalSet = new EinsplineSetHybrid<complex<double> >; } #endif else { if (UseRealOrbitals) OrbitalSet = new EinsplineSetExtended<double>; else OrbitalSet = new EinsplineSetExtended<complex<double> >; } //set the internal parameters setTiling(OrbitalSet,numOrbs); if (HaveLocalizedOrbs) { EinsplineSetLocal *restrict orbitalSet = dynamic_cast<EinsplineSetLocal*>(OrbitalSet); #pragma omp critical(read_einspline_orbs) { if ((spinSet == LastSpinSet) && (numOrbs <= NumOrbitalsRead) && (!NewOcc) ) CopyBands(numOrbs); else { // Now, figure out occupation for the bands and read them OccupyBands(spinSet, sortBands); ReadBands (spinSet, orbitalSet); } } // Now, store what we have read LastOrbitalSet = OrbitalSet; LastSpinSet = spinSet; NumOrbitalsRead = numOrbs; } else // Otherwise, use EinsplineSetExtended { mytimer.restart(); bool use_single= (spo_prec == "single" || spo_prec == "float"); if (UseRealOrbitals) { OccupyBands(spinSet, sortBands); //check if a matching BsplineReaderBase exists BsplineReaderBase* spline_reader=0; //if(TargetPtcl.Lattice.SuperCellEnum != SUPERCELL_BULK && truncate=="yes") if(truncate=="yes") { if(use_single) { if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_OPEN) spline_reader= new SplineMixedAdoptorReader<SplineOpenAdoptor<float,double,3> >(this); else if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_SLAB) spline_reader= new SplineMixedAdoptorReader<SplineMixedAdoptor<float,double,3> >(this); else spline_reader= new SplineAdoptorReader<SplineR2RAdoptor<float,double,3> >(this); } else { if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_OPEN) spline_reader= new SplineMixedAdoptorReader<SplineOpenAdoptor<double,double,3> >(this); else if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_SLAB) spline_reader= new SplineMixedAdoptorReader<SplineMixedAdoptor<double,double,3> >(this); else spline_reader= new SplineAdoptorReader<SplineR2RAdoptor<double,double,3> >(this); } } else { if(use_single) spline_reader= new SplineAdoptorReader<SplineR2RAdoptor<float,double,3> >(this); } if(spline_reader) { HasCoreOrbs=bcastSortBands(NumDistinctOrbitals,myComm->rank()==0); SPOSetBase* bspline_zd=spline_reader->create_spline_set(spinSet,OrbitalSet); delete spline_reader; if(bspline_zd) SPOSetMap[aset] = bspline_zd; return bspline_zd; } else { app_log() << ">>>> Creating EinsplineSetExtended<double> <<<< " << endl; EinsplineSetExtended<double> *restrict orbitalSet = dynamic_cast<EinsplineSetExtended<double>* > (OrbitalSet); if (Format == ESHDF) ReadBands_ESHDF(spinSet,orbitalSet); else ReadBands(spinSet, orbitalSet); } } else { OccupyBands(spinSet, sortBands); BsplineReaderBase* spline_reader=0; if(truncate == "yes") { app_log() << " Truncated orbitals with multiple kpoints are not supported yet!" << endl; } if(use_single) { #if defined(QMC_COMPLEX) spline_reader= new SplineAdoptorReader<SplineC2CPackedAdoptor<float,double,3> >(this); #else spline_reader= new SplineAdoptorReader<SplineC2RPackedAdoptor<float,double,3> >(this); #endif } if(spline_reader) { RotateBands_ESHDF(spinSet, dynamic_cast<EinsplineSetExtended<complex<double> >*>(OrbitalSet)); HasCoreOrbs=bcastSortBands(NumDistinctOrbitals,myComm->rank()==0); SPOSetBase* bspline_zd=spline_reader->create_spline_set(spinSet,OrbitalSet); delete spline_reader; if(bspline_zd) SPOSetMap[aset] = bspline_zd; return bspline_zd; } else { EinsplineSetExtended<complex<double> > *restrict orbitalSet = dynamic_cast<EinsplineSetExtended<complex<double> >*>(OrbitalSet); if (Format == ESHDF) ReadBands_ESHDF(spinSet,orbitalSet); else ReadBands(spinSet, orbitalSet); } } app_log() << "TIMER EinsplineSetBuilder::ReadBands " << mytimer.elapsed() << endl; } #ifndef QMC_COMPLEX if (myComm->rank()==0 && OrbitalSet->MuffinTins.size() > 0) { FILE *fout = fopen ("TestMuffins.dat", "w"); Vector<double> phi(numOrbs), lapl(numOrbs); Vector<PosType> grad(numOrbs); ParticleSet P; P.R.resize(6); for (int i=0; i<P.R.size(); i++) P.R[i] = PosType (0.0, 0.0, 0.0); PosType N = 0.25*PrimCell.a(0) + 0.25*PrimCell.a(1) + 0.25*PrimCell.a(2); for (double x=-1.0; x<=1.0; x+=0.0000500113412) { // for (double x=-0.003; x<=0.003; x+=0.0000011329343481381) { P.R[0] = x * (PrimCell.a(0) + 0.914*PrimCell.a(1) + 0.781413*PrimCell.a(2)); double r = std::sqrt(dot(P.R[0], P.R[0])); double rN = std::sqrt(dot(P.R[0]-N, P.R[0]-N)); OrbitalSet->evaluate(P, 0, phi, grad, lapl); // OrbitalSet->evaluate(P, 0, phi); fprintf (fout, "%1.12e ", r*x/std::fabs(x)); for (int j=0; j<numOrbs; j++) { double gmag = std::sqrt(dot(grad[j],grad[j])); fprintf (fout, "%16.12e ", /*phi[j]*phi[j]**/(-5.0/r -0.5*lapl[j]/phi[j])); // double E = -5.0/r -0.5*lapl[j]/phi[j]; fprintf (fout, "%16.12e ", phi[j]); fprintf (fout, "%16.12e ", gmag); } fprintf (fout, "\n"); } fclose(fout); } #endif SPOSetMap[aset] = OrbitalSet; if (sourceName.size() && (ParticleSets.find(sourceName) == ParticleSets.end())) { app_log() << " EinsplineSetBuilder creates a ParticleSet " << sourceName << endl; ParticleSet* ions=new ParticleSet; ions->Lattice=TargetPtcl.Lattice; ESHDFIonsParser ap(*ions,H5FileID,myComm); ap.put(XMLRoot); ap.expand(TileMatrix); ions->setName(sourceName); ParticleSets[sourceName]=ions; //overwrite the lattice and assign random if(TargetPtcl.Lattice.SuperCellEnum) { TargetPtcl.Lattice=ions->Lattice; makeUniformRandom(TargetPtcl.R); TargetPtcl.R.setUnit(PosUnit::LatticeUnit); TargetPtcl.convert2Cart(TargetPtcl.R); TargetPtcl.createSK(); } } #ifdef QMC_CUDA if (useGPU == "yes" || useGPU == "1") { app_log() << "Initializing GPU data structures.\n"; OrbitalSet->initGPU(); } #endif return OrbitalSet; }
void GamesXmlParser::getGaussianCenters(vector<xmlNodePtr>& bPtrList) { //if(bPtrList.size() != aPtrList.size()) gBound.push_back(0); int offset=0; double zeta,c; SizeOfBasisSet=0; for(int i=0; i<bPtrList.size(); i++) { string p; int ng_tot=0,ng; xmlNodePtr cur=bPtrList[i]->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "PSHELL") { ng_tot++; xmlNodePtr cur1=cur->children; int gshellType=1; while(cur1!= NULL) { string tname((const char*)cur1->name); if(tname == "PTYPE") { putContent(p,cur1); if(p == "S") { gshellType=1; SizeOfBasisSet+=1; } else if(p == "P") { gshellType=3; SizeOfBasisSet+=3; } else if(p == "D") { gshellType=4; SizeOfBasisSet+=5; } gShell.push_back(gshellType); } else if(tname == "PNGAUSS") { putContent(ng,cur1); gNumber.push_back(ng); // ng_tot+=ng; } else if(tname == "PGAUSSIAN") { xmlNodePtr cur2=cur1->children; while(cur2 != NULL) { string cname2((const char*)cur2->name); if(cname2 == "PZETA") { putContent(zeta,cur2); gExp.push_back(zeta); } else if(cname2 == "PCONE") { putContent(c,cur2); gC0.push_back(c); } cur2=cur2->next; } cout << "zeta,c " << zeta << " " << c << endl; } cur1=cur1->next; } } cur=cur->next; } offset+=ng_tot; gBound.push_back(offset); } cout << "Bound of gauassians " << endl; std::copy(gBound.begin(), gBound.end(),ostream_iterator<int>(cout, " ")); cout << endl; cout << "Number of shell type " << endl; std::copy(gShell.begin(), gShell.end(),ostream_iterator<int>(cout, " ")); cout << endl; cout << "Number of gaussians per shell " << endl; std::copy(gNumber.begin(), gNumber.end(),ostream_iterator<int>(cout, " ")); cout << endl; gC1.resize(gC0.size(),0.0); }
SPOSetBase* PWOrbitalBuilder::createPW(xmlNodePtr cur, int spinIndex) { int nb=targetPtcl.last(spinIndex)-targetPtcl.first(spinIndex); vector<int> occBand(nb); for(int i=0;i<nb; i++) occBand[i]=i; typedef PWBasis::GIndex_t GIndex_t; GIndex_t nG(1); bool transform2grid=false; cur=cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == "transform") { putContent(nG,cur); transform2grid=true; } else if(cname == "occupation") { string occMode("ground"); int bandoffset(1); OhmmsAttributeSet aAttrib; aAttrib.add(spinIndex,"spindataset"); aAttrib.add(occMode,"mode"); aAttrib.add(bandoffset,"offset"); /* reserved for index offset */ aAttrib.put(cur); if(occMode == "excited") { vector<int> occ; vector<int> deleted, added; putContent(occ,cur); for(int i=0; i<occ.size(); i++) { if(occ[i]<0) deleted.push_back(-occ[i]); else added.push_back(occ[i]); } if(deleted.size() != added.size()) { app_error() << " Numbers of deleted and added bands are not identical." << endl; OHMMS::Controller->abort(); } for(int i=0; i<deleted.size(); i++) { occBand[deleted[i]-bandoffset]=added[i]-bandoffset; } app_log() << " mode=\"excited\" Occupied states: " << endl; std::copy(occBand.begin(),occBand.end(),ostream_iterator<int>(app_log()," ")); app_log() << endl; } } cur=cur->next; } string tname=myParam->getTwistName(); hid_t es_grp_id = H5Gopen(hfileID,myParam->eigTag.c_str()); hid_t twist_grp_id = H5Gopen(es_grp_id,tname.c_str()); //create a single-particle orbital set SPOSetType* psi=new SPOSetType; if(transform2grid) { nb=myParam->numBands; occBand.resize(nb); for(int i=0;i<nb; i++) occBand[i]=i; } //going to take care of occ psi->resize(myBasisSet,nb,true); if(myParam->hasComplexData(hfileID))//input is complex { app_log() << " PW coefficients are complex." << endl; typedef std::vector<complex<RealType> > TempVecType; TempVecType coefs(myBasisSet->inputmap.size()); HDFAttribIO<TempVecType> hdfobj_coefs(coefs); int ib=0; while(ib<nb) { string bname(myParam->getBandName(occBand[ib],spinIndex)); app_log() << " Reading " << myParam->eigTag << "/" << tname <<"/"<< bname << endl; hid_t band_grp_id = H5Gopen(twist_grp_id,bname.c_str()); hdfobj_coefs.read(band_grp_id,myParam->eigvecTag.c_str()); psi->addVector(coefs,ib); H5Gclose(band_grp_id); ++ib; } } else { app_log() << " PW coefficients are real." << endl; typedef std::vector<RealType> TempVecType; TempVecType coefs(myBasisSet->inputmap.size()); HDFAttribIO<TempVecType> hdfobj_coefs(coefs); int ib=0; while(ib<nb) { string bname(myParam->getBandName(occBand[ib],spinIndex)); app_log() << " Reading " << myParam->eigTag << "/" << tname <<"/"<< bname << endl; hid_t band_grp_id = H5Gopen(twist_grp_id,bname.c_str()); hdfobj_coefs.read(band_grp_id,myParam->eigvecTag.c_str()); psi->addVector(coefs,ib); H5Gclose(band_grp_id); ++ib; } } H5Gclose(twist_grp_id); H5Gclose(es_grp_id); #if defined(QMC_COMPLEX) if(transform2grid) { app_warning() << " Going to transform on grid " << endl; transform2GridData(nG,spinIndex,*psi); } #endif return psi; }
bool LRTwoBodyJastrow::put(xmlNodePtr cur, VarRegistry<RealType>& vlist) { if(skRef == 0) { app_error() << " LRTowBodyJastrow should not be used for non periodic systems." << endl; return false; } std::map<int,std::vector<int>*>& kpts_sorted(skRef->KLists.kpts_sorted); Fk_symm.resize(kpts_sorted.size()); bool foundCoeff=false; xmlNodePtr tcur=cur->children; while(tcur != NULL) { string cname((const char*)(tcur->name)); if(cname == "parameter") { const xmlChar* kptr=xmlGetProp(tcur,(const xmlChar *)"name"); const xmlChar* idptr=xmlGetProp(tcur,(const xmlChar *)"id"); if(idptr!= NULL && kptr != NULL) { int ik=atoi((const char*)kptr); if(ik<Fk_symm.size()) { // only accept valid ik RealType x; putContent(x,tcur); Fk_symm[ik]=x; vlist.add((const char*)idptr,Fk_symm.data()+ik); } foundCoeff=true; } } tcur=tcur->next; } Fk.resize(NumKpts); if(foundCoeff) { reset(); } else { std::map<int,std::vector<int>*>::iterator it(kpts_sorted.begin()); int uniqueK=0; while(it != kpts_sorted.end()) { std::vector<int>::iterator vit((*it).second->begin()); int ik=(*vit); Fk_symm[uniqueK]=Fk[ik]=-1.0*handler->Fk[ik]; ++vit; while(vit != (*it).second->end()) { int ik=(*vit); Fk[ik]=-1.0*handler->Fk[ik]; ++vit; } ++it;++uniqueK; } char coeffname[128]; for(int ik=0; ik<Fk_symm.size(); ik++) { sprintf(coeffname,"rpa_k%d",ik); vlist.add(coeffname,Fk_symm.data()+ik); std::ostringstream kname,val; kname << ik; val<<Fk_symm[ik]; xmlNodePtr p_ptr = xmlNewTextChild(cur,NULL,(const xmlChar*)"parameter", (const xmlChar*)val.str().c_str()); xmlNewProp(p_ptr,(const xmlChar*)"id",(const xmlChar*)coeffname); xmlNewProp(p_ptr,(const xmlChar*)"name",(const xmlChar*)kname.str().c_str()); } } app_log() << " Long-range Two-Body Jastrow coefficients " << endl; for(int ikpt=0; ikpt<NumKpts; ikpt++) { app_log() << skRef->KLists.ksq[ikpt] << " " << Fk[ikpt] << endl; } return true; }