/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2014 Frederik Heber. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* SavePotentialsAction.cpp
*
* Created on: Sep 12, 2014
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
// include headers that implement a archive in simple text format
// and before MemDebug due to placement new
#include
#include
#include "CodePatterns/MemDebug.hpp"
#include "Actions/PotentialAction/SavePotentialsAction.hpp"
#include
#include
#include "CodePatterns/Log.hpp"
#include "Potentials/Exceptions.hpp"
#include "Potentials/PotentialSerializer.hpp"
using namespace MoleCuilder;
// and construct the stuff
#include "SavePotentialsAction.def"
#include "Action_impl_pre.hpp"
/** =========== define the function ====================== */
ActionState::ptr PotentialSavePotentialsAction::performCall()
{
// store the potentials
if (!params.potential_file.get().string().empty()) {
// print fitted potentials
std::stringstream potentials;
PotentialSerializer serialize(potentials);
serialize();
LOG(1, "STATUS: Resulting parameters are " << std::endl << potentials.str());
std::ofstream returnstream(params.potential_file.get().string().c_str());
if (returnstream.good()) {
returnstream << potentials.str();
} else {
STATUS("Could not open stream to write potentials!");
return Action::failure;
}
} else {
STATUS("No existing potential file given!");
return Action::failure;
}
return Action::success;
}
ActionState::ptr PotentialSavePotentialsAction::performUndo(ActionState::ptr _state) {
STATUS("Undo of PotentialSavePotentialsAction not implemented.");
return Action::failure;
}
ActionState::ptr PotentialSavePotentialsAction::performRedo(ActionState::ptr _state){
STATUS("Redo of PotentialSavePotentialsAction not implemented.");
return Action::failure;
}
bool PotentialSavePotentialsAction::canUndo() {
return false;
}
bool PotentialSavePotentialsAction::shouldUndo() {
return false;
}
/** =========== end of function ====================== */