QMCPACK
BackflowBuilder Class Reference
+ Collaboration diagram for BackflowBuilder:

Public Member Functions

 BackflowBuilder (ParticleSet &p, const PSetMap &pool)
 
std::unique_ptr< BackflowTransformationbuildBackflowTransformation (xmlNodePtr cur)
 

Public Attributes

RealType cutOff
 

Private Types

using RealType = BackflowFunctionBase::RealType
 
using HandlerType = LRHandlerBase
 
using GridType = LinearGrid< RealType >
 
using PSetMap = std::map< std::string, const std::unique_ptr< ParticleSet > >
 

Private Member Functions

std::unique_ptr< BackflowFunctionBaseaddOneBody (xmlNodePtr cur)
 
std::unique_ptr< BackflowFunctionBaseaddTwoBody (xmlNodePtr cur)
 
std::unique_ptr< BackflowFunctionBaseaddRPA (xmlNodePtr cur)
 
void makeShortRange_oneBody ()
 
void makeLongRange_oneBody ()
 
void makeShortRange_twoBody (xmlNodePtr cur, Backflow_ee< BsplineFunctor< RealType >> *tbf, std::vector< int > &offsets)
 
void makeLongRange_twoBody (xmlNodePtr cur, Backflow_ee_kSpace *tbf, std::vector< int > &offsets)
 

Private Attributes

ParticleSettargetPtcl
 
const PSetMapptclPool
 
bool IgnoreSpin
 
RealType Rs
 
RealType Kc
 
RealType Rcut
 
bool OneBody
 
bool TwoBody
 
HandlerTypemyHandler
 

Detailed Description

Definition at line 34 of file BackflowBuilder.h.

Member Typedef Documentation

◆ GridType

using GridType = LinearGrid<RealType>
private

Definition at line 38 of file BackflowBuilder.h.

◆ HandlerType

using HandlerType = LRHandlerBase
private

Definition at line 37 of file BackflowBuilder.h.

◆ PSetMap

using PSetMap = std::map<std::string, const std::unique_ptr<ParticleSet> >
private

Definition at line 39 of file BackflowBuilder.h.

◆ RealType

Definition at line 36 of file BackflowBuilder.h.

Constructor & Destructor Documentation

◆ BackflowBuilder()

BackflowBuilder ( ParticleSet p,
const PSetMap pool 
)

Definition at line 43 of file BackflowBuilder.cpp.

43  : cutOff(1.0), targetPtcl(els), ptclPool(pool)
44 {}

Member Function Documentation

◆ addOneBody()

std::unique_ptr< BackflowFunctionBase > addOneBody ( xmlNodePtr  cur)
private

Definition at line 94 of file BackflowBuilder.cpp.

References OhmmsAttributeSet::add(), APP_ABORT, qmcplusplus::app_log(), optimize::BACKFLOW_P, BackflowBuilder::cutOff, qmcplusplus::extractCoefficientsID(), SpeciesSet::findSpecies(), ParticleSet::get(), ParticleSet::getLattice(), getNodeName(), ParticleSet::getSpeciesSet(), SpeciesSet::getTotalNum(), ParticleSet::getTotalNum(), ParticleSet::GroupID, BackflowBuilder::ptclPool, OhmmsAttributeSet::put(), putContent(), and BackflowBuilder::targetPtcl.

Referenced by BackflowBuilder::buildBackflowTransformation().

