QMCPACK
EinsplineSetBuilder Class Reference

EinsplineSet builder. More...

+ Inheritance diagram for EinsplineSetBuilder:
+ Collaboration diagram for EinsplineSetBuilder:

Classes

struct  CenterInfo
 

Public Types

enum  FormatType { QMCPACK, ESHDF }
 
using PSetMap = std::map< std::string, const std::unique_ptr< ParticleSet > >
 
using UnitCellType = CrystalLattice< ParticleSet::Scalar_t, DIM >
 
- 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 Member Functions

 EinsplineSetBuilder (ParticleSet &p, const PSetMap &psets, Communicate *comm, xmlNodePtr cur)
 constructor More...
 
 ~EinsplineSetBuilder () override
 destructor More...
 
std::unique_ptr< SPOSetcreateSPOSetFromXML (xmlNodePtr cur) override
 initialize the Antisymmetric wave function for electrons More...
 
std::unique_ptr< SPOSetcreateSPOSet (xmlNodePtr cur, SPOSetInputInfo &input_info) override
 initialize with the existing SPOSet More...
 
bool ReadOrbitalInfo (bool skipChecks=false)
 
bool ReadOrbitalInfo_ESHDF (bool skipChecks=false)
 
void BroadcastOrbitalInfo ()
 
bool CheckLattice ()
 
bool ReadGvectors_ESHDF ()
 read gvectors for each twist More...
 
bool TwistPair (PosType a, PosType b) const
 
void TileIons ()
 
void OccupyBands (int spin, int sortBands, int numOrbs, bool skipChecks=false)
 
void OccupyBands_ESHDF (int spin, int sortBands, int numOrbs)
 
std::string OrbitalPath (int ti, int bi)
 
- 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)
 

Public Attributes

const PSetMapParticleSets
 reference to the particleset pool More...
 
ParticleSetTargetPtcl
 quantum particle set More...
 
ParticleSetSourcePtcl
 ionic system More...
 
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
 Helper vector for sorting bands. More...
 
std::unique_ptr< BsplineReaderMixedSplineReader
 reader to use BsplineReader More...
 
bool HaveOrbDerivs
 This is true if we have the orbital derivatives w.r.t. the ion positions. More...
 
xmlNodePtr XMLRoot
 root XML node with href, sort, tilematrix, twistnum, source, precision,truncate,version More...
 
std::map< H5OrbSet, SPOSet *, H5OrbSetSPOSetMap
 
hdf_archive H5File
 
std::filesystem::path H5FileName
 
FormatType Format
 
TinyVector< int, 3 > Version
 
std::string parameterGroup
 
std::string ionsGroup
 
std::string eigenstatesGroup
 
std::vector< int > Occ
 
Tensor< double, OHMMS_DIMLattice
 
Tensor< double, OHMMS_DIMRecipLattice
 
Tensor< double, OHMMS_DIMLatticeInv
 
Tensor< double, OHMMS_DIMSuperLattice
 
Tensor< double, OHMMS_DIMGGt
 
UnitCellType SuperCell
 
UnitCellType PrimCell
 
UnitCellType PrimCellInv
 
int NumBands
 
int NumElectrons
 
int NumSpins
 
int NumTwists
 
int MaxNumGvecs
 
double MeshFactor
 
RealType MatchingTol
 
TinyVector< int, 3 > MeshSize
 
std::vector< std::vector< TinyVector< int, 3 > > > Gvecs
 
Vector< int > IonTypes
 
Vector< TinyVector< double, OHMMS_DIM > > IonPos
 
std::vector< int > Super2Prim
 
int twist_num_
 
std::vector< TinyVector< double, OHMMS_DIM > > primcell_kpoints
 
Tensor< int, OHMMS_DIMTileMatrix
 
std::vector< TinyVector< int, OHMMS_DIM > > UseTwists
 
std::vector< int > IncludeTwists
 
std::vector< int > DistinctTwists
 
bool use_real_splines_
 if false, splines are conceptually complex valued More...
 
int NumDistinctOrbitals
 
std::vector< bool > MakeTwoCopies
 
std::map< TinyVector< int, OHMMS_DIM >, int, Int3lessTwistMap
 
struct qmcplusplus::EinsplineSetBuilder::CenterInfo AtomicCentersInfo
 
int LastSpinSet
 
int NumOrbitalsRead
 
std::string occ_format
 
int particle_hole_pairs
 
bool makeRotations
 
- 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

void bcastSortBands (int splin, int N, bool root)
 broadcast SortBands More...
 
void set_metadata (int numOrbs, int twist_num_inp, const TinyVector< double, OHMMS_DIM > &twist_inp, bool skipChecks=false)
 a specific but clean code path in createSPOSetFromXML, for PBC, double, ESHDF More...
 
void AnalyzeTwists2 (const int twist_num_inp, const TinyVector< double, OHMMS_DIM > &twist_inp)
 analyze twists of orbitals in h5 and determinine twist_num_ More...
 

Static Protected Attributes

static constexpr int TWISTNUM_NO_INPUT = -9999
 twistnum_inp == -9999 to indicate no given input after parsing XML More...
 
static constexpr double TWIST_NO_INPUT = -9999
 twist_inp[i] <= -9999 to indicate no given input after parsing XML More...
 

Additional Inherited Members

- 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

EinsplineSet builder.

Definition at line 114 of file EinsplineSetBuilder.h.

Member Typedef Documentation

◆ PSetMap

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

Definition at line 117 of file EinsplineSetBuilder.h.

◆ UnitCellType

Member Enumeration Documentation

◆ FormatType

Constructor & Destructor Documentation

◆ EinsplineSetBuilder()

EinsplineSetBuilder ( ParticleSet p,
const PSetMap psets,
Communicate comm,
xmlNodePtr  cur 
)

constructor

Definition at line 41 of file EinsplineSetBuilderCommon.cpp.

References MPIObjectBase::ClassName, EinsplineSetBuilder::FullBands, ParticleSet::groups(), EinsplineSetBuilder::MatchingTol, SPOSetBuilder::states, and EinsplineSetBuilder::TileMatrix.

42  : SPOSetBuilder("spline", comm),
43  ParticleSets(psets),
44  TargetPtcl(p),
45  XMLRoot(cur),
46  Format(QMCPACK),
47  NumBands(0),
48  NumElectrons(0),
49  NumSpins(0),
50  NumTwists(0),
51  MeshFactor(1.0),
52  MeshSize(0, 0, 0),
53  twist_num_(-1),
54  LastSpinSet(-1),
55  NumOrbitalsRead(-1),
56  makeRotations(false)
57 {
58  ClassName = "EinsplineSetBuilder";
59 
60  MatchingTol = 10 * std::numeric_limits<float>::epsilon();
61  for (int i = 0; i < 3; i++)
62  for (int j = 0; j < 3; j++)
63  TileMatrix(i, j) = 0;
64 
65  //invalidate states by the basis class
66  states.clear();
67  states.resize(p.groups());
68 
69  //create vectors with nullptr
70  FullBands.resize(p.groups());
71 }
const PSetMap & ParticleSets
reference to the particleset pool
Tensor< int, OHMMS_DIM > TileMatrix
ParticleSet & TargetPtcl
quantum particle set
std::vector< std::unique_ptr< SPOSetInfo > > states
state info of all possible states available in the basis
Definition: SPOSetBuilder.h:57
SPOSetBuilder(const std::string &type_name, Communicate *comm)
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
Helper vector for sorting bands.
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
xmlNodePtr XMLRoot
root XML node with href, sort, tilematrix, twistnum, source, precision,truncate,version ...

◆ ~EinsplineSetBuilder()

~EinsplineSetBuilder ( )
override

destructor

Definition at line 86 of file EinsplineSetBuilderCommon.cpp.

References DEBUG_MEMORY.

86 { DEBUG_MEMORY("EinsplineSetBuilder::~EinsplineSetBuilder"); }
#define DEBUG_MEMORY(msg)
Definition: Configuration.h:31

Member Function Documentation

◆ AnalyzeTwists2()

void AnalyzeTwists2 ( const int  twist_num_inp,
const TinyVector< double, OHMMS_DIM > &  twist_inp 
)
protected

analyze twists of orbitals in h5 and determinine twist_num_

Parameters
twist_num_inptwistnum XML input
twist_inptwst XML input

Definition at line 332 of file EinsplineSetBuilderCommon.cpp.

References qmcplusplus::abs(), APP_ABORT, APP_ABORT_TRACE, qmcplusplus::app_error(), qmcplusplus::app_log(), qmcplusplus::app_warning(), qmcplusplus::det(), EinsplineSetBuilder::DistinctTwists, qmcplusplus::dot(), qmcplusplus::Units::charge::e, qmcplusplus::FracPart(), EinsplineSetBuilder::IncludeTwists, qmcplusplus::IntPart(), CrystalLattice< T, D >::k_cart(), EinsplineSetBuilder::MakeTwoCopies, EinsplineSetBuilder::MatchingTol, MPIObjectBase::myComm, qmcplusplus::Units::force::N, OHMMS_DIM, EinsplineSetBuilder::PrimCell, EinsplineSetBuilder::primcell_kpoints, Communicate::rank(), ParticleSet::setTwist(), TinyVector< T, D >::size(), EinsplineSetBuilder::SuperCell, EinsplineSetBuilder::TargetPtcl, EinsplineSetBuilder::TileMatrix, EinsplineSetBuilder::TWIST_NO_INPUT, EinsplineSetBuilder::twist_num_, EinsplineSetBuilder::TWISTNUM_NO_INPUT, EinsplineSetBuilder::TwistPair(), and EinsplineSetBuilder::use_real_splines_.

Referenced by EinsplineSetBuilder::set_metadata().

