QMCPACK
PWOrbitalSetBuilder Class Reference

OrbitalBuilder for Slater determinants in PW basis. More...

+ Inheritance diagram for PWOrbitalSetBuilder:
+ Collaboration diagram for PWOrbitalSetBuilder:

Public Member Functions

 PWOrbitalSetBuilder (const ParticleSet &p, Communicate *comm, xmlNodePtr cur)
 constructor More...
 
 ~PWOrbitalSetBuilder () override
 
std::unique_ptr< SPOSetcreateSPOSetFromXML (xmlNodePtr cur) override
 create an sposet from xml and save the resulting SPOSet More...
 
- Public Member Functions inherited from SPOSetBuilder
 SPOSetBuilder (const std::string &type_name, Communicate *comm)
 
virtual ~SPOSetBuilder ()
 
void reserve_states (int nsets=1)
 reserve space for states (usually only one set, multiple for e.g. spin dependent einspline) More...
 
void modify_states (int index=0)
 allow modification of state information More...
 
void clear_states (int index=0)
 clear state information More...
 
std::unique_ptr< SPOSetcreateSPOSet (xmlNodePtr cur)
 create an sposet from xml and save the resulting SPOSet More...
 
std::unique_ptr< SPOSetcreateRotatedSPOSet (xmlNodePtr cur)
 create orbital rotation transformation from xml and save the resulting SPOSet More...
 
const std::string & getTypeName () const
 
- 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)
 

Private Types

using SPOSetType = PWRealOrbitalSet
 

Private Member Functions

bool getH5 (xmlNodePtr cur, const char *aname)
 
bool createPWBasis ()
 The read routine - get data from XML and H5. More...
 
std::unique_ptr< SPOSetcreatePW (xmlNodePtr cur, const std::string &objname, int spinIndex)
 

Private Attributes

const ParticleSettargetPtcl
 target particle set More...
 
xmlNodePtr rootNode {nullptr}
 xml node for determinantset More...
 
PosType TwistAngle
 input twist angle More...
 
std::unique_ptr< PWParameterSetmyParam
 parameter set More...
 
std::unique_ptr< PWBasismyBasisSet
 
hdf_archive hfile
 hdf5 handler to clean up More...
 

Additional Inherited Members

- Public Types inherited from SPOSetBuilder
using indices_t = std::vector< int >
 
using energies_t = std::vector< RealType >
 
- Public Types inherited from QMCTraits
enum  { DIM = OHMMS_DIM, DIM_VGL = OHMMS_DIM + 2 }
 
using QTBase = QMCTypes< OHMMS_PRECISION, DIM >
 
using QTFull = QMCTypes< OHMMS_PRECISION_FULL, DIM >
 
using RealType = QTBase::RealType
 
using ComplexType = QTBase::ComplexType
 
using ValueType = QTBase::ValueType
 
using PosType = QTBase::PosType
 
using GradType = QTBase::GradType
 
using TensorType = QTBase::TensorType
 
using IndexType = OHMMS_INDEXTYPE
 define other types More...
 
using FullPrecRealType = QTFull::RealType
 
using FullPrecValueType = QTFull::ValueType
 
using PropertySetType = RecordNamedProperty< FullPrecRealType >
 define PropertyList_t More...
 
using PtclGrpIndexes = std::vector< std::pair< int, int > >
 
- Public Types inherited from MPIObjectBase
using mpi_comm_type = Communicate::mpi_comm_type
 
- Public Attributes inherited from SPOSetBuilder
bool legacy
 whether implementation conforms only to legacy standard More...
 
std::vector< std::unique_ptr< SPOSetInfo > > states
 state info of all possible states available in the basis More...
 
- Protected Member Functions inherited from SPOSetBuilder
virtual std::unique_ptr< SPOSetcreateSPOSet (xmlNodePtr cur, SPOSetInputInfo &input_info)
 create an sposet from a general xml request More...
 
- Protected Attributes inherited from SPOSetBuilder
const std::string type_name_
 type name of the SPO objects built by this builder. More...
 
- 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

OrbitalBuilder for Slater determinants in PW basis.

Definition at line 37 of file PWOrbitalSetBuilder.h.

Member Typedef Documentation

◆ SPOSetType

using SPOSetType = PWRealOrbitalSet
private

Definition at line 43 of file PWOrbitalSetBuilder.h.

Constructor & Destructor Documentation

◆ PWOrbitalSetBuilder()

PWOrbitalSetBuilder ( const ParticleSet p,
Communicate comm,
xmlNodePtr  cur 
)

constructor

Definition at line 28 of file PWOrbitalSetBuilder.cpp.

References qmcplusplus::comm.

