QMCPACK
OneBodyDensityMatricesInput.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) 2023 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // Some code refactored from: DensityMatrices1b.cpp
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "string_utils.h"
13 #include "EstimatorInput.h"
15 
16 namespace qmcplusplus
17 {
18 
19 template bool InputSection::setIfInInput<qmcplusplus::OneBodyDensityMatricesInput::Integrator>(qmcplusplus::OneBodyDensityMatricesInput::Integrator& var, const std::string& tag);
20 
21 
23 {
24  // This results in checkParticularValidity being called on OneBodyDensityMatrixInputSection
26  auto setIfInInput = LAMBDA_setIfInInput;
27  setIfInInput(energy_matrix_, "energy_matrix");
28  setIfInInput(use_drift_, "use_drift");
29  setIfInInput(normalized_, "normalized");
30  setIfInInput(volume_normalized_, "volume_normalized");
31  setIfInInput(check_overlap_, "check_overlap");
32  setIfInInput(check_derivatives_, "check_derivatives");
33  setIfInInput(rstats_, "rstats");
34  setIfInInput(write_acceptance_ratio_, "acceptance_ratio");
35  setIfInInput(integrator_, "integrator");
36  setIfInInput(evaluator_, "evaluator");
37  setIfInInput(scale_, "scale");
38  center_defined_ = setIfInInput(center_, "center");
39  corner_defined_ = setIfInInput(corner_, "corner");
40  setIfInInput(timestep_, "timestep");
41  setIfInInput(points_, "points");
42  setIfInInput(samples_, "samples");
43  setIfInInput(warmup_samples_, "warmup_samples");
44  setIfInInput(basis_sets_, "basis");
45 }
46 
48 {
49  using namespace estimatorinput;
50  const std::string error_tag{"OneBodyDensityMatrices input: "};
51  checkCenterCorner(*this, error_tag);
52  if (has("scale"))
53  {
54  Real scale = get<Real>("scale");
55  if (scale > 1.0 + 1e-10)
56  throw UniformCommunicateError(error_tag + "scale must be less than one");
57  else if (scale < 0.0 - 1e-10)
58  throw UniformCommunicateError(error_tag + "scale must be greater than zero");
59  }
60  std::vector<std::string> basis_sets = get<std::vector<std::string>>("basis");
61  if (basis_sets.size() == 0 || basis_sets[0].size() == 0)
62  throw UniformCommunicateError(error_tag + "basis must have at least one sposet");
63  // An example of how to do specific validation of input.
64  if (get<std::string>("integrator") != "density")
65  {
66  if (has("acceptance_ratio") && get<bool>("acceptance_ratio") == true)
67  throw UniformCommunicateError(error_tag + "acceptance_ratio can only be true for density integrator");
68  }
69  if (get<std::string>("integrator") == "uniform_grid")
70  {
71  if (has("samples"))
72  throw UniformCommunicateError(error_tag +
73  "samples are set from points for uniform_grid integrator and are invalid input");
74  }
75 }
76 
78 {
79  return lookupAnyEnum(name, get<std::string>(name), lookup_input_enum_value);
80 }
81 
82 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QMCTraits::FullPrecRealType Real
Definition: InputSection.h:40
Position center_
center_ does not have a default. The estimator sets if from input Lattice if it isn&#39;t set ...
#define LAMBDA_setIfInInput
If tag is present in input_secution set its variable.
This a subclass for runtime errors that will occur on all ranks.
void readXML(xmlNodePtr cur)
Read variable values (initialize) from XML input, call checkValid.
OneBodyDensityMatricesInput(const OneBodyDensityMatricesInput &)=default
default copy constructor This is required due to OBDMI being part of a variant used as a vector eleme...
static std::any lookupAnyEnum(const std::string &enum_name, const std::string &enum_value, const std::unordered_map< std::string, std::any > &enum_map)
Assign any enum helper for InputSection derived class assumes enum lookup table of this form: inline ...
bool center_defined_
This flag is derived from input so if you construct an OBDMI directly with center it must be set...
static const std::unordered_map< std::string, std::any > lookup_input_enum_value
mapping for enumerated options of OneBodyDensityMatrices This data object is the basis of input enum ...
OneBodyDensityMatricesInputSection input_section_
bool has(const std::string &name) const
Definition: InputSection.h:87
void checkCenterCorner(InputSection &input_section, const std::string &error_tag)
std::any assignAnyEnum(const std::string &name) const override
Derived class overrides this to get proper assignment of scoped enum values.