/*
* 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 .
*/
/*
* ParsePotentialsAction.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/ParsePotentialsAction.hpp"
#include
#include
#include "CodePatterns/Log.hpp"
#include "Potentials/EmpiricalPotential.hpp"
#include "Potentials/Exceptions.hpp"
#include "Potentials/PotentialFactory.hpp"
#include "Potentials/PotentialRegistry.hpp"
#include "Potentials/RegistryDeserializer.hpp"
using namespace MoleCuilder;
// and construct the stuff
#include "ParsePotentialsAction.def"
#include "Action_impl_pre.hpp"
/** =========== define the function ====================== */
ActionState::ptr PotentialParsePotentialsAction::performCall()
{
if (boost::filesystem::exists(params.potential_file.get())) {
std::ifstream returnstream(params.potential_file.get().string().c_str());
if (returnstream.good()) {
std::string linestring;
std::string token;
while (returnstream.good()) {
getline(returnstream, linestring);
const std::string comment("#");
if (linestring.find(comment) != std::string::npos) {
LOG(4, "DEBUG: Skippeing comment line:"+linestring);
continue;
}
const std::string whitespace(" \t");
const size_t strBegin = linestring.find_first_not_of(whitespace);
const size_t curlyopenpos = linestring.find("{");
const size_t curlyclosedpos = linestring.find("}");
if (curlyopenpos != std::string::npos) {
// begin of new type section
token = linestring.substr(strBegin, curlyopenpos);
const size_t tokenEnd = token.find_first_of(whitespace);
token = token.substr(0, tokenEnd);
LOG(1, "INFO: Token is " << token);
const type_name_map_t::right_const_iterator tokeniter = TypeNameMap.right.find(token);
ASSERT( tokeniter != TypeNameMap.right.end(),
"PotentialParsePotentialsAction::performCall() - could not find type to "
+toString(token)+".");
const tokentype_t tokentype = tokeniter->second;
// get either particles {} or potentials {}
switch (tokentype) {
case particles:
{
if (!parseItems(
returnstream,
ParticleFactory::getInstance(),
ParticleRegistry::getInstance(),
std::string("particle")))
return Action::failure;
break;
}
case bonds:
case angles:
case torsions:
case impropers:
case nonbonded_2body_potentials:
{
if (!parseItems(
returnstream,
PotentialFactory::getInstance(),
PotentialRegistry::getInstance(),
std::string("potential")))
return Action::failure;
break;
}
default:
ASSERT( 0,
"PotentialParsePotentialsAction::performCall() - token type "
+toString(tokentype)+" is unknown.");
}
} else if (curlyclosedpos != std::string::npos) {
// section end encountered, just read next line
} else {
ELOG(0, "Parser confused, neither curly open nor curly closed on line "
<< linestring);
return Action::failure;
}
}
} else {
STATUS("Failed to parse from "+params.potential_file.get().string()+".");
return Action::failure;
}
returnstream.close();
LOG(0, "STATUS: Parsed a set of potentials parsed from "
<< params.potential_file.get().string() << ".");
} else {
STATUS("No existing potential file given!");
return Action::failure;
}
return Action::success;
}
ActionState::ptr PotentialParsePotentialsAction::performUndo(ActionState::ptr _state) {
STATUS("Undo of PotentialParsePotentialsAction not implemented.");
return Action::failure;
}
ActionState::ptr PotentialParsePotentialsAction::performRedo(ActionState::ptr _state){
STATUS("Redo of PotentialParsePotentialsAction not implemented.");
return Action::failure;
}
bool PotentialParsePotentialsAction::canUndo() {
return false;
}
bool PotentialParsePotentialsAction::shouldUndo() {
return false;
}
/** =========== end of function ====================== */