8 #ifndef SWOOSE_TASKMANAGEMENT_H
9 #define SWOOSE_TASKMANAGEMENT_H
13 #include <Core/ModuleManager.h>
21 #include <yaml-cpp/yaml.h>
25 namespace TaskManagement {
33 std::shared_ptr<Core::Calculator> getMmCalculatorFromModel(std::string mmModel, Core::ModuleManager& manager) {
34 std::shared_ptr<Core::Calculator> calculator;
36 calculator = manager.get<Core::Calculator>(mmModel);
38 catch (
const std::runtime_error& e) {
39 throw std::runtime_error(
"MM model could not be loaded via the module system.");
54 void manageTasks(Core::ModuleManager& manager, std::string mode,
bool quantum,
bool hessianRequired,
55 std::string structureFile, YAML::Node& yamlNode, std::string yamlSettingsPath, Core::Log& log) {
61 if (mode ==
"calculate" && !quantum) {
62 auto mmModel = SwooseUtilities::getChosenMMCalculatorOption(yamlNode);
63 auto calculator = getMmCalculatorFromModel(mmModel, manager);
64 calculator->setLog(log);
65 Utils::nodeToSettings(calculator->settings(), yamlNode,
false);
66 Utils::PropertyList properties = Utils::Property::Energy | Utils::Property::Gradients;
68 properties = Utils::Property::Energy | Utils::Property::Gradients | Utils::Property::Hessian;
69 Tasks::runMMCalculationTask(*calculator, structureFile, properties, log);
71 else if (mode ==
"calculate") {
72 std::shared_ptr<Qmmm::QmmmCalculator> calculator;
73 SwooseUtilities::fillQmmmCalculatorWithUnderlyingCalculators(calculator, yamlNode);
74 calculator->setLog(log);
75 Utils::PropertyList properties = Utils::Property::Energy | Utils::Property::Gradients;
76 Tasks::runQmmmCalculationTask(*calculator, structureFile, properties, log, yamlNode);
78 else if (mode ==
"parametrize") {
79 std::shared_ptr<Core::MMParametrizer> parametrizer;
81 parametrizer = manager.get<Core::MMParametrizer>(
"SFAM_parametrizer");
83 catch (
const std::runtime_error& e) {
84 throw std::runtime_error(
"The SFAM parametrizer could not be loaded via the module system.");
86 parametrizer->setLog(log);
87 Utils::nodeToSettings(parametrizer->settings(), yamlNode,
true);
88 parametrizer->settings().modifyString(SwooseUtilities::SettingsNames::yamlSettingsFilePath, yamlSettingsPath);
89 Tasks::runSFAMParametrizationTask(*parametrizer, structureFile, log);
91 else if (mode ==
"md" && !quantum) {
92 auto mmModel = SwooseUtilities::getChosenMMCalculatorOption(yamlNode);
93 auto calculator = getMmCalculatorFromModel(mmModel, manager);
94 calculator->setLog(warningLog);
95 Utils::nodeToSettings(calculator->settings(), yamlNode,
true);
96 Utils::MolecularDynamics molecularDynamics(*calculator);
97 Utils::nodeToSettings(molecularDynamics.settings(), yamlNode,
true);
98 molecularDynamics.settings().normalizeStringCases();
99 Tasks::runMDSimulationTask(molecularDynamics, structureFile, log);
101 else if (mode ==
"md") {
102 std::shared_ptr<Qmmm::QmmmCalculator> calculator;
103 calculator->setLog(warningLog);
104 SwooseUtilities::fillQmmmCalculatorWithUnderlyingCalculators(calculator, yamlNode);
105 Utils::nodeToSettings(calculator->settings(), yamlNode,
true);
106 Utils::MolecularDynamics molecularDynamics(*calculator);
107 Utils::nodeToSettings(molecularDynamics.settings(), yamlNode,
true);
108 Tasks::runMDSimulationTask(molecularDynamics, structureFile, log);
110 else if (mode ==
"optimize" && !quantum) {
111 auto mmModel = SwooseUtilities::getChosenMMCalculatorOption(yamlNode);
112 auto calculator = getMmCalculatorFromModel(mmModel, manager);
113 calculator->setLog(warningLog);
114 Utils::nodeToSettings(calculator->settings(), yamlNode,
true);
115 auto optimizer = std::make_unique<Utils::GeometryOptimizer<Utils::Bfgs>>(*calculator);
116 auto optSettings = optimizer->getSettings();
117 Utils::nodeToSettings(optSettings, yamlNode,
true);
118 optimizer->setSettings(optSettings);
119 Tasks::runMMOptimizationTask(*calculator, *optimizer, structureFile, log, yamlNode);
121 else if (mode ==
"optimize") {
122 std::shared_ptr<Qmmm::QmmmCalculator> calculator;
123 calculator->setLog(warningLog);
124 SwooseUtilities::fillQmmmCalculatorWithUnderlyingCalculators(calculator, yamlNode);
125 auto optimizer = std::make_unique<Utils::QmmmGeometryOptimizer<Utils::Bfgs>>(*calculator);
126 auto optSettings = optimizer->getSettings();
127 Utils::nodeToSettings(optSettings, yamlNode,
true);
128 optimizer->setSettings(optSettings);
129 Tasks::runQmmmOptimizationTask<Utils::Bfgs>(*calculator, *optimizer, structureFile, log, yamlNode);
131 else if (mode ==
"select_qm") {
132 Tasks::runQmRegionSelectionTask(structureFile, log, yamlNode, yamlSettingsPath);
134 else if (mode ==
"prepare-analyze" || mode ==
"prepare-protonate" || mode ==
"prepare-finalize" || mode ==
"prepare-automate") {
135 auto processor = std::make_unique<Scine::StructurePreparation::StructureProcessor>();
136 Utils::nodeToSettings(processor->settings(), yamlNode,
false);
137 Tasks::runPDBPreparationTask(*processor, structureFile, mode, log);
140 throw std::runtime_error(
141 "Your specified mode is not valid. Options are: parametrize, calculate, md, optimize, and select_qm.");
149 #endif // SWOOSE_TASKMANAGEMENT_H
static SinkPtr cerrSink()