QMCPACK
test_lattice_gaussian.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) 2019 QMCPACK developers.
6 //
7 // File developed by: Yubo "Paul Yang", yubo.paul.yang@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Yubo "Paul Yang", yubo.paul.yang@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "OhmmsData/Libxml2Doc.h"
16 #include "OhmmsPETE/OhmmsMatrix.h"
17 #include "Particle/ParticleSet.h"
22 #include "ParticleIO/LatticeIO.h"
23 
24 #include <stdio.h>
25 #include <string>
26 
27 using std::string;
28 
29 namespace qmcplusplus
30 {
32 using LogValue = std::complex<QMCTraits::QTFull::RealType>;
33 
34 TEST_CASE("lattice gaussian", "[wavefunction]")
35 {
36  Communicate* c;
38 
40  // initialize simulationcell for kvectors
41  const char* xmltext = R"(<tmp>
42  <simulationcell>
43  <parameter name="lattice" units="bohr">
44  6.00000000 0.00000000 0.00000000
45  0.00000000 6.00000000 0.00000000
46  0.00000000 0.00000000 6.00000000
47  </parameter>
48  <parameter name="bconds">
49  p p p
50  </parameter>
51  <parameter name="LR_dim_cutoff"> 15 </parameter>
52  </simulationcell>
53 </tmp>)";
55  bool okay = doc.parseFromString(xmltext);
56  REQUIRE(okay);
57 
58  // read lattice
59  xmlNodePtr root = doc.getRoot();
60  xmlNodePtr part1 = xmlFirstElementChild(root);
61 
63  lp.put(part1);
64  lattice.print(app_log(), 0);
65  const SimulationCell simulation_cell(lattice);
66  auto ions_ptr = std::make_unique<ParticleSet>(simulation_cell);
67  auto elec_ptr = std::make_unique<ParticleSet>(simulation_cell);
68  auto &ions(*ions_ptr), elec(*elec_ptr);
69 
70  ions.setName("ion");
71  ions.create({2});
72  ions.R[0] = {0.0, 0.0, 0.0};
73  ions.R[1] = {0.0, 0.0, 0.0};
74  elec.setName("elec");
75  elec.create({2, 0});
76  elec.R[0] = {-0.28, 0.0225, -2.709};
77  elec.R[1] = {-1.08389, 1.9679, -0.0128914};
78  std::map<string, const std::unique_ptr<ParticleSet>> pp;
79  pp.emplace(ions_ptr->getName(), std::move(ions_ptr));
80  pp.emplace(elec_ptr->getName(), std::move(elec_ptr));
81 
82  SpeciesSet& tspecies = elec.getSpeciesSet();
83  int upIdx = tspecies.addSpecies("u");
84  int downIdx = tspecies.addSpecies("d");
85  int chargeIdx = tspecies.addAttribute("charge");
86  tspecies(chargeIdx, upIdx) = -1;
87  tspecies(chargeIdx, downIdx) = -1;
88 
89  // initialize SK
90  elec.createSK();
91 
92  const char* particles = R"(<tmp>
93  <ionwf name="ionwf" source="ion" width="0.5 0.5"/>
94 </tmp>
95 )";
96  okay = doc.parseFromString(particles);
97  REQUIRE(okay);
98 
99  root = doc.getRoot();
100 
101  xmlNodePtr jas1 = xmlFirstElementChild(root);
102 
103  LatticeGaussianProductBuilder jastrow(c, elec, pp);
104  auto LGP_uptr = jastrow.buildComponent(jas1);
105  auto LGP = dynamic_cast<LatticeGaussianProduct*>(LGP_uptr.get());
106  double width = 0.5;
107  double alpha = 1. / (2 * width * width);
108  // check initialization. Nope, cannot access Psi.Z
109  for (int i = 0; i < 2; i++)
110  {
111  CHECK(LGP->ParticleAlpha[i] == Approx(alpha));
112  }
113 
114  // update all distance tables
115  ions.update();
116  elec.update();
117 
118  LogValue logpsi = LGP->evaluateLog(elec, elec.G, elec.L);
119  // check answer
120  RealType r2 = Dot(elec.R, elec.R);
121  double wfval = std::exp(-alpha * r2);
122  CHECK(logpsi == ComplexApprox(std::log(wfval)));
123 }
124 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
LatticeGaussianProduct LatticeGaussianProduct Builder with constraints.
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
std::unique_ptr< WaveFunctionComponent > buildComponent(xmlNodePtr cur) override
process a xml node at cur
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
Definition: LatticeIO.cpp:32
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
T Dot(const ParticleAttrib< TinyVector< T, D >> &pa, const ParticleAttrib< TinyVector< T, D >> &pb)
Wrapping information on parallelism.
Definition: Communicate.h:68
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
REQUIRE(std::filesystem::exists(filename))
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
QMCTraits::RealType RealType
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
Declaraton of ParticleAttrib<T>
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Declaration of WaveFunctionComponent.
std::complex< double > LogValue
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
Simple gaussian functions used for orbitals for ions.