QMCPACK
AGPDeterminantBuilder.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: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 /**@file
17  *@brief definition of three-body jastrow of Geminal functions
18  */
19 #include "AGPDeterminantBuilder.h"
20 #include "OhmmsData/AttributeSet.h"
22 
23 namespace qmcplusplus
24 {
26  : WaveFunctionComponentBuilder(comm, els), ptclPool(pset)
27 {}
28 
29 template<class BasisBuilderT>
30 bool AGPDeterminantBuilder::createAGP(BasisBuilderT* abuilder, xmlNodePtr cur)
31 {
32  bool spinpolarized = false;
33  typename BasisBuilderT::BasisSetType* basisSet = 0;
34  cur = cur->xmlChildrenNode;
35  while (cur != NULL)
36  {
37  std::string cname(castXMLCharToChar(cur->name));
38  if (cname == "coefficient" || cname == "coefficients")
39  {
40  if (agpDet == nullptr)
41  {
42  int nup = targetPtcl.first(1), ndown = 0;
43  if (targetPtcl.groups() > 1)
44  ndown = targetPtcl.first(2) - nup;
45  basisSet->resize(nup + ndown);
46  agpDet = std::make_unique<AGPDeterminant>(basisSet);
47  agpDet->resize(nup, ndown);
48  }
49  int offset = 1;
50  xmlNodePtr tcur = cur->xmlChildrenNode;
51  while (tcur != NULL)
52  {
53  if (xmlStrEqual(tcur->name, (const xmlChar*)"lambda"))
54  {
55  int i = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"i")));
56  int j = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"j")));
57  double c = atof((const char*)(xmlGetProp(tcur, (const xmlChar*)"c")));
58  agpDet->Lambda(i - offset, j - offset) = c;
59  if (i != j)
60  {
61  agpDet->Lambda(j - offset, i - offset) = c;
62  }
63  }
64  tcur = tcur->next;
65  }
66  }
67  else if (cname == "unpaired")
68  {
69  spinpolarized = true;
70  int offset = 1;
71  xmlNodePtr tcur = cur->xmlChildrenNode;
72  while (tcur != NULL)
73  {
74  if (xmlStrEqual(tcur->name, (const xmlChar*)"lambda"))
75  {
76  int i = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"i")));
77  int j = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"j")));
78  double c = atof((const char*)(xmlGetProp(tcur, (const xmlChar*)"c")));
79  agpDet->LambdaUP(j - offset, i - offset) = c;
80  }
81  tcur = tcur->next;
82  }
83  }
84  cur = cur->next;
85  }
86  //app_log() << agpDet->Lambda << std::endl;
87  if (spinpolarized)
88  {
89  app_log() << " Coefficients for the unpaired electrons " << std::endl;
90  app_log() << agpDet->LambdaUP << std::endl;
91  }
92  return true;
93 }
94 
95 std::unique_ptr<WaveFunctionComponent> AGPDeterminantBuilder::buildComponent(xmlNodePtr cur)
96 {
97  if (agpDet)
98  {
99  APP_ABORT(" AGPDeterminantBuilder::put exits. AGPDeterminant has been already created.\n");
100  return std::unique_ptr<AGPDeterminant>();
101  }
102  app_log() << " AGPDeterminantBuilder Creating AGPDeterminant." << std::endl;
103  xmlNodePtr curRoot = cur;
104  bool success = true;
105  std::string tname;
106  xmlNodePtr cPtr = NULL;
107  xmlNodePtr uPtr = NULL;
108  OhmmsAttributeSet oAttrib;
109  oAttrib.add(funcOpt, "function");
110  oAttrib.add(transformOpt, "transform");
111  oAttrib.put(cur);
112  cur = cur->children;
113  while (cur != NULL)
114  {
115  std::string cname(getNodeName(cur));
116  if (cname.find("coeff") < cname.size())
117  {
118  cPtr = cur;
119  }
120  else if (cname.find("un") < cname.size())
121  {
122  uPtr = cur;
123  }
124  cur = cur->next;
125  }
126  if (cPtr == NULL)
127  {
128  std::ostringstream err_msg;
129  err_msg << " AGPDeterminantBuilder::put Cannot create AGPDeterminant." << std::endl
130  << " Missing <coefficients/>" << std::endl;
131  APP_ABORT(err_msg.str());
132  return nullptr;
133  }
135  {
136  mySPOSetBuilderFactory = std::make_unique<SPOSetBuilderFactory>(myComm, targetPtcl, ptclPool);
137  mySPOSetBuilderFactory->createSPOSetBuilder(curRoot);
138  }
139  // mmorales: this needs to be fixed after changes to BasisSetfactory
140  // BasisSetBase<RealType>* myBasisSet=mySPOSetBuilderFactory->getBasisSet();
141  BasisSetBase<RealType>* myBasisSet = 0; //=mySPOSetBuilderFactory->getBasisSet();
142  int nup = targetPtcl.first(1), ndown = 0;
143  if (targetPtcl.groups() > 1)
144  ndown = targetPtcl.first(2) - nup;
145  myBasisSet->resize(nup + ndown);
146  agpDet = std::make_unique<AGPDeterminant>(myBasisSet);
147  agpDet->resize(nup, ndown);
148  //set Lambda: possible to move to AGPDeterminant
149  int offset = 1;
150  xmlNodePtr tcur = cPtr->xmlChildrenNode;
151  while (tcur != NULL)
152  {
153  if (xmlStrEqual(tcur->name, (const xmlChar*)"lambda"))
154  {
155  int i = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"i")));
156  int j = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"j")));
157  double c = atof((const char*)(xmlGetProp(tcur, (const xmlChar*)"c")));
158  agpDet->Lambda(i - offset, j - offset) = c;
159  if (i != j)
160  {
161  agpDet->Lambda(j - offset, i - offset) = c;
162  }
163  }
164  tcur = tcur->next;
165  }
166  if (uPtr != NULL)
167  {
168  tcur = uPtr->xmlChildrenNode;
169  while (tcur != NULL)
170  {
171  if (xmlStrEqual(tcur->name, (const xmlChar*)"lambda"))
172  {
173  int i = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"i")));
174  int j = atoi((const char*)(xmlGetProp(tcur, (const xmlChar*)"j")));
175  double c = atof((const char*)(xmlGetProp(tcur, (const xmlChar*)"c")));
176  agpDet->LambdaUP(j - offset, i - offset) = c;
177  }
178  tcur = tcur->next;
179  }
180  app_log() << " AGPDeterminantBuilder::put Coefficients for the unpaired electrons " << std::endl;
181  app_log() << agpDet->LambdaUP << std::endl;
182  }
183  if (agpDet)
184  return std::move(agpDet);
185 
186  APP_ABORT("failed to create an AGP determinant!\n");
187  return nullptr;
188 }
189 
190 } // namespace qmcplusplus
const PSetMap & ptclPool
reference to a PSetMap
declaration of a builder class for AGPDeterminant
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
An abstract class for wave function builders.
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
base class for a basis set
Definition: BasisSetBase.h:38
std::unique_ptr< WaveFunctionComponent > buildComponent(xmlNodePtr cur) override
process a xml node at cur
bool createAGP(BasisBuilderT *abuilder, xmlNodePtr cur)
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
AGPDeterminantBuilder(Communicate *comm, ParticleSet &els, const PSetMap &pset)
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
Wrapping information on parallelism.
Definition: Communicate.h:68
int groups() const
return the number of groups
Definition: ParticleSet.h:511
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
char * castXMLCharToChar(xmlChar *c)
assign a value from a node. Use specialization for classes.
Definition: libxmldefs.h:62
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
std::unique_ptr< AGPDeterminant > agpDet
AGPDeterminant.
std::unique_ptr< SPOSetBuilderFactory > mySPOSetBuilderFactory
basiset Factory
void resize(int ntargets)
resize the container
Definition: BasisSetBase.h:88
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