LocalCorePolPotential::LocalCorePolPotential(ParticleSet& ions,
    ParticleSet& els):
  FirstTime(true), eCoreCore(0.0), IonConfig(ions), d_ie(0), d_ii(0)
{
  //set the distance tables
  d_ie = DistanceTable::add(ions,els);
  d_ii = DistanceTable::add(ions);
  nCenters = ions.getTotalNum();
  nParticles = els.getTotalNum();
  InpCPP.resize(IonConfig.getSpeciesSet().getTotalNum(),0);
  Centers.resize(nCenters,0);
  CoreCoreDipole.resize(nCenters,0.0);
  CoreElDipole.resize(nCenters,nParticles);
  CoreElDipole = 0.0;
}
Example #2
0
/*void StressPBCAA::acceptMove(int active)
{
  if(is_active)
  {
    Return_t* restrict sr_ptr=SR2[active];
    Return_t* restrict pr_ptr=SR2.data()+active;
    for(int iat=0; iat<NumCenters; ++iat, ++sr_ptr,pr_ptr+=NumCenters)
      *pr_ptr = *sr_ptr += dSR[iat];
    Value=NewValue;
  }
}
*/
void StressPBCAA::initBreakup(ParticleSet& P)
{
  //SpeciesSet& tspecies(PtclRef->getSpeciesSet());
  SpeciesSet& tspecies(P.getSpeciesSet());
  //Things that don't change with lattice are done here instead of InitBreakup()
  ChargeAttribIndx = tspecies.addAttribute("charge");
  MemberAttribIndx = tspecies.addAttribute("membersize");
  NumCenters = P.getTotalNum();
  NumSpecies = tspecies.TotalNum;
 // V_const.resize(NumCenters);
  Zat.resize(NumCenters);
  Zspec.resize(NumSpecies);
  NofSpecies.resize(NumSpecies);
  for(int spec=0; spec<NumSpecies; spec++)
  {
    Zspec[spec] = tspecies(ChargeAttribIndx,spec);
    NofSpecies[spec] = static_cast<int>(tspecies(MemberAttribIndx,spec));
  }
  SpeciesID.resize(NumCenters);
  for(int iat=0; iat<NumCenters; iat++)
  {
    SpeciesID[iat]=P.GroupID[iat];
    Zat[iat] = Zspec[P.GroupID[iat]];
  }
  AA = LRCoulombSingleton::getDerivHandler(P);
  //AA->initBreakup(*PtclRef);
  myConst=evalConsts();
  myRcut=AA->get_rc();//Basis.get_rc();
  if(rVs==0)
  {
    rVs = LRCoulombSingleton::createSpline4RbyVs(AA,myRcut,myGrid);
  }
}
Example #3
0
 LocalECPotential::LocalECPotential(const ParticleSet& ions, ParticleSet& els):
   IonConfig(ions), d_table(0)
 { 
   NumIons=ions.getTotalNum();
   d_table = DistanceTable::add(ions,els);
   //allocate null
   PP.resize(NumIons,0);
   Zeff.resize(NumIons,1.0);
 } 
  RandomMomDist::RandomMomDist(ParticleSet& PtclSet, const Vector<PosType>& inGVectors, 
			       PtclChoiceBase* pcb) : DirectMomDist(pcb, PtclSet.getTotalNum()) {
    GVectors.resize(inGVectors.size());
    for (IndexType i = 0; i < inGVectors.size(); i++) {
      GVectors[i] = inGVectors[i];
    }
    NofK.resize(inGVectors.size());
    MomDist.resize(inGVectors.size());
  }
Example #5
0
 LocalECPotential::Return_t 
   LocalECPotential::registerData(ParticleSet& P, BufferType& buffer) 
   {
     PPart.resize(P.getTotalNum());
     NewValue=Value=evaluateForPbyP(P);
     buffer.add(PPart.begin(),PPart.end());
     buffer.add(Value);
     return Value;
   }
Example #6
0
 void NumericalDiffOrbital::resetTargetParticleSet(ParticleSet& P)
 {
   int nptcls=P.getTotalNum();
   dg_p.resize(nptcls);
   dl_p.resize(nptcls);
   dg_m.resize(nptcls);
   dl_m.resize(nptcls);
   gradLogPsi.resize(nptcls);
   lapLogPsi.resize(nptcls);
 }
/*
 * Three Dimensional Momentum Distribution.  This will take displacements in three dimensions
 * and produce a three dimensional n(k)
 */ 
  ThreeDimMomDist::ThreeDimMomDist(ParticleSet& PtclSet, const Vector<IndexType>& DimSizes, 
				   PtclChoiceBase* pcb) : FFTMomentumDist<3>(pcb, PtclSet.getTotalNum()) {
    TinyVector<IndexType, 3> inNumPts;
    TinyVector<RealType, 3> InvSpacing;
    for (IndexType i = 0; i < 3; i++) {
      inNumPts[i] = DimSizes[i];
      InvSpacing = 1.0 / std::sqrt(dot(PtclSet.Lattice.a(i), PtclSet.Lattice.a(i)));
    }
    initialize(inNumPts, InvSpacing);
  }
/*
 * One Dimensional Averaged Momentum Distribution.  This will take displacements in three dimensions
 * and produce a one dimensional n(k)
 */ 
  AveragedOneDimMomDist::AveragedOneDimMomDist(ParticleSet& PtclSet, const Vector<IndexType>& DimSizes, 
					       PtclChoiceBase* pcb) : FFTMomentumDist<1>(pcb, PtclSet.getTotalNum()) {
    TinyVector<IndexType, 1> inIndSize;
    TinyVector<RealType, 1> InvSpacing;
    for (IndexType i = 0; i < 1; i++) {
      inIndSize[i] = DimSizes[i];
      InvSpacing = 1.0 / std::sqrt(dot(PtclSet.Lattice.a(i), PtclSet.Lattice.a(i)));
    }
    initialize(inIndSize, InvSpacing);
  }
