Changeset d24ef58 for src/Actions


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:
bccbe9
Parents:
3b74fa
git-author:
Frederik Heber <frederik.heber@…> (05/17/17 11:34:16)
git-committer:
Frederik Heber <frederik.heber@…> (07/12/17 19:10:31)
Message:

Extracted conversion to boost::graph into distinct struct.

  • BoostGraphCreator allows to convert sets of atoms into a boost::graph while using an additional predicate.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/StretchBondAction.cpp

    r3b74fa rd24ef58  
    3535#include <boost/graph/adjacency_list.hpp>
    3636#include <boost/graph/breadth_first_search.hpp>
    37 #include <boost/graph/subgraph.hpp>
    3837
    3938//#include "CodePatterns/MemDebug.hpp"
     
    4140#include "Actions/MoleculeAction/StretchBondAction.hpp"
    4241
     42#include <boost/bind.hpp>
     43
     44#include "CodePatterns/Assert.hpp"
    4345#include "CodePatterns/Log.hpp"
    4446#include "CodePatterns/Verbose.hpp"
     
    4951#include "Bond/bond.hpp"
    5052#include "Descriptors/AtomIdDescriptor.hpp"
     53#include "Graph/BoostGraphCreator.hpp"
    5154#include "molecule.hpp"
    5255#include "World.hpp"
     
    8588{
    8689  return distance_recorder<DistanceMap>(d);
     90}
     91
     92static bool addEdgePredicate(
     93    const bond &_bond,
     94    const std::vector<atomId_t> &_atomids)
     95{
     96  ASSERT(_atomids.size() == (size_t)2,
     97      "addEdgePredicate() - atomids must contain exactly two ids.");
     98  // do not add selected edge
     99  return ((_bond.leftatom->getId() != _atomids[0])
     100      || (_bond.rightatom->getId() != _atomids[1]));
    87101}
    88102
     
    118132  // shift either set as desired. If not, then we simply shift each atom,
    119133  // leaving the other positions untouched.
    120   typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS,
    121       boost::no_property, boost::no_property > UndirectedGraph;
    122134
    123135  // convert BondGraph into boost::graph
    124   UndirectedGraph molgraph(mol->getAtomCount());
    125   size_t no_edges = 0;
    126   for(molecule::const_iterator iter = const_cast<const molecule * const>(mol)->begin();
    127       iter != const_cast<const molecule * const>(mol)->end(); ++iter) {
    128     LOG(2, "DEBUG: Looking at node " << (*iter)->getId());
    129     const BondList& ListOfBonds = (*iter)->getListOfBonds();
    130     for(BondList::const_iterator bonditer = ListOfBonds.begin();
    131         bonditer != ListOfBonds.end(); ++bonditer) {
    132       const unsigned int &leftid = (*bonditer)->leftatom->getId();
    133       const unsigned int &rightid = (*bonditer)->rightatom->getId();
    134       // only add each edge once and do not add selected edge
    135       if ((leftid == (*iter)->getId())
    136           && ((leftid != atomids[0]) || (rightid != atomids[1]))) {
    137         LOG(1, "DEBUG: ADDING edge " << leftid << " <-> " << rightid);
    138         boost::add_edge(leftid, rightid, molgraph);
    139         ++no_edges;
    140       } else {
    141         LOG(1, "DEBUG: Discarding edge " << leftid << " <-> " << rightid);
    142       }
    143     }
    144   }
    145   typedef boost::property_map < boost::adjacency_list <>, boost::vertex_index_t >::type index_map_t;
    146   index_map_t index_map = boost::get(boost::vertex_index, molgraph);
    147   const size_t num_vertices = boost::num_vertices(molgraph);
    148   LOG(2, "DEBUG: We have " << num_vertices << " nodes and " << no_edges
    149       << " edges in the molecule graph.");
    150 
     136  BoostGraphCreator BGcreator;
     137  BGcreator.createFromMolecule(*mol,
     138      boost::bind(addEdgePredicate, _1, boost::ref(atomids)));
     139  const BoostGraphCreator::UndirectedGraph &molgraph = BGcreator.get();
     140
     141  const size_t num_vertices = BGcreator.getNumVertices();
    151142  std::vector< std::vector<size_t> > distances;
    152143  for (size_t i=0;i<2;++i) {
     
    184175  // go through the molecule and stretch each atom in either set of nodes
    185176  if (bondside_sets[0].empty()) {
     177    const BoostGraphCreator::index_map_t index_map = BGcreator.getIndexMap();
    186178    for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    187179      const Vector &position = (*iter)->getPosition();
Note: See TracChangeset for help on using the changeset viewer.