29  : SPOSetBuilder("Planewave", comm),
30  targetPtcl(p),
31  rootNode(cur),
32  myParam{std::make_unique<PWParameterSet>(comm)},
33  hfile{comm}
34 {
35  //
36  //Get wavefunction data and parameters from XML and HDF5
37  //
38  //catch parameters
39  myParam->put(cur);
40  //check the current href
41  bool success = getH5(cur, "href");
42  //Move through the XML tree and read basis information
43  processChildren(cur, [&](const std::string& cname, const xmlNodePtr element) {
44  if (cname == "basisset")
45  {
46  const std::string a(getXMLAttributeValue(element, "ecut"));
47  if (!a.empty())
48  myParam->Ecut = std::stod(a);
49  }
50  else if (cname == "coefficients")
51  {
52  //close
53  if (success)
54  hfile.close();
55  success = getH5(element, "hdata");
56  }
57  });
58 
59  if (!success)
60  throw std::runtime_error("h5 cannot be open for creating PW basis!");
61  //create PW Basis
62  createPWBasis();
63 }
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
bool getH5(xmlNodePtr cur, const char *aname)
SPOSetBuilder(const std::string &type_name, Communicate *comm)
hdf_archive hfile
hdf5 handler to clean up
std::unique_ptr< PWParameterSet > myParam
parameter set
xmlNodePtr rootNode
xml node for determinantset
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
void processChildren(const xmlNodePtr cur, const F &functor)
process through all the children of an XML element F is a lambda or functor void F/[](const std::stri...
Definition: libxmldefs.h:175
const ParticleSet & targetPtcl
target particle set
bool createPWBasis()
The read routine - get data from XML and H5.

◆ ~PWOrbitalSetBuilder()

~PWOrbitalSetBuilder ( )
overridedefault

Member Function Documentation

◆ createPW()

std::unique_ptr< SPOSet > createPW ( xmlNodePtr  cur,
const std::string &  objname,
int  spinIndex 
)
private

Definition at line 134 of file PWOrbitalSetBuilder.cpp.

References Communicate::abort(), OhmmsAttributeSet::add(), qmcplusplus::app_error(), qmcplusplus::app_log(), qmcplusplus::app_warning(), OHMMS::Controller, copy(), ParticleSet::first(), PWOrbitalSetBuilder::hfile, ParticleSet::last(), PWOrbitalSetBuilder::myBasisSet, PWOrbitalSetBuilder::myParam, hdf_archive::pop(), hdf_archive::push(), OhmmsAttributeSet::put(), putContent(), hdf_archive::read(), and PWOrbitalSetBuilder::targetPtcl.

Referenced by PWOrbitalSetBuilder::createSPOSetFromXML().

135 {
136  int nb = targetPtcl.last(spinIndex) - targetPtcl.first(spinIndex);
137  std::vector<int> occBand(nb);
138  for (int i = 0; i < nb; i++)
139  occBand[i] = i;
140  using GIndex_t = PWBasis::GIndex_t;
141  GIndex_t nG(1);
142  bool transform2grid = false;
143  cur = cur->children;
144  while (cur != NULL)
145  {
146  std::string cname((const char*)(cur->name));
147  if (cname == "transform")
148  {
149  putContent(nG, cur);
150  transform2grid = true;
151  }
152  else if (cname == "occupation")
153  {
154  std::string occMode("ground");
155  int bandoffset(1);
156  OhmmsAttributeSet aAttrib;
157  aAttrib.add(occMode, "mode");
158  aAttrib.add(bandoffset, "offset"); /* reserved for index offset */
159  aAttrib.put(cur);
160  if (occMode == "excited")
161  {
162  std::vector<int> occ;
163  std::vector<int> deleted, added;
164  putContent(occ, cur);
165  for (int i = 0; i < occ.size(); i++)
166  {
167  if (occ[i] < 0)
168  deleted.push_back(-occ[i]);
169  else
170  added.push_back(occ[i]);
171  }
172  if (deleted.size() != added.size())
173  {
174  app_error() << " Numbers of deleted and added bands are not identical." << std::endl;
176  }
177  for (int i = 0; i < deleted.size(); i++)
178  {
179  occBand[deleted[i] - bandoffset] = added[i] - bandoffset;
180  }
181  app_log() << " mode=\"excited\" Occupied states: " << std::endl;
182  copy(occBand.begin(), occBand.end(), std::ostream_iterator<int>(app_log(), " "));
183  app_log() << std::endl;
184  }
185  }
186  cur = cur->next;
187  }
188  std::string tname = "kpoint_0";
189  hfile.push("electrons", false);
190  hfile.push("kpoint_0", false);
191  //create a single-particle orbital set
192  auto psi = std::make_unique<SPOSetType>(objname);
193  if (transform2grid)
194  {
195  nb = myParam->numBands;
196  occBand.resize(nb);
197  for (int i = 0; i < nb; i++)
198  occBand[i] = i;
199  }
200  //going to take care of occ
201  psi->resize(new PWBasis(*myBasisSet), nb, true);
202  if (myParam->hasComplexData(hfile)) //input is complex
203  {
204  //app_log() << " PW coefficients are complex." << std::endl;
205  using TempVecType = std::vector<std::complex<RealType>>;
206  using TempVecType_DP = std::vector<std::complex<double>>;
207  TempVecType_DP coefs_DP(myBasisSet->inputmap.size());
208  int ib = 0;
209  while (ib < nb)
210  {
211  std::string bname(myParam->getBandName(occBand[ib], spinIndex));
212  app_log() << " Reading " << tname << "/" << bname << std::endl;
213  hfile.push(bname, false);
214  hfile.read(coefs_DP, "psi_g");
215  TempVecType coefs(coefs_DP.begin(), coefs_DP.end());
216  psi->addVector(coefs, ib);
217  hfile.pop();
218  ++ib;
219  }
220  }
221  else
222  {
223  // It appears the coefficients are always stored as complex in the HDF file?
224  //app_log() << " PW coefficients are real." << std::endl;
225  using ComplexTempVecType = std::vector<std::complex<RealType>>;
226  using ComplexTempVecType_DP = std::vector<std::complex<double>>;
227  ComplexTempVecType_DP complex_coefs_DP(myBasisSet->inputmap.size());
228  int ib = 0;
229  while (ib < nb)
230  {
231  std::string bname(myParam->getBandName(occBand[ib], spinIndex));
232  app_log() << " Reading " << tname << "/" << bname << std::endl;
233  hfile.push(bname, false);
234  hfile.read(complex_coefs_DP, "psi_g");
235  ComplexTempVecType complex_coefs(complex_coefs_DP.begin(), complex_coefs_DP.end());
236  psi->addVector(complex_coefs, ib);
237  hfile.pop();
238  ++ib;
239  }
240  }
241  hfile.pop();
242  hfile.pop();
243 #if defined(QMC_COMPLEX)
244  if (transform2grid)
245  {
246  app_warning() << " Going to transform on grid " << std::endl;
247  transform2GridData(nG, spinIndex, *psi);
248  }
249 #endif
250  return psi;
251 }
std::ostream & app_warning()
Definition: OutputManager.h:69
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::ostream & app_error()
Definition: OutputManager.h:67
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
hdf_archive hfile
hdf5 handler to clean up
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::unique_ptr< PWParameterSet > myParam
parameter set
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
void push(const std::string &gname, bool createit=true)
push a group to the group stack
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
void abort() const
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:306
const ParticleSet & targetPtcl
target particle set
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
TinyVector< IndexType, 3 > GIndex_t
Definition: PWBasis.h:44
std::unique_ptr< PWBasis > myBasisSet

◆ createPWBasis()

bool createPWBasis ( )
private

The read routine - get data from XML and H5.

Process it and build orbitals.

  • parameters – num_tiwsts – num_bands – complex_coefficients – maximum_ecut
  • basis

Definition at line 88 of file PWOrbitalSetBuilder.cpp.

References Communicate::abort(), qmcplusplus::app_error(), qmcplusplus::app_log(), OHMMS::Controller, ParticleSet::getLattice(), ParticleSet::getTotalNum(), PWOrbitalSetBuilder::hfile, ParticleSet::last(), PWOrbitalSetBuilder::myBasisSet, PWOrbitalSetBuilder::myParam, hdf_archive::read(), PWOrbitalSetBuilder::targetPtcl, and PWOrbitalSetBuilder::TwistAngle.

89 {
90  //recycle int and double reader
91  int idata = 0;
92  //start of parameters
93  hfile.read(idata, "electrons/number_of_kpoints");
94  int nkpts = idata;
95  hfile.read(idata, "electrons/number_of_spins");
96  hfile.read(idata, "electrons/kpoint_0/spin_0/number_of_states");
97  int nbands = idata;
98  myParam->numBands = nbands;
99  app_log() << "Number of bands = " << nbands << std::endl;
100  // Cutoff no longer present in the HDF file
101  RealType ecut = 0.0;
102  //end of parameters
103  //check if input parameters are valid
104  int nup = targetPtcl.last(0);
105  int ndown = targetPtcl.getTotalNum() - nup;
106  if (nbands < nup || nbands < ndown)
107  {
108  app_error() << "Not enough bands in h5 file" << std::endl;
110  }
111  std::string tname = myParam->getTwistAngleName();
112  TinyVector<double, OHMMS_DIM> TwistAngle_DP;
113  hfile.read(TwistAngle_DP, "/electrons/kpoint_0/reduced_k");
114  TwistAngle = TwistAngle_DP;
115  if (!myBasisSet)
116  myBasisSet = std::make_unique<PWBasis>(TwistAngle);
117 
118  //Read the planewave basisset.
119  //Note that the same data is opened here for each twist angle-avoids duplication in the
120  //h5 file (which may become very large).
121  //return the ecut to be used by the basis set
122  RealType real_ecut = myParam->getEcut(ecut);
123  //create at least one basis set but do resize the containers
124  int nh5gvecs = myBasisSet->readbasis(hfile, real_ecut, targetPtcl.getLattice(), myParam->pwTag, myParam->pwMultTag);
125  app_log() << " num_twist = " << nkpts << std::endl;
126  app_log() << " twist angle = " << TwistAngle << std::endl;
127  app_log() << " num_bands = " << nbands << std::endl;
128  app_log() << " input maximum_ecut = " << ecut << std::endl;
129  app_log() << " current maximum_ecut = " << real_ecut << std::endl;
130  app_log() << " num_planewaves = " << nh5gvecs << std::endl;
131  return true;
132 }
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_error()
Definition: OutputManager.h:67
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
hdf_archive hfile
hdf5 handler to clean up
std::unique_ptr< PWParameterSet > myParam
parameter set
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
void abort() const
QMCTraits::RealType RealType
const auto & getLattice() const
Definition: ParticleSet.h:251
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:306
const ParticleSet & targetPtcl
target particle set
std::unique_ptr< PWBasis > myBasisSet
PosType TwistAngle
input twist angle

◆ createSPOSetFromXML()

std::unique_ptr< SPOSet > createSPOSetFromXML ( xmlNodePtr  cur)
overridevirtual

create an sposet from xml and save the resulting SPOSet

Implements SPOSetBuilder.

Definition at line 67 of file PWOrbitalSetBuilder.cpp.

References OhmmsAttributeSet::add(), PWOrbitalSetBuilder::createPW(), and OhmmsAttributeSet::put().

68 {
69  int spin_group = 0;
70  std::string spo_object_name;
71  OhmmsAttributeSet aAttrib;
72  aAttrib.add(spin_group, "spindataset");
73  aAttrib.add(spo_object_name, "name");
74  aAttrib.add(spo_object_name, "id");
75  aAttrib.put(cur);
76  return createPW(cur, spo_object_name, spin_group);
77 }
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
std::unique_ptr< SPOSet > createPW(xmlNodePtr cur, const std::string &objname, int spinIndex)
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

◆ getH5()

bool getH5 ( xmlNodePtr  cur,
const char *  aname 
)
private

Definition at line 360 of file PWOrbitalSetBuilder.cpp.

References Communicate::abort(), qmcplusplus::app_error(), OHMMS::Controller, getXMLAttributeValue(), PWOrbitalSetBuilder::hfile, PWOrbitalSetBuilder::myParam, hdf_archive::open(), and PWOrbitalSetBuilder::rootNode.

361 {
362  const std::string a(getXMLAttributeValue(cur, aname));
363  if (a.empty())
364  return false;
365 
366  bool success = hfile.open(a, H5F_ACC_RDONLY | H5P_DEFAULT);
367  if (!success)
368  {
369  app_error() << " Cannot open " << a << " file." << std::endl;
371  }
372  myParam->checkVersion(hfile);
373  //overwrite the parameters
374  myParam->put(rootNode);
375  return success;
376 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
std::ostream & app_error()
Definition: OutputManager.h:67
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
hdf_archive hfile
hdf5 handler to clean up
std::unique_ptr< PWParameterSet > myParam
parameter set
xmlNodePtr rootNode
xml node for determinantset
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
void abort() const

Member Data Documentation

◆ hfile

hdf_archive hfile
private

hdf5 handler to clean up

Definition at line 57 of file PWOrbitalSetBuilder.h.

Referenced by PWOrbitalSetBuilder::createPW(), PWOrbitalSetBuilder::createPWBasis(), and PWOrbitalSetBuilder::getH5().

◆ myBasisSet

std::unique_ptr<PWBasis> myBasisSet
private

◆ myParam

std::unique_ptr<PWParameterSet> myParam
private

◆ rootNode

xmlNodePtr rootNode {nullptr}
private

xml node for determinantset

Definition at line 49 of file PWOrbitalSetBuilder.h.

Referenced by PWOrbitalSetBuilder::getH5().

◆ targetPtcl

const ParticleSet& targetPtcl
private

target particle set

Definition at line 47 of file PWOrbitalSetBuilder.h.

Referenced by PWOrbitalSetBuilder::createPW(), and PWOrbitalSetBuilder::createPWBasis().

◆ TwistAngle

PosType TwistAngle
private

input twist angle

Definition at line 51 of file PWOrbitalSetBuilder.h.

Referenced by PWOrbitalSetBuilder::createPWBasis().


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