Example #9
0
 LocalECPotential::LocalECPotential(const ParticleSet& ions, ParticleSet& els):
   IonConfig(ions)
 { 
   NumIons=ions.getTotalNum();
   myTableIndex=els.addTable(ions);
   //allocate null
   PPset.resize(ions.getSpeciesSet().getTotalNum(),0);
   PP.resize(NumIons,0);
   Zeff.resize(NumIons,0.0);
   gZeff.resize(ions.getSpeciesSet().getTotalNum(),0);
 } 
Example #10
0
 void AnalyticDiffOrbital::resetTargetParticleSet(ParticleSet& P)
 {
   if(MyIndex<0) return;
   for(int i=0; i<refOrbital.size(); ++i) refOrbital[i]->resetTargetParticleSet(P);
   int nptcls=P.getTotalNum();
   if(gradLogPsi.size()!=nptcls)
   {
     gradLogPsi.resize(nptcls);
     lapLogPsi.resize(nptcls);
   }
 }
 /** constructor
  *\param ions the positions of the ions
  *\param els the positions of the electrons
  *\param psi trial wavefunction
  */
 NonLocalECPotential::NonLocalECPotential
 (ParticleSet& ions, ParticleSet& els,
  TrialWaveFunction& psi) : 
  IonConfig(ions), d_table(0), Psi(psi)
 { 
   d_table = DistanceTable::add(ions,els);
   NumIons=ions.getTotalNum();
   //els.resizeSphere(NumIons);
   PP.resize(NumIons,0);
   PPset.resize(IonConfig.getSpeciesSet().getTotalNum(),0);
 }
Example #12
0
 LRTwoBodyJastrow::LRTwoBodyJastrow(ParticleSet& p, HandlerType* inHandler):
 NumPtcls(0), NumSpecies(0), skRef(0) {
   Optimizable=true;
   handler=inHandler;
   NumSpecies=p.groups();
   skRef=p.SK;
   handler = LRJastrowSingleton::getHandler(p);
   if(skRef) {
     //Rs  = Omega
     OneOverCellVolume = 1.0 / p.Lattice.Volume;
     Omega = std::pow(3.0/(4.0*M_PI)*p.Lattice.Volume/static_cast<RealType>(p.getTotalNum()),1.0/3.0);
     //Rs=std::pow(3.0/4.0/M_PI*p.Lattice.Volume/static_cast<RealType>(p.getTotalNum()),1.0/3.0);
     //Omega=std::sqrt(4.0*M_PI*static_cast<RealType>(p.getTotalNum())/p.Lattice.Volume);
     OneOverOmega=1.0/Omega;
     FourPiOmega=4.0*M_PI*Omega;
     NumPtcls=p.getTotalNum();
     NumKpts=skRef->KLists.numk;
     NormConstant=FourPiOmega*NumPtcls*(NumPtcls-1)*0.5;
     resize();
     reset();
   }
 }
/** constructor
 *\param ions the positions of the ions
 *\param els the positions of the electrons
 *\param psi trial wavefunction
 */
NonLocalECPotential::NonLocalECPotential(ParticleSet& ions, ParticleSet& els,
    TrialWaveFunction& psi,
    bool computeForces):
  IonConfig(ions), d_table(0), Psi(psi),
  ComputeForces(computeForces), ForceBase(ions,els)
{
  d_table = DistanceTable::add(ions,els);
  NumIons=ions.getTotalNum();
  //els.resizeSphere(NumIons);
  PP.resize(NumIons,0);
  prefix="FNL";
  PPset.resize(IonConfig.getSpeciesSet().getTotalNum(),0);
  PulayTerm.resize(NumIons);
}
Example #14
0
MomentumEstimator::Return_t MomentumEstimator::evaluate(ParticleSet& P)
{
    const int np=P.getTotalNum();
    nofK=0.0;
    compQ=0.0;

    //will use temp[i].r1 for the Compton profile
    const vector<DistanceTableData::TempDistType>& temp(P.DistTables[0]->Temp);
    Vector<RealType> tmpn_k(nofK);
    for (int s=0; s<M; ++s)
    {
        PosType newpos;

        for (int i=0; i<OHMMS_DIM; ++i) newpos[i]=myRNG();
        //make it cartesian
        newpos=Lattice.toCart(newpos);
        P.makeVirtualMoves(newpos); //updated: temp[i].r1=|newpos-P.R[i]|, temp[i].dr1=newpos-P.R[i]
        refPsi.get_ratios(P,psi_ratios);
//         for (int i=0; i<np; ++i) app_log()<<i<<" "<<psi_ratios[i].real()<<" "<<psi_ratios[i].imag()<<endl;
        P.rejectMove(0); //restore P.R[0] to the orginal position

        for (int ik=0; ik < kPoints.size(); ++ik)
        {
            for (int i=0; i<np; ++i) kdotp[i]=dot(kPoints[ik],temp[i].dr1_nobox);
            eval_e2iphi(np,kdotp.data(),phases.data());
            RealType nofk_here(std::real(BLAS::dot(np,phases.data(),&psi_ratios[0])));//psi_ratios.data())));
            nofK[ik]+= nofk_here;
            tmpn_k[ik]=nofk_here;
        }

        for (int iq=0; iq < compQ.size(); ++iq)
            for (int i=0; i<mappedQtonofK[iq].size(); ++i)
                compQ[iq] += tmpn_k[mappedQtonofK[iq][i]];




    }
    for (int ik=0; ik<nofK.size(); ++ik) nofK[ik] *= norm_nofK;
    for (int iq=0; iq<compQ.size(); ++iq) compQ[iq] *= mappedQnorms[iq];

    if (hdf5_out)
    {
        int j=myIndex;
        for (int ik=0; ik<nofK.size(); ++ik,++j) P.Collectables[j]+= nofK[ik];
        for (int iq=0; iq<compQ.size(); ++iq,++j) P.Collectables[j]+= compQ[iq];
    }
    return 0.0;
}
  RNDiracDeterminantBaseAlternate::RealType
  RNDiracDeterminantBaseAlternate::registerData(ParticleSet& P, PooledData<RealType>& buf)
  {

    if (NP == 0) //first time, allocate once
      {
        //int norb = cols();
        dpsiV.resize(NumOrbitals);
        d2psiV.resize(NumOrbitals);
        workV1.resize(NumOrbitals);
        workV2.resize(NumOrbitals);
        NP=P.getTotalNum();
        myG.resize(NP);
        myL.resize(NP);
        myG_temp.resize(NP);
        myL_temp.resize(NP);
        myG_alternate.resize(NP);
        myL_alternate.resize(NP);
        FirstAddressOfG = &myG[0][0];
        LastAddressOfG = FirstAddressOfG + NP*DIM;
        FirstAddressOfdV = &(dpsiM(0,0)[0]); //(*dpsiM.begin())[0]);
        LastAddressOfdV = FirstAddressOfdV + NumPtcls*NumOrbitals*DIM;
      }

    myG=0.0;
    myL=0.0;
    myG_alternate=0.0;
    myL_alternate=0.0;

    //ValueType x=evaluate(P,myG,myL);
    evaluateLog(P,myG,myL);

    P.G += myG;
    P.L += myL;

    //add the data: determinant, inverse, gradient and laplacians
    buf.add(psiM.first_address(),psiM.last_address());
    buf.add(FirstAddressOfdV,LastAddressOfdV);
    buf.add(d2psiM.first_address(),d2psiM.last_address());
    buf.add(myL.first_address(), myL.last_address());
    buf.add(FirstAddressOfG,LastAddressOfG);
    buf.add(LogValue);
    buf.add(alternateLogValue);
    buf.add(PhaseValue);

    return LogValue;
  }
