QMCPACK
LCAOSpinorBuilder Class Reference
+ Inheritance diagram for LCAOSpinorBuilder:
+ Collaboration diagram for LCAOSpinorBuilder:

Public Member Functions

 LCAOSpinorBuilder (ParticleSet &els, ParticleSet &ions, Communicate *comm, xmlNodePtr cur)
 constructor More...
 
std::unique_ptr< SPOSetcreateSPOSetFromXML (xmlNodePtr cur) override
 creates and returns SpinorSet More...
 
- Public Member Functions inherited from LCAOrbitalBuilder
 LCAOrbitalBuilder (ParticleSet &els, ParticleSet &ions, Communicate *comm, xmlNodePtr cur)
 constructor More...
 
 ~LCAOrbitalBuilder () override
 
const BasissetMapgetBasissetMap () const
 
- 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 Member Functions

bool loadMO (LCAOrbitalSet &up, LCAOrbitalSet &dn, xmlNodePtr cur)
 load the up and down MO sets More...
 
bool putFromH5 (LCAOrbitalSet &up, LCAOrbitalSet &dn, xmlNodePtr)
 parse h5 file for spinor info More...
 

Additional Inherited Members

- Public Types inherited from LCAOrbitalBuilder
using BasisSet_t = LCAOrbitalSet::basis_type
 
using BasissetMap = std::map< std::string, std::unique_ptr< BasisSet_t > >
 
- 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 LCAOrbitalBuilder
template<int I, int J>
BasisSet_tcreateBasisSet (xmlNodePtr cur)
 create basis set More...
 
template<int I, int J>
BasisSet_tcreateBasisSetH5 ()
 
bool loadMO (LCAOrbitalSet &spo, xmlNodePtr cur)
 Parse the xml file for information on the Dirac determinants. More...
 
bool putOccupation (LCAOrbitalSet &spo, xmlNodePtr occ_ptr)
 
bool putFromXML (LCAOrbitalSet &spo, xmlNodePtr coeff_ptr)
 
bool putFromH5 (LCAOrbitalSet &spo, xmlNodePtr coeff_ptr)
 read data from a hdf5 file More...
 
bool putPBCFromH5 (LCAOrbitalSet &spo, xmlNodePtr coeff_ptr)
 read data from a hdf5 file More...
 
void LoadFullCoefsFromH5 (hdf_archive &hin, int setVal, PosType &SuperTwist, Matrix< std::complex< RealType >> &Ctemp, bool MultiDet)
 
void LoadFullCoefsFromH5 (hdf_archive &hin, int setVal, PosType &SuperTwist, Matrix< RealType > &Creal, bool Multidet)
 
void EvalPeriodicImagePhaseFactors (PosType SuperTwist, Vector< RealType, OffloadPinnedAllocator< RealType >> &LocPeriodicImagePhaseFactors, Array< RealType, 2, OffloadPinnedAllocator< RealType >> &LocPeriodicImageDisplacements)
 Periodic Image Phase Factors computation to be determined. More...
 
void EvalPeriodicImagePhaseFactors (PosType SuperTwist, Vector< std::complex< RealType >, OffloadPinnedAllocator< std::complex< RealType >>> &LocPeriodicImagePhaseFactors, Array< RealType, 2, OffloadPinnedAllocator< RealType >> &LocPeriodicImageDisplacements)
 
void readRealMatrixFromH5 (hdf_archive &hin, const std::string &setname, Matrix< LCAOrbitalBuilder::RealType > &Creal) const
 read matrix from h5 file 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 LCAOrbitalBuilder
ParticleSettargetPtcl
 target ParticleSet More...
 
ParticleSetsourcePtcl
 source ParticleSet More...
 
std::map< std::string, std::unique_ptr< BasisSet_t > > basisset_map_
 localized basis set map More...
 
bool cuspCorr
 if true, add cusp correction to orbitals More...
 
std::string h5_path
 Path to HDF5 Wavefunction. More...
 
TinyVector< int, 3 > PBCImages
 Number of periodic Images for Orbital evaluation. More...
 
PosType SuperTwist
 Coordinates Super Twist. More...
 
