QMCPACK
test_wavefunction_pool.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) 2017 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 
16 #include "Message/Communicate.h"
17 #include "OhmmsData/Libxml2Doc.h"
20 #include "Utilities/ProjectData.h"
21 
22 
23 #include <stdio.h>
24 #include <string>
25 #include <sstream>
26 
27 
28 namespace qmcplusplus
29 {
30 void setupParticleSetPool(ParticleSetPool& pp)
31 {
32  // See ParticleIO/tests/test_xml_io.cpp for particle parsing
33  const char* particles = R"(
34 <tmp>
35  <simulationcell>
36  <parameter name='lattice' units='bohr'>
37  3.37316115 3.37316115 0.00000000
38  0.00000000 3.37316115 3.37316115
39  3.37316115 0.00000000 3.37316115
40  </parameter>
41  <parameter name='bconds'>
42  p p p
43  </parameter>
44  <parameter name='LR_dim_cutoff'>15 </parameter>
45 </simulationcell>
46 <particleset name="ion" size="2">
47  <group name="C">
48  <parameter name="charge">4</parameter>
49  </group>
50  <attrib name="position" datatype="posArray">
51  0.00000000 0.00000000 0.00000000
52  1.68658058 1.68658058 1.68658058
53  </attrib>
54 </particleset>
55  <particleset name="e" random="yes" >
56  <group name="u" size="4">
57  <parameter name="charge">-1</parameter>
58  </group>
59  <group name="d" size="4">
60  <parameter name="charge">-1</parameter>
61  </group>
62 </particleset>
63 </tmp>
64 )";
66 
67  bool okay = doc.parseFromString(particles);
68  REQUIRE(okay);
69 
70  xmlNodePtr root = doc.getRoot();
71  xmlNodePtr sim_cell = xmlFirstElementChild(root);
72  // Need to set up simulation cell lattice before reading particle sets
73  pp.readSimulationCellXML(sim_cell);
74 
75  xmlNodePtr part_ion = xmlNextElementSibling(sim_cell);
76  pp.put(part_ion);
77  xmlNodePtr part_elec = xmlNextElementSibling(part_ion);
78  pp.put(part_elec);
79  pp.randomize();
80 }
81 
82 
83 TEST_CASE("WaveFunctionPool", "[qmcapp]")
84 {
86  Communicate* c;
88 
89  ParticleSetPool pp(c);
91 
93 
94  REQUIRE(wp.empty() == true);
95 
96 
97  const char* wf_input = R"(<wavefunction target='e'>
98  <determinantset type='einspline' href='diamondC_1x1x1.pwscf.h5' tilematrix='1 0 0 0 1 0 0 0 1' twistnum='0' source='ion' meshfactor='1.0' precision='float'>
99  <slaterdeterminant>
100  <determinant id='updet' size='4'>
101  <occupation mode='ground' spindataset='0'/>
102  </determinant>
103  <determinant id='downdet' size='4'>
104  <occupation mode='ground' spindataset='0'/>
105  </determinant>
106  </slaterdeterminant>
107  </determinantset>
108  </wavefunction>
109  )";
110 
112  bool okay = doc.parseFromString(wf_input);
113  REQUIRE(okay);
114 
115  xmlNodePtr root = doc.getRoot();
116 
117  wp.put(root);
118 
119  TrialWaveFunction* psi = wp.getWaveFunction("psi0");
120  REQUIRE(psi != nullptr);
121  REQUIRE(psi->getOrbitals().size() == 1);
122 }
123 } // namespace qmcplusplus
class that handles xmlDoc
Definition: Libxml2Doc.h:76
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
class ProjectData
Definition: ProjectData.h:36
TEST_CASE("complex_helper", "[type_traits]")
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
ProjectData test_project("test", ProjectData::DriverVersion::BATCH)
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
const RuntimeOptions & getRuntimeOptions() const noexcept
Wrapping information on parallelism.
Definition: Communicate.h:68
REQUIRE(std::filesystem::exists(filename))
void setupParticleSetPool(ParticleSetPool &pp)
Declaration of WaveFunctionPool.
Manage a collection of ParticleSet objects.
std::vector< std::unique_ptr< WaveFunctionComponent > > const & getOrbitals()
Class to represent a many-body trial wave function.
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
Manage a collection of TrialWaveFunction objects.
Declaration of ParticleSetPool.