Exemplo n.º 1
0
  /** Parses the xml input file for parameter definitions for the wavefunction optimization.
   * @param q current xmlNode 
   * @return true if successful
   */
  bool
  QMCOptimize::put(xmlNodePtr q) {

    string vmcMove("pbyp");
    string useGPU("no");
    OhmmsAttributeSet oAttrib;
    oAttrib.add(vmcMove,"move");    
    oAttrib.add(useGPU,"gpu");
    oAttrib.put(q);

    xmlNodePtr qsave=q;
    xmlNodePtr cur=qsave->children;
    int pid=OHMMS::Controller->rank();
    while(cur != NULL) {
      string cname((const char*)(cur->name));
      if(cname == "mcwalkerset") {
        mcwalkerNodePtr.push_back(cur);
      } else if(cname == "optimizer") {
        xmlChar* att= xmlGetProp(cur,(const xmlChar*)"method");
        if(att) { optmethod = (const char*)att; }
        optNode=cur;
      } else if(cname == "optimize") {
        xmlChar* att= xmlGetProp(cur,(const xmlChar*)"method");
        if(att) { optmethod = (const char*)att; }
      }
      cur=cur->next;
    }  

    //no walkers exist, add 10
    if(W.getActiveWalkers() == 0) addWalkers(omp_get_max_threads()); 

    NumOfVMCWalkers=W.getActiveWalkers();

    //create VMC engine
    if(vmcEngine ==0) {
#if defined (QMC_CUDA)
      if (useGPU == "yes")
	vmcEngine = new VMCcuda(W,Psi,H);
      else
#endif

#if defined(ENABLE_OPENMP)
      if(omp_get_max_threads()>1)
        vmcEngine = new VMCSingleOMP(W,Psi,H,hamPool);
      else
#endif
        vmcEngine = new VMCSingle(W,Psi,H);
      vmcEngine->setUpdateMode(vmcMove[0] == 'p');
      vmcEngine->initCommunicator(myComm);
    }

    vmcEngine->setStatus(RootName,h5FileRoot,AppendRun);
    vmcEngine->process(qsave);

    if(optSolver ==0)
    {
      if(optmethod == "anneal") 
      {
        app_log() << " Annealing optimization using DampedDynamics"<<endl;
        optSolver = new DampedDynamics<RealType>;
      } 
      else
      {
        app_log() << " Conjugate-gradient optimization using CGOptimization"<<endl;
        optSolver = new CGOptimization<RealType>;
      }
      //set the stream
      optSolver->setOstream(&app_log());
    }

    if(optNode == NULL) 
      optSolver->put(qmcNode);
    else
      optSolver->put(optNode);

    bool success=true;
    if(optTarget == 0) {
#if defined (QMC_CUDA)
      if (useGPU == "yes")
	optTarget = new QMCCostFunctionCUDA(W,Psi,H,hamPool);
      else
#endif
#if defined(ENABLE_OPENMP)
      if(omp_get_max_threads()>1)
      {
        optTarget = new QMCCostFunctionOMP(W,Psi,H,hamPool);
      }
      else
#endif
        optTarget = new QMCCostFunctionSingle(W,Psi,H);

      optTarget->setStream(&app_log());
      success=optTarget->put(q);
    }
    return success;
  }
