QMCPACK
test_spo_collection_input_MSD_LCAO_h5.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"
19 #include "WaveFunctionFactory.h"
20 #include "LCAO/LCAOrbitalSet.h"
22 
23 #include <stdio.h>
24 #include <string>
25 #include <limits>
26 
27 using std::string;
28 
29 namespace qmcplusplus
30 {
31 void test_LiH_msd_xml_input(const std::string& spo_xml_string,
32  const std::string& check_sponame,
33  int check_spo_size,
34  int check_basisset_size)
35 {
37 
39  auto ions_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
40  auto elec_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
41  ParticleSet& ions_(*ions_uptr);
42  ParticleSet& elec_(*elec_uptr);
43 
44  ions_.setName("ion0");
45  ptcl.addParticleSet(std::move(ions_uptr));
46  ions_.create({1, 1});
47  ions_.R[0] = {0.0, 0.0, 0.0};
48  ions_.R[1] = {0.0, 0.0, 3.0139239693};
49  SpeciesSet& ispecies = ions_.getSpeciesSet();
50  int LiIdx = ispecies.addSpecies("Li");
51  int HIdx = ispecies.addSpecies("H");
52 
53  elec_.setName("elec");
54  ptcl.addParticleSet(std::move(elec_uptr));
55  elec_.create({2, 2});
56  elec_.R[0] = {0.5, 0.5, 0.5};
57  elec_.R[1] = {0.1, 0.1, 1.1};
58  elec_.R[2] = {-0.5, -0.5, -0.5};
59  elec_.R[3] = {-0.1, -0.1, 1.5};
60 
61  SpeciesSet& tspecies = elec_.getSpeciesSet();
62  int upIdx = tspecies.addSpecies("u");
63  int downIdx = tspecies.addSpecies("d");
64  int massIdx = tspecies.addAttribute("mass");
65  tspecies(massIdx, upIdx) = 1.0;
66  tspecies(massIdx, downIdx) = 1.0;
67 
69  bool okay = doc.parseFromString(spo_xml_string);
70  REQUIRE(okay);
71 
72  xmlNodePtr ein_xml = doc.getRoot();
73 
74  WaveFunctionFactory wf_factory(elec_, ptcl.getPool(), c);
75  RuntimeOptions runtime_options;
76  auto twf_ptr = wf_factory.buildTWF(ein_xml, runtime_options);
77 
78  auto& spo = dynamic_cast<const LCAOrbitalSet&>(twf_ptr->getSPOSet(check_sponame));
79  REQUIRE(spo.getOrbitalSetSize() == check_spo_size);
80  REQUIRE(spo.getBasisSetSize() == check_basisset_size);
81 }
82 
83 TEST_CASE("SPO input spline from xml LiH_msd", "[wavefunction]")
84 {
85  // capture 3 spo input styles, the 2nd and 3rd ones will be deprecated and removed eventually.
86  // the first case should be simplified using SPOSetBuilderFactory instead of WaveFunctionFactory
87  app_log() << "-------------------------------------------------------------" << std::endl;
88  app_log() << "LiH_msd input style 1 using sposet_collection" << std::endl;
89  app_log() << "-------------------------------------------------------------" << std::endl;
90  const char* spo_xml_string1 = R"(<wavefunction name="psi0" target="e">
91  <sposet_collection type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no" href="LiH.orbs.h5">
92  <sposet basisset="LCAOBSet" name="spo-up" size="85">
93  <occupation mode="ground"/>
94  <coefficient size="85" spindataset="0"/>
95  </sposet>
96  <sposet basisset="LCAOBSet" name="spo-dn" size="85">
97  <occupation mode="ground"/>
98  <coefficient size="85" spindataset="0"/>
99  </sposet>
100  </sposet_collection>
101  <determinantset>
102  <multideterminant optimize="yes" spo_up="spo-up" spo_dn="spo-dn">
103  <detlist size="1487" type="DETS" nca="0" ncb="0" nea="2" neb="2" nstates="85" cutoff="1e-20" href="LiH.orbs.h5"/>
104  </multideterminant>
105  </determinantset>
106 </wavefunction>
107 )";
108  test_LiH_msd_xml_input(spo_xml_string1, "spo-up", 85, 105);
109 
110  app_log() << "-----------------------------------------------------------------" << std::endl;
111  app_log() << "LiH_msd input style 1 using sposet_collection with basisset added" << std::endl;
112  app_log() << "-----------------------------------------------------------------" << std::endl;
113  const char* spo_xml_string1_updated =
114  R"(<wavefunction name=" psi0 " target=" e ">
115  <sposet_collection type = "MolecularOrbital" name = "LCAOBSet" source = "ion0" cuspCorrection = "no" href =
116  "LiH.orbs.h5" > <basisset name = "LCAOBSet" key = "GTO" transform = "yes">
117  <grid type = "log" ri = "1.e-6" rf = "1.e2" npts = "1001" /></basisset>
118  <sposet basisset = "LCAOBSet" name = "spo-up" size = "85"><occupation mode = "ground" />
119  <coefficient size = "85" spindataset = "0" /></sposet>
120  <sposet basisset = "LCAOBSet" name = "spo-dn" size = "85"><occupation mode = "ground" />
121  <coefficient size = "85" spindataset = "0" /></sposet></sposet_collection><determinantset>
122  <multideterminant optimize = "yes" spo_up = "spo-up" spo_dn = "spo-dn">
123  <detlist size = "1487" type = "DETS" nca = "0" ncb = "0" nea = "2" neb = "2" nstates = "85" cutoff =
124  "1e-20" href = "LiH.orbs.h5" /></multideterminant></determinantset></wavefunction>)";
125  test_LiH_msd_xml_input(spo_xml_string1_updated, "spo-up", 85, 105);
126 
127  app_log() << "------------------------------------------------------------------------------" << std::endl;
128  app_log() << "LiH_msd input style 1 using sposet_collection with basisset added no transform" << std::endl;
129  app_log() << "------------------------------------------------------------------------------" << std::endl;
130  const char* spo_xml_string1_updated_no_transform = R"(<wavefunction name="psi0" target="e">
131  <sposet_collection type="MolecularOrbital" name="LCAOBSet" source="ion0" cuspCorrection="no" href="LiH.orbs.h5">
132  <basisset name="LCAOBSet" key="GTO" transform="no">
133  <grid type="log" ri="1.e-6" rf="1.e2" npts="1001"/>
134  </basisset>
135  <sposet basisset="LCAOBSet" name="spo-up" size="85">
136  <occupation mode="ground"/>
137  <coefficient size="85" spindataset="0"/>
138  </sposet>
139  <sposet basisset="LCAOBSet" name="spo-dn" size="85">
140  <occupation mode="ground"/>
141  <coefficient size="85" spindataset="0"/>
142  </sposet>
143  </sposet_collection>
144  <determinantset>
145  <multideterminant optimize="yes" spo_up="spo-up" spo_dn="spo-dn">
146  <detlist size="1487" type="DETS" nca="0" ncb="0" nea="2" neb="2" nstates="85" cutoff="1e-20" href="LiH.orbs.h5"/>
147  </multideterminant>
148  </determinantset>
149 </wavefunction>
150 )";
151  test_LiH_msd_xml_input(spo_xml_string1_updated_no_transform, "spo-up", 85, 105);
152 
153  app_log() << "-------------------------------------------------------------" << std::endl;
154  app_log() << "LiH_msd input style 2 using sposet_collection" << std::endl;
155  app_log() << "-------------------------------------------------------------" << std::endl;
156  const char* spo_xml_string2 = R"(<wavefunction name="psi0" target="e">
157  <sposet_collection type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no" href="LiH.orbs.h5">
158  <sposet basisset="LCAOBSet" name="spo" size="85">
159  <occupation mode="ground"/>
160  <coefficient size="85" spindataset="0"/>
161  </sposet>
162  </sposet_collection>
163  <determinantset>
164  <multideterminant optimize="yes" spo_up="spo" spo_dn="spo">
165  <detlist size="1487" type="DETS" nca="0" ncb="0" nea="2" neb="2" nstates="85" cutoff="1e-20" href="LiH.orbs.h5"/>
166  </multideterminant>
167  </determinantset>
168 </wavefunction>
169 )";
170  test_LiH_msd_xml_input(spo_xml_string2, "spo", 85, 105);
171 
172  app_log() << "-------------------------------------------------------------" << std::endl;
173  app_log() << "LiH_msd input style 3 sposet inside determinantset" << std::endl;
174  app_log() << "-------------------------------------------------------------" << std::endl;
175  const char* spo_xml_string3 = R"(<wavefunction name="psi0" target="e">
176  <determinantset type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no" href="LiH.orbs.h5">
177  <sposet basisset="LCAOBSet" name="spo-up" size="85">
178  <occupation mode="ground"/>
179  <coefficient size="85" spindataset="0"/>
180  </sposet>
181  <sposet basisset="LCAOBSet" name="spo-dn" size="85">
182  <occupation mode="ground"/> \
183  <coefficient size="85" spindataset="0"/>
184  </sposet>
185  <multideterminant optimize="yes" spo_up="spo-up" spo_dn="spo-dn">
186  <detlist size="1487" type="DETS" nca="0" ncb="0" nea="2" neb="2" nstates="85" cutoff="1e-20" href="LiH.orbs.h5"/>
187  </multideterminant>
188  </determinantset>
189 </wavefunction>
190 )";
191  test_LiH_msd_xml_input(spo_xml_string3, "spo-up", 85, 105);
192 }
193 
194 void test_LiH_msd_xml_input_with_positron(const std::string& spo_xml_string,
195  const std::string& check_sponame,
196  int check_spo_size,
197  int check_basisset_size)
198 {
200 
202  auto ions_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
203  auto elec_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
204  ParticleSet& ions_(*ions_uptr);
205  ParticleSet& elec_(*elec_uptr);
206 
207  ions_.setName("ion0");
208  ptcl.addParticleSet(std::move(ions_uptr));
209  ions_.create({1, 1});
210  ions_.R[0] = {0.0, 0.0, 0.0};
211  ions_.R[1] = {0.0, 0.0, 3.0139239693};
212  SpeciesSet& ispecies = ions_.getSpeciesSet();
213  int LiIdx = ispecies.addSpecies("Li");
214  int HIdx = ispecies.addSpecies("H");
215 
216  elec_.setName("elec");
217  ptcl.addParticleSet(std::move(elec_uptr));
218  elec_.create({2, 2, 1});
219  elec_.R[0] = {0.5, 0.5, 0.5};
220  elec_.R[1] = {0.1, 0.1, 1.1};
221  elec_.R[2] = {-0.5, -0.5, -0.5};
222  elec_.R[3] = {-0.1, -0.1, 1.5};
223  elec_.R[4] = {0.0, -1.0, 2};
224 
225  SpeciesSet& tspecies = elec_.getSpeciesSet();
226  int upIdx = tspecies.addSpecies("u");
227  int downIdx = tspecies.addSpecies("d");
228  int positronIdx = tspecies.addSpecies("pos");
229  int massIdx = tspecies.addAttribute("mass");
230  int chargeIdx = tspecies.addAttribute("charge");
231  tspecies(massIdx, upIdx) = 1.0;
232  tspecies(massIdx, downIdx) = 1.0;
233  tspecies(massIdx, positronIdx) = 1.0;
234  tspecies(chargeIdx, upIdx) = -1.0;
235  tspecies(chargeIdx, downIdx) = -1.0;
236  tspecies(chargeIdx, positronIdx) = 1.0;
237 
239  bool okay = doc.parseFromString(spo_xml_string);
240  REQUIRE(okay);
241 
242  xmlNodePtr ein_xml = doc.getRoot();
243 
244  WaveFunctionFactory wf_factory(elec_, ptcl.getPool(), c);
245  RuntimeOptions runtime_options;
246  auto twf_ptr = wf_factory.buildTWF(ein_xml, runtime_options);
247 
248  auto& spo = dynamic_cast<const LCAOrbitalSet&>(twf_ptr->getSPOSet(check_sponame));
249  REQUIRE(spo.getOrbitalSetSize() == check_spo_size);
250  REQUIRE(spo.getBasisSetSize() == check_basisset_size);
251 }
252 
253 TEST_CASE("SPO input spline from xml LiH_msd arbitrary species", "[wavefunction]")
254 {
255  app_log() << "-------------------------------------------------------------" << std::endl;
256  app_log() << "LiH_msd with positron xml input style" << std::endl;
257  app_log() << "-------------------------------------------------------------" << std::endl;
258  const char* spo_xml_string1 = R"(<wavefunction name="psi0" target="e">
259  <sposet_collection type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no" href="LiH.orbs.h5">
260  <sposet basisset="LCAOBSet" name="spo-up" size="5">
261  <occupation mode="ground"/>
262  <coefficient size="5" spindataset="0"/>
263  </sposet>
264  <sposet basisset="LCAOBSet" name="spo-dn" size="5">
265  <occupation mode="ground"/>
266  <coefficient size="5" spindataset="0"/>
267  </sposet>
268  <sposet basisset="LCAOBSet" name="spo-ps" size="5">
269  <occupation mode="ground"/>
270  <coefficient size="5" spindataset="0"/>
271  </sposet>
272  </sposet_collection>
273  <determinantset>
274  <multideterminant optimize="yes" spo_0="spo-up" spo_1="spo-dn" spo_2="spo-ps">
275  <detlist size="2" type="DETS" nc0="0" nc1="0" nc2="0" ne0="2" ne1="2" ne2="1" nstates="5" cutoff="1e-20">
276  <ci id="CIcoeff_0" coeff="0.7071" qchem_coeff="0.7071" occ0="11000" occ1="11000" occ2="10000"/>
277  <ci id="CIcoeff_1" coeff="-0.7071" qchem_coeff="-0.7071" occ0="10100" occ1="11000" occ2="00100" />
278  </detlist>
279  </multideterminant>
280  </determinantset>
281 </wavefunction>
282 )";
283  test_LiH_msd_xml_input_with_positron(spo_xml_string1, "spo-ps", 5, 105);
284 }
285 TEST_CASE("SPO input spline from h5 LiH_msd arbitrary species", "[wavefunction]")
286 {
287  app_log() << "-------------------------------------------------------------" << std::endl;
288  app_log() << "LiH_msd with positron h5 input style" << std::endl;
289  app_log() << "-------------------------------------------------------------" << std::endl;
290  const char* spo_xml_string1 = R"(<wavefunction name="psi0" target="e">
291  <sposet_collection type="MolecularOrbital" name="LCAOBSet" source="ion0" transform="yes" cuspCorrection="no" href="LiH.orbs.h5">
292  <sposet basisset="LCAOBSet" name="spo-up" size="5">
293  <occupation mode="ground"/>
294  <coefficient size="5" spindataset="0"/>
295  </sposet>
296  <sposet basisset="LCAOBSet" name="spo-dn" size="5">
297  <occupation mode="ground"/>
298  <coefficient size="5" spindataset="0"/>
299  </sposet>
300  <sposet basisset="LCAOBSet" name="spo-ps" size="5">
301  <occupation mode="ground"/>
302  <coefficient size="5" spindataset="0"/>
303  </sposet>
304  </sposet_collection>
305  <determinantset>
306  <multideterminant optimize="yes" spo_0="spo-up" spo_1="spo-dn" spo_2="spo-ps">
307  <detlist size="2" type="DETS" cutoff="1e-20" href="LiH.Multidet.h5"/>
308  </multideterminant>
309  </determinantset>
310 </wavefunction>
311 )";
312  test_LiH_msd_xml_input_with_positron(spo_xml_string1, "spo-ps", 5, 105);
313 }
314 } // namespace qmcplusplus
void setName(const std::string &aname)
Definition: ParticleSet.h:237
class that handles xmlDoc
Definition: Libxml2Doc.h:76
void test_LiH_msd_xml_input(const std::string &spo_xml_string, const std::string &check_sponame, int check_spo_size, int check_basisset_size)
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
void test_LiH_msd_xml_input_with_positron(const std::string &spo_xml_string, const std::string &check_sponame, int check_spo_size, int check_basisset_size)
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
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.
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
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
Declaration of a WaveFunctionFactory.
class to handle linear combinations of basis orbitals used to evaluate the Dirac determinants.
Definition: LCAOrbitalSet.h:30
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.