Changeset 1be100


Ignore:
Timestamp:
Apr 23, 2021, 8:51:43 PM (5 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
9171d8
Parents:
d951a5
git-author:
Frederik Heber <frederik.heber@…> (03/27/21 16:54:08)
git-committer:
Frederik Heber <frederik.heber@…> (04/23/21 20:51:43)
Message:

FIX: Several small errors in Graph6Reader.

  • off-by-one error with encoding starts at 63 (0), not 64.
  • cur_byte needs to exist outside of scope of next_edge().
  • need a mapping from edges_by_vertices in the subgraph (with indices from the subgraph vertices) to the edge index used in th degrees array to properly calculate the bond degrees.
  • TESTS: Added a chemical space evaluator test case with 3 nodes.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/GraphAction/ChemicalSpaceEvaluatorAction.cpp

    rd951a5 r1be100  
    142142{
    143143  const BoostGraphCreator::Vertex u = source(e, graph);
    144   const BoostGraphCreator::Vertex v = source(e, graph);
     144  const BoostGraphCreator::Vertex v = target(e, graph);
    145145  return getEdgeByVertices(u,v);
    146146}
     
    204204    for (boost::tie(i, end) = boost::out_edges(v, graph); i != end; ++i) {
    205205      const BoostGraphCreator::Edge &e = *i;
    206       const BoostGraphCreator::Vertex e1 = source(e, graph);
    207       const BoostGraphCreator::Vertex e2 = target(e, graph);
    208       const edge_by_vertices_t edge_by_vertices = getEdgeByVertices(e1,e2);
     206      const edge_by_vertices_t edge_by_vertices = getEdgeVerticesByEdge(e, graph);
    209207      LOG(3, "DEBUG: Current edge is (" << edge_by_vertices << ")");
    210208      const size_t index = getElementFromMap<edge_index_t, edge_by_vertices_t>(
     
    231229      std::pair<BoostGraphCreator::Edge, bool> edge_inserter =
    232230          boost::add_edge(v, h, newgraph.saturated_graph);
     231      ASSERT( edge_inserter.second,
     232          "Failed to insert hydrogen into saturation graph.");
    233233    }
    234234    LOG(2, "DEBUG: Added " << (max_valence - total_valence)
     
    242242BoostGraphCreator::UndirectedGraph extractSubgraph(
    243243    const graph_t &_graph,
    244     const Extractors::nodes_t &nodes)
     244    const Extractors::nodes_t &nodes,
     245    const edge_index_t &_edge_index,
     246    edge_index_t &_subgraph_edge_index)
    245247{
    246248  BoostGraphCreator::UndirectedGraph subgraph;
    247249  const Extractors::index_map_t index_map = boost::get(boost::vertex_index, _graph);
     250  typedef std::map<Extractors::node_t, BoostGraphCreator::Vertex> graph_index_to_subgraph_vertex_t;
     251  graph_index_to_subgraph_vertex_t graph_index_to_subgraph_vertex;
    248252
    249253  // add nodes
    250254  BoostGraphCreator::vertex_iter viter, vend;
    251255  for (boost::tie(viter, vend) = boost::vertices(_graph); viter != vend; ++viter) {
    252     const size_t nodeid = boost::get(index_map, *viter);
     256    const Extractors::node_t nodeid = boost::get(index_map, *viter);
    253257    if (nodes.find(nodeid) != nodes.end()) {
    254       boost::add_vertex(*viter, subgraph);
     258      const BoostGraphCreator::Vertex vnew = boost::add_vertex(*viter, subgraph);
     259      graph_index_to_subgraph_vertex.insert( std::make_pair(nodeid, vnew) );
    255260      LOG(4, "DEBUG: Adding node " << *viter << " to subgraph.");
    256261    }
    257262  }
     263  const Extractors::index_map_t subgraph_index_map = boost::get(boost::vertex_index, subgraph);
    258264
    259265  // add edges
     
    264270      const Extractors::node_t sourceindex = boost::get(index_map, boost::source(*i, _graph));
    265271      const Extractors::node_t targetindex = boost::get(index_map, boost::target(*i, _graph));
     272      // we need to translate the vertex index from graph to subgraph
     273      const Extractors::node_t subsourceindex = boost::get(
     274          subgraph_index_map, graph_index_to_subgraph_vertex[sourceindex]);
     275      const Extractors::node_t subtargetindex = boost::get(
     276          subgraph_index_map, graph_index_to_subgraph_vertex[targetindex]);
    266277      if ((nodes.find(sourceindex) != nodes.end()) && (nodes.find(targetindex) != nodes.end())
    267278          && (sourceindex < targetindex)) {
    268         boost::add_edge(sourceindex, targetindex, subgraph);
    269         LOG(4, "DEBUG: Adding edge " << sourceindex << "<->" << targetindex << " to subgraph.");
     279        // and we need to translate the edge index from the graph to the subgraph
     280        const std::pair<BoostGraphCreator::Edge, bool> newedgeinserter =
     281            boost::add_edge(subsourceindex, subtargetindex, subgraph);
     282        ASSERT( newedgeinserter.second,
     283            "extractSubgraph() - could not insert edge "+toString(subsourceindex)+"<->"
     284            +toString(subtargetindex)+".");
     285        const edge_by_vertices_t edge_by_vertices = getEdgeVerticesByEdge(*i, _graph);
     286        const edge_index_t::const_iterator edgeiter = _edge_index.find(edge_by_vertices);
     287        ASSERT( edgeiter != _edge_index.end(),
     288            "extractSubgraph() - could not find edge "+toString(edge_by_vertices)+" in edge_index map." );
     289        const edge_by_vertices_t subgraph_edge_by_vertices =
     290            getEdgeVerticesByEdge(newedgeinserter.first, subgraph);
     291        _subgraph_edge_index.insert( std::make_pair(subgraph_edge_by_vertices, edgeiter->second) );
     292        LOG(4, "DEBUG: Adding edge " << sourceindex << "<->" << targetindex
     293            << " in graph to subgraph as edge " << subsourceindex << "<->" << subtargetindex << ".");
    270294      }
    271295    }
     
    412436  }
    413437
    414   typedef std::vector<
    415       std::pair<
    416           BoostGraphCreator::UndirectedGraph,
    417           degrees_t> > graphs_with_degrees_t;
    418 
    419438  // 6. for every combination saturate fragments for lookup and energy contribution summation
     439  size_t num_admissible = 0;
    420440  const HomologyContainer &container = World::getInstance().getHomologies();
    421441  for (list_of_edge_degrees_t::const_iterator degrees_iter = list_of_edge_degrees.begin();
     
    436456      continue;
    437457    } else {
     458      ++num_admissible;
    438459      LOG(2, "DEBUG: The degree combination is admissable.");
    439460    }
     
    452473
    453474      // create subgraph
    454       Extractors::UndirectedGraph newgraph = extractSubgraph(graph, current_nodes);
     475      edge_index_t subgraph_edge_index;
     476      Extractors::UndirectedGraph newgraph = extractSubgraph(
     477          graph, current_nodes, edge_index, subgraph_edge_index);
    455478
    456479      const BoostGraphCreator::name_map_t new_name_map =
     
    469492      SaturatedGraph fragmentgraph =
    470493          saturateGraph(newgraph, new_name_map,
    471               type_index_lookup, type_valence_map, edge_index,
     494              type_index_lookup, type_valence_map, subgraph_edge_index,
    472495              edges, current_degrees);
    473496
     
    514537    LOG(1, "The graph with degrees " << current_degrees << " has a total BOSSANOVA energy of " << total_energy);
    515538  }
     539  LOG(1, "There have been " << num_admissible << " admissible degree combinations for the given graph.");
    516540
    517541  return Action::success;
  • src/Graph/Graph6Reader.cpp

    rd951a5 r1be100  
    5757        if (*_it <126) {
    5858                //6-bit encoding
    59                 num_nodes = *_it-64;
     59                num_nodes = *_it-63;
    6060        } else if (*_it++ == 126) {
    6161                unsigned int packets = 3;
     
    6666                }
    6767                for(unsigned int i =0; i<packets*packet_size; ++i) {
    68                         unsigned char packet = (*_it++) - 64;
     68                        unsigned char packet = (*_it++) - 63;
    6969                        ASSERT(packet<=(1<<(packet_size+1)),
    7070                                        "The input is malformed. "
     
    8484void Graph6Reader::next_edge(std::istream_iterator<unsigned char> &_it) {
    8585  unsigned int bit = 0;
    86   int cur_byte = 0;
    8786  while(!bit && !eos) {
    8887    if (++row==column) {
     
    9594    }
    9695    if (bit_pos<0) {
    97       ASSERT((*_it >= 63) && (*_it <= 126),
     96      ASSERT(_it != std::istream_iterator<unsigned char>(),
     97          "Graph6Reader::next_edge() - less characters than expected in string.");
     98      ASSERT((*_it >= 64) && (*_it <= 126),
    9899          "The input contains a non-printable ascii char in the matrix encoding");
    99100      cur_byte = (*_it) - 63;
  • src/Graph/Graph6Reader.hpp

    rd951a5 r1be100  
    4444    eos(false),
    4545    bit_pos(-1),
     46    cur_byte(0),
    4647    num_nodes(0)
    4748  {}
     
    6667  bool eos;
    6768  int bit_pos;
     69  int cur_byte;
    6870  static const int packet_size;
    6971
  • tests/regression/Graph/ChemicalSpaceEvaluator/testsuite-chemical-space-evaluator.at

    rd951a5 r1be100  
    2626AT_CHECK([../../molecuilder \
    2727        --parse-homologies $file \
    28         --evaluate-chemical-space --graph6 'B`' --elements C C], 0, [stdout], [stderr])
     28        --evaluate-chemical-space --graph6 'A`' --elements C C], 0, [stdout], [stderr])
    2929AT_CHECK([fgrep "2 nodes in the fragment graph." stdout], 0, [ignore], [ignore])
    3030AT_CHECK([fgrep "Added 3 graph degree combinations" stdout], 0, [ignore], [ignore])
    31 AT_CHECK([fgrep "The graph with degrees ( 1; ) has a total energy of -78.9805" stdout], 0, [ignore], [ignore])
    32 AT_CHECK([fgrep "The graph with degrees ( 2; ) has a total energy of -77.7951" stdout], 0, [ignore], [ignore])
    33 AT_CHECK([fgrep "The graph with degrees ( 3; ) has a total energy of -38.1564" stdout], 0, [ignore], [ignore])
     31AT_CHECK([fgrep "The graph with degrees ( 1; ) has a total BOSSANOVA energy of -78.9805" stdout], 0, [ignore], [ignore])
     32AT_CHECK([fgrep "The graph with degrees ( 2; ) has a total BOSSANOVA energy of -77.7951" stdout], 0, [ignore], [ignore])
     33AT_CHECK([fgrep "The graph with degrees ( 3; ) has a total BOSSANOVA energy of -38.1564" stdout], 0, [ignore], [ignore])
    3434
    3535AT_CLEANUP
    3636
     37AT_SETUP([Graph - evaluate chemical space II])
     38AT_KEYWORDS([graph evaluate-chemical-space graph6])
     39
     40file=homologies.dat
     41AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Graph/ChemicalSpaceEvaluator/pre/homologies_CC.dat $file], 0)
     42AT_CHECK([chmod u+w $file], 0)
     43AT_CHECK([../../molecuilder \
     44        --parse-homologies $file \
     45        --evaluate-chemical-space --graph6 'BW' --elements C C C], 0, [stdout], [stderr])
     46AT_CHECK([fgrep "3 nodes in the fragment graph." stdout], 0, [ignore], [ignore])
     47AT_CHECK([fgrep "Added 9 graph degree combinations" stdout], 0, [ignore], [ignore])
     48AT_CHECK([fgrep "The graph with degrees ( 1; 1; ) has a total BOSSANOVA energy of -117.884" stdout], 0, [ignore], [ignore])
     49AT_CHECK([fgrep "The graph with degrees ( 1; 2; ) has a total BOSSANOVA energy of -116.699" stdout], 0, [ignore], [ignore])
     50AT_CHECK([fgrep "The graph with degrees ( 1; 3; ) has a total BOSSANOVA energy of -77.0602" stdout], 0, [ignore], [ignore])
     51AT_CHECK([fgrep "The graph with degrees ( 2; 1; ) has a total BOSSANOVA energy of -116.699" stdout], 0, [ignore], [ignore])
     52AT_CHECK([fgrep "The graph with degrees ( 2; 2; ) has a total BOSSANOVA energy of -115.513" stdout], 0, [ignore], [ignore])
     53AT_CHECK([fgrep "The graph with degrees ( 3; 1; ) has a total BOSSANOVA energy of -77.0602" stdout], 0, [ignore], [ignore])
     54
     55AT_CLEANUP
Note: See TracChangeset for help on using the changeset viewer.