Exemplo n.º 2
0
/** Parses the xml input file for parameter definitions for the wavefunction optimization.
* @param q current xmlNode
* @return true if successful
*/
bool
QMCSHLinearOptimize::put(xmlNodePtr q)
{
  string useGPU("no");
  string vmcMove("pbyp");
  OhmmsAttributeSet oAttrib;
//     oAttrib.add(useGPU,"gpu");
  oAttrib.add(vmcMove,"move");
  oAttrib.put(q);
  optNode=q;
  xmlNodePtr cur=optNode->children;
  int pid=OHMMS::Controller->rank();
//     while (cur != NULL)
//     {
//         string cname((const char*)(cur->name));
//         if (cname == "mcwalkerset")
//         {
//             mcwalkerNodePtr.push_back(cur);
//         }
//         cur=cur->next;
//     }
  //no walkers exist, add 10
  if (W.getActiveWalkers() == 0)
    addWalkers(omp_get_max_threads());
  NumOfVMCWalkers=W.getActiveWalkers();
  //create VMC engine
  if ((vmcEngine ==0)||(dmcEngine ==0))
  {
#if defined (QMC_CUDA)
    if (useGPU == "yes")
      vmcEngine = new VMCcuda(W,Psi,H,psiPool);
    else
#endif
      vmcEngine = dmcEngine = new DMCOMPOPT(W,Psi,H,hamPool,psiPool);
    dmcEngine->setUpdateMode(vmcMove[0] == 'p');
    dmcEngine->initCommunicator(myComm);
  }
//     app_log()<<RootName<<"   "<<h5FileRoot<<endl;
  dmcEngine->setStatus(RootName,h5FileRoot,AppendRun);
  dmcEngine->process(optNode);
//     dmcEngine->setBranchEngine(branchEngine);
  bool success=true;
  if (optTarget == 0)
  {
#if defined (QMC_CUDA)
    if (useGPU == "yes")
      optTarget = new QMCCostFunctionCUDA(W,Psi,H,hamPool);
    else
#endif
// #if defined(ENABLE_OPENMP)
//             if (omp_get_max_threads()>1)
//             {
//                 optTarget = new QMCCostFunctionOMP(W,Psi,H,hamPool);
//             }
//             else
// #endif
//                 optTarget = new QMCCostFunctionSingle(W,Psi,H);
      optTarget = new QMCCostFunctionOMP(W,Psi,H,hamPool);
    optTarget->setneedGrads(false);
    optTarget->setStream(&app_log());
    optTarget->setDMC();
    success=optTarget->put(optNode);
  }
  return success;
}
Exemplo n.º 3
0
bool BsplineJastrowBuilder::createOneBodyJastrow(xmlNodePtr cur)
{
    ReportEngine PRE(ClassName,"createOneBodyJastrow(xmlNodePtr)");
    string j1name("J1");
    {
        OhmmsAttributeSet a;
        a.add(j1name,"name");
        a.put(cur);
    }
    int taskid=targetPsi.getGroupID();//(targetPsi.is_manager())?targetPsi.getGroupID():-1;
    OBJT* J1 =new OBJT(*sourcePtcl,targetPtcl);
    DOBJT *dJ1 = new DOBJT(*sourcePtcl, targetPtcl);
    xmlNodePtr kids = cur->xmlChildrenNode;
    // Find the number of the source species
    SpeciesSet &sSet = sourcePtcl->getSpeciesSet();
    SpeciesSet &tSet = targetPtcl.getSpeciesSet();
    int numSpecies = sSet.getTotalNum();
    bool success=false;
    bool Opt(false);
    while (kids != NULL)
    {
        std::string kidsname = (char*)kids->name;
        if (kidsname == "correlation")
        {
            RealType cusp=0.0;
            string speciesA;
            string speciesB;
            OhmmsAttributeSet rAttrib;
            rAttrib.add(speciesA,"elementType");
            rAttrib.add(speciesA,"speciesA");
            rAttrib.add(speciesB,"speciesB");
            rAttrib.add(cusp,"cusp");
            rAttrib.put(kids);
            BsplineFunctor<RealType> *functor = new BsplineFunctor<RealType>(cusp);
            functor->elementType = speciesA;
            int ig = sSet.findSpecies (speciesA);
            functor->cutoff_radius = sourcePtcl->Lattice.WignerSeitzRadius;
            int jg=-1;
            if(speciesB.size())
                jg=tSet.findSpecies(speciesB);
            if (ig < numSpecies)
            {
                //ignore
                functor->put (kids);
                if (functor->cutoff_radius < 1.0e-6)
                {
                    app_log()  << "  BsplineFunction rcut is currently zero.\n"
                               << "  Setting to Wigner-Seitz radius = "
                               << sourcePtcl->Lattice.WignerSeitzRadius << endl;
                    functor->cutoff_radius = sourcePtcl->Lattice.WignerSeitzRadius;
                    functor->reset();
                }
                J1->addFunc (ig,functor,jg);
                success = true;
                dJ1->addFunc(ig,functor,jg);
                Opt=(!functor->notOpt or Opt);
                if(qmc_common.io_node)
                {
                    char fname[128];
                    if(qmc_common.mpi_groups>1)
                    {
                        if(speciesB.size())
                            sprintf(fname,"%s.%s%s.g%03d.dat",j1name.c_str(),speciesA.c_str(),speciesB.c_str(),taskid);
                        else
                            sprintf(fname,"%s.%s.g%03d.dat",j1name.c_str(),speciesA.c_str(),taskid);
                    }
                    else
                    {
                        if(speciesB.size())
                            sprintf(fname,"%s.%s%s.dat",j1name.c_str(),speciesA.c_str(),speciesB.c_str());
                        else
                            sprintf(fname,"%s.%s.dat",j1name.c_str(),speciesA.c_str());
                    }
                    functor->setReportLevel(ReportLevel,fname);
                    functor->print();
                }
            }
        }
        kids = kids->next;
    }
    if(success)
    {
        J1->dPsi=dJ1;
        targetPsi.addOrbital(J1,"J1_bspline");
        J1->setOptimizable(Opt);
        return true;
    }
    else
    {
        PRE.warning("BsplineJastrowBuilder failed to add an One-Body Jastrow.");
        delete J1;
        delete dJ1;
        return false;
    }
}
Exemplo n.º 4
0
  ParticleSet* ParticleSetPool::createESParticleSet(xmlNodePtr cur, const string& target)
  {
    TinyVector<int,OHMMS_DIM> tilefactor;
    Tensor<int,OHMMS_DIM> tilematrix(1,0,0,0,1,0,0,0,1);
    double lr_cut=10;
    string h5name;
    string source("i");
    string bc("p p p");

    OhmmsAttributeSet attribs;
    attribs.add(h5name, "href");
    attribs.add(tilefactor, "tile");
    attribs.add(tilematrix, "tilematrix");
    attribs.add(source, "source");
    attribs.add(bc, "bconds");
    attribs.add(lr_cut, "LR_dim_cutoff");
    attribs.put(cur);

    ParticleSet* ions=getParticleSet(source);
    if(ions==0)
    {
      ions=new MCWalkerConfiguration;
      ions->setName(source);
    }

    //set the boundary condition
    ions->Lattice.LR_dim_cutoff=lr_cut;
    std::istringstream  is(bc);
    char c;
    int idim=0;
    while(!is.eof() && idim<OHMMS_DIM) 
    { 
      if(is>>c) ions->Lattice.BoxBConds[idim++]=(c=='p');
    }
    
    //initialize ions from hdf5
    hid_t h5=-1;
    if(myComm->rank()==0)
      h5 = H5Fopen(h5name.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
    ESHDFIonsParser ap(*ions,h5,myComm);
    ap.put(cur);
    ap.expand(tilematrix);
    if(h5>-1) H5Fclose(h5);

    //failed to initialize the ions
    if(ions->getTotalNum() == 0) return 0;

    typedef ParticleSet::SingleParticleIndex_t SingleParticleIndex_t;
    vector<SingleParticleIndex_t> grid(OHMMS_DIM,SingleParticleIndex_t(1));
    ions->Lattice.reset();
    ions->Lattice.makeGrid(grid);

    if(SimulationCell==0)
    {
      SimulationCell = new ParticleSet::ParticleLayout_t(ions->Lattice);
    }

    //create the electrons
    MCWalkerConfiguration* qp = new MCWalkerConfiguration;
    qp->setName(target);
    qp->Lattice.copy(ions->Lattice);

    //qp->Lattice.reset();
    //qp->Lattice.makeGrid(grid);

    app_log() << "  Simulation cell radius = " << qp->Lattice.SimulationCellRadius << endl;
    app_log() << "  Wigner-Seitz    radius = " << qp->Lattice.WignerSeitzRadius    << endl;
    SimulationCell->print(app_log());

    myPool[target]=qp;
    myPool[source]=ions;
    //addParticleSet(qp);
    //addParticleSet(ions);

    {//get the number of electrons per spin
      vector<int> num_spin;
      xmlNodePtr cur1=cur->children;
      while(cur1!=NULL)
      {
        string cname1((const char*)cur1->name);
        if(cname1 == OrbitalBuilderBase::sd_tag)
        {
          num_spin.clear();
          xmlNodePtr cur2=cur1->children;
          while(cur2!=NULL)
          {
            string cname2((const char*)cur2->name);
            if(cname2 == OrbitalBuilderBase::det_tag)
            {
              int n=0;
              OhmmsAttributeSet a;
              a.add(n,"size");
              a.put(cur2);
              if(num_spin.size()<2) num_spin.push_back(n);
            }
            cur2=cur2->next;
          }
        }
        cur1=cur1->next;
      }
      //create species
      SpeciesSet& species=qp->getSpeciesSet();
      //add up and down
      species.addSpecies("u");
      if(num_spin.size()>1) species.addSpecies("d");
      int chid=species.addAttribute("charge");
      for(int i=0; i<num_spin.size(); ++i) species(chid,i)=-1.0;
      int mid=species.addAttribute("membersize");
      for(int i=0; i<num_spin.size(); ++i) species(mid,i)=num_spin[i];
      mid=species.addAttribute("mass");
      for(int i=0; i<num_spin.size(); ++i) species(mid,i)=1.0;
      qp->create(num_spin);
    }
    //name it with the target
    qp->setName(target);

    //assign non-trivial positions for the quanmtum particles
    if(qp->Lattice.SuperCellEnum)
    {
      makeUniformRandom(qp->R);
      qp->R.setUnit(PosUnit::LatticeUnit);
      qp->convert2Cart(qp->R);
      qp->createSK();
    }
    else
    {
      InitMolecularSystem mole(this);
      if(ions->getTotalNum()>1)
        mole.initMolecule(ions,qp);
      else
        mole.initAtom(ions,qp);
    }

    //for(int i=0; i<qp->getTotalNum(); ++i)
    //  cout << qp->GroupID[i] << " " << qp->R[i] << endl;

    if(qp->getTotalNum() == 0 || ions->getTotalNum() == 0)
    {
      delete qp;
      delete ions;
      APP_ABORT("ParticleSetPool failed to create particlesets for the electron structure calculation");
      return 0;
    }
    return qp;
  }
Exemplo n.º 5
0
bool ForwardWalking::putSpecial(xmlNodePtr cur, QMCHamiltonian& h, ParticleSet& P)
{
  FirstHamiltonian = h.startIndex();
  nObservables=0;
  nValues=0;
  blockT=1;
  //       OhmmsAttributeSet attrib;
  //       attrib.add(blockT,"blockSize");
  //       attrib.put(cur);
  xmlNodePtr tcur = cur->children;
  while(tcur != NULL)
  {
    string cname((const char*)tcur->name);
    if(cname == "Observable")
    {
      string tagName("none");
      int Hindex(-100);
      int blockSeries(0);
      int blockFreq(0);
      OhmmsAttributeSet Tattrib;
      Tattrib.add(tagName,"name");
      Tattrib.add(blockSeries,"max");
      Tattrib.add(blockFreq,"frequency");
      Tattrib.put(tcur);
      if (tagName.find("*")==string::npos)
      {
        //Single Observable case
        int numProps = P.PropertyList.Names.size();
        Hindex = h.getObservable(tagName)+NUMPROPERTIES;
        if(tagName=="LocalPotential")
        {
          Hindex=LOCALPOTENTIAL ;
          tagName="LocPot";
        }
        else
          if(tagName=="LocalEnergy")
          {
            Hindex=LOCALENERGY ;
            tagName="LocEn";
          }
          else
            if (Hindex==(NUMPROPERTIES-1))
            {
              app_log()<<"Not a valid H element("<<Hindex<<") Valid names are:";
              for (int jk=0; jk<h.sizeOfObservables(); jk++)
                app_log()<<"  "<<h.getObservableName(jk);
              app_log()<<endl;
              exit(-1);
            }
        Names.push_back(tagName);
        Hindices.push_back( Hindex);
        app_log()<<" Hamiltonian Element "<<tagName<<" was found at "<< Hindex<<endl;
        int numT=blockSeries/blockFreq ;
        nObservables+=1;
        nValues+=numT;
        app_log()<<"   "<<numT<<" values will be calculated every "<<blockFreq<<"*tau H^-1"<<endl;
        vector<int> pms(3);
        pms[0]=blockFreq;
        pms[1]=numT;
        pms[2]=blockSeries+2;
        walkerLengths.push_back(pms);
        int maxWsize=blockSeries+2;
        int pindx = P.addPropertyHistory(maxWsize);
        // summed values.
        //         P.addPropertyHistory(numT);
        Pindices.push_back(pindx);
      }
      else
      {
        bool FOUNDH(false);
        // 	    Multiple observables for this tag
        int found=tagName.rfind("*");
        tagName.replace (found,1,"");
        int numProps = P.PropertyList.Names.size();
        for(int j=0; j<h.sizeOfObservables(); j++)
        {
          string Hname = h.getObservableName(j);
          if (Hname.find(tagName) != string::npos)
          {
            //               vector<int> Parameters;
            //               if(blockSeries==0)
            //                 putContent(Parameters,tcur);
            //               else
            //                 for( int pl=blockFreq;pl<=blockSeries;pl+=blockFreq) Parameters.push_back(pl);
            FOUNDH=true;
            app_log()<<" Hamiltonian Element "<<Hname<<" was found at "<< j<<endl;
            Names.push_back(Hname);
            Hindex = j+NUMPROPERTIES;
            Hindices.push_back( Hindex);
            int numT=blockSeries/blockFreq ;
            nObservables+=1;
            nValues+=numT;
            app_log()<<"   "<<numT<<" values will be calculated every "<<blockFreq<<"*tau H^-1"<<endl;
            vector<int> pms(3);
            pms[0]=blockFreq;
            pms[1]=numT;
            pms[2]=blockSeries+2;
            walkerLengths.push_back(pms);
            int maxWsize=blockSeries+2;
            int pindx = P.addPropertyHistory(maxWsize);
            Pindices.push_back(pindx);
          }
        }
        //handle FOUNDH
        if (FOUNDH)
        {
          nObservables+=1;
        }
        else
        {
          app_log()<<"Not a valid H element("<<Hindex<<") Valid names are:";
          for (int jk=0; jk<h.sizeOfObservables(); jk++)
            app_log()<<"  "<<h.getObservableName(jk);
          app_log()<<endl;
          APP_ABORT("ForwardWalking::put");
        }
      }
    }
    tcur = tcur->next;
  }
  app_log()<<"Total number of observables calculated:"<<nObservables<<endl;
  app_log()<<"Total number of values calculated:"<<nValues<<endl;
  Values.resize(nValues);
  return true;
}
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;
}
Exemplo n.º 7
0
  /** Create a two-body Jatrow function with a template 
   *@param cur the current xmlNode 
   *@param dummy null pointer used to identify FN
   *
   *The template class JeeType is a functor which handles the
   *evaluation of the function value, gradients and laplacians using
   *distance tables. This is a specialized builder function for
   *spin-dependent Jastrow function,e.g., for electrons, two functions
   *are created for uu(dd) and ud(du).
   */
  template<class FN> bool JAABuilder::createJAA(xmlNodePtr cur, const string& jname) 
  {

    string corr_tag("correlation");
    int ng = targetPtcl.groups();

    int ia=0, ib=0, iab=0;
    xmlNodePtr gridPtr=NULL;
    cur = cur->children;
    const SpeciesSet& species(targetPtcl.getSpeciesSet());
    typedef TwoBodyJastrowOrbital<FN> JeeType;
    JeeType *J2 = new JeeType(targetPtcl);
    typedef DiffTwoBodyJastrowOrbital<FN> dJ2Type;
    dJ2Type *dJ2 = new dJ2Type(targetPtcl);

    RealType rc=targetPtcl.Lattice.WignerSeitzRadius;
    int pairs=0;
    while(cur != NULL) {
      string cname((const char*)(cur->name));
      if(cname == corr_tag) 
      {
        string spA("u");
        string spB("u");
        OhmmsAttributeSet rAttrib;
        rAttrib.add(spA, "speciesA"); rAttrib.add(spA, "species1");
        rAttrib.add(spB, "speciesB"); rAttrib.add(spB, "species2");
        rAttrib.put(cur);
        if(spA==targetPsi.getName()) //could have used the particle name
        {
          spA=species.speciesName[0];
          spB=species.speciesName[0];
        }
        int ia = species.findSpecies(spA);
        int ib = species.findSpecies(spB);
        if(ia==species.size() || ia == species.size())
        {
          APP_ABORT("JAABuilder::createJAA is trying to use invalid species");
        }
        string pairID=spA+spB;
        FN *j= new FN;
        j->cutoff_radius=rc;
        j->put(cur);
        J2->addFunc(pairID,ia,ib,j);
	dJ2->addFunc(pairID,ia,ib,j);
        ++pairs;
      }
      cur = cur->next;
    } // while cur

    if(pairs)
    {
      J2->dPsi=dJ2;
      string j2name="J2_"+jname;
      targetPsi.addOrbital(J2,j2name);
      return true;
    }
    else
    {//clean up and delete the twobody orbitals
      delete J2;
      return false;
    }
  }
