QMCPACK
test_cartesian_ao.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: Cody A. Melton, cmelton@sandia.gov, Sandia National Laboratories
8 //
9 // File created by: Cody A. Melton, cmelton@sandia.gov, Sandia National Laboratories
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "Configuration.h"
16 #include "Message/Communicate.h"
22 
23 namespace qmcplusplus
24 {
26 {
27  std::ostringstream section_name;
28  section_name << "Cartesian AO ordering";
29 
30  SECTION(section_name.str())
31  {
33 
34  const SimulationCell simulation_cell;
35  auto elec_ptr = std::make_unique<ParticleSet>(simulation_cell);
36  auto& elec(*elec_ptr);
37  std::vector<int> agroup(2);
38  agroup[0] = 1;
39  elec.setName("e");
40  elec.create(agroup);
41  elec.R[0] = 0.0;
42 
43  SpeciesSet& tspecies = elec.getSpeciesSet();
44  int upIdx = tspecies.addSpecies("u");
45  int massIdx = tspecies.addAttribute("mass");
46  tspecies(massIdx, upIdx) = 1.0;
47 
48  auto ions_ptr = std::make_unique<ParticleSet>(simulation_cell);
49  auto& ions(*ions_ptr);
50  ions.setName("ion0");
51  ions.create({1});
52  ions.R[0] = 0.0;
53  SpeciesSet& ispecies = ions.getSpeciesSet();
54  int hIdx = ispecies.addSpecies("H");
55  ions.update();
56 
57  elec.addTable(ions);
58  elec.update();
59 
61  bool okay = doc.parse("cartesian_order.wfnoj.xml");
62  REQUIRE(okay);
63  xmlNodePtr root = doc.getRoot();
64 
66  particle_set_map.emplace(elec_ptr->getName(), std::move(elec_ptr));
67  particle_set_map.emplace(ions_ptr->getName(), std::move(ions_ptr));
68 
69  SPOSetBuilderFactory bf(c, elec, particle_set_map);
70 
71  OhmmsXPathObject MO_base("//determinantset", doc.getXPathContext());
72  REQUIRE(MO_base.size() == 1);
73 
74  const auto bb_ptr = bf.createSPOSetBuilder(MO_base[0]);
75  auto& bb(*bb_ptr);
76 
77  OhmmsXPathObject slater_base("//determinant", doc.getXPathContext());
78  auto sposet = bb.createSPOSet(slater_base[0]);
79 
80  SPOSet::ValueVector values;
81  values.resize(1);
82 
83  // Call makeMove to compute the distances
84  ParticleSet::SingleParticlePos newpos(0.1, -0.3, 0.2);
85  elec.makeMove(0, newpos);
86 
87  sposet->evaluateValue(elec, 0, values);
88 
89  //generated from ao_order_test.py
90  CHECK(values[0] == Approx(0.48224527310155046).epsilon(1E-6));
91  }
92 }
93 
95 {
96  std::ostringstream section_name;
97  section_name << "Dirac AO ordering";
98 
99  SECTION(section_name.str())
100  {
102 
103  const SimulationCell simulation_cell;
104  auto elec_ptr = std::make_unique<ParticleSet>(simulation_cell);
105  auto& elec(*elec_ptr);
106  std::vector<int> agroup(2);
107  agroup[0] = 1;
108  elec.setName("e");
109  elec.create(agroup);
110  elec.R[0] = 0.0;
111 
112  SpeciesSet& tspecies = elec.getSpeciesSet();
113  int upIdx = tspecies.addSpecies("u");
114  int massIdx = tspecies.addAttribute("mass");
115  tspecies(massIdx, upIdx) = 1.0;
116 
117  auto ions_ptr = std::make_unique<ParticleSet>(simulation_cell);
118  auto& ions(*ions_ptr);
119  ions.setName("ion0");
120  ions.create({1});
121  ions.R[0] = 0.0;
122  SpeciesSet& ispecies = ions.getSpeciesSet();
123  int hIdx = ispecies.addSpecies("H");
124  ions.update();
125 
126  elec.addTable(ions);
127  elec.update();
128 
130  bool okay = doc.parse("dirac_order.wfnoj.xml");
131  REQUIRE(okay);
132  xmlNodePtr root = doc.getRoot();
133 
134  WaveFunctionComponentBuilder::PSetMap particle_set_map;
135  particle_set_map.emplace(elec_ptr->getName(), std::move(elec_ptr));
136  particle_set_map.emplace(ions_ptr->getName(), std::move(ions_ptr));
137 
138 
139  SPOSetBuilderFactory bf(c, elec, particle_set_map);
140 
141  OhmmsXPathObject MO_base("//determinantset", doc.getXPathContext());
142  REQUIRE(MO_base.size() == 1);
143 
144  const auto bb_ptr = bf.createSPOSetBuilder(MO_base[0]);
145  auto& bb(*bb_ptr);
146 
147  OhmmsXPathObject slater_base("//determinant", doc.getXPathContext());
148  auto sposet = bb.createSPOSet(slater_base[0]);
149 
150  SPOSet::ValueVector values;
151  values.resize(1);
152 
153  // Call makeMove to compute the distances
154  ParticleSet::SingleParticlePos newpos(0.1, -0.3, 0.2);
155  elec.makeMove(0, newpos);
156 
157  sposet->evaluateValue(elec, 0, values);
158 
159  //from ao_order_test.py
160  CHECK(values[0] == Approx(0.35953790416302006).epsilon(1E-6));
161  }
162 }
163 
164 TEST_CASE("Cartesian Gaussian Ordering", "[wavefunction]") { test_cartesian_ao(); }
165 TEST_CASE("Dirac Cartesian Gaussian Ordering", "[wavefunction]") { test_dirac_ao(); }
166 
167 } // namespace qmcplusplus
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
xmlXPathContextPtr getXPathContext()
Definition: Libxml2Doc.cpp:100
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
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
class to handle xmlXPathObject
Definition: Libxml2Doc.h:26
Wrapping information on parallelism.
Definition: Communicate.h:68
Decalaration of One-Dimesional grids.
REQUIRE(std::filesystem::exists(filename))
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
void test_cartesian_ao()
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
bool parse(const std::string &fname)
Definition: Libxml2Doc.cpp:180
std::unique_ptr< SPOSetBuilder > createSPOSetBuilder(xmlNodePtr rootNode)
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33