Vector< ValueType, OffloadPinnedAllocator< ValueType > > PeriodicImagePhaseFactors
 Periodic Image Phase Factors. Correspond to the phase from the PBCImages. Computed only once. More...
 
Array< RealType, 2, OffloadPinnedAllocator< RealType > > PeriodicImageDisplacements
 
Tensor< double, 3 > Lattice
 Store Lattice parameters from HDF5 to use in PeriodicImagePhaseFactors. More...
 
bool doCuspCorrection
 Enable cusp correction. More...
 
std::string useGPU
 Captured gpu input string. More...
 
Vector< RealTypeOcc
 occupation number 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

Definition at line 26 of file LCAOSpinorBuilder.h.

Constructor & Destructor Documentation

◆ LCAOSpinorBuilder()

LCAOSpinorBuilder ( ParticleSet els,
ParticleSet ions,
Communicate comm,
xmlNodePtr  cur 
)

constructor

Parameters
elsreference to the electrons
ionsreference to the ions

Derives from LCAOrbitalBuilder, but will require an h5_path to be set

Definition at line 21 of file LCAOSpinorBuilder.cpp.

References Communicate::barrier_and_abort(), MPIObjectBase::ClassName, LCAOrbitalBuilder::h5_path, and MPIObjectBase::myComm.

22  : LCAOrbitalBuilder(els, ions, comm, cur)
23 {
24  ClassName = "LCAOSpinorBuilder";
25 
26  if (h5_path == "")
27  myComm->barrier_and_abort("LCAOSpinorBuilder only works with href");
28 }
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
LCAOrbitalBuilder(ParticleSet &els, ParticleSet &ions, Communicate *comm, xmlNodePtr cur)
constructor
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
std::string h5_path
Path to HDF5 Wavefunction.
void barrier_and_abort(const std::string &msg) const

Member Function Documentation

◆ createSPOSetFromXML()

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

creates and returns SpinorSet

Creates an up and down LCAOrbitalSet calls LCAOSpinorBuilder::loadMO to build up and down from the H5 file registers up and down into a SpinorSet and returns

Reimplemented from LCAOrbitalBuilder.

Definition at line 30 of file LCAOSpinorBuilder.cpp.

References OhmmsAttributeSet::add(), qmcplusplus::app_log(), Communicate::barrier_and_abort(), LCAOrbitalBuilder::basisset_map_, MPIObjectBase::ClassName, LCAOSpinorBuilder::loadMO(), SoaBasisSetBase< T >::makeClone(), MPIObjectBase::myComm, and OhmmsAttributeSet::put().

31 {
32  ReportEngine PRE(ClassName, "createSPO(xmlNodePtr)");
33  std::string spo_name(""), optimize("no");
34  std::string basisset_name("LCAOBSet");
35  size_t norbs(0);
36  OhmmsAttributeSet spoAttrib;
37  spoAttrib.add(spo_name, "name");
38  spoAttrib.add(optimize, "optimize");
39  spoAttrib.add(basisset_name, "basisset");
40  spoAttrib.add(norbs, "size");
41  spoAttrib.put(cur);
42 
43  BasisSet_t* myBasisSet = nullptr;
44  if (basisset_map_.find(basisset_name) == basisset_map_.end())
45  myComm->barrier_and_abort("basisset \"" + basisset_name + "\" cannot be found\n");
46  else
47  myBasisSet = basisset_map_[basisset_name].get();
48 
49  if (optimize == "yes")
50  app_log() << " SPOSet " << spo_name << " is optimizable\n";
51 
52  std::unique_ptr<LCAOrbitalSet> upspo =
53  std::make_unique<LCAOrbitalSet>(spo_name + "_up", std::unique_ptr<BasisSet_t>(myBasisSet->makeClone()), norbs,
54  false, false);
55  std::unique_ptr<LCAOrbitalSet> dnspo =
56  std::make_unique<LCAOrbitalSet>(spo_name + "_dn", std::unique_ptr<BasisSet_t>(myBasisSet->makeClone()), norbs,
57  false, false);
58  loadMO(*upspo, *dnspo, cur);
59 
60  //create spinor and register up/dn
61  auto spinor_set = std::make_unique<SpinorSet>(spo_name);
62  spinor_set->set_spos(std::move(upspo), std::move(dnspo));
63  return spinor_set;
64 }
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::map< std::string, std::unique_ptr< BasisSet_t > > basisset_map_
localized basis set map
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
LCAOrbitalSet::basis_type BasisSet_t
bool loadMO(LCAOrbitalSet &up, LCAOrbitalSet &dn, xmlNodePtr cur)
load the up and down MO sets
void barrier_and_abort(const std::string &msg) const
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