333 {
334  Tensor<double, 3> S;
335  for (int i = 0; i < 3; i++)
336  for (int j = 0; j < 3; j++)
337  S(i, j) = (double)TileMatrix(i, j);
338 
339  const int num_prim_kpoints = primcell_kpoints.size();
340 
341  // build a list of unique super twists that all the primitive cell k-point correspond to.
342  std::vector<PosType> superFracs; // twist super twist coordinates
343  std::vector<int>
344  superIndex; // the indices of the super twists that correpsond to all the primitive cell k-points in the unique list.
345  {
346  // scan all the primitive cell k-points
347  for (int ki = 0; ki < num_prim_kpoints; ki++)
348  {
349  PosType primTwist = primcell_kpoints[ki];
350  PosType superTwist = dot(S, primTwist);
351  PosType kp = PrimCell.k_cart(primTwist);
352  PosType ks = SuperCell.k_cart(superTwist);
353  // check the consistency of tiling, primitive and super cells.
354  if (dot(ks - kp, ks - kp) > 1.0e-6)
355  {
356  app_error() << "Primitive and super k-points do not agree. Error in coding.\n";
357  APP_ABORT("EinsplineSetBuilder::AnalyzeTwists2");
358  }
359  PosType frac = FracPart(superTwist);
360  // verify if the super twist that correpsonds to this primitive cell k-point exists in the unique list or not.
361  bool found = false;
362  for (int j = 0; j < superFracs.size(); j++)
363  {
364  PosType diff = frac - superFracs[j];
365  if (dot(diff, diff) < 1.0e-6)
366  {
367  found = true;
368  superIndex.push_back(j);
369  }
370  }
371  if (!found)
372  {
373  superIndex.push_back(superFracs.size());
374  superFracs.push_back(frac);
375  }
376  }
377  assert(superIndex.size() == num_prim_kpoints);
378  }
379 
380  const int numSuperTwists = superFracs.size();
381  {
382  app_log() << "Found " << numSuperTwists << " distinct supercell twist" << (numSuperTwists > 1 ? "s" : "")
383  << " based on " << num_prim_kpoints << " primitive cell k-point" << (num_prim_kpoints > 1 ? "s" : "")
384  << std::endl;
385  if (myComm->rank() == 0)
386  {
387  int n_tot_irred(0);
388  for (int si = 0; si < numSuperTwists; si++)
389  {
390  std::array<char, 1000> buf;
391  int length = std::snprintf(buf.data(), buf.size(), "Super twist #%d: [ %9.5f %9.5f %9.5f ]\n", si,
392  superFracs[si][0], superFracs[si][1], superFracs[si][2]);
393  if (length < 0)
394  throw std::runtime_error("Error converting Super twist to a string");
395  app_log() << std::string_view(buf.data(), length);
396  app_log().flush();
397  }
398  }
399  }
400 
401  // For each supercell twist, create a list of primitive twists which correspond to it.
402  std::vector<std::vector<int>> superSets;
403  {
404  superSets.resize(numSuperTwists);
405  for (int ki = 0; ki < num_prim_kpoints; ki++)
406  superSets[superIndex[ki]].push_back(ki);
407  }
408 
409  { // look up a super cell twist and return its index in the unique list of super cell twists.
410  std::function find_twist = [&](const TinyVector<double, OHMMS_DIM>& twist) {
411  int twist_num = -1;
412  PosType gtFrac = FracPart(twist);
413  float eps = 1e-5;
414  for (int si = 0; si < numSuperTwists; si++)
415  {
416  PosType locDiff = gtFrac - superFracs[si];
417  if (dot(locDiff, locDiff) < eps)
418  twist_num = si;
419  }
420 
421  if (twist_num < 0)
422  {
423  std::array<char, 1000> buf;
424  int length = std::
425  snprintf(buf.data(), buf.size(),
426  "AnalyzeTwists2. Input twist [ %9.5f %9.5f %9.5f] not found in the list of super twists above.\n",
427  twist[0], twist[1], twist[2]);
428  if (length < 0)
429  throw std::runtime_error("Error generating error message");
430  throw UniformCommunicateError(buf.data());
431  }
432  return twist_num;
433  };
434 
435  if (twist_inp[0] > TWIST_NO_INPUT || twist_inp[1] > TWIST_NO_INPUT || twist_inp[2] > TWIST_NO_INPUT)
436  {
437  if (twist_num_inp != TWISTNUM_NO_INPUT)
438  app_warning() << "twist attribute exists. twistnum attribute ignored. "
439  "To prevent this message, remove twistnum from input."
440  << std::endl;
441 
442  twist_num_ = find_twist(twist_inp);
443  }
444  else if (twist_num_inp != TWISTNUM_NO_INPUT)
445  {
446  app_warning() << "twist attribute does't exist but twistnum attribute was found. "
447  << "This is potentially ambiguous. Specifying twist attribute is preferred." << std::endl;
448  if (twist_num_inp < 0 || twist_num_inp >= numSuperTwists)
449  {
450  std::ostringstream msg;
451  msg << "AnalyzeTwists2. twistnum input value " << twist_num_inp << " is outside the acceptable range [0, "
452  << numSuperTwists << ")." << std::endl;
453  throw UniformCommunicateError(msg.str());
454  }
455  twist_num_ = twist_num_inp;
456  }
457  else
458  {
459  app_log() << "twist attribte does't exist. Set Gamma point." << std::endl;
460  twist_num_ = find_twist({0, 0, 0});
461  }
462 
463  assert(twist_num_ >= 0 && twist_num_ < numSuperTwists);
464 
465  std::array<char, 1000> buf;
466  int length = std::snprintf(buf.data(), buf.size(), " Using supercell twist %d: [ %9.5f %9.5f %9.5f]", twist_num_,
467  superFracs[twist_num_][0], superFracs[twist_num_][1], superFracs[twist_num_][2]);
468  if (length < 0)
469  throw std::runtime_error("Error converting supercell twist to a string");
470  app_log() << std::string_view(buf.data(), length) << std::endl;
471  }
472 
473  TargetPtcl.setTwist(superFracs[twist_num_]);
474 #ifndef QMC_COMPLEX
475  // Check to see if supercell twist is okay to use with real wave
476  // functions
477  for (int dim = 0; dim < OHMMS_DIM; dim++)
478  {
479  double t = 2.0 * superFracs[twist_num_][dim];
480  if (std::abs(t - round(t)) > MatchingTol * 100)
481  {
482  app_error() << "Cannot use this super twist with real wavefunctions.\n"
483  << "Please recompile with QMC_COMPLEX=1.\n";
484  APP_ABORT("EinsplineSetBuilder::AnalyzeTwists2");
485  }
486  }
487 #endif
488  // Now check to see that each supercell twist has the right twists
489  // to tile the primitive cell orbitals.
490  const int numTwistsNeeded = std::abs(det(TileMatrix));
491  for (int si = 0; si < numSuperTwists; si++)
492  {
493  // First make sure we have enough points
494  if (superSets[si].size() != numTwistsNeeded)
495  {
496  std::array<char, 1000> buf;
497  int length = std::snprintf(buf.data(), buf.size(), "Super twist %d should own %d k-points, but owns %d.\n", si,
498  numTwistsNeeded, static_cast<int>(superSets[si].size()));
499  if (length < 0)
500  throw std::runtime_error("Error generating Super twist string");
501  app_error() << std::string_view(buf.data(), length);
502  if (si == twist_num_)
503  {
504  APP_ABORT("EinsplineSetBuilder::AnalyzeTwists2");
505  }
506  else
507  continue;
508  }
509  // Now, make sure they are all distinct
510  int N = superSets[si].size();
511  for (int i = 0; i < N; i++)
512  {
513  PosType twistPrim_i = primcell_kpoints[superSets[si][i]];
514  PosType twistSuper_i = dot(S, twistPrim_i);
515  PosType superInt_i = IntPart(twistSuper_i);
516  for (int j = i + 1; j < N; j++)
517  {
518  PosType twistPrim_j = primcell_kpoints[superSets[si][j]];
519  PosType twistSuper_j = dot(S, twistPrim_j);
520  PosType superInt_j = IntPart(twistSuper_j);
521  if (dot(superInt_i - superInt_j, superInt_i - superInt_j) < 1.0e-6)
522  {
523  app_error() << "Identical k-points detected in super twist set " << si << std::endl;
524  APP_ABORT_TRACE(__FILE__, __LINE__, "AnalyzeTwists2");
525  }
526  }
527  }
528  }
529  app_log().flush();
530  // Finally, record which k-points to include on this group of
531  // processors, which have been assigned supercell twist twist_num_
532  IncludeTwists.clear();
533  for (int i = 0; i < superSets[twist_num_].size(); i++)
534  IncludeTwists.push_back(superSets[twist_num_][i]);
535  // Now, find out which twists are distinct
536  DistinctTwists.clear();
537 #ifndef QMC_COMPLEX
538  std::vector<int> copyTwists;
539  for (int i = 0; i < IncludeTwists.size(); i++)
540  {
541  int ti = IncludeTwists[i];
542  PosType twist_i = primcell_kpoints[ti];
543  bool distinct = true;
544  for (int j = i + 1; j < IncludeTwists.size(); j++)
545  {
546  int tj = IncludeTwists[j];
547  PosType twist_j = primcell_kpoints[tj];
548  PosType sum = twist_i + twist_j;
549  PosType diff = twist_i - twist_j;
550  if (TwistPair(twist_i, twist_j))
551  distinct = false;
552  }
553  if (distinct)
554  DistinctTwists.push_back(ti);
555  else
556  copyTwists.push_back(ti);
557  }
558  // Now determine which distinct twists require two copies
559  MakeTwoCopies.resize(DistinctTwists.size());
560  for (int i = 0; i < DistinctTwists.size(); i++)
561  {
562  MakeTwoCopies[i] = false;
563  int ti = DistinctTwists[i];
564  PosType twist_i = primcell_kpoints[ti];
565  for (int j = 0; j < copyTwists.size(); j++)
566  {
567  int tj = copyTwists[j];
568  PosType twist_j = primcell_kpoints[tj];
569  if (TwistPair(twist_i, twist_j))
570  MakeTwoCopies[i] = true;
571  }
572  if (myComm->rank() == 0)
573  {
574  std::array<char, 1000> buf;
575  int length = std::snprintf(buf.data(), buf.size(), "Using %d copies of twist angle [%6.3f, %6.3f, %6.3f]\n",
576  MakeTwoCopies[i] ? 2 : 1, twist_i[0], twist_i[1], twist_i[2]);
577  if (length < 0)
578  throw std::runtime_error("Error generating string");
579  app_log() << std::string_view(buf.data(), length);
580  app_log().flush();
581  }
582  }
583  // Find out if we can make real orbitals
584  use_real_splines_ = true;
585  for (int i = 0; i < DistinctTwists.size(); i++)
586  {
587  int ti = DistinctTwists[i];
588  PosType twist = primcell_kpoints[ti];
589  for (int j = 0; j < OHMMS_DIM; j++)
590  if (std::abs(twist[j] - 0.0) > MatchingTol && std::abs(twist[j] - 0.5) > MatchingTol &&
591  std::abs(twist[j] + 0.5) > MatchingTol)
592  use_real_splines_ = false;
593  }
594  if (use_real_splines_ && (DistinctTwists.size() > 1))
595  {
596  app_log() << "***** Use of real orbitals is possible, but not currently implemented\n"
597  << " with more than one twist angle.\n";
598  use_real_splines_ = false;
599  }
600  if (use_real_splines_)
601  app_log() << "Using real splines.\n";
602  else
603  app_log() << "Using complex splines.\n";
604 #else
605  DistinctTwists.resize(IncludeTwists.size());
606  MakeTwoCopies.resize(IncludeTwists.size());
607  for (int i = 0; i < IncludeTwists.size(); i++)
608  {
610  MakeTwoCopies[i] = false;
611  }
612  use_real_splines_ = false;
613 #endif
614 }
bool TwistPair(PosType a, PosType b) const
Tensor< int, OHMMS_DIM > TileMatrix
std::ostream & app_warning()
Definition: OutputManager.h:69
int rank() const
return the rank
Definition: Communicate.h:116
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
Definition: TensorOps.h:838
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::ostream & app_log()
Definition: OutputManager.h:65
ParticleSet & TargetPtcl
quantum particle set
TinyVector< T, 3 > FracPart(const TinyVector< T, 3 > &twist)
std::ostream & app_error()
Definition: OutputManager.h:67
#define OHMMS_DIM
Definition: config.h:64
QMCTraits::PosType PosType
TinyVector< T, 3 > IntPart(const TinyVector< T, 3 > &twist)
SingleParticlePos k_cart(const SingleParticlePos &kin) const
conversion of a reciprocal-vector
static constexpr double TWIST_NO_INPUT
twist_inp[i] <= -9999 to indicate no given input after parsing XML
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void setTwist(const SingleParticlePos &t)
Definition: ParticleSet.h:481
static constexpr int TWISTNUM_NO_INPUT
twistnum_inp == -9999 to indicate no given input after parsing XML
std::vector< TinyVector< double, OHMMS_DIM > > primcell_kpoints
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
#define APP_ABORT_TRACE(f, l, msg)
Definition: AppAbort.h:34
bool use_real_splines_
if false, splines are conceptually complex valued

◆ bcastSortBands()

void bcastSortBands ( int  splin,
int  N,
bool  root 
)
protected

broadcast SortBands

Parameters
Nnumber of state
roottrue if it is the i/o node

Definition at line 702 of file EinsplineSetBuilderCommon.cpp.

References qmcplusplus::bcast(), Communicate::bcast(), EinsplineSetBuilder::FullBands, PooledData< T >::get(), EinsplineSetBuilder::MakeTwoCopies, MPIObjectBase::myComm, qmcplusplus::n, EinsplineSetBuilder::NumDistinctOrbitals, PooledData< T >::put(), and PooledData< T >::rewind().

Referenced by EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

703 {
704  std::vector<BandInfo>& SortBands(*FullBands[spin]);
705 
706  TinyVector<int, 2> nbands(int(SortBands.size()), n);
707  mpi::bcast(*myComm, nbands);
708 
709  //buffer to serialize BandInfo
710  PooledData<OHMMS_PRECISION_FULL> misc(nbands[0] * 4);
711  n = NumDistinctOrbitals = nbands[1];
712 
713  if (root)
714  {
715  misc.rewind();
716  for (int i = 0; i < n; ++i)
717  {
718  misc.put(SortBands[i].TwistIndex);
719  misc.put(SortBands[i].BandIndex);
720  misc.put(SortBands[i].Energy);
721  misc.put(SortBands[i].MakeTwoCopies);
722  }
723 
724  for (int i = n; i < SortBands.size(); ++i)
725  {
726  misc.put(SortBands[i].TwistIndex);
727  misc.put(SortBands[i].BandIndex);
728  misc.put(SortBands[i].Energy);
729  misc.put(SortBands[i].MakeTwoCopies);
730  }
731  }
732  myComm->bcast(misc);
733 
734  if (!root)
735  {
736  SortBands.resize(nbands[0]);
737  misc.rewind();
738  for (int i = 0; i < n; ++i)
739  {
740  misc.get(SortBands[i].TwistIndex);
741  misc.get(SortBands[i].BandIndex);
742  misc.get(SortBands[i].Energy);
743  misc.get(SortBands[i].MakeTwoCopies);
744  }
745  for (int i = n; i < SortBands.size(); ++i)
746  {
747  misc.get(SortBands[i].TwistIndex);
748  misc.get(SortBands[i].BandIndex);
749  misc.get(SortBands[i].Energy);
750  misc.get(SortBands[i].MakeTwoCopies);
751  }
752  }
753 }
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
Helper vector for sorting bands.
void bcast(T &a, Communicate *comm)
Definition: CommUtilities.h:78
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
void bcast(T &)

◆ BroadcastOrbitalInfo()

void BroadcastOrbitalInfo ( )

Definition at line 121 of file EinsplineSetBuilderCommon.cpp.

References PooledData< T >::add(), EinsplineSetBuilder::AtomicCentersInfo, Communicate::bcast(), TinyVector< T, D >::begin(), Tensor< T, D >::begin(), EinsplineSetBuilder::CenterInfo::cutoff, ParticleSet::Density_G, ParticleSet::DensityReducedGvecs, TinyVector< T, D >::end(), Tensor< T, D >::end(), EinsplineSetBuilder::Format, PooledData< T >::get(), EinsplineSetBuilder::CenterInfo::GroupID, EinsplineSetBuilder::HaveOrbDerivs, EinsplineSetBuilder::CenterInfo::inner_cutoff, EinsplineSetBuilder::CenterInfo::ion_pos, EinsplineSetBuilder::IonPos, EinsplineSetBuilder::IonTypes, EinsplineSetBuilder::LatticeInv, EinsplineSetBuilder::CenterInfo::lmax, MPIObjectBase::myComm, EinsplineSetBuilder::CenterInfo::non_overlapping_radius, EinsplineSetBuilder::NumBands, EinsplineSetBuilder::NumElectrons, EinsplineSetBuilder::NumSpins, EinsplineSetBuilder::NumTwists, OHMMS_DIM, EinsplineSetBuilder::primcell_kpoints, ParticleSet::R, Communicate::rank(), EinsplineSetBuilder::RecipLattice, Vector< T, Alloc >::resize(), EinsplineSetBuilder::CenterInfo::resize(), PooledData< T >::rewind(), Communicate::size(), Vector< T, Alloc >::size(), EinsplineSetBuilder::SourcePtcl, EinsplineSetBuilder::CenterInfo::spline_npoints, EinsplineSetBuilder::CenterInfo::spline_radius, EinsplineSetBuilder::Super2Prim, EinsplineSetBuilder::SuperLattice, EinsplineSetBuilder::TargetPtcl, and EinsplineSetBuilder::Version.