Example #16
0
void TrialWaveFunction::evaluateHessian(ParticleSet & P, HessVector_t& grad_grad_psi)
{
  vector<OrbitalBase*>::iterator it(Z.begin());
  vector<OrbitalBase*>::iterator it_end(Z.end());
  
  grad_grad_psi.resize(P.getTotalNum());
  
  for (int i=0; i<Z.size(); i++)
  {	
	  HessVector_t tmp_hess(grad_grad_psi);
	  tmp_hess=0.0;
	  Z[i]->evaluateHessian(P, tmp_hess);
	  grad_grad_psi+=tmp_hess;
	//  app_log()<<"TrialWavefunction::tmp_hess = "<<tmp_hess<<endl;
	//  app_log()<<endl<<endl;
  }
 // app_log()<<" TrialWavefunction::Hessian = "<<grad_grad_psi<<endl;
}
Example #17
0
 void SpinDensity::test(int moves,ParticleSet& P)
 {
   app_log()<<"  SpinDensity test"<<endl;
   RandomGenerator_t rng;
   int particles = P.getTotalNum();
   int pmin = numeric_limits<int>::max();
   int pmax = numeric_limits<int>::min();
   for(int m=0;m<moves;++m)
   {
     for(int p=0;p<particles;++p)
     {
       PosType u;
       for(int d=0;d<DIM;++d)
         u[d] = rng();
       P.R[p] = P.Lattice.toCart(u);
     }
     test_evaluate(P,pmin,pmax);
   }
   app_log()<<"  end SpinDensity test"<<endl;
   APP_ABORT("SpinDensity::test  test complete");
 }
  DiracDeterminantBase::ValueType DiracDeterminantBase::registerData(ParticleSet& P, PooledData<RealType>& buf) {

    if(NP == 0) {//first time, allocate once
      //int norb = cols();
      dpsiV.resize(NumOrbitals);
      d2psiV.resize(NumOrbitals);
      workV1.resize(NumOrbitals);
      workV2.resize(NumOrbitals);
      NP=P.getTotalNum();
      myG.resize(NP);
      myL.resize(NP);
      myG_temp.resize(NP);
      myL_temp.resize(NP);
      FirstAddressOfG = &myG[0][0];
      LastAddressOfG = FirstAddressOfG + NP*DIM;
      FirstAddressOfdV = &(dpsiM(0,0)[0]); //(*dpsiM.begin())[0]);
      LastAddressOfdV = FirstAddressOfdV + NumPtcls*NumOrbitals*DIM;
    }

    //allocate once but each walker calls this
    myG=0.0;
    myL=0.0;

    ValueType x=evaluate(P,myG,myL); 

    P.G += myG;
    P.L += myL;

    //add the data: determinant, inverse, gradient and laplacians
    buf.add(psiM.first_address(),psiM.last_address());
    buf.add(FirstAddressOfdV,LastAddressOfdV);
    buf.add(d2psiM.first_address(),d2psiM.last_address());
    buf.add(myL.first_address(), myL.last_address());
    buf.add(FirstAddressOfG,LastAddressOfG);
    buf.add(CurrentDet);

    return CurrentDet;
  }