Exemplo n.º 8
0
  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;
  }
Exemplo n.º 9
0
bool MomentumEstimator::putSpecial(xmlNodePtr cur, ParticleSet& elns, bool rootNode)
{
    OhmmsAttributeSet pAttrib;
    string hdf5_flag="yes";
    pAttrib.add(hdf5_flag,"hdf5");
    pAttrib.add(M,"samples");
    pAttrib.put(cur);
    hdf5_out = (hdf5_flag=="yes");



    xmlNodePtr kids=cur->children;
    while (kids!=NULL)
    {
        string cname((const char*)(kids->name));
        if (cname=="kpoints")
        {
            string ctype("manual");
            OhmmsAttributeSet pAttrib;
            pAttrib.add(ctype,"mode");
            pAttrib.add(kgrid,"grid");
            pAttrib.put(kids);

            int numqtwists(6*kgrid+3);
            std::vector<int> qk(0);
            mappedQtonofK.resize(numqtwists,qk);
            compQ.resize(numqtwists);

            RealType qn(4.0*M_PI*M_PI*std::pow(Lattice.Volume,-2.0/3.0));
            mappedQnorms.resize(numqtwists,qn*0.5/RealType(M));
            if (twist[0]==0) mappedQnorms[kgrid]=qn/RealType(M);
            if (twist[1]==0) mappedQnorms[3*kgrid+1]=qn/RealType(M);
            if (twist[2]==0) mappedQnorms[5*kgrid+2]=qn/RealType(M);

//             app_log()<<" Jnorm="<<qn<<endl;
            Q.resize(numqtwists);
            for (int i=-kgrid; i<(kgrid+1); i++)
            {
                PosType kpt;
                kpt[0]=i-twist[0];
                kpt[1]=i-twist[1];
                kpt[2]=i-twist[2];
                kpt=Lattice.k_cart(kpt);
                Q[i+kgrid]=abs(kpt[0]);
                Q[i+kgrid+(2*kgrid+1)]=abs(kpt[1]);
                Q[i+kgrid+(4*kgrid+2)]=abs(kpt[2]);
            }

            app_log()<<" Using all k-space points with (nx^2+ny^2+nz^2)^0.5 < "<< kgrid <<" for Momentum Distribution."<<endl;
            app_log()<<"  My twist is:"<<twist[0]<<"  "<<twist[1]<<"  "<<twist[2]<<endl;

            int indx(0);
            for (int i=-kgrid; i<(kgrid+1); i++)
            {
                for (int j=-kgrid; j<(kgrid+1); j++)
                {
                    for (int k=-kgrid; k<(kgrid+1); k++)
                    {
                        if (std::sqrt(i*i+j*j+k*k)<=kgrid)
                        {
                            PosType kpt;
                            kpt[0]=i-twist[0];
                            kpt[1]=j-twist[1];
                            kpt[2]=k-twist[2];

                            //convert to Cartesian: note that 2Pi is multiplied
                            kpt=Lattice.k_cart(kpt);
                            kPoints.push_back(kpt);

                            mappedQtonofK[i+kgrid].push_back(indx);
                            mappedQtonofK[j+kgrid+(2*kgrid+1)].push_back(indx);
                            mappedQtonofK[k+kgrid+(4*kgrid+2)].push_back(indx);
                            indx++;
                        }
                    }
                }
            }
        }

        kids=kids->next;
    }
    if (rootNode)
    {
        std::stringstream sstr;
        int t0=(int)round(100.0*twist[0]);
        int t1=(int)round(100.0*twist[1]);
        int t2=(int)round(100.0*twist[2]);
        sstr<<"Kpoints."<<t0<<"_"<<t1<<"_"<<t2<<".dat";
        ofstream fout(sstr.str().c_str());
        fout.setf(ios::scientific, ios::floatfield);
        fout << "# mag_k        kx           ky            kz " << endl;
        for (int i=0; i<kPoints.size(); i++)
        {
            float khere(std::sqrt(dot(kPoints[i],kPoints[i])));
            fout<<khere<<"   "<<kPoints[i][0]<<"    "<<kPoints[i][1]<<"    "<<kPoints[i][2]
                <<endl;
        }
        fout.close();
        sstr.str("");
        sstr<<"Qpoints."<<t0<<"_"<<t1<<"_"<<t2<<".dat";
        ofstream qout(sstr.str().c_str());
        qout.setf(ios::scientific, ios::floatfield);
        qout << "# mag_q" << endl;
        for (int i=0; i<Q.size(); i++)
        {
            qout<<Q[i]<<endl;
        }
        qout.close();
    }

    nofK.resize(kPoints.size());
    norm_nofK=1.0/RealType(M);

    return true;
}
Exemplo n.º 10
0
bool QMCDriverFactory::setQMCDriver(int curSeries, xmlNodePtr cur)
{
  string curName((const char*)cur->name);
  string update_mode("pbyp");
  string qmc_mode("invalid");
  string multi_tag("no");
  string warp_tag("no");
  string append_tag("no");
#if defined(QMC_CUDA)
  string gpu_tag("yes");
#else
  string gpu_tag("no");
#endif
  string traces_tag("none");
  OhmmsAttributeSet aAttrib;
  aAttrib.add(qmc_mode,"method");
  aAttrib.add(update_mode,"move");
  aAttrib.add(multi_tag,"multiple");
  aAttrib.add(warp_tag,"warp");
  aAttrib.add(append_tag,"append");
  aAttrib.add(gpu_tag,"gpu");
  aAttrib.add(traces_tag,"trace");
  aAttrib.put(cur);
  bitset<QMC_MODE_MAX>  WhatToDo;
  bool append_run =(append_tag == "yes");
  WhatToDo[SPACEWARP_MODE]= (warp_tag == "yes");
  WhatToDo[MULTIPLE_MODE]= (multi_tag == "yes");
  WhatToDo[UPDATE_MODE]= (update_mode == "pbyp");
#if defined(QMC_CUDA)
  WhatToDo[GPU_MODE      ] = (gpu_tag     == "yes");
#endif
  OhmmsInfo::flush();
  QMCRunType newRunType = DUMMY_RUN;
  if(curName != "qmc")
    qmc_mode=curName;
  int nchars=qmc_mode.size();
  if(qmc_mode.find("linear") < nchars)
  {
    if (qmc_mode.find("cslinear") < nchars)
      newRunType=CS_LINEAR_OPTIMIZE_RUN;
    else
      newRunType=LINEAR_OPTIMIZE_RUN;
  }
  else
    if(qmc_mode.find("opt") < nchars)
    {
      newRunType=OPTIMIZE_RUN;
    }
    else
    {
      if(qmc_mode.find("ptcl")<nchars)
        WhatToDo[UPDATE_MODE]=1;
      if(qmc_mode.find("mul")<nchars)
        WhatToDo[MULTIPLE_MODE]=1;
      if(qmc_mode.find("warp")<nchars)
        WhatToDo[SPACEWARP_MODE]=1;
//       if (qmc_mode.find("rmcPbyP")<nchars)
//       {
//         newRunType=RMC_PBYP_RUN;
//       }
//       else
      if(qmc_mode.find("rmc")<nchars)
      {
        newRunType=RMC_RUN;
      }
      else
        if(qmc_mode.find("vmc")<nchars)
        {
          newRunType=VMC_RUN;
        }
        else
          if(qmc_mode.find("dmc")<nchars)
          {
            newRunType=DMC_RUN;
          }
    }
  unsigned long newQmcMode=WhatToDo.to_ulong();
  //initialize to 0
  QMCDriver::BranchEngineType* branchEngine=0;
  if(qmcDriver)
  {
    if( newRunType != curRunType || newQmcMode != curQmcMode)
    {
      if(curRunType == DUMMY_RUN)
      {
        APP_ABORT("QMCDriverFactory::setQMCDriver\n Other qmc sections cannot come after <qmc method=\"test\">.\n");
      }
      //pass to the new driver
      branchEngine=qmcDriver->getBranchEngine();
      delete qmcDriver;
      //set to 0 so that a new driver is created
      qmcDriver = 0;
      //if the current qmc method is different from the previous one, append_run is set to false
      append_run = false;
    }
    else
    {
      app_log() << "  Reusing " << qmcDriver->getEngineName() << endl;
      //         if(curRunType == DMC_RUN)
      qmcDriver->resetComponents(cur);
    }
  }
  if(curSeries == 0)
    append_run = false;
  //add trace information
  bool allow_traces =  traces_tag=="yes"
                       ||(traces_tag=="none"
                          && (newRunType==VMC_RUN || newRunType==DMC_RUN));
  //continue with the existing qmcDriver
  if(qmcDriver)
  {
    qmcDriver->allow_traces = allow_traces;
    return append_run;
  }
  //need to create a qmcDriver
  curRunType = newRunType;
  curQmcMode = newQmcMode;
  curQmcModeBits = WhatToDo;
  //create a driver
  createQMCDriver(cur);
  //initialize QMCDriver::myComm
  qmcDriver->initCommunicator(myComm);
  //branchEngine has to be transferred to a new QMCDriver
  if(branchEngine)
    qmcDriver->setBranchEngine(branchEngine);
  OhmmsInfo::flush();
  qmcDriver->allow_traces = allow_traces;
  return append_run;
}
Exemplo n.º 11
0
  bool SpinDensity::put(xmlNodePtr cur)
  {
    using std::ceil;
    using std::sqrt;
    reset();
    string write_report = "no";
    OhmmsAttributeSet attrib;
    attrib.add(myName,"name");
    attrib.add(write_report,"report");
    attrib.put(cur);

    bool have_dr = false;
    bool have_grid = false;
    bool have_center = false;
    bool have_corner = false;
    bool have_cell = false;

    PosType dr;
    PosType center;
    Tensor<RealType,DIM> axes;

    int test_moves = 0;

    xmlNodePtr element = cur->xmlChildrenNode;
    while(element!=NULL)
    {
      string ename((const char*)element->name);
      if(ename=="parameter")
      {
        string name((const char*)(xmlGetProp(element,(const xmlChar*)"name")));
        if(name=="dr")      
        {
          have_dr = true;
          putContent(dr,element);   
        }
        else if(name=="grid") 
        {
          have_grid = true;
          putContent(grid,element);        
        }
        else if(name=="corner") 
        {
          have_corner = true;
          putContent(corner,element);        
        }
        else if(name=="center") 
        {
          have_center = true;
          putContent(center,element);        
        }
        else if(name=="cell") 
        {
          have_cell = true;
          putContent(axes,element);        
        }
        else if(name=="test_moves") 
          putContent(test_moves,element);        
      }
      element = element->next;
    }

    if(have_dr && have_grid)
    {
      APP_ABORT("SpinDensity::put  dr and grid are provided, this is ambiguous");
    }
    else if(!have_dr && !have_grid)
      APP_ABORT("SpinDensity::put  must provide dr or grid");

    if(have_corner && have_center)
      APP_ABORT("SpinDensity::put  corner and center are provided, this is ambiguous");
    if(have_cell)
    {
      cell.set(axes);
      if(!have_corner && !have_center)
        APP_ABORT("SpinDensity::put  must provide corner or center");
    }
    else
      cell = Ptmp->Lattice;

    if(have_center)
      corner = center-cell.Center;

    if(have_dr)
      for(int d=0;d<DIM;++d)
        grid[d] = (int)ceil(sqrt(dot(cell.Rv[d],cell.Rv[d]))/dr[d]);

    npoints = 1;
    for(int d=0;d<DIM;++d)
      npoints *= grid[d];
    gdims[0] = npoints/grid[0];
    for(int d=1;d<DIM;++d)
      gdims[d] = gdims[d-1]/grid[d];

    if(write_report=="yes")
      report("  ");
    if(test_moves>0)
      test(test_moves,*Ptmp);

    return true;
  }
