8 #ifndef SWOOSEUTILITIES_CALCULATOROPTIONS_H
9 #define SWOOSEUTILITIES_CALCULATOROPTIONS_H
15 #include <yaml-cpp/yaml.h>
18 namespace SwooseUtilities {
21 constexpr
const char* qmModelKey =
"qm_model";
22 constexpr
const char* qmModuleKey =
"qm_module";
23 constexpr
const char* mmModelKey =
"mm_model";
24 constexpr
const char* defaultMolecularMechanicsModel =
"SFAM";
33 inline std::string getChosenMMCalculatorOption(YAML::Node& yamlNode) {
34 std::string mmModel = defaultMolecularMechanicsModel;
35 if (yamlNode[mmModelKey]) {
36 mmModel = yamlNode[mmModelKey].as<std::string>();
37 yamlNode.remove(mmModelKey);
40 std::transform(mmModel.begin(), mmModel.end(), mmModel.begin(), ::toupper);
49 inline std::pair<std::string, std::string> getChosenQmCalculatorOption(YAML::Node& yamlNode) {
52 if (yamlNode[qmModelKey]) {
53 qmModel = yamlNode[qmModelKey].as<std::string>();
54 yamlNode.remove(qmModelKey);
56 if (yamlNode[qmModuleKey]) {
57 qmModule = yamlNode[qmModuleKey].as<std::string>();
58 yamlNode.remove(qmModuleKey);
60 if (qmModel.empty() || qmModule.empty())
61 throw std::runtime_error(
"For a QM/MM calculation, one needs to specify the QM model and module.");
64 std::transform(qmModel.begin(), qmModel.end(), qmModel.begin(), ::toupper);
67 std::transform(qmModule.begin(), qmModule.end(), qmModule.begin(), ::tolower);
68 qmModule.at(0) = std::toupper(qmModule.at(0));
70 return {qmModel, qmModule};
80 inline void fillQmmmCalculatorWithUnderlyingCalculators(std::shared_ptr<Scine::Qmmm::QmmmCalculator>& qmmmCalculator,
81 YAML::Node& yamlNode) {
82 std::string methodFamilies, programs;
84 if (yamlNode[qmModelKey]) {
85 methodFamilies = yamlNode[qmModelKey].as<std::string>() +
'/' + defaultMolecularMechanicsModel;
87 else if (yamlNode[Utils::SettingsNames::methodFamily]) {
88 methodFamilies = yamlNode[Utils::SettingsNames::methodFamily].as<std::string>();
89 if (methodFamilies.find(
'/') == std::string::npos) {
90 methodFamilies +=
"/" + std::string(defaultMolecularMechanicsModel);
94 throw std::runtime_error(
"Please provide two method families for a QM/MM calculation.\n"
95 "For instance, method_family: PM6/SFAM and program: Sparrow/Swoose");
97 if (yamlNode[qmModuleKey]) {
98 programs = yamlNode[qmModuleKey].as<std::string>() +
'/' +
"Swoose";
100 else if (yamlNode[Utils::SettingsNames::program]) {
101 programs = yamlNode[Utils::SettingsNames::program].as<std::string>();
102 if (programs.find(
'/') == std::string::npos) {
103 programs +=
"/" + std::string(
"Swoose");
107 programs =
"Any/Swoose";
110 "The QM/MM calculator could not be loaded via the module system.\nCheck: (i) whether the requested "
111 "calculators are available (see manual), (ii) that you have installed all "
112 "relevant modules, and (iii) that all necessary environment variables are set (e.g., ORCA_BINARY_PATH or "
115 auto loadedCalc = Utils::CalculationRoutines::getCalculator(methodFamilies, programs);
117 throw std::runtime_error(error);
118 auto castedCalc = std::dynamic_pointer_cast<Qmmm::QmmmCalculator>(loadedCalc);
120 throw std::runtime_error(
"The loaded calculator is not a QM/MM calculator.");
121 qmmmCalculator = castedCalc;
123 catch (
const std::runtime_error& e) {
124 std::cerr << e.what() << std::endl;
125 throw std::runtime_error(error);
132 #endif // SWOOSEUTILITIES_CALCULATOROPTIONS_H