Example #19
0
CoulombPBCAB::Return_t
CoulombPBCAB::evaluateForPyP(ParticleSet& P)
{
  Return_t res=myConst;
#if defined(USE_REAL_STRUCT_FACTOR)
  APP_ABORT("CoulombPBCAB::evaluateForPyP(ParticleSet& P)");
#else
  SRpart=0.0;
  const DistanceTableData* d_ab=P.DistTables[myTableIndex];
  for(int iat=0; iat<NptclA; ++iat)
  {
    RealType z=Zat[iat];
    RadFunctorType* rVs=Vat[iat];
    for(int nn=d_ab->M[iat], jat=0; nn<d_ab->M[iat+1]; nn++,jat++)
    {
      RealType e=z*Qat[jat]*d_ab->rinv(nn)*rVs->splint(d_ab->r(nn));
      SRpart[jat]+=e;
      res+=e;
    }
  }
  LRpart=0.0;
  const StructFact& RhoKA(*(PtclA.SK));
  const StructFact& RhoKB(*(P.SK));
  // const StructFact& RhoKB(*(PtclB->SK));
  for(int i=0; i<NumSpeciesA; i++)
  {
    RealType z=Zspec[i];
    for(int jat=0; jat<P.getTotalNum(); ++jat)
    {
      RealType e=z*Qat[jat]*AB->evaluate(RhoKA.KLists.kshell, RhoKA.rhok[i],RhoKB.eikr[jat]);
      LRpart[jat]+=e;
      res+=e;
    }
  }
#endif
  return res;
}
Example #20
0
void CoulombPBCAB::initBreakup(ParticleSet& P)
{
  SpeciesSet& tspeciesA(PtclA.getSpeciesSet());
  SpeciesSet& tspeciesB(P.getSpeciesSet());
  int ChargeAttribIndxA = tspeciesA.addAttribute("charge");
  int MemberAttribIndxA = tspeciesA.addAttribute("membersize");
  int ChargeAttribIndxB = tspeciesB.addAttribute("charge");
  int MemberAttribIndxB = tspeciesB.addAttribute("membersize");
  NptclA = PtclA.getTotalNum();
  NptclB = P.getTotalNum();
  NumSpeciesA = tspeciesA.TotalNum;
  NumSpeciesB = tspeciesB.TotalNum;
  //Store information about charges and number of each species
  Zat.resize(NptclA);
  Zspec.resize(NumSpeciesA);
  Qat.resize(NptclB);
  Qspec.resize(NumSpeciesB);
  NofSpeciesA.resize(NumSpeciesA);
  NofSpeciesB.resize(NumSpeciesB);
  for(int spec=0; spec<NumSpeciesA; spec++)
  {
    Zspec[spec] = tspeciesA(ChargeAttribIndxA,spec);
    NofSpeciesA[spec] = static_cast<int>(tspeciesA(MemberAttribIndxA,spec));
  }
  for(int spec=0; spec<NumSpeciesB; spec++)
  {
    Qspec[spec] = tspeciesB(ChargeAttribIndxB,spec);
    NofSpeciesB[spec] = static_cast<int>(tspeciesB(MemberAttribIndxB,spec));
  }
  RealType totQ=0.0;
  for(int iat=0; iat<NptclA; iat++)
    totQ+=Zat[iat] = Zspec[PtclA.GroupID[iat]];
  for(int iat=0; iat<NptclB; iat++)
    totQ+=Qat[iat] = Qspec[P.GroupID[iat]];
//    if(totQ>numeric_limits<RealType>::epsilon())
//    {
//      LOGMSG("PBCs not yet finished for non-neutral cells");
//      OHMMS::Controller->abort();
//    }
  ////Test if the box sizes are same (=> kcut same for fixed dimcut)
  kcdifferent = (std::abs(PtclA.Lattice.LR_kc - P.Lattice.LR_kc) > numeric_limits<RealType>::epsilon());
  minkc = std::min(PtclA.Lattice.LR_kc,P.Lattice.LR_kc);
  //AB->initBreakup(*PtclB);
  //initBreakup is called only once
  //AB = LRCoulombSingleton::getHandler(*PtclB);
  AB = LRCoulombSingleton::getHandler(P);
  myConst=evalConsts();
  myRcut=AB->get_rc();//Basis.get_rc();
  // create the spline function for the short-range part assuming pure potential
  if(V0==0)
  {
    V0 = LRCoulombSingleton::createSpline4RbyVs(AB,myRcut,myGrid);
    if(Vat.size())
    {
      app_log() << "  Vat is not empty. Something is wrong" << endl;
      OHMMS::Controller->abort();
    }
    Vat.resize(NptclA,V0);
    Vspec.resize(NumSpeciesA,0);//prepare for PP to overwrite it
  }
}
Example #21
0
CoulombPBCAB::Return_t
CoulombPBCAB::spevaluate(ParticleSet& P)
{
  RealType  Vsr = 0.0;
  RealType  Vlr = 0.0;
  RealType& Vc  = myConst;
  Array<RealType,1>& Ve_samp = *Ve_sample;
  Array<RealType,1>& Vi_samp = *Vi_sample;
  Ve_samp = 0.0;
  Vi_samp = 0.0;
  {
    //SR
    const DistanceTableData &d_ab(*P.DistTables[myTableIndex]);
    RealType pairpot;
    RealType z;
    //Loop over distinct eln-ion pairs
    for(int iat=0; iat<NptclA; iat++)
    {
      z = .5*Zat[iat];
      RadFunctorType* rVs=Vat[iat];
      for(int nn=d_ab.M[iat], jat=0; nn<d_ab.M[iat+1]; ++nn,++jat)
      {
        pairpot = z*Qat[jat]*d_ab.rinv(nn)*rVs->splint(d_ab.r(nn));
        Vi_samp(iat)+=pairpot;
        Ve_samp(jat)+=pairpot;
        Vsr+=pairpot;
      }
    }
    Vsr *= 2.0;
  }
  {
    //LR
    const StructFact& RhoKA(*(PtclA.SK));
    const StructFact& RhoKB(*(P.SK));
    if(RhoKA.SuperCellEnum==SUPERCELL_SLAB)
    {
      APP_ABORT("CoulombPBCAB::spevaluate single particle traces have not been implemented for slab geometry");
    }
    else
    {
      //jtk mark: needs optimizations for USE_REAL_STRUCT_FACTOR
      //          will likely require new function definitions
      RealType v1; //single particle energy
      RealType q;
      for(int i=0; i<P.getTotalNum(); ++i)
      {
        q=.5*Qat[i];
        v1=0.0;
        for(int s=0; s<NumSpeciesA; s++)
#if defined(USE_REAL_STRUCT_FACTOR)
          v1+=Zspec[s]*q*AB->evaluate(RhoKA.KLists.kshell,RhoKA.rhok_r[s],RhoKA.rhok_i[s],RhoKB.eikr_r[i],RhoKB.eikr_i[i]);
#else
          v1+=Zspec[s]*q*AB->evaluate(RhoKA.KLists.kshell,RhoKA.rhok[s],RhoKB.eikr[i]);
#endif
        Ve_samp(i)+=v1;
        Vlr+=v1;
      }
      for(int i=0; i<PtclA.getTotalNum(); ++i)
      {
        q=.5*Zat[i];
        v1=0.0;
        for(int s=0; s<NumSpeciesB; s++)
#if defined(USE_REAL_STRUCT_FACTOR)
          v1+=Qspec[s]*q*AB->evaluate(RhoKB.KLists.kshell,RhoKB.rhok_r[s],RhoKB.rhok_i[s],RhoKA.eikr_r[i],RhoKA.eikr_i[i]);
#else
          v1+=Qspec[s]*q*AB->evaluate(RhoKB.KLists.kshell,RhoKB.rhok[s],RhoKA.eikr[i]);
#endif
        Vi_samp(i)+=v1;
        Vlr+=v1;
      }
    }
  }
  for(int i=0; i<Ve_samp.size(); ++i)
    Ve_samp(i)+=Ve_const(i);
  for(int i=0; i<Vi_samp.size(); ++i)
    Vi_samp(i)+=Vi_const(i);
  Value = Vsr + Vlr + Vc;
#if defined(TRACE_CHECK)
  RealType Vlrnow  = evalLR(P);
  RealType Vsrnow  = evalSR(P);
  RealType Vcnow   = myConst;
  RealType Vnow    = Vlrnow+Vsrnow+Vcnow;
  RealType Vesum    = Ve_samp.sum();
  RealType Vecsum   = Ve_const.sum();
  RealType Visum    = Vi_samp.sum();
  RealType Vicsum   = Vi_const.sum();
  RealType Vsum    = Vesum+Visum;
  RealType Vcsum   = Vecsum+Vicsum;
  RealType Vsrold  = evalSR_old(P);
  RealType Vlrold  = evalLR_old(P);
  RealType Vcold   = evalConsts_old(false);
  RealType Vcorig  = evalConsts_orig(false);
  if(abs(Vsum-Vnow)>TraceManager::trace_tol)
  {
    app_log()<<"accumtest: CoulombPBCAA::evaluate()"<<endl;
    app_log()<<"accumtest:   tot:"<< Vnow <<endl;
    app_log()<<"accumtest:   sum:"<< Vsum  <<endl;
    APP_ABORT("Trace check failed");
  }
  if(abs(Vcsum-Vcnow)>TraceManager::trace_tol)
  {
    app_log()<<"accumtest: CoulombPBCAA::evalConsts()"<<endl;
    app_log()<<"accumtest:   tot:"<< Vcnow <<endl;
    app_log()<<"accumtest:   sum:"<< Vcsum  <<endl;
    APP_ABORT("Trace check failed");
  }
  if(abs(Vesum-Visum)>TraceManager::trace_tol)
  {
    app_log()<<"sharetest: CoulombPBCAB::evaluate()"<<endl;
    app_log()<<"sharetest:   e share:"<< Vesum  <<endl;
    app_log()<<"sharetest:   i share:"<< Visum  <<endl;
  }
  if(abs(Vecsum-Vicsum)>TraceManager::trace_tol)
  {
    app_log()<<"sharetest: CoulombPBCAB::evalConsts()"<<endl;
    app_log()<<"sharetest:   e share:"<< Vecsum  <<endl;
    app_log()<<"sharetest:   i share:"<< Vicsum <<endl;
  }
  if(abs(Vsrold-Vsrnow)>TraceManager::trace_tol)
  {
    app_log()<<"versiontest: CoulombPBCAA::evalSR()"<<endl;
    app_log()<<"versiontest:    old:"<< Vsrold <<endl;
    app_log()<<"versiontest:    mod:"<< Vsrnow <<endl;
    APP_ABORT("Trace check failed");
  }
  if(abs(Vlrold-Vlrnow)>TraceManager::trace_tol)
  {
    app_log()<<"versiontest: CoulombPBCAA::evalLR()"<<endl;
    app_log()<<"versiontest:    old:"<< Vlrold <<endl;
    app_log()<<"versiontest:    mod:"<< Vlrnow <<endl;
    APP_ABORT("Trace check failed");
  }
  if(abs(Vcold-Vcorig)>TraceManager::trace_tol ||
      abs(Vcnow-Vcorig)>TraceManager::trace_tol )
  {
    app_log()<<"versiontest: CoulombPBCAA::evalConsts()"<<endl;
    app_log()<<"versiontest:    old:"<< Vcold <<endl;
    app_log()<<"versiontest:   orig:"<< Vcorig <<endl;
    app_log()<<"versiontest:    mod:"<< Vcnow <<endl;
    APP_ABORT("Trace check failed");
  }
#endif
  return Value;
}
  void SlaterDetWithBackflow::testDerivGL(ParticleSet& P)
  {

// testing derivatives of G and L
         
       app_log() <<"testing derivatives of G and L \n";
       opt_variables_type wfVars,wfvar_prime;
       checkInVariables(wfVars);
       checkOutVariables(wfVars);
       int Nvars= wfVars.size();
       wfvar_prime= wfVars;
       wfVars.print(cout);
       vector<RealType> dlogpsi;
       vector<RealType> dhpsi;
       dlogpsi.resize(Nvars);
       dhpsi.resize(Nvars);
       ParticleSet::ParticleGradient_t G0,G1,G2;
       ParticleSet::ParticleLaplacian_t L0,L1,L2;
       G0.resize(P.getTotalNum());
       G1.resize(P.getTotalNum());
       G2.resize(P.getTotalNum());
       L0.resize(P.getTotalNum());
       L1.resize(P.getTotalNum());
       L2.resize(P.getTotalNum());
       ValueType psi0 = 1.0;
       ValueType psi1 = 1.0;
       ValueType psi2 = 1.0;
       double dh=0.00001;

         for(int k=0; k<Dets.size(); k++) {
           DiracDeterminantWithBackflow* Dets_ = (DiracDeterminantWithBackflow*) Dets[k];
           Dets_->testGGG(P);
           for( int i=0; i<Nvars; i++) {
             Dets_->testDerivFjj(P,i);
             Dets_->testDerivLi(P,i);
           }
         }


       app_log() <<"Nvars: " <<Nvars <<endl;
       for(int i=0; i<Nvars; i++) {

         for (int j=0; j<Nvars; j++) wfvar_prime[j]=wfVars[j];
         resetParameters(wfvar_prime);        
         BFTrans->evaluateDerivatives(P);
         G0=0.0;G1=0.0;G2=0.0;
         L0=0.0;L1=0.0;L2=0.0;
         for(int k=0; k<Dets.size(); k++) {
           DiracDeterminantWithBackflow* Dets_ = (DiracDeterminantWithBackflow*) Dets[k];
           Dets_->evaluateDerivatives(P,wfVars,dlogpsi,dhpsi,&G0,&L0,i);
         }
         

         for (int j=0; j<Nvars; j++) wfvar_prime[j]=wfVars[j];
         wfvar_prime[i] = wfVars[i]+ dh;
         resetParameters(wfvar_prime);

         BFTrans->evaluate(P);
         for(int k=0; k<Dets.size(); k++) psi1 += Dets[k]->evaluateLog(P,G1,L1);

         for (int j=0; j<Nvars; j++) wfvar_prime[j]=wfVars[j];
         wfvar_prime[i] = wfVars[i]- dh;
         resetParameters(wfvar_prime);

         BFTrans->evaluate(P);
         for(int k=0; k<Dets.size(); k++) psi2 += Dets[k]->evaluateLog(P,G2,L2);

         ValueType tmp=0.0;
         for(int q=0; q<P.getTotalNum(); q++) tmp+=(L1[q]-L2[q])/(2*dh);
         app_log() <<i <<"\n"
                     <<"Ldiff : " <<L0[0] <<"  " <<tmp
                     <<"  " <<L0[0]-tmp <<endl;

         for(int k=0; k<P.getTotalNum(); k++) {
           app_log()<<G0[k] <<endl
                     <<(G1[k]-G2[k])/(2*dh) <<endl
                     <<"Gdiff: " <<G0[k]-(G1[k]-G2[k])/(2*dh) <<endl <<endl;
         }

       }
       resetParameters(wfVars);        
      //APP_ABORT("Testing bF derivs \n");
  }