Exemplo n.º 12
0
  bool 
    ECPComponentBuilder::parseCasino(const std::string& fname, xmlNodePtr cur)
  {

    app_log() << "   Start ECPComponentBuilder::parseCasino" << endl;
    RealType rmax=2.0;
    Llocal=-1;
    Lmax=-1;
    OhmmsAttributeSet aAttrib;
    aAttrib.add(rmax,"cutoff");
    aAttrib.add(Llocal,"l-local");
    aAttrib.add(Lmax,"lmax");
    aAttrib.add(Nrule,"nrule");
    aAttrib.put(cur);
    //const xmlChar* rptr=xmlGetProp(cur,(const xmlChar*)"cutoff");
    //if(rptr != NULL) rmax = atof((const char*)rptr);


    //app_log() << "   Creating a Linear Grid Rmax=" << rmax << endl;
    //const RealType d=5e-4;
    //LinearGrid<RealType>* agrid = new LinearGrid<RealType>;
    //int ng=static_cast<int>(rmax/d)+1;
    //agrid->set(0,rmax,ng);

    ifstream fin(fname.c_str(),ios_base::in);
    if(!fin)
    {
      app_error() << "Could not open file " << fname << endl;
      APP_ABORT("ECPComponentBuilder::parseCasino");
    }      

    if(pp_nonloc==0) pp_nonloc=new NonLocalECPComponent; 

    OhmmsAsciiParser aParser;
    int atomNumber=0;
    int npts=0, idummy;
    string eunits("rydberg");

    app_log() << "    ECPComponentBuilder::parseCasino" <<endl;
    aParser.skiplines(fin,1);//Header
    aParser.skiplines(fin,1);//Atomic number and pseudo-charge
    aParser.getValue(fin,atomNumber,Zeff);
    app_log() << "      Atomic number = " << atomNumber << "  Zeff = " << Zeff << endl;
    aParser.skiplines(fin,1);//Energy units (rydberg/hartree/ev):
    aParser.getValue(fin,eunits);
    app_log() << "      Unit of the potentials = " << eunits << endl;
    RealType Vprefactor = (eunits == "rydberg")?0.5:1.0;

    aParser.skiplines(fin,1);//Angular momentum of local component (0=s,1=p,2=d..)
    aParser.getValue(fin,idummy);
    if(Lmax<0) Lmax=idummy;
    aParser.skiplines(fin,1);//NLRULE override (1) VMC/DMC (2) config gen (0 ==> input/default value)
    aParser.skiplines(fin,1);//0 0, not sure what to do yet
    aParser.skiplines(fin,1);//Number of grid points
    aParser.getValue(fin,npts);
    app_log() << "      Input Grid size = " << npts << endl;
    vector<RealType> temp(npts);

    aParser.skiplines(fin,1);//R(i) in atomic units
    aParser.getValues(fin,temp.begin(),temp.end());

    //create a global grid of numerical type
    grid_global= new NumericalGrid<RealType>(temp);

    Matrix<RealType> vnn(Lmax+1,npts);
    for(int l=0; l<=Lmax; l++)
    {
      aParser.skiplines(fin,1);
      aParser.getValues(fin,vnn[l],vnn[l]+npts);
    }

    vector<int> angList(Lmax+1);
    for(int l=0; l<=Lmax; l++) angList[l]=l;

    // Now, check to see what maximum cutoff should be
    if(vnn.size()>1)
    {
      const double tolerance=1.0e-5;
      double rc_check = grid_global->r(npts-1);
      for (int j=npts-1; j>0; j++) {
        bool closeEnough = true;
        for (int i=0; i<vnn.rows(); i++)
          for (int k=i+1; k<vnn.rows(); k++)
            if (std::fabs(vnn[i][j] - vnn[k][j]) > tolerance)
              closeEnough = false;
        if (!closeEnough) {
          rc_check = grid_global->r(j);
          break;
        }
      }
      app_log() << "  Maxium cutoff for non-local pseudopotentials " << rc_check << endl;
    }

    doBreakUp(angList,vnn,rmax,Vprefactor);

    SetQuadratureRule(Nrule);
    app_log() << "    Non-local pseudopotential parameters" <<endl;
    pp_nonloc->print(app_log());

    return true;
  }
