QMCPACK
test_pw.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Mark Dewing, markdewing@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"
20 
21 
22 #include <stdio.h>
23 #include <string>
24 
25 using std::string;
26 
27 namespace qmcplusplus
28 {
29 TEST_CASE("PlaneWave SPO from HDF for BCC H", "[wavefunction]")
30 {
32 
33  // BCC H
35  lattice.R = {3.77945227, 0.0, 0.0, 0.0, 3.77945227, 0.0, 0.0, 0.0, 3.77945227};
36  lattice.reset();
37 
40  auto ions_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
41  auto elec_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
42  ParticleSet& ions(*ions_uptr);
43  ParticleSet& elec(*elec_uptr);
44 
45  ions.setName("ion");
46  ptcl.addParticleSet(std::move(ions_uptr));
47  ions.create({2});
48  ions.R[0] = {0.0, 0.0, 0.0};
49  ions.R[1] = {1.88972614, 1.88972614, 1.88972614};
50  std::vector<int> agroup(2);
51  agroup[0] = 1;
52  agroup[1] = 1;
53  elec.create(agroup);
54 
55  elec.setName("elec");
56  ptcl.addParticleSet(std::move(elec_uptr));
57  elec.R[0] = {0.0, 0.0, 0.0};
58  elec.R[1] = {0.0, 1.0, 0.0};
59  SpeciesSet& tspecies = elec.getSpeciesSet();
60  int upIdx = tspecies.addSpecies("u");
61  int downIdx = tspecies.addSpecies("d");
62  int chargeIdx = tspecies.addAttribute("charge");
63  tspecies(chargeIdx, upIdx) = -1;
64  tspecies(chargeIdx, downIdx) = -1;
65 
66  elec.addTable(ions);
67  elec.resetGroups();
68  elec.update();
69 
70  //BCC H
71  const char* particles = R"(
72 <sposet_collection type="PW" href="bccH.pwscf.h5" tilematrix="1 0 0 0 1 0 0 0 1" twistnum="0" source="ion">
73  <sposet name="updet" size="1" spindataset="0">
74  <occupation mode="ground"/>
75  </sposet>
76 </sposet_collection>
77 )";
78 
80  bool okay = doc.parseFromString(particles);
81  REQUIRE(okay);
82 
83  xmlNodePtr root = doc.getRoot();
84  xmlNodePtr pw1 = xmlFirstElementChild(root);
85 
86 
87  PWOrbitalSetBuilder pw_builder(elec, c, root);
88  auto spo = pw_builder.createSPOSet(pw1);
89  REQUIRE(spo);
90 
91  const int orbSize = spo->getOrbitalSetSize();
92  elec.update();
93  SPOSet::ValueVector orbs(orbSize);
94  spo->evaluateValue(elec, 0, orbs);
95 
96  CHECK(std::real(orbs[0]) == Approx(-1.2473558998));
97 
98 #if 0
99  // Dump values of the orbitals
100  int basisSize= spo->getBasisSetSize();
101  printf("orb size = %d basis set size = %d\n",orbSize, basisSize);
102 
103  elec.R[1][1] = 0.0;
104  double step = 3.78/10;
105  FILE *fspo = fopen("spo.dat", "w");
106  for (int ix = 0; ix < 10; ix++) {
107  for (int iy = 0; iy < 10; iy++) {
108  for (int iz = 0; iz < 10; iz++) {
109  double x = step*ix;
110  double y = step*iy;
111  double z = step*iz;
112  elec.R[0] = {x, y, z};
113  elec.update();
114  SPOSet::ValueVector orbs(orbSize);
115  spo->evaluateValue(elec, 0, orbs);
116  fprintf(fspo, "%g %g %g",x,y,z);
117  for (int j = 0; j < orbSize; j++) {
118 #ifdef QMC_COMPLEX
119  fprintf(fspo, " %g,%g ",orbs[j].real(),orbs[j].imag());
120 #else
121  fprintf(fspo, " %g ",orbs[j]);
122 #endif
123  }
124  fprintf(fspo, "\n");
125  }
126  }
127  }
128  fclose(fspo);
129 #endif
130 }
131 
132 
133 TEST_CASE("PlaneWave SPO from HDF for LiH arb", "[wavefunction]")
134 {
136 
137  // LiH
139  lattice.R = {-3.55, 0.0, 3.55, 0.0, 3.55, 3.55, -3.55, 3.55, 0.0};
140  lattice.reset();
141 
144  auto ions_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
145  auto elec_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
146  ParticleSet& ions(*ions_uptr);
147  ParticleSet& elec(*elec_uptr);
148 
149  ions.setName("ion");
150  ptcl.addParticleSet(std::move(ions_uptr));
151  ions.create({2});
152  ions.R[0] = {0.0, 0.0, 0.0};
153  ions.R[1] = {3.55, 3.55, 3.55};
154  std::vector<int> agroup(2);
155  agroup[0] = 2;
156  agroup[1] = 2;
157  elec.create(agroup);
158 
159  elec.setName("elec");
160  ptcl.addParticleSet(std::move(elec_uptr));
161  elec.R[0] = {0.0, 0.0, 0.0};
162  elec.R[1] = {0.0, 1.0, 0.0};
163  elec.R[2] = {0.0, 0.0, 1.0};
164  elec.R[3] = {0.0, 1.0, 1.0};
165  SpeciesSet& tspecies = elec.getSpeciesSet();
166  int upIdx = tspecies.addSpecies("u");
167  int downIdx = tspecies.addSpecies("d");
168  int chargeIdx = tspecies.addAttribute("charge");
169  tspecies(chargeIdx, upIdx) = -1;
170  tspecies(chargeIdx, downIdx) = -1;
171 
172  elec.addTable(ions);
173  elec.resetGroups();
174  elec.update();
175 
176  //diamondC_1x1x1
177  const char* particles = R"(
178 <sposet_collection type="PW" href="LiH-arb.pwscf.h5" tilematrix="1 0 0 0 1 0 0 0 1" twistnum="0" source="ion">
179  <sposet name="updet" size="2" spindataset="0">
180  <occupation mode="ground"/>
181  </sposet>
182 </sposet_collection>
183 )";
184 
186  bool okay = doc.parseFromString(particles);
187  REQUIRE(okay);
188 
189  xmlNodePtr root = doc.getRoot();
190  xmlNodePtr pw1 = xmlFirstElementChild(root);
191 
192 
193  PWOrbitalSetBuilder pw_builder(elec, c, root);
194  auto spo = pw_builder.createSPOSet(pw1);
195  REQUIRE(spo);
196 
197  const int orbSize = spo->getOrbitalSetSize();
198  elec.update();
199  SPOSet::ValueVector orbs(orbSize);
200  spo->evaluateValue(elec, 0, orbs);
201 
202  CHECK(std::real(orbs[0]) == Approx(-14.3744302974));
203 
204 #if 0
205  // Dump values of the orbitals
206  int basisSize= spo->getBasisSetSize();
207  printf("orb size = %d basis set size = %d\n",orbSize, basisSize);
208 
209  elec.R[1][1] = 0.0;
210  double step = 3.55/10;
211  FILE *fspo = fopen("spo.dat", "w");
212  for (int ix = 0; ix < 10; ix++) {
213  for (int iy = 0; iy < 10; iy++) {
214  for (int iz = 0; iz < 10; iz++) {
215  double x = step*ix;
216  double y = step*iy;
217  double z = step*iz;
218  elec.R[0] = {x, y, z};
219  elec.update();
220  SPOSet::ValueVector orbs(orbSize);
221  spo->evaluateValue(elec, 0, orbs);
222  fprintf(fspo, "%g %g %g",x,y,z);
223  for (int j = 0; j < orbSize; j++) {
224 #ifdef QMC_COMPLEX
225  fprintf(fspo, " %g,%g ",orbs[j].real(),orbs[j].imag());
226 #else
227  fprintf(fspo, " %g ",orbs[j]);
228 #endif
229  }
230  fprintf(fspo, "\n");
231  }
232  }
233  }
234  fclose(fspo);
235 #endif
236 }
237 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
void setName(const std::string &aname)
Definition: ParticleSet.h:237
void setSimulationCell(const SimulationCell &simulation_cell)
set simulation cell
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
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::unique_ptr< SPOSet > createSPOSet(xmlNodePtr cur)
create an sposet from xml and save the resulting SPOSet
TEST_CASE("complex_helper", "[type_traits]")
void addParticleSet(std::unique_ptr< ParticleSet > &&p)
add a ParticleSet* to the pool with its ownership transferred ParticleSet built outside the ParticleS...
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
void update(bool skipSK=false)
update the internal data
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
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
REQUIRE(std::filesystem::exists(filename))
Manage a collection of ParticleSet objects.
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
ParticlePos R
Position.
Definition: ParticleSet.h:79
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void create(const std::vector< int > &agroup)
create grouped particles
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Declaration of a builder class for PWOrbitalSet.
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
OrbitalBuilder for Slater determinants in PW basis.
const auto & getSimulationCell() const
get simulation cell
Declaration of ParticleSetPool.