Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 51 additions & 37 deletions src/QMCWaveFunctions/Fermion/SlaterDetBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Utilities/ProgressReportEngine.h"
#include "OhmmsData/AttributeSet.h"
#include "PlatformSelector.hpp"
#include <Message/UniformCommunicateError.h>

#include "QMCWaveFunctions/Fermion/SlaterDet.h"
#include "QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h"
Expand Down Expand Up @@ -62,8 +63,7 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
{
ReportEngine PRE(ClassName, "put(xmlNodePtr)");
///save the current node
xmlNodePtr curRoot = cur;
bool multiDet = false;
bool multiDet = false;
std::string msd_algorithm;

std::unique_ptr<WaveFunctionComponent> built_singledet_or_multidets;
Expand All @@ -75,23 +75,20 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
app_warning() << "!!!!!!! Deprecated input style: creating SPO set inside determinantset. Support for this usage "
"will soon be removed. SPO sets should be built outside using sposet_collection."
<< std::endl;
legacy_input_sposet_builder = sposet_builder_factory_.createSPOSetBuilder(curRoot);
legacy_input_sposet_builder = sposet_builder_factory_.createSPOSetBuilder(cur);
}

//check the basis set and backflow transformation
//check the basisset and backflow transformation
std::unique_ptr<BackflowTransformation> BFTrans;
cur = curRoot->children;
while (cur != NULL) //check the basis set
{
std::string cname(getNodeName(cur));
processChildren(cur, [&](const std::string& cname, const xmlNodePtr element) {
if (cname == sposet_tag)
{
app_warning() << "!!!!!!! Deprecated input style: creating SPO set inside determinantset. Support for this usage "
"will soon be removed. SPO sets should be built outside using sposet_collection."
<< std::endl;
app_log() << "Creating SPOSet in SlaterDetBuilder::put(xmlNodePtr cur).\n";
assert(legacy_input_sposet_builder);
sposet_builder_factory_.addSPOSet(legacy_input_sposet_builder->createSPOSet(cur));
sposet_builder_factory_.addSPOSet(legacy_input_sposet_builder->createSPOSet(element));
}
else if (cname == backflow_tag)
{
Expand All @@ -104,15 +101,40 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
"Please collect all transformations into a single block.");

BackflowBuilder bfbuilder(targetPtcl, ptclPool);
BFTrans = bfbuilder.buildBackflowTransformation(cur);
BFTrans = bfbuilder.buildBackflowTransformation(element);
}
cur = cur->next;
}
});

cur = curRoot->children;
while (cur != NULL)
if (sposet_builder_factory_.empty())
{
std::string cname(getNodeName(cur));
processChildren(cur, [&](const std::string& cname, const xmlNodePtr element) {
if (cname == sd_tag)
{
// look for sposet inside slaterdeterminant and nested determinant tag
processChildren(element, [&](const std::string& cname, const xmlNodePtr element) {
if (cname == det_tag)
{
app_warning() << "!!!!!!! Deprecated input style: creating SPO set inside slaterdeterminant and nested "
"determinant tags. Support for this usage "
"will soon be removed. SPO sets should be built outside using sposet_collection."
<< std::endl;
auto sposet_name = getXMLAttributeValue(element, "sposet");
if (sposet_name.empty())
sposet_name = getXMLAttributeValue(element, "id");
if (sposet_name.empty())
sposet_name = "0";

app_log() << " Create a new SPOSet " << sposet_name << std::endl;
assert(legacy_input_sposet_builder);
auto sposet = legacy_input_sposet_builder->createSPOSet(element);
sposet_builder_factory_.addSPOSet(std::move(sposet));
}
});
}
});
}

processChildren(cur, [&](const std::string& cname, const xmlNodePtr element) {
if (cname == sd_tag)
{
app_summary() << std::endl;
Expand All @@ -124,23 +146,20 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP

std::vector<std::unique_ptr<DiracDeterminantBase>> dirac_dets;
size_t spin_group = 0;
xmlNodePtr tcur = cur->children;
while (tcur != NULL)
{
std::string tname(getNodeName(tcur));
if (tname == det_tag || tname == rn_tag)
processChildren(element, [&](const std::string& cname, const xmlNodePtr element) {
if (cname == det_tag || cname == rn_tag)
{
if (spin_group >= targetPtcl.groups())
{
std::ostringstream err_msg;
err_msg << "Need only " << targetPtcl.groups() << " determinant input elements. Found more." << std::endl;
throw std::runtime_error(err_msg.str());
}
dirac_dets.push_back(putDeterminant(tcur, spin_group, legacy_input_sposet_builder, BFTrans));
dirac_dets.push_back(putDeterminant(element, spin_group, BFTrans));
spin_group++;
}
tcur = tcur->next;
}
});

if (spin_group < targetPtcl.groups())
{
std::ostringstream err_msg;
Expand Down Expand Up @@ -186,7 +205,7 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
}
spoAttrib.add(fastAlg, "Fast", {"", "yes", "no"}, TagStatus::DELETED);
spoAttrib.add(msd_algorithm, "algorithm", {"precomputed_table_method", "table_method"});
spoAttrib.put(cur);
spoAttrib.put(element);

//new format
std::vector<std::unique_ptr<SPOSet>> spo_clones;
Expand All @@ -213,7 +232,7 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
else
app_summary() << " Using the table method without precomputing. Slower." << std::endl;

auto msd_fast = createMSDFast(cur, targetPtcl, std::move(spo_clones), targetPtcl.isSpinor(),
auto msd_fast = createMSDFast(element, targetPtcl, std::move(spo_clones), targetPtcl.isSpinor(),
msd_algorithm == "precomputed_table_method");

// The primary purpose of this function is to create all the optimizable orbital rotation parameters.
Expand All @@ -222,8 +241,7 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
msd_fast->buildOptVariables();
built_singledet_or_multidets = std::move(msd_fast);
}
cur = cur->next;
}
});

if (built_singledet_or_multidets)
return built_singledet_or_multidets;
Expand All @@ -248,7 +266,6 @@ magnetic system
std::unique_ptr<DiracDeterminantBase> SlaterDetBuilder::putDeterminant(
xmlNodePtr cur,
int spin_group,
const std::unique_ptr<SPOSetBuilder>& legacy_input_sposet_builder,
const std::unique_ptr<BackflowTransformation>& BFTrans)
{
ReportEngine PRE(ClassName, "putDeterminant(xmlNodePtr,int)");
Expand Down Expand Up @@ -331,16 +348,13 @@ std::unique_ptr<DiracDeterminantBase> SlaterDetBuilder::putDeterminant(

const SPOSet* psi = sposet_builder_factory_.getSPOSet(sposet_name);
//check if the named sposet exists
if (psi == 0)
if (psi == nullptr)
{
app_warning() << "!!!!!!! Deprecated input style: creating SPO set inside determinantset. Support for this usage "
"will soon be removed. SPO sets should be built outside using sposet_collection."
<< std::endl;
app_log() << " Create a new SPO set " << sposet_name << std::endl;
assert(legacy_input_sposet_builder);
auto sposet = legacy_input_sposet_builder->createSPOSet(cur);
psi = sposet.get();
sposet_builder_factory_.addSPOSet(std::move(sposet));
std::ostringstream err_msg;
err_msg << "A sposet named \"" << sposet_name
<< "\" cannot be found for constructing a Slater determinant! Please check the xml input file!"
<< std::endl;
throw UniformCommunicateError(err_msg.str());
}

std::unique_ptr<SPOSet> psi_clone(psi->makeClone());
Expand Down
2 changes: 0 additions & 2 deletions src/QMCWaveFunctions/Fermion/SlaterDetBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ class SlaterDetBuilder : public WaveFunctionComponentBuilder
/** process a determinant element
* @param cur xml node
* @param spin_group the spin group of the created determinant
* @return legacy_input_sposet_builder an sposet builder to handle legacy input
* @return BFTrans backflow transformations
*/
std::unique_ptr<DiracDeterminantBase> putDeterminant(
xmlNodePtr cur,
int spin_group,
const std::unique_ptr<SPOSetBuilder>& legacy_input_sposet_builder,
const std::unique_ptr<BackflowTransformation>& BFTrans);

std::unique_ptr<MultiSlaterDetTableMethod> createMSDFast(xmlNodePtr cur,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ TEST_CASE("SPO input spline from xml He_sto3g", "[wavefunction]")
</atomicBasisSet>
</basisset>
<slaterdeterminant>
<determinant name="spo" size="1">
<determinant id="spo" size="1">
<occupation mode="ground"/>
<coefficient size="1" id="updetC">
1.00000000000000e+00
</coefficient>
</determinant>
<determinant name="spo-down" size="1">
<determinant id="downdet" size="1">
<occupation mode="ground"/>
<coefficient size="1" id="downdetC">
1.00000000000000e+00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ TEST_CASE("SPO input spline from HDF diamond_2x1x1", "[wavefunction]")
const char* spo_xml_string3 = R"(<wavefunction name="psi0" target="elec">
<determinantset type="einspline" href="diamondC_2x1x1.pwscf.h5" tilematrix="2 0 0 0 1 0 0 0 1" twistnum="0" source="ion" meshfactor="1.0" precision="float">
<slaterdeterminant>
<determinant name="spo" size="4" spindataset="0"/>
<determinant id="spo" size="4" spindataset="0"/>
</slaterdeterminant>
</determinantset>
</wavefunction>
Expand Down
Loading