Exemplo n.º 13
0
  bool QMCDriverFactory::setQMCDriver(int curSeries, xmlNodePtr cur) 
  {

    string curName((const char*)cur->name);
    string update_mode("walker");
    string qmc_mode("invalid");
    string multi_tag("no");
    string warp_tag("no");
    string append_tag("no");

    OhmmsAttributeSet aAttrib;
    aAttrib.add(qmc_mode,"method");
    aAttrib.add(update_mode,"move");
    aAttrib.add(multi_tag,"multiple");
    aAttrib.add(warp_tag,"warp");
    aAttrib.add(append_tag,"append");
    aAttrib.put(cur);

    bool append_run =(append_tag == "yes");
    bitset<3>  WhatToDo;
    WhatToDo[SPACEWARP_MODE]= (warp_tag == "yes");
    WhatToDo[MULTIPLE_MODE]= (multi_tag == "yes");
    WhatToDo[UPDATE_MODE]= (update_mode == "pbyp");

    QMCRunType newRunType = DUMMY_RUN;
    if(curName != "qmc") qmc_mode=curName;
    int nchars=qmc_mode.size();
    if(qmc_mode.find("opt") < nchars)
    {
      newRunType=OPTIMIZE_RUN;
    }
    else
    {
      if(qmc_mode.find("vmc")<nchars)
      {
        newRunType=VMC_RUN;
      }
      else if(qmc_mode.find("dmc")<nchars)
      {
        newRunType=DMC_RUN;
      }
      else if(qmc_mode.find("rmc")<nchars)
      {
        newRunType=RMC_RUN;
      }
      if(qmc_mode.find("ptcl")<nchars) WhatToDo[UPDATE_MODE]=1;
      if(qmc_mode.find("mul")<nchars) WhatToDo[MULTIPLE_MODE]=1;
      if(qmc_mode.find("warp")<nchars) WhatToDo[SPACEWARP_MODE]=1;
    } 

    unsigned long newQmcMode=WhatToDo.to_ulong();
   
    //initialize to 0
    QMCDriver::BranchEngineType* branchEngine=0;

    if(qmcDriver) {
      if(newRunType != curRunType || newQmcMode != curQmcMode) {
        //copy the pointer of the BranchEngine 
        branchEngine=qmcDriver->getBranchEngine();
        //remove the qmcDriver
        delete qmcDriver;
        //set to 0 so that a new driver is created
        qmcDriver = 0;
        //if the current qmc method is different from the previous one, append_run is set to false
        append_run = false;
      } else { 
        app_log() << "  Reusing " << qmcDriver->getEngineName() << endl;
      }
    }

    if(curSeries == 0) append_run = false;

    //carryon with the existing qmcDriver
    if(qmcDriver) return append_run;

    //need to create a qmcDriver
    curRunType = newRunType;
    curQmcMode = newQmcMode;
    curQmcModeBits = WhatToDo;
    createQMCDriver(cur);

    if(qmcComm)
      qmcDriver->setCommunicator(qmcComm);
    else
      qmcDriver->setCommunicator(OHMMS::Controller);

    //branchEngine has to be transferred to a new QMCDriver
    if(branchEngine) qmcDriver->setBranchEngine(branchEngine);

    return append_run;
  }
Exemplo n.º 14
0
  bool JastrowBuilder::addThreeBody(xmlNodePtr cur) 
  {
    if(sourceOpt == targetPtcl.getName()) 
    {
      app_warning() << "  Three-Body Jastrow Function needs a source different from " << targetPtcl.getName() << endl;
      app_warning() << "  Exit JastrowBuilder::addOneBody." << endl;
      return false;
    }

    PtclPoolType::iterator pit(ptclPool.find(sourceOpt));
    if(pit == ptclPool.end()) {
      app_error() << "     JastrowBuilder::addThreeBody requires a center. " << sourceOpt << " is invalid " << endl;
      return false;
    }
    app_log() << "  JastrowBuilder::addThreeBody source="<< sourceOpt <<  endl;
    xmlNodePtr basisPtr=NULL;
    xmlNodePtr coeffPtr=NULL;
    cur = cur->xmlChildrenNode;
    string diagOnly("no");
    while(cur != NULL) {
      string cname((const char*)(cur->name));
      if(cname == basisset_tag) 
      {
        basisPtr=cur;
      } 
      else if(cname.find("coeff")<cname.size())
      {
        coeffPtr=cur;
        OhmmsAttributeSet oAttrib;
        oAttrib.add(diagOnly,"diagonal");
        oAttrib.put(cur);
      }
      cur=cur->next;
    }

    if(basisPtr == NULL)
    {
      app_error() << "     JastrowBuilder::addThreeBody exit. Missing <basisset/>"<< endl;
      return false;
    }

    ParticleSet* sourcePtcl=(*pit).second;
    JastrowBasisBuilder* basisBuilder = 
      new JastrowBasisBuilder(targetPtcl,*sourcePtcl,funcOpt,transformOpt == "yes");
    basisBuilder->put(basisPtr);

    if(diagOnly == "yes")
    {
      app_log() << "\n  creating Three-Body Jastrow function using only diagnoal blocks." << endl;
      ThreeBodyBlockSparse* J3 = new ThreeBodyBlockSparse(*sourcePtcl, targetPtcl);
      J3->setBasisSet(basisBuilder->myBasisSet);
      J3->put(coeffPtr,targetPsi.VarList);
      J3->setBlocks(basisBuilder->SizeOfBasisPerCenter);
      targetPsi.addOrbital(J3);
    } 
    else
    {
      app_log() << "\n  creating Three-Body Jastrow function using a complete Geminal matrix." << endl;
      ThreeBodyGeminal* J3 = new ThreeBodyGeminal(*sourcePtcl, targetPtcl);
      J3->setBasisSet(basisBuilder->myBasisSet);
      J3->put(coeffPtr,targetPsi.VarList);
      targetPsi.addOrbital(J3);
    }

    //if(jbuilder)
    //{
    //  jbuilder->put(cur);
    //  Children.push_back(jbuilder);
    //  return true;
    //}
    //    } else if (jasttype == "Three-Body-Pade") {
    //      app_log() << "\n  creating Three-Body-Pade Jastrow function " << endl;
    //      string source_name("i");
    //      const xmlChar* iptr = xmlGetProp(cur, (const xmlChar *)"source");
    //      //if(iptr != NULL) source_name=(const char*)iptr;
    //      PtclPoolType::iterator pit(ptclPool.find(source_name));
    //      if(pit != ptclPool.end()) {
    //        jbuilder = new ThreeBodyPadeBuilder(*targetPtcl,*targetPsi,*((*pit).second));
    //      }
    //    }
    return true;
  }
Exemplo n.º 15
0
  bool RPAJastrow::put(xmlNodePtr cur){
    ReportEngine PRE("RPAJastrow","put");
    xmlNodePtr myNode=xmlCopyNode(cur,1);

    //capture attribute jastrow/@name
    MyName="RPA_Jee";
    string useL="yes";
    string useS="yes";
    rpafunc="breakup";
    
    OhmmsAttributeSet a;
    a.add(MyName,"name");
    a.add(useL,"longrange");
    a.add(useS,"shortrange");
    a.add(rpafunc,"function");
    a.put(cur);

    Rs=-1.0;
    Kc=-1.0;
    string ID_Rs="RPA_rs";
    ParameterSet params;
    params.add(Rs,"rs","double");
    params.add(Kc,"kc","double");
    params.put(cur);

    app_log() <<endl<<"   LongRangeForm is "<<rpafunc<<endl;

    DropLongRange = (useL == "no");
    DropShortRange = (useS=="no");

    app_log() << "    Rs can be optimized using ID=" << ID_Rs << endl;
    RealType tlen = std::pow(3.0/4.0/M_PI*targetPtcl.Lattice.Volume/ static_cast<RealType>(targetPtcl.getTotalNum()) ,1.0/3.0);
    
    if(Rs<0) {
      if(targetPtcl.Lattice.SuperCellEnum) {
        Rs=tlen;
      } else {
        cout<<"  Error finding rs. Is this an open system?!"<<endl;
        Rs=100.0;
      }
    }
    
    //Add Rs to optimizable list
    myVars.insert(ID_Rs,Rs,true);
    
    int indx = targetPtcl.SK->KLists.ksq.size()-1;
    double Kc_max=std::pow(targetPtcl.SK->KLists.ksq[indx],0.5);

    if(Kc<0){ 
      Kc = 2.0*  std::pow(2.25*M_PI,1.0/3.0)/tlen ;
    }
    
    if(Kc>Kc_max){
      Kc=Kc_max;
      app_log() << "    Kc set too high. Resetting to the maximum value"<<endl;
    }

    app_log() << "    RPAJastrowBuilder::addTwoBodyPart Rs = " << Rs <<  "  Kc= " << Kc << endl;
    
    if (rpafunc=="Yukawa" || rpafunc=="breakup"){
      myHandler= new LRHandlerTemp<YukawaBreakup<RealType>,LPQHIBasis>(targetPtcl,Kc);
    } else if (rpafunc=="RPA"){
      myHandler= new LRRPAHandlerTemp<RPABreakup<RealType>,LPQHIBasis>(targetPtcl,Kc);
    } else if (rpafunc=="dYukawa"){
      myHandler= new LRHandlerTemp<DerivYukawaBreakup<RealType>,LPQHIBasis >(targetPtcl,Kc);
    } else if (rpafunc=="dRPA"){
      myHandler= new LRRPAHandlerTemp<DerivRPABreakup<RealType>,LPQHIBasis >(targetPtcl,Kc);
    }
    
    
    myHandler->Breakup(targetPtcl,Rs);
    
    app_log() << "  Maximum K shell " << myHandler->MaxKshell << endl;
    app_log() << "  Number of k vectors " << myHandler->Fk.size() << endl;

    if(!DropLongRange) makeLongRange();
    if(!DropShortRange) makeShortRange();

    return true;
  }
