diff --git a/src/Estimators/MomentumDistribution.cpp b/src/Estimators/MomentumDistribution.cpp index 8e08b8659c..e2c6cfb473 100644 --- a/src/Estimators/MomentumDistribution.cpp +++ b/src/Estimators/MomentumDistribution.cpp @@ -85,9 +85,9 @@ MomentumDistribution::MomentumDistribution(MomentumDistributionInput&& mdi, for (int k = -kgrid; k < (kgrid + 1); k++) { PosType ikpt, kpt; - ikpt[0] = i - twist[0]; - ikpt[1] = j - twist[1]; - ikpt[2] = k - twist[2]; + ikpt[0] = i + twist[0]; + ikpt[1] = j + twist[1]; + ikpt[2] = k + twist[2]; //convert to Cartesian: note that 2Pi is multiplied kpt = Lattice.k_cart(ikpt); bool not_recorded = true; diff --git a/src/QMCHamiltonians/MomentumEstimator.cpp b/src/QMCHamiltonians/MomentumEstimator.cpp index ad49563940..709a0f2e01 100644 --- a/src/QMCHamiltonians/MomentumEstimator.cpp +++ b/src/QMCHamiltonians/MomentumEstimator.cpp @@ -214,9 +214,9 @@ bool MomentumEstimator::putSpecial(xmlNodePtr cur, ParticleSet& elns, bool rootN for (int k = -kgrid; k < (kgrid + 1); k++) { PosType ikpt, kpt; - ikpt[0] = i - twist[0]; - ikpt[1] = j - twist[1]; - ikpt[2] = k - twist[2]; + ikpt[0] = i + twist[0]; + ikpt[1] = j + twist[1]; + ikpt[2] = k + twist[2]; //convert to Cartesian: note that 2Pi is multiplied kpt = lattice_.k_cart(ikpt); bool not_recorded = true; diff --git a/src/QMCWaveFunctions/BsplineFactory/BsplineReaderBase.h b/src/QMCWaveFunctions/BsplineFactory/BsplineReaderBase.h index f00cede95c..0ee1a5e285 100644 --- a/src/QMCWaveFunctions/BsplineFactory/BsplineReaderBase.h +++ b/src/QMCWaveFunctions/BsplineFactory/BsplineReaderBase.h @@ -113,7 +113,7 @@ struct BsplineReaderBase for (int iorb = 0; iorb < N; iorb++) { int ti = cur_bands[iorb].TwistIndex; - bspline->kPoints[iorb] = mybuilder->PrimCell.k_cart(mybuilder->TwistAngles[ti]); //twist); + bspline->kPoints[iorb] = mybuilder->PrimCell.k_cart(-mybuilder->TwistAngles[ti]); bspline->MakeTwoCopies[iorb] = (num < (numOrbs - 1)) && cur_bands[iorb].MakeTwoCopies; num += bspline->MakeTwoCopies[iorb] ? 2 : 1; } @@ -125,7 +125,6 @@ struct BsplineReaderBase if (!bspline->is_complex) { //no k-point folding, single special k point (G, L ...) - //TinyVector twist0 = mybuilder->TwistAngles[cur_bands[0].TwistIndex]; TinyVector twist0 = mybuilder->TwistAngles[bandgroup.TwistIndex]; for (int i = 0; i < 3; i++) if (bconds[i] && ((std::abs(std::abs(twist0[i]) - 0.5) < 1.0e-8))) @@ -191,7 +190,7 @@ struct BsplineReaderBase /** export the MultiSpline to the old class EinsplineSetExtended for the GPU calculation*/ virtual std::unique_ptr export_MultiSplineComplexDouble() = 0; - virtual std::unique_ptr export_MultiSplineDouble() = 0; + virtual std::unique_ptr export_MultiSplineDouble() = 0; }; } // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/BsplineFactory/BsplineSet.h b/src/QMCWaveFunctions/BsplineFactory/BsplineSet.h index d0d1a32be0..cf8d3c6a84 100644 --- a/src/QMCWaveFunctions/BsplineFactory/BsplineSet.h +++ b/src/QMCWaveFunctions/BsplineFactory/BsplineSet.h @@ -47,7 +47,10 @@ class BsplineSet : public SPOSet TinyVector HalfG; ///flags to unpack sin/cos std::vector MakeTwoCopies; - ///kpoints for each unique orbitals + /** kpoints for each unique orbitals. + * Note: for historic reason, this sign is opposite to what was used in DFT when orbitals were generated. + * Changing the sign requires updating all the evaluation code. + */ std::vector kPoints; ///remap splines to orbitals aligned_vector BandIndexMap; diff --git a/src/QMCWaveFunctions/EinsplineSet.h b/src/QMCWaveFunctions/EinsplineSet.h index 203af8cac3..27defb9ecd 100644 --- a/src/QMCWaveFunctions/EinsplineSet.h +++ b/src/QMCWaveFunctions/EinsplineSet.h @@ -262,7 +262,10 @@ class EinsplineSetExtended : public EinsplineSet // True if we should unpack this orbital into two copies std::vector MakeTwoCopies; - // k-points for each orbital + /** kpoints for each unique orbitals. + * Note: for historic reason, this sign is opposite to what was used in DFT when orbitals were generated. + * Changing the sign requires updating all the evaluation code. + */ Vector> kPoints; /////////////////// diff --git a/src/QMCWaveFunctions/EinsplineSetBuilderCommon.cpp b/src/QMCWaveFunctions/EinsplineSetBuilderCommon.cpp index e352471412..9e01584573 100644 --- a/src/QMCWaveFunctions/EinsplineSetBuilderCommon.cpp +++ b/src/QMCWaveFunctions/EinsplineSetBuilderCommon.cpp @@ -633,124 +633,6 @@ void EinsplineSetBuilder::AnalyzeTwists2() } -// This function analyzes the twist vectors to see if they lay on a -// valid k-point mesh. It flags errors an aborts if they do not. -// As a side-effect, it sets up TwistMap, which maps [ix,iy,iz] into -// a single integer twist index. -/* seems legacy. Ye Luo -void -EinsplineSetBuilder::AnalyzeTwists() -{ - PosType minTwist(TwistAngles[0]), maxTwist(TwistAngles[0]); - for (int ti=0; ti n((int)round(nf[0]), (int)round(nf[1]), (int)round(nf[2])); - TwistMesh = n; - // Now, make sure we have all the k-points in the lattice - PosType twist; - for (int ix=0; ix tindex (ix, iy, iz); - TwistMap[tindex] = ti; - } - } - if (!twistFound) - { - fprintf (stderr, "Missing twist vector (%8.4f, %8.4f, %8.4f) " - "in CheckkPointMesh.\n", twist[0], twist[1], twist[2]); - abort(); - } - } - // If we got this far, we have a valid twist mesh. Now check to - // see if the mesh is commensurate with the tiling factor - if (((TwistMesh[0] % TileFactor[0]) != 0) || - ((TwistMesh[1] % TileFactor[1]) != 0) || - ((TwistMesh[2] % TileFactor[2]) != 0)) - { - app_error() << "The tiling factor, " - << TileFactor[0] << "x" << TileFactor[1] << "x" << TileFactor[2] - << " is not commensurate with the k-point mesh, " - << TwistMesh[0] << "x" << TwistMesh[1] << "x" << TwistMesh[2] << ".\n"; - abort(); - } - TinyVector untiledMesh (TwistMesh[0]/TileFactor[0], - TwistMesh[1]/TileFactor[1], - TwistMesh[2]/TileFactor[2]); - // Finally, let's decide which twist vectors we're supposed to - // read - fprintf (stderr, " After untiling by %dx%dx%d, we are left with a %dx%dx%d k-point mesh.\n", - TileFactor[0], TileFactor[1], TileFactor[2], - untiledMesh[0], untiledMesh[1], untiledMesh[2]); - TinyVector offset; - offset[0] = TwistNum/(untiledMesh[2]*untiledMesh[1]); - offset[1] = (TwistNum%(untiledMesh[2]*untiledMesh[1])) / untiledMesh[1]; - offset[2] = (TwistNum%(untiledMesh[2]*untiledMesh[1])) % untiledMesh[1]; -// std::map, int>::iterator iter; -// for (iter = TwistMap.begin(); iter!=TwistMap.end(); iter++) -// std::cerr << "TwistMap = " << (*iter).first -// << ", " << (*iter).second << std::endl; - app_log() << " Including twist vectors:\n"; - UseTwists.clear(); - for (int tx=0; tx tIndex; - tIndex = offset; - tIndex[0] += tx*untiledMesh[0]; - tIndex[1] += ty*untiledMesh[1]; - tIndex[2] += tz*untiledMesh[2]; - UseTwists.push_back(tIndex); - int ti = TwistMap[tIndex]; - app_log() << "tIndex = (" << tIndex[0] << ", " << tIndex[1] << ", " - << tIndex[2] << ")\n"; - // fprintf (stderr, "tIndex = (%d, %d, %d) ti = %d\n", - // tIndex[0], tIndex[1], tIndex[2], ti); - char buff[100]; - snprintf (buff, 100, " (%6.3f %6.3f %6.3f)\n", - TwistAngles[ti][0], TwistAngles[ti][1], TwistAngles[ti][2]); - app_log() << buff; - } -} -*/ - - void EinsplineSetBuilder::OccupyBands(int spin, int sortBands, int numOrbs, bool skipChecks) { if (myComm->rank() != 0) diff --git a/src/QMCWaveFunctions/EinsplineSetBuilderESHDF.fft.cpp b/src/QMCWaveFunctions/EinsplineSetBuilderESHDF.fft.cpp index 763c82a608..9bf2e46ebc 100644 --- a/src/QMCWaveFunctions/EinsplineSetBuilderESHDF.fft.cpp +++ b/src/QMCWaveFunctions/EinsplineSetBuilderESHDF.fft.cpp @@ -177,9 +177,9 @@ bool EinsplineSetBuilder::ReadOrbitalInfo_ESHDF(bool skipChecks) for (int i = 0; i < IonPos.size(); i++) AtomicCentersInfo.ion_pos[i] = IonPos[i]; const auto& source_species = SourcePtcl->getSpeciesSet(); - int Zind = source_species.findAttribute("atomicnumber"); - const int table_id = SourcePtcl->addTable(*SourcePtcl); - const auto& ii_table = SourcePtcl->getDistTable(table_id); + int Zind = source_species.findAttribute("atomicnumber"); + const int table_id = SourcePtcl->addTable(*SourcePtcl); + const auto& ii_table = SourcePtcl->getDistTable(table_id); SourcePtcl->update(true); for (int i = 0; i < IonPos.size(); i++) { @@ -295,15 +295,6 @@ bool EinsplineSetBuilder::ReadOrbitalInfo_ESHDF(bool skipChecks) HDFAttribIO h_Nsym(TwistWeight[ti]); h_Nsym.read(H5FileID, nsym_path.str().c_str()); } - // Early versions from wfconv had wrong sign convention for - // k-points. EinsplineSet uses the opposite sign convention - // from most DFT codes. - if (Version[0] >= 2) - for (int dim = 0; dim < OHMMS_DIM; dim++) - TwistAngles[ti][dim] *= -1.0; - // snprintf (buff, 1000, " Found twist angle (%6.3f, %6.3f, %6.3f)\n", - // TwistAngles[ti][0], TwistAngles[ti][1], TwistAngles[ti][2]); - // app_log() << buff; } if (qmc_common.use_density) { @@ -654,356 +645,4 @@ void EinsplineSetBuilder::OccupyBands_ESHDF(int spin, int sortBands, int numOrbs app_log() << "There are " << NumCoreOrbs << " core states and " << NumValenceOrbs << " valence states.\n"; } -#if 0 -/** TODO: FIXME RotateBands_ESHDF need psi_r */ -void EinsplineSetBuilder::RotateBands_ESHDF (int spin, EinsplineSetExtended >* orbitalSet) -{ - bool root = (myComm->rank()==0); - if (root) - { - rotationMatrix.resize(0); - rotatedOrbitals.resize(0); - xmlNodePtr kids=XMLRoot->children; - while(kids != NULL) - { - std::string cname((const char*)(kids->name)); - if(cname == "rotationmatrix") - putContent(rotationMatrix,kids); - else - if(cname=="rotatedorbitals") - putContent(rotatedOrbitals,kids); - kids=kids->next; - } - if ((rotatedOrbitals.size()*rotatedOrbitals.size() != rotationMatrix.size()) && (rotationMatrix.size()!=0)) - { - app_log()<<" Rotation Matrix is wrong dimension. "<0) - { - app_log()<<" Rotating between: "; - for (int i=0; i0) && (rotatedOrbitals.size()>0) ) - { - int N = NumDistinctOrbitals; - int num(0); - for (int iorb=0, indx=0; iorbMakeTwoCopies[iorb] ? 2 : 1; - if (num==rotatedOrbitals[indx]) - { - rotatedOrbitals[indx]=iorb; - indx++; - } - } - //simple copy file function. make backup. - std::string backupName = H5FileName+"_bkup"; - std::ifstream fin(H5FileName.c_str(), std::ios::in | std::ios::binary); - std::ofstream fout(backupName.c_str() , std::ios::in); // open with this mode to check whether file exists - // std::ofstream fout(backupName.c_str(), std::ios::out | std::ios::binary); - if (fin.fail()) - { - // reset status flags - fin.clear(); - std::cout << " source file does not exist, try it again"<< std::endl; - exit( 0 ); - } - if (!fout.fail()) - { - fout.close(); - std::cout << " destination file already exists, backup completed"<< std::endl; - } - else - { - fout.close(); - fout.open(backupName.c_str() , std::ios::out | std::ios::binary); // change to writing mode - int BUFFER_SIZE = 128; - char buffer[BUFFER_SIZE]; - while (!fin.eof() ) - { - fin.read( buffer, BUFFER_SIZE); - if (fin.bad()) - { - std::cout << "Error reading data" << std::endl; - exit( 0 ); - } - else - fout.write(buffer, fin.gcount()); - } - } - fin.close(); - fout.close(); - int nx, ny, nz, bi, ti; - std::vector,3> > allRotatedSplines; - Array,3> splineData; - TinyVector mesh; - // Find the orbital mesh size - HDFAttribIO > h_mesh(mesh); - h_mesh.read (H5FileID, "/electrons/psi_r_mesh"); - h_mesh.read (H5FileID, "/electrons/mesh"); - // myComm->bcast(mesh); - nx=mesh[0]; - ny=mesh[1]; - nz=mesh[2]; - splineData.resize(nx,ny,nz); - std::vector& SortBands(*FullBands[spin]); - for (int i=0; iPrimLattice.k_cart(twist); - fprintf (stderr, " Rotating state: ti=%3d bi=%3d energy=%8.5f k=(%7.4f, %7.4f, %7.4f) rank=%d \n", - ti, bi, e, k[0], k[1], k[2], myComm->rank() ); - std::ostringstream path; - path << "/electrons/kpoint_" << ti << "/spin_" << spin << "/state_" << bi << "/"; - std::string psirName = path.str() + "psi_r"; - HDFAttribIO,3> > h_splineData(splineData); - h_splineData.read(H5FileID, psirName.c_str()); - if ((splineData.size(0) != nx) || - (splineData.size(1) != ny) || - (splineData.size(2) != nz)) - { - fprintf (stderr, "Error in EinsplineSetBuilder::ReadBands.\n"); - fprintf (stderr, "Extended orbitals should all have the same dimensions\n"); - abort(); - } - allRotatedSplines.push_back(splineData); - } - app_log()<< std::endl; - std::vector,3> > allOriginalSplines(allRotatedSplines); -#pragma omp parallel for - for (int i=0; i,3> > h_splineData(allRotatedSplines[i],true); - h_splineData.write(H5FileID, psirName.c_str()); - } - // for (int i=0;i,3> > h_splineData(allOriginalSplines[i]); - // h_splineData.read(H5FileID, psirName.c_str()); - // } - } - else - app_log()<<" No rotations defined"<< std::endl; - } -} - -void EinsplineSetBuilder::RotateBands_ESHDF (int spin, EinsplineSetExtended* orbitalSet) -{ - bool root = (myComm->rank()==0); - if (root) - { - rotationMatrix.resize(0); - rotatedOrbitals.resize(0); - xmlNodePtr kids=XMLRoot->children; - while(kids != NULL) - { - std::string cname((const char*)(kids->name)); - if(cname == "rotationmatrix") - putContent(rotationMatrix,kids); - else - if(cname=="rotatedorbitals") - putContent(rotatedOrbitals,kids); - kids=kids->next; - } - if ((rotatedOrbitals.size()*rotatedOrbitals.size() != rotationMatrix.size()) && (rotationMatrix.size()!=0)) - { - app_log()<<" Rotation Matrix is wrong dimension. "<0) - { - app_log()<<" Rotating between: "; - for (int i=0; i0) && (rotatedOrbitals.size()>0) ) - { - int N = NumDistinctOrbitals; - int num(0); - for (int iorb=0, indx=0; iorbMakeTwoCopies[iorb] ? 2 : 1; - if (num==rotatedOrbitals[indx]) - { - rotatedOrbitals[indx]=iorb; - indx++; - } - } - //simple copy file function. make backup. - std::string backupName = H5FileName+"_bkup"; - std::ifstream fin(H5FileName.c_str(), std::ios::in | std::ios::binary); - std::ofstream fout(backupName.c_str() , std::ios::in); // open with this mode to check whether file exists - // std::ofstream fout(backupName.c_str(), std::ios::out | std::ios::binary); - if (fin.fail()) - { - // reset status flags - fin.clear(); - std::cout << " source file does not exist, try it again"<< std::endl; - exit( 0 ); - } - if (!fout.fail()) - { - fout.close(); - std::cout << " destination file already exists, backup completed"<< std::endl; - } - else - { - fout.close(); - fout.open(backupName.c_str() , std::ios::out | std::ios::binary); // change to writing mode - int BUFFER_SIZE = 128; - char buffer[BUFFER_SIZE]; - while (!fin.eof() ) - { - fin.read( buffer, BUFFER_SIZE); - if (fin.bad()) - { - std::cout << "Error reading data" << std::endl; - exit( 0 ); - } - else - fout.write(buffer, fin.gcount()); - } - } - fin.close(); - fout.close(); - int nx, ny, nz, bi, ti; - std::vector,3> > allRotatedSplines; - Array,3> splineData; - TinyVector mesh; - // Find the orbital mesh size - HDFAttribIO > h_mesh(mesh); - h_mesh.read (H5FileID, "/electrons/psi_r_mesh"); - h_mesh.read (H5FileID, "/electrons/mesh"); - // myComm->bcast(mesh); - nx=mesh[0]; - ny=mesh[1]; - nz=mesh[2]; - splineData.resize(nx,ny,nz); - std::vector& SortBands(*FullBands[spin]); - for (int i=0; iPrimLattice.k_cart(twist); - fprintf (stderr, " Rotating state: ti=%3d bi=%3d energy=%8.5f k=(%7.4f, %7.4f, %7.4f) rank=%d \n", - ti, bi, e, k[0], k[1], k[2], myComm->rank() ); - std::ostringstream path; - path << "/electrons/kpoint_" << ti << "/spin_" << spin << "/state_" << bi << "/"; - std::string psirName = path.str() + "psi_r"; - HDFAttribIO,3> > h_splineData(splineData); - h_splineData.read(H5FileID, psirName.c_str()); - if ((splineData.size(0) != nx) || - (splineData.size(1) != ny) || - (splineData.size(2) != nz)) - { - fprintf (stderr, "Error in EinsplineSetBuilder::ReadBands.\n"); - fprintf (stderr, "Extended orbitals should all have the same dimensions\n"); - abort(); - } - allRotatedSplines.push_back(splineData); - } - app_log()<< std::endl; - std::vector,3> > allOriginalSplines(allRotatedSplines); -#pragma omp parallel for - for (int i=0; i,3> > h_splineData(allRotatedSplines[i],true); - h_splineData.write(H5FileID, psirName.c_str()); - } - // for (int i=0;i,3> > h_splineData(allOriginalSplines[i]); - // h_splineData.read(H5FileID, psirName.c_str()); - // } - } - else - app_log()<<" No rotations defined"<< std::endl; - } -} -#endif } // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/EinsplineSetBuilder_createSPOs.cpp b/src/QMCWaveFunctions/EinsplineSetBuilder_createSPOs.cpp index 5fa456afc3..f684e681da 100644 --- a/src/QMCWaveFunctions/EinsplineSetBuilder_createSPOs.cpp +++ b/src/QMCWaveFunctions/EinsplineSetBuilder_createSPOs.cpp @@ -365,7 +365,7 @@ std::unique_ptr EinsplineSetBuilder::createSPOSetFromXML(xmlNodePtr cur) for (int iorb = 0, num = 0; iorb < NumDistinctOrbitals; iorb++) { int ti = (*FullBands[spinSet])[iorb].TwistIndex; - temp_OrbitalSet->kPoints[iorb] = PrimCell.k_cart(TwistAngles[ti]); + temp_OrbitalSet->kPoints[iorb] = PrimCell.k_cart(-TwistAngles[ti]); temp_OrbitalSet->MakeTwoCopies[iorb] = (num < (numOrbs - 1)) && (*FullBands[spinSet])[iorb].MakeTwoCopies; num += temp_OrbitalSet->MakeTwoCopies[iorb] ? 2 : 1; } diff --git a/src/QMCWaveFunctions/einspline_helper.hpp b/src/QMCWaveFunctions/einspline_helper.hpp index 0659894b58..da5db77dc6 100644 --- a/src/QMCWaveFunctions/einspline_helper.hpp +++ b/src/QMCWaveFunctions/einspline_helper.hpp @@ -95,7 +95,7 @@ inline void fix_phase_rotate_c2r(Array, 3>& in, for (int iz = 0; iz < nz; iz++) { T ruz = static_cast(iz) * nz_i * twist[2]; - qmcplusplus::sincos(two_pi * (rux + ruy + ruz), &s, &c); + qmcplusplus::sincos(-two_pi * (rux + ruy + ruz), &s, &c); std::complex eikr(c, s); *in_ptr *= eikr; rNorm += in_ptr->real() * in_ptr->real(); @@ -259,7 +259,7 @@ inline void compute_phase(const Array, 3>& in, const TinyVector< for (size_t iz = 0; iz < nz; ++iz) { const T ruz = static_cast(iz) * nz_i * twist[2]; - qmcplusplus::sincos(two_pi * (rux + ruy + ruz), &s, &c); + qmcplusplus::sincos(-two_pi * (rux + ruy + ruz), &s, &c); const T re = c * in_ptr[iz].real() - s * in_ptr[iz].imag(); const T im = s * in_ptr[iz].real() + c * in_ptr[iz].imag(); rsum += re * re;