QMCPACK
WaveFunctionFactory.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
13 // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
14 //
15 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
16 //////////////////////////////////////////////////////////////////////////////////////
17 
18 
19 /**@file WaveFunctionFactory.cpp
20  *@brief Definition of a WaveFunctionFactory
21  */
22 #include "WaveFunctionFactory.h"
27 #if OHMMS_DIM == 3 && !defined(QMC_COMPLEX)
29 #endif
30 
33 #include "OhmmsData/AttributeSet.h"
34 namespace qmcplusplus
35 {
37  : MPIObjectBase(c), targetPtcl(qp), ptclPool(pset)
38 {
39  ClassName = "WaveFunctionFactory";
40 }
41 
43 
44 std::unique_ptr<TrialWaveFunction> WaveFunctionFactory::buildTWF(xmlNodePtr cur, const RuntimeOptions& runtime_options)
45 {
46  // YL: how can this happen?
47  if (cur == NULL)
48  return nullptr;
49 
50  ReportEngine PRE(ClassName, "build");
51 
52  std::string psiName("psi0"), tasking;
53  OhmmsAttributeSet pAttrib;
54  pAttrib.add(psiName, "id");
55  pAttrib.add(psiName, "name");
56  pAttrib.add(tasking, "tasking", {"no", "yes"});
57  pAttrib.put(cur);
58 
59  app_summary() << std::endl;
60  app_summary() << " Many-body wavefunction" << std::endl;
61  app_summary() << " -------------------" << std::endl;
62  app_summary() << " Name: " << psiName << " Tasking: " << (tasking == "yes" ? "yes" : "no") << std::endl;
63  app_summary() << std::endl;
64 
65  auto targetPsi = std::make_unique<TrialWaveFunction>(runtime_options, psiName, tasking == "yes");
66  targetPsi->setMassTerm(targetPtcl);
67  targetPsi->storeXMLNode(cur);
68 
69  SPOSetBuilderFactory sposet_builder_factory(myComm, targetPtcl, ptclPool);
70 
71  std::string vp_file_to_load;
72  cur = cur->children;
73  while (cur != NULL)
74  {
75  std::string cname((const char*)(cur->name));
76  if (cname == "sposet_builder" || cname == "sposet_collection")
77  sposet_builder_factory.buildSPOSetCollection(cur);
79  {
80  addFermionTerm(*targetPsi, sposet_builder_factory, cur);
81  bool foundtwist(false);
82  xmlNodePtr kcur = cur->children;
83  while (kcur != NULL)
84  {
85  std::string kname((const char*)(kcur->name));
86  if (kname == "h5tag")
87  {
88  std::string hdfName;
89  OhmmsAttributeSet attribs;
90  attribs.add(hdfName, "name");
91  if (hdfName == "twistAngle")
92  {
93  std::vector<ParticleSet::RealType> twists(3, 0);
94  putContent(twists, kcur);
95  targetPsi->setTwist(std::move(twists));
96  foundtwist = true;
97  }
98  }
99  kcur = kcur->next;
100  }
101  if (!foundtwist)
102  {
103  //default twist is [0 0 0]
104  targetPsi->setTwist(std::vector<ParticleSet::RealType>(3, 0));
105  }
106  }
108  {
109  auto jbuilder = std::make_unique<JastrowBuilder>(myComm, targetPtcl, ptclPool);
110  targetPsi->addComponent(jbuilder->buildComponent(cur));
111  }
112  else if (cname == "fdlrwfn")
113  {
114  APP_ABORT("FDLR wave functions are not currently supported.");
115  }
117  {
118  auto builder = std::make_unique<LatticeGaussianProductBuilder>(myComm, targetPtcl, ptclPool);
119  targetPsi->addComponent(builder->buildComponent(cur));
120  }
121  else if ((cname == "Molecular") || (cname == "molecular"))
122  {
123  APP_ABORT(" Removed Helium Molecular terms from qmcpack ");
124  }
125  else if (cname == "example_he")
126  {
127  auto exampleHe_builder = std::make_unique<ExampleHeBuilder>(myComm, targetPtcl, ptclPool);
128  targetPsi->addComponent(exampleHe_builder->buildComponent(cur));
129  }
130 #if !defined(QMC_COMPLEX) && OHMMS_DIM == 3
131  else if (cname == "agp")
132  {
133  auto agpbuilder = std::make_unique<AGPDeterminantBuilder>(myComm, targetPtcl, ptclPool);
134  targetPsi->addComponent(agpbuilder->buildComponent(cur));
135  }
136 #endif
137  else if (cname == "override_variational_parameters")
138  {
139  OhmmsAttributeSet attribs;
140  attribs.add(vp_file_to_load, "href");
141  attribs.put(cur);
142  }
143 
144  cur = cur->next;
145  }
146  //{
147  // ReportEngine PREA("TrialWaveFunction","print");
148  // targetPsi->VarList.print(app_log());
149  //}
150  // synch all parameters. You don't want some being different if same name.
151  opt_variables_type dummy;
152  targetPsi->checkInVariables(dummy);
153  dummy.resetIndex();
154  targetPsi->checkOutVariables(dummy);
155 
156  if (!vp_file_to_load.empty())
157  {
158  app_log() << " Reading variational parameters from " << vp_file_to_load << std::endl;
159  hdf_archive hin;
160  dummy.readFromHDF(vp_file_to_load, hin);
161 
162  UniqueOptObjRefs opt_obj_refs = targetPsi->extractOptimizableObjectRefs();
163  for (auto opt_obj : opt_obj_refs)
164  opt_obj.get().readVariationalParameters(hin);
165  }
166 
167  targetPsi->resetParameters(dummy);
168  targetPsi->storeSPOMap(sposet_builder_factory.exportSPOSets());
169  return targetPsi;
170 }
171 
173 {
174  ReportEngine PRE(ClassName, "addFermionTerm");
175  std::string orbtype("MolecularOrbital");
176  std::string nuclei("i");
177  OhmmsAttributeSet oAttrib;
178  oAttrib.add(orbtype, "type");
179  oAttrib.add(nuclei, "source");
180  oAttrib.put(cur);
181  std::unique_ptr<WaveFunctionComponentBuilder> detbuilder;
182  if (orbtype == "electron-gas")
183  {
184  std::ostringstream msg;
185  msg << "electron-gas in determinantset is deprecated";
186  msg << " please use \"free\" orbitals in sposet_builder" << std::endl;
187  throw std::runtime_error(msg.str());
188  }
189  else
190  detbuilder = std::make_unique<SlaterDetBuilder>(myComm, spo_factory, targetPtcl, psi, ptclPool);
191  psi.addComponent(detbuilder->buildComponent(cur));
192  return true;
193 }
194 
195 } // namespace qmcplusplus
declaration of a builder class for AGPDeterminant
Base class for any object which needs to know about a MPI communicator.
Definition: MPIObjectBase.h:26
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_summary()
Definition: OutputManager.h:63
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
void readFromHDF(const std::string &filename, qmcplusplus::hdf_archive &hin)
Read variational parameters from an HDF file.
class to handle hdf file
Definition: hdf_archive.h:51
ParticleSet & targetPtcl
many-body wavefunction object target ParticleSet
void resetIndex()
reset Index
Wrapping information on parallelism.
Definition: Communicate.h:68
const PSetMap & ptclPool
reference to the PSetMap
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
std::unique_ptr< TrialWaveFunction > buildTWF(xmlNodePtr cur, const RuntimeOptions &runtime_options)
read from xmlNode
static std::string detset_tag
the element name for a set of Slater determinants, contains 1..* Slater determinants ...
Final class and should not be derived.
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
declaration of ProgressReportEngine
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
bool addFermionTerm(TrialWaveFunction &psi, SPOSetBuilderFactory &spo_factory, xmlNodePtr cur)
add Fermion wavefunction term
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
WaveFunctionFactory(ParticleSet &qp, const PSetMap &pset, Communicate *c)
constructor
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
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
Class to represent a many-body trial wave function.
static std::string ionorb_tag
the element name for an ion wavefunction
Declaration of a WaveFunctionFactory.
static std::string jastrow_tag
the element name for jatrow
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
Example builder for simple He wavefunction.