MADNESS 0.10.1
QCCalculationParametersBase.h
Go to the documentation of this file.
1/*
2 * QCCalculationParametersBase.h
3 *
4 * Created on: 27 Jun 2019
5 * Author: fbischoff
6 */
7
8#ifndef SRC_APPS_CHEM_QCCALCULATIONPARAMETERSBASE_H_
9#define SRC_APPS_CHEM_QCCALCULATIONPARAMETERSBASE_H_
10
12#include <string>
13#include <algorithm>
14#include <iomanip>
15#include <typeindex>
16#include <map>
17#include <fstream>
18#include <typeinfo>
19// #include <madness/external/gtest/include/gtest/internal/gtest-type-util.h>
20
21#include "madness/misc/misc.h"
23#include "madness/world/world.h"
25#include "madness/external/nlohmann_json/json.hpp"
26
27
28namespace madness {
29 using json = nlohmann::json;
30
31 template <typename T>
32 static typename std::enable_if<std::is_floating_point<T>::value, void>::type
33 check_for_inf(const std::string& str, T& arg) {
34 std::string sinf;
35 std::stringstream ss;
37 sinf = ss.str();
38
39 if (sinf == str) arg = std::numeric_limits<T>::infinity();
40 }
41
42 template <typename T>
43 static typename std::enable_if<!std::is_floating_point<T>::value, void>::type
44 check_for_inf(const std::string& str, T& arg) {
45 return;
46 }
47
48 /// inverting the print method from print.h for std::vector
49 /// TODO: move this where it belongs (into print.h ??)
50 template <typename T, typename A=std::allocator<T>>
51 std::istream& operator>>(std::istream& is, std::vector<T, A>& v) {
52 // get the full line from opening to closing brackets [ .. ]
53 std::string word, line = "";
54 while (is >> word) {
55 line += word;
56 if (word.find(']') != std::string::npos) break;
57 }
58 if (line.size() != 0) is.clear();
59
60 // remove enclosing brackets and commas
61 auto find_c = [](char& c) { return ((c == ',') or (c == '[') or (c == ']')); };
62 std::replace_if(line.begin(), line.end(), find_c, ' '); // 0 2 0 4 0 6 0 8 0
63
64 // stream the values into the container
65 std::stringstream sline(line);
66 T tmp;
67 while (sline >> word) {
68 std::stringstream sword(word);
69 sword >> tmp;
71 v.push_back(tmp);
72 }
73 if (sline.bad()) {
74 madness::print("error while reading vector from istream: ");
75 madness::print(line, "\n");
76 throw std::runtime_error("IO error");
77 }
78
79 return is;
80 }
81
82
83 /// inverting the print method from print.h for std::vector
84 /// TODO: move this where it belongs (into print.h ??)
85 template <typename Q, typename T>
86 std::istream& operator>>(std::istream& is, std::pair<T, Q>& p) {
87 // get all words from the line
88 std::string word, line = "";
89 while (is >> word) {
90 line += word + " ";
91 };
92 // have to set this here to account for the error handling later..
93 is.clear();
94
95 // remove enclosing brackets and commas
96 auto find_c = [](char& c) { return ((c == ',') or (c == '(') or (c == ')')); };
97 std::replace_if(line.begin(), line.end(), find_c, ' '); // 0 2 0 4 0 6 0 8 0
98
99 // stream the values into the container
100 std::stringstream sline(line);
101 T tmp1;
102 Q tmp2;
103 sline >> tmp1 >> tmp2;
104 if (sline.bad() or sline.fail()) {
105 madness::print("error while reading vector from istream: ");
106 madness::print(line, "\n");
107 throw std::runtime_error("IO error");
108 }
109 p = std::pair<T, Q>(tmp1, tmp2);
110
111 return is;
112 }
113
114
115 /// structure holding the value for a given parameter
116
117 /// keeps logic about default, derived and user-defined settings (with increasing priority),
118 /// as well as comments for the user (e.g. a recommended range for a given parameter).
119 ///
120 /// might be extended to hold allowed values for certain parameters, e.g. localization procedures.
121 ///
122 /// all values are stored as strings and must be converted to their respective types by the
123 /// QCCalculationParametersBase class (see below)
124 struct QCParameter {
125 public:
127
128 QCParameter(const std::string v, const std::string t, const std::string comment = "",
129 const std::vector<std::string> allowed_values1 = {})
131 static int i = 0;
132 print_order = i++;
133 set_all();
134 }
135
136 void set_derived_value(const std::string val) {
137 precedence = std::max(derived, precedence);
138 derived_value = val;
139 set_all();
140 }
141
142 void set_user_defined_value(const std::string val) {
143 precedence = std::max(defined, precedence);
144 user_defined_value = val;
145 set_all();
146 }
147
148 bool is_user_defined() const {
149 return (precedence == defined);
150 }
151
152 std::string get_value() const { return value; }
153 std::string get_type() const { return type; }
154 std::string get_comment() const { return comment; }
155
156 std::string print_precedence() const {
157 if (precedence == def) return "default";
158 if (precedence == derived) return "derived";
159 if (precedence == defined) return "defined";
160 std::stringstream sprecedence;
162 throw std::runtime_error("unknown precedence in QCParameter" + sprecedence.str());
163 return "darn";
164 }
165
166 int get_print_order() const { return print_order; }
167
168 std::string print_line(const std::string& key) const {
169 auto fill_left = [](const int size, const std::string word) {
170 int nspaces = std::max(int(0), size - int(word.length()));
171 return std::string(nspaces, ' ') + word;
172 };
173 auto fill_right = [](const int size, const std::string word) {
174 int nspaces = std::max(int(0), size - int(word.length()));
175 return word + std::string(nspaces, ' ');
176 };
177
178 // key-value block
179 std::string keyval = fill_left(20, key) + " " + fill_right(10, get_value()) + " # " + fill_right(
180 10, print_precedence());
181 std::string empty_keyval(keyval.size(), ' ');
182 empty_keyval[33] = '#';
183
184 std::string allowed_val;
185 if (allowed_values.size() > 0) {
186 using madness::operators::operator<<;
187 std::stringstream ss;
189 allowed_val += ss.str();
190 }
191
192 // split comment into several lines: split onto words and add linebreak
194
195 // first line breaks after 80 characters, all other lines after 120 (leave space f
196 long keyvalsize = keyval.size(); // length of key, value, precedence
197 std::string comment1 = get_comment();
199 std::vector<std::string> commentlines(1);
200 long nchar = 0;
201 for (auto word : commentwords) {
202 bool is_first_line = commentlines.size() == 1;
203 long thislinebreak = 120;
206
207 nchar += word.size() + 1;
208 if (nchar > commentsize) { // start newline
209 commentlines.push_back("");
210 nchar = word.size() + 1;
211 }
212 commentlines.back() += word + " ";
213 }
214
215 std::string result;
216 for (size_t i = 0; i < commentlines.size(); ++i) {
217 if (i == 0) result = keyval + fill_right(40, commentlines[i]) + allowed_val;
218 else result += "\n" + empty_keyval + commentlines[i];
219 }
220
221 // trim result
222 std::size_t last = result.find_last_not_of(' ');
223 return result.substr(0, last + 1);
224 }
225
226 template <typename Archive>
231
233
234 bool operator==(const QCParameter& other) const {
235 return (value == other.value and default_value == other.default_value and
237 type == other.type and null == other.null and comment == other.comment and
239 }
240
241 hashT hash() const {
242 return hash_value(value);
243 }
244
245 private:
246 void set_all() {
250 if (not check_allowed()) throw std::invalid_argument(not_allowed_errmsg());
251 }
252
254 if (allowed_values.size() == 0) return true;
255 auto it = std::find(allowed_values.begin(), allowed_values.end(), value);
256 return (it != allowed_values.end());
257 }
258
259 std::string not_allowed_errmsg() const {
260 using madness::operators::operator<<;
261 std::stringstream ss;
263 std::string errmsg = "\ntrying to assign a value that's not allowed\n\n";
264 errmsg += "\tuser-defined value: " + value + "\n";
265 errmsg += "\tallowed values: " + ss.str() + "\n\n";
266 return errmsg;
267 }
268
269
270 std::string value;
271 std::string default_value = "";
272 std::string derived_value = "";
273 std::string user_defined_value = "";
274 std::string type = "";
275 std::string null = "";
276 std::string comment = "";
277 std::vector<std::string> allowed_values = std::vector<std::string>();
278 int print_order = 0; // use this for printing the parameters in the same order as they are defined
279 };
280
281 /// class for holding the parameters for calculation
282
283 /// Actual parameter classes will be derived from this class with a simple constructor
284 /// (see test_QCCalculationParametersBase.cc for an example) and convenience
285 /// getters for the parameters of each parameter class.
286 /// Having the base class will allow consistent parameter input/output handling
287 /// for all madness programs and reuse of the parsing methods.
288 /// Even if the same parameter is used in different programs, default might differ
289 /// (i.e. econv for 3D/6D calculations). The parameter class will effectively serve as
290 /// a factory for the calculation classes (SCF, nemo, mp2, etc)
291 ///
292 /// parameters are kept in a map with key (string) and value (QCParameter),
293 /// types are converted whenever a parameter is accessed (i.e. should not be
294 /// done too frequently in an inner loop)
296 public:
297 /// print all parameters
298 void print(const std::string header = "", const std::string footer = "") const;
299
300 virtual std::string get_tag() const = 0;
301
302 std::string print_to_string(const std::list<std::string> precedences={"all"}) const;
303
304 template <typename T>
305 T get(const std::string key) const {
306 const QCParameter& parameter = get_parameter(key);
308 if (std::is_same<T, std::string>::value) {
309 return fromstring<T>(add_quotes(parameter.get_value()));
310 }
311 return fromstring<T>(parameter.get_value());
312 }
313
314 bool is_user_defined(std::string key) const {
315 return get_parameter(key).is_user_defined();
316 }
317
318 template <typename Archive>
319 void serialize(Archive& ar) {
320 ar & parameters & print_debug;
321 }
322
323 hashT hash() const {
324 return hash_range(parameters.begin(), parameters.end());
325 }
326
327 protected:
328 typedef std::map<std::string, QCParameter> ParameterContainerT;
330
332 const commandlineparser& parser,
333 const std::string tag) {
334 try {
335 // check that user-defined input files actually exist
336 bool file_ok = true;
337 if (parser.key_exists("user_defined_input_file")) file_ok = file_exists(world, parser.value("input"));
338 if (file_ok) read_input(world, parser.value("input"), tag);
339 else {
340 std::string msg = "could not find user-defined input file: " + parser.value("input") + "\n";
341 throw std::invalid_argument(msg);
342 }
343 }
344 catch (std::invalid_argument& e) {
345 throw;
346 } catch (std::exception& e) {
347 madness::print(e.what());
348 }
349 read_commandline_options(world, parser, tag);
350 }
351
352 public:
353 bool file_exists(World& world, std::string filename) const;
354
355 private:
356 /// read the parameters from file
357
358 /// only world.rank()==0 reads the input file and broadcasts to all other nodes,
359 /// so we don't need to serialize the ParameterMap
360 void read_input(World& world, const std::string filename, const std::string tag);
361
362 void read_commandline_options(World& world, const commandlineparser& parser, const std::string tag);
363
364 protected:
365 bool print_debug = false;
369
370 /// ctor for testing
372
373 /// copy ctor
377
378 /// destructor
380
381 template <typename T>
382 void initialize(const std::string& key, const T& value, const std::string comment = "",
383 const std::vector<T> allowed_values = {}) {
384 if (parameters.find(key) != parameters.end()) {
385 madness::print("you cannot initialize a parameter twice: ", key);
386 throw std::runtime_error("initialization error");
387 }
388
389 std::string svalue = tostring(value);
390 std::string type = std::type_index(typeid(T)).name();
391
392 // transform everything to lower case
393 std::string key_lower = key;
394 std::transform(key_lower.begin(), key_lower.end(), key_lower.begin(), ::tolower);
395 std::transform(svalue.begin(), svalue.end(), svalue.begin(), ::tolower);
396 std::vector<std::string> av_lower_vec;
397 for (const T& av : allowed_values) {
398 std::string av_lower = tostring(av);
399 std::transform(av_lower.begin(), av_lower.end(), av_lower.begin(), ::tolower);
400 av_lower_vec.push_back(av_lower);
401 }
402
403 parameters.insert(std::make_pair<std::string, QCParameter>
404 (std::string(key_lower), QCParameter(svalue, type, comment, av_lower_vec)));
405 }
406
407 public:
408 template <typename T>
409 void set_derived_value(const std::string& key, const T& value) {
412 throw std::runtime_error("type error in set_derived_value for key " + key);
413 }
414 parameter.set_derived_value(tostring(value));
415 }
416
420
421 protected:
422 /// helper function for try_setting_user_defined_value
423 template <typename Tuple, std::size_t... I>
424 bool try_setting_any_impl(const std::string& key, const std::string& value, Tuple, std::index_sequence<I...>) {
425 bool success = false;
426 (void)std::initializer_list<int>{
428 };
429 return success;
430 }
431
432 /// helper function for try_setting_user_defined_value
433 template <typename Tuple>
434 bool try_setting_any(const std::string& key, const std::string& value) {
435 return try_setting_any_impl(key, value, Tuple{}, std::make_index_sequence<std::tuple_size<Tuple>::value>{});
436 }
437
438 /// helper function for try_setting_user_defined_value
439 template <typename T>
440 bool try_setting_user_defined_value(const std::string& key, const std::string& val) {
441 if (not check_type_silent<T>(get_parameter(key))) return false;
442
443 if (print_debug) ::madness::print("key:", key, "will set type", std::type_index(typeid(T)).name());
444 T value = fromstring<T>(val);
445 set_user_defined_value<T>(key, value);
446 return true;
447 }
448
449 public:
450
451 template <typename... Types>
452 bool try_set_from_json(QCParameter& parameter, const nlohmann::json& value) {
453 bool success = false;
454 (void)std::initializer_list<int>{
455 (parameter.get_type() == std::type_index(typeid(Types)).name()
456 ? (parameter.set_user_defined_value(QCCalculationParametersBase::tostring(value.get<Types>())), success = true, 0)
457 : 0)...
458 };
459 return success;
460 }
461
462 void from_json(const json& j) {
463 for (const auto& [key, value1] : j.items()) {
464 const auto& value = value1; // avoid shadowing
467 bool ok = false;
468 std::apply([&](auto&&... args) {
469 ok = try_set_from_json<std::decay_t<decltype(args)>...>(parameter, value);
470 }, all_types{});
471 if (!ok) {
472 throw std::runtime_error("Unsupported parameter type for key: " + key);
473 }
474 }
475 }
476 // Helper to forward tuple types to qcparameter_to_json
477 template <typename... Types>
478 void qcparameter_to_json(json& j, const std::pair<std::string, QCParameter>& p,
479 const std::tuple<Types...>&) const {
480 (void)std::initializer_list<int>{
481 (check_type_silent<Types>(p.second) ? (j[p.first] = get<Types>(p.first), 0) : 0)...
482 };
483 }
484
485 // Helper to forward tuple types to qcparameter_to_json
486 template <typename Tuple>
487 void qcparameter_to_json_from_tuple(json& j, const std::pair<std::string, QCParameter>& p, const Tuple&) const {
488 std::apply([&](auto&&... args) {
489 qcparameter_to_json(j, p, std::tuple<std::decay_t<decltype(args)>...>{});
490 }, Tuple{});
491 }
492
493 /// convert all parameters to a json object
494 [[nodiscard]] json to_json() const {
495 json j_params = {};
497 return j_params;
498 }
499
500 /// convert all parameters to a json object
501 void to_json(json& j) const {
502 json j_params = {};
503 for (auto& p : parameters) {
505 }
506 j["parameters"] = j_params;
507 }
508
509 /// convert all parameters to a json object, but only those with a given precedence
511 const std::string& precedence) const {
512 json j_params = {};
513 for (auto& p : parameters) {
514 if (p.second.print_precedence() == precedence) {
516 }
517 }
518 return j_params;
519 }
520
521 template <typename T>
522 void set_user_defined_value(const std::string& key, const T& value) {
525 throw std::runtime_error("type error in set_user_defined_value");
526 }
527
528 parameter.set_user_defined_value(tostring(value));
529 }
530
531 friend bool operator==(const QCCalculationParametersBase& p1,
533
534 protected:
535 const QCParameter& get_parameter(const std::string& key) const {
536 if (not parameter_exists(key)) {
537 throw std::runtime_error("could not find parameter for key " + key);
538 }
539 const QCParameter& parameter = parameters.find(key)->second;
540 return parameter;
541 }
542
543 public:
544 QCParameter& get_parameter(const std::string key) {
545 if (not parameter_exists(key)) {
546 madness::print("\ncould not find parameter for key", key, "\n");
547 throw std::runtime_error("could not find parameter for key " + key);
548 }
549 QCParameter& parameter = parameters.find(key)->second;
550 return parameter;
551 }
552
553 bool parameter_exists(const std::string& key) const {
554 return (parameters.find(key) != parameters.end());
555 }
556
557 template <typename T>
558 static bool check_type(const std::string key, const QCParameter& parameter) {
560 return true;
561
563 "trying to get the wrong type in QCCalculationParametersBase");
564 madness::print("key ", key);
565 madness::print("parameter type ", parameter.get_type());
566 madness::print("setting type ", std::type_index(typeid(T)).name());
567 madness::print("value ", parameter.get_value());
568 return false;
569 }
570
571 template <typename T>
573 return (parameter.get_type() == std::type_index(typeid(T)).name());
574 }
575
576 /// read the stream, starting from tag
577
578 /// only parameters that are defined in the constructor will be processed,
579 /// all others will be discarded.
580 virtual void read_internal(World& world, std::string& filecontents,
581 std::string tag);
582
583 static std::string tostring(const bool& arg) {
584 std::ostringstream ss;
585 ss << std::boolalpha << arg;
586 return ss.str();
587 }
588
589 template <typename T>
590 static std::string tostring(const T& arg) {
591 using madness::operators::operator<<;
592 std::ostringstream ss;
593 static_assert(not std::is_same<T, bool>::value, "you need to specialize tostring for this type");
594
595 ss << std::scientific << std::setprecision(4) << arg;
596 std::string str = ss.str();
597 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
598
599 overwrite_if_inf(str, arg);
600 return str;
601 }
602
603 template <typename T>
604 static typename std::enable_if<std::is_floating_point<T>::value, void>::type
605 overwrite_if_inf(std::string& str, const T& arg) {
607 MADNESS_PRAGMA_CLANG(diagnostic ignored "-Wtautological-constant-compare")
608 if (std::isinf(arg)) {
609 std::stringstream ss;
611 str = ss.str();
612 }
614 }
615
616 template <typename T>
617 static typename std::enable_if<!std::is_floating_point<T>::value, void>::type
618 overwrite_if_inf(std::string& str, const T& arg) {
619 return;
620 }
621
622 template <typename T>
623 static typename std::enable_if<!std::is_same<T, bool>::value, T>::type
624 fromstring(const std::string& arg) {
625 std::stringstream ssvalue(arg);
626
627 // if argument is std::string read the everything between possible double quotes
628 T result = read_quotes<T>(ssvalue);
629
630 bool type_conversion_failed = ssvalue.fail();
631
632 // check for infinity in floating point conversions
633 if (type_conversion_failed and (std::is_floating_point<T>::value)) {
634 const static T inf = std::numeric_limits<T>::infinity();
635 std::string sinf = tostring(inf); // repeat type conversion from above
636 if (sinf == arg)
637 result = inf;
639 }
640
642 std::string errmsg = "error in type conversion for argument >> " + arg +
643 " << to type " + std::type_index(typeid(T)).name();
644 throw std::runtime_error(errmsg);
645 }
646
647 // check for trailing characters
648 std::string word;
649 while (ssvalue >> word) {
650 std::string errmsg = "trailing characters in arguement >> " + arg + " <<";
651 throw std::runtime_error(errmsg);
652 }
653 return result;
654 }
655
656 template <typename T>
657 static typename std::enable_if<std::is_same<T, std::string>::value, T>::type
658 read_quotes(std::stringstream& ssvalue) {
659 T arg = ssvalue.str();
660 T result;
661
662 if (arg.find("\"") == std::string::npos) { // no double quotes found
663 ssvalue >> result;
664 }
665 else { // found double quotes
666 int counter = 0;
667 while (counter < 2) {
668 T tmp;
669 ssvalue >> tmp;
670 if (ssvalue.fail()) {
671 std::string errmsg = "missing closing double quote in line >> " + arg;
672 throw std::runtime_error(errmsg);
673 }
674 result += " " + tmp;
675 counter = std::count(result.begin(), result.end(), '"');
676 }
677
678 // use only the text between the double quotes
679 result = trim_blanks(trim_quotes(result));
680 }
681 return result;
682 }
683
684 static std::string trim_blanks(const std::string arg) {
685 std::size_t first = arg.find_first_not_of(' ');
686 std::size_t last = arg.find_last_not_of(' ');
687 return arg.substr(first, last - first + 1);
688 }
689
690 static std::string trim_quotes(const std::string arg) {
691 std::size_t first = arg.find_first_of('"');
692 std::size_t last = arg.find_last_of('"');
693 return arg.substr(first + 1, last - first - 1);
694 }
695
696 static std::string add_quotes(const std::string arg) {
697 return "\"" + arg + "\"";
698 }
699
700 template <typename T>
701 static typename std::enable_if<!std::is_same<T, std::string>::value, T>::type
702 read_quotes(std::stringstream& ssvalue) {
703 T result;
704 ssvalue >> result;
705 return result;
706 }
707
708 template <typename T>
709 static typename std::enable_if<std::is_same<T, bool>::value, T>::type
710 fromstring(const std::string& arg) {
711 std::string str = arg;
712 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
713 if (str == "true" or str == "1" or str == "yes")
714 return true;
715 if (str == "false" or str == "0" or str == "no")
716 return false;
717 std::string errmsg = "error in type conversion for argument >> " + arg +
718 " << to type " + std::type_index(typeid(T)).name();
719 throw std::runtime_error(errmsg);
720 return 0;
721 }
722
723
724 // a templated list of all acceptable parameter types for looping in a parameter pack
725 using all_parameter_types = std::tuple<
726 double, int, unsigned int, long, std::size_t, bool, std::string,
727 std::vector<double>, std::vector<int>, std::vector<std::size_t>,
728 std::vector<std::string>, std::pair<std::string, double>>;
729 };
730
733} /* namespace madness */
734
735#endif /* SRC_APPS_CHEM_QCCALCULATIONPARAMETERSBASE_H_ */
Interface templates for the archives (serialization).
class for holding the parameters for calculation
Definition QCCalculationParametersBase.h:295
static bool check_type_silent(const QCParameter &parameter)
Definition QCCalculationParametersBase.h:572
std::tuple< double, int, unsigned int, long, std::size_t, bool, std::string, std::vector< double >, std::vector< int >, std::vector< std::size_t >, std::vector< std::string >, std::pair< std::string, double > > all_parameter_types
Definition QCCalculationParametersBase.h:728
static std::enable_if< std::is_same< T, std::string >::value, T >::type read_quotes(std::stringstream &ssvalue)
Definition QCCalculationParametersBase.h:658
void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition QCCalculationParametersBase.h:331
ParameterContainerT get_all_parameters() const
Definition QCCalculationParametersBase.h:417
static std::string tostring(const T &arg)
Definition QCCalculationParametersBase.h:590
hashT hash() const
Definition QCCalculationParametersBase.h:323
friend bool operator==(const QCCalculationParametersBase &p1, const QCCalculationParametersBase &p2)
Definition QCCalculationParametersBase.cc:190
static std::enable_if< std::is_floating_point< T >::value, void >::type overwrite_if_inf(std::string &str, const T &arg)
Definition QCCalculationParametersBase.h:605
static std::enable_if<!std::is_floating_point< T >::value, void >::type overwrite_if_inf(std::string &str, const T &arg)
Definition QCCalculationParametersBase.h:618
void qcparameter_to_json(json &j, const std::pair< std::string, QCParameter > &p, const std::tuple< Types... > &) const
Definition QCCalculationParametersBase.h:478
bool throw_if_datagroup_not_found
Definition QCCalculationParametersBase.h:368
bool try_setting_any_impl(const std::string &key, const std::string &value, Tuple, std::index_sequence< I... >)
helper function for try_setting_user_defined_value
Definition QCCalculationParametersBase.h:424
void set_user_defined_value(const std::string &key, const T &value)
Definition QCCalculationParametersBase.h:522
bool print_debug
Definition QCCalculationParametersBase.h:365
const QCParameter & get_parameter(const std::string &key) const
Definition QCCalculationParametersBase.h:535
json to_json() const
convert all parameters to a json object
Definition QCCalculationParametersBase.h:494
void to_json(json &j) const
convert all parameters to a json object
Definition QCCalculationParametersBase.h:501
void qcparameter_to_json_from_tuple(json &j, const std::pair< std::string, QCParameter > &p, const Tuple &) const
Definition QCCalculationParametersBase.h:487
virtual void read_internal(World &world, std::string &filecontents, std::string tag)
read the stream, starting from tag
Definition QCCalculationParametersBase.cc:122
void read_input(World &world, const std::string filename, const std::string tag)
read the parameters from file
Definition QCCalculationParametersBase.cc:74
std::string print_to_string(const std::list< std::string > precedences={"all"}) const
Definition QCCalculationParametersBase.cc:31
void read_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
read the parameters from the command line and broadcast
Definition QCCalculationParametersBase.cc:100
bool parameter_exists(const std::string &key) const
Definition QCCalculationParametersBase.h:553
T get(const std::string key) const
Definition QCCalculationParametersBase.h:305
bool try_set_from_json(QCParameter &parameter, const nlohmann::json &value)
Definition QCCalculationParametersBase.h:452
void initialize(const std::string &key, const T &value, const std::string comment="", const std::vector< T > allowed_values={})
Definition QCCalculationParametersBase.h:382
void print(const std::string header="", const std::string footer="") const
print all parameters
Definition QCCalculationParametersBase.cc:22
void from_json(const json &j)
Definition QCCalculationParametersBase.h:462
bool ignore_unknown_keys
Definition QCCalculationParametersBase.h:366
bool file_exists(World &world, std::string filename) const
Definition QCCalculationParametersBase.cc:62
static std::string tostring(const bool &arg)
Definition QCCalculationParametersBase.h:583
QCCalculationParametersBase(const QCCalculationParametersBase &other)
copy ctor
Definition QCCalculationParametersBase.h:374
static std::enable_if<!std::is_same< T, std::string >::value, T >::type read_quotes(std::stringstream &ssvalue)
Definition QCCalculationParametersBase.h:702
bool ignore_unknown_keys_silently
Definition QCCalculationParametersBase.h:367
QCParameter & get_parameter(const std::string key)
Definition QCCalculationParametersBase.h:544
bool is_user_defined(std::string key) const
Definition QCCalculationParametersBase.h:314
void serialize(Archive &ar)
Definition QCCalculationParametersBase.h:319
bool try_setting_user_defined_value(const std::string &key, const std::string &val)
helper function for try_setting_user_defined_value
Definition QCCalculationParametersBase.h:440
json to_json_if_precedence(const std::string &precedence) const
convert all parameters to a json object, but only those with a given precedence
Definition QCCalculationParametersBase.h:510
bool try_setting_any(const std::string &key, const std::string &value)
helper function for try_setting_user_defined_value
Definition QCCalculationParametersBase.h:434
static std::string trim_blanks(const std::string arg)
Definition QCCalculationParametersBase.h:684
ParameterContainerT parameters
Definition QCCalculationParametersBase.h:329
std::map< std::string, QCParameter > ParameterContainerT
Definition QCCalculationParametersBase.h:328
static bool check_type(const std::string key, const QCParameter &parameter)
Definition QCCalculationParametersBase.h:558
static std::string add_quotes(const std::string arg)
Definition QCCalculationParametersBase.h:696
static std::enable_if< std::is_same< T, bool >::value, T >::type fromstring(const std::string &arg)
Definition QCCalculationParametersBase.h:710
static std::enable_if<!std::is_same< T, bool >::value, T >::type fromstring(const std::string &arg)
Definition QCCalculationParametersBase.h:624
virtual ~QCCalculationParametersBase()
destructor
Definition QCCalculationParametersBase.h:379
static std::string trim_quotes(const std::string arg)
Definition QCCalculationParametersBase.h:690
void set_derived_value(const std::string &key, const T &value)
Definition QCCalculationParametersBase.h:409
QCCalculationParametersBase()
ctor for testing
Definition QCCalculationParametersBase.h:371
virtual std::string get_tag() const =0
A parallel world class.
Definition world.h:132
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:28
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition tensor.h:2503
static const double v
Definition hatom_sf_dirac.cc:20
Macros and tools pertaining to the configuration of MADNESS.
#define MADNESS_PRAGMA_CLANG(x)
Definition madness_config.h:200
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Header to declare stuff which has not yet found a home.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void hash_range(hashT &seed, It first, It last)
Definition worldhash.h:280
static const char * filename
Definition legendre.cc:96
bool operator!=(const ResponseParameters &p1, const ResponseParameters &p2)
Definition response_parameters.cpp:13
nlohmann::json json
Definition QCCalculationParametersBase.h:29
static std::enable_if< std::is_floating_point< T >::value, void >::type check_for_inf(const std::string &str, T &arg)
Definition QCCalculationParametersBase.h:33
static double pop(std::vector< double > &v)
Definition SCF.cc:115
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:226
std::istream & operator>>(std::istream &is, PairType &en)
Definition PNOParameters.cpp:24
std::size_t hashT
The hash value type.
Definition worldhash.h:145
std::string type(const PairType &n)
Definition PNOParameters.h:18
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition array_addons.h:78
double Q(double a)
Definition relops.cc:20
static const double c
Definition relops.cc:10
structure holding the value for a given parameter
Definition QCCalculationParametersBase.h:124
int print_order
Definition QCCalculationParametersBase.h:278
bool operator==(const QCParameter &other) const
Definition QCCalculationParametersBase.h:234
std::vector< std::string > allowed_values
Definition QCCalculationParametersBase.h:277
std::string print_line(const std::string &key) const
Definition QCCalculationParametersBase.h:168
QCParameter()
Definition QCCalculationParametersBase.h:126
enum madness::QCParameter::@0 precedence
QCParameter(const std::string v, const std::string t, const std::string comment="", const std::vector< std::string > allowed_values1={})
Definition QCCalculationParametersBase.h:128
int get_print_order() const
Definition QCCalculationParametersBase.h:166
std::string default_value
Definition QCCalculationParametersBase.h:271
std::string not_allowed_errmsg() const
Definition QCCalculationParametersBase.h:259
void serialize(Archive &ar)
Definition QCCalculationParametersBase.h:227
std::string user_defined_value
Definition QCCalculationParametersBase.h:273
@ derived
Definition QCCalculationParametersBase.h:232
@ defined
Definition QCCalculationParametersBase.h:232
@ def
Definition QCCalculationParametersBase.h:232
void set_all()
Definition QCCalculationParametersBase.h:246
bool check_allowed()
Definition QCCalculationParametersBase.h:253
std::string get_comment() const
Definition QCCalculationParametersBase.h:154
void set_user_defined_value(const std::string val)
Definition QCCalculationParametersBase.h:142
std::string type
Definition QCCalculationParametersBase.h:274
std::string print_precedence() const
Definition QCCalculationParametersBase.h:156
std::string value
Definition QCCalculationParametersBase.h:270
std::string derived_value
Definition QCCalculationParametersBase.h:272
std::string get_type() const
Definition QCCalculationParametersBase.h:153
std::string comment
Definition QCCalculationParametersBase.h:276
bool is_user_defined() const
Definition QCCalculationParametersBase.h:148
std::string null
Definition QCCalculationParametersBase.h:275
std::string get_value() const
Definition QCCalculationParametersBase.h:152
void set_derived_value(const std::string val)
Definition QCCalculationParametersBase.h:136
hashT hash() const
Definition QCCalculationParametersBase.h:241
very simple command line parser
Definition commandlineparser.h:15
std::string value(const std::string key) const
Definition commandlineparser.h:62
bool key_exists(std::string key) const
Definition commandlineparser.h:58
static std::vector< std::string > split(std::string s, const std::string delimiter)
split a string s into a vector of strings, using delimiter
Definition commandlineparser.h:94
static const double_complex I
Definition tdse1d.cc:164
std::string ok(const bool b)
Definition test6.cc:43
void errmsg(const char *msg, int status)
Definition test_hashthreaded.cc:54
void e()
Definition test_sig.cc:75
Declares the World class for the parallel runtime environment.