- Timestamp:
- Jul 12, 2017, 7:10:31 PM (7 years ago)
- Branches:
- Action_Thermostats, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision
- Children:
- 6e5b8d
- Parents:
- d24ef58
- git-author:
- Frederik Heber <frederik.heber@…> (05/18/17 17:45:47)
- git-committer:
- Frederik Heber <frederik.heber@…> (07/12/17 19:10:31)
- Location:
- src/Graph
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Graph/BoostGraphCreator.cpp
rd24ef58 rbccbe9 85 85 std::back_inserter(atomids), getAtomId); 86 86 ASSERT( _atoms.size() == atomids.size(), 87 "BoostGraphCreator::createFromAtom() - atomids and atoms differ in size?"); 87 "BoostGraphCreator::createFromAtom() - atomids " 88 +toString(atomids.size())+" and atoms "+toString(_atoms.size()) 89 +" differ in size?"); 88 90 std::sort(atomids.begin(), atomids.end()); 89 91 const predicate_t predicate = boost::bind(inSetPredicate, boost::ref(atomids), _1); … … 95 97 } 96 98 99 BoostGraphCreator::nodeId_t BoostGraphCreator::getNodeId( 100 const atomId_t &_atomid) const 101 { 102 atomids_nodeids_t::const_iterator iter = 103 atomids_nodeids.find(_atomid); 104 return (iter == atomids_nodeids.end()) ? (nodeId_t)-1 : iter->second; 105 } 106 97 107 template <typename iterator> 98 108 void BoostGraphCreator::createFromRange( … … 101 111 const size_t &_no_nodes, 102 112 const predicate_t &_pred 103 ) { 104 // convert BondGraph into boost::graph 105 UndirectedGraph molgraph(_no_nodes); 113 ) 114 { 115 graph = UndirectedGraph(); 116 117 // add vertices 106 118 for(iterator iter = _begin; iter != _end; ++iter) { 107 LOG(2, "DEBUG: Looking at node " << (*iter)->getId()); 119 const atomId_t atomid = (*iter)->getId(); 120 Vertex v = boost::add_vertex(atomid, graph); 121 const atomId_t vertexname = boost::get(boost::get(boost::vertex_name, graph), v); 122 const nodeId_t vertexindex = boost::get(boost::get(boost::vertex_index, graph), v); 123 LOG(2, "DEBUG: Adding node " << vertexindex << " associated to atom #" << vertexname); 124 ASSERT( vertexname == atomid, 125 "BoostGraphCreator::createFromRange() - atomid "+toString(atomid) 126 +" is not name of vertex "+toString(vertexname)+"."); 127 atomids_nodeids.insert( std::make_pair(vertexname, vertexindex) ); 128 } 129 130 // add edges 131 for(iterator iter = _begin; iter != _end; ++iter) { 132 LOG(2, "DEBUG: Looking at atom " << (*iter)->getId()); 108 133 const BondList& ListOfBonds = (*iter)->getListOfBonds(); 109 134 for(BondList::const_iterator bonditer = ListOfBonds.begin(); 110 135 bonditer != ListOfBonds.end(); ++bonditer) { 136 LOG(2, "DEBUG: Looking at bond " << *(*bonditer)); 111 137 const atomId_t leftid = (*bonditer)->leftatom->getId(); 138 const nodeId_t leftnodeid = getNodeId(leftid); 112 139 const atomId_t rightid = (*bonditer)->rightatom->getId(); 140 const nodeId_t rightnodeid = getNodeId(rightid); 113 141 // only pick each bond once and evaluate predicate 114 142 if ((leftid == (*iter)->getId()) 115 143 && (_pred(**bonditer))) { 116 LOG(3, "DEBUG: ADDING edge " << left id << " <-> " << rightid);117 boost::add_edge(left id, rightid, graph);144 LOG(3, "DEBUG: ADDING edge " << leftnodeid << " <-> " << rightnodeid); 145 boost::add_edge(leftnodeid, rightnodeid, graph); 118 146 } else { 119 LOG(3, "DEBUG: Discarding edge " << left id << " <-> " << rightid);147 LOG(3, "DEBUG: Discarding edge " << leftnodeid << " <-> " << rightnodeid); 120 148 } 121 149 } -
src/Graph/BoostGraphCreator.hpp
rd24ef58 rbccbe9 15 15 #endif 16 16 17 #include <map> 17 18 #include <vector> 18 19 19 20 #include <boost/function.hpp> 20 21 #include <boost/graph/adjacency_list.hpp> 22 23 #include "types.hpp" 21 24 22 25 class atom; … … 32 35 //!> typedef for an undirected graph using boost::graph 33 36 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, 34 boost:: no_property, boost::no_property > UndirectedGraph;37 boost::property<boost::vertex_name_t, atomId_t>, boost::no_property > UndirectedGraph; 35 38 //!> typedef for a map of graph node indices 36 typedef boost::property_map < boost::adjacency_list <>, boost::vertex_index_t >::type index_map_t; 39 typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::type index_map_t; 40 typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::const_type const_index_map_t; 41 //!> typedef for a map of graph node indices 42 typedef boost::property_map < UndirectedGraph, boost::vertex_name_t >::type name_map_t; 43 typedef boost::property_map < UndirectedGraph, boost::vertex_name_t >::const_type const_name_map_t; 37 44 //!> typedef for the predicate to evaluate for adding the current edge or not 38 45 typedef boost::function<bool (const bond &)> predicate_t; 46 //!> typedef for a Vertex 47 typedef boost::graph_traits<UndirectedGraph>::vertex_descriptor Vertex; 48 //!> typedef for vertex iterator 49 typedef boost::graph_traits<UndirectedGraph>::vertex_iterator vertex_iter; 39 50 51 //!> typedef for a node id 52 typedef size_t nodeId_t; 53 //!> typedef for map converting between node id in graph and the associated atomic id 54 typedef std::map<atomId_t, nodeId_t> atomids_nodeids_t; 40 55 41 56 /** Creates the boost::graph using all atoms and bonds in the given \a _mol. … … 89 104 } 90 105 106 /** Returns the node id to a given atom id \a _atomid. 107 * 108 * \param _atomid atom id 109 * \return node id 110 */ 111 nodeId_t getNodeId(const atomId_t &_atomid) const; 112 91 113 private: 92 114 /** General purpose function that contains the internal logic of walking the … … 114 136 //!> internal graph that is created by creator functions 115 137 UndirectedGraph graph; 138 //!> external property map for all the atomic ids of each graph node 139 atomids_nodeids_t atomids_nodeids; 116 140 }; 117 141 -
src/Graph/Makefile.am
rd24ef58 rbccbe9 3 3 4 4 GRAPHSOURCE = \ 5 Graph/AdjacencyList.cpp \ 5 6 Graph/BondGraph.cpp \ 6 7 Graph/BoostGraphCreator.cpp \ 8 Graph/BreadthFirstSearchGatherer.cpp \ 7 9 Graph/BuildInducedSubgraph.cpp \ 8 Graph/AdjacencyList.cpp \9 10 Graph/ConnectedSubgraph.cpp \ 10 11 Graph/CyclicStructureAnalysis.cpp \ … … 12 13 13 14 GRAPHHEADER = \ 15 Graph/AdjacencyList.hpp \ 14 16 Graph/BondGraph.hpp \ 15 17 Graph/BoostGraphCreator.hpp \ 18 Graph/BoostGraphHelpers.hpp \ 19 Graph/BreadthFirstSearchGatherer.hpp \ 16 20 Graph/BuildInducedSubgraph.hpp \ 17 Graph/AdjacencyList.hpp \18 21 Graph/ConnectedSubgraph.hpp \ 19 22 Graph/CyclicStructureAnalysis.hpp \
Note:
See TracChangeset
for help on using the changeset viewer.