Referenced by EinsplineSetBuilder::set_metadata().

122 {
123  if (myComm->size() == 1)
124  return;
125  int numIons = IonTypes.size();
126  int numDensityGvecs = TargetPtcl.DensityReducedGvecs.size();
127  PooledData<double> abuffer;
128  PooledData<int> aibuffer;
129  aibuffer.add(Version.begin(), Version.end()); //myComm->bcast(Version);
130  aibuffer.add(Format);
131  abuffer.add(Lattice.begin(), Lattice.end()); //myComm->bcast(Lattice);
132  abuffer.add(RecipLattice.begin(), RecipLattice.end()); //myComm->bcast(RecipLattice);
133  abuffer.add(SuperLattice.begin(), SuperLattice.end()); //myComm->bcast(SuperLattice);
134  abuffer.add(LatticeInv.begin(), LatticeInv.end()); //myComm->bcast(LatticeInv);
135  aibuffer.add(NumBands); //myComm->bcast(NumBands);
136  aibuffer.add(NumElectrons); //myComm->bcast(NumElectrons);
137  aibuffer.add(NumSpins); //myComm->bcast(NumSpins);
138  aibuffer.add(NumTwists); //myComm->bcast(NumTwists);
139  aibuffer.add(numIons); //myComm->bcast(numIons);
140  aibuffer.add(numDensityGvecs);
141  aibuffer.add(HaveOrbDerivs);
142  myComm->bcast(abuffer);
143  myComm->bcast(aibuffer);
144  if (myComm->rank())
145  {
146  abuffer.rewind();
147  aibuffer.rewind();
148  aibuffer.get(Version.begin(), Version.end());
149  aibuffer.get(Format);
150  abuffer.get(Lattice.begin(), Lattice.end());
151  abuffer.get(RecipLattice.begin(), RecipLattice.end());
152  abuffer.get(SuperLattice.begin(), SuperLattice.end());
153  abuffer.get(LatticeInv.begin(), LatticeInv.end());
154  aibuffer.get(NumBands);
155  aibuffer.get(NumElectrons);
156  aibuffer.get(NumSpins);
157  aibuffer.get(NumTwists);
158  aibuffer.get(numIons);
159  aibuffer.get(numDensityGvecs);
160  aibuffer.get(HaveOrbDerivs);
161  TargetPtcl.DensityReducedGvecs.resize(numDensityGvecs);
162  TargetPtcl.Density_G.resize(numDensityGvecs);
163  }
164  if (IonTypes.size() != numIons)
165  {
166  IonTypes.resize(numIons);
167  IonPos.resize(numIons);
168  }
169  //new buffer
170  PooledData<double> bbuffer;
171  PooledData<int> bibuffer;
172  for (int i = 0; i < numIons; ++i)
173  bibuffer.add(IonTypes[i]);
174  //myComm->bcast(IonTypes);
175  bbuffer.add(&IonPos[0][0], &IonPos[0][0] + OHMMS_DIM * numIons);
176  //myComm->bcast(IonPos);
177  if (primcell_kpoints.size() != NumTwists)
178  primcell_kpoints.resize(NumTwists);
179  bbuffer.add(&primcell_kpoints[0][0], &primcell_kpoints[0][0] + OHMMS_DIM * NumTwists);
180  bibuffer.add(&(TargetPtcl.DensityReducedGvecs[0][0]),
181  &(TargetPtcl.DensityReducedGvecs[0][0]) + numDensityGvecs * OHMMS_DIM);
182  bbuffer.add(&(TargetPtcl.Density_G[0]), &(TargetPtcl.Density_G[0]) + numDensityGvecs);
183  myComm->bcast(bbuffer);
184  myComm->bcast(bibuffer);
185  if (myComm->rank())
186  {
187  bbuffer.rewind();
188  bibuffer.rewind();
189  for (int i = 0; i < numIons; ++i)
190  bibuffer.get(IonTypes[i]);
191  bbuffer.get(&IonPos[0][0], &IonPos[0][0] + OHMMS_DIM * numIons);
192  bbuffer.get(&primcell_kpoints[0][0], &primcell_kpoints[0][0] + OHMMS_DIM * NumTwists);
193  bibuffer.get(&(TargetPtcl.DensityReducedGvecs[0][0]),
194  &(TargetPtcl.DensityReducedGvecs[0][0]) + numDensityGvecs * OHMMS_DIM);
195  bbuffer.get(&(TargetPtcl.Density_G[0]), &(TargetPtcl.Density_G[0]) + numDensityGvecs);
196  }
197  //buffer to bcast hybrid representation atomic orbital info
198  PooledData<double> cbuffer;
199  PooledData<int> cibuffer;
200  myComm->bcast(cbuffer);
201  myComm->bcast(cibuffer);
202  AtomicCentersInfo.resize(numIons);
203  Super2Prim.resize(SourcePtcl->R.size());
206  cbuffer.add(AtomicCentersInfo.cutoff.begin(), AtomicCentersInfo.cutoff.end());
208  cibuffer.add(Super2Prim.begin(), Super2Prim.end());
209  cibuffer.add(AtomicCentersInfo.lmax.begin(), AtomicCentersInfo.lmax.end());
210  cibuffer.add(AtomicCentersInfo.GroupID.begin(), AtomicCentersInfo.GroupID.end());
212  myComm->bcast(cbuffer);
213  myComm->bcast(cibuffer);
214  if (myComm->rank())
215  {
216  cbuffer.rewind();
217  cibuffer.rewind();
220  cbuffer.get(AtomicCentersInfo.cutoff.begin(), AtomicCentersInfo.cutoff.end());
222  cibuffer.get(Super2Prim.begin(), Super2Prim.end());
223  cibuffer.get(AtomicCentersInfo.lmax.begin(), AtomicCentersInfo.lmax.end());
224  cibuffer.get(AtomicCentersInfo.GroupID.begin(), AtomicCentersInfo.GroupID.end());
226  for (int i = 0; i < numIons; i++)
228  }
229 }
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
ParticleSet & TargetPtcl
quantum particle set
std::vector< TinyVector< double, OHMMS_DIM > > ion_pos
struct qmcplusplus::EinsplineSetBuilder::CenterInfo AtomicCentersInfo
ParticleSet * SourcePtcl
ionic system
void rewind(size_type cur=0)
set the Current to a cursor
Definition: PooledData.h:56
int size() const
return the number of tasks
Definition: Communicate.h:118
#define OHMMS_DIM
Definition: config.h:64
bool HaveOrbDerivs
This is true if we have the orbital derivatives w.r.t. the ion positions.
Vector< TinyVector< double, OHMMS_DIM > > IonPos
size_type size() const
return the current size
Definition: OhmmsVector.h:162
void add(T &x)
Definition: PooledData.h:88
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
std::vector< ComplexType > Density_G
Definition: ParticleSet.h:98
void get(T &x)
Definition: PooledData.h:131
ParticlePos R
Position.
Definition: ParticleSet.h:79
Tensor< double, OHMMS_DIM > LatticeInv
Tensor< double, OHMMS_DIM > SuperLattice
std::vector< TinyVector< double, OHMMS_DIM > > primcell_kpoints
void bcast(T &)
Type_t * begin()
Definition: Tensor.h:269
Tensor< double, OHMMS_DIM > RecipLattice
std::vector< TinyVector< int, OHMMS_DIM > > DensityReducedGvecs
Particle density in G-space for MPC interaction.
Definition: ParticleSet.h:97
Tensor< double, OHMMS_DIM > Lattice
Type_t * end()
Definition: Tensor.h:271

◆ CheckLattice()

bool CheckLattice ( )

Definition at line 89 of file EinsplineSetBuilderCommon.cpp.

References qmcplusplus::abs(), qmcplusplus::app_error(), ParticleSet::getLattice(), EinsplineSetBuilder::MatchingTol, OHMMS_DIM, EinsplineSetBuilder::SuperLattice, and EinsplineSetBuilder::TargetPtcl.

Referenced by EinsplineSetBuilder::ReadOrbitalInfo_ESHDF(), and qmcplusplus::TEST_CASE().

90 {
91  double diff = 0.0;
92  for (int i = 0; i < OHMMS_DIM; i++)
93  for (int j = 0; j < OHMMS_DIM; j++)
94  {
95  double max_abs =
96  std::max(std::abs(SuperLattice(i, j)), static_cast<double>(std::abs(TargetPtcl.getLattice().R(i, j))));
97  if (max_abs > MatchingTol)
98  diff = std::max(diff, std::abs(SuperLattice(i, j) - TargetPtcl.getLattice().R(i, j)) / max_abs);
99  }
100 
101  if (diff > MatchingTol)
102  {
103  std::ostringstream o;
104  o.setf(std::ios::scientific, std::ios::floatfield);
105  o.precision(6);
106  o << "EinsplineSetBuilder::ReadOrbitalInfo_ESHDF \n" << "Mismatched supercell lattices.\n";
107  o << " Lattice in ESHDF5 " << std::endl;
108  o << SuperLattice << std::endl;
109  o << " Lattice in xml" << std::endl;
110  o << TargetPtcl.getLattice().R << std::endl;
111  o << " Difference " << std::endl;
112  o << SuperLattice - TargetPtcl.getLattice().R << std::endl;
113  o << " Max relative error = " << diff << std::endl;
114  o << " Tolerance = " << MatchingTol << std::endl;
115  app_error() << o.str();
116  return false;
117  }
118  return true;
119 }
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
ParticleSet & TargetPtcl
quantum particle set
std::ostream & app_error()
Definition: OutputManager.h:67
#define OHMMS_DIM
Definition: config.h:64
Tensor< double, OHMMS_DIM > SuperLattice
const auto & getLattice() const
Definition: ParticleSet.h:251

◆ createSPOSet()

std::unique_ptr< SPOSet > createSPOSet ( xmlNodePtr  cur,
SPOSetInputInfo input_info 
)
overridevirtual

initialize with the existing SPOSet

Reimplemented from SPOSetBuilder.

Definition at line 280 of file EinsplineSetBuilder_createSPOs.cpp.

References OhmmsAttributeSet::add(), Communicate::barrier_and_abort(), EinsplineSetBuilder::H5FileName, SPOSetInputInfo::max_index(), EinsplineSetBuilder::MixedSplineReader, MPIObjectBase::myComm, OhmmsAttributeSet::put(), and EinsplineSetBuilder::SPOSetMap.

281 {
282  if (MixedSplineReader == 0)
283  myComm->barrier_and_abort("EinsplineSetExtended<T> cannot create a SPOSet");
284 
285  std::string aname;
286  int spinSet(0);
288  a.add(spinSet, "spindataset");
289  a.add(spinSet, "group");
290  a.put(cur);
291 
292  //allow only non-overlapping index sets and use the max index as the identifier
293  int norb = input_info.max_index();
294  H5OrbSet aset(H5FileName, spinSet, norb);
295 
296  auto bspline_zd = MixedSplineReader->create_spline_set(spinSet, cur, input_info);
297  if (bspline_zd)
298  SPOSetMap[aset] = bspline_zd.get();
299  return bspline_zd;
300 }
std::map< H5OrbSet, SPOSet *, H5OrbSet > SPOSetMap
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::unique_ptr< BsplineReader > MixedSplineReader
reader to use BsplineReader
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

◆ createSPOSetFromXML()

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

initialize the Antisymmetric wave function for electrons

Parameters
curthe current xml node

Implements SPOSetBuilder.

Reimplemented in EinsplineSpinorSetBuilder.

Definition at line 106 of file EinsplineSetBuilder_createSPOs.cpp.

References OhmmsAttributeSet::add(), qmcplusplus::app_log(), qmcplusplus::app_warning(), Communicate::barrier_and_abort(), EinsplineSetBuilder::bcastSortBands(), PlatformSelector< KIND >::candidate_values(), qmcplusplus::createBsplineComplex(), qmcplusplus::createBsplineReal(), qmcplusplus::createGlobalTimer(), DELETED, Timer::elapsed(), EinsplineSetBuilder::FullBands, ParticleSet::get(), EinsplineSetBuilder::H5FileName, EinsplineSetBuilder::MeshFactor, EinsplineSetBuilder::MixedSplineReader, MPIObjectBase::myComm, MPIObjectBase::myName, EinsplineSetBuilder::NumDistinctOrbitals, EinsplineSetBuilder::Occ, EinsplineSetBuilder::occ_format, EinsplineSetBuilder::OccupyBands(), EinsplineSetBuilder::particle_hole_pairs, EinsplineSetBuilder::ParticleSets, OhmmsAttributeSet::put(), putContent(), Communicate::rank(), Timer::restart(), EinsplineSetBuilder::set_metadata(), EinsplineSetBuilder::SourcePtcl, EinsplineSetBuilder::SPOSetMap, EinsplineSetBuilder::TileIons(), EinsplineSetBuilder::TileMatrix, qmcplusplus::timer_level_medium, EinsplineSetBuilder::TWIST_NO_INPUT, EinsplineSetBuilder::TWISTNUM_NO_INPUT, EinsplineSetBuilder::use_real_splines_, and EinsplineSetBuilder::XMLRoot.