Example #23
0
void
ParticleSet::randomizeFromSource (ParticleSet &src)
{
  SpeciesSet& srcSpSet(src.getSpeciesSet());
  SpeciesSet& spSet(getSpeciesSet());
  int srcChargeIndx = srcSpSet.addAttribute("charge");
  int srcMemberIndx = srcSpSet.addAttribute("membersize");
  int ChargeIndex   = spSet.addAttribute("charge");
  int MemberIndx    = spSet.addAttribute("membersize");
  int Nsrc  = src.getTotalNum();
  int Nptcl = getTotalNum();
  int NumSpecies    = spSet.TotalNum;
  int NumSrcSpecies = srcSpSet.TotalNum;
  //Store information about charges and number of each species
  vector<int> Zat, Zspec, NofSpecies, NofSrcSpecies, CurElec;
  Zat.resize(Nsrc);
  Zspec.resize(NumSrcSpecies);
  NofSpecies.resize(NumSpecies);
  CurElec.resize(NumSpecies);
  NofSrcSpecies.resize(NumSrcSpecies);
  for(int spec=0; spec<NumSrcSpecies; spec++)
  {
    Zspec[spec] = (int)round(srcSpSet(srcChargeIndx,spec));
    NofSrcSpecies[spec] = (int)round(srcSpSet(srcMemberIndx,spec));
  }
  for(int spec=0; spec<NumSpecies; spec++)
  {
    NofSpecies[spec] = (int)round(spSet(MemberIndx,spec));
    CurElec[spec] = first(spec);
  }
  int totQ=0;
  for(int iat=0; iat<Nsrc; iat++)
    totQ+=Zat[iat] = Zspec[src.GroupID[iat]];
  app_log() << "  Total ion charge    = " << totQ << endl;
  totQ -= Nptcl;
  app_log() << "  Total system charge = " << totQ << endl;
  // Now, loop over ions, attaching electrons to them to neutralize
  // charge
  int spToken = 0;
  // This is decremented when we run out of electrons in each species
  int spLeft = NumSpecies;
  vector<PosType> gaussRand (Nptcl);
  makeGaussRandom (gaussRand);
  for (int iat=0; iat<Nsrc; iat++)
  {
    // Loop over electrons to add, selecting round-robin from the
    // electron species
    int z = Zat[iat];
    while (z > 0  && spLeft)
    {
      int sp = spToken++ % NumSpecies;
      if (NofSpecies[sp])
      {
        NofSpecies[sp]--;
        z--;
        int elec = CurElec[sp]++;
        app_log() << "  Assigning " << (sp ? "down" : "up  ")
                  << " electron " << elec << " to ion " << iat
                  << " with charge " << z << endl;
        double radius = 0.5* std::sqrt((double)Zat[iat]);
        R[elec] = src.R[iat] + radius * gaussRand[elec];
      }
      else
        spLeft--;
    }
  }
  // Assign remaining electrons
  int ion=0;
  for (int sp=0; sp < NumSpecies; sp++)
  {
    for (int ie=0; ie<NofSpecies[sp]; ie++)
    {
      int iat = ion++ % Nsrc;
      double radius = std::sqrt((double)Zat[iat]);
      int elec = CurElec[sp]++;
      R[elec] = src.R[iat] + radius * gaussRand[elec];
    }
  }
}
Example #24
0
  ThreeBodySM::ValueType ThreeBodySM::evaluateLog(ParticleSet& P, ParticleSet::ParticleGradient_t& G, 
      ParticleSet::ParticleLaplacian_t& L) {

    LogValue=0.0;
    RealType dudr, d2udr2;

    int nc(CenterRef.getTotalNum()), nptcl(P.getTotalNum());

    //first fill the matrix AA(i,j) where j is a composite index
    for(int I=0; I<nc; I++) {
      BasisType& a(*ieBasis[CenterRef.GroupID[I]]);
      int offset(0);
      for(int nn=dist_ie->M[I]; nn<dist_ie->M[I+1]; nn++) {
        RealType sep(dist_ie->r(nn));
        RealType rinv(dist_ie->rinv(nn));
        int i(dist_ie->J[nn]);
        int offset(ieBasisOffset[I]);
        for(int k=0; k<a.size(); k++,offset++) {
          AA(i,offset)=a[k]->evaluate(sep,dudr,d2udr2);
          dudr *= rinv;
          dAA(i,offset)=dudr*dist_ie->dr(nn);
          d2AA(i,offset)=d2udr2+2.0*dudr;
        }
      }
    }

    for(int i=0; i<nptcl; i++) {
      for(int nn=dist_ee->M[i]; nn<dist_ee->M[i]; nn++) {
        int j(dist_ee->J[nn]);
        RealType sep(dist_ee->r(nn));
        RealType rinv(dist_ee->rinv(nn));
        for(int m=0; m<eeBasis.size(); m++) {
          RealType psum=0,lapmi=0,lapmj=0;
          PosType grmi,grmj;
          for(int I=0; I<nc; I++) {
            const Matrix<RealType>& cblock(*C(m,CenterRef.GroupID[I]));
            int offsetI(ieBasisOffSet[I]);
            for(int k=0; k< ieBasisSize[I],kb=offsetI; k++,kb++) {
              RealType vall=0,valk=AA(i,kb);
              for(int l=0; l<ieBasisSize[I],lb=offsetI; l++,lb++) {
                vall += cblock(k,l)*AA(j,lb);
                grmj += valk*cblock(k,l)*dAA(j,lb);
                lapmj += valk*cblock(k,l)*d2AA(j,lb);
              }//l
              psum += valk*vall;
              grmi += dAA(i,kb)*vall;
              lampi += d2AA(i,kb)*vall;
            }//k
          }//I

          RealType bm =eeBasis[m]->evaluate(sep,dudr,d2udr2);
          dudr *= rinv;
          PosType dbm=dudr*dist_ee->dr(nn);
          RealType d2bm=d2udr2+2.0*dudr;

          LogValue += bm*psum;

          G[i] += bm*grmi-dbm*psum;
          G[j] += bm*grmj+dbm*psum;
          L[i] += b2bm*psum+bm*lapi;
          L[j] += b2bm*psum+bm*lapj;

        }
      }
    }
    return LogValue;

  }