95 {
96  OhmmsAttributeSet spoAttrib;
97  std::string source("none");
98  std::string name("bf0");
99  std::string type("none");
100  std::string funct("Gaussian");
101  std::string unique("no");
102  std::string spin("no"); //add spin attribute, with default spin="no"
103  spoAttrib.add(name, "name");
104  spoAttrib.add(type, "type");
105  spoAttrib.add(source, "source");
106  spoAttrib.add(funct, "function");
107  spoAttrib.add(unique, "unique");
108  spoAttrib.add(spin, "spin");
109  spoAttrib.put(cur);
110  ParticleSet* ions = 0;
111  auto pit(ptclPool.find(source));
112  if (pit == ptclPool.end())
113  {
114  APP_ABORT("Missing backflow/@source.");
115  }
116  else
117  ions = pit->second.get();
118  app_log() << "Adding electron-Ion backflow for source:" << source << " \n";
119  std::unique_ptr<BackflowFunctionBase> tbf;
120  int nIons = ions->getTotalNum();
121  SpeciesSet& sSet = ions->getSpeciesSet();
122  SpeciesSet& tSet = targetPtcl.getSpeciesSet();
123  int numSpecies = sSet.getTotalNum();
124  if (spin == "yes")
125  {
126  APP_ABORT("Spin one body backflow not supported");
127  //if (funct != "Bspline")
128  // APP_ABORT("DON'T KNOW WHAT TO DO YET"); //will template this
129  //Backflow_eI_spin<BsplineFunctor<RealType>>* tbf1 =
130  // new Backflow_eI_spin<BsplineFunctor<RealType>>(*ions, targetPtcl);
131  //tbf1->numParams = 0;
132  //xmlNodePtr cur1 = cur->children;
133  //while (cur1 != NULL)
134  //{
135  // std::string cname (getNodeName(cur1));
136  // if (cname == "correlation")
137  // {
138  // RealType my_cusp = 0.0;
139  // std::string speciesA("0");
140  // std::string speciesB("e"); //assume electrons
141  // OhmmsAttributeSet anAttrib;
142  // anAttrib.add(speciesA, "elementType");
143  // anAttrib.add(speciesA, "speciesA");
144  // anAttrib.add(speciesB, "speciesB");
145  // anAttrib.add(my_cusp, "cusp");
146  // anAttrib.put(cur1);
147  // BsplineFunctor<RealType>* afunc = new BsplineFunctor<RealType>(my_cusp);
148  // afunc->elementType = speciesA;
149  // int ig = sSet.findSpecies(speciesA);
150  // afunc->cutoff_radius = ions->Lattice.WignerSeitzRadius;
151  // int jg = -1;
152  // if (speciesB.size())
153  // jg = tSet.findSpecies(speciesB);
154  // if (ig < numSpecies)
155  // {
156  // //ignore
157  // afunc->put(cur1);
158  // tbf1->addFunc(ig, afunc, jg);
159  // //WHAT IS THIS
160  // afunc->myVars.setParameterType(optimize::BACKFLOW_P);
161  // tbf1->myVars.insertFrom(afunc->myVars);
162  // tbf1->myVars.resetIndex();
163  // afunc->myVars.getIndex(tbf1->myVars);
164  // tbf1->numParams = tbf1->myVars.size();
165  // int offset_a = tbf1->myVars.getIndex(afunc->myVars.name(0));
166  // if (jg < 0)
167  // {
168  // for (int jjg = 0; jjg < targetPtcl.groups(); ++jjg)
169  // tbf1->offsetPrms(ig, jjg) = offset_a;
170  // }
171  // else
172  // tbf1->offsetPrms(ig, jg) = offset_a;
173  // }
174  // }
175  // cur1 = cur1->next;
176  //}
177  ////synch parameters
178  //tbf1->resetParameters(tbf1->myVars);
179  //tbf1->derivs.resize(tbf1->numParams);
180  //tbf = tbf1;
181  }
182  else //keep original implementation
183  {
184  std::vector<xmlNodePtr> funs;
185  std::vector<int> ion2functor(nIons, -1);
186  std::vector<RealType> cusps;
187  xmlNodePtr curRoot = cur;
188  std::string cname;
189  cur = curRoot->children;
190  while (cur != NULL)
191  {
192  std::string cname(getNodeName(cur));
193  if (cname == "correlation")
194  {
195  RealType my_cusp = 0.0;
196  std::string elementType("none");
197  OhmmsAttributeSet anAttrib;
198  anAttrib.add(elementType, "elementType");
199  anAttrib.add(my_cusp, "cusp");
200  anAttrib.put(cur);
201  funs.push_back(cur);
202  cusps.push_back(my_cusp);
203  if (unique == "yes") // look for <index> block, and map based on that
204  {
205  xmlNodePtr kids = cur;
206  kids = cur->children;
207  while (kids != NULL)
208  {
209  std::string aname(getNodeName(kids));
210  if (aname == "index")
211  {
212  std::vector<int> pos;
213  putContent(pos, kids);
214  for (int i = 0; i < pos.size(); i++)
215  {
216  app_log() << "Adding backflow transformation of type " << funs.size() - 1 << " for atom " << pos[i]
217  << ".\n";
218  ion2functor[pos[i]] = funs.size() - 1;
219  }
220  }
221  kids = kids->next;
222  }
223  }
224  else
225  // map based on elementType
226  {
227  int ig = sSet.findSpecies(elementType);
228  if (ig < numSpecies)
229  {
230  for (int i = 0; i < ion2functor.size(); i++)
231  if (ions->GroupID[i] == ig)
232  {
233  ion2functor[i] = funs.size() - 1;
234  app_log() << "Adding backflow transformation of element type " << elementType << " for atom " << i
235  << ".\n";
236  }
237  }
238  }
239  }
240  cur = cur->next;
241  }
242  if (funct == "Bspline")
243  {
244  app_log() << "Using BsplineFunctor type. \n";
245  auto dum = std::make_unique<Backflow_eI<BsplineFunctor<RealType>>>(*ions, targetPtcl);
246  auto& num_params = dum->numParams;
247  num_params = 0;
248  std::vector<int> offsets;
249  for (int i = 0; i < funs.size(); i++)
250  {
251  // BsplineFunctor<RealType> *bsp = new BsplineFunctor<RealType>(cusps[i]);
252  auto bsp = std::make_unique<BsplineFunctor<RealType>>(extractCoefficientsID(funs[i]));
253  bsp->cutoff_radius = targetPtcl.getLattice().WignerSeitzRadius;
254  bsp->put(funs[i]);
255  if (bsp->cutoff_radius > cutOff)
256  cutOff = bsp->cutoff_radius;
257  bsp->myVars.setParameterType(optimize::BACKFLOW_P);
258  //bsp->print();
259  offsets.push_back(num_params);
260  num_params += bsp->NumParams;
261  dum->uniqueRadFun.push_back(std::move(bsp));
262  }
263  dum->derivs.resize(num_params);
264  dum->offsetPrms.resize(nIons);
265  dum->RadFun.resize(nIons);
266  for (int i = 0; i < ion2functor.size(); i++)
267  {
268  if (ion2functor[i] < 0 || ion2functor[i] >= funs.size())
269  {
270  APP_ABORT("backflowTransformation::put() ion not mapped to radial function.\n");
271  }
272  dum->RadFun[i] = dum->uniqueRadFun[ion2functor[i]].get();
273  dum->offsetPrms[i] = offsets[ion2functor[i]];
274  }
275  tbf = std::move(dum);
276  }
277  else
278  {
279  APP_ABORT("Unknown function type in e-I BF Transformation.\n");
280  }
281  } //spin="no"
282  return tbf;
283 }
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
int getTotalNum() const
return the number of species
Definition: SpeciesSet.h:55
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
QMCTraits::RealType RealType
const auto & getLattice() const
Definition: ParticleSet.h:251
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
std::string getNodeName(xmlNodePtr cur)
Definition: libxmldefs.cpp:15