Referenced by qmcplusplus::TEST_CASE(), and qmcplusplus::testTrialWaveFunction_diamondC_2x1x1().

107 {
108  //use 2 bohr as the default when truncated orbitals are used based on the extend of the ions
109  int numOrbs = 0;
110  int sortBands(1);
111  int spinSet = 0;
112  bool skipChecks = false;
113  int twist_num_inp = TWISTNUM_NO_INPUT;
115 
116  std::string sourceName;
117  std::string spo_prec("double");
118  std::string truncate("no");
119  std::string hybrid_rep("no");
120  std::string skip_checks("no");
121  std::string use_einspline_set_extended(
122  "no"); // use old spline library for high-order derivatives, e.g. needed for backflow optimization
123  std::string useGPU;
124  std::string GPUsharing = "no";
125 
126  ScopedTimer spo_timer_scope(createGlobalTimer("einspline::CreateSPOSetFromXML", timer_level_medium));
127 
128  {
129  TinyVector<int, OHMMS_DIM> TileFactor_do_not_use;
131  a.add(H5FileName, "href");
132  a.add(TileFactor_do_not_use, "tile", {}, TagStatus::DELETED);
133  a.add(sortBands, "sort");
134  a.add(TileMatrix, "tilematrix");
135  a.add(twist_num_inp, "twistnum");
136  a.add(twist_inp, "twist");
137  a.add(sourceName, "source");
138  a.add(MeshFactor, "meshfactor");
139  a.add(hybrid_rep, "hybridrep");
141  a.add(GPUsharing, "gpusharing"); // split spline across GPUs visible per rank
142  a.add(spo_prec, "precision");
143  a.add(truncate, "truncate");
144  a.add(myName, "tag");
145  a.add(skip_checks, "skip_checks");
146 
147  a.put(XMLRoot);
148  a.add(numOrbs, "size");
149  a.add(numOrbs, "norbs");
150  a.add(spinSet, "spindataset");
151  a.add(spinSet, "group");
152  a.put(cur);
153 
154  if (myName.empty())
155  myName = "einspline";
156  }
157 
158  if (skip_checks == "yes")
159  skipChecks = true;
160 
161  auto pit(ParticleSets.find(sourceName));
162  if (pit == ParticleSets.end())
163  myComm->barrier_and_abort("Einspline needs the source particleset");
164  else
165  SourcePtcl = pit->second.get();
166 
167  ///////////////////////////////////////////////
168  // Read occupation information from XML file //
169  ///////////////////////////////////////////////
170  const std::vector<int> last_occ(Occ);
171  Occ.resize(0, 0); // correspond to ground
172  bool NewOcc(false);
173 
174  {
175  OhmmsAttributeSet oAttrib;
176  oAttrib.add(spinSet, "spindataset");
177  oAttrib.put(cur);
178  }
179 
180  xmlNodePtr spo_cur = cur;
181  cur = cur->children;
182  while (cur != NULL)
183  {
184  std::string cname((const char*)(cur->name));
185  if (cname == "occupation")
186  {
187  std::string occ_mode("ground");
188  occ_format = "energy";
190  OhmmsAttributeSet oAttrib;
191  oAttrib.add(occ_mode, "mode");
192  oAttrib.add(spinSet, "spindataset");
193  oAttrib.add(occ_format, "format");
194  oAttrib.add(particle_hole_pairs, "pairs");
195  oAttrib.put(cur);
196  if (occ_mode == "excited")
197  putContent(Occ, cur);
198  else if (occ_mode != "ground")
199  myComm->barrier_and_abort("EinsplineSetBuilder::createSPOSet Only ground state occupation "
200  "currently supported in EinsplineSetBuilder.");
201  }
202  cur = cur->next;
203  }
204  if (Occ != last_occ)
205  {
206  NewOcc = true;
207  }
208  else
209  NewOcc = false;
210 #if defined(MIXED_PRECISION)
211  app_log() << "\t MIXED_PRECISION=1 Overwriting the einspline storage to single precision.\n";
212  spo_prec = "single"; //overwrite
213 #endif
214  H5OrbSet aset(H5FileName, spinSet, numOrbs);
215  const auto iter = SPOSetMap.find(aset);
216  if ((iter != SPOSetMap.end()) && (!NewOcc))
217  app_warning() << "!!!!!!! Identical SPOSets are detected by EinsplineSetBuilder! "
218  "Implicit sharing one SPOSet for spin-up and spin-down electrons has been removed. "
219  "Each determinant creates its own SPOSet with dedicated memory for spline coefficients. "
220  "To avoid increasing the memory footprint of spline coefficients, "
221  "create a single SPOset outside the determinantset using 'sposet_collection' "
222  "and reference it by name on the determinant line."
223  << std::endl;
224 
225  if (FullBands[spinSet] == 0)
226  FullBands[spinSet] = std::make_unique<std::vector<BandInfo>>();
227 
228  // Ensure the first SPO set must be spinSet==0
229  // to correctly initialize key data of EinsplineSetBuilder
230  if (SPOSetMap.size() == 0 && spinSet != 0)
231  myComm->barrier_and_abort("The first SPO set must have spindataset=\"0\"");
232 
233  // set the internal parameters
234  if (spinSet == 0)
235  set_metadata(numOrbs, twist_num_inp, twist_inp, skipChecks);
236 
237  //////////////////////////////////
238  // Create the OrbitalSet object
239  //////////////////////////////////
240  Timer mytimer;
241  mytimer.restart();
242  OccupyBands(spinSet, sortBands, numOrbs, skipChecks);
243  if (spinSet == 0)
244  TileIons();
245 
246  bool use_single = (spo_prec == "single" || spo_prec == "float");
247 
248  // safeguard for a removed feature
249  if (truncate == "yes")
251  "The 'truncate' feature of spline SPO has been removed. Please use hybrid orbital representation.");
252 
253 #if !defined(QMC_COMPLEX)
254  if (use_real_splines_)
255  {
256  //if(TargetPtcl.Lattice.SuperCellEnum != SUPERCELL_BULK && truncate=="yes")
257  if (MixedSplineReader == 0)
258  MixedSplineReader = createBsplineReal(this, use_single, hybrid_rep == "yes", useGPU);
259  }
260  else
261 #endif
262  {
263  if (MixedSplineReader == 0)
264  MixedSplineReader = createBsplineComplex(this, use_single, hybrid_rep == "yes", useGPU);
265  }
266 
267  MixedSplineReader->setCommon(XMLRoot);
268  // temporary disable the following function call, Ye Luo
269  // RotateBands_ESHDF(spinSet, dynamic_cast<EinsplineSetExtended<std::complex<double> >*>(OrbitalSet));
270  bcastSortBands(spinSet, NumDistinctOrbitals, myComm->rank() == 0);
271  auto OrbitalSet = MixedSplineReader->create_spline_set(spinSet, spo_cur);
272  if (!OrbitalSet)
273  myComm->barrier_and_abort("Failed to create SPOSet*");
274  app_log() << "Time spent in creating B-spline SPOs " << mytimer.elapsed() << " sec" << std::endl;
275  OrbitalSet->finalizeConstruction();
276  SPOSetMap[aset] = OrbitalSet.get();
277  return OrbitalSet;
278 }
const PSetMap & ParticleSets
reference to the particleset pool
Tensor< int, OHMMS_DIM > TileMatrix
std::ostream & app_warning()
Definition: OutputManager.h:69
int rank() const
return the rank
Definition: Communicate.h:116
std::map< H5OrbSet, SPOSet *, H5OrbSet > SPOSetMap
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::string myName
name of the object
Definition: MPIObjectBase.h:67
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
ParticleSet * SourcePtcl
ionic system
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
Helper vector for sorting bands.
static constexpr double TWIST_NO_INPUT
twist_inp[i] <= -9999 to indicate no given input after parsing XML
void bcastSortBands(int splin, int N, bool root)
broadcast SortBands
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
std::unique_ptr< BsplineReader > createBsplineReal(EinsplineSetBuilder *e, bool use_single, bool hybrid_rep, const std::string &useGPU)
create a reader which handles real splines, R2R case spline storage and computation precision is doub...
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
std::unique_ptr< BsplineReader > createBsplineComplex(EinsplineSetBuilder *e, bool hybrid_rep, const std::string &useGPU)
create a reader which handles complex (double size real) splines, C2R or C2C case spline storage and ...
void OccupyBands(int spin, int sortBands, int numOrbs, bool skipChecks=false)
std::unique_ptr< BsplineReader > MixedSplineReader
reader to use BsplineReader
static constexpr int TWISTNUM_NO_INPUT
twistnum_inp == -9999 to indicate no given input after parsing XML
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 set_metadata(int numOrbs, int twist_num_inp, const TinyVector< double, OHMMS_DIM > &twist_inp, bool skipChecks=false)
a specific but clean code path in createSPOSetFromXML, for PBC, double, ESHDF
xmlNodePtr XMLRoot
root XML node with href, sort, tilematrix, twistnum, source, precision,truncate,version ...
void barrier_and_abort(const std::string &msg) const
bool get(std::ostream &os) const override
dummy. For satisfying OhmmsElementBase.
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
bool use_real_splines_
if false, splines are conceptually complex valued
const std::vector< std::string > candidate_values

◆ OccupyBands()

void OccupyBands ( int  spin,
int  sortBands,
int  numOrbs,
bool  skipChecks = false 
)

Definition at line 617 of file EinsplineSetBuilderCommon.cpp.

References qmcplusplus::app_error(), qmcplusplus::app_log(), BandInfo::BandIndex, EinsplineSetBuilder::DistinctTwists, EinsplineSetBuilder::eigenstatesGroup, BandInfo::Energy, EinsplineSetBuilder::ESHDF, EinsplineSetBuilder::Format, EinsplineSetBuilder::FullBands, EinsplineSetBuilder::H5File, BandInfo::MakeTwoCopies, EinsplineSetBuilder::MakeTwoCopies, MPIObjectBase::myComm, EinsplineSetBuilder::NumBands, EinsplineSetBuilder::NumDistinctOrbitals, EinsplineSetBuilder::NumSpins, EinsplineSetBuilder::NumTwists, EinsplineSetBuilder::OccupyBands_ESHDF(), Communicate::rank(), hdf_archive::read(), BandInfo::Spin, BandInfo::TwistIndex, and EinsplineSetBuilder::Version.

Referenced by EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

618 {
619  if (myComm->rank() != 0)
620  return;
621  if (spin >= NumSpins && !skipChecks)
622  {
623  app_error() << "To developer: User is requesting for orbitals in an invalid spin group " << spin
624  << ". Current h5 file only contains spin groups " << "[0.." << NumSpins - 1 << "]." << std::endl;
625  app_error() << "To user: Orbital H5 file contains no spin down data and is appropriate only for spin unpolarized "
626  "calculations. "
627  << "If this is your intent, please replace 'spindataset=1' with 'spindataset=0' in the input file."
628  << std::endl;
629  abort();
630  }
631  if (Format == ESHDF)
632  {
633  OccupyBands_ESHDF(spin, sortBands, numOrbs);
634  return;
635  }
636  std::string eigenstatesGroup;
637  if (Version[0] == 0 && Version[1] == 11)
638  eigenstatesGroup = "/eigenstates_3";
639  else if (Version[0] == 0 && Version[1] == 20)
640  eigenstatesGroup = "/eigenstates";
641 
642  if (FullBands[spin]->size())
643  {
644  app_log() << " FullBand[" << spin << "] exists. Reuse it. " << std::endl;
645  return;
646  }
647 
648  std::vector<BandInfo>& SortBands(*FullBands[spin]);
649 
650  SortBands.clear();
651  for (int ti = 0; ti < DistinctTwists.size(); ti++)
652  {
653  int tindex = DistinctTwists[ti];
654  // First, read valence states
655  for (int bi = 0; bi < NumBands; bi++)
656  {
657  BandInfo band;
658  band.TwistIndex = tindex;
659  band.BandIndex = bi;
660  band.MakeTwoCopies = MakeTwoCopies[ti];
661  // Read eigenenergy from file
662  std::ostringstream ePath, sPath;
663  if ((Version[0] == 0 && Version[1] == 11) || NumTwists > 1)
664  {
665  ePath << eigenstatesGroup << "/twist_" << tindex << "/band_" << bi << "/eigenvalue";
666  sPath << eigenstatesGroup << "/twist_" << tindex << "/band_" << bi << "/spin";
667  }
668  else if (NumBands > 1)
669  {
670  ePath << eigenstatesGroup << "/twist/band_" << bi << "/eigenvalue";
671  sPath << eigenstatesGroup << "/twist/band_" << bi << "/spin";
672  }
673  else
674  {
675  ePath << eigenstatesGroup << "/twist/band/eigenvalue";
676  sPath << eigenstatesGroup << "/twist/band/spin";
677  }
678  band.Energy = -1.01e100;
679  H5File.read(band.Energy, ePath.str());
680  if (band.Energy > -1.0e100)
681  {
682  H5File.read(band.Spin, sPath.str());
683  if (band.Spin == spin)
684  SortBands.push_back(band);
685  }
686  }
687  }
688  int orbIndex = 0;
689  int numOrbs_counter = 0;
690  while (numOrbs_counter < numOrbs)
691  {
692  if (SortBands[orbIndex].MakeTwoCopies)
693  numOrbs_counter += 2;
694  else
695  numOrbs_counter++;
696  orbIndex++;
697  }
698  NumDistinctOrbitals = orbIndex;
699  app_log() << "We will read " << NumDistinctOrbitals << " distinct orbitals.\n";
700 }
int rank() const
return the rank
Definition: Communicate.h:116
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_error()
Definition: OutputManager.h:67
void OccupyBands_ESHDF(int spin, int sortBands, int numOrbs)
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
Helper vector for sorting bands.
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
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

