26 #include <string_view> 32 #include "mpi/collectives.h" 60 MatchingTol = 10 * std::numeric_limits<float>::epsilon();
61 for (
int i = 0; i < 3; i++)
62 for (
int j = 0; j < 3; j++)
76 return TinyVector<T, 3>(round(twist[0] - 1.0
e-6), round(twist[1] - 1.0
e-6), round(twist[2] - 1.0
e-6));
103 std::ostringstream o;
104 o.setf(std::ios::scientific, std::ios::floatfield);
106 o <<
"EinsplineSetBuilder::ReadOrbitalInfo_ESHDF \n" <<
"Mismatched supercell lattices.\n";
107 o <<
" Lattice in ESHDF5 " << std::endl;
109 o <<
" Lattice in xml" << std::endl;
111 o <<
" Difference " << std::endl;
113 o <<
" Max relative error = " << diff << std::endl;
139 aibuffer.
add(numIons);
140 aibuffer.
add(numDensityGvecs);
158 aibuffer.
get(numIons);
159 aibuffer.
get(numDensityGvecs);
172 for (
int i = 0; i < numIons; ++i)
189 for (
int i = 0; i < numIons; ++i)
226 for (
int i = 0; i < numIons; i++)
250 for (
int j = 0; j <
IonPos.size(); ++j)
325 double d = a[
n] + b[
n];
335 for (
int i = 0; i < 3; i++)
336 for (
int j = 0; j < 3; j++)
342 std::vector<PosType> superFracs;
347 for (
int ki = 0; ki < num_prim_kpoints; ki++)
354 if (
dot(ks - kp, ks - kp) > 1.0
e-6)
356 app_error() <<
"Primitive and super k-points do not agree. Error in coding.\n";
357 APP_ABORT(
"EinsplineSetBuilder::AnalyzeTwists2");
362 for (
int j = 0; j < superFracs.size(); j++)
364 PosType diff = frac - superFracs[j];
365 if (
dot(diff, diff) < 1.0e-6)
368 superIndex.push_back(j);
373 superIndex.push_back(superFracs.size());
374 superFracs.push_back(frac);
377 assert(superIndex.size() == num_prim_kpoints);
380 const int numSuperTwists = superFracs.
size();
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" :
"")
388 for (
int si = 0; si < numSuperTwists; si++)
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]);
394 throw std::runtime_error(
"Error converting Super twist to a string");
395 app_log() << std::string_view(buf.data(), length);
402 std::vector<std::vector<int>> superSets;
404 superSets.resize(numSuperTwists);
405 for (
int ki = 0; ki < num_prim_kpoints; ki++)
406 superSets[superIndex[ki]].push_back(ki);
414 for (
int si = 0; si < numSuperTwists; si++)
416 PosType locDiff = gtFrac - superFracs[si];
417 if (
dot(locDiff, locDiff) < eps)
423 std::array<char, 1000> buf;
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]);
429 throw std::runtime_error(
"Error generating error message");
438 app_warning() <<
"twist attribute exists. twistnum attribute ignored. " 439 "To prevent this message, remove twistnum from input." 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)
450 std::ostringstream msg;
451 msg <<
"AnalyzeTwists2. twistnum input value " << twist_num_inp <<
" is outside the acceptable range [0, " 452 << numSuperTwists <<
")." << std::endl;
459 app_log() <<
"twist attribte does't exist. Set Gamma point." << std::endl;
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_,
469 throw std::runtime_error(
"Error converting supercell twist to a string");
470 app_log() << std::string_view(buf.data(), length) << std::endl;
477 for (
int dim = 0; dim <
OHMMS_DIM; dim++)
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");
491 for (
int si = 0; si < numSuperTwists; si++)
494 if (superSets[si].size() != numTwistsNeeded)
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()));
500 throw std::runtime_error(
"Error generating Super twist string");
501 app_error() << std::string_view(buf.data(), length);
504 APP_ABORT(
"EinsplineSetBuilder::AnalyzeTwists2");
510 int N = superSets[si].size();
511 for (
int i = 0; i <
N; i++)
516 for (
int j = i + 1; j <
N; j++)
521 if (
dot(superInt_i - superInt_j, superInt_i - superInt_j) < 1.0
e-6)
523 app_error() <<
"Identical k-points detected in super twist set " << si << std::endl;
533 for (
int i = 0; i < superSets[
twist_num_].size(); i++)
538 std::vector<int> copyTwists;
543 bool distinct =
true;
548 PosType sum = twist_i + twist_j;
549 PosType diff = twist_i - twist_j;
556 copyTwists.push_back(ti);
565 for (
int j = 0; j < copyTwists.size(); j++)
567 int tj = copyTwists[j];
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]);
578 throw std::runtime_error(
"Error generating string");
579 app_log() << std::string_view(buf.data(), length);
596 app_log() <<
"***** Use of real orbitals is possible, but not currently implemented\n" 597 <<
" with more than one twist angle.\n";
601 app_log() <<
"Using real splines.\n";
603 app_log() <<
"Using complex splines.\n";
621 if (spin >=
NumSpins && !skipChecks)
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 " 627 <<
"If this is your intent, please replace 'spindataset=1' with 'spindataset=0' in the input file." 644 app_log() <<
" FullBand[" << spin <<
"] exists. Reuse it. " << std::endl;
648 std::vector<BandInfo>& SortBands(*
FullBands[spin]);
655 for (
int bi = 0; bi <
NumBands; bi++)
662 std::ostringstream ePath, sPath;
665 ePath <<
eigenstatesGroup <<
"/twist_" << tindex <<
"/band_" << bi <<
"/eigenvalue";
666 sPath <<
eigenstatesGroup <<
"/twist_" << tindex <<
"/band_" << bi <<
"/spin";
680 if (band.
Energy > -1.0e100)
683 if (band.
Spin == spin)
684 SortBands.push_back(band);
689 int numOrbs_counter = 0;
690 while (numOrbs_counter < numOrbs)
693 numOrbs_counter += 2;
704 std::vector<BandInfo>& SortBands(*
FullBands[spin]);
716 for (
int i = 0; i <
n; ++i)
718 misc.
put(SortBands[i].TwistIndex);
719 misc.
put(SortBands[i].BandIndex);
720 misc.
put(SortBands[i].Energy);
724 for (
int i =
n; i < SortBands.size(); ++i)
726 misc.
put(SortBands[i].TwistIndex);
727 misc.
put(SortBands[i].BandIndex);
728 misc.
put(SortBands[i].Energy);
736 SortBands.resize(nbands[0]);
738 for (
int i = 0; i <
n; ++i)
740 misc.
get(SortBands[i].TwistIndex);
741 misc.
get(SortBands[i].BandIndex);
742 misc.
get(SortBands[i].Energy);
745 for (
int i =
n; i < SortBands.size(); ++i)
747 misc.
get(SortBands[i].TwistIndex);
748 misc.
get(SortBands[i].BandIndex);
749 misc.
get(SortBands[i].Energy);
void resize(size_type n, Type_t val=Type_t())
Resize the container.
a class that defines a supercell in D-dimensional Euclean space.
bool TwistPair(PosType a, PosType b) const
double Energy
energy associated with this band
Tensor< int, OHMMS_DIM > TileMatrix
std::ostream & app_warning()
void resize(int ncenters)
helper functions for EinsplineSetBuilder
int rank() const
return the rank
std::vector< double > spline_radius
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
std::vector< int > DistinctTwists
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
size_t getTotalNum() const
ParticleSet & TargetPtcl
quantum particle set
TinyVector< T, 3 > FracPart(const TinyVector< T, 3 > &twist)
std::vector< TinyVector< double, OHMMS_DIM > > ion_pos
std::ostream & app_error()
Builder class for einspline-based SPOSet objects.
void OccupyBands_ESHDF(int spin, int sortBands, int numOrbs)
struct qmcplusplus::EinsplineSetBuilder::CenterInfo AtomicCentersInfo
TinyVector< int, 3 > Version
ParticleSet * SourcePtcl
ionic system
std::vector< std::unique_ptr< SPOSetInfo > > states
state info of all possible states available in the basis
std::vector< int > Super2Prim
std::vector< double > non_overlapping_radius
void rewind(size_type cur=0)
set the Current to a cursor
int size() const
return the number of tasks
void AnalyzeTwists2(const int twist_num_inp, const TinyVector< double, OHMMS_DIM > &twist_inp)
analyze twists of orbitals in h5 and determinine twist_num_
std::vector< int > spline_npoints
std::vector< std::unique_ptr< std::vector< BandInfo > > > FullBands
Helper vector for sorting bands.
std::vector< double > inner_cutoff
ParticleIndex GroupID
Species ID.
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Wrapping information on parallelism.
bool HaveOrbDerivs
This is true if we have the orbital derivatives w.r.t. the ion positions.
int groups() const
return the number of groups
TinyVector< T, 3 > IntPart(const TinyVector< T, 3 > &twist)
Vector< TinyVector< double, OHMMS_DIM > > IonPos
SingleParticlePos k_cart(const SingleParticlePos &kin) const
conversion of a reciprocal-vector
void bcast(T &a, Communicate *comm)
Specialized paritlce class for atomistic simulations.
base class for the real SPOSet builder
size_type size() const
return the current size
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
~EinsplineSetBuilder() override
destructor
base class to read data and manage spline tables
void BroadcastOrbitalInfo()
Communicate * myComm
pointer to Communicate
This a subclass for runtime errors that will occur on all ranks.
std::vector< ComplexType > Density_G
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
std::string ClassName
class Name
std::string eigenstatesGroup
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
bool MakeTwoCopies
This is true if we should make distinct copies represeninting a +k, -k pair.
std::vector< bool > MakeTwoCopies
void setTwist(const SingleParticlePos &t)
void OccupyBands(int spin, int sortBands, int numOrbs, bool skipChecks=false)
static constexpr int TWISTNUM_NO_INPUT
twistnum_inp == -9999 to indicate no given input after parsing XML
#define DEBUG_MEMORY(msg)
std::vector< double > cutoff
int TwistIndex
twist index
Tensor< double, OHMMS_DIM > LatticeInv
Tensor< double, OHMMS_DIM > SuperLattice
const auto & getLattice() const
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 ...
std::vector< int > IncludeTwists
#define APP_ABORT_TRACE(f, l, msg)
Tensor< double, OHMMS_DIM > RecipLattice
EinsplineSetBuilder(ParticleSet &p, const PSetMap &psets, Communicate *comm, xmlNodePtr cur)
constructor
std::vector< TinyVector< int, OHMMS_DIM > > DensityReducedGvecs
Particle density in G-space for MPC interaction.
std::vector< int > GroupID
bool use_real_splines_
if false, splines are conceptually complex valued
auto & getPrimitiveLattice() const