48 xmlNodePtr curRoot = cur;
49 auto BFTrans = std::make_unique<BackflowTransformation>(
targetPtcl);
50 cur = curRoot->children;
54 if (cname ==
"transf" || cname ==
"transformation")
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");
64 BFTrans->sources[source] = BFTrans->names.size();
65 BFTrans->names.push_back(name);
70 else if (type ==
"e-e-I")
72 APP_ABORT(
"e-e-I backflow is not implemented yet. \n");
74 else if (type ==
"e-I")
78 else if (type ==
"rpa")
80 app_log() <<
"Adding RPA backflow functions. \n";
81 BFTrans->bfFuns.push_back(
addRPA(cur));
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");
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");
117 ions = pit->second.
get();
118 app_log() <<
"Adding electron-Ion backflow for source:" << source <<
" \n";
119 std::unique_ptr<BackflowFunctionBase> tbf;
126 APP_ABORT(
"Spin one body backflow not supported");
184 std::vector<xmlNodePtr> funs;
185 std::vector<int> ion2functor(nIons, -1);
186 std::vector<RealType> cusps;
187 xmlNodePtr curRoot = cur;
189 cur = curRoot->children;
193 if (cname ==
"correlation")
196 std::string elementType(
"none");
198 anAttrib.
add(elementType,
"elementType");
199 anAttrib.
add(my_cusp,
"cusp");
202 cusps.push_back(my_cusp);
205 xmlNodePtr kids = cur;
206 kids = cur->children;
210 if (aname ==
"index")
212 std::vector<int> pos;
214 for (
int i = 0; i < pos.size(); i++)
216 app_log() <<
"Adding backflow transformation of type " << funs.size() - 1 <<
" for atom " << pos[i]
218 ion2functor[pos[i]] = funs.size() - 1;
230 for (
int i = 0; i < ion2functor.size(); i++)
233 ion2functor[i] = funs.size() - 1;
234 app_log() <<
"Adding backflow transformation of element type " << elementType <<
" for atom " << i
242 if (funct ==
"Bspline")
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;
248 std::vector<int> offsets;
249 for (
int i = 0; i < funs.size(); i++)
255 if (bsp->cutoff_radius >
cutOff)
256 cutOff = bsp->cutoff_radius;
259 offsets.push_back(num_params);
260 num_params += bsp->NumParams;
261 dum->uniqueRadFun.push_back(std::move(bsp));
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++)
268 if (ion2functor[i] < 0 || ion2functor[i] >= funs.size())
270 APP_ABORT(
"backflowTransformation::put() ion not mapped to radial function.\n");
272 dum->RadFun[i] = dum->uniqueRadFun[ion2functor[i]].get();
273 dum->offsetPrms[i] = offsets[ion2functor[i]];
275 tbf = std::move(dum);
279 APP_ABORT(
"Unknown function type in e-I BF Transformation.\n");
287 app_log() <<
"Adding electron-electron backflow. \n";
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");
296 xmlNodePtr curRoot = cur;
300 std::vector<int> offsets;
301 if (funct ==
"Bspline")
303 app_log() <<
"Using BsplineFunctor type. \n";
305 cur = curRoot->children;
309 if (cname ==
"correlation")
312 std::string spA(species.speciesName[0]);
313 std::string spB(species.speciesName[0]);
315 anAttrib.
add(cusp,
"cusp");
316 anAttrib.
add(spA,
"speciesA");
317 anAttrib.
add(spB,
"speciesB");
318 anAttrib.
add(cusp,
"cusp");
320 int ia = species.findSpecies(spA);
321 int ib = species.findSpecies(spB);
322 if (ia == species.size() || ib == species.size())
324 APP_ABORT(
"Failed. Species are incorrect in e-e backflow.");
326 app_log() <<
"Adding radial component for species: " << spA <<
" " << spB <<
" " << ia <<
" " << ib
331 if (bsp->cutoff_radius >
cutOff)
332 cutOff = bsp->cutoff_radius;
334 offsets.push_back(tbf->numParams);
335 tbf->numParams += bsp->NumParams;
336 tbf->addFunc(ia, ib, std::move(bsp));
340 tbf->derivs.resize(tbf->numParams);
343 for (
int i = 0; i < tbf->RadFun.size(); i++)
346 for (
int k = 0; k < tbf->uniqueRadFun.size(); k++)
348 if (tbf->RadFun[i] == tbf->uniqueRadFun[k].get())
351 tbf->offsetPrms[i] = offsets[k];
357 APP_ABORT(
"Error creating Backflow_ee object. \n");
363 APP_ABORT(
"Unknown function type in e-e BF Transformation.\n");
383 anAttrib0.
add(
Rs,
"rs");
384 anAttrib0.
add(
Kc,
"kc");
402 std::cout <<
" Error finding rs. Is this an open system?!" << std::endl;
410 Kc = 2.0 *
std::pow(2.25 * M_PI, 1.0 / 3.0) / tlen;
415 app_log() <<
" BackflowBuilderBuilder Kc set too high. Resetting to the maximum value" << std::endl;
417 app_log() <<
" BackflowBuilderBuilder Rs = " <<
Rs <<
" Kc= " <<
Kc << std::endl;
424 std::vector<int> offsetsSR;
425 std::vector<int> offsetsLR;
426 std::unique_ptr<Backflow_ee<BsplineFunctor<RealType>>> tbf;
433 if (cname ==
"correlation")
435 std::string type =
"none";
437 anAttrib.
add(type,
"type");
439 if (type ==
"shortrange")
447 else if (type ==
"longrange")
455 APP_ABORT(
"Only a single LongRange RPAbackflow allowed for now. ");
461 APP_ABORT(
"Unknown rpa backflow type in <correlation/>.");
468 tbf->derivs.resize(tbf->numParams);
471 for (
int i = 0; i < tbf->RadFun.size(); i++)
474 for (
int k = 0; k < tbf->uniqueRadFun.size(); k++)
476 if (tbf->RadFun[i] == tbf->uniqueRadFun[k].get())
480 tbf->offsetPrms[i] = offsetsSR[k];
486 APP_ABORT(
"Error creating Backflow_ee object in addRPA. \n");
498 std::string spA(species.speciesName[0]);
499 std::string spB(species.speciesName[0]);
500 std::string init =
"yes";
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");
508 int ia = species.findSpecies(spA);
509 int ib = species.findSpecies(spB);
510 if (ia == species.size() || ib == species.size())
512 APP_ABORT(
"Failed. Species are incorrect in longrange RPA backflow.");
514 app_log() <<
"Adding RPABackflow longrange component for species: " << spA <<
" " << spB <<
" " << ia <<
" " << ib
517 xmlNodePtr xmlCoefs = cur->xmlChildrenNode;
518 while (xmlCoefs != NULL)
520 std::string cname((
const char*)xmlCoefs->name);
521 if (cname ==
"coefficients")
523 std::string type(
"0"), id(
"0");
526 cAttrib.
add(
id,
"id");
527 cAttrib.
add(type,
"type");
529 cAttrib.
put(xmlCoefs);
532 APP_ABORT(
"Unknown correlation type " + type +
" in Backflow.");
536 std::vector<RealType> yk;
537 if (init ==
"true" || init ==
"yes")
539 app_log() <<
"Initializing k-space backflow function with RPA form.";
541 for (
int i = 0; i < yk.size(); i++)
546 app_log() <<
"Reading k-space backflow function from xml.";
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");
559 std::ofstream fout(fname.data());
560 fout.setf(std::ios::scientific, std::ios::floatfield);
561 fout <<
"# Backflow longrange \n";
567 <<
" " << yk[i] << std::endl;
572 xmlCoefs = xmlCoefs->next;
579 std::vector<int>& offsets)
583 std::string spA(species.speciesName[0]);
584 std::string spB(species.speciesName[0]);
586 std::string init =
"yes";
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");
595 int ia = species.findSpecies(spA);
596 int ib = species.findSpecies(spB);
597 if (ia == species.size() || ib == species.size())
599 APP_ABORT(
"Failed. Species are incorrect in e-e backflow.");
601 app_log() <<
"Adding radial component for species: " << spA <<
" " << spB <<
" " << ia <<
" " << ib << std::endl;
603 xmlNodePtr xmlCoefs = cur->xmlChildrenNode;
604 while (xmlCoefs != NULL)
606 std::string cname((
const char*)xmlCoefs->name);
607 if (cname ==
"coefficients")
609 std::string type(
"0"), id(
"0");
612 cAttrib.
add(
id,
"id");
613 cAttrib.
add(type,
"type");
615 cAttrib.
put(xmlCoefs);
618 APP_ABORT(
"Unknown correlation type " + type +
" in Backflow.");
621 if (init ==
"true" || init ==
"yes")
623 app_log() <<
"Initializing backflow radial functions with RPA.";
626 int npts =
static_cast<int>(
Rcut / 0.01) + 3;
627 myGrid->
set(0,
Rcut - 0.01, npts);
629 std::vector<RealType> x(myGrid->
size()), y(myGrid->
size());
635 for (
int i = 0; i < myGrid->
size(); i++)
641 app_log() <<
"Rcut,npts:" <<
Rcut <<
" " << npts <<
" " << x[myGrid->
size() - 1] << std::endl;
643 int nfitgaussians(3);
645 for (
int i = 0; i < npts; i++)
648 for (
int j = 0; j < nfitgaussians; j++)
651 std::vector<RealType> gb(nfitgaussians);
654 for (
int i = 0; i < myGrid->
size(); i++)
658 for (
int j = 0; j < nfitgaussians; j++)
665 auto tmp_bsp = std::make_unique<BsplineFunctor<RealType>>(
"tmp_bsp");
666 tmp_bsp->initialize(12, x, y, cusp,
Rcut,
id,
optimize);
668 for (
int i = 0; i < myGrid->
size(); i++)
670 y[i] = tmp_bsp->f(x[i]);
679 if (bsp->cutoff_radius >
cutOff)
680 cutOff = bsp->cutoff_radius;
682 tbf->addFunc(ia, ib, std::move(bsp));
683 offsets.push_back(tbf->numParams);
684 tbf->numParams += bsp->NumParams;
686 xmlCoefs = xmlCoefs->next;
void makeShortRange_oneBody()
void set(T ri, T rf, int n) override
Set the grid given the parameters.
BackflowFunctionBase::RealType RealType
helper functions for EinsplineSetBuilder
BsplineFunctor class for the Jastrows REAL is the real type used by offload target, it is the correct type for the mw data pointers and is also used to coerce/implicitly convert the Real type inherited OptimizableFunctorBase into that buffer if offload is off this happens too but is just an implementation quirk.
std::unique_ptr< BackflowFunctionBase > addOneBody(xmlNodePtr cur)
size_t getTotalNum() const
virtual void Breakup(ParticleSet &ref, mRealType rs_in)=0
bool put(xmlNodePtr cur)
assign attributes to the set
DECLARE_COULOMB_TYPES int MaxKshell
Maxkimum Kshell for the given Kc.
void addFunc(int ia, int ib)
Communicate * Controller
Global Communicator for a process.
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
std::unique_ptr< BackflowFunctionBase > addTwoBody(xmlNodePtr cur)
ParticleIndex GroupID
Species ID.
void setParameterType(int type)
LinearGrid< RealType > GridType
int getTotalNum() const
return the number of species
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
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
Specialized paritlce class for atomistic simulations.
std::unique_ptr< BackflowFunctionBase > addRPA(xmlNodePtr cur)
void makeShortRange_twoBody(xmlNodePtr cur, Backflow_ee< BsplineFunctor< RealType >> *tbf, std::vector< int > &offsets)
size_type size() const
return the current size
void makeLongRange_twoBody(xmlNodePtr cur, Backflow_ee_kSpace *tbf, std::vector< int > &offsets)
A derivative of LRBasis class to provide the functionality of the LPQHI basis.
Final class and should not be derived.
class to handle a set of attributes of an xmlNode
declaration of ProgressReportEngine
Define a LRHandler with two template parameters.
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
Vector< mRealType > Fk
Fourier component for all the k-point.
std::unique_ptr< BackflowTransformation > buildBackflowTransformation(xmlNodePtr cur)
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Declaration of a TrialWaveFunction.
bool putContent(T &a, xmlNodePtr cur)
replaces a's value with the first "element" in the "string" returned by XMLNodeString{cur}.
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
int size() const
returns the size of the grid
void makeLongRange_oneBody()
opt_variables_type myVars
set of variables to be optimized
const auto & getLattice() const
BackflowBuilder(ParticleSet &p, const PSetMap &pool)
Custom container for set of attributes for a set of species.
int findSpecies(const std::string &name) const
if the input species is not found, add a new species
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
bool get(std::ostream &os) const override
dummy. For satisfying OhmmsElementBase.
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
std::string getNodeName(xmlNodePtr cur)
Define a LRHandler with two template parameters.
void LinearFit(std::vector< T > &y, Matrix< T > &A, std::vector< T > &coefs)
void initialize(ParticleSet &P, std::vector< RealType > &yk)
Vector< mRealType > Fk_symm
Fourier component for each k-shell.