◆ OccupyBands_ESHDF()

void OccupyBands_ESHDF ( int  spin,
int  sortBands,
int  numOrbs 
)

Definition at line 491 of file EinsplineSetBuilderESHDF.fft.cpp.

References APP_ABORT, qmcplusplus::app_log(), BandInfo::BandIndex, Communicate::barrier_and_abort(), EinsplineSetBuilder::DistinctTwists, BandInfo::Energy, EinsplineSetBuilder::FullBands, EinsplineSetBuilder::H5File, BandInfo::MakeTwoCopies, EinsplineSetBuilder::MakeTwoCopies, MPIObjectBase::myComm, EinsplineSetBuilder::NumBands, EinsplineSetBuilder::NumDistinctOrbitals, EinsplineSetBuilder::Occ, EinsplineSetBuilder::occ_format, EinsplineSetBuilder::particle_hole_pairs, Communicate::rank(), hdf_archive::read(), qmcplusplus::sortByIndex(), and BandInfo::TwistIndex.

Referenced by EinsplineSetBuilder::OccupyBands().

492 {
493  if (myComm->rank() != 0)
494  return;
495 
496  std::vector<BandInfo>& SortBands(*FullBands[spin]);
497  SortBands.clear(); //??? can exit if SortBands is already made?
498  int maxOrbs(0);
499  for (int ti = 0; ti < DistinctTwists.size(); ti++)
500  {
501  int tindex = DistinctTwists[ti];
502  // First, read valence states
503  std::ostringstream ePath;
504  ePath << "/electrons/kpoint_" << tindex << "/spin_" << spin << "/eigenvalues";
505  std::vector<double> eigvals;
506  H5File.read(eigvals, ePath.str());
507  for (int bi = 0; bi < NumBands; bi++)
508  {
509  BandInfo band;
510  band.TwistIndex = tindex;
511  band.BandIndex = bi;
512  band.MakeTwoCopies = MakeTwoCopies[ti];
513  band.Energy = eigvals[bi];
514  if (band.Energy > -1.0e100)
515  SortBands.push_back(band);
516  if (MakeTwoCopies[ti])
517  maxOrbs += 2;
518  else
519  maxOrbs++;
520  }
521  }
522 
523  app_log() << SortBands.size() << " complex-valued orbitals supplied by h5 can be expanded up to " << maxOrbs
524  << " SPOs." << std::endl;
525  if (maxOrbs < numOrbs)
526  myComm->barrier_and_abort("EinsplineSetBuilder::OccupyBands_ESHDF user input requests "
527  "more orbitals than what the h5 file supplies.");
528 
529  // Now sort the bands by energy
530  if (sortBands == 2)
531  {
532  app_log() << "Sorting the bands by index now:\n";
533  sort(SortBands.begin(), SortBands.end(), sortByIndex);
534  }
535  else if (sortBands == 1)
536  {
537  app_log() << "Sorting the bands now:\n";
538  sort(SortBands.begin(), SortBands.end());
539  }
540 
541  std::vector<int> gsOcc(maxOrbs);
542  int N_gs_orbs = numOrbs;
543  int nocced(0);
544  for (int ti = 0; ti < SortBands.size(); ti++)
545  {
546  if (nocced < N_gs_orbs)
547  {
548  if (SortBands[ti].MakeTwoCopies && (N_gs_orbs - nocced > 1))
549  {
550  nocced += 2;
551  gsOcc[ti] = 2;
552  }
553  else if ((SortBands[ti].MakeTwoCopies && (N_gs_orbs - nocced == 1)) || !SortBands[ti].MakeTwoCopies)
554  {
555  nocced += 1;
556  gsOcc[ti] = 1;
557  }
558  }
559  }
560  if (occ_format == "energy")
561  {
562  app_log() << " Occupying bands based on energy in mode " << (Occ.size() > 0 ? "\"excited\"" : "\"ground\"")
563  << std::endl;
564  // To get the occupations right.
565  std::vector<int> Removed(0, 0);
566  std::vector<int> Added(0, 0);
567  for (int ien = 0; ien < Occ.size(); ien++)
568  {
569  if (Occ[ien] < 0)
570  Removed.push_back(-Occ[ien]);
571  else if (Occ[ien] > 0)
572  Added.push_back(Occ[ien]);
573  }
574  if (Added.size() - Removed.size() != 0)
575  {
576  app_log() << "need to add and remove same number of orbitals. " << Added.size() << " " << Removed.size()
577  << std::endl;
578  APP_ABORT("ChangedOccupations");
579  }
580  std::vector<int> DiffOcc(maxOrbs, 0);
581  //Probably a cleaner way to do this.
582  for (int i = 0; i < Removed.size(); i++)
583  DiffOcc[Removed[i] - 1] -= 1;
584  for (int i = 0; i < Added.size(); i++)
585  DiffOcc[Added[i] - 1] += 1;
586  std::vector<int> SumOrb(SortBands.size(), 0);
587  int doi(0);
588  for (int i = 0; i < SumOrb.size(); i++)
589  {
590  if (SortBands[i].MakeTwoCopies)
591  {
592  SumOrb[i] = gsOcc[i] + DiffOcc[doi++];
593  SumOrb[i] += DiffOcc[doi++];
594  }
595  else
596  SumOrb[i] = gsOcc[i] + DiffOcc[doi++];
597  }
598  std::vector<BandInfo> ReOrderedBands;
599  std::vector<BandInfo> RejectedBands;
600  for (int i = 0; i < SumOrb.size(); i++)
601  {
602  if (SumOrb[i] == 2)
603  {
604  SortBands[i].MakeTwoCopies = true;
605  ReOrderedBands.push_back(SortBands[i]);
606  }
607  else if (SumOrb[i] == 1)
608  {
609  SortBands[i].MakeTwoCopies = false;
610  ReOrderedBands.push_back(SortBands[i]);
611  }
612  else if (SumOrb[i] == 0)
613  {
614  SortBands[i].MakeTwoCopies = false;
615  RejectedBands.push_back(SortBands[i]);
616  }
617  else
618  {
619  app_log() << " Trying to add the same orbital (" << i << ") less than zero or more than 2 times." << std::endl;
620  APP_ABORT("Sorting Excitation");
621  }
622  }
623  ReOrderedBands.insert(ReOrderedBands.end(), RejectedBands.begin(), RejectedBands.end());
624  SortBands = ReOrderedBands;
625  }
626  else if (occ_format == "band")
627  {
628  app_log() << " Occupying bands based on (ti,bi) data." << std::endl;
629  if (Occ.size() != particle_hole_pairs * 4)
630  {
631  app_log() << " Need Occ = pairs*4. Occ is (ti,bi) of removed, then added." << std::endl;
632  app_log() << Occ.size() << " " << particle_hole_pairs << std::endl;
633  APP_ABORT("ChangedOccupations");
634  }
635  int cnt(0);
636  for (int ien = 0; ien < SortBands.size(); ien++)
637  {
638  if ((Occ[cnt] == SortBands[ien].TwistIndex) && (Occ[cnt + 1] == SortBands[ien].BandIndex))
639  {
640  if (cnt < particle_hole_pairs * 2)
641  {
642  gsOcc[ien] -= 1;
643  cnt += 2;
644  app_log() << "removing orbital " << ien << std::endl;
645  }
646  else
647  {
648  gsOcc[ien] += 1;
649  app_log() << "adding orbital " << ien << std::endl;
650  cnt += 2;
651  }
652  }
653  }
654  std::vector<BandInfo> ReOrderedBands;
655  std::vector<BandInfo> RejectedBands;
656  for (int i = 0; i < SortBands.size(); i++)
657  {
658  if (gsOcc[i] == 2)
659  {
660  SortBands[i].MakeTwoCopies = true;
661  ReOrderedBands.push_back(SortBands[i]);
662  }
663  else if (gsOcc[i] == 1)
664  {
665  SortBands[i].MakeTwoCopies = false;
666  ReOrderedBands.push_back(SortBands[i]);
667  }
668  else if (gsOcc[i] == 0)
669  {
670  SortBands[i].MakeTwoCopies = false;
671  RejectedBands.push_back(SortBands[i]);
672  }
673  else
674  {
675  app_log() << " Trying to add the same orbital (" << i << ") less than zero or more than 2 times." << std::endl;
676  APP_ABORT("Sorting Excitation");
677  }
678  }
679  ReOrderedBands.insert(ReOrderedBands.end(), RejectedBands.begin(), RejectedBands.end());
680  SortBands = ReOrderedBands;
681  }
682  //for(int sw=0;sw<Removed.size();sw++){
683  // app_log()<<" Swapping two orbitals "<<Removed[sw]<<" and "<<Added[sw]<< std::endl;
684  // BandInfo tempband(SortBands[Removed[sw]-1]);
685  // SortBands[Removed[sw]-1] = SortBands[Added[sw]-1];
686  // SortBands[Added[sw]-1] = tempband;
687  //}
688  int orbIndex = 0;
689  int numOrbs_counter = 0;
690  while (numOrbs_counter < numOrbs)
691  {
692  if (SortBands[orbIndex].MakeTwoCopies)
693  numOrbs_counter += 2;
694  else
695  numOrbs_counter++;
696  orbIndex++;
697  }
698  NumDistinctOrbitals = orbIndex;
699  app_log() << "We will read " << NumDistinctOrbitals << " distinct complex-valued orbitals from h5.\n";
700 }
int rank() const
return the rank
Definition: Communicate.h:116
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
Helper vector for sorting bands.
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
bool sortByIndex(BandInfo leftB, BandInfo rightB)
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
void barrier_and_abort(const std::string &msg) const

◆ OrbitalPath()

std::string OrbitalPath ( int  ti,
int  bi 
)

◆ ReadGvectors_ESHDF()

bool ReadGvectors_ESHDF ( )

read gvectors for each twist

Returns
true, if psi_g is found

Definition at line 369 of file EinsplineSetBuilderESHDF.fft.cpp.

References qmcplusplus::abs(), APP_ABORT, qmcplusplus::app_log(), Communicate::bcast(), qmcplusplus::ceil(), EinsplineSetBuilder::DistinctTwists, EinsplineSetBuilder::Gvecs, EinsplineSetBuilder::H5File, qmcplusplus::lower_bound(), EinsplineSetBuilder::MaxNumGvecs, EinsplineSetBuilder::MeshFactor, EinsplineSetBuilder::MeshSize, MPIObjectBase::myComm, EinsplineSetBuilder::NumTwists, Communicate::rank(), hdf_archive::read(), hdf_archive::readEntry(), and EinsplineSetBuilder::Version.

Referenced by BsplineReader::set_grid().