Exemplo n.º 16
0
  bool ECPotentialBuilder::put(xmlNodePtr cur) {

    if(localPot.empty()) {
      int ng(IonConfig.getSpeciesSet().getTotalNum());
      localZeff.resize(ng,1);
      localPot.resize(ng,0);
      nonLocalPot.resize(ng,0);
    }

    string ecpFormat("table");
    string pbc("yes");
    string forces("no");
    OhmmsAttributeSet pAttrib;
    pAttrib.add(ecpFormat,"format");
    pAttrib.add(pbc,"pbc");
    pAttrib.add(forces,"forces");
    pAttrib.put(cur);
    bool doForces = (forces == "yes") || (forces == "true");

    //const xmlChar* t=xmlGetProp(cur,(const xmlChar*)"format");
    //if(t != NULL) {
    //  ecpFormat= (const char*)t;
    //} 

    if(ecpFormat == "xml")  
    {
      useXmlFormat(cur);
    } 
    else 
    {
      useSimpleTableFormat();
    } 

    ///create LocalECPotential
    bool usePBC = 
      !(IonConfig.Lattice.SuperCellEnum == SUPERCELL_OPEN || pbc =="no");
    if(hasLocalPot) {
      if(IonConfig.Lattice.SuperCellEnum == SUPERCELL_OPEN || pbc =="no") 
      {
#ifdef QMC_CUDA
        LocalECPotential_CUDA* apot = 
	  new LocalECPotential_CUDA(IonConfig,targetPtcl);
#else
        LocalECPotential* apot = new LocalECPotential(IonConfig,targetPtcl);
#endif
        for(int i=0; i<localPot.size(); i++) {
          if(localPot[i]) apot->add(i,localPot[i],localZeff[i]);
        }
        targetH.addOperator(apot,"LocalECP");
      }
      else
      {
	if (doForces) 
	  app_log() << "  Will compute forces in CoulombPBCABTemp.\n" << endl;
#ifdef QMC_CUDA
        CoulombPBCAB_CUDA* apot=
	  new CoulombPBCAB_CUDA(IonConfig,targetPtcl, doForces);
#else
	CoulombPBCABTemp* apot =
	  new CoulombPBCABTemp(IonConfig,targetPtcl, doForces);
#endif
        for(int i=0; i<localPot.size(); i++) {
          if(localPot[i]) apot->add(i,localPot[i]);
        }
        targetH.addOperator(apot,"LocalECP");
      }
      //if(IonConfig.Lattice.BoxBConds[0]) {
      //  CoulombPBCABTemp* apot=new CoulombPBCABTemp(IonConfig,targetPtcl);
      //  for(int i=0; i<localPot.size(); i++) {
      //    if(localPot[i]) apot->add(i,localPot[i]);
      //  }
      //  targetH.addOperator(apot,"LocalECP");
      //} else {
      //  LocalECPotential* apot = new LocalECPotential(IonConfig,targetPtcl);
      //  for(int i=0; i<localPot.size(); i++) {
      //    if(localPot[i]) apot->add(i,localPot[i],localZeff[i]);
      //  }
      //  targetH.addOperator(apot,"LocalECP");
      //}
    }

    if(hasNonLocalPot) {
      //resize the sphere
      targetPtcl.resizeSphere(IonConfig.getTotalNum());
      RealType rc2=0.0;
#ifdef QMC_CUDA   
      NonLocalECPotential_CUDA* apot = 
	new NonLocalECPotential_CUDA(IonConfig,targetPtcl,targetPsi,usePBC,doForces);
#else
      NonLocalECPotential* apot = 
	new NonLocalECPotential(IonConfig,targetPtcl,targetPsi, doForces);
#endif

      for(int i=0; i<nonLocalPot.size(); i++) 
      {
        if(nonLocalPot[i]) 
        {
          rc2=std::max(rc2,nonLocalPot[i]->Rmax);
          apot->add(i,nonLocalPot[i]);
        }
      }
      targetPtcl.checkBoundBox(2*rc2);
      targetH.addOperator(apot,"NonLocalECP");

      for(int ic=0; ic<IonConfig.getTotalNum(); ic++) 
      {
        int ig=IonConfig.GroupID[ic];
        if(nonLocalPot[ig]) { 
          if(nonLocalPot[ig]->nknot) targetPtcl.Sphere[ic]->resize(nonLocalPot[ig]->nknot);
        }
      }
    }
    return true;
  }
Exemplo n.º 17
0
  bool AGPDeterminantBuilder::put(xmlNodePtr cur) 
  {
    if(agpDet)
    {
      app_error() << "  AGPDeterminantBuilder::put exits. AGPDeterminant has been already created."
        << endl;
      return false;
    }

    app_log() << "  AGPDeterminantBuilder Creating AGPDeterminant." << endl;
    xmlNodePtr curRoot=cur;
    bool success=true;
    string cname, tname;

    xmlNodePtr bPtr=NULL;
    xmlNodePtr cPtr=NULL;
    xmlNodePtr uPtr=NULL;

    OhmmsAttributeSet oAttrib;
    oAttrib.add(funcOpt,"function");
    oAttrib.add(transformOpt,"transform");
    oAttrib.put(cur);

    cur = cur->children;
    while(cur != NULL) 
    {
      getNodeName(cname,cur);
      if(cname == basisset_tag) 
      {
        bPtr=cur;
      }
      else if(cname.find("coeff")<cname.size())
      {
        cPtr=cur;
      }
      else if(cname.find("un")<cname.size())
      {
        uPtr=cur;
      }
      cur=cur->next;
    }

    if(bPtr == NULL || cPtr == NULL)
    {
      app_error() << "  AGPDeterminantBuilder::put Cannot create AGPDeterminant. " << endl;
      app_error() << "    Missing <basisset/> or <coefficients/>" << endl;
      return false;
    }

    if(myBasisSetFactory == 0)
    {
      myBasisSetFactory = new BasisSetFactory(targetPtcl,targetPsi,ptclPool);
      myBasisSetFactory->createBasisSet(bPtr,curRoot);
    }
// mmorales: this needs to be fixed after changes to BasisSetfactory
//    BasisSetBase<RealType>* myBasisSet=myBasisSetFactory->getBasisSet();
    BasisSetBase<RealType>* myBasisSet; //=myBasisSetFactory->getBasisSet();
    int nup=targetPtcl.first(1), ndown=0;
    if(targetPtcl.groups()>1) ndown = targetPtcl.first(2)-nup;
    myBasisSet->resize(nup+ndown);
    agpDet = new AGPDeterminant(myBasisSet);
    agpDet->resize(nup,ndown);

    //set Lambda: possible to move to AGPDeterminant
    int offset=1;
    xmlNodePtr tcur=cPtr->xmlChildrenNode;
    while(tcur != NULL) {
      if(xmlStrEqual(tcur->name,(const xmlChar*)"lambda")) {
        int i=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"i")));
        int j=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"j")));
        double c=atof((const char*)(xmlGetProp(tcur,(const xmlChar*)"c")));
        agpDet->Lambda(i-offset,j-offset)=c;
        if(i != j) {
          agpDet->Lambda(j-offset,i-offset)=c;
        }
      }
      tcur=tcur->next;
    }

    if(uPtr != NULL)
    {
      tcur=uPtr->xmlChildrenNode;
      while(tcur != NULL) 
      {
        if(xmlStrEqual(tcur->name,(const xmlChar*)"lambda")) {
          int i=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"i")));
          int j=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"j")));
          double c=atof((const char*)(xmlGetProp(tcur,(const xmlChar*)"c")));
          agpDet->LambdaUP(j-offset,i-offset)=c;
        }
        tcur=tcur->next;
      }
      app_log() << "  AGPDeterminantBuilder::put Coefficients for the unpaired electrons " << endl;
      app_log() << agpDet->LambdaUP << endl;
    }

    if(agpDet) targetPsi.addOrbital(agpDet,"AGP");
    return success;
  }
