QMCPACK
WaveFunctionFactory Class Reference

Factory class to build a many-body wavefunction. More...

+ Inheritance diagram for WaveFunctionFactory:
+ Collaboration diagram for WaveFunctionFactory:

Public Types

using PSetMap = std::map< std::string, const std::unique_ptr< ParticleSet > >
 
- Public Types inherited from MPIObjectBase
using mpi_comm_type = Communicate::mpi_comm_type
 

Public Member Functions

 WaveFunctionFactory (ParticleSet &qp, const PSetMap &pset, Communicate *c)
 constructor More...
 
 ~WaveFunctionFactory ()
 destructor More...
 
std::unique_ptr< TrialWaveFunctionbuildTWF (xmlNodePtr cur, const RuntimeOptions &runtime_options)
 read from xmlNode More...
 
- Public Member Functions inherited from MPIObjectBase
 MPIObjectBase (Communicate *c)
 constructor with communicator More...
 
int rank () const
 return the rank of the communicator More...
 
int getGroupID () const
 return the group id of the communicator More...
 
CommunicategetCommunicator () const
 return myComm More...
 
CommunicategetCommRef () const
 return a TEMPORARY reference to Communicate More...
 
mpi_comm_type getMPI () const
 return MPI communicator if one wants to use MPI directly More...
 
bool is_manager () const
 return true if the rank == 0 More...
 
const std::string & getName () const
 return the name More...
 
void setName (const std::string &aname)
 

Static Public Member Functions

static std::unique_ptr< TrialWaveFunctionbuildEmptyTWFForTesting (const RuntimeOptions &runtime_options, const std::string_view name)
 create an empty TrialWaveFunction for testing use. More...
 

Private Member Functions

bool addFermionTerm (TrialWaveFunction &psi, SPOSetBuilderFactory &spo_factory, xmlNodePtr cur)
 add Fermion wavefunction term More...
 

Private Attributes

ParticleSettargetPtcl
 many-body wavefunction object target ParticleSet More...
 
const PSetMapptclPool
 reference to the PSetMap More...
 

Additional Inherited Members

- Protected Attributes inherited from MPIObjectBase
CommunicatemyComm
 pointer to Communicate More...
 
std::string ClassName
 class Name More...
 
std::string myName
 name of the object More...
 

Detailed Description

Factory class to build a many-body wavefunction.

Definition at line 31 of file WaveFunctionFactory.h.

Member Typedef Documentation

◆ PSetMap

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

Definition at line 34 of file WaveFunctionFactory.h.

Constructor & Destructor Documentation

◆ WaveFunctionFactory()

WaveFunctionFactory ( ParticleSet qp,
const PSetMap pset,
Communicate c 
)

constructor

Parameters
psiNamename for both the factory and psi
qpquantum particleset (aka target)
psetpool of particlesets
ccommunicator
cusing tasking inside TWF

Definition at line 36 of file WaveFunctionFactory.cpp.

References MPIObjectBase::ClassName.

38 {
39  ClassName = "WaveFunctionFactory";
40 }
ParticleSet & targetPtcl
many-body wavefunction object target ParticleSet
const PSetMap & ptclPool
reference to the PSetMap
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
MPIObjectBase(Communicate *c)
constructor with communicator

◆ ~WaveFunctionFactory()

~WaveFunctionFactory ( )
default

destructor

Member Function Documentation

◆ addFermionTerm()

bool addFermionTerm ( TrialWaveFunction psi,
SPOSetBuilderFactory spo_factory,
xmlNodePtr  cur 
)
private

add Fermion wavefunction term

Definition at line 172 of file WaveFunctionFactory.cpp.

References OhmmsAttributeSet::add(), MPIObjectBase::ClassName, MPIObjectBase::myComm, WaveFunctionFactory::ptclPool, OhmmsAttributeSet::put(), and WaveFunctionFactory::targetPtcl.

Referenced by WaveFunctionFactory::buildTWF().

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 }
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
ParticleSet & targetPtcl
many-body wavefunction object target ParticleSet
const PSetMap & ptclPool
reference to the PSetMap
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
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

◆ buildEmptyTWFForTesting()

static std::unique_ptr<TrialWaveFunction> buildEmptyTWFForTesting ( const RuntimeOptions runtime_options,
const std::string_view  name 
)
inlinestatic

create an empty TrialWaveFunction for testing use.

Definition at line 52 of file WaveFunctionFactory.h.

Referenced by qmcplusplus::TEST_CASE().

54  {
55  return std::make_unique<TrialWaveFunction>(runtime_options, name);
56  }

◆ buildTWF()

std::unique_ptr< TrialWaveFunction > buildTWF ( xmlNodePtr  cur,
const RuntimeOptions runtime_options 
)

read from xmlNode

Definition at line 44 of file WaveFunctionFactory.cpp.

References OhmmsAttributeSet::add(), WaveFunctionFactory::addFermionTerm(), APP_ABORT, qmcplusplus::app_log(), qmcplusplus::app_summary(), SPOSetBuilderFactory::buildSPOSetCollection(), MPIObjectBase::ClassName, WaveFunctionComponentBuilder::detset_tag, SPOSetBuilderFactory::exportSPOSets(), WaveFunctionComponentBuilder::ionorb_tag, WaveFunctionComponentBuilder::jastrow_tag, MPIObjectBase::myComm, WaveFunctionFactory::ptclPool, OhmmsAttributeSet::put(), putContent(), VariableSet::readFromHDF(), VariableSet::resetIndex(), and WaveFunctionFactory::targetPtcl.

Referenced by WaveFunctionPool::put(), qmcplusplus::setup_He_wavefunction(), and qmcplusplus::TEST_CASE().

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 }
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
ParticleSet & targetPtcl
many-body wavefunction object target ParticleSet
void resetIndex()
reset Index
const PSetMap & ptclPool
reference to the PSetMap
static std::string detset_tag
the element name for a set of Slater determinants, contains 1..* Slater determinants ...
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
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
optimize::VariableSet opt_variables_type
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
static std::string ionorb_tag
the element name for an ion wavefunction
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

Member Data Documentation

◆ ptclPool

const PSetMap& ptclPool
private

reference to the PSetMap

Definition at line 66 of file WaveFunctionFactory.h.

Referenced by WaveFunctionFactory::addFermionTerm(), and WaveFunctionFactory::buildTWF().

◆ targetPtcl

ParticleSet& targetPtcl
private

many-body wavefunction object target ParticleSet

Definition at line 64 of file WaveFunctionFactory.h.

Referenced by WaveFunctionFactory::addFermionTerm(), and WaveFunctionFactory::buildTWF().


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