370 {
371  bool root = myComm->rank() == 0;
372  //this is always ugly
373  MeshSize = 0;
374  int hasPsig = 1;
375  if (root)
376  {
377  H5File.readEntry(MeshSize, "/electrons/psi_r_mesh");
378  H5File.readEntry(MeshSize, "/electrons/mesh");
379  }
381  hasPsig = (MeshSize[0] == 0);
382  if (hasPsig)
383  {
384  int nallowed = 257;
385  int allowed[] = {72, 75, 80, 81, 90, 96, 100, 108, 120, 125, 128, 135, 144, 150,
386  160, 162, 180, 192, 200, 216, 225, 240, 243, 250, 256, 270, 288, 300,
387  320, 324, 360, 375, 384, 400, 405, 432, 450, 480, 486, 500, 512, 540,
388  576, 600, 625, 640, 648, 675, 720, 729, 750, 768, 800, 810, 864, 900,
389  960, 972, 1000, 1024, 1080, 1125, 1152, 1200, 1215, 1250, 1280, 1296, 1350, 1440,
390  1458, 1500, 1536, 1600, 1620, 1728, 1800, 1875, 1920, 1944, 2000, 2025, 2048, 2160,
391  2187, 2250, 2304, 2400, 2430, 2500, 2560, 2592, 2700, 2880, 2916, 3000, 3072, 3125,
392  3200, 3240, 3375, 3456, 3600, 3645, 3750, 3840, 3888, 4000, 4050, 4096, 4320, 4374,
393  4500, 4608, 4800, 4860, 5000, 5120, 5184, 5400, 5625, 5760, 5832, 6000, 6075, 6144,
394  6250, 6400, 6480, 6561, 6750, 6912, 7200, 7290, 7500, 7680, 7776, 8000, 8100, 8192,
395  8640, 8748, 9000, 9216, 9375, 9600, 9720, 10000, 10125, 10240, 10368, 10800, 10935, 11250,
396  11520, 11664, 12000, 12150, 12288, 12500, 12800, 12960, 13122, 13500, 13824, 14400, 14580, 15000,
397  15360, 15552, 15625, 16000, 16200, 16384, 16875, 17280, 17496, 18000, 18225, 18432, 18750, 19200,
398  19440, 19683, 20000, 20250, 20480, 20736, 21600, 21870, 22500, 23040, 23328, 24000, 24300, 24576,
399  25000, 25600, 25920, 26244, 27000, 27648, 28125, 28800, 29160, 30000, 30375, 30720, 31104, 31250,
400  32000, 32400, 32768, 32805, 33750, 34560, 34992, 36000, 36450, 36864, 37500, 38400, 38880, 39366,
401  40000, 40500, 40960, 41472, 43200, 43740, 45000, 46080, 46656, 46875, 48000, 48600, 49152, 50000,
402  50625, 51200, 51840, 52488, 54000, 54675, 55296, 56250, 57600, 58320, 59049, 60000, 60750, 61440,
403  62208, 62500, 64000, 64800, 65536};
404  MaxNumGvecs = 0;
405  // std::set<TinyVector<int,3> > Gset;
406  // Read k-points for all G-vectors and take the union
407  TinyVector<int, 3> maxIndex(0, 0, 0);
408  Gvecs.resize(NumTwists);
409  {
410  int numg = 0;
411  if (root)
412  {
413  std::ostringstream Gpath;
414  Gpath << "/electrons/kpoint_0/gvectors";
415  H5File.read(Gvecs[0], Gpath.str());
416  numg = Gvecs[0].size();
417  }
418  myComm->bcast(numg);
419  if (!root)
420  Gvecs[0].resize(numg);
421  myComm->bcast(Gvecs[0]);
422  MaxNumGvecs = Gvecs[0].size();
423  for (int ig = 0; ig < Gvecs[0].size(); ig++)
424  {
425  maxIndex[0] = std::max(maxIndex[0], std::abs(Gvecs[0][ig][0]));
426  maxIndex[1] = std::max(maxIndex[1], std::abs(Gvecs[0][ig][1]));
427  maxIndex[2] = std::max(maxIndex[2], std::abs(Gvecs[0][ig][2]));
428  }
429  // for (int ig=0; ig<Gvecs.size(); ig++)
430  // if (Gset.find(Gvecs[ig]) == Gset.end())
431  // Gset.insert(Gvecs[ig]);
432  } //done with kpoint_0
433  MeshSize[0] = (int)std::ceil(4.0 * MeshFactor * maxIndex[0]);
434  MeshSize[1] = (int)std::ceil(4.0 * MeshFactor * maxIndex[1]);
435  MeshSize[2] = (int)std::ceil(4.0 * MeshFactor * maxIndex[2]);
436  //only use 2^a 3^b 5^c where a>=2 up to 65536
437  int* ix = std::lower_bound(allowed, allowed + nallowed, MeshSize[0]);
438  int* iy = std::lower_bound(allowed, allowed + nallowed, MeshSize[1]);
439  int* iz = std::lower_bound(allowed, allowed + nallowed, MeshSize[2]);
440  MeshSize[0] = (MeshSize[0] > 128) ? *ix : (MeshSize[0] + MeshSize[0] % 2);
441  MeshSize[1] = (MeshSize[1] > 128) ? *iy : (MeshSize[1] + MeshSize[1] % 2);
442  MeshSize[2] = (MeshSize[2] > 128) ? *iz : (MeshSize[2] + MeshSize[2] % 2);
443  if (Version[0] < 2)
444  {
445  //get the map for each twist, but use the MeshSize from kpoint_0
446  app_log() << " ESHDF::Version " << Version << std::endl;
447  app_log() << " Assumes distinct Gvecs set for different twists. Regenerate orbital files using updated QE."
448  << std::endl;
449  for (int k = 0; k < DistinctTwists.size(); ++k)
450  {
451  int ik = DistinctTwists[k];
452  if (ik == 0)
453  continue; //already done
454  int numg = 0;
455  if (root)
456  {
457  std::ostringstream Gpath;
458  Gpath << "/electrons/kpoint_" << ik << "/gvectors";
459  H5File.read(Gvecs[ik], Gpath.str());
460  numg = Gvecs[ik].size();
461  }
462  myComm->bcast(numg);
463  if (numg == 0)
464  {
465  //copy kpoint_0, default
466  Gvecs[ik] = Gvecs[0];
467  }
468  else
469  {
470  if (numg != MaxNumGvecs)
471  {
472  std::ostringstream o;
473  o << "Twist " << ik << ": The number of Gvecs is different from kpoint_0."
474  << " This is not supported anymore. Rerun pw2qmcpack.x or equivalent";
475  APP_ABORT(o.str());
476  }
477  if (!root)
478  Gvecs[ik].resize(numg);
479  myComm->bcast(Gvecs[ik]);
480  }
481  }
482  }
483  }
484  app_log() << "B-spline mesh factor is " << MeshFactor << std::endl;
485  app_log() << "B-spline mesh size is (" << MeshSize[0] << ", " << MeshSize[1] << ", " << MeshSize[2] << ")\n";
486  app_log() << "Maxmimum number of Gvecs " << MaxNumGvecs << std::endl;
487  app_log().flush();
488  return hasPsig;
489 }
int rank() const
return the rank
Definition: Communicate.h:116
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::ostream & app_log()
Definition: OutputManager.h:65
TinyVector< T, 3 > lower_bound(const TinyVector< T, 3 > &a, const TinyVector< T, 3 > &b)
helper function to determine the lower bound of a domain (need to move up)
MakeReturn< UnaryNode< FnCeil, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t ceil(const Vector< T1, C1 > &l)
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
std::vector< std::vector< TinyVector< int, 3 > > > Gvecs
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
void bcast(T &)
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293

◆ ReadOrbitalInfo()

bool ReadOrbitalInfo ( bool  skipChecks = false)

Definition at line 43 of file EinsplineSetBuilderESHDF.fft.cpp.

References qmcplusplus::app_error(), qmcplusplus::app_log(), qmcplusplus::Units::charge::e, EinsplineSetBuilder::ESHDF, EinsplineSetBuilder::Format, EinsplineSetBuilder::H5File, EinsplineSetBuilder::H5FileName, hdf_archive::open(), hdf_archive::read(), EinsplineSetBuilder::ReadOrbitalInfo_ESHDF(), and EinsplineSetBuilder::Version.

Referenced by EinsplineSetBuilder::set_metadata().

