/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2017 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 .
*/
/*
* ChemicalSpaceEvaluator.cpp
*
* Created on: Sep 26, 2017
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
//#include "CodePatterns/MemDebug.hpp"
#include
#include
#include
#include "CodePatterns/Log.hpp"
#include "Actions/GraphAction/ChemicalSpaceEvaluatorAction.hpp"
#include "Element/element.hpp"
#include "Graph/BoostGraphCreator.hpp"
#include "Fragmentation/Homology/HomologyContainer.hpp"
#include "FunctionApproximation/Extractors.hpp"
#include "World.hpp"
#include
using namespace MoleCuilder;
// and construct the stuff
#include "ChemicalSpaceEvaluatorAction.def"
#include "Action_impl_pre.hpp"
/** =========== define the function ====================== */
ActionState::ptr GraphChemicalSpaceEvaluatorAction::performCall() {
// create boost::graph from graph6 string
BoostGraphCreator BGC;
BGC.createFromGraph6String(params.graph_string.get());
BoostGraphCreator::UndirectedGraph graph = BGC.get();
Extractors::index_map_t index_map = boost::get(boost::vertex_index, graph);
LOG(2, "DEBUG: We have " << boost::num_vertices(graph) << " nodes in the fragment graph.");
// associate type with a node index
Extractors::type_index_lookup_t type_index_lookup;
std::vector elementnumbers;
elementnumbers.reserve(params.graph_elements.get().size());
for (std::vector::const_iterator iter = params.graph_elements.get().begin();
iter != params.graph_elements.get().end(); ++iter) {
elementnumbers.push_back((*iter)->getAtomicNumber());
type_index_lookup.left.insert(
std::make_pair(
std::distance(iter, params.graph_elements.get().begin()),
Extractors::ParticleType_t(elementnumbers.back())));
}
// create all induced subgraphs
const size_t nodes_in_graph = boost::num_vertices(graph);
LOG(2, "DEBUG: There are " << nodes_in_graph << " nodes in the graph.");
Extractors::set_of_nodes_t set_of_nodes;
for (size_t nodeid = 0; nodeid < nodes_in_graph; ++nodeid) {
const size_t &rootindex = nodeid;
LOG(2, "DEBUG: Current root index is " << rootindex);
/// 5a. from node in graph (with this index) perform BFS till n-1 (#nodes in binding model)
std::vector distances(boost::num_vertices(graph));
boost::breadth_first_search(
graph,
boost::vertex(rootindex, graph),
boost::visitor(Extractors::record_distance(&distances[0])));
LOG(3, "DEBUG: BFS discovered the following distances " << distances);
/// 5b. and store all node in map with distance to root as key
Extractors::nodes_per_level_t nodes_per_level;
for (size_t i=0;isecond.energy);
}
}
return Action::success;
}
ActionState::ptr GraphChemicalSpaceEvaluatorAction::performUndo(ActionState::ptr _state) {
return Action::success;
}
ActionState::ptr GraphChemicalSpaceEvaluatorAction::performRedo(ActionState::ptr _state){
return Action::success;
}
bool GraphChemicalSpaceEvaluatorAction::canUndo() {
return true;
}
bool GraphChemicalSpaceEvaluatorAction::shouldUndo() {
return true;
}
/** =========== end of function ====================== */