From 6ebe8f6bf51d92c9fd7d4c4e6236439547e4695e Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Thu, 28 Sep 2023 14:16:36 -0500 Subject: [PATCH 1/4] Change PWOrbitalBuilder to PWOrbitalSetBuilder --- .../EinsplineSetBuilder_createSPOs.cpp | 3 - src/QMCWaveFunctions/CMakeLists.txt | 2 +- ...talBuilder.cpp => PWOrbitalSetBuilder.cpp} | 119 +++++------------- ...OrbitalBuilder.h => PWOrbitalSetBuilder.h} | 30 ++--- src/QMCWaveFunctions/SPOSetBuilderFactory.cpp | 18 ++- src/QMCWaveFunctions/WaveFunctionFactory.cpp | 5 - 6 files changed, 57 insertions(+), 120 deletions(-) rename src/QMCWaveFunctions/PlaneWave/{PWOrbitalBuilder.cpp => PWOrbitalSetBuilder.cpp} (76%) rename src/QMCWaveFunctions/PlaneWave/{PWOrbitalBuilder.h => PWOrbitalSetBuilder.h} (68%) diff --git a/src/QMCWaveFunctions/BsplineFactory/EinsplineSetBuilder_createSPOs.cpp b/src/QMCWaveFunctions/BsplineFactory/EinsplineSetBuilder_createSPOs.cpp index 8aba6bf396..16a9869fbc 100644 --- a/src/QMCWaveFunctions/BsplineFactory/EinsplineSetBuilder_createSPOs.cpp +++ b/src/QMCWaveFunctions/BsplineFactory/EinsplineSetBuilder_createSPOs.cpp @@ -124,7 +124,6 @@ std::unique_ptr EinsplineSetBuilder::createSPOSetFromXML(xmlNodePtr cur) "no"); // use old spline library for high-order derivatives, e.g. needed for backflow optimization std::string useGPU; std::string GPUsharing = "no"; - std::string spo_object_name; ScopedTimer spo_timer_scope(createGlobalTimer("einspline::CreateSPOSetFromXML", timer_level_medium)); @@ -177,8 +176,6 @@ std::unique_ptr EinsplineSetBuilder::createSPOSetFromXML(xmlNodePtr cur) { OhmmsAttributeSet oAttrib; oAttrib.add(spinSet, "spindataset"); - oAttrib.add(spo_object_name, "name"); - oAttrib.add(spo_object_name, "id"); oAttrib.put(cur); } diff --git a/src/QMCWaveFunctions/CMakeLists.txt b/src/QMCWaveFunctions/CMakeLists.txt index 886663216c..44b8a90a4a 100644 --- a/src/QMCWaveFunctions/CMakeLists.txt +++ b/src/QMCWaveFunctions/CMakeLists.txt @@ -103,7 +103,7 @@ if(OHMMS_DIM MATCHES 3) endif(HAVE_EINSPLINE) # plane wave SPO - set(FERMION_SRCS ${FERMION_SRCS} PlaneWave/PWBasis.cpp PlaneWave/PWParameterSet.cpp PlaneWave/PWOrbitalBuilder.cpp) + set(FERMION_SRCS ${FERMION_SRCS} PlaneWave/PWBasis.cpp PlaneWave/PWParameterSet.cpp PlaneWave/PWOrbitalSetBuilder.cpp) if(QMC_COMPLEX) set(FERMION_SRCS ${FERMION_SRCS} PlaneWave/PWOrbitalSet.cpp) else() diff --git a/src/QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.cpp b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp similarity index 76% rename from src/QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.cpp rename to src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp index bb932a00d1..e64f578950 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.cpp +++ b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp @@ -16,38 +16,23 @@ /** @file * @brief Definition of a builder class for PWOrbitalSet */ -#include "PWOrbitalBuilder.h" +#include "PWOrbitalSetBuilder.h" #include "QMCWaveFunctions/PlaneWave/PWParameterSet.h" -#include "QMCWaveFunctions/Fermion/DiracDeterminant.h" -#include "QMCWaveFunctions/Fermion/SlaterDet.h" #include "OhmmsData/ParameterSet.h" #include "OhmmsData/AttributeSet.h" #include "Message/Communicate.h" namespace qmcplusplus { -PWOrbitalBuilder::PWOrbitalBuilder(Communicate* comm, ParticleSet& els, const PSetMap& psets) - : WaveFunctionComponentBuilder(comm, els), ptclPool(psets), myParam{std::make_unique(comm)}, hfile{comm} {} - -PWOrbitalBuilder::~PWOrbitalBuilder() = default; - -//All data parsing is handled here, outside storage classes. -std::unique_ptr PWOrbitalBuilder::buildComponent(xmlNodePtr cur) -{ - std::unique_ptr slater_det; - //save the parent - rootNode = cur; +PWOrbitalSetBuilder::PWOrbitalSetBuilder(const ParticleSet& p, Communicate* comm, xmlNodePtr cur) + : SPOSetBuilder("Planewave", comm), targetPtcl(p), rootNode(cur), myParam{std::make_unique(comm)}, hfile{comm} { // //Get wavefunction data and parameters from XML and HDF5 // - - //close it if open - hfile.close(); + //catch parameters + myParam->put(cur); //check the current href bool success = getH5(cur, "href"); - //no file, check the root - if (!success) - success = getH5(rootNode, "href"); //Move through the XML tree and read basis information cur = cur->children; while (cur != nullptr) @@ -66,75 +51,26 @@ std::unique_ptr PWOrbitalBuilder::buildComponent(xmlNodeP hfile.close(); success = getH5(cur, "hdata"); } - else if (cname == sd_tag) - { - if (!success) - success = getH5(cur, "href"); - if (!success) - { - APP_ABORT(" Cannot create a SlaterDet due to missing h5 file\n"); - OHMMS::Controller->abort(); - } - createPWBasis(cur); - slater_det = putSlaterDet(cur); - } cur = cur->next; } - hfile.close(); - return slater_det; + + //create PW Basis + createPWBasis(cur); } -std::unique_ptr PWOrbitalBuilder::putSlaterDet(xmlNodePtr cur) +PWOrbitalSetBuilder::~PWOrbitalSetBuilder() = default; + +std::unique_ptr PWOrbitalSetBuilder::createSPOSetFromXML(xmlNodePtr cur) { - //catch parameters - myParam->put(cur); - std::vector> dets; int spin_group = 0; - cur = cur->children; - while (cur != NULL) - { - std::string cname((const char*)(cur->name)); - //Which determinant? - if (cname == "determinant") - { - std::string id("updet"); - std::string ref("0"); - OhmmsAttributeSet aAttrib; - aAttrib.add(id, "id"); - aAttrib.add(ref, "ref"); - aAttrib.put(cur); - if (ref == "0") - ref = id; - const int firstIndex = targetPtcl.first(spin_group); - const int lastIndex = targetPtcl.last(spin_group); - std::map::iterator lit(spomap.find(ref)); - //int spin_group=0; - if (lit == spomap.end()) - { - app_log() << " Create a PWOrbitalSet" << std::endl; - std::unique_ptr psi(createPW(cur, spin_group)); - spomap[ref] = psi.get(); - dets.push_back(std::make_unique>(std::move(psi), firstIndex, lastIndex)); - } - else - { - app_log() << " Reuse a PWOrbitalSet" << std::endl; - std::unique_ptr psi((*lit).second->makeClone()); - dets.push_back(std::make_unique>(std::move(psi), firstIndex, lastIndex)); - } - app_log() << " spin=" << spin_group << " id=" << id << " ref=" << ref << std::endl; - spin_group++; - } - cur = cur->next; - } - - if (spin_group) - return std::make_unique(targetPtcl, std::move(dets)); - ; - - myComm->barrier_and_abort(" Failed to create a SlaterDet at PWOrbitalBuilder::putSlaterDet "); - return nullptr; + std::string spo_object_name; + OhmmsAttributeSet aAttrib; + aAttrib.add(spin_group, "spindataset"); + aAttrib.add(spo_object_name, "name"); + aAttrib.add(spo_object_name, "id"); + aAttrib.put(cur); + return createPW(cur, spo_object_name, spin_group); } /** The read routine - get data from XML and H5. Process it and build orbitals. @@ -146,7 +82,7 @@ std::unique_ptr PWOrbitalBuilder::putSlaterDet(xmlNodePtr * -- maximum_ecut * - basis */ -bool PWOrbitalBuilder::createPWBasis(xmlNodePtr cur) +bool PWOrbitalSetBuilder::createPWBasis(xmlNodePtr cur) { //recycle int and double reader int idata; @@ -193,7 +129,7 @@ bool PWOrbitalBuilder::createPWBasis(xmlNodePtr cur) return true; } -SPOSet* PWOrbitalBuilder::createPW(xmlNodePtr cur, int spinIndex) +std::unique_ptr PWOrbitalSetBuilder::createPW(xmlNodePtr cur, const std::string& objname, int spinIndex) { int nb = targetPtcl.last(spinIndex) - targetPtcl.first(spinIndex); std::vector occBand(nb); @@ -216,7 +152,6 @@ SPOSet* PWOrbitalBuilder::createPW(xmlNodePtr cur, int spinIndex) std::string occMode("ground"); int bandoffset(1); OhmmsAttributeSet aAttrib; - aAttrib.add(spinIndex, "spindataset"); aAttrib.add(occMode, "mode"); aAttrib.add(bandoffset, "offset"); /* reserved for index offset */ aAttrib.put(cur); @@ -252,7 +187,7 @@ SPOSet* PWOrbitalBuilder::createPW(xmlNodePtr cur, int spinIndex) hfile.push("electrons", false); hfile.push("kpoint_0", false); //create a single-particle orbital set - SPOSetType* psi = new SPOSetType(getXMLAttributeValue(cur, "name")); + auto psi = std::make_unique(objname); if (transform2grid) { nb = myParam->numBands; @@ -314,7 +249,7 @@ SPOSet* PWOrbitalBuilder::createPW(xmlNodePtr cur, int spinIndex) } #if defined(QMC_COMPLEX) -void PWOrbitalBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, PWOrbitalSet& pwFunc) +void PWOrbitalSetBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, PWOrbitalSet& pwFunc) { std::ostringstream splineTag; splineTag << "eigenstates_" << nG[0] << "_" << nG[1] << "_" << nG[2]; @@ -380,6 +315,8 @@ void PWOrbitalBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, for (int ib = 0; ib < nb; ib++) inData.push_back(std::make_unique(nG[0], nG[1], nG[2])); PosType tAngle = targetPtcl.getLattice().k_cart(TwistAngle); + ParticleSet ptemp(targetPtcl.getSimulationCell()); + ptemp.create({1}); PWOrbitalSet::ValueVector phi(nb); for (int ig = 0; ig < nG[0]; ig++) { @@ -389,9 +326,9 @@ void PWOrbitalBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, RealType y = jg * dy; for (int kg = 0; kg < nG[2]; kg++) { - targetPtcl.R[0] = lattice.toCart(PosType(x, y, kg * dz)); - pwFunc.evaluateValue(targetPtcl, 0, phi); - RealType x(dot(targetPtcl.R[0], tAngle)); + ptemp.R[0] = lattice.toCart(PosType(x, y, kg * dz)); + pwFunc.evaluateValue(ptemp, 0, phi); + RealType x(dot(ptemp.R[0], tAngle)); ValueType phase(std::cos(x), -std::sin(x)); for (int ib = 0; ib < nb; ib++) (*inData[ib])(ig, jg, kg) = phase * phi[ib]; @@ -419,7 +356,7 @@ void PWOrbitalBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, } #endif -bool PWOrbitalBuilder::getH5(xmlNodePtr cur, const char* aname) +bool PWOrbitalSetBuilder::getH5(xmlNodePtr cur, const char* aname) { const std::string a(getXMLAttributeValue(cur, aname)); if (a.empty()) diff --git a/src/QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.h b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h similarity index 68% rename from src/QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.h rename to src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h index 825119706c..6b093d0411 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.h +++ b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h @@ -2,9 +2,10 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. +// Copyright (c) 2023 QMCPACK developers. // -// File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign +// File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory +// Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign // // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign @@ -15,15 +16,17 @@ * @brief Declaration of a builder class for PWOrbitalSet * */ -#ifndef QMCPLUSPLUS_PLANEWAVE_ORBITALBUILD_V0_H -#define QMCPLUSPLUS_PLANEWAVE_ORBITALBUILD_V0_H -#include "QMCWaveFunctions/WaveFunctionComponentBuilder.h" +#ifndef QMCPLUSPLUS_PWORBITAL_BUILDER_H +#define QMCPLUSPLUS_PWORBITAL_BUILDER_H + +#include "SPOSetBuilder.h" #include "hdf/hdf_archive.h" #if defined(QMC_COMPLEX) #include "QMCWaveFunctions/PlaneWave/PWOrbitalSet.h" #else #include "QMCWaveFunctions/PlaneWave/PWRealOrbitalSet.h" #endif + namespace qmcplusplus { struct PWParameterSet; @@ -31,7 +34,7 @@ class SlaterDet; /** OrbitalBuilder for Slater determinants in PW basis */ -class PWOrbitalBuilder : public WaveFunctionComponentBuilder +class PWOrbitalSetBuilder : public SPOSetBuilder { private: #if defined(QMC_COMPLEX) @@ -40,8 +43,8 @@ class PWOrbitalBuilder : public WaveFunctionComponentBuilder using SPOSetType = PWRealOrbitalSet; #endif - std::map spomap; - const PSetMap& ptclPool; + /// target particle set + const ParticleSet& targetPtcl; ///xml node for determinantset xmlNodePtr rootNode{nullptr}; ///input twist angle @@ -54,17 +57,16 @@ class PWOrbitalBuilder : public WaveFunctionComponentBuilder hdf_archive hfile; public: ///constructor - PWOrbitalBuilder(Communicate* comm, ParticleSet& els, const PSetMap& psets); - ~PWOrbitalBuilder() override; + PWOrbitalSetBuilder(const ParticleSet& p, Communicate* comm, xmlNodePtr cur); + ~PWOrbitalSetBuilder() override; - ///implement vritual function - std::unique_ptr buildComponent(xmlNodePtr cur) override; + /// create an sposet from xml and save the resulting SPOSet + std::unique_ptr createSPOSetFromXML(xmlNodePtr cur) override; private: bool getH5(xmlNodePtr cur, const char* aname); - std::unique_ptr putSlaterDet(xmlNodePtr cur); bool createPWBasis(xmlNodePtr cur); - SPOSet* createPW(xmlNodePtr cur, int spinIndex); + std::unique_ptr createPW(xmlNodePtr cur, const std::string& objname, int spinIndex); #if defined(QMC_COMPLEX) void transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, PWOrbitalSet& pwFunc); #endif diff --git a/src/QMCWaveFunctions/SPOSetBuilderFactory.cpp b/src/QMCWaveFunctions/SPOSetBuilderFactory.cpp index c878d5120e..25932eeb45 100644 --- a/src/QMCWaveFunctions/SPOSetBuilderFactory.cpp +++ b/src/QMCWaveFunctions/SPOSetBuilderFactory.cpp @@ -17,23 +17,24 @@ #include "SPOSetBuilderFactory.h" -#include "QMCWaveFunctions/SPOSetScanner.h" -#include "QMCWaveFunctions/HarmonicOscillator/SHOSetBuilder.h" +#include "SPOSetScanner.h" +#include "HarmonicOscillator/SHOSetBuilder.h" +#include "PlaneWave/PWOrbitalSetBuilder.h" #include "ModernStringUtils.hpp" -#include "QMCWaveFunctions/ElectronGas/FreeOrbitalBuilder.h" +#include "ElectronGas/FreeOrbitalBuilder.h" #if OHMMS_DIM == 3 -#include "QMCWaveFunctions/LCAO/LCAOrbitalBuilder.h" +#include "LCAO/LCAOrbitalBuilder.h" #if defined(QMC_COMPLEX) #include "BsplineFactory/EinsplineSpinorSetBuilder.h" -#include "QMCWaveFunctions/LCAO/LCAOSpinorBuilder.h" +#include "LCAO/LCAOSpinorBuilder.h" #endif #if defined(HAVE_EINSPLINE) #include "BsplineFactory/EinsplineSetBuilder.h" #endif #endif -#include "QMCWaveFunctions/CompositeSPOSet.h" +#include "CompositeSPOSet.h" #include "Utilities/ProgressReportEngine.h" #include "Utilities/IteratorUtility.h" #include "OhmmsData/AttributeSet.h" @@ -105,6 +106,11 @@ std::unique_ptr SPOSetBuilderFactory::createSPOSetBuilder(xmlNode app_log() << "Harmonic Oscillator SPO set" << std::endl; bb = std::make_unique(targetPtcl, myComm); } + else if (type == "PWBasis" || type == "PW" || type == "pw") + { + app_log() << "Planewave basis SPO set" << std::endl; + bb = std::make_unique(targetPtcl, myComm, rootNode); + } #if OHMMS_DIM == 3 else if (type.find("spline") < type.size()) { diff --git a/src/QMCWaveFunctions/WaveFunctionFactory.cpp b/src/QMCWaveFunctions/WaveFunctionFactory.cpp index a6efb4378e..2b0a785a9c 100644 --- a/src/QMCWaveFunctions/WaveFunctionFactory.cpp +++ b/src/QMCWaveFunctions/WaveFunctionFactory.cpp @@ -24,7 +24,6 @@ #include "QMCWaveFunctions/Fermion/SlaterDetBuilder.h" #include "QMCWaveFunctions/LatticeGaussianProductBuilder.h" #include "QMCWaveFunctions/ExampleHeBuilder.h" -#include "QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.h" #if OHMMS_DIM == 3 && !defined(QMC_COMPLEX) #include "QMCWaveFunctions/AGPDeterminantBuilder.h" #endif @@ -187,10 +186,6 @@ bool WaveFunctionFactory::addFermionTerm(TrialWaveFunction& psi, SPOSetBuilderFa msg << " please use \"free\" orbitals in sposet_builder" << std::endl; throw std::runtime_error(msg.str()); } - else if (orbtype == "PWBasis" || orbtype == "PW" || orbtype == "pw") - { - detbuilder = std::make_unique(myComm, targetPtcl, ptclPool); - } else detbuilder = std::make_unique(myComm, spo_factory, targetPtcl, psi, ptclPool); psi.addComponent(detbuilder->buildComponent(cur)); From 5c1bc51d96702829e30090aa1f0f795f6c7aa416 Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Thu, 28 Sep 2023 15:47:43 -0500 Subject: [PATCH 2/4] Fix pw unit tests. --- src/QMCWaveFunctions/PlaneWave/PWBasis.cpp | 6 +- .../PlaneWave/PWOrbitalSetBuilder.cpp | 23 +++--- .../PlaneWave/PWOrbitalSetBuilder.h | 2 +- src/QMCWaveFunctions/tests/test_pw.cpp | 70 ++++++------------- 4 files changed, 34 insertions(+), 67 deletions(-) diff --git a/src/QMCWaveFunctions/PlaneWave/PWBasis.cpp b/src/QMCWaveFunctions/PlaneWave/PWBasis.cpp index fb613687f5..68ea84e3e9 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWBasis.cpp +++ b/src/QMCWaveFunctions/PlaneWave/PWBasis.cpp @@ -34,10 +34,8 @@ int PWBasis::readbasis(hdf_archive& h5basisgroup, h5basisgroup.read(gvecs, "/electrons/kpoint_0/gvectors"); NumPlaneWaves = std::max(gvecs.size(), kplusgvecs_cart.size()); if (NumPlaneWaves == 0) - { - app_error() << " PWBasis::readbasis Basis is missing. Abort " << std::endl; - abort(); //FIX_ABORT - } + throw std::runtime_error(" PWBasis::readbasis Basis is missing."); + if (kplusgvecs_cart.empty()) { kplusgvecs_cart.resize(NumPlaneWaves); diff --git a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp index e64f578950..3ea58fdb14 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp +++ b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp @@ -34,13 +34,10 @@ PWOrbitalSetBuilder::PWOrbitalSetBuilder(const ParticleSet& p, Communicate* comm //check the current href bool success = getH5(cur, "href"); //Move through the XML tree and read basis information - cur = cur->children; - while (cur != nullptr) - { - std::string cname((const char*)(cur->name)); + processChildren(cur, [&](const std::string& cname, const xmlNodePtr element) { if (cname == "basisset") { - const std::string a(getXMLAttributeValue(cur, "ecut")); + const std::string a(getXMLAttributeValue(element, "ecut")); if (!a.empty()) myParam->Ecut = std::stod(a); } @@ -49,13 +46,14 @@ PWOrbitalSetBuilder::PWOrbitalSetBuilder(const ParticleSet& p, Communicate* comm //close if (success) hfile.close(); - success = getH5(cur, "hdata"); + success = getH5(element, "hdata"); } - cur = cur->next; - } + }); + if (!success) + throw std::runtime_error("h5 cannot be open for creating PW basis!"); //create PW Basis - createPWBasis(cur); + createPWBasis(); } PWOrbitalSetBuilder::~PWOrbitalSetBuilder() = default; @@ -82,10 +80,10 @@ std::unique_ptr PWOrbitalSetBuilder::createSPOSetFromXML(xmlNodePtr cur) * -- maximum_ecut * - basis */ -bool PWOrbitalSetBuilder::createPWBasis(xmlNodePtr cur) +bool PWOrbitalSetBuilder::createPWBasis() { //recycle int and double reader - int idata; + int idata = 0; //start of parameters hfile.read(idata, "electrons/number_of_kpoints"); int nkpts = idata; @@ -110,9 +108,8 @@ bool PWOrbitalSetBuilder::createPWBasis(xmlNodePtr cur) hfile.read(TwistAngle_DP, "/electrons/kpoint_0/reduced_k"); TwistAngle = TwistAngle_DP; if (!myBasisSet) - { myBasisSet = std::make_unique(TwistAngle); - } + //Read the planewave basisset. //Note that the same data is opened here for each twist angle-avoids duplication in the //h5 file (which may become very large). diff --git a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h index 6b093d0411..96081dcdaf 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h +++ b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h @@ -65,7 +65,7 @@ class PWOrbitalSetBuilder : public SPOSetBuilder private: bool getH5(xmlNodePtr cur, const char* aname); - bool createPWBasis(xmlNodePtr cur); + bool createPWBasis(); std::unique_ptr createPW(xmlNodePtr cur, const std::string& objname, int spinIndex); #if defined(QMC_COMPLEX) void transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, PWOrbitalSet& pwFunc); diff --git a/src/QMCWaveFunctions/tests/test_pw.cpp b/src/QMCWaveFunctions/tests/test_pw.cpp index d68a5160cd..a44e8b599a 100644 --- a/src/QMCWaveFunctions/tests/test_pw.cpp +++ b/src/QMCWaveFunctions/tests/test_pw.cpp @@ -16,9 +16,7 @@ #include "OhmmsPETE/OhmmsMatrix.h" #include "Particle/ParticleSet.h" #include "Particle/ParticleSetPool.h" -#include "QMCWaveFunctions/WaveFunctionComponent.h" -#include "QMCWaveFunctions/PlaneWave/PWOrbitalBuilder.h" -#include "QMCWaveFunctions/Fermion/SlaterDet.h" +#include "PlaneWave/PWOrbitalSetBuilder.h" #include @@ -70,18 +68,12 @@ TEST_CASE("PlaneWave SPO from HDF for BCC H", "[wavefunction]") elec.update(); //BCC H - const char* particles = R"( - - - - - - - - - - - + const char* particles = R"( + + + + + )"; Libxml2Document doc; @@ -89,21 +81,14 @@ TEST_CASE("PlaneWave SPO from HDF for BCC H", "[wavefunction]") REQUIRE(okay); xmlNodePtr root = doc.getRoot(); - xmlNodePtr pw1 = xmlFirstElementChild(root); - PWOrbitalBuilder pw_builder(c, elec, ptcl.getPool()); - auto orb = pw_builder.buildComponent(pw1); - SlaterDet* sd = dynamic_cast(orb.get()); - REQUIRE(sd != nullptr); - REQUIRE(sd->Dets.size() == 2); - SPOSetPtr spo = sd->getPhi(0); - REQUIRE(spo != nullptr); - //SPOSet *spo = einSet.createSPOSetFromXML(ein1); - //REQUIRE(spo != nullptr); + PWOrbitalSetBuilder pw_builder(elec, c, root); + auto spo = pw_builder.createSPOSet(pw1); + REQUIRE(spo); - int orbSize = spo->getOrbitalSetSize(); + const int orbSize = spo->getOrbitalSetSize(); elec.update(); SPOSet::ValueVector orbs(orbSize); spo->evaluateValue(elec, 0, orbs); @@ -189,18 +174,12 @@ TEST_CASE("PlaneWave SPO from HDF for LiH arb", "[wavefunction]") elec.update(); //diamondC_1x1x1 - const char* particles = R"( - - - - - - - - - - - + const char* particles = R"( + + + + + )"; Libxml2Document doc; @@ -208,21 +187,14 @@ TEST_CASE("PlaneWave SPO from HDF for LiH arb", "[wavefunction]") REQUIRE(okay); xmlNodePtr root = doc.getRoot(); - xmlNodePtr pw1 = xmlFirstElementChild(root); - PWOrbitalBuilder pw_builder(c, elec, ptcl.getPool()); - auto orb = pw_builder.buildComponent(pw1); - SlaterDet* sd = dynamic_cast(orb.get()); - REQUIRE(sd != nullptr); - REQUIRE(sd->Dets.size() == 2); - SPOSetPtr spo = sd->getPhi(0); - REQUIRE(spo != nullptr); - //SPOSet *spo = einSet.createSPOSetFromXML(ein1); - //REQUIRE(spo != nullptr); + PWOrbitalSetBuilder pw_builder(elec, c, root); + auto spo = pw_builder.createSPOSet(pw1); + REQUIRE(spo); - int orbSize = spo->getOrbitalSetSize(); + const int orbSize = spo->getOrbitalSetSize(); elec.update(); SPOSet::ValueVector orbs(orbSize); spo->evaluateValue(elec, 0, orbs); From 775198053d526fdfbdf19539b97015bf02a5ebed Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Thu, 28 Sep 2023 15:52:18 -0500 Subject: [PATCH 3/4] Formatting. --- .../PlaneWave/PWOrbitalSetBuilder.cpp | 11 +++++++---- src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h | 1 + src/QMCWaveFunctions/tests/test_pw.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp index 3ea58fdb14..ab0e2dff81 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp +++ b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp @@ -25,7 +25,12 @@ namespace qmcplusplus { PWOrbitalSetBuilder::PWOrbitalSetBuilder(const ParticleSet& p, Communicate* comm, xmlNodePtr cur) - : SPOSetBuilder("Planewave", comm), targetPtcl(p), rootNode(cur), myParam{std::make_unique(comm)}, hfile{comm} { + : SPOSetBuilder("Planewave", comm), + targetPtcl(p), + rootNode(cur), + myParam{std::make_unique(comm)}, + hfile{comm} +{ // //Get wavefunction data and parameters from XML and HDF5 // @@ -60,7 +65,6 @@ PWOrbitalSetBuilder::~PWOrbitalSetBuilder() = default; std::unique_ptr PWOrbitalSetBuilder::createSPOSetFromXML(xmlNodePtr cur) { - int spin_group = 0; std::string spo_object_name; OhmmsAttributeSet aAttrib; @@ -250,7 +254,7 @@ void PWOrbitalSetBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinInde { std::ostringstream splineTag; splineTag << "eigenstates_" << nG[0] << "_" << nG[1] << "_" << nG[2]; - herr_t status = H5Eset_auto2(H5E_DEFAULT, NULL, NULL); + herr_t status = H5Eset_auto2(H5E_DEFAULT, NULL, NULL); std::string splineTagStr = splineTag.str(); app_log() << " splineTag " << splineTagStr << std::endl; if (!hfile.is_group(splineTagStr)) @@ -284,7 +288,6 @@ void PWOrbitalSetBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinInde { bname = myParam->getSpinName(spinIndex); hfile.push(bname, true); - } } for (int ig = 0; ig < nG[0]; ig++) { diff --git a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h index 96081dcdaf..f31de65968 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h +++ b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.h @@ -55,6 +55,7 @@ class PWOrbitalSetBuilder : public SPOSetBuilder std::unique_ptr myBasisSet; ///hdf5 handler to clean up hdf_archive hfile; + public: ///constructor PWOrbitalSetBuilder(const ParticleSet& p, Communicate* comm, xmlNodePtr cur); diff --git a/src/QMCWaveFunctions/tests/test_pw.cpp b/src/QMCWaveFunctions/tests/test_pw.cpp index a44e8b599a..af7b02e009 100644 --- a/src/QMCWaveFunctions/tests/test_pw.cpp +++ b/src/QMCWaveFunctions/tests/test_pw.cpp @@ -81,11 +81,11 @@ TEST_CASE("PlaneWave SPO from HDF for BCC H", "[wavefunction]") REQUIRE(okay); xmlNodePtr root = doc.getRoot(); - xmlNodePtr pw1 = xmlFirstElementChild(root); + xmlNodePtr pw1 = xmlFirstElementChild(root); PWOrbitalSetBuilder pw_builder(elec, c, root); - auto spo = pw_builder.createSPOSet(pw1); + auto spo = pw_builder.createSPOSet(pw1); REQUIRE(spo); const int orbSize = spo->getOrbitalSetSize(); @@ -187,11 +187,11 @@ TEST_CASE("PlaneWave SPO from HDF for LiH arb", "[wavefunction]") REQUIRE(okay); xmlNodePtr root = doc.getRoot(); - xmlNodePtr pw1 = xmlFirstElementChild(root); + xmlNodePtr pw1 = xmlFirstElementChild(root); PWOrbitalSetBuilder pw_builder(elec, c, root); - auto spo = pw_builder.createSPOSet(pw1); + auto spo = pw_builder.createSPOSet(pw1); REQUIRE(spo); const int orbSize = spo->getOrbitalSetSize(); From 439dbd086a006b7f4e65da3058b33db352f00c3f Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Thu, 28 Sep 2023 16:03:34 -0500 Subject: [PATCH 4/4] Update header --- src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp index ab0e2dff81..41ab9e4b7b 100644 --- a/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp +++ b/src/QMCWaveFunctions/PlaneWave/PWOrbitalSetBuilder.cpp @@ -2,12 +2,13 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. +// Copyright (c) 2023 QMCPACK developers. // // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign +// Ye Luo, yeluo@anl.gov, Argonne National Laboratory // // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign //////////////////////////////////////////////////////////////////////////////////////