44 {
45  if (!H5File.open(H5FileName, H5F_ACC_RDONLY))
46  {
47  app_error() << "Could not open HDF5 file \"" << H5FileName << "\" in EinsplineSetBuilder::ReadOrbitalInfo.\n";
48  return false;
49  }
50 
51  try
52  {
53  // Read format
54  std::string format;
55  H5File.read(format, "/format");
56  if (format.find("ES") == std::string::npos)
57  throw std::runtime_error("Format string input \"" + format + "\" doesn't contain \"ES\" keyword.");
58  Format = ESHDF;
59  H5File.read(Version, "/version");
60  app_log() << " HDF5 orbital file version " << Version[0] << "." << Version[1] << "." << Version[2] << std::endl;
61  }
62  catch (const std::exception& e)
63  {
64  app_error() << e.what() << std::endl
65  << "EinsplineSetBuilder::ReadOrbitalInfo h5 file format is too old or it is not a bspline orbital file!"
66  << std::endl;
67  return false;
68  }
69 
70  return ReadOrbitalInfo_ESHDF(skipChecks);
71 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_error()
Definition: OutputManager.h:67
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
bool ReadOrbitalInfo_ESHDF(bool skipChecks=false)

◆ ReadOrbitalInfo_ESHDF()

bool ReadOrbitalInfo_ESHDF ( bool  skipChecks = false)

Definition at line 73 of file EinsplineSetBuilderESHDF.fft.cpp.

References qmcplusplus::abs(), ParticleSet::addTable(), APP_ABORT, qmcplusplus::app_error(), qmcplusplus::app_log(), EinsplineSetBuilder::AtomicCentersInfo, EinsplineSetBuilder::CheckLattice(), EinsplineSetBuilder::CenterInfo::cutoff, ParticleSet::Density_G, ParticleSet::Density_r, ParticleSet::DensityReducedGvecs, qmcplusplus::det(), qmcplusplus::dot(), qmcplusplus::Units::charge::e, SpeciesSet::findAttribute(), ParticleSet::getDistTable(), ParticleSet::getLattice(), ParticleSet::getSpeciesSet(), ParticleSet::getTotalNum(), ParticleSet::GroupID, EinsplineSetBuilder::CenterInfo::GroupID, EinsplineSetBuilder::H5File, EinsplineSetBuilder::HaveOrbDerivs, EinsplineSetBuilder::CenterInfo::inner_cutoff, qmcplusplus::inverse(), EinsplineSetBuilder::CenterInfo::ion_pos, EinsplineSetBuilder::IonPos, EinsplineSetBuilder::IonTypes, EinsplineSetBuilder::Lattice, EinsplineSetBuilder::LatticeInv, EinsplineSetBuilder::CenterInfo::lmax, EinsplineSetBuilder::MatchingTol, EinsplineSetBuilder::CenterInfo::Ncenters, EinsplineSetBuilder::CenterInfo::non_overlapping_radius, EinsplineSetBuilder::NumBands, EinsplineSetBuilder::NumElectrons, EinsplineSetBuilder::NumSpins, EinsplineSetBuilder::NumTwists, OHMMS_DIM, EinsplineSetBuilder::PrimCell, EinsplineSetBuilder::primcell_kpoints, qmcplusplus::qmc_common, ParticleSet::R, hdf_archive::read(), hdf_archive::readEntry(), EinsplineSetBuilder::RecipLattice, Vector< T, Alloc >::resize(), EinsplineSetBuilder::CenterInfo::resize(), CrystalLattice< T, D >::set(), Array< T, D, ALLOC >::size(), Vector< T, Alloc >::size(), EinsplineSetBuilder::SourcePtcl, EinsplineSetBuilder::CenterInfo::spline_npoints, EinsplineSetBuilder::CenterInfo::spline_radius, EinsplineSetBuilder::Super2Prim, qmcplusplus::SUPERCELL_BULK, EinsplineSetBuilder::SuperLattice, EinsplineSetBuilder::TargetPtcl, EinsplineSetBuilder::TileMatrix, CrystalLattice< T, D >::toUnit_floor(), ParticleSet::update(), QMCState::use_density, EinsplineSetBuilder::Version, ParticleSet::VHXC_G, ParticleSet::VHXC_r, and ParticleSet::VHXCReducedGvecs.

Referenced by EinsplineSetBuilder::ReadOrbitalInfo().

74 {
75  app_log() << " Reading orbital file in ESHDF format.\n";
76  H5File.read(Version, "/version");
77  app_log() << " ESHDF orbital file version " << Version[0] << "." << Version[1] << "." << Version[2] << std::endl;
78  H5File.read(Lattice, "/supercell/primitive_vectors");
79  RecipLattice = 2.0 * M_PI * inverse(Lattice);
81  std::array<char, 1000> buff;
82  int length = std::snprintf(buff.data(), buff.size(),
83  " Lattice = \n [ %9.6f %9.6f %9.6f\n"
84  " %9.6f %9.6f %9.6f\n"
85  " %9.6f %9.6f %9.6f ]\n",
86  Lattice(0, 0), Lattice(0, 1), Lattice(0, 2), Lattice(1, 0), Lattice(1, 1), Lattice(1, 2),
87  Lattice(2, 0), Lattice(2, 1), Lattice(2, 2));
88  if (length < 0)
89  throw std::runtime_error("Error converting lattice to a string");
90  app_log() << std::string_view(buff.data(), length);
91  length =
92  std::snprintf(buff.data(), buff.size(),
93  " SuperLattice = \n [ %9.6f %9.6f %9.6f\n"
94  " %9.6f %9.6f %9.6f\n"
95  " %9.6f %9.6f %9.6f ]\n",
96  SuperLattice(0, 0), SuperLattice(0, 1), SuperLattice(0, 2), SuperLattice(1, 0), SuperLattice(1, 1),
97  SuperLattice(1, 2), SuperLattice(2, 0), SuperLattice(2, 1), SuperLattice(2, 2));
98  if (length < 0)
99  throw std::runtime_error("Error converting SuperLattice to a string");
100  app_log() << std::string_view(buff.data(), length) << std::endl;
101  if (!CheckLattice())
102  throw std::runtime_error("CheckLattice failed");
104  for (int i = 0; i < 3; i++)
105  for (int j = 0; j < 3; j++)
106  LatticeInv(i, j) = RecipLattice(i, j) / (2.0 * M_PI);
107  int have_dpsi = false;
108  NumTwists = NumSpins = NumBands = 0;
110  H5File.read(NumBands, "/electrons/kpoint_0/spin_0/number_of_states");
111  H5File.readEntry(NumSpins, "/electrons/number_of_spins");
112  H5File.read(NumTwists, "/electrons/number_of_kpoints");
113  H5File.readEntry(have_dpsi, "/electrons/have_dpsi");
114  HaveOrbDerivs = have_dpsi;
115  app_log() << "bands=" << NumBands << ", elecs=" << NumElectrons << ", spins=" << NumSpins << ", twists=" << NumTwists
116  << std::endl;
117  //////////////////////////////////
118  // Read ion types and locations //
119  //////////////////////////////////
120  Vector<int> species_ids;
121  H5File.read(species_ids, "/atoms/species_ids");
122  int num_species;
123  H5File.read(num_species, "/atoms/number_of_species");
124  std::vector<int> atomic_numbers(num_species);
125  for (int isp = 0; isp < num_species; isp++)
126  {
127  std::ostringstream name;
128  name << "/atoms/species_" << isp << "/atomic_number";
129  H5File.readEntry(atomic_numbers[isp], name.str());
130  }
131  IonTypes.resize(species_ids.size());
132  for (int i = 0; i < species_ids.size(); i++)
133  IonTypes[i] = atomic_numbers[species_ids[i]];
134  H5File.read(IonPos, "/atoms/positions");
135  for (int i = 0; i < IonTypes.size(); i++)
136  app_log() << "Atom type(" << i << ") = " << IonTypes[i] << std::endl;
137  /////////////////////////////////////
138  // Read atom orbital info from xml //
139  /////////////////////////////////////
140  // construct Super2Prim mapping.
141  if (Super2Prim.size() == 0)
142  {
143  //SourcePtcl->convert2Cart(SourcePtcl->R);
144  Super2Prim.resize(SourcePtcl->R.size(), -1);
145  std::vector<int> prim_atom_counts;
146  prim_atom_counts.resize(IonPos.size(), 0);
147  for (int i = 0; i < SourcePtcl->R.size(); i++)
148  {
150  for (int j = 0; j < IonPos.size(); j++)
151  {
152  PosType dr = PrimCell.toUnit_floor(IonPos[j]) - ref;
153  for (int k = 0; k < OHMMS_DIM; k++)
154  dr[k] -= round(dr[k]);
155  if (dot(dr, dr) < MatchingTol)
156  {
157  if (Super2Prim[i] < 0)
158  {
159  Super2Prim[i] = j;
160  prim_atom_counts[j]++;
161  }
162  else
163  {
164  app_error() << "Supercell ion " << i << " at " << SourcePtcl->R[j]
165  << " was found twice in the primitive cell as ion " << Super2Prim[i] << " and " << j
166  << std::endl;
167  if (!skipChecks)
168  abort();
169  }
170  }
171  }
172  if (Super2Prim[i] < 0)
173  {
174  app_error() << "Supercell ion " << i << " not found in the primitive cell" << std::endl;
175  if (!skipChecks)
176  abort();
177  }
178  else
179  {
180  //app_log() << "Supercell ion " << i << " mapped to primitive cell ion " << Super2Prim[i] << std::endl;
181  }
182  }
183  const int tiling_size = std::abs(det(TileMatrix));
184  for (int i = 0; i < IonPos.size(); i++)
185  if (prim_atom_counts[i] != tiling_size)
186  {
187  app_error() << "Primitive cell ion " << i << " was found only " << prim_atom_counts[i]
188  << " times in the supercell rather than " << tiling_size << std::endl;
189  if (!skipChecks)
190  abort();
191  }
192  // construct AtomicCentersInfo
194  for (int i = 0; i < IonPos.size(); i++)
196  const auto& source_species = SourcePtcl->getSpeciesSet();
197  int Zind = source_species.findAttribute("atomicnumber");
198  const int table_id = SourcePtcl->addTable(*SourcePtcl);
199  const auto& ii_table = SourcePtcl->getDistTable(table_id);
200  SourcePtcl->update(true);
201  for (int i = 0; i < IonPos.size(); i++)
202  {
203  AtomicCentersInfo.non_overlapping_radius[i] = std::numeric_limits<RealType>::max();
204  //should only call get_first_neighbor to set non_overlapping_radius if there are more than one atom in the cell
205  if (Super2Prim.size() == 1)
206  continue;
207  for (int j = 0; j < Super2Prim.size(); j++)
208  if (Super2Prim[j] == i)
209  {
210  // set GroupID for each ion in primitive cell
211  if ((Zind < 0) || (source_species(Zind, SourcePtcl->GroupID[j]) == IonTypes[i]))
213  else
214  {
215  app_error() << "Primitive cell ion " << i << " vs supercell ion " << j
216  << " atomic number not matching: " << IonTypes[i] << " vs "
217  << source_species(Zind, SourcePtcl->GroupID[j]) << std::endl;
218  if (!skipChecks)
219  abort();
220  }
221  // set non_overlapping_radius for each ion in primitive cell
222  RealType r(0);
223  PosType dr;
224  ii_table.get_first_neighbor(j, r, dr, false);
225  if (r < 1e-3)
226  APP_ABORT("EinsplineSetBuilder::ReadOrbitalInfo_ESHDF too close ions <1e-3 bohr!");
228  break;
229  }
230  }
231 
232  // load cutoff_radius, spline_radius, spline_npoints, lmax if exists.
233  const int inner_cutoff_ind = source_species.findAttribute("inner_cutoff");
234  const int cutoff_radius_ind = source_species.findAttribute("cutoff_radius");
235  const int spline_radius_ind = source_species.findAttribute("spline_radius");
236  const int spline_npoints_ind = source_species.findAttribute("spline_npoints");
237  const int lmax_ind = source_species.findAttribute("lmax");
238 
239  for (int center_idx = 0; center_idx < AtomicCentersInfo.Ncenters; center_idx++)
240  {
241  const int my_GroupID = AtomicCentersInfo.GroupID[center_idx];
242  if (inner_cutoff_ind >= 0)
243  AtomicCentersInfo.inner_cutoff[center_idx] = source_species(inner_cutoff_ind, my_GroupID);
244  if (cutoff_radius_ind >= 0)
245  AtomicCentersInfo.cutoff[center_idx] = source_species(cutoff_radius_ind, my_GroupID);
246  if (spline_radius_ind >= 0)
247  AtomicCentersInfo.spline_radius[center_idx] = source_species(spline_radius_ind, my_GroupID);
248  if (spline_npoints_ind >= 0)
249  AtomicCentersInfo.spline_npoints[center_idx] = source_species(spline_npoints_ind, my_GroupID);
250  if (lmax_ind >= 0)
251  AtomicCentersInfo.lmax[center_idx] = source_species(lmax_ind, my_GroupID);
252  }
253  }
254  ///////////////////////////
255  // Read the twist angles //
256  ///////////////////////////
257  primcell_kpoints.resize(NumTwists);
258  for (int ti = 0; ti < NumTwists; ti++)
259  {
260  std::ostringstream path;
261  path << "/electrons/kpoint_" << ti << "/reduced_k";
262  TinyVector<double, OHMMS_DIM> primcell_kpoints_DP;
263  H5File.read(primcell_kpoints_DP, path.str());
264  primcell_kpoints[ti] = primcell_kpoints_DP;
265  }
267  {
268  //////////////////////////////////////////////////////////
269  // Only if it is bulk: If the density has not been set in TargetPtcl, and //
270  // the density is available, read it in and save it //
271  // in TargetPtcl. //
272  //////////////////////////////////////////////////////////
273  if (TargetPtcl.getLattice().SuperCellEnum == SUPERCELL_BULK)
274  {
275  // FIXME: add support for more than one spin density
276  if (TargetPtcl.Density_G.empty())
277  {
278  Array<double, OHMMS_DIM> Density_r_DP;
279  TinyVector<int, 3> mesh;
280  H5File.read(TargetPtcl.DensityReducedGvecs, "/electrons/density/gvectors");
281  int numG = TargetPtcl.DensityReducedGvecs.size();
282 // Convert primitive G-vectors to supercell G-vectors
283 // Also, flip sign since ESHDF format uses opposite sign convention
284 #pragma omp parallel for
285  for (int iG = 0; iG < numG; iG++)
287  app_log() << " Read " << numG << " density G-vectors.\n";
288  for (int ispin = 0; ispin < NumSpins; ispin++)
289  {
290  std::ostringstream density_r_path, density_g_path;
291  density_r_path << "/electrons/density/spin_" << ispin << "/density_r";
292  density_g_path << "/electrons/density/spin_" << ispin << "/density_g";
293  H5File.readEntry(Density_r_DP, density_r_path.str());
294  TargetPtcl.Density_r = Density_r_DP;
295  if (TargetPtcl.DensityReducedGvecs.size())
296  {
297  app_log() << " EinsplineSetBuilder found density in the HDF5 file.\n";
298  std::vector<ComplexType> density_G;
299  std::vector<std::complex<double>> Density_G_DP;
300  H5File.read(Density_G_DP, density_g_path.str());
301  density_G.assign(Density_G_DP.begin(), Density_G_DP.end());
302  if (!density_G.size())
303  {
304  app_error() << " Density reduced G-vectors defined, but not the" << " density.\n";
305  abort();
306  }
307  else
308  {
309  if (ispin == 0)
310  TargetPtcl.Density_G = density_G;
311  else
312  for (int iG = 0; iG < density_G.size(); iG++)
313  TargetPtcl.Density_G[iG] += density_G[iG];
314  }
315  }
316  }
317  }
318  //////////////////////////////////////////////////////////
319  // If the density has not been set in TargetPtcl, and //
320  // the density is available, read it in and save it //
321  // in TargetPtcl. //
322  //////////////////////////////////////////////////////////
323  // FIXME: add support for more than one spin potential
324  if (!TargetPtcl.VHXC_r[0].size())
325  {
326  TinyVector<int, 3> mesh;
327  H5File.readEntry(TargetPtcl.VHXCReducedGvecs, "/electrons/VHXC/gvectors");
328  int numG = TargetPtcl.VHXCReducedGvecs.size();
329 // Convert primitive G-vectors to supercell G-vectors
330 // Also, flip sign since ESHDF format uses opposite sign convention
331 #pragma omp parallel for
332  for (int iG = 0; iG < numG; iG++)
334  app_log() << " Read " << numG << " VHXC G-vectors.\n";
335  for (int ispin = 0; ispin < NumSpins; ispin++)
336  {
337  Array<double, OHMMS_DIM> VHXC_r_DP;
338  std::ostringstream VHXC_r_path, VHXC_g_path;
339  VHXC_r_path << "/electrons/VHXC/spin_" << ispin << "/VHXC_r";
340  VHXC_g_path << "/electrons/VHXC/spin_" << ispin << "/VHXC_g";
341  H5File.readEntry(VHXC_r_DP, VHXC_r_path.str());
342  TargetPtcl.VHXC_r[ispin] = VHXC_r_DP;
343  if (TargetPtcl.VHXCReducedGvecs.size())
344  {
345  app_log() << " EinsplineSetBuilder found VHXC in the HDF5 file.\n";
346  std::vector<std::complex<double>> VHXC_G_DP;
347  std::vector<ComplexType> VHXC_G;
348  H5File.read(VHXC_G_DP, VHXC_g_path.str());
349  VHXC_G.assign(VHXC_G_DP.begin(), VHXC_G_DP.end());
350  if (!VHXC_G.size())
351  {
352  app_error() << " VHXC reduced G-vectors defined, but not the" << " VHXC.\n";
353  abort();
354  }
355  else
356  TargetPtcl.VHXC_G[ispin] = VHXC_G;
357  }
358  }
359  }
360  }
361  }
362  else
363  {
364  app_log() << " Skip initialization of the density" << std::endl;
365  }
366  return true;
367 }
void set(const Tensor< TT, D > &lat)
set the lattice vector from the command-line options
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
Tensor< int, OHMMS_DIM > TileMatrix
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
Definition: TensorOps.h:838
Array< RealType, OHMMS_DIM > Density_r
Definition: ParticleSet.h:99
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
ParticleSet & TargetPtcl
quantum particle set
std::vector< TinyVector< double, OHMMS_DIM > > ion_pos
std::ostream & app_error()
Definition: OutputManager.h:67
struct qmcplusplus::EinsplineSetBuilder::CenterInfo AtomicCentersInfo
ParticleSet * SourcePtcl
ionic system
void update(bool skipSK=false)
update the internal data
#define OHMMS_DIM
Definition: config.h:64
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
QMCTraits::PosType PosType
bool HaveOrbDerivs
This is true if we have the orbital derivatives w.r.t. the ion positions.
Vector< TinyVector< double, OHMMS_DIM > > IonPos
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
std::vector< ComplexType > VHXC_G[2]
Definition: ParticleSet.h:103
size_type size() const
return the current size
Definition: OhmmsVector.h:162
SingleParticlePos toUnit_floor(const TinyVector< T1, D > &r) const
std::vector< ComplexType > Density_G
Definition: ParticleSet.h:98
size_t size() const
Definition: OhmmsArray.h:57
ParticlePos R
Position.
Definition: ParticleSet.h:79
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
auto & getDistTable(int table_ID) const
get a distance table by table_ID
Definition: ParticleSet.h:190
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
QMCTraits::RealType RealType
Tensor< T, D > inverse(const Tensor< T, D > &a)
Definition: TensorOps.h:879
Tensor< double, OHMMS_DIM > LatticeInv
Array< RealType, OHMMS_DIM > VHXC_r[2]
Definition: ParticleSet.h:104
Tensor< double, OHMMS_DIM > SuperLattice
const auto & getLattice() const
Definition: ParticleSet.h:251
std::vector< TinyVector< double, OHMMS_DIM > > primcell_kpoints
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
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
QMCState qmc_common
a unique QMCState during a run
Definition: qmc_common.cpp:111
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25
int findAttribute(const std::string &name) const
almost all code ignores this and just uses addAttribute for the same purpose.
Definition: SpeciesSet.h:128
Tensor< double, OHMMS_DIM > RecipLattice
std::vector< TinyVector< int, OHMMS_DIM > > DensityReducedGvecs
Particle density in G-space for MPC interaction.
Definition: ParticleSet.h:97
std::vector< TinyVector< int, OHMMS_DIM > > VHXCReducedGvecs
DFT potential.
Definition: ParticleSet.h:102
Tensor< double, OHMMS_DIM > Lattice
bool use_density
true, if density is used, e.g. MPC
Definition: qmc_common.h:35

◆ set_metadata()

void set_metadata ( int  numOrbs,
int  twist_num_inp,
const TinyVector< double, OHMMS_DIM > &  twist_inp,
bool  skipChecks = false 
)
protected

a specific but clean code path in createSPOSetFromXML, for PBC, double, ESHDF

Parameters
curthe current xml node

Definition at line 39 of file EinsplineSetBuilder_createSPOs.cpp.

References EinsplineSetBuilder::AnalyzeTwists2(), qmcplusplus::app_log(), Communicate::barrier(), Communicate::barrier_and_abort(), EinsplineSetBuilder::BroadcastOrbitalInfo(), qmcplusplus::dot(), Timer::elapsed(), CrystalLattice< T, D >::G, EinsplineSetBuilder::GGt, MPIObjectBase::myComm, EinsplineSetBuilder::PrimCell, Communicate::rank(), EinsplineSetBuilder::ReadOrbitalInfo(), Timer::restart(), CrystalLattice< T, D >::set(), EinsplineSetBuilder::SuperCell, EinsplineSetBuilder::SuperLattice, EinsplineSetBuilder::TileMatrix, and qmcplusplus::transpose().

Referenced by EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

43 {
44  // 1. set a lot of internal parameters in the EinsplineSetBuilder class
45  // e.g. TileMatrix, use_real_splines_, DistinctTwists, MakeTwoCopies.
46  // 2. this is also where metadata for the orbitals are read from the wavefunction hdf5 file
47  // and broadcast to MPI groups. Variables broadcasted are listed in
48  // EinsplineSetBuilderCommon.cpp EinsplineSetBuilder::BroadcastOrbitalInfo()
49  //
50 
51  Timer orb_info_timer;
52  // The tiling can be set by a simple vector, (e.g. 2x2x2), or by a
53  // full 3x3 matrix of integers. If the tilematrix was not set in
54  // the input file...
55  bool matrixNotSet = true;
56  for (int i = 0; i < 3; i++)
57  for (int j = 0; j < 3; j++)
58  matrixNotSet = matrixNotSet && (TileMatrix(i, j) == 0);
59  // then set the matrix to identity.
60  if (matrixNotSet)
61  for (int i = 0; i < 3; i++)
62  for (int j = 0; j < 3; j++)
63  TileMatrix(i, j) = (i == j) ? 1 : 0;
64  if (myComm->rank() == 0)
65  {
66  std::array<char, 1000> buff;
67  int length =
68  std::snprintf(buff.data(), buff.size(), " TileMatrix = \n [ %2d %2d %2d\n %2d %2d %2d\n %2d %2d %2d ]\n",
69  TileMatrix(0, 0), TileMatrix(0, 1), TileMatrix(0, 2), TileMatrix(1, 0), TileMatrix(1, 1),
70  TileMatrix(1, 2), TileMatrix(2, 0), TileMatrix(2, 1), TileMatrix(2, 2));
71  if (length < 0)
72  throw std::runtime_error("Error converting TileMatrix to a string");
73  app_log() << std::string_view(buff.data(), length);
74  }
75  if (numOrbs == 0)
77  "EinsplineSetBuilder::createSPOSet You must specify the number of orbitals in the input file.");
78  else
79  app_log() << " Reading " << numOrbs << " orbitals from HDF5 file.\n";
80 
81  /////////////////////////////////////////////////////////////////
82  // Read the basic orbital information, without reading all the //
83  // orbitals themselves. //
84  /////////////////////////////////////////////////////////////////
85  orb_info_timer.restart();
86  if (myComm->rank() == 0)
87  if (!ReadOrbitalInfo(skipChecks))
88  throw std::runtime_error("EinsplineSetBuilder::set_metadata Error reading orbital info from HDF5 file.");
89  app_log() << "TIMER EinsplineSetBuilder::ReadOrbitalInfo " << orb_info_timer.elapsed() << std::endl;
90  myComm->barrier();
91 
92  orb_info_timer.restart();
94  app_log() << "TIMER EinsplineSetBuilder::BroadcastOrbitalInfo " << orb_info_timer.elapsed() << std::endl;
95  app_log().flush();
96 
97  // setup primitive cell and supercell
101 
102  // Now, analyze the k-point mesh to figure out the what k-points are needed
103  AnalyzeTwists2(twist_num_inp, twist_inp);
104 }
void set(const Tensor< TT, D > &lat)
set the lattice vector from the command-line options
Tensor< double, OHMMS_DIM > GGt
Tensor< int, OHMMS_DIM > TileMatrix
void barrier() const
int rank() const
return the rank
Definition: Communicate.h:116
std::ostream & app_log()
Definition: OutputManager.h:65
Tensor_t G
Reciprocal unit vectors. G(j,i) i=vector and j=x,y,z.
void AnalyzeTwists2(const int twist_num_inp, const TinyVector< double, OHMMS_DIM > &twist_inp)
analyze twists of orbitals in h5 and determinine twist_num_
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
AntiSymTensor< T, D > transpose(const AntiSymTensor< T, D > &rhs)
Tensor< double, OHMMS_DIM > SuperLattice
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void barrier_and_abort(const std::string &msg) const
Tensor< double, OHMMS_DIM > Lattice

