[1356af] | 1 | /*
|
---|
| 2 | * BoostGraphCreator_impl.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 18, 2017
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | #ifndef GRAPH_BOOSTGRAPHCREATOR_IMPL_HPP_
|
---|
| 10 | #define GRAPH_BOOSTGRAPHCREATOR_IMPL_HPP_
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 | #include "BoostGraphCreator.hpp"
|
---|
| 18 |
|
---|
| 19 | #include "CodePatterns/Assert.hpp"
|
---|
| 20 | #include "CodePatterns/Log.hpp"
|
---|
| 21 |
|
---|
| 22 | #include "Atom/atom.hpp"
|
---|
| 23 | #include "Bond/bond.hpp"
|
---|
| 24 |
|
---|
| 25 | template <typename iterator>
|
---|
| 26 | void BoostGraphCreator::createFromRange(
|
---|
| 27 | const iterator &_begin,
|
---|
| 28 | const iterator &_end,
|
---|
| 29 | const size_t &_no_nodes,
|
---|
| 30 | const predicate_t &_pred
|
---|
| 31 | )
|
---|
| 32 | {
|
---|
| 33 | graph = UndirectedGraph();
|
---|
| 34 |
|
---|
| 35 | // add vertices
|
---|
| 36 | for(iterator iter = _begin; iter != _end; ++iter) {
|
---|
| 37 | const atomId_t atomid = (*iter)->getId();
|
---|
| 38 | Vertex v = boost::add_vertex(atomid, graph);
|
---|
| 39 | const atomId_t vertexname = boost::get(boost::get(boost::vertex_name, graph), v);
|
---|
| 40 | const nodeId_t vertexindex = boost::get(boost::get(boost::vertex_index, graph), v);
|
---|
| 41 | LOG(2, "DEBUG: Adding node " << vertexindex << " associated to atom #" << vertexname);
|
---|
| 42 | ASSERT( vertexname == atomid,
|
---|
| 43 | "BoostGraphCreator::createFromRange() - atomid "+toString(atomid)
|
---|
| 44 | +" is not name of vertex "+toString(vertexname)+".");
|
---|
| 45 | atomids_nodeids.insert( std::make_pair(vertexname, vertexindex) );
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | // add edges
|
---|
| 49 | for(iterator iter = _begin; iter != _end; ++iter) {
|
---|
| 50 | LOG(2, "DEBUG: Looking at atom " << (*iter)->getId());
|
---|
| 51 | const BondList& ListOfBonds = (*iter)->getListOfBonds();
|
---|
| 52 | for(BondList::const_iterator bonditer = ListOfBonds.begin();
|
---|
| 53 | bonditer != ListOfBonds.end(); ++bonditer) {
|
---|
| 54 | LOG(2, "DEBUG: Looking at bond " << *(*bonditer));
|
---|
| 55 | const atomId_t leftid = (*bonditer)->leftatom->getId();
|
---|
| 56 | const nodeId_t leftnodeid = getNodeId(leftid);
|
---|
| 57 | const atomId_t rightid = (*bonditer)->rightatom->getId();
|
---|
| 58 | const nodeId_t rightnodeid = getNodeId(rightid);
|
---|
| 59 | // only pick each bond once and evaluate predicate
|
---|
| 60 | if ((leftid == (*iter)->getId())
|
---|
| 61 | && (_pred(**bonditer))) {
|
---|
| 62 | LOG(3, "DEBUG: ADDING edge " << leftnodeid << " <-> " << rightnodeid);
|
---|
| 63 | boost::add_edge(leftnodeid, rightnodeid, graph);
|
---|
| 64 | } else {
|
---|
| 65 | LOG(3, "DEBUG: Discarding edge " << leftnodeid << " <-> " << rightnodeid);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | LOG(2, "DEBUG: We have " << getNumVertices() << " nodes and " << getNumEdges()
|
---|
| 70 | << " edges in the molecule graph.");
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | #endif /* GRAPH_BOOSTGRAPHCREATOR_IMPL_HPP_ */
|
---|