Example #25
0
int main(int argc, char **argv) {

    using namespace ohmmsqmc;

    xmlDocPtr m_doc;
    xmlNodePtr m_root;
    xmlXPathContextPtr m_context;

    enum {SourceIndex  = DistanceTableData::SourceIndex};

    OHMMS::Controller->initialize(argc,argv);
    OhmmsInfo welcome(argc,argv,OHMMS::Controller->mycontext());

    ///project description
    OHMMS::ProjectData myProject;

    ///random number controller
    OHMMS::RandomNumberControl myRandomControl;

    if(argc>1) {
        // build an XML tree from a the file;
        LOGMSG("Opening file " << argv[1])
        m_doc = xmlParseFile(argv[1]);
        if (m_doc == NULL) {
            ERRORMSG("File " << argv[1] << " is invalid")
            xmlFreeDoc(m_doc);
            return 1;
        }
        // Check the document is of the right kind
        m_root = xmlDocGetRootElement(m_doc);
        if (m_root == NULL) {
            ERRORMSG("Empty document");
            xmlFreeDoc(m_doc);
            return 1;
        }
    } else {
        WARNMSG("No argument is given. Assume that  does not need an input file")
    }

    m_context = xmlXPathNewContext(m_doc);


    xmlXPathObjectPtr result
        = xmlXPathEvalExpression((const xmlChar*)"//project",m_context);
    if(xmlXPathNodeSetIsEmpty(result->nodesetval)) {
        WARNMSG("Project is not defined")
        myProject.reset();
    } else {
        myProject.put(result->nodesetval->nodeTab[0]);
    }
    xmlXPathFreeObject(result);
    //initialize the random number generator
    xmlNodePtr rptr = myRandomControl.initialize(m_context);
    if(rptr) {
        xmlAddChild(m_root,rptr);
    }

    ///the ions
    ParticleSet ion;

    MCWalkerConfiguration el;
    el.setName("e");
    int iu = el.Species.addSpecies("u");
    int id = el.Species.addSpecies("d");
    int icharge = el.Species.addAttribute("charge");
    el.Species(icharge,iu) = -1;
    el.Species(icharge,id) = -1;

    bool init_els = determineNumOfElectrons(el,m_context);

    result
        = xmlXPathEvalExpression((const xmlChar*)"//particleset",m_context);

    xmlNodePtr el_ptr=NULL, ion_ptr=NULL;
    for(int i=0; i<result->nodesetval->nodeNr; i++) {
        xmlNodePtr cur=result->nodesetval->nodeTab[i];
        xmlChar* aname= xmlGetProp(cur,(const xmlChar*)"name");
        if(aname) {
            char fc = aname[0];
            if(fc == 'e') {
                el_ptr=cur;
            }
            else if(fc == 'i') {
                ion_ptr=cur;
            }
        }
    }

    bool donotresize = false;
    if(init_els) {
        el.setName("e");
        XMLReport("The configuration for electrons is already determined by the wave function")
        donotresize = true;
    }
    if(el_ptr) {
        XMLParticleParser pread(el,donotresize);
        pread.put(el_ptr);
    }

    if(ion_ptr) {
        XMLParticleParser pread(ion);
        pread.put(ion_ptr);
    }

    xmlXPathFreeObject(result);

    if(!ion.getTotalNum()) {
        ion.setName("i");
        ion.create(1);
        ion.R[0] = 0.0;
    }

    //The ion-ion distance-table
    DistanceTableData* d_ii = DistanceTable::getTable(DistanceTable::add(ion));
    d_ii->create(1);
    d_ii->evaluate(ion);

    vector<double> Cut, Core;
    int Centers = ion.getTotalNum();
    //attribute id for cut
    int icut = ion.Species.addAttribute("cut");
    //store the max distance from atom
    Cut.resize(Centers);
    for(int iat=0; iat<Centers; iat++) {
        int id = ion.GroupID[iat];
        Cut[iat] = ion.Species(icut,id);
    }

    int icore = ion.Species.addAttribute("core");
    //store the max distance from atom
    Core.resize(Centers);
    for(int iat=0; iat<Centers; iat++) {
        Core[iat]=ion.Species(icore,ion.GroupID[iat]);
    }

    //3N-dimensional Gaussian
    ParticleSet::ParticlePos_t chi(el.getTotalNum());
    makeGaussRandom(chi);

    //determine if odd or even number of particles
    int irem = el.getTotalNum()%2;
    int ihalf = el.getTotalNum()/2;

    //assign the core
    int ncore(0);
    for(int iat=0; iat<Centers; iat++) {
        double sep=0.8*Cut[iat];
        for(int iel=0; iel<Core[iat]/2; iel++,ncore++) {
            el.R[ncore]=ion.R[iat]+sep*chi[ncore];
            el.R[ncore+ihalf]=ion.R[iat]+sep*chi[ncore+ihalf];
        }
    }

    int ipart = ncore;
    int isave_iat=0;

    for(int iat=0; iat<Centers; iat++) {
        for(int nn=d_ii->M[iat]; nn<d_ii->M[iat+1]; nn++) {
            double bondlength = d_ii->r(nn);
            int jat = d_ii->J[nn];
            //only assign if the half bond-length < cutoff
            if(bondlength < Cut[iat]+Cut[jat]) {
                if(ipart < ihalf) {
                    XMLReport("Assigning particles = " << ipart << " and " << ipart+ihalf)
                    /*place 2 electrons (an up and a down) at half
                      the bond-length plus a random number multiplied
                      by 10% of the bond-length*/
                    el.R[ipart] = ion.R[iat]+0.5*d_ii->dr(nn)+0.1*bondlength*chi[ipart];
                    el.R[ipart+ihalf] = ion.R[iat]+0.5*d_ii->dr(nn)+0.1*bondlength*chi[ipart+ihalf];
                    ipart++;
                    isave_iat = iat;
                }
            }
        }
    }

    //assign the last particle (if odd number of particles)
    int flag = 1;
    ipart = el.getTotalNum()-1;
    if(irem) {
        XMLReport("Assigning last particle.")
        for(int iat = isave_iat+1; iat<Centers; iat++) {
            for(int nn=d_ii->M[iat]; nn<d_ii->M[iat+1]; nn++) {
                double bondlength = d_ii->r(nn);
                if((0.5*bondlength < Cut[iat]) && flag) {
                    XMLReport("Assigning particle = " << ipart)
                    el.R[ipart] = ion.R[iat]+0.5*d_ii->dr(nn)+0.1*bondlength*chi[ipart];
                    flag = 0;
                }
            }
        }
    }

    cout << "Ionic configuration : " << ion.getName() << endl;
    ion.get(cout);

    cout << "Electronic configuration : " << el.getName() << endl;
    el.get(cout);

    string newxml(myProject.CurrentRoot());
    newxml.append(".ptcl.xml");
    ofstream ptcl_out(newxml.c_str());

    /*
      ofstream molmol("assign.xyz");

      molmol << Centers+el.getTotalNum() << endl;
      molmol << endl;

      for(int iat=0; iat<Centers; iat++)
      molmol << ion.Species.speciesName[ion.GroupID[iat]] << 0.5292*ion.R[iat] << endl;

      for(int ipart=0; ipart<el.getTotalNum(); ipart++)
      molmol << "He" << 0.5292*el.R[ipart] << endl;

      molmol.close();
    */

    xmlXPathFreeContext(m_context);
    xmlFreeDoc(m_doc);

    int nup = el.last(0);
    int ndown = el.last(1)-el.last(0);

    ptcl_out << "<?xml version=\"1.0\"?>" << endl;
    ptcl_out << "<particleset name=\"e\">" << endl;
    ptcl_out << "<group name=\"u\" size=\"" << nup << "\">" << endl;
    ptcl_out << "<parameter name=\"charge\">-1</parameter>" << endl;
    ptcl_out << "<attrib name=\"position\" datatype=\"posArray\">" << endl;
    for (int ipart=0; ipart<nup; ++ipart)
        ptcl_out << el.R[ipart] << endl;
    ptcl_out << "</attrib>" << endl;
    ptcl_out << "</group>" << endl;
    ptcl_out << "<group name=\"d\" size=\"" << ndown << "\">" << endl;
    ptcl_out << "<parameter name=\"charge\">-1</parameter>" << endl;
    ptcl_out << "<attrib name=\"position\" datatype=\"posArray\">" << endl;
    for (int ipart=nup; ipart<el.getTotalNum(); ++ipart)
        ptcl_out << el.R[ipart] << endl;
    ptcl_out << "</attrib>" << endl;
    ptcl_out << "</group>" << endl;
    ptcl_out << "</particleset>" << endl;

    OHMMS::Controller->finalize();
    return 0;
}