Skip to content

Commit 6908fdd

Browse files
authored
Merge pull request #5461 from ye-luo/adjust-input-parsing
Adjust parsing legacy input when sposets are implicitly inside determiants
2 parents ad918a3 + 90a4cd7 commit 6908fdd

File tree

4 files changed

+54
-42
lines changed

4 files changed

+54
-42
lines changed

src/QMCWaveFunctions/Fermion/SlaterDetBuilder.cpp

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Utilities/ProgressReportEngine.h"
2525
#include "OhmmsData/AttributeSet.h"
2626
#include "PlatformSelector.hpp"
27+
#include <Message/UniformCommunicateError.h>
2728

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

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

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

106103
BackflowBuilder bfbuilder(targetPtcl, ptclPool);
107-
BFTrans = bfbuilder.buildBackflowTransformation(cur);
104+
BFTrans = bfbuilder.buildBackflowTransformation(element);
108105
}
109-
cur = cur->next;
110-
}
106+
});
111107

112-
cur = curRoot->children;
113-
while (cur != NULL)
108+
if (sposet_builder_factory_.empty())
114109
{
115-
std::string cname(getNodeName(cur));
110+
processChildren(cur, [&](const std::string& cname, const xmlNodePtr element) {
111+
if (cname == sd_tag)
112+
{
113+
// look for sposet inside slaterdeterminant and nested determinant tag
114+
processChildren(element, [&](const std::string& cname, const xmlNodePtr element) {
115+
if (cname == det_tag)
116+
{
117+
app_warning() << "!!!!!!! Deprecated input style: creating SPO set inside slaterdeterminant and nested "
118+
"determinant tags. Support for this usage "
119+
"will soon be removed. SPO sets should be built outside using sposet_collection."
120+
<< std::endl;
121+
auto sposet_name = getXMLAttributeValue(element, "sposet");
122+
if (sposet_name.empty())
123+
sposet_name = getXMLAttributeValue(element, "id");
124+
if (sposet_name.empty())
125+
sposet_name = "0";
126+
127+
app_log() << " Create a new SPOSet " << sposet_name << std::endl;
128+
assert(legacy_input_sposet_builder);
129+
auto sposet = legacy_input_sposet_builder->createSPOSet(element);
130+
sposet_builder_factory_.addSPOSet(std::move(sposet));
131+
}
132+
});
133+
}
134+
});
135+
}
136+
137+
processChildren(cur, [&](const std::string& cname, const xmlNodePtr element) {
116138
if (cname == sd_tag)
117139
{
118140
app_summary() << std::endl;
@@ -124,23 +146,20 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
124146

125147
std::vector<std::unique_ptr<DiracDeterminantBase>> dirac_dets;
126148
size_t spin_group = 0;
127-
xmlNodePtr tcur = cur->children;
128-
while (tcur != NULL)
129-
{
130-
std::string tname(getNodeName(tcur));
131-
if (tname == det_tag || tname == rn_tag)
149+
processChildren(element, [&](const std::string& cname, const xmlNodePtr element) {
150+
if (cname == det_tag || cname == rn_tag)
132151
{
133152
if (spin_group >= targetPtcl.groups())
134153
{
135154
std::ostringstream err_msg;
136155
err_msg << "Need only " << targetPtcl.groups() << " determinant input elements. Found more." << std::endl;
137156
throw std::runtime_error(err_msg.str());
138157
}
139-
dirac_dets.push_back(putDeterminant(tcur, spin_group, legacy_input_sposet_builder, BFTrans));
158+
dirac_dets.push_back(putDeterminant(element, spin_group, BFTrans));
140159
spin_group++;
141160
}
142-
tcur = tcur->next;
143-
}
161+
});
162+
144163
if (spin_group < targetPtcl.groups())
145164
{
146165
std::ostringstream err_msg;
@@ -186,7 +205,7 @@ std::unique_ptr<WaveFunctionComponent> SlaterDetBuilder::buildComponent(xmlNodeP
186205
}
187206
spoAttrib.add(fastAlg, "Fast", {"", "yes", "no"}, TagStatus::DELETED);
188207
spoAttrib.add(msd_algorithm, "algorithm", {"precomputed_table_method", "table_method"});
189-
spoAttrib.put(cur);
208+
spoAttrib.put(element);
190209

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

216-
auto msd_fast = createMSDFast(cur, targetPtcl, std::move(spo_clones), targetPtcl.isSpinor(),
235+
auto msd_fast = createMSDFast(element, targetPtcl, std::move(spo_clones), targetPtcl.isSpinor(),
217236
msd_algorithm == "precomputed_table_method");
218237

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

228246
if (built_singledet_or_multidets)
229247
return built_singledet_or_multidets;
@@ -248,7 +266,6 @@ magnetic system
248266
std::unique_ptr<DiracDeterminantBase> SlaterDetBuilder::putDeterminant(
249267
xmlNodePtr cur,
250268
int spin_group,
251-
const std::unique_ptr<SPOSetBuilder>& legacy_input_sposet_builder,
252269
const std::unique_ptr<BackflowTransformation>& BFTrans)
253270
{
254271
ReportEngine PRE(ClassName, "putDeterminant(xmlNodePtr,int)");
@@ -331,16 +348,13 @@ std::unique_ptr<DiracDeterminantBase> SlaterDetBuilder::putDeterminant(
331348

332349
const SPOSet* psi = sposet_builder_factory_.getSPOSet(sposet_name);
333350
//check if the named sposet exists
334-
if (psi == 0)
351+
if (psi == nullptr)
335352
{
336-
app_warning() << "!!!!!!! Deprecated input style: creating SPO set inside determinantset. Support for this usage "
337-
"will soon be removed. SPO sets should be built outside using sposet_collection."
338-
<< std::endl;
339-
app_log() << " Create a new SPO set " << sposet_name << std::endl;
340-
assert(legacy_input_sposet_builder);
341-
auto sposet = legacy_input_sposet_builder->createSPOSet(cur);
342-
psi = sposet.get();
343-
sposet_builder_factory_.addSPOSet(std::move(sposet));
353+
std::ostringstream err_msg;
354+
err_msg << "A sposet named \"" << sposet_name
355+
<< "\" cannot be found for constructing a Slater determinant! Please check the xml input file!"
356+
<< std::endl;
357+
throw UniformCommunicateError(err_msg.str());
344358
}
345359

346360
std::unique_ptr<SPOSet> psi_clone(psi->makeClone());

src/QMCWaveFunctions/Fermion/SlaterDetBuilder.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ class SlaterDetBuilder : public WaveFunctionComponentBuilder
7070
/** process a determinant element
7171
* @param cur xml node
7272
* @param spin_group the spin group of the created determinant
73-
* @return legacy_input_sposet_builder an sposet builder to handle legacy input
7473
* @return BFTrans backflow transformations
7574
*/
7675
std::unique_ptr<DiracDeterminantBase> putDeterminant(
7776
xmlNodePtr cur,
7877
int spin_group,
79-
const std::unique_ptr<SPOSetBuilder>& legacy_input_sposet_builder,
8078
const std::unique_ptr<BackflowTransformation>& BFTrans);
8179

8280
std::unique_ptr<MultiSlaterDetTableMethod> createMSDFast(xmlNodePtr cur,

src/QMCWaveFunctions/tests/test_spo_collection_input_LCAO_xml.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ TEST_CASE("SPO input spline from xml He_sto3g", "[wavefunction]")
230230
</atomicBasisSet>
231231
</basisset>
232232
<slaterdeterminant>
233-
<determinant name="spo" size="1">
233+
<determinant id="spo" size="1">
234234
<occupation mode="ground"/>
235235
<coefficient size="1" id="updetC">
236236
1.00000000000000e+00
237237
</coefficient>
238238
</determinant>
239-
<determinant name="spo-down" size="1">
239+
<determinant id="downdet" size="1">
240240
<occupation mode="ground"/>
241241
<coefficient size="1" id="downdetC">
242242
1.00000000000000e+00

src/QMCWaveFunctions/tests/test_spo_collection_input_spline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ TEST_CASE("SPO input spline from HDF diamond_2x1x1", "[wavefunction]")
147147
const char* spo_xml_string3 = R"(<wavefunction name="psi0" target="elec">
148148
<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">
149149
<slaterdeterminant>
150-
<determinant name="spo" size="4" spindataset="0"/>
150+
<determinant id="spo" size="4" spindataset="0"/>
151151
</slaterdeterminant>
152152
</determinantset>
153153
</wavefunction>

0 commit comments

Comments
 (0)