QMCPACK
test_spo_collection_input_LCAO_xml.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2020 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "OhmmsData/Libxml2Doc.h"
16 #include "OhmmsPETE/OhmmsMatrix.h"
17 #include "Particle/ParticleSet.h"
21 
22 #include <stdio.h>
23 #include <string>
24 #include <limits>
25 
26 using std::string;
27 
28 namespace qmcplusplus
29 {
30 void test_He_sto3g_xml_input(const std::string& spo_xml_string)
31 {
33 
35  auto elec_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
36  auto ions_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
37  ParticleSet& elec(*elec_uptr);
38  ParticleSet& ions(*ions_uptr);
39 
40  elec.setName("e");
41  ptcl.addParticleSet(std::move(elec_uptr));
42  elec.create({1, 1});
43  elec.R[0] = 0.0;
44 
45  SpeciesSet& tspecies = elec.getSpeciesSet();
46  int upIdx = tspecies.addSpecies("u");
47  int downIdx = tspecies.addSpecies("d");
48  int massIdx = tspecies.addAttribute("mass");
49  tspecies(massIdx, upIdx) = 1.0;
50  tspecies(massIdx, downIdx) = 1.0;
51 
52  ions.setName("ion0");
53  ptcl.addParticleSet(std::move(ions_uptr));
54  ions.create({1});
55  ions.R[0] = 0.0;
57  int heIdx = ispecies.addSpecies("He");
58  ions.update();
59 
60  elec.addTable(ions);
61  elec.update();
62 
64  bool okay = doc.parseFromString(spo_xml_string);
65  REQUIRE(okay);
66 
67  xmlNodePtr ein_xml = doc.getRoot();
68 
69  WaveFunctionFactory wf_factory(elec, ptcl.getPool(), c);
70  RuntimeOptions runtime_options;
71  auto twf_ptr = wf_factory.buildTWF(ein_xml, runtime_options);
72 
73  std::unique_ptr<SPOSet> sposet(twf_ptr->getSPOSet("spo").makeClone());
74 
75  SPOSet::ValueVector values;
76  SPOSet::GradVector dpsi;
77  SPOSet::ValueVector d2psi;
78  values.resize(1);
79  dpsi.resize(1);
80  d2psi.resize(1);
81 
82  // Call makeMove to compute the distances
83  ParticleSet::SingleParticlePos newpos(0.0001, 0.0, 0.0);
84  elec.makeMove(0, newpos);
85 
86  sposet->evaluateValue(elec, 0, values);
87 
88  // Generated from gen_mo.py for position [0.0001, 0.0, 0.0]
89  CHECK(values[0] == ValueApprox(0.9996037001));
90 
91  sposet->evaluateVGL(elec, 0, values, dpsi, d2psi);
92 
93  // Generated from gen_mo.py for position [0.0001, 0.0, 0.0]
94  CHECK(values[0] == ValueApprox(0.9996037001));
95  CHECK(dpsi[0][0] == ValueApprox(-0.0006678035459));
96  CHECK(dpsi[0][1] == ValueApprox(0.0));
97  CHECK(dpsi[0][2] == ValueApprox(0.0));
98  CHECK(d2psi[0] == ValueApprox(-20.03410564));
99 
100 
101  ParticleSet::SingleParticlePos disp(1.0, 0.0, 0.0);
102  elec.makeMove(0, disp);
103 
104  sposet->evaluateVGL(elec, 0, values, dpsi, d2psi);
105  // Generated from gen_mo.py for position [1.0, 0.0, 0.0]
106  CHECK(values[0] == ValueApprox(0.2315567641));
107  CHECK(dpsi[0][0] == ValueApprox(-0.3805431885));
108  CHECK(dpsi[0][1] == ValueApprox(0.0));
109  CHECK(dpsi[0][2] == ValueApprox(0.0));
110  CHECK(d2psi[0] == ValueApprox(-0.2618497452));
111 }
112 
113 TEST_CASE("SPO input spline from xml He_sto3g", "[wavefunction]")
114 {
115  // capture 3 spo input styles, the 2nd and 3rd ones will be deprecated and removed eventually.
116  // the first case should be simplified using SPOSetBuilderFactory instead of WaveFunctionFactory
117  app_log() << "-------------------------------------------------------------" << std::endl;
118  app_log() << "He_sto3g input style 1 using sposet_collection" << std::endl;
119  app_log() << "-------------------------------------------------------------" << std::endl;
120  const char* spo_xml_string1 = R"(<wavefunction name="psi0" target="e">
121  <sposet_collection type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no">
122  <basisset name="LCAOBSet">
123  <atomicBasisSet name="Gaussian" angular="cartesian" type="Gaussian" elementType="He" normalized="no">
124  <grid type="log" ri="1.e-6" rf="1.e2" npts="1001"/>
125  <basisGroup rid="He00" n="0" l="0" type="Gaussian">
126  <radfunc exponent="6.362421400000e+00" contraction="1.543289672950e-01"/>
127  <radfunc exponent="1.158923000000e+00" contraction="5.353281422820e-01"/>
128  <radfunc exponent="3.136498000000e-01" contraction="4.446345421850e-01"/>
129  </basisGroup>
130  </atomicBasisSet>
131  </basisset>
132  <sposet name="spo" size="1">
133  <occupation mode="ground"/>
134  <coefficient size="1" id="updetC">
135  1.00000000000000e+00
136  </coefficient>
137  </sposet>
138  </sposet_collection>
139  <determinantset>
140  <slaterdeterminant>
141  <determinant name="det_up" sposet="spo"/>
142  <determinant name="det_dn" sposet="spo"/>
143  </slaterdeterminant>
144  </determinantset>
145 </wavefunction>
146 )";
147  test_He_sto3g_xml_input(spo_xml_string1);
148 
149  app_log() << "-------------------------------------------------------------" << std::endl;
150  app_log() << "He_sto3g input style 1 using sposet_collection updated" << std::endl;
151  app_log() << "-------------------------------------------------------------" << std::endl;
152  const char* spo_xml_string1_updated = R"(<wavefunction name="psi0" target="e">
153  <sposet_collection type="MolecularOrbital" name="LCAOBSet" source="ion0" cuspCorrection="no">
154  <basisset name="LCAOBSet" transform="yes">
155  <atomicBasisSet name="Gaussian" angular="cartesian" type="Gaussian" elementType="He" normalized="no">
156  <grid type="log" ri="1.e-6" rf="1.e2" npts="1001"/>
157  <basisGroup rid="He00" n="0" l="0" type="Gaussian">
158  <radfunc exponent="6.362421400000e+00" contraction="1.543289672950e-01"/>
159  <radfunc exponent="1.158923000000e+00" contraction="5.353281422820e-01"/>
160  <radfunc exponent="3.136498000000e-01" contraction="4.446345421850e-01"/>
161  </basisGroup>
162  </atomicBasisSet>
163  </basisset>
164  <sposet name="spo" basisset="LCAOBSet" size="1">
165  <occupation mode="ground"/>
166  <coefficient size="1" id="updetC">
167  1.00000000000000e+00
168  </coefficient>
169  </sposet>
170  </sposet_collection>
171  <determinantset>
172  <slaterdeterminant>
173  <determinant name="det_up" sposet="spo"/>
174  <determinant name="det_dn" sposet="spo"/>
175  </slaterdeterminant>
176  </determinantset>
177 </wavefunction>
178 )";
179  test_He_sto3g_xml_input(spo_xml_string1_updated);
180 
181  app_log() << "-------------------------------------------------------------" << std::endl;
182  app_log() << "He_sto3g input style 2 sposet inside determinantset" << std::endl;
183  app_log() << "-------------------------------------------------------------" << std::endl;
184  const char* spo_xml_string2 = R"(<wavefunction name="psi0" target="e">
185  <determinantset type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no">
186  <basisset name="LCAOBSet">
187  <grid type="log" ri="1.e-6" rf="1.e2" npts="1001"/>
188  <atomicBasisSet name="Gaussian" angular="cartesian" type="Gaussian" elementType="He" normalized="no">
189  <basisGroup rid="He00" n="0" l="0" type="Gaussian">
190  <radfunc exponent="6.362421400000e+00" contraction="1.543289672950e-01"/>
191  <radfunc exponent="1.158923000000e+00" contraction="5.353281422820e-01"/>
192  <radfunc exponent="3.136498000000e-01" contraction="4.446345421850e-01"/>
193  </basisGroup>
194  </atomicBasisSet>
195  </basisset>
196  <sposet name="spo" size="1">
197  <occupation mode="ground"/>
198  <coefficient size="1" id="updetC">
199  1.00000000000000e+00
200  </coefficient>
201  </sposet>
202  <sposet name="spo-down" size="1">
203  <occupation mode="ground"/>
204  <coefficient size="1" id="downdetC">
205  1.00000000000000e+00
206  </coefficient>
207  </sposet>
208  <slaterdeterminant>
209  <determinant name="det_up" sposet="spo"/>
210  <determinant name="det_dn" sposet="spo-down"/>
211  </slaterdeterminant>
212  </determinantset>
213 </wavefunction>
214 )";
215  test_He_sto3g_xml_input(spo_xml_string2);
216 
217  app_log() << "-------------------------------------------------------------" << std::endl;
218  app_log() << "He_sto3g input style 3 sposet inside determinantset" << std::endl;
219  app_log() << "-------------------------------------------------------------" << std::endl;
220  const char* spo_xml_string3 = R"(<wavefunction name="psi0" target="e">
221  <determinantset type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no">
222  <basisset name="LCAOBSet">
223  <atomicBasisSet name="Gaussian" angular="cartesian" type="Gaussian" elementType="He" normalized="no">
224  <grid type="log" ri="1.e-6" rf="1.e2" npts="1001"/>
225  <basisGroup rid="He00" n="0" l="0" type="Gaussian">
226  <radfunc exponent="6.362421400000e+00" contraction="1.543289672950e-01"/>
227  <radfunc exponent="1.158923000000e+00" contraction="5.353281422820e-01"/>
228  <radfunc exponent="3.136498000000e-01" contraction="4.446345421850e-01"/>
229  </basisGroup>
230  </atomicBasisSet>
231  </basisset>
232  <slaterdeterminant>
233  <determinant name="spo" size="1">
234  <occupation mode="ground"/>
235  <coefficient size="1" id="updetC">
236  1.00000000000000e+00
237  </coefficient>
238  </determinant>
239  <determinant name="spo-down" size="1">
240  <occupation mode="ground"/>
241  <coefficient size="1" id="downdetC">
242  1.00000000000000e+00
243  </coefficient>
244  </determinant>
245  </slaterdeterminant>
246  </determinantset>
247 </wavefunction>
248 )";
249  test_He_sto3g_xml_input(spo_xml_string3);
250 }
251 } // namespace qmcplusplus
void setName(const std::string &aname)
Definition: ParticleSet.h:237
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
class that handles xmlDoc
Definition: Libxml2Doc.h:76
int addSpecies(const std::string &aname)
When a name species does not exist, add a new species.
Definition: SpeciesSet.cpp:33
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::ostream & app_log()
Definition: OutputManager.h:65
TEST_CASE("complex_helper", "[type_traits]")
void addParticleSet(std::unique_ptr< ParticleSet > &&p)
add a ParticleSet* to the pool with its ownership transferred ParticleSet built outside the ParticleS...
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
void test_He_sto3g_xml_input(const std::string &spo_xml_string)
void update(bool skipSK=false)
update the internal data
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
int addAttribute(const std::string &aname)
for a new attribute, allocate the data, !More often used to get the index of a species ...
Definition: SpeciesSet.cpp:45
Wrapping information on parallelism.
Definition: Communicate.h:68
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
REQUIRE(std::filesystem::exists(filename))
Manage a collection of ParticleSet objects.
Factory class to build a many-body wavefunction.
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
ParticlePos R
Position.
Definition: ParticleSet.h:79
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void create(const std::vector< int > &agroup)
create grouped particles
OrbitalSetTraits< ValueType >::GradVector GradVector
Definition: SPOSet.h:51
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Declaration of a WaveFunctionFactory.
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
const PoolType & getPool() const
get the Pool object
const auto & getSimulationCell() const
get simulation cell
Declaration of ParticleSetPool.