Index: src/Actions/MoleculeAction/StretchBondAction.cpp
===================================================================
--- src/Actions/MoleculeAction/StretchBondAction.cpp	(revision 3b74fa571b14434bdf4e8ec5bf8356451fdb57b7)
+++ src/Actions/MoleculeAction/StretchBondAction.cpp	(revision d24ef58f28627a24574b012f8f2b174072c4da20)
@@ -35,5 +35,4 @@
 #include <boost/graph/adjacency_list.hpp>
 #include <boost/graph/breadth_first_search.hpp>
-#include <boost/graph/subgraph.hpp>
 
 //#include "CodePatterns/MemDebug.hpp"
@@ -41,4 +40,7 @@
 #include "Actions/MoleculeAction/StretchBondAction.hpp"
 
+#include <boost/bind.hpp>
+
+#include "CodePatterns/Assert.hpp"
 #include "CodePatterns/Log.hpp"
 #include "CodePatterns/Verbose.hpp"
@@ -49,4 +51,5 @@
 #include "Bond/bond.hpp"
 #include "Descriptors/AtomIdDescriptor.hpp"
+#include "Graph/BoostGraphCreator.hpp"
 #include "molecule.hpp"
 #include "World.hpp"
@@ -85,4 +88,15 @@
 {
   return distance_recorder<DistanceMap>(d);
+}
+
+static bool addEdgePredicate(
+    const bond &_bond,
+    const std::vector<atomId_t> &_atomids)
+{
+  ASSERT(_atomids.size() == (size_t)2,
+      "addEdgePredicate() - atomids must contain exactly two ids.");
+  // do not add selected edge
+  return ((_bond.leftatom->getId() != _atomids[0])
+      || (_bond.rightatom->getId() != _atomids[1]));
 }
 
@@ -118,35 +132,12 @@
   // shift either set as desired. If not, then we simply shift each atom,
   // leaving the other positions untouched.
-  typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS,
-      boost::no_property, boost::no_property > UndirectedGraph;
 
   // convert BondGraph into boost::graph
-  UndirectedGraph molgraph(mol->getAtomCount());
-  size_t no_edges = 0;
-  for(molecule::const_iterator iter = const_cast<const molecule * const>(mol)->begin();
-      iter != const_cast<const molecule * const>(mol)->end(); ++iter) {
-    LOG(2, "DEBUG: Looking at node " << (*iter)->getId());
-    const BondList& ListOfBonds = (*iter)->getListOfBonds();
-    for(BondList::const_iterator bonditer = ListOfBonds.begin();
-        bonditer != ListOfBonds.end(); ++bonditer) {
-      const unsigned int &leftid = (*bonditer)->leftatom->getId();
-      const unsigned int &rightid = (*bonditer)->rightatom->getId();
-      // only add each edge once and do not add selected edge
-      if ((leftid == (*iter)->getId())
-          && ((leftid != atomids[0]) || (rightid != atomids[1]))) {
-        LOG(1, "DEBUG: ADDING edge " << leftid << " <-> " << rightid);
-        boost::add_edge(leftid, rightid, molgraph);
-        ++no_edges;
-      } else {
-        LOG(1, "DEBUG: Discarding edge " << leftid << " <-> " << rightid);
-      }
-    }
-  }
-  typedef boost::property_map < boost::adjacency_list <>, boost::vertex_index_t >::type index_map_t;
-  index_map_t index_map = boost::get(boost::vertex_index, molgraph);
-  const size_t num_vertices = boost::num_vertices(molgraph);
-  LOG(2, "DEBUG: We have " << num_vertices << " nodes and " << no_edges
-      << " edges in the molecule graph.");
-
+  BoostGraphCreator BGcreator;
+  BGcreator.createFromMolecule(*mol,
+      boost::bind(addEdgePredicate, _1, boost::ref(atomids)));
+  const BoostGraphCreator::UndirectedGraph &molgraph = BGcreator.get();
+
+  const size_t num_vertices = BGcreator.getNumVertices();
   std::vector< std::vector<size_t> > distances;
   for (size_t i=0;i<2;++i) {
@@ -184,4 +175,5 @@
   // go through the molecule and stretch each atom in either set of nodes
   if (bondside_sets[0].empty()) {
+    const BoostGraphCreator::index_map_t index_map = BGcreator.getIndexMap();
     for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
       const Vector &position = (*iter)->getPosition();
Index: src/Graph/BoostGraphCreator.cpp
===================================================================
--- src/Graph/BoostGraphCreator.cpp	(revision d24ef58f28627a24574b012f8f2b174072c4da20)
+++ src/Graph/BoostGraphCreator.cpp	(revision d24ef58f28627a24574b012f8f2b174072c4da20)
@@ -0,0 +1,127 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2017 Frederik Heber. All rights reserved.
+ *
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * BoostGraphCreator.cpp
+ *
+ *  Created on: May 17, 2017
+ *      Author: heber
+ */
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+//#include "CodePatterns/MemDebug.hpp"
+
+#include "BoostGraphCreator.hpp"
+
+#include <algorithm>
+#include <iterator>
+
+#include "CodePatterns/Assert.hpp"
+#include "CodePatterns/Log.hpp"
+
+#include "Atom/atom.hpp"
+#include "Bond/bond.hpp"
+#include "molecule.hpp"
+
+void BoostGraphCreator::createFromMolecule(
+    const molecule &_mol,
+    const predicate_t &_pred)
+{
+  createFromRange<molecule::const_iterator>(_mol.begin(), _mol.end(), _mol.getAtomCount(), _pred);
+}
+
+static bool predicateAnd(
+    const BoostGraphCreator::predicate_t &_pred1,
+    const BoostGraphCreator::predicate_t &_pred2,
+    const bond &_bond)
+{ return (_pred1(_bond) && _pred2(_bond)); }
+
+static atomId_t getAtomId(
+    const atom *_atom
+    )
+{ return _atom->getId(); }
+
+static bool inSetPredicate(
+  const std::vector<atomId_t> &_atomids,
+  const bond &_bond)
+{
+  const atomId_t leftid = _bond.leftatom->getId();
+  const atomId_t rightid = _bond.rightatom->getId();
+  return std::binary_search(_atomids.begin(), _atomids.end(), leftid)
+      && std::binary_search(_atomids.begin(), _atomids.end(), rightid);
+}
+
+void BoostGraphCreator::createFromAtoms(
+    const std::vector<atom *> &_atoms,
+    const predicate_t &_pred)
+{
+  // sort makes binary_search possible
+  std::vector<atomId_t> atomids;
+  std::transform(_atoms.begin(), _atoms.end(),
+      std::back_inserter(atomids), getAtomId);
+  ASSERT( _atoms.size() == atomids.size(),
+      "BoostGraphCreator::createFromAtom() - atomids and atoms differ in size?");
+  std::sort(atomids.begin(), atomids.end());
+  const predicate_t predicate = boost::bind(inSetPredicate, boost::ref(atomids), _1);
+  createFromRange<std::vector<atom *>::const_iterator>(
+      const_cast<const std::vector<atom *> &>(_atoms).begin(),
+      const_cast<const std::vector<atom *> &>(_atoms).end(),
+      _atoms.size(),
+      boost::bind(predicateAnd, _pred, predicate, _1));
+}
+
+template <typename iterator>
+void BoostGraphCreator::createFromRange(
+    const iterator &_begin,
+    const iterator &_end,
+    const size_t &_no_nodes,
+    const predicate_t &_pred
+    ) {
+  // convert BondGraph into boost::graph
+  UndirectedGraph molgraph(_no_nodes);
+  for(iterator iter = _begin; iter != _end; ++iter) {
+    LOG(2, "DEBUG: Looking at node " << (*iter)->getId());
+    const BondList& ListOfBonds = (*iter)->getListOfBonds();
+    for(BondList::const_iterator bonditer = ListOfBonds.begin();
+        bonditer != ListOfBonds.end(); ++bonditer) {
+      const atomId_t leftid = (*bonditer)->leftatom->getId();
+      const atomId_t rightid = (*bonditer)->rightatom->getId();
+      // only pick each bond once and evaluate predicate
+      if ((leftid == (*iter)->getId())
+          && (_pred(**bonditer))) {
+        LOG(3, "DEBUG: ADDING edge " << leftid << " <-> " << rightid);
+        boost::add_edge(leftid, rightid, graph);
+      } else {
+        LOG(3, "DEBUG: Discarding edge " << leftid << " <-> " << rightid);
+      }
+    }
+  }
+  LOG(2, "DEBUG: We have " << getNumVertices() << " nodes and " << getNumEdges()
+      << " edges in the molecule graph.");
+}
+
+
Index: src/Graph/BoostGraphCreator.hpp
===================================================================
--- src/Graph/BoostGraphCreator.hpp	(revision d24ef58f28627a24574b012f8f2b174072c4da20)
+++ src/Graph/BoostGraphCreator.hpp	(revision d24ef58f28627a24574b012f8f2b174072c4da20)
@@ -0,0 +1,119 @@
+/*
+ * BoostGraphCreator.hpp
+ *
+ *  Created on: May 17, 2017
+ *      Author: heber
+ */
+
+
+#ifndef GRAPH_BOOSTGRAPHCREATOR_HPP_
+#define GRAPH_BOOSTGRAPHCREATOR_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vector>
+
+#include <boost/function.hpp>
+#include <boost/graph/adjacency_list.hpp>
+
+class atom;
+class bond;
+class molecule;
+
+/** This is a helper class that contains functions to create a boost::graph
+ * from the present bond graph of molecules.
+ */
+struct BoostGraphCreator
+{
+public:
+  //!> typedef for an undirected graph using boost::graph
+  typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS,
+      boost::no_property, boost::no_property > UndirectedGraph;
+  //!> typedef for a map of graph node indices
+  typedef boost::property_map < boost::adjacency_list <>, boost::vertex_index_t >::type index_map_t;
+  //!> typedef for the  predicate to evaluate for adding the current edge or not
+  typedef boost::function<bool (const bond &)> predicate_t;
+
+
+  /** Creates the boost::graph using all atoms and bonds in the given \a _mol.
+   *
+   * \param _mol molecule whose bond graph to construct
+   * \param _pred predicate to evaluate on adding each edge/bond
+   */
+  void createFromMolecule(
+      const molecule &_mol,
+      const predicate_t &_pred);
+
+  /** Creates the boost::graph using all atoms and bonds in the given vector
+   * of \a _atoms
+   *
+   * \param _atoms vector of _atoms whose bond graph to construct
+   * \param _pred predicate to evaluate on adding each edge/bond
+   */
+  void createFromAtoms(
+      const std::vector<atom *> &_atoms,
+      const predicate_t &_pred);
+
+  /** Getter for the created graph.
+   *
+   * \return graph
+   */
+  UndirectedGraph get() const
+  { return graph; }
+
+  /** Getter for the index map  of the created graph.
+   *
+   * \return indexmap
+   */
+  index_map_t getIndexMap() const {
+    return boost::get(boost::vertex_index, graph);
+  }
+
+  /** Return the number of vertices contained in the created graph.
+   *
+   * \return number of vertices
+   */
+  size_t getNumVertices() const {
+    return boost::num_vertices(graph);
+  }
+
+  /** Return the number of edges contained in the created graph.
+   *
+   * \return number of edges
+   */
+  size_t getNumEdges() const {
+    return boost::num_edges(graph);
+  }
+
+private:
+  /** General purpose function that contains the internal logic of walking the
+   * bonds of a set of atoms given by \a _begin and \a _end iterators and
+   * adding its edges to a graph based on the evaluation of a given predicate
+   * \a _pred.
+   *
+   * \note We need \a _no_nodes because molecule::iterator does not work with
+   * std::distance.
+   *
+   * \param _begin begin iterator
+   * \param _end end iterator
+   * \param _no_nodes number of nodes
+   * \param _pred predicate
+   */
+  template <typename iterator>
+  void createFromRange(
+      const iterator &_begin,
+      const iterator &_end,
+      const size_t &_no_nodes,
+      const predicate_t &_pred
+      );
+
+private:
+  //!> internal graph that is created by creator functions
+  UndirectedGraph graph;
+};
+
+
+#endif /* GRAPH_BOOSTGRAPHCREATOR_HPP_ */
Index: src/Graph/Makefile.am
===================================================================
--- src/Graph/Makefile.am	(revision 3b74fa571b14434bdf4e8ec5bf8356451fdb57b7)
+++ src/Graph/Makefile.am	(revision d24ef58f28627a24574b012f8f2b174072c4da20)
@@ -4,4 +4,5 @@
 GRAPHSOURCE = \
 	Graph/BondGraph.cpp \
+	Graph/BoostGraphCreator.cpp \
 	Graph/BuildInducedSubgraph.cpp \
 	Graph/AdjacencyList.cpp \
@@ -12,4 +13,5 @@
 GRAPHHEADER = \
 	Graph/BondGraph.hpp \
+	Graph/BoostGraphCreator.hpp \
 	Graph/BuildInducedSubgraph.hpp \
 	Graph/AdjacencyList.hpp \