◆ loadMO()

bool loadMO ( LCAOrbitalSet up,
LCAOrbitalSet dn,
xmlNodePtr  cur 
)
private

load the up and down MO sets

checks to make sure not PBC and initialize the Occ vector. call putFromH5 to parse the up and down MO coefficients

Definition at line 66 of file LCAOSpinorBuilder.cpp.

References OhmmsAttributeSet::add(), qmcplusplus::app_log(), Communicate::barrier_and_abort(), Communicate::bcast(), LCAOrbitalSet::C, hdf_archive::close(), LCAOrbitalBuilder::h5_path, MPIObjectBase::myComm, hdf_archive::open(), hdf_archive::push(), OhmmsAttributeSet::put(), LCAOSpinorBuilder::putFromH5(), Communicate::rank(), and hdf_archive::read().

Referenced by LCAOSpinorBuilder::createSPOSetFromXML().

67 {
68  bool PBC = false;
69  std::string debugc("no");
70  OhmmsAttributeSet aAttrib;
71  aAttrib.add(debugc, "debug");
72  aAttrib.put(cur);
73 
74  xmlNodePtr occ_ptr = nullptr;
75  cur = cur->xmlChildrenNode;
76  while (cur != nullptr)
77  {
78  std::string cname((const char*)(cur->name));
79  if (cname == "occupation")
80  {
81  occ_ptr = cur;
82  }
83  cur = cur->next;
84  }
85 
86  hdf_archive hin(myComm);
87  if (myComm->rank() == 0)
88  {
89  if (!hin.open(h5_path, H5F_ACC_RDONLY))
90  myComm->barrier_and_abort("LCAOSpinorBuilder::loadMO missing or incorrect path to H5 file.");
91  hin.push("PBC");
92  PBC = false;
93  hin.read(PBC, "PBC");
94  hin.close();
95  }
96  myComm->bcast(PBC);
97  if (PBC)
98  myComm->barrier_and_abort("LCAOSpinorBuilder::loadMO lcao spinors not implemented in PBC");
99 
100  bool success = putFromH5(up, dn, occ_ptr);
101 
102 
103  if (debugc == "yes")
104  {
105  app_log() << "UP: Single-particle orbital coefficients dims=" << up.C->rows() << " x " << up.C->cols()
106  << std::endl;
107  app_log() << *up.C << std::endl;
108  app_log() << "DN: Single-particle orbital coefficients dims=" << dn.C->rows() << " x " << dn.C->cols()
109  << std::endl;
110  app_log() << *dn.C << std::endl;
111  }
112  return success;
113 }
int rank() const
return the rank
Definition: Communicate.h:116
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.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
std::string h5_path
Path to HDF5 Wavefunction.
bool putFromH5(LCAOrbitalSet &up, LCAOrbitalSet &dn, xmlNodePtr)
parse h5 file for spinor info
void bcast(T &)
void barrier_and_abort(const std::string &msg) const
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

◆ putFromH5()

bool putFromH5 ( LCAOrbitalSet up,
LCAOrbitalSet dn,
xmlNodePtr  occ_ptr 
)
private

parse h5 file for spinor info

assumes the h5 file has KPTS_0/eigenset_0(_imag) for the real/imag part of up component of spinor assumes the h5 file as KPTS_0/eigenset_1(_imag) for the real/imag part of dn component of spinor reads the various coefficient matricies and broadcast after this, we have up/dn LCAOrbitalSet that can be registered to the SpinorSet

Definition at line 115 of file LCAOSpinorBuilder.cpp.

References Communicate::barrier_and_abort(), LCAOrbitalSet::C, hdf_archive::close(), Matrix< T, Alloc >::cols(), copy(), LCAOrbitalSet::getBasisSetSize(), SPOSet::getOrbitalSetSize(), LCAOrbitalBuilder::h5_path, MPIObjectBase::myComm, qmcplusplus::n, LCAOrbitalBuilder::Occ, hdf_archive::open(), LCAOrbitalBuilder::putOccupation(), Communicate::rank(), LCAOrbitalBuilder::readRealMatrixFromH5(), Vector< T, Alloc >::resize(), and Matrix< T, Alloc >::rows().

