Changeset bccbe9 for src/Graph


Ignore:
Timestamp:
Jul 12, 2017, 7:10:31 PM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
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)
Message:

Extracted extraction (subset of) nodes from BoostGraph into BreadthFirstSearchGatherer.

  • also added helper namespace BoostGraphHelpers.
  • we now treat the vertex indices and vertex names properly. Before that they had to coincide. Now, the name is the atomic id associated with the node and the index is the boost::graph internal index.
Location:
src/Graph
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/BoostGraphCreator.cpp

    rd24ef58 rbccbe9  
    8585      std::back_inserter(atomids), getAtomId);
    8686  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?");
    8890  std::sort(atomids.begin(), atomids.end());
    8991  const predicate_t predicate = boost::bind(inSetPredicate, boost::ref(atomids), _1);
     
    9597}
    9698
     99BoostGraphCreator::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
    97107template <typename iterator>
    98108void BoostGraphCreator::createFromRange(
     
    101111    const size_t &_no_nodes,
    102112    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
    106118  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());
    108133    const BondList& ListOfBonds = (*iter)->getListOfBonds();
    109134    for(BondList::const_iterator bonditer = ListOfBonds.begin();
    110135        bonditer != ListOfBonds.end(); ++bonditer) {
     136      LOG(2, "DEBUG: Looking at bond " << *(*bonditer));
    111137      const atomId_t leftid = (*bonditer)->leftatom->getId();
     138      const nodeId_t leftnodeid = getNodeId(leftid);
    112139      const atomId_t rightid = (*bonditer)->rightatom->getId();
     140      const nodeId_t rightnodeid = getNodeId(rightid);
    113141      // only pick each bond once and evaluate predicate
    114142      if ((leftid == (*iter)->getId())
    115143          && (_pred(**bonditer))) {
    116         LOG(3, "DEBUG: ADDING edge " << leftid << " <-> " << rightid);
    117         boost::add_edge(leftid, rightid, graph);
     144        LOG(3, "DEBUG: ADDING edge " << leftnodeid << " <-> " << rightnodeid);
     145        boost::add_edge(leftnodeid, rightnodeid, graph);
    118146      } else {
    119         LOG(3, "DEBUG: Discarding edge " << leftid << " <-> " << rightid);
     147        LOG(3, "DEBUG: Discarding edge " << leftnodeid << " <-> " << rightnodeid);
    120148      }
    121149    }
  • src/Graph/BoostGraphCreator.hpp

    rd24ef58 rbccbe9  
    1515#endif
    1616
     17#include <map>
    1718#include <vector>
    1819
    1920#include <boost/function.hpp>
    2021#include <boost/graph/adjacency_list.hpp>
     22
     23#include "types.hpp"
    2124
    2225class atom;
     
    3235  //!> typedef for an undirected graph using boost::graph
    3336  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;
    3538  //!> 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;
    3744  //!> typedef for the  predicate to evaluate for adding the current edge or not
    3845  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;
    3950
     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;
    4055
    4156  /** Creates the boost::graph using all atoms and bonds in the given \a _mol.
     
    89104  }
    90105
     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
    91113private:
    92114  /** General purpose function that contains the internal logic of walking the
     
    114136  //!> internal graph that is created by creator functions
    115137  UndirectedGraph graph;
     138  //!> external property map for all the atomic ids of each graph node
     139  atomids_nodeids_t atomids_nodeids;
    116140};
    117141
  • src/Graph/Makefile.am

    rd24ef58 rbccbe9  
    33
    44GRAPHSOURCE = \
     5        Graph/AdjacencyList.cpp \
    56        Graph/BondGraph.cpp \
    67        Graph/BoostGraphCreator.cpp \
     8        Graph/BreadthFirstSearchGatherer.cpp \
    79        Graph/BuildInducedSubgraph.cpp \
    8         Graph/AdjacencyList.cpp \
    910        Graph/ConnectedSubgraph.cpp \
    1011        Graph/CyclicStructureAnalysis.cpp \
     
    1213                                 
    1314GRAPHHEADER = \
     15        Graph/AdjacencyList.hpp \
    1416        Graph/BondGraph.hpp \
    1517        Graph/BoostGraphCreator.hpp \
     18        Graph/BoostGraphHelpers.hpp \
     19        Graph/BreadthFirstSearchGatherer.hpp \
    1620        Graph/BuildInducedSubgraph.hpp \
    17         Graph/AdjacencyList.hpp \
    1821        Graph/ConnectedSubgraph.hpp \
    1922        Graph/CyclicStructureAnalysis.hpp \
Note: See TracChangeset for help on using the changeset viewer.