| [999eaf] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2021 Frederik Heber. All rights reserved. | 
|---|
|  | 5 | * | 
|---|
|  | 6 | * | 
|---|
|  | 7 | *   This file is part of MoleCuilder. | 
|---|
|  | 8 | * | 
|---|
|  | 9 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
|  | 10 | *    it under the terms of the GNU General Public License as published by | 
|---|
|  | 11 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
|  | 12 | *    (at your option) any later version. | 
|---|
|  | 13 | * | 
|---|
|  | 14 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
|  | 15 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 16 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 17 | *    GNU General Public License for more details. | 
|---|
|  | 18 | * | 
|---|
|  | 19 | *    You should have received a copy of the GNU General Public License | 
|---|
|  | 20 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
|  | 21 | */ | 
|---|
|  | 22 |  | 
|---|
|  | 23 | /* | 
|---|
|  | 24 | * EvaluateStabilityAction.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: Apr 18, 2021 | 
|---|
|  | 27 | *      Author: heber | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
|  | 30 | // include config.h | 
|---|
|  | 31 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 32 | #include <config.h> | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
|  | 35 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include "CodePatterns/Log.hpp" | 
|---|
|  | 38 |  | 
|---|
|  | 39 | #include <boost/filesystem.hpp> | 
|---|
|  | 40 |  | 
|---|
|  | 41 | #include "Fragmentation/Evaluation/StabilityEvaluator.hpp" | 
|---|
|  | 42 | #include "World.hpp" | 
|---|
|  | 43 |  | 
|---|
|  | 44 | #include "Actions/FragmentationAction/EvaluateStabilityAction.hpp" | 
|---|
|  | 45 |  | 
|---|
|  | 46 | using namespace MoleCuilder; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | // and construct the stuff | 
|---|
|  | 49 | #include "EvaluateStabilityAction.def" | 
|---|
|  | 50 | #include "Action_impl_pre.hpp" | 
|---|
|  | 51 | /** =========== define the function ====================== */ | 
|---|
|  | 52 | ActionState::ptr FragmentationEvaluateStabilityAction::performCall() { | 
|---|
|  | 53 |  | 
|---|
|  | 54 | if (World::getConstInstance().countSelectedMolecules() != 1) { | 
|---|
|  | 55 | STATUS("Exactly one molecule needs to be selected."); | 
|---|
|  | 56 | return Action::failure; | 
|---|
|  | 57 | } | 
|---|
|  | 58 | const molecule *mol = *(World::getConstInstance().getSelectedMolecules().begin()); | 
|---|
|  | 59 |  | 
|---|
|  | 60 | // evaluate | 
|---|
|  | 61 | const StabilityEvaluator evaluator(mol); | 
|---|
|  | 62 | const StabilityEvaluator::stabilities_t stabilities = evaluator(); | 
|---|
|  | 63 |  | 
|---|
|  | 64 | // write to file | 
|---|
|  | 65 | const std::string outputfilename = params.outputFilename.get().string(); | 
|---|
|  | 66 | LOG(1, "INFO: Stability criterions are "+toString(stabilities)); | 
|---|
|  | 67 | { | 
|---|
|  | 68 | std::ofstream outputstream(outputfilename.c_str()); | 
|---|
|  | 69 | const char separator = '\t'; | 
|---|
|  | 70 | if (outputstream.good()) { // check if opened | 
|---|
|  | 71 | // write header | 
|---|
|  | 72 | outputstream << "educt1\teduct2\tenergy_educts\tproduct1\tproduct2\tenergy_products" << std::endl; | 
|---|
|  | 73 | for (StabilityEvaluator::stabilities_t::const_iterator iter = stabilities.begin(); | 
|---|
|  | 74 | iter != stabilities.end(); ++iter) { | 
|---|
|  | 75 | outputstream << iter->formula_educt1 << separator; | 
|---|
|  | 76 | outputstream << iter->formula_educt2 << separator; | 
|---|
|  | 77 | outputstream << iter->energy_educts << separator; | 
|---|
|  | 78 | outputstream << iter->formula_product1 << separator; | 
|---|
|  | 79 | outputstream << iter->formula_product2 << separator; | 
|---|
|  | 80 | outputstream << iter->energy_products << std::endl; | 
|---|
|  | 81 | } | 
|---|
|  | 82 | if (outputstream.fail()) { // check if correctly written | 
|---|
|  | 83 | STATUS("Failed to write to file "+outputfilename+"."); | 
|---|
|  | 84 | return Action::failure; | 
|---|
|  | 85 | } else | 
|---|
|  | 86 | outputstream.close(); | 
|---|
|  | 87 | } else { | 
|---|
|  | 88 | STATUS("Failed to open file "+outputfilename+" for writing."); | 
|---|
|  | 89 | return Action::failure; | 
|---|
|  | 90 | } | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | return Action::success; | 
|---|
|  | 94 | } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | ActionState::ptr FragmentationEvaluateStabilityAction::performUndo(ActionState::ptr _state) { | 
|---|
|  | 97 | return Action::success; | 
|---|
|  | 98 | } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | ActionState::ptr FragmentationEvaluateStabilityAction::performRedo(ActionState::ptr _state){ | 
|---|
|  | 101 | return Action::success; | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | bool FragmentationEvaluateStabilityAction::canUndo() { | 
|---|
|  | 105 | return true; | 
|---|
|  | 106 | } | 
|---|
|  | 107 |  | 
|---|
|  | 108 | bool FragmentationEvaluateStabilityAction::shouldUndo() { | 
|---|
|  | 109 | return true; | 
|---|
|  | 110 | } | 
|---|
|  | 111 | /** =========== end of function ====================== */ | 
|---|