Scine::Swoose  1.0.0
This is the SCINE module Swoose.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
CalculatorOptions.h
Go to the documentation of this file.
1 
8 #ifndef SWOOSEUTILITIES_CALCULATOROPTIONS_H
9 #define SWOOSEUTILITIES_CALCULATOROPTIONS_H
10 
11 #include <Utils/IO/Yaml.h>
12 #include <yaml-cpp/yaml.h>
13 
14 namespace Scine {
15 namespace SwooseUtilities {
16 
17 namespace {
18 constexpr const char* qmModelKey = "qm_model";
19 constexpr const char* qmModuleKey = "qm_module";
20 constexpr const char* mmModelKey = "mm_model";
21 constexpr const char* defaultMolecularMechanicsModel = "SFAM";
22 } // namespace
23 
30 inline std::string getChosenMMCalculatorOption(YAML::Node& yamlNode) {
31  std::string mmModel = defaultMolecularMechanicsModel;
32  if (yamlNode[mmModelKey]) {
33  mmModel = yamlNode[mmModelKey].as<std::string>();
34  yamlNode.remove(mmModelKey);
35  }
36  // capitalize MM model string and return it
37  std::transform(mmModel.begin(), mmModel.end(), mmModel.begin(), ::toupper);
38  return mmModel;
39 }
40 
46 inline std::pair<std::string, std::string> getChosenQmCalculatorOption(YAML::Node& yamlNode) {
47  std::string qmModel;
48  std::string qmModule;
49  if (yamlNode[qmModelKey]) {
50  qmModel = yamlNode[qmModelKey].as<std::string>();
51  yamlNode.remove(qmModelKey);
52  }
53  if (yamlNode[qmModuleKey]) {
54  qmModule = yamlNode[qmModuleKey].as<std::string>();
55  yamlNode.remove(qmModuleKey);
56  }
57  if (qmModel.empty() || qmModule.empty())
58  throw std::runtime_error("For a QM/MM calculation, one needs to specify the QM model and module.");
59 
60  // Capitalize the QM model:
61  std::transform(qmModel.begin(), qmModel.end(), qmModel.begin(), ::toupper);
62 
63  // Convert module to only first letter as uppercase:
64  std::transform(qmModule.begin(), qmModule.end(), qmModule.begin(), ::tolower);
65  qmModule.at(0) = std::toupper(qmModule.at(0));
66 
67  return {qmModel, qmModule};
68 }
69 
70 } // namespace SwooseUtilities
71 } // namespace Scine
72 
73 #endif // SWOOSEUTILITIES_OPTIONNAMES_H