Exemplo n.º 18
0
  int SlaterDetBuilder::putDeterminant(xmlNodePtr cur, int firstIndex) {

    ReportEngine PRE(ClassName,"putDeterminant(xmlNodePtr,int)");

    string basisName("invalid");
    string detname("0"), refname("0");
    OhmmsAttributeSet aAttrib;
    aAttrib.add(basisName,basisset_tag);
    aAttrib.add(detname,"id");
    aAttrib.add(refname,"ref");
    aAttrib.put(cur);

    //index of the last SlaterDeterminant
    int dIndex=DetSet.size();
    if(refname[0] == '0') { //create one and use detname
      if(detname[0] =='0') { //no id is given, assign one
        char newname[8];
        sprintf(newname,"det%d",dIndex);
        detname=newname;
        //add attributed id and ref
        xmlNewProp(cur,(const xmlChar*)"id",(const xmlChar*)newname);
        xmlNewProp(cur,(const xmlChar*)"ref",(const xmlChar*)newname);
      }
      else
      {
        //add reference name
        xmlNewProp(cur,(const xmlChar*)"ref",(const xmlChar*)detname.c_str());
      }
    }

    map<string,SPOSetBasePtr>::iterator lit(SPOSet.find(detname));
    Det_t* adet=0;
    SPOSetBasePtr psi;
    if(lit == SPOSet.end()) {
#if defined(ENABLE_SMARTPOINTER)
      psi.reset(myBasisSetFactory->createSPOSet(cur)); 
#else
      psi = myBasisSetFactory->createSPOSet(cur); 
#endif
      psi->put(cur);
      psi->checkObject();
      SPOSet[detname]=psi;
    } else {
      psi = (*lit).second;
    }

    if(psi->getOrbitalSetSize()) {
      map<string,Det_t*>::iterator dit(DetSet.find(detname));
      if(dit == DetSet.end()) {
        adet = new Det_t(psi,firstIndex);
        adet->set(firstIndex,psi->getOrbitalSetSize());
        DetSet[detname]=adet;
      } else {
        adet = (*dit).second;
      }
      firstIndex += psi->getOrbitalSetSize();
    }

    //only if a determinant is not 0
    if(adet) SlaterDetSet.back()->add(adet);

    return firstIndex;
  }
Exemplo n.º 19
0
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;
}
Exemplo n.º 20
0
  /** Parses the xml input file for parameter definitions for a single qmc simulation.
   */
  bool 
  QMCDriver::putQMCInfo(xmlNodePtr cur) {
    
    //set the default walker to the number of threads times 10
    int defaultw = omp_get_max_threads()*10;
    int targetw = 0;

    //these options are reset for each block
    Period4WalkerDump=10;
    Period4CheckPoint=1;

    OhmmsAttributeSet aAttrib;
    aAttrib.add(Period4CheckPoint,"checkpoint");
    aAttrib.put(cur);
     
    if(cur != NULL) {
      //initialize the parameter set
      m_param.put(cur);
      xmlNodePtr tcur=cur->children;
      //determine how often to print walkers to hdf5 file
      while(tcur != NULL) {
	string cname((const char*)(tcur->name));
	if(cname == "record") {
          //dump walkers for optimization
          OhmmsAttributeSet rAttrib;
          rAttrib.add(Period4WalkerDump,"stride");
          rAttrib.add(Period4WalkerDump,"period");
          rAttrib.put(tcur);
	} else if(cname == "checkpoint") {
          OhmmsAttributeSet rAttrib;
          rAttrib.add(Period4CheckPoint,"stride");
          rAttrib.add(Period4CheckPoint,"period");
          rAttrib.put(tcur);
        } else if(cname == "random") {
          ResetRandom = true;
        }
	tcur=tcur->next;
      }
    }
    
    //reset CurrentStep to zero if qmc/@continue='no'
    if(!AppendRun) CurrentStep=0;

    //target number of walkers is less than the number of threads. Reset it.
    if(nTargetWalkers && nTargetWalkers<omp_get_max_threads()) 
      nTargetWalkers=omp_get_max_threads();

    app_log() << "  timestep = " << Tau << endl;
    app_log() << "  blocks = " << nBlocks << endl;
    app_log() << "  steps = " << nSteps << endl;
    app_log() << "  current = " << CurrentStep << endl;

    //Need MPI-IO
    app_log() << "  walkers = " << W.getActiveWalkers() << endl;

    /*check to see if the target population is different 
      from the current population.*/ 
    int nw  = W.getActiveWalkers();
    int ndiff = 0;
    if(nw) { // walkers exist
      // nTargetWalkers == 0, if it is not set by the input file
      ndiff = (nTargetWalkers)? nTargetWalkers-nw: 0;
    } else {
      ndiff= (nTargetWalkers)? nTargetWalkers:defaultw;
    }

    addWalkers(ndiff);

    //always true
    return (W.getActiveWalkers()>0);
  }
Exemplo n.º 21
0
  bool ThreeBodyGeminal::put(xmlNodePtr cur) 
  {

    //BasisSize = GeminalBasis->TotalBasis;
    BasisSize = GeminalBasis->getBasisSetSize();

    app_log() << "  The number of Geminal functions "
      <<"for Three-body Jastrow " << BasisSize << endl;
    app_log() << "  The number of particles " << NumPtcls << endl;

    Lambda.resize(BasisSize,BasisSize);

    //disable lambda's so that element-by-element input can be handled
    FreeLambda.resize(BasisSize*(BasisSize+1)/2);
    FreeLambda=false;

    //zero is default
    Lambda=0.0;
    //for(int ib=0; ib<BasisSize; ib++) Lambda(ib,ib)=NormFac;
    //for(int ib=0; ib<BasisSize; ib++) 
    //  for(int jb=ib; jb<BasisSize; ++jb)
    //  {
    //    Lambda(ib,jb)=Random();
    //    if(jb!=ib) Lambda(jb,ib)=Lambda(ib,jb);
    //  }

    if(cur == NULL) 
    { 
      FreeLambda=true;
    }
    else 
    {//read from an input nodes
      string aname("j3");
      string datatype("no");
      int sizeIn(0);
      IndexOffSet=1;
      OhmmsAttributeSet attrib;
      attrib.add(aname,"id");
      attrib.add(sizeIn,"size");
      attrib.add(aname,"name");
      attrib.add(datatype,"type");
      attrib.add(IndexOffSet,"offset");
      attrib.put(cur);

      ID_Lambda=aname;

      if(datatype.find("rray")<datatype.size())
      {
        if (sizeIn==Lambda.rows())
        {
          putContent(Lambda,cur);
        }
        FreeLambda=true; 
        //addOptimizables(varlist);
        //symmetrize it
        //for(int ib=0; ib<BasisSize; ib++) {
        //  sprintf(coeffname,"%s_%d_%d",aname.c_str(),ib+IndexOffSet,ib+IndexOffSet);
        //  varlist[coeffname]=Lambda(ib,ib);
        //  for(int jb=ib+1; jb<BasisSize; jb++) {
        //    sprintf(coeffname,"%s_%d_%d",aname.c_str(),ib+IndexOffSet,jb+IndexOffSet);
        //    Lambda(jb,ib) = Lambda(ib,jb);
        //    varlist[coeffname]=Lambda(ib,jb);
        //  }
        //}
      }
      else 
      {
        xmlNodePtr tcur=cur->xmlChildrenNode;
        while(tcur != NULL) {
          if(xmlStrEqual(tcur->name,(const xmlChar*)"lambda")) {
            int iIn=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"i")));
            int jIn=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"j")));
            int i=iIn-IndexOffSet;
            int j=jIn-IndexOffSet;
            double c=atof((const char*)(xmlGetProp(tcur,(const xmlChar*)"c")));
            Lambda(i,j)=c;
            FreeLambda(i*BasisSize+j)=true;
            if(i != j) Lambda(j,i)=c;
            //sprintf(coeffname,"%s_%d_%d",aname.c_str(),iIn,jIn);
            //varlist[coeffname]=c;
          }
          tcur=tcur->next;
        }
      }
    }

    //myVars are set
    myVars.clear();
    char coeffname[16];
    int ii=0;
    for(int ib=0; ib<BasisSize; ib++) {
      if(FreeLambda(ii++))
      {
        sprintf(coeffname,"%s_%d_%d",ID_Lambda.c_str(),ib,ib);
        myVars.insert(coeffname,Lambda(ib,ib));
      }
      for(int jb=ib+1; jb<BasisSize; jb++) 
      {
        if(FreeLambda(ii++))
        {
          sprintf(coeffname,"%s_%d_%d",ID_Lambda.c_str(),ib,jb);
          myVars.insert(coeffname,Lambda(ib,jb));
        }
      }
    }

    //app_log() << "  Lambda Variables " << endl;
    //myVars.print(app_log());
    //app_log() << endl;

    V.resize(NumPtcls,BasisSize);
    Y.resize(NumPtcls,BasisSize);
    dY.resize(NumPtcls,BasisSize);
    d2Y.resize(NumPtcls,BasisSize);

    curGrad.resize(NumPtcls);
    curLap.resize(NumPtcls);
    curVal.resize(NumPtcls);

    tGrad.resize(NumPtcls);
    tLap.resize(NumPtcls);
    curV.resize(BasisSize);
    delV.resize(BasisSize);

    Uk.resize(NumPtcls);
    dUk.resize(NumPtcls,NumPtcls);
    d2Uk.resize(NumPtcls,NumPtcls);


    //app_log() << "  Three-body Geminal coefficients " << endl;
    //app_log() << Lambda << endl;

    //GeminalBasis->resize(NumPtcls);

    return true;
  }
