bool JABBuilder::createJAB(xmlNodePtr cur, const string& jname) { string corr_tag("correlation"); vector<FN*> jastrow; int ng = 0; ParticleSet* sourcePtcl=0; const xmlChar* s=xmlGetProp(cur,(const xmlChar*)"source"); if (s != NULL) { map<string,ParticleSet*>::iterator pa_it(ptclPool.find((const char*)s)); if (pa_it == ptclPool.end()) return false; sourcePtcl = (*pa_it).second; ng=sourcePtcl->getSpeciesSet().getTotalNum(); for (int i=0; i<ng; i++) jastrow.push_back(0); } cur = cur->xmlChildrenNode; while (cur != NULL) { string cname((const char*)(cur->name)); if (cname == dtable_tag) { string source_name((const char*)(xmlGetProp(cur,(const xmlChar *)"source"))); map<string,ParticleSet*>::iterator pa_it(ptclPool.find(source_name)); if (pa_it == ptclPool.end()) return false; sourcePtcl = (*pa_it).second; ng=sourcePtcl->getSpeciesSet().getTotalNum(); XMLReport("Number of sources " << ng) for (int i=0; i<ng; i++) jastrow.push_back(0); } else if (cname == corr_tag)
/** create Input Analytic function * * \xmlonly * <jastrow name="Jne" * type="Two-Body|One-Body|Polarization|Three-Body-Geminal" * function="pade|pade2|no-cusp" * transform="no|yes" spin="no|yes" * source="ionic system"> * <grid/> * <correlation speciesA="sourceSpecies" speciesB="targetSpecies" type="pade|pade2|no-cusp"> * <parameter name=" ">value<parameter> * </correlation> * </jastrow> * \endxmlonly */ bool NJABBuilder::putInFunc(xmlNodePtr cur) { string corr_tag("correlation"); string jastfunction("pade"); int ng=1; const xmlChar *ftype = xmlGetProp(cur, (const xmlChar *)"function"); if(ftype != NULL) jastfunction = (const char*) ftype; const xmlChar* s=xmlGetProp(cur,(const xmlChar*)"source"); if(s != NULL) { map<string,ParticleSet*>::iterator pa_it(ptclPool.find((const char*)s)); if(pa_it == ptclPool.end()) return false; sourcePtcl = (*pa_it).second; ng=sourcePtcl->getSpeciesSet().getTotalNum(); } int ia=0, ib=0, iab=0; cur = cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == "grid") { gridPtr=cur; //save the pointer } else if(cname == dtable_tag) { string source_name((const char*)(xmlGetProp(cur,(const xmlChar *)"source"))); map<string,ParticleSet*>::iterator pa_it(ptclPool.find(source_name)); if(pa_it == ptclPool.end()) return false; sourcePtcl=(*pa_it).second; ng = sourcePtcl->getSpeciesSet().getTotalNum(); XMLReport("Number of sources " << ng) InFunc.resize(ng,0); } else if(cname ==corr_tag) { if(sourcePtcl==0) return false; string jfunctype(jastfunction); string spA((const char*)(xmlGetProp(cur,(const xmlChar *)"speciesA"))); ftype = xmlGetProp(cur, (const xmlChar *)"type"); if(ftype) { jfunctype=(const char*)ftype; } ia = sourcePtcl->getSpeciesSet().findSpecies(spA); if(!(InFunc[ia])) { InFuncType *j1=createInFunc(jfunctype); InFunc[ia]= j1; app_log() <<" Added Jastrow Correlation ("<<jfunctype << ") between " <<spA<<" and "<<targetPtcl.getName() << endl; } InFunc[ia]->put(cur); InFunc[ia]->addOptimizables(targetPsi.VarList); } cur = cur->next; } // while cur return true; }
bool PadeBuilder::put(xmlNodePtr cur) { const xmlChar* spin=xmlGetProp(cur,(const xmlChar*)"spin"); if(spin != NULL) { string a((const char*)spin); if(a == "yes") IgnoreSpin=false; } string functionOpt("pade"); const xmlChar *ftype = xmlGetProp(cur, (const xmlChar *)"function"); if(ftype != NULL) functionOpt = (const char*) ftype; const xmlChar* s = xmlGetProp(cur, (const xmlChar *)"source"); if(s != NULL) { map<string,ParticleSet*>::iterator pa_it(ptclPool.find((const char*)s)); if(pa_it != ptclPool.end()) { sourcePtcl=(*pa_it).second; } } bool success=false; OrbitalConstraintsBase* control=0; if(functionOpt == "pade") { app_log() << " Pade Jastrow Functions = " << functionOpt << endl; control = new PadeConstraints(IgnoreSpin); } else if(functionOpt == "scaledpade") { app_log() << " Scaled Pade Jastrow Functions = " << functionOpt << endl; control = new ScaledPadeConstraints(IgnoreSpin); } if(control==0) return false; if(!control->put(cur)) { delete control; return false; } ComboOrbital* jcombo=new ComboOrbital(control); OrbitalBase* j2=control->createTwoBody(targetPtcl); jcombo->Psi.push_back(j2); if(sourcePtcl) // add one-body term using Zeff and e-e B { OrbitalBase* j1=control->createOneBody(targetPtcl,*sourcePtcl); if(j1) jcombo->Psi.push_back(j1); } targetPsi.addOrbital(jcombo); return success; }
bool JastrowBuilder::addOneBody(xmlNodePtr cur) { app_log() << " JastrowBuilder::addOneBody "<< endl; if(sourceOpt == targetPtcl.getName()) { app_warning() << " One-Body Jastrow Function needs a source different from " << targetPtcl.getName() << endl; app_warning() << " Exit JastrowBuilder::addOneBody." << endl; return false; } map<string,ParticleSet*>::iterator pa_it(ptclPool.find(sourceOpt)); if(pa_it == ptclPool.end()) { app_warning() << " JastrowBuilder::addOneBody failed. " << sourceOpt << " does not exist" << endl; return false; } ParticleSet* sourcePtcl= (*pa_it).second; if(funcOpt == "any" || funcOpt == "poly") { OrbitalConstraintsBase* control=0; if(funcOpt == "any") control = new AnyConstraints(targetPtcl,targetPsi); else control = new PolyConstraints(targetPtcl,targetPsi,true); control->put(cur); OrbitalBase* j=control->createOneBody(*sourcePtcl); if(j) { control->addOptimizables(targetPsi.VarList); targetPsi.addOrbital(j); Children.push_back(control); return true; } else { delete control; return false; } } else { app_log() << "\n Using JABBuilder for one-body jatrow with analytic functions" << endl; OrbitalBuilderBase* jb = new JABBuilder(targetPtcl,targetPsi,ptclPool); Children.push_back(jb); return jb->put(cur); } }
bool TwoBodyJastrowBuilder::put(xmlNodePtr cur) { string functionOpt("pade"); string transformOpt("no"); string sourceOpt("9NONE"); string spinOpt("yes"); OhmmsAttributeSet oAttrib; oAttrib.add(functionOpt,"function"); oAttrib.add(transformOpt,"transform"); oAttrib.add(sourceOpt,"source"); oAttrib.add(spinOpt,"spin"); oAttrib.put(cur); IgnoreSpin = (spinOpt == "no"); if(sourceOpt[0] != '9') { map<string,ParticleSet*>::iterator pa_it(ptclPool.find(sourceOpt)); if(pa_it != ptclPool.end()) { sourcePtcl=(*pa_it).second; } } bool success=false; OrbitalConstraintsBase* control=0; //@todo automatically set it to yes with PBC bool useSpline= (transformOpt == "yes"); app_log() << " TwoBodyJastrowBuilder for " << functionOpt << endl; if(functionOpt == "pade") { //control = new PadeConstraints(IgnoreSpin); //Transform is ignored. Cutoff function is not too good if(useSpline) { control = new PadeOnGridConstraints(IgnoreSpin); } else { control = new PadeConstraints(IgnoreSpin); } } else if(functionOpt == "scaledpade") { control = new ScaledPadeConstraints(IgnoreSpin); } else if(functionOpt == "rpa") { if(useSpline) { control = new RPAPBCConstraints(IgnoreSpin); } else { control = new RPAConstraints(IgnoreSpin); } } else if(functionOpt == "WM") { control = new WMConstraints(IgnoreSpin); } if(control==0) { //try generic JAABuilder and NJAABuilder OrbitalBuilderBase* jbuilder=0; if(useSpline) { jbuilder = new NJAABuilder(targetPtcl,targetPsi); } else { jbuilder = new JAABuilder(targetPtcl,targetPsi); } return jbuilder->put(cur); } success=control->put(cur); if(!control->put(cur)) { delete control; return false; } ComboOrbital* jcombo=new ComboOrbital(control); control->addTwoBodyPart(targetPtcl, jcombo); if(sourcePtcl) { // add one-body term using Zeff and e-e B OrbitalBase* j1=control->createOneBody(targetPtcl,*sourcePtcl); if(j1) jcombo->Psi.push_back(j1); } control->addOptimizables(targetPsi.VarList); targetPsi.addOrbital(jcombo); return success; }
bool TwoBodyJastrowBuilder::put(xmlNodePtr cur) { myNode=cur; string functionOpt("pade"); string transformOpt("no"); string sourceOpt(targetPtcl.getName()); string spinOpt("yes"); OhmmsAttributeSet oAttrib; oAttrib.add(functionOpt,"function"); oAttrib.add(transformOpt,"transform"); oAttrib.add(sourceOpt,"source"); oAttrib.add(spinOpt,"spin"); oAttrib.put(cur); bool IgnoreSpin = (spinOpt == "no"); bool success=false; OrbitalConstraintsBase* control=0; //@todo automatically set it to yes with PBC bool useSpline= (transformOpt == "yes"); app_log() << " TwoBodyJastrowBuilder for " << functionOpt << endl; if(functionOpt == "pade") { app_log() << " Using analytic Pade Jastrow Functor " <<endl; control = new PadeConstraints(targetPtcl,targetPsi,IgnoreSpin); } else if(functionOpt == "scaledpade") { app_log() << " Using analytic Scaled Pade Jastrow Functor " <<endl; control = new ScaledPadeConstraints(targetPtcl,targetPsi,IgnoreSpin); } else if(functionOpt == "rpa") { if(useSpline) control = new RPAPBCConstraints(targetPtcl,targetPsi,IgnoreSpin); else control = new RPAConstraints(targetPtcl,targetPsi,IgnoreSpin); } else //known analytic function { OrbitalBuilderBase* jbuilder=0; jbuilder = new JAABuilder(targetPtcl,targetPsi); Children.push_back(jbuilder); return jbuilder->put(cur); } success=control->put(cur); if(!success) { delete control; return false; } ComboOrbital* jcombo=new ComboOrbital(control); control->addTwoBodyPart(jcombo); if(sourceOpt != targetPtcl.getName()) { app_log() << " Adding one-body Jastrow function dependent upon two-body " << functionOpt << endl; map<string,ParticleSet*>::iterator pa_it(ptclPool.find(sourceOpt)); if(pa_it == ptclPool.end()) { return false; } ParticleSet* sourcePtcl= sourcePtcl=(*pa_it).second; OrbitalBase* j1=control->createOneBody(*sourcePtcl); if(j1) jcombo->Psi.push_back(j1); } control->addOptimizables(targetPsi.VarList); targetPsi.addOrbital(jcombo); return success; }
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; }
bool JastrowBuilder::addTwoBody(xmlNodePtr cur) { app_log() << " JastrowBuilder::addTwoBody "<< endl; bool success=false; bool useSpline = (targetPtcl.Lattice.BoxBConds[0] && transformOpt == "yes"); bool ignoreSpin = (spinOpt == "no"); OrbitalConstraintsBase* control=0; if(funcOpt == "any") { app_log() << " Using generic Jastrow Function Builder " <<endl; control=new AnyConstraints(targetPtcl,targetPsi); } else if(funcOpt == "pade") { app_log() << " Using analytic Pade Jastrow Functor " <<endl; control = new PadeConstraints(targetPtcl,targetPsi,ignoreSpin); } else if(funcOpt == "rpa") { if(targetPtcl.Lattice.SuperCellEnum == SUPERCELL_OPEN) { app_warning() << " RPA is requested for an open system. Please choose other functors." << endl; return false; } else control = new RPAPBCConstraints(targetPtcl,targetPsi,ignoreSpin); } else if(funcOpt == "poly") { app_log() << " Using analytic Polynomial expansion Jastrow Functor " <<endl; control = new PolyConstraints(targetPtcl,targetPsi,ignoreSpin); } else if(funcOpt == "scaledpade") { app_log() << " Using analytic Scaled Pade Jastrow Functor " <<endl; control = new ScaledPadeConstraints(targetPtcl,targetPsi,ignoreSpin); } else //known analytic function { OrbitalBuilderBase* jbuilder=0; jbuilder = new JAABuilder(targetPtcl,targetPsi); Children.push_back(jbuilder); return jbuilder->put(cur); } success=control->put(cur); if(!success) { app_error() << " Failed to buld " << nameOpt << " Jastrow function " << endl; delete control; return false; } OrbitalBase* j2=control->createTwoBody(); if(j2== 0) { app_error() << " JastrowBuilder::addTwoBody failed to create a two body Jastrow" << endl; delete control; } enum {MULTIPLE=0, LONGRANGE, ONEBODY, TWOBODY, THREEBODY, FOURBODY}; if(control->JComponent[MULTIPLE]) { //create a combo orbital ComboOrbital* jcombo=new ComboOrbital(control); jcombo->Psi.push_back(j2); if(control->JComponent[ONEBODY] && sourceOpt != targetPtcl.getName()) { app_log() << " Adding one-body Jastrow function dependent upon two-body " << funcOpt << endl; map<string,ParticleSet*>::iterator pa_it(ptclPool.find(sourceOpt)); if(pa_it != ptclPool.end()) { OrbitalBase* j1=control->createOneBody(*((*pa_it).second)); if(j1) jcombo->Psi.push_back(j1); } } if(control->JComponent[LONGRANGE]) { app_log() << " Adding long-range component of " << funcOpt << " Jastrow function "<< endl; control->addExtra2ComboOrbital(jcombo); } targetPsi.addOrbital(jcombo); } else { targetPsi.addOrbital(j2); } control->addOptimizables(targetPsi.VarList); Children.push_back(control); return success; }