Referenced by LCAOSpinorBuilder::loadMO().

116 {
117 #ifdef QMC_COMPLEX
118  if (up.getBasisSetSize() == 0 || dn.getBasisSetSize() == 0)
119  {
120  myComm->barrier_and_abort("LCASpinorBuilder::loadMO detected ZERO BasisSetSize");
121  return false;
122  }
123 
124  bool success = true;
125  hdf_archive hin(myComm);
126  if (myComm->rank() == 0)
127  {
128  if (!hin.open(h5_path, H5F_ACC_RDONLY))
129  myComm->barrier_and_abort("LCAOSpinorBuilder::putFromH5 missing or incorrect path to H5 file");
130 
131  Matrix<RealType> upReal;
132  Matrix<RealType> upImag;
133  std::string setname = "/Super_Twist/eigenset_0";
134  readRealMatrixFromH5(hin, setname, upReal);
135  setname += "_imag";
136  readRealMatrixFromH5(hin, setname, upImag);
137 
138  assert(upReal.rows() == upImag.rows());
139  assert(upReal.cols() == upImag.cols());
140 
141  Matrix<ValueType> upTemp(upReal.rows(), upReal.cols());
142  for (int i = 0; i < upTemp.rows(); i++)
143  {
144  for (int j = 0; j < upTemp.cols(); j++)
145  {
146  upTemp[i][j] = ValueType(upReal[i][j], upImag[i][j]);
147  }
148  }
149 
150  Matrix<RealType> dnReal;
151  Matrix<RealType> dnImag;
152  setname = "/Super_Twist/eigenset_1";
153  readRealMatrixFromH5(hin, setname, dnReal);
154  setname += "_imag";
155  readRealMatrixFromH5(hin, setname, dnImag);
156 
157  assert(dnReal.rows() == dnImag.rows());
158  assert(dnReal.cols() == dnImag.cols());
159 
160  Matrix<ValueType> dnTemp(dnReal.rows(), dnReal.cols());
161  for (int i = 0; i < dnTemp.rows(); i++)
162  {
163  for (int j = 0; j < dnTemp.cols(); j++)
164  {
165  dnTemp[i][j] = ValueType(dnReal[i][j], dnImag[i][j]);
166  }
167  }
168 
169  assert(upReal.rows() == dnReal.rows());
170  assert(upReal.cols() == dnReal.cols());
171 
172  Occ.resize(upReal.rows());
173  success = putOccupation(up, occ_ptr);
174 
175  int norbs = up.getOrbitalSetSize();
176 
177  int n = 0, i = 0;
178  while (i < norbs)
179  {
180  if (Occ[n] > 0.0)
181  {
182  std::copy(upTemp[n], upTemp[n + 1], (*up.C)[i]);
183  std::copy(dnTemp[n], dnTemp[n + 1], (*dn.C)[i]);
184  i++;
185  }
186  n++;
187  }
188 
189  hin.close();
190  }
191 
192 #ifdef HAVE_MPI
193  myComm->comm.broadcast_n(up.C->data(), up.C->size());
194  myComm->comm.broadcast_n(dn.C->data(), dn.C->size());
195 #endif
196 
197 #else
198  myComm->barrier_and_abort("LCAOSpinorBuilder::putFromH5 Must build with QMC_COMPLEX");
199 #endif
200 
201  return success;
202 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
int rank() const
return the rank
Definition: Communicate.h:116
Vector< RealType > Occ
occupation number
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
QTBase::ValueType ValueType
Definition: Configuration.h:60
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
bool putOccupation(LCAOrbitalSet &spo, xmlNodePtr occ_ptr)
std::string h5_path
Path to HDF5 Wavefunction.
void readRealMatrixFromH5(hdf_archive &hin, const std::string &setname, Matrix< LCAOrbitalBuilder::RealType > &Creal) const
read matrix from h5 file
void barrier_and_abort(const std::string &msg) const

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