◆ TileIons()

void TileIons ( )

Definition at line 245 of file EinsplineSetBuilderCommon.cpp.

References Vector< T, Alloc >::begin(), copy(), qmcplusplus::FracPart(), ParticleSet::getPrimitiveLattice(), ParticleSet::getTotalNum(), ParticleSet::GroupID, EinsplineSetBuilder::IonPos, EinsplineSetBuilder::IonTypes, ParticleSet::R, Vector< T, Alloc >::resize(), and EinsplineSetBuilder::SourcePtcl.

Referenced by EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

246 {
247  //set the primitive lattice
249 
250  for (int j = 0; j < IonPos.size(); ++j)
252 
253  IonPos.resize(SourcePtcl->getTotalNum());
255  std::copy(SourcePtcl->R.begin(), SourcePtcl->R.end(), IonPos.begin());
257 
258  //app_log() << " Primitive Cell\n";
259  //SourcePtcl->getPrimitiveLattice().print(app_log());
260  //app_log() << " Super Cell\n";
261  //SourcePtcl->Lattice.print(app_log());
262 
263  //Don't need to do this, already one by ParticleSetPool.cpp
264  // Vector<TinyVector<double, OHMMS_DIM> > primPos = IonPos;
265  // Vector<int> primTypes = IonTypes;
266  // int numCopies = std::abs(det(TileMatrix));
267  // IonTypes.resize(primPos.size()*numCopies);
268  // IonPos.resize (primPos.size()*numCopies);
269  // int maxCopies = 10;
270  // using Vec3 = TinyVector<double,3>;
271  // int index=0;
272  // for (int i0=-maxCopies; i0<=maxCopies; i0++)
273  // for (int i1=-maxCopies; i1<=maxCopies; i1++)
274  // for (int i2=-maxCopies; i2<=maxCopies; i2++)
275  // for (int iat=0; iat < primPos.size(); iat++)
276  // {
277  // Vec3 r = primPos[iat];
278  // Vec3 uPrim = PrimCell.toUnit(r);
279  // for (int i=0; i<3; i++)
280  // uPrim[i] -= std::floor(uPrim[i]);
281  // r = PrimCell.toCart(uPrim) + (double)i0*PrimCell.a(0) +
282  // (double)i1*PrimCell.a(1) + (double)i2*PrimCell.a(2);
283  // Vec3 uSuper = SuperCell.toUnit(r);
284  // if ((uSuper[0] >= -1.0e-4) && (uSuper[0] < 0.9999) &&
285  // (uSuper[1] >= -1.0e-4) && (uSuper[1] < 0.9999) &&
286  // (uSuper[2] >= -1.0e-4) && (uSuper[2] < 0.9999))
287  // {
288  // IonPos[index]= r;
289  // IonTypes[index]= primTypes[iat];
290  // index++;
291  // }
292  // }
293  // if (index != primPos.size()*numCopies)
294  // {
295  // app_error() << "The number of tiled ions, " << IonPos.size()
296  // << ", does not match the expected number of "
297  // << primPos.size()*numCopies << " or the index "<< index <<". Aborting.\n";
298  // APP_ABORT("EinsplineSetBuilder::TileIons()");
299  // }
300  // if (myComm->rank() == 0)
301  // {
302  // char buf[1000];
303  // snprintf (buf, 1000, "Supercell reduced ion positions = \n");
304  // app_log() << buf;
305  // app_log().flush();
306  // for (int i=0; i<IonPos.size(); i++)
307  // {
308  // PosType u = SuperCell.toUnit(IonPos[i]);
309  // char buf2[1000];
310  // snprintf (buf2, 1000, " %14.10f %14.10f %14.10f\n",
311  // u[0], u[1], u[2]);
312  // app_log() << buf2;
313  // app_log().flush();
314  // // IonPos[i][0], IonPos[i][1], IonPos[i][2]);
315  // }
316  // }
317 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
size_t getTotalNum() const
Definition: ParticleSet.h:493
TinyVector< T, 3 > FracPart(const TinyVector< T, 3 > &twist)
ParticleSet * SourcePtcl
ionic system
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
Vector< TinyVector< double, OHMMS_DIM > > IonPos
ParticlePos R
Position.
Definition: ParticleSet.h:79
Tensor< double, OHMMS_DIM > Lattice
auto & getPrimitiveLattice() const
Definition: ParticleSet.h:252

◆ TwistPair()

bool TwistPair ( PosType  a,
PosType  b 
) const

Definition at line 320 of file EinsplineSetBuilderCommon.cpp.

References qmcplusplus::abs(), EinsplineSetBuilder::MatchingTol, qmcplusplus::n, and OHMMS_DIM.

Referenced by EinsplineSetBuilder::AnalyzeTwists2().

321 {
322  bool pair = true;
323  for (int n = 0; n < OHMMS_DIM; n++)
324  {
325  double d = a[n] + b[n];
326  if (std::abs(d - round(d)) > MatchingTol)
327  pair = false;
328  }
329  return pair;
330 }
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
#define OHMMS_DIM
Definition: config.h:64

Member Data Documentation

◆ AtomicCentersInfo

◆ DistinctTwists

◆ eigenstatesGroup

std::string eigenstatesGroup

Definition at line 168 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::OccupyBands().

◆ Format

◆ FullBands

◆ GGt

Tensor<double, OHMMS_DIM> GGt

Definition at line 180 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::set_metadata().

◆ Gvecs

std::vector<std::vector<TinyVector<int, 3> > > Gvecs

Definition at line 187 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::ReadGvectors_ESHDF().

◆ H5File

◆ H5FileName

◆ HaveOrbDerivs

bool HaveOrbDerivs

This is true if we have the orbital derivatives w.r.t. the ion positions.

Definition at line 135 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::BroadcastOrbitalInfo(), and EinsplineSetBuilder::ReadOrbitalInfo_ESHDF().

◆ IncludeTwists

std::vector<int> IncludeTwists

Definition at line 205 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::AnalyzeTwists2().

◆ IonPos

◆ ionsGroup

std::string ionsGroup

Definition at line 168 of file EinsplineSetBuilder.h.

◆ IonTypes

◆ LastSpinSet

int LastSpinSet

Definition at line 255 of file EinsplineSetBuilder.h.

◆ Lattice

◆ LatticeInv

◆ makeRotations

bool makeRotations

Definition at line 259 of file EinsplineSetBuilder.h.

◆ MakeTwoCopies

◆ MatchingTol

◆ MaxNumGvecs

int MaxNumGvecs

Definition at line 183 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::ReadGvectors_ESHDF().

◆ MeshFactor

◆ MeshSize

◆ MixedSplineReader

◆ NumBands

◆ NumDistinctOrbitals

◆ NumElectrons

◆ NumOrbitalsRead

int NumOrbitalsRead

Definition at line 255 of file EinsplineSetBuilder.h.

◆ NumSpins

◆ NumTwists

◆ Occ

◆ occ_format

◆ parameterGroup

std::string parameterGroup

Definition at line 168 of file EinsplineSetBuilder.h.

◆ particle_hole_pairs

◆ ParticleSets

const PSetMap& ParticleSets

reference to the particleset pool

Definition at line 121 of file EinsplineSetBuilder.h.

Referenced by EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

◆ PrimCell

◆ primcell_kpoints

◆ PrimCellInv

UnitCellType PrimCellInv

Definition at line 181 of file EinsplineSetBuilder.h.

◆ RecipLattice

◆ SourcePtcl

◆ SPOSetMap

◆ Super2Prim

std::vector<int> Super2Prim

◆ SuperCell

◆ SuperLattice

◆ TargetPtcl

◆ TileMatrix

◆ TWIST_NO_INPUT

constexpr double TWIST_NO_INPUT = -9999
staticprotected

twist_inp[i] <= -9999 to indicate no given input after parsing XML

Definition at line 285 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::AnalyzeTwists2(), EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

◆ twist_num_

◆ TwistMap

std::map<TinyVector<int, OHMMS_DIM>, int, Int3less> TwistMap

Definition at line 214 of file EinsplineSetBuilder.h.

◆ TWISTNUM_NO_INPUT

constexpr int TWISTNUM_NO_INPUT = -9999
staticprotected

twistnum_inp == -9999 to indicate no given input after parsing XML

Definition at line 283 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::AnalyzeTwists2(), EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

◆ use_real_splines_

bool use_real_splines_

if false, splines are conceptually complex valued

Definition at line 207 of file EinsplineSetBuilder.h.

Referenced by EinsplineSetBuilder::AnalyzeTwists2(), EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().

◆ UseTwists

std::vector<TinyVector<int, OHMMS_DIM> > UseTwists

Definition at line 204 of file EinsplineSetBuilder.h.

◆ Version

◆ XMLRoot

xmlNodePtr XMLRoot

root XML node with href, sort, tilematrix, twistnum, source, precision,truncate,version

Definition at line 137 of file EinsplineSetBuilder.h.

Referenced by EinsplineSpinorSetBuilder::createSPOSetFromXML(), and EinsplineSetBuilder::createSPOSetFromXML().


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