◆ addRPA()

std::unique_ptr< BackflowFunctionBase > addRPA ( xmlNodePtr  cur)
private

Definition at line 368 of file BackflowBuilder.cpp.

References OhmmsAttributeSet::add(), APP_ABORT, qmcplusplus::app_log(), LRHandlerBase::Breakup(), BLAS::done, LRHandlerBase::Fk, ParticleSet::getLattice(), getNodeName(), ParticleSet::getSimulationCell(), ParticleSet::getTotalNum(), BackflowBuilder::Kc, BackflowBuilder::makeLongRange_twoBody(), BackflowBuilder::makeShortRange_twoBody(), LRHandlerBase::MaxKshell, BackflowBuilder::myHandler, qmcplusplus::pow(), OhmmsAttributeSet::put(), BackflowBuilder::Rs, Vector< T, Alloc >::size(), and BackflowBuilder::targetPtcl.

Referenced by BackflowBuilder::buildBackflowTransformation().

369 {
370  ReportEngine PRE("BackflowBuilder", "addRPA");
371  /*
372  std::string useL="yes";
373  std::string useS="yes";
374 
375  OhmmsAttributeSet a;
376  a.add(useL,"longrange");
377  a.add(useS,"shortrange");
378  a.put(cur);
379  */
380  Rs = -1.0;
381  Kc = -1.0;
382  OhmmsAttributeSet anAttrib0;
383  anAttrib0.add(Rs, "rs");
384  anAttrib0.add(Kc, "kc");
385  anAttrib0.put(cur);
386  //ParameterSet params;
387  //params.add(Rs,"rs","RealType");
388  //params.add(Kc,"kc","RealType");
389  //params.add(Kc,"Kc","RealType");
390  //params.put(cur);
391  RealType tlen =
392  std::pow(3.0 / 4.0 / M_PI * targetPtcl.getLattice().Volume / static_cast<RealType>(targetPtcl.getTotalNum()),
393  1.0 / 3.0);
394  if (Rs < 0)
395  {
396  if (targetPtcl.getLattice().SuperCellEnum)
397  {
398  Rs = tlen;
399  }
400  else
401  {
402  std::cout << " Error finding rs. Is this an open system?!" << std::endl;
403  Rs = 100.0;
404  }
405  }
406  int indx = targetPtcl.getSimulationCell().getKLists().ksq.size() - 1;
407  RealType Kc_max = std::pow(targetPtcl.getSimulationCell().getKLists().ksq[indx], 0.5);
408  if (Kc < 0)
409  {
410  Kc = 2.0 * std::pow(2.25 * M_PI, 1.0 / 3.0) / tlen;
411  }
412  if (Kc > Kc_max)
413  {
414  Kc = Kc_max;
415  app_log() << " BackflowBuilderBuilder Kc set too high. Resetting to the maximum value" << std::endl;
416  }
417  app_log() << " BackflowBuilderBuilder Rs = " << Rs << " Kc= " << Kc << std::endl;
418  // mmorales: LRRPABFeeHandlerTemp is a copy of LRRPAHandlerTemp for now,
419  // in case I need to specialize it later on
420  myHandler = new LRRPABFeeHandlerTemp<RPABFeeBreakup<RealType>, LPQHIBasis>(targetPtcl, Kc);
422  app_log() << " Maximum K shell " << myHandler->MaxKshell << std::endl;
423  app_log() << " Number of k vectors " << myHandler->Fk.size() << std::endl;
424  std::vector<int> offsetsSR;
425  std::vector<int> offsetsLR;
426  std::unique_ptr<Backflow_ee<BsplineFunctor<RealType>>> tbf;
427  Backflow_ee_kSpace* tbfks = 0;
428  // now look for components
429  cur = cur->children;
430  while (cur != NULL)
431  {
432  std::string cname(getNodeName(cur));
433  if (cname == "correlation")
434  {
435  std::string type = "none";
436  OhmmsAttributeSet anAttrib;
437  anAttrib.add(type, "type");
438  anAttrib.put(cur);
439  if (type == "shortrange")
440  {
441  if (tbf == nullptr)
442  {
443  tbf = std::make_unique<Backflow_ee<BsplineFunctor<RealType>>>(targetPtcl, targetPtcl);
444  }
445  makeShortRange_twoBody(cur, tbf.get(), offsetsSR);
446  }
447  else if (type == "longrange")
448  {
449  if (tbfks == 0)
450  {
451  tbfks = new Backflow_ee_kSpace(targetPtcl, targetPtcl);
452  }
453  else
454  {
455  APP_ABORT("Only a single LongRange RPAbackflow allowed for now. ");
456  }
457  makeLongRange_twoBody(cur, tbfks, offsetsLR);
458  }
459  else
460  {
461  APP_ABORT("Unknown rpa backflow type in <correlation/>.");
462  }
463  }
464  cur = cur->next;
465  }
466  if (tbf != nullptr)
467  {
468  tbf->derivs.resize(tbf->numParams);
469  // setup offsets
470  // could keep a std::map<std::pair<>,int>
471  for (int i = 0; i < tbf->RadFun.size(); i++)
472  {
473  bool done = false;
474  for (int k = 0; k < tbf->uniqueRadFun.size(); k++)
475  {
476  if (tbf->RadFun[i] == tbf->uniqueRadFun[k].get())
477  {
478  done = true;
479  // how do I calculate the offset now???
480  tbf->offsetPrms[i] = offsetsSR[k];
481  break;
482  }
483  }
484  if (!done)
485  {
486  APP_ABORT("Error creating Backflow_ee object in addRPA. \n");
487  }
488  }
489  }
490  return tbf;
491 }
size_t getTotalNum() const
Definition: ParticleSet.h:493
virtual void Breakup(ParticleSet &ref, mRealType rs_in)=0
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
DECLARE_COULOMB_TYPES int MaxKshell
Maxkimum Kshell for the given Kc.
Definition: LRHandlerBase.h:35
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
void makeShortRange_twoBody(xmlNodePtr cur, Backflow_ee< BsplineFunctor< RealType >> *tbf, std::vector< int > &offsets)
size_type size() const
return the current size
Definition: OhmmsVector.h:162
void makeLongRange_twoBody(xmlNodePtr cur, Backflow_ee_kSpace *tbf, std::vector< int > &offsets)
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
Vector< mRealType > Fk
Fourier component for all the k-point.
Definition: LRHandlerBase.h:41
QMCTraits::RealType RealType
constexpr double done
Definition: BLAS.hpp:48
const auto & getLattice() const
Definition: ParticleSet.h:251
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
std::string getNodeName(xmlNodePtr cur)
Definition: libxmldefs.cpp:15

