QMCPACK
test_spo_collection_input_spline.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: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "OhmmsData/Libxml2Doc.h"
16 #include "OhmmsPETE/OhmmsMatrix.h"
17 #include "Particle/ParticleSet.h"
21 
22 #include <stdio.h>
23 #include <string>
24 #include <limits>
25 
26 using std::string;
27 
28 namespace qmcplusplus
29 {
30 void test_diamond_2x1x1_xml_input(const std::string& spo_xml_string)
31 {
33 
34  // diamondC_2x1x1
36  lattice.R = {6.7463223, 6.7463223, 0.0, 0.0, 3.37316115, 3.37316115, 3.37316115, 0.0, 3.37316115};
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({4});
48  ions_.R[0] = {0.0, 0.0, 0.0};
49  ions_.R[1] = {1.68658058, 1.68658058, 1.68658058};
50  ions_.R[2] = {3.37316115, 3.37316115, 0.0};
51  ions_.R[3] = {5.05974173, 5.05974173, 1.68658058};
52  elec_.setName("elec");
53  ptcl.addParticleSet(std::move(elec_uptr));
54  elec_.create({2});
55  elec_.R[0] = {0.0, 0.0, 0.0};
56  elec_.R[1] = {0.0, 1.0, 0.0};
57  SpeciesSet& tspecies = elec_.getSpeciesSet();
58  int upIdx = tspecies.addSpecies("u");
59  int chargeIdx = tspecies.addAttribute("charge");
60  tspecies(chargeIdx, upIdx) = -1;
61 
63  bool okay = doc.parseFromString(spo_xml_string);
64  REQUIRE(okay);
65 
66  xmlNodePtr ein_xml = doc.getRoot();
67 
68  WaveFunctionFactory wf_factory(elec_, ptcl.getPool(), c);
69  RuntimeOptions runtime_options;
70  auto twf_ptr = wf_factory.buildTWF(ein_xml, runtime_options);
71 
72  std::unique_ptr<SPOSet> spo(twf_ptr->getSPOSet("spo").makeClone());
73 
74  // for vgl
75  SPOSet::ValueMatrix psiM(elec_.R.size(), spo->getOrbitalSetSize());
76  SPOSet::GradMatrix dpsiM(elec_.R.size(), spo->getOrbitalSetSize());
77  SPOSet::ValueMatrix d2psiM(elec_.R.size(), spo->getOrbitalSetSize());
78  spo->evaluate_notranspose(elec_, 0, elec_.R.size(), psiM, dpsiM, d2psiM);
79 
80  // real part
81  // due to the different ordering of bands skip the tests on CUDA+Real builds
82  // checking evaluations, reference values are not independently generated.
83  // value
84  CHECK(std::real(psiM[1][0]) == Approx(0.9008999467));
85  CHECK(std::real(psiM[1][1]) == Approx(1.2383049726));
86  // grad
87  CHECK(std::real(dpsiM[1][0][0]) == Approx(0.0025820041));
88  CHECK(std::real(dpsiM[1][0][1]) == Approx(-0.1880052537));
89  CHECK(std::real(dpsiM[1][0][2]) == Approx(-0.0025404284));
90  CHECK(std::real(dpsiM[1][1][0]) == Approx(0.1069662273));
91  CHECK(std::real(dpsiM[1][1][1]) == Approx(-0.4364597797));
92  CHECK(std::real(dpsiM[1][1][2]) == Approx(-0.106951952));
93  // lapl
94  CHECK(std::real(d2psiM[1][0]) == Approx(-1.3757134676));
95  CHECK(std::real(d2psiM[1][1]) == Approx(-2.4803137779));
96 
97 #if defined(QMC_COMPLEX)
98  // imaginary part
99  // value
100  CHECK(std::imag(psiM[1][0]) == Approx(0.9008999467));
101  CHECK(std::imag(psiM[1][1]) == Approx(1.2383049726));
102  // grad
103  CHECK(std::imag(dpsiM[1][0][0]) == Approx(0.0025820041));
104  CHECK(std::imag(dpsiM[1][0][1]) == Approx(-0.1880052537));
105  CHECK(std::imag(dpsiM[1][0][2]) == Approx(-0.0025404284));
106  CHECK(std::imag(dpsiM[1][1][0]) == Approx(0.1069453433));
107  CHECK(std::imag(dpsiM[1][1][1]) == Approx(-0.43649593));
108  CHECK(std::imag(dpsiM[1][1][2]) == Approx(-0.1069145575));
109  // lapl
110  CHECK(std::imag(d2psiM[1][0]) == Approx(-1.3757134676));
111  CHECK(std::imag(d2psiM[1][1]) == Approx(-2.4919104576));
112 #endif
113 }
114 
115 TEST_CASE("SPO input spline from HDF diamond_2x1x1", "[wavefunction]")
116 {
117  // capture 3 spo input styles, the 2nd and 3rd ones will be deprecated and removed eventually.
118  // the first case should be simplified using SPOSetBuilderFactory instead of WaveFunctionFactory
119  app_log() << "-------------------------------------------------------------" << std::endl;
120  app_log() << "diamondC_2x1x1 input style 1 using sposet_collection" << std::endl;
121  app_log() << "-------------------------------------------------------------" << std::endl;
122  const char* spo_xml_string1 = R"(<wavefunction name="psi0" target="elec">
123 <sposet_collection name="einspline_diamond_size4" type="einspline" href="diamondC_2x1x1.pwscf.h5" tilematrix="2 0 0 0 1 0 0 0 1" twistnum="0" source="ion" meshfactor="1.0" precision="float">
124  <sposet name="spo" size="4" spindataset="0"/>
125 </sposet_collection>
126 </wavefunction>
127 )";
128  test_diamond_2x1x1_xml_input(spo_xml_string1);
129 
130  app_log() << "-------------------------------------------------------------" << std::endl;
131  app_log() << "diamondC_2x1x1 input style 2 sposet inside determinantset" << std::endl;
132  app_log() << "-------------------------------------------------------------" << std::endl;
133  const char* spo_xml_string2 = R"(<wavefunction name="psi0" target="elec">
134 <determinantset type="einspline" href="diamondC_2x1x1.pwscf.h5" tilematrix="2 0 0 0 1 0 0 0 1" twistnum="0" source="ion" meshfactor="1.0" precision="float">
135  <sposet name="spo" size="4" spindataset="0"/>
136  <slaterdeterminant>
137  <determinant name="det" sposet="spo"/>
138  </slaterdeterminant>
139 </determinantset>
140 </wavefunction>
141 )";
142  test_diamond_2x1x1_xml_input(spo_xml_string2);
143 
144  app_log() << "-------------------------------------------------------------" << std::endl;
145  app_log() << "diamondC_2x1x1 input style 3 sposet inside determinantset" << std::endl;
146  app_log() << "-------------------------------------------------------------" << std::endl;
147  const char* spo_xml_string3 = R"(<wavefunction name="psi0" target="elec">
148 <determinantset type="einspline" href="diamondC_2x1x1.pwscf.h5" tilematrix="2 0 0 0 1 0 0 0 1" twistnum="0" source="ion" meshfactor="1.0" precision="float">
149  <slaterdeterminant>
150  <determinant name="spo" size="4" spindataset="0"/>
151  </slaterdeterminant>
152 </determinantset>
153 </wavefunction>
154 )";
155  test_diamond_2x1x1_xml_input(spo_xml_string3);
156 }
157 } // 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::ostream & app_log()
Definition: OutputManager.h:65
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
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
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
OrbitalSetTraits< ValueType >::GradMatrix GradMatrix
Definition: SPOSet.h:52
Wrapping information on parallelism.
Definition: Communicate.h:68
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
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...
size_type size() const
return the current size
Definition: OhmmsVector.h:162
REQUIRE(std::filesystem::exists(filename))
void test_diamond_2x1x1_xml_input(const std::string &spo_xml_string)
Manage a collection of ParticleSet objects.
Factory class to build a many-body wavefunction.
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 WaveFunctionFactory.
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
const PoolType & getPool() const
get the Pool object
const auto & getSimulationCell() const
get simulation cell
Declaration of ParticleSetPool.