Exemplo n.º 22
0
int main(int argc, char** argv)
{
  OHMMS::Controller->initialize(argc,argv);
  Communicate* comm=OHMMS::Controller;
  OhmmsInfo Welcome("density",comm->rank());
  Random.init(0,1,11);

  ParticleSet::ParticleLayout_t simcell;
  string trace_root;
  int node_start=0, node_end=0;
  {
    Libxml2Document adoc;
    bool success = adoc.parse(argv[1]);
    xmlNodePtr cur=adoc.getRoot()->children;
    while(cur != NULL)
    {
      string cname((const char*)cur->name);
      if(cname.find("cell")<cname.size())
      {
        LatticeParser a(simcell);
        a.put(cur);
      }
      else if(cname =="density")
      {
        OhmmsAttributeSet a;
        a.add(trace_root,"file_root");
        a.add(node_start,"start");
        a.add(node_end,"end");
        a.put(cur);
      }
      cur=cur->next;
    }
  }

  //use proper root and extensition convention
  string h5fname=trace_root+".h5";

  int numptcls=0;
  vector<int> id;
  vector<double> pos;
  vector<double> weight;

  { //will be made into a class with id,weight and the data to analyze, e.g. pos
    hdf_archive hout(comm);
    hout.open(h5fname,H5F_ACC_RDONLY);

    ///read id
    hsize_t dims[2];
    bool g=hout.push("/int_data",false);
    if(g)
    {
      hid_t gid=hout.top();
      bool gotit=get_space(gid,"traces",2,dims);
    }
    {
      id.resize(dims[0]*dims[1]);
      TinyVector<int,2> gcounts(dims[0],dims[1]);
      hyperslab_proxy<vector<int>, 2> id_slab(id,gcounts);
      hout.read(id_slab,"traces");
    }
    hout.pop();

    ///read weight
    int nblocks=dims[0];
    int blockoffset=0;
    weight.resize(nblocks);
    {
      TinyVector<int,2> gcounts(dims[0],dims[1]);
      TinyVector<int,2> counts(dims[0],1);
      TinyVector<int,2> offsets(blockoffset,0);
      hyperslab_proxy<vector<double>, 2> w_slab(weight,gcounts,counts,offsets);
      hout.read(w_slab,"traces");
    }

    g=hout.push("/real_data",false);
    if(g)
    {
      hid_t gid=hout.top();
      bool gotit=get_space(gid,"traces",2,dims);
    }
    int pos_start=3;
    int pos_end=7;
    hout.read(pos_start,"layout/e/position/row_start");
    hout.read(pos_end,"layout/e/position/row_end");
    int npos=pos_end-pos_start;
    numptcls=npos/3;
    Timer now;
    now.restart();
    pos.resize(nblocks*npos);
    {
      TinyVector<int,2> gcounts(dims[0],dims[1]);
      TinyVector<int,2> counts(nblocks,npos);
      TinyVector<int,2> offsets(blockoffset,pos_start);
      hyperslab_proxy<vector<double>, 2> pos_slab(pos,gcounts,counts,offsets);
      hout.read(pos_slab,"traces");
    }
    int mbytes=(pos_start*pos_end*sizeof(double))>>20;

    app_log() << "Time to read positions " << now.elapsed() << endl;
    app_log() << "pos_start = " << pos_start << " pos_end = " << pos_end << " mbytes " << mbytes<< endl;

    hout.pop();
  }

  typedef ParticleSet::ParticlePos_t ParticlePos_t;
  typedef ParticleSet::Tensor_t Tensor_t;
  ParticlePos_t R(numptcls); //cartesian coordiates
  ParticlePos_t Ru(numptcls);//unit coordinates [0,1)
  std::copy(pos.data(),pos.data()+3*numptcls, &(R[0][0]));
  //convert Cartesian to unit in a box
  ApplyBConds<ParticlePos_t,Tensor_t,3,false>::Cart2Unit(R,simcell.G,Ru,0,numptcls);

  for(int i=0; i<8; ++i)
    app_log() << R[i] << " " << Ru[i] << endl;

  OHMMS::Controller->finalize();
  return 0;
}
Exemplo n.º 23
0
bool BsplineJastrowBuilder::put(xmlNodePtr cur)
{
    ReportEngine PRE(ClassName,"put(xmlNodePtr)");
    bool PrintTables=false;
    typedef BsplineFunctor<RealType> RadFuncType;
    // Create a one-body Jastrow
    if (sourcePtcl)
    {
        string j1spin("no");
        OhmmsAttributeSet jAttrib;
        jAttrib.add(j1spin,"spin");
        jAttrib.put(cur);
#ifdef QMC_CUDA
        return createOneBodyJastrow<OneBodyJastrowOrbitalBspline,DiffOneBodySpinJastrowOrbital<RadFuncType> >(cur);
#else
        //if(sourcePtcl->IsGrouped)
        //{
        //  app_log() << "Creating OneBodySpinJastrowOrbital<T> " << endl;
        //  return createOneBodyJastrow<OneBodySpinJastrowOrbital<RadFuncType>,DiffOneBodySpinJastrowOrbital<RadFuncType> >(cur);
        //}
        //else
        //{
        //  app_log() << "Creating OneBodyJastrowOrbital<T> " << endl;
        //  return createOneBodyJastrow<OneBodyJastrowOrbital<RadFuncType>,DiffOneBodyJastrowOrbital<RadFuncType> >(cur);
        //}
        if(j1spin=="yes")
            return createOneBodyJastrow<OneBodySpinJastrowOrbital<RadFuncType>,DiffOneBodySpinJastrowOrbital<RadFuncType> >(cur);
        else
            return createOneBodyJastrow<OneBodyJastrowOrbital<RadFuncType>,DiffOneBodyJastrowOrbital<RadFuncType> >(cur);
#endif
    }
    else // Create a two-body Jastrow
    {
        string init_mode("0");
        {
            OhmmsAttributeSet hAttrib;
            hAttrib.add(init_mode,"init");
            hAttrib.put(cur);
        }
        BsplineInitializer<RealType> j2Initializer;
        xmlNodePtr kids = cur->xmlChildrenNode;
#ifdef QMC_CUDA
        typedef TwoBodyJastrowOrbitalBspline J2Type;
#else
        typedef TwoBodyJastrowOrbital<BsplineFunctor<RealType> > J2Type;
#endif
        typedef DiffTwoBodyJastrowOrbital<BsplineFunctor<RealType> > dJ2Type;
        int taskid=(targetPsi.is_manager())?targetPsi.getGroupID():-1;
        J2Type *J2 = new J2Type(targetPtcl,taskid);
        dJ2Type *dJ2 = new dJ2Type(targetPtcl);
        SpeciesSet& species(targetPtcl.getSpeciesSet());
        int chargeInd=species.addAttribute("charge");
        //std::map<std::string,RadFuncType*> functorMap;
        bool Opt(false);
        while (kids != NULL)
        {
            std::string kidsname((const char*)kids->name);
            if (kidsname == "correlation")
            {
                OhmmsAttributeSet rAttrib;
                RealType cusp=-1e10;
                string pairType("0");
                string spA(species.speciesName[0]);
                string spB(species.speciesName[0]);
                rAttrib.add(spA,"speciesA");
                rAttrib.add(spB,"speciesB");
                rAttrib.add(pairType,"pairType");
                rAttrib.add(cusp,"cusp");
                rAttrib.put(kids);
                if(pairType[0]=='0')
                {
                    pairType=spA+spB;
                }
                else
                {
                    PRE.warning("pairType is deprecated. Use speciesA/speciesB");
                    //overwrite the species
                    spA=pairType[0];
                    spB=pairType[1];
                }
                int ia = species.findSpecies(spA);
                int ib = species.findSpecies(spB);
                if(ia==species.size() || ib == species.size())
                {
                    PRE.error("Failed. Species are incorrect.",true);
                }
                if(cusp<-1e6)
                {
                    RealType qq=species(chargeInd,ia)*species(chargeInd,ib);
                    cusp = (ia==ib)? -0.25*qq:-0.5*qq;
                }
                app_log() << "  BsplineJastrowBuilder adds a functor with cusp = " << cusp << endl;
                RadFuncType *functor = new RadFuncType(cusp);
                functor->cutoff_radius = targetPtcl.Lattice.WignerSeitzRadius;
                bool initialized_p=functor->put(kids);
                functor->elementType=pairType;
                if (functor->cutoff_radius < 1.0e-6)
                {
                    app_log()  << "  BsplineFunction rcut is currently zero.\n"
                               << "  Setting to Wigner-Seitz radius = "
                               << targetPtcl.Lattice.WignerSeitzRadius << endl;
                    functor->cutoff_radius = targetPtcl.Lattice.WignerSeitzRadius;
                    functor->reset();
                }
                //RPA INIT
                if(!initialized_p && init_mode =="rpa")
                {
                    app_log() << "  Initializing Two-Body with RPA Jastrow " << endl;
                    j2Initializer.initWithRPA(targetPtcl,*functor,-cusp/0.5);
                }
                J2->addFunc(ia,ib,functor);
                dJ2->addFunc(ia,ib,functor);
                Opt=(!functor->notOpt or Opt);
                if(qmc_common.io_node)
                {
                    char fname[32];
                    if(qmc_common.mpi_groups>1)
                        sprintf(fname,"J2.%s.g%03d.dat",pairType.c_str(),taskid);
                    else
                        sprintf(fname,"J2.%s.dat",pairType.c_str());
                    functor->setReportLevel(ReportLevel,fname);
                    functor->print();
                }
            }
            kids = kids->next;
        }
        //dJ2->initialize();
        //J2->setDiffOrbital(dJ2);
        J2->dPsi=dJ2;
        targetPsi.addOrbital(J2,"J2_bspline");
        J2->setOptimizable(Opt);
    }
    return true;
}