◆ addTwoBody()

std::unique_ptr< BackflowFunctionBase > addTwoBody ( xmlNodePtr  cur)
private

Definition at line 285 of file BackflowBuilder.cpp.

References OhmmsAttributeSet::add(), APP_ABORT, qmcplusplus::app_log(), optimize::BACKFLOW_P, BackflowBuilder::cutOff, BLAS::done, qmcplusplus::extractCoefficientsID(), ParticleSet::getLattice(), getNodeName(), ParticleSet::getSpeciesSet(), OhmmsAttributeSet::put(), and BackflowBuilder::targetPtcl.

Referenced by BackflowBuilder::buildBackflowTransformation().

286 {
287  app_log() << "Adding electron-electron backflow. \n";
288  OhmmsAttributeSet trAttrib;
289  std::string source("none");
290  std::string name("bf0");
291  std::string type("none");
292  std::string funct("Bspline");
293  trAttrib.add(name, "name");
294  trAttrib.add(funct, "function");
295  trAttrib.put(cur);
296  xmlNodePtr curRoot = cur;
297  //BackflowFunctionBase *tbf = (BackflowFunctionBase *) new Backflow_ee<BsplineFunctor<RealType> >(targetPtcl,targetPtcl);
298  auto tbf = std::make_unique<Backflow_ee<BsplineFunctor<RealType>>>(targetPtcl, targetPtcl);
299  SpeciesSet& species(targetPtcl.getSpeciesSet());
300  std::vector<int> offsets;
301  if (funct == "Bspline")
302  {
303  app_log() << "Using BsplineFunctor type. \n";
304  // BsplineFunctor<RealType> *bsp = new BsplineFunctor<RealType>(cusp);
305  cur = curRoot->children;
306  while (cur != NULL)
307  {
308  std::string cname(getNodeName(cur));
309  if (cname == "correlation")
310  {
311  RealType cusp = 0;
312  std::string spA(species.speciesName[0]);
313  std::string spB(species.speciesName[0]);
314  OhmmsAttributeSet anAttrib;
315  anAttrib.add(cusp, "cusp");
316  anAttrib.add(spA, "speciesA");
317  anAttrib.add(spB, "speciesB");
318  anAttrib.add(cusp, "cusp");
319  anAttrib.put(cur);
320  int ia = species.findSpecies(spA);
321  int ib = species.findSpecies(spB);
322  if (ia == species.size() || ib == species.size())
323  {
324  APP_ABORT("Failed. Species are incorrect in e-e backflow.");
325  }
326  app_log() << "Adding radial component for species: " << spA << " " << spB << " " << ia << " " << ib
327  << std::endl;
328  auto bsp = std::make_unique<BsplineFunctor<RealType>>(extractCoefficientsID(cur));
329  bsp->cutoff_radius = targetPtcl.getLattice().WignerSeitzRadius;
330  bsp->put(cur);
331  if (bsp->cutoff_radius > cutOff)
332  cutOff = bsp->cutoff_radius;
333  bsp->myVars.setParameterType(optimize::BACKFLOW_P);
334  offsets.push_back(tbf->numParams);
335  tbf->numParams += bsp->NumParams;
336  tbf->addFunc(ia, ib, std::move(bsp));
337  }
338  cur = cur->next;
339  }
340  tbf->derivs.resize(tbf->numParams);
341  // setup offsets
342  // could keep a std::map<std::pair<>,int>
343  for (int i = 0; i < tbf->RadFun.size(); i++)
344  {
345  bool done = false;
346  for (int k = 0; k < tbf->uniqueRadFun.size(); k++)
347  {
348  if (tbf->RadFun[i] == tbf->uniqueRadFun[k].get())
349  {
350  done = true;
351  tbf->offsetPrms[i] = offsets[k];
352  break;
353  }
354  }
355  if (!done)
356  {
357  APP_ABORT("Error creating Backflow_ee object. \n");
358  }
359  }
360  }
361  else
362  {
363  APP_ABORT("Unknown function type in e-e BF Transformation.\n");
364  }
365  return tbf;
366 }
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
QMCTraits::RealType RealType
constexpr double done
Definition: BLAS.hpp:48
const auto & getLattice() const
Definition: ParticleSet.h:251
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
std::string getNodeName(xmlNodePtr cur)
Definition: libxmldefs.cpp:15

◆ buildBackflowTransformation()

std::unique_ptr< BackflowTransformation > buildBackflowTransformation ( xmlNodePtr  cur)

Definition at line 46 of file BackflowBuilder.cpp.

References OhmmsAttributeSet::add(), BackflowBuilder::addOneBody(), BackflowBuilder::addRPA(), BackflowBuilder::addTwoBody(), APP_ABORT, qmcplusplus::app_log(), BackflowBuilder::cutOff, getNodeName(), OhmmsAttributeSet::put(), and BackflowBuilder::targetPtcl.

Referenced by SlaterDetBuilder::buildComponent().

47 {
48  xmlNodePtr curRoot = cur;
49  auto BFTrans = std::make_unique<BackflowTransformation>(targetPtcl);
50  cur = curRoot->children;
51  while (cur != NULL)
52  {
53  std::string cname(getNodeName(cur));
54  if (cname == "transf" || cname == "transformation")
55  {
56  OhmmsAttributeSet spoAttrib;
57  std::string source("none");
58  std::string name("bf0");
59  std::string type("none");
60  spoAttrib.add(name, "name");
61  spoAttrib.add(type, "type");
62  spoAttrib.add(source, "source");
63  spoAttrib.put(cur);
64  BFTrans->sources[source] = BFTrans->names.size();
65  BFTrans->names.push_back(name);
66  if (type == "e-e")
67  {
68  BFTrans->bfFuns.push_back(addTwoBody(cur));
69  }
70  else if (type == "e-e-I")
71  {
72  APP_ABORT("e-e-I backflow is not implemented yet. \n");
73  }
74  else if (type == "e-I")
75  {
76  BFTrans->bfFuns.push_back(addOneBody(cur));
77  }
78  else if (type == "rpa")
79  {
80  app_log() << "Adding RPA backflow functions. \n";
81  BFTrans->bfFuns.push_back(addRPA(cur));
82  }
83  else
84  {
85  APP_ABORT("Unknown backflow type. \n");
86  }
87  }
88  cur = cur->next;
89  }
90  BFTrans->cutOff = cutOff;
91  return BFTrans;
92 }
std::unique_ptr< BackflowFunctionBase > addOneBody(xmlNodePtr cur)
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::unique_ptr< BackflowFunctionBase > addTwoBody(xmlNodePtr cur)
std::unique_ptr< BackflowFunctionBase > addRPA(xmlNodePtr cur)
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
std::string getNodeName(xmlNodePtr cur)
Definition: libxmldefs.cpp:15

◆ makeLongRange_oneBody()

void makeLongRange_oneBody ( )
private

Definition at line 493 of file BackflowBuilder.cpp.

493 {}

◆ makeLongRange_twoBody()

void makeLongRange_twoBody ( xmlNodePtr  cur,
Backflow_ee_kSpace tbf,
std::vector< int > &  offsets 
)
private

Definition at line 494 of file BackflowBuilder.cpp.

References OhmmsAttributeSet::add(), Backflow_ee_kSpace::addFunc(), APP_ABORT, qmcplusplus::app_log(), optimize::BACKFLOW_P, OHMMS::Controller, LRHandlerBase::Fk_symm, ParticleSet::getSimulationCell(), ParticleSet::getSpeciesSet(), Backflow_ee_kSpace::initialize(), BackflowBuilder::myHandler, Backflow_ee_kSpace::myVars, Backflow_ee_kSpace::NumKShells, Backflow_ee_kSpace::numParams, Backflow_ee_kSpace::Optimize, OhmmsAttributeSet::put(), putContent(), qmcplusplus::rank, VariableSet::setParameterType(), Vector< T, Alloc >::size(), qmcplusplus::sqrt(), and BackflowBuilder::targetPtcl.

Referenced by BackflowBuilder::addRPA().

495 {
496  int size = -1;
497  SpeciesSet& species(targetPtcl.getSpeciesSet());
498  std::string spA(species.speciesName[0]);
499  std::string spB(species.speciesName[0]);
500  std::string init = "yes";
501  OhmmsAttributeSet anAttrib;
502  anAttrib.add(size, "size");
503  anAttrib.add(init, "init");
504  anAttrib.add(init, "initialize");
505  anAttrib.add(spA, "speciesA");
506  anAttrib.add(spB, "speciesB");
507  anAttrib.put(cur);
508  int ia = species.findSpecies(spA);
509  int ib = species.findSpecies(spB);
510  if (ia == species.size() || ib == species.size())
511  {
512  APP_ABORT("Failed. Species are incorrect in longrange RPA backflow.");
513  }
514  app_log() << "Adding RPABackflow longrange component for species: " << spA << " " << spB << " " << ia << " " << ib
515  << std::endl;
516  // Now read coefficents
517  xmlNodePtr xmlCoefs = cur->xmlChildrenNode;
518  while (xmlCoefs != NULL)
519  {
520  std::string cname((const char*)xmlCoefs->name);
521  if (cname == "coefficients")
522  {
523  std::string type("0"), id("0");
524  std::string optimize("no");
525  OhmmsAttributeSet cAttrib;
526  cAttrib.add(id, "id");
527  cAttrib.add(type, "type");
528  cAttrib.add(optimize, "optimize");
529  cAttrib.put(xmlCoefs);
530  if (type != "Array")
531  {
532  APP_ABORT("Unknown correlation type " + type + " in Backflow.");
533  }
534  if (optimize == "true" || optimize == "yes")
535  tbfks->Optimize = true;
536  std::vector<RealType> yk;
537  if (init == "true" || init == "yes")
538  {
539  app_log() << "Initializing k-space backflow function with RPA form.";
540  yk.resize(myHandler->Fk_symm.size());
541  for (int i = 0; i < yk.size(); i++)
542  yk[i] = myHandler->Fk_symm[i];
543  }
544  else
545  {
546  app_log() << "Reading k-space backflow function from xml.";
547  putContent(yk, xmlCoefs);
548  }
549  tbfks->initialize(targetPtcl, yk);
550  tbfks->myVars.setParameterType(optimize::BACKFLOW_P);
551  tbfks->addFunc(ia, ib);
552  offsets.push_back(tbfks->numParams);
553  if (OHMMS::Controller->rank() == 0)
554  {
555  std::array<char, 16> fname;
556  if (std::snprintf(fname.data(), fname.size(), "RPABFee-LR.%s.dat", (spA + spB).c_str()) < 0)
557  throw std::runtime_error("Error generating filename");
558 
559  std::ofstream fout(fname.data());
560  fout.setf(std::ios::scientific, std::ios::floatfield);
561  fout << "# Backflow longrange \n";
562  for (int i = 0; i < tbfks->NumKShells; i++)
563  {
565  .getKLists()
566  .ksq[targetPtcl.getSimulationCell().getKLists().kshell[i]])
567  << " " << yk[i] << std::endl;
568  }
569  fout.close();
570  }
571  }
572  xmlCoefs = xmlCoefs->next;
573  }
574 }
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
size_type size() const
return the current size
Definition: OhmmsVector.h:162
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
Vector< mRealType > Fk_symm
Fourier component for each k-shell.
Definition: LRHandlerBase.h:49

◆ makeShortRange_oneBody()

void makeShortRange_oneBody ( )
private

Definition at line 576 of file BackflowBuilder.cpp.

576 {}

◆ makeShortRange_twoBody()

void makeShortRange_twoBody ( xmlNodePtr  cur,
Backflow_ee< BsplineFunctor< RealType >> *  tbf,
std::vector< int > &  offsets 
)
private

Definition at line 577 of file BackflowBuilder.cpp.

References OhmmsAttributeSet::add(), APP_ABORT, qmcplusplus::app_log(), optimize::BACKFLOW_P, BackflowBuilder::cutOff, LRHandlerBase::evaluate(), qmcplusplus::exp(), qmcplusplus::extractCoefficientsID(), LRHandlerBase::get_rc(), ParticleSet::getSpeciesSet(), qmcplusplus::LinearFit(), BackflowBuilder::myHandler, OhmmsAttributeSet::put(), BackflowBuilder::Rcut, LinearGrid< T, CT >::set(), OneDimGridBase< T, CT >::size(), and BackflowBuilder::targetPtcl.

Referenced by BackflowBuilder::addRPA().

580 {
581  int size = -1;
582  SpeciesSet& species(targetPtcl.getSpeciesSet());
583  std::string spA(species.speciesName[0]);
584  std::string spB(species.speciesName[0]);
585  RealType cusp = 0.0;
586  std::string init = "yes";
587  OhmmsAttributeSet anAttrib;
588  anAttrib.add(cusp, "cusp");
589  anAttrib.add(size, "size");
590  anAttrib.add(init, "init");
591  anAttrib.add(init, "initialize");
592  anAttrib.add(spA, "speciesA");
593  anAttrib.add(spB, "speciesB");
594  anAttrib.put(cur);
595  int ia = species.findSpecies(spA);
596  int ib = species.findSpecies(spB);
597  if (ia == species.size() || ib == species.size())
598  {
599  APP_ABORT("Failed. Species are incorrect in e-e backflow.");
600  }
601  app_log() << "Adding radial component for species: " << spA << " " << spB << " " << ia << " " << ib << std::endl;
602  // Now read coefficents
603  xmlNodePtr xmlCoefs = cur->xmlChildrenNode;
604  while (xmlCoefs != NULL)
605  {
606  std::string cname((const char*)xmlCoefs->name);
607  if (cname == "coefficients")
608  {
609  std::string type("0"), id("0");
610  std::string optimize("no");
611  OhmmsAttributeSet cAttrib;
612  cAttrib.add(id, "id");
613  cAttrib.add(type, "type");
614  cAttrib.add(optimize, "optimize");
615  cAttrib.put(xmlCoefs);
616  if (type != "Array")
617  {
618  APP_ABORT("Unknown correlation type " + type + " in Backflow.");
619  }
620  auto bsp = std::make_unique<BsplineFunctor<RealType>>(extractCoefficientsID(cur));
621  if (init == "true" || init == "yes")
622  {
623  app_log() << "Initializing backflow radial functions with RPA.";
624  Rcut = myHandler->get_rc() - 0.01;
625  GridType* myGrid = new GridType;
626  int npts = static_cast<int>(Rcut / 0.01) + 3;
627  myGrid->set(0, Rcut - 0.01, npts);
628  //create the numerical functor
629  std::vector<RealType> x(myGrid->size()), y(myGrid->size());
630  // x[0]=(*myGrid)(0);
631  // RealType x0=x[0];
632  // if(x0 < 1.0e-6) x0 = 1.0e-6;
633  //// y[0]=-myHandler->srDf(x0,1.0/x0)/x0;
634  // y[0]=myHandler->evaluate(x0,1.0/x0);
635  for (int i = 0; i < myGrid->size(); i++)
636  {
637  x[i] = (*myGrid)(i);
638  // y[i]=-myHandler->srDf(x[i],1.0/x[i])/x[i];
639  y[i] = myHandler->evaluate(x[i], 0.0);
640  }
641  app_log() << "Rcut,npts:" << Rcut << " " << npts << " " << x[myGrid->size() - 1] << std::endl;
642  //fit potential to gaussians
643  int nfitgaussians(3);
644  Matrix<RealType> basis(myGrid->size(), nfitgaussians);
645  for (int i = 0; i < npts; i++)
646  {
647  RealType r = x[i];
648  for (int j = 0; j < nfitgaussians; j++)
649  basis(i, j) = std::exp(-r * r / ((j + 1) * Rcut * Rcut)) - std::exp(-1 / (j + 1));
650  }
651  std::vector<RealType> gb(nfitgaussians);
652  LinearFit(y, basis, gb);
653  //spline deriv of gaussian fit
654  for (int i = 0; i < myGrid->size(); i++)
655  {
656  RealType r = x[i];
657  y[i] = 0;
658  for (int j = 0; j < nfitgaussians; j++)
659  y[i] += gb[j] * (2.0 / ((j + 1) * Rcut * Rcut) * std::exp(-r * r / ((j + 1) * Rcut * Rcut)));
660  }
661  // RealType y1_c(0),y2_c(0);
662  // for (int j=0; j<nfitgaussians; j++) y1_c+=gb[j]*(std::exp(-x[1]*x[1]/((j+1)*Rcut*Rcut)));
663  // for (int j=0; j<nfitgaussians; j++) y2_c+=gb[j]*(std::exp(-x[2]*x[2]/((j+1)*Rcut*Rcut)));
664  //make a temp functor to ensure right BC's (Necessary?)
665  auto tmp_bsp = std::make_unique<BsplineFunctor<RealType>>("tmp_bsp");
666  tmp_bsp->initialize(12, x, y, cusp, Rcut, id, optimize);
667  // tmp_bsp->print(app_log());
668  for (int i = 0; i < myGrid->size(); i++)
669  {
670  y[i] = tmp_bsp->f(x[i]);
671  }
672  //make functor for backflow
673  bsp->initialize(size, x, y, cusp, Rcut, id, optimize);
674  }
675  else
676  {
677  bsp->put(cur);
678  }
679  if (bsp->cutoff_radius > cutOff)
680  cutOff = bsp->cutoff_radius;
681  bsp->myVars.setParameterType(optimize::BACKFLOW_P);
682  tbf->addFunc(ia, ib, std::move(bsp));
683  offsets.push_back(tbf->numParams);
684  tbf->numParams += bsp->NumParams;
685  }
686  xmlCoefs = xmlCoefs->next;
687  }
688 }
void set(T ri, T rf, int n) override
Set the grid given the parameters.
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
mRealType evaluate(const std::vector< int > &kshell, const pRealType *restrict rk1_r, const pRealType *restrict rk1_i, const pRealType *restrict rk2_r, const pRealType *restrict rk2_i) const
evaluate
Definition: LRHandlerBase.h:93
LinearGrid< RealType > GridType
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
QMCTraits::RealType RealType
GridType
The different types of grids that we currently allow.
Definition: Grid.h:29
mRealType get_rc() const
Definition: LRHandlerBase.h:69
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
void LinearFit(std::vector< T > &y, Matrix< T > &A, std::vector< T > &coefs)
Definition: LinearFit.h:28

Member Data Documentation

◆ cutOff

◆ IgnoreSpin

bool IgnoreSpin
private

Definition at line 51 of file BackflowBuilder.h.

◆ Kc

RealType Kc
private

Definition at line 53 of file BackflowBuilder.h.

Referenced by BackflowBuilder::addRPA().

◆ myHandler

◆ OneBody

bool OneBody
private

Definition at line 55 of file BackflowBuilder.h.

◆ ptclPool

const PSetMap& ptclPool
private

Definition at line 50 of file BackflowBuilder.h.

Referenced by BackflowBuilder::addOneBody().

◆ Rcut

RealType Rcut
private

Definition at line 54 of file BackflowBuilder.h.

Referenced by BackflowBuilder::makeShortRange_twoBody().

◆ Rs

RealType Rs
private

Definition at line 52 of file BackflowBuilder.h.

Referenced by BackflowBuilder::addRPA().

◆ targetPtcl

◆ TwoBody

bool TwoBody
private

Definition at line 56 of file BackflowBuilder.h.


The documentation for this class was generated from the following files: