QMCPACK
test_wavefunction_factory.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) 2018 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "Configuration.h"
16 #include "Message/Communicate.h"
17 #include "OhmmsData/Libxml2Doc.h"
20 
21 namespace qmcplusplus
22 {
23 TEST_CASE("WaveFunctionFactory", "[wavefunction]")
24 {
26 
27  const SimulationCell simulation_cell;
28  auto qp = std::make_unique<ParticleSet>(simulation_cell);
29  std::vector<int> agroup(2, 1);
30  qp->setName("e");
31  qp->create(agroup);
32  qp->R[0] = {1.0, 2.0, 3.0};
33  qp->R[1] = {0.0, 1.1, 2.2};
34 
35  SpeciesSet& tspecies = qp->getSpeciesSet();
36  int upIdx = tspecies.addSpecies("u");
37  int downIdx = tspecies.addSpecies("d");
38  int massIdx = tspecies.addAttribute("mass");
39  tspecies(massIdx, upIdx) = 1.0;
40  tspecies(massIdx, downIdx) = 1.0;
41 
42  qp->update();
43 
44  WaveFunctionFactory::PSetMap particle_set_map;
45  particle_set_map.emplace("e", std::move(qp));
46 
47  WaveFunctionFactory wff(*particle_set_map["e"], particle_set_map, c);
48 
49  const char* wavefunction_xml = R"(<wavefunction>
50  <jastrow type="Two-Body" name="J2" function="bspline" print="yes" gpu="no">
51  <correlation speciesA="u" speciesB="d" size="8" cutoff="10.0">
52  <coefficients id="ud" type="Array">
53 0.5954603818 0.5062051797 0.3746940461 0.2521010502 0.1440163317 0.07796688253
54 0.03804420551 0.01449320872
55  </coefficients>
56  </correlation>
57  </jastrow>
58 </wavefunction>)";
60  bool okay = doc.parseFromString(wavefunction_xml);
61  REQUIRE(okay);
62 
63  xmlNodePtr root = doc.getRoot();
64  RuntimeOptions runtime_options;
65  auto twf_ptr = wff.buildTWF(root, runtime_options);
66 
67  REQUIRE(twf_ptr != nullptr);
68  REQUIRE(twf_ptr->size() == 1);
69 
70  auto& j2_base = twf_ptr->getOrbitals()[0];
71  REQUIRE(j2_base != nullptr);
72 }
73 } // namespace qmcplusplus
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
TEST_CASE("complex_helper", "[type_traits]")
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
std::unique_ptr< TrialWaveFunction > buildTWF(xmlNodePtr cur, const RuntimeOptions &runtime_options)
read from xmlNode
REQUIRE(std::filesystem::exists(filename))
Factory class to build a many-body wavefunction.
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
Declaration of a WaveFunctionFactory.
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33