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"
18 #include "Particle/ParticleSetPool.h"
19 #include "QMCWaveFunctions/WaveFunctionComponent.h"
20 #include "QMCWaveFunctions/Jastrow/kSpaceJastrow.h"
21 #include "QMCWaveFunctions/Jastrow/kSpaceJastrowBuilder.h"
22 #include "ParticleIO/ParticleLayoutIO.h"
23 
24 #include <stdio.h>
25 #include <string>
26 
27 using std::string;
28 
29 namespace qmcplusplus
30 {
31 TEST_CASE("kspace jastrow", "[wavefunction]")
32 {
33   Communicate* c;
34   c = OHMMS::Controller;
35 
36   ParticleSet ions_;
37   ParticleSet elec_;
38 
39   ions_.setName("ion");
40   ions_.create(1);
41   ions_.R[0][0] = 0.0;
42   ions_.R[0][1] = 0.0;
43   ions_.R[0][2] = 0.0;
44 
45   elec_.setName("elec");
46   std::vector<int> ud(2);
47   ud[0] = 2;
48   ud[1] = 0;
49   elec_.create(ud);
50   elec_.R[0][0] = -0.28;
51   elec_.R[0][1] = 0.0225;
52   elec_.R[0][2] = -2.709;
53   elec_.R[1][0] = -1.08389;
54   elec_.R[1][1] = 1.9679;
55   elec_.R[1][2] = -0.0128914;
56 
57   SpeciesSet& tspecies         = elec_.getSpeciesSet();
58   int upIdx                    = tspecies.addSpecies("u");
59   int downIdx                  = tspecies.addSpecies("d");
60   int chargeIdx                = tspecies.addAttribute("charge");
61   tspecies(chargeIdx, upIdx)   = -1;
62   tspecies(chargeIdx, downIdx) = -1;
63   // initialize simulationcell for kvectors
64   const char* xmltext = "<tmp> \
65   <simulationcell>\
66      <parameter name=\"lattice\" units=\"bohr\">\
67               6.00000000        0.00000000        0.00000000\
68               0.00000000        6.00000000        0.00000000\
69               0.00000000        0.00000000        6.00000000\
70      </parameter>\
71      <parameter name=\"bconds\">\
72         p p p\
73      </parameter>\
74      <parameter name=\"LR_dim_cutoff\"       >    15                 </parameter>\
75   </simulationcell>\
76 </tmp> ";
77   Libxml2Document doc;
78   bool okay = doc.parseFromString(xmltext);
79   REQUIRE(okay);
80 
81   xmlNodePtr root  = doc.getRoot();
82   xmlNodePtr part1 = xmlFirstElementChild(root);
83 
84   // read lattice
85   auto SimulationCell = std::make_unique<ParticleSet::ParticleLayout_t>();
86   LatticeParser lp(*SimulationCell);
87   lp.put(part1);
88   SimulationCell->print(app_log(), 0);
89   elec_.Lattice = *SimulationCell;
90   // kSpaceJastrow::setupGvecs requires ions to have lattice
91   ions_.Lattice = *SimulationCell;
92   // initialize SK
93   elec_.createSK();
94 
95   const char* particles = "<tmp> \
96 <jastrow name=\"Jk\" type=\"kSpace\" source=\"ion\"> \
97   <correlation kc=\"1.5\" type=\"Two-Body\" symmetry=\"isotropic\"> \
98     <coefficients id=\"cG2\" type=\"Array\"> \
99       -100. -50. \
100     </coefficients> \
101   </correlation> \
102 </jastrow> \
103 </tmp> \
104 ";
105   okay = doc.parseFromString(particles);
106   REQUIRE(okay);
107 
108   root = doc.getRoot();
109   xmlNodePtr jas1 = xmlFirstElementChild(root);
110 
111   kSpaceJastrowBuilder jastrow(c, elec_, ions_);
112   std::unique_ptr<WaveFunctionComponent> jas(jastrow.buildComponent(jas1));
113 
114   // update all distance tables
115   elec_.update();
116 
117   double logpsi_real = std::real(jas->evaluateLog(elec_, elec_.G, elec_.L));
118   REQUIRE(logpsi_real == Approx(-4.4088303951)); // !!!! value not checked
119 }
120 } // namespace qmcplusplus
121