Index: src/Graph/BoostGraphCreator.hpp
===================================================================
--- src/Graph/BoostGraphCreator.hpp	(revision 6370f98df055b78f20b37cb38a86e6bbf0cb031b)
+++ src/Graph/BoostGraphCreator.hpp	(revision 060fc39009b34e71d0cf196958307bc4565011a5)
@@ -38,7 +38,12 @@
 
 public:
+
   //!> typedef for an undirected graph using boost::graph
   typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS,
-      boost::property<boost::vertex_name_t, atomId_t>, boost::no_property > UndirectedGraph;
+      boost::property<boost::vertex_name_t, atomId_t>,
+      boost::property<boost::vertex_color_t, boost::default_color_type> /* needed for limited-depth DFS,
+      otherwise the property_map gets full size of graph */
+  > UndirectedGraph;
+
   //!> typedef for a map of graph node indices
   typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::type index_map_t;
Index: src/Graph/BreadthFirstSearchGatherer.cpp
===================================================================
--- src/Graph/BreadthFirstSearchGatherer.cpp	(revision 6370f98df055b78f20b37cb38a86e6bbf0cb031b)
+++ src/Graph/BreadthFirstSearchGatherer.cpp	(revision 060fc39009b34e71d0cf196958307bc4565011a5)
@@ -44,4 +44,6 @@
 #include <boost/graph/breadth_first_search.hpp>
 
+struct found_max_distance {}; // exception when doing limited BFS
+
 /**
  * I have no idea why this is so complicated with BGL ...
@@ -54,5 +56,7 @@
 {
 public:
-  distance_recorder(DistanceMap dist) : d(dist) {}
+  distance_recorder(
+      DistanceMap dist,
+      const size_t _max_distance) : d(dist), max_distance(_max_distance) {}
 
   template <typename Edge, typename Graph>
@@ -62,12 +66,19 @@
   }
 
+  template <typename Vertex, typename Graph>
+  void discover_vertex(Vertex u, const Graph &g) const {
+    if ((max_distance > 0) && (d[u] >= max_distance))
+      throw found_max_distance();
+  }
+
 private:
   DistanceMap d;
+  const size_t max_distance;
 };
 
 template <typename DistanceMap>
-distance_recorder<DistanceMap> record_distance(DistanceMap d)
+distance_recorder<DistanceMap> record_distance(DistanceMap d, const size_t _max_distance)
 {
-  return distance_recorder<DistanceMap>(d);
+  return distance_recorder<DistanceMap>(d, _max_distance);
 }
 
@@ -76,5 +87,7 @@
 {}
 
-std::vector<atomId_t> BreadthFirstSearchGatherer::operator()(const atomId_t &_discoverfrom)
+std::vector<atomId_t> BreadthFirstSearchGatherer::operator()(
+    const atomId_t &_discoverfrom,
+    const size_t &_max_distance)
 {
   std::vector<atomId_t> returnids;
@@ -86,8 +99,12 @@
   const BoostGraphCreator::nodeId_t discoverfrom_nodeid = BGcreator.getNodeId(_discoverfrom);
   distances[ boost::vertex(discoverfrom_nodeid, BGgraph) ] = 0;
-  boost::breadth_first_search(
-      BGgraph,
-      boost::vertex(discoverfrom_nodeid, BGgraph),
-      boost::visitor(record_distance(&distances[0])));
+  try {
+    boost::breadth_first_search(
+        BGgraph,
+        boost::vertex(discoverfrom_nodeid, BGgraph),
+        boost::visitor(record_distance(&distances[0], _max_distance)));
+  } catch (found_max_distance &e) {
+    // where are at discovery horizon
+  }
   LOG(3, "DEBUG: From atom #" << _discoverfrom
       << " BFS discovered the following distances " << distances);
Index: src/Graph/BreadthFirstSearchGatherer.hpp
===================================================================
--- src/Graph/BreadthFirstSearchGatherer.hpp	(revision 6370f98df055b78f20b37cb38a86e6bbf0cb031b)
+++ src/Graph/BreadthFirstSearchGatherer.hpp	(revision 060fc39009b34e71d0cf196958307bc4565011a5)
@@ -35,6 +35,11 @@
   /** Discovers all nodes from the given \a _discoverfrom and returns
    * the vector of ids.
+   *
+   * \param _discoverfrom node to start BFS from
+   * \param _max_distance max distance to discover (0 means all)
    */
-  std::vector<atomId_t> operator()(const atomId_t &_discoverfrom);
+  std::vector<atomId_t> operator()(
+      const atomId_t &_discoverfrom,
+      const size_t &_max_distance = 0);
 
 private:
Index: src/Graph/unittests/BreadthFirstSearchGathererUnitTest.cpp
===================================================================
--- src/Graph/unittests/BreadthFirstSearchGathererUnitTest.cpp	(revision 6370f98df055b78f20b37cb38a86e6bbf0cb031b)
+++ src/Graph/unittests/BreadthFirstSearchGathererUnitTest.cpp	(revision 060fc39009b34e71d0cf196958307bc4565011a5)
@@ -105,2 +105,20 @@
   CPPUNIT_ASSERT_EQUAL (compareids, atomids);
 };
+
+/** Tests whether operator() with limited distance works.
+ */
+void BreadthFirstSearchGathererTest::limitedDistanceTest()
+{
+  // create linear test graph
+  prepareLinearGraph();
+
+  // call operator
+  BreadthFirstSearchGatherer gatherer(*BGCreator);
+  std::vector<atomId_t> atomids = gatherer(0, 3);
+
+  // create comparator set
+  std::vector<atomId_t> compareids;
+  compareids += 0,1,2,3;
+  CPPUNIT_ASSERT_EQUAL ((size_t)4, atomids.size());
+  CPPUNIT_ASSERT_EQUAL (compareids, atomids);
+};
Index: src/Graph/unittests/BreadthFirstSearchGathererUnitTest.hpp
===================================================================
--- src/Graph/unittests/BreadthFirstSearchGathererUnitTest.hpp	(revision 6370f98df055b78f20b37cb38a86e6bbf0cb031b)
+++ src/Graph/unittests/BreadthFirstSearchGathererUnitTest.hpp	(revision 060fc39009b34e71d0cf196958307bc4565011a5)
@@ -25,4 +25,5 @@
     CPPUNIT_TEST_SUITE( BreadthFirstSearchGathererTest) ;
     CPPUNIT_TEST ( operatorTest );
+    CPPUNIT_TEST ( limitedDistanceTest );
     CPPUNIT_TEST_SUITE_END();
 
@@ -31,4 +32,5 @@
       void tearDown();
       void operatorTest();
+      void limitedDistanceTest();
 
 private:
