Index: configure.ac
===================================================================
--- configure.ac	(revision 0cbad258eb8c0251e3a78b10e2b68fdd0a5d2791)
+++ configure.ac	(revision 300220077f0507b7ef3d400de839792167c20b51)
@@ -115,6 +115,6 @@
 #AC_MSG_NOTICE(["GLU_CFLAGS: $GLU_CFLAGS, GLU_CXXFLAGS: $GLU_CXXFLAGS, GLU_LDFLAGS: $GLU_LDFLAGS, GLU_LIBS: $GLU_LIBS"])
 
-# CodePatterns library (needs ObservedIterator<> operator==,!= to be const)
-AM_PATH_CODEPATTERNS([1.0.11], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])])
+# CodePatterns library (needs operator<<(.., range<>) ) 
+AM_PATH_CODEPATTERNS([1.0.13], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])])
 
 # Checks for header files.
Index: src/Actions/FragmentationAction/CreateAdjacencyAction.cpp
===================================================================
--- src/Actions/FragmentationAction/CreateAdjacencyAction.cpp	(revision 0cbad258eb8c0251e3a78b10e2b68fdd0a5d2791)
+++ src/Actions/FragmentationAction/CreateAdjacencyAction.cpp	(revision 300220077f0507b7ef3d400de839792167c20b51)
@@ -27,4 +27,5 @@
 #include "bondgraph.hpp"
 #include "CodePatterns/Log.hpp"
+#include "CodePatterns/Range.hpp"
 #include "CodePatterns/Verbose.hpp"
 #include "config.hpp"
@@ -65,5 +66,4 @@
   atom *OtherWalker = NULL;
   int n[NDIM];
-  double MinDistance, MaxDistance;
   LinkedCell *LC = NULL;
   Box &domain = World::getInstance().getDomain();
@@ -136,8 +136,9 @@
                           ASSERT(OtherWalker,"TesselPoint that was not an atom retrieved from LinkedNode");
                           //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
-                          BG->getMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
+                          range<double> MinMaxDistanceSquared(0.,0.);
+                          BG->getMinMaxDistanceSquared(Walker, OtherWalker, MinMaxDistanceSquared, IsAngstroem);
                           const double distance = domain.periodicDistanceSquared(OtherWalker->getPosition(),Walker->getPosition());
-                          const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance);
-//                          Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl;
+                          const bool status = MinMaxDistanceSquared.isInRange(distance);
+//                          LOG3, "INFO: MinMaxDistanceSquared interval is " << MinMaxDistanceSquared << ".");
                           if (AtomIds[OtherWalker->father] > AtomIds[Walker->father]) {
                             if (status) { // create bond if distance is smaller
Index: src/bondgraph.cpp
===================================================================
--- src/bondgraph.cpp	(revision 0cbad258eb8c0251e3a78b10e2b68fdd0a5d2791)
+++ src/bondgraph.cpp	(revision 300220077f0507b7ef3d400de839792167c20b51)
@@ -93,5 +93,7 @@
 }
 
-double BondGraph::GetBondLength(int firstZ, int secondZ)
+double BondGraph::GetBondLength(
+    int firstZ,
+    int secondZ) const
 {
   std::cout << "Request for length between " << firstZ << " and " << secondZ << ": ";
@@ -110,32 +112,66 @@
 }
 
-
-void BondGraph::CovalentMinMaxDistance(const BondedParticle * const Walker, const BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
-{
-  MinDistance = OtherWalker->getType()->getCovalentRadius() + Walker->getType()->getCovalentRadius();
-  MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
-  MaxDistance = MinDistance + BondThreshold;
-  MinDistance -= BondThreshold;
-}
-
-void BondGraph::BondLengthMatrixMinMaxDistance(const BondedParticle * const Walker, const BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
-{
-  ASSERT(BondLengthMatrix != NULL,
-      "BondGraph::BondLengthMatrixMinMaxDistance() called without NULL BondLengthMatrix.");
-  MinDistance = GetBondLength(Walker->getType()->getAtomicNumber()-1, OtherWalker->getType()->getAtomicNumber()-1);
-  MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
-  MaxDistance = MinDistance + BondThreshold;
-  MinDistance -= BondThreshold;
-}
-
-void BondGraph::getMinMaxDistance(const BondedParticle * const Walker, const BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
+void BondGraph::CovalentMinMaxDistance(
+    const element * const Walker,
+    const element * const OtherWalker,
+    range<double> &MinMaxDistance,
+    bool IsAngstroem) const
+{
+  MinMaxDistance.first = OtherWalker->getCovalentRadius() + Walker->getCovalentRadius();
+  MinMaxDistance.first *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
+  MinMaxDistance.last = MinMaxDistance.first + BondThreshold;
+  MinMaxDistance.first -= BondThreshold;
+}
+
+void BondGraph::BondLengthMatrixMinMaxDistance(
+    const element * const Walker,
+    const element * const OtherWalker,
+    range<double> &MinMaxDistance,
+    bool IsAngstroem) const
+{
+  ASSERT(BondLengthMatrix, "BondGraph::BondLengthMatrixMinMaxDistance() called without NULL BondLengthMatrix.");
+  ASSERT(Walker, "BondGraph::BondLengthMatrixMinMaxDistance() - illegal element given.");
+  ASSERT(OtherWalker, "BondGraph::BondLengthMatrixMinMaxDistance() - illegal other element given.");
+  MinMaxDistance.first = GetBondLength(Walker->getAtomicNumber()-1, OtherWalker->getAtomicNumber()-1);
+  MinMaxDistance.first *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
+  MinMaxDistance.last = MinMaxDistance.first + BondThreshold;
+  MinMaxDistance.first -= BondThreshold;
+}
+
+void BondGraph::getMinMaxDistance(
+    const element * const Walker,
+    const element * const OtherWalker,
+    range<double> &MinMaxDistance,
+    bool IsAngstroem) const
 {
   if (BondLengthMatrix == NULL) {// safety measure if no matrix has been parsed yet
-    LOG(2, "INFO: Using Covalent radii criterion for [min,max] distances.");
-    CovalentMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
+    LOG(2, "INFO: Using Covalent radii criterion for [min,max) distances.");
+    CovalentMinMaxDistance(Walker, OtherWalker, MinMaxDistance, IsAngstroem);
   } else {
-    LOG(2, "INFO: Using Covalent radii criterion for [min,max] distances.");
-    BondLengthMatrixMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
-  }
+    LOG(2, "INFO: Using Covalent radii criterion for [min,max) distances.");
+    BondLengthMatrixMinMaxDistance(Walker, OtherWalker, MinMaxDistance, IsAngstroem);
+  }
+}
+
+void BondGraph::getMinMaxDistance(
+    const BondedParticle * const Walker,
+    const BondedParticle * const OtherWalker,
+    range<double> &MinMaxDistance,
+    bool IsAngstroem) const
+{
+  getMinMaxDistance(Walker->getType(), OtherWalker->getType(),MinMaxDistance, IsAngstroem);
+}
+
+void BondGraph::getMinMaxDistanceSquared(
+    const BondedParticle * const Walker,
+    const BondedParticle * const OtherWalker,
+    range<double> &MinMaxDistance,
+    bool IsAngstroem) const
+{
+  // use non-squared version
+  getMinMaxDistance(Walker, OtherWalker,MinMaxDistance, IsAngstroem);
+  // and square
+  MinMaxDistance.first *= MinMaxDistance.first;
+  MinMaxDistance.last *= MinMaxDistance.last;
 }
 
@@ -145,5 +181,4 @@
   atom *OtherWalker = NULL;
   int n[NDIM];
-  double MinDistance, MaxDistance;
   Box &domain = World::getInstance().getDomain();
 
@@ -174,9 +209,9 @@
                         ASSERT(OtherWalker != NULL,
                             "BondGraph::CreateAdjacency() - TesselPoint that was not an atom retrieved from LinkedNode");
-                        getMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
+                        range<double> MinMaxDistanceSquared(0.,0.);
+                        getMinMaxDistanceSquared(Walker, OtherWalker, MinMaxDistanceSquared, IsAngstroem);
                         const double distance = domain.periodicDistanceSquared(OtherWalker->getPosition(),Walker->getPosition());
-                        LOG(2, "INFO: Checking distance " << distance << " against typical bond length of [" << MinDistance * MinDistance << "," << MaxDistance * MaxDistance << "].");
-                        const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance);
-                        LOG(3, "INFO: MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << ".");
+                        LOG(2, "INFO: Checking squared distance " << distance << " against typical bond length of " << MinMaxDistanceSquared << ".");
+                        const bool status = MinMaxDistanceSquared.isInRange(distance);
                         if (OtherWalker->father > Walker->father ) { // just to not add bonds from both sides
                           if (status) { // create bond if distance is smaller
@@ -188,7 +223,6 @@
                           } else {
                             LOG(1, "REJECT: Squared distance "
-                                << distance << " is out of covalent bounds ["
-                                << MinDistance*MinDistance << ","
-                                << MaxDistance * MaxDistance << "].");
+                                << distance << " is out of squared covalent bounds "
+                                << MinMaxDistanceSquared << ".");
                           }
                         } else {
Index: src/bondgraph.hpp
===================================================================
--- src/bondgraph.hpp	(revision 0cbad258eb8c0251e3a78b10e2b68fdd0a5d2791)
+++ src/bondgraph.hpp	(revision 300220077f0507b7ef3d400de839792167c20b51)
@@ -44,4 +44,8 @@
 
 class BondGraph {
+  //!> analysis bonds unit test should be friend to access private parts.
+  friend class AnalysisBondsTest;
+  //!> own bond graph unit test should be friend to access private parts.
+  friend class BondGraphTest;
 public:
   /** Constructor of class BondGraph.
@@ -62,11 +66,4 @@
   bool LoadBondLengthTable(std::istream &input);
 
-  /** Returns the entry for a given index pair.
-   * \param firstelement index/atom number of first element (row index)
-   * \param secondelement index/atom number of second element (column index)
-   * \note matrix is of course symmetric.
-   */
-  double GetBondLength(int firstelement, int secondelement);
-
   /** Determines the maximum of all element::CovalentRadius for elements present in \a &Set.
    *
@@ -103,12 +100,29 @@
 
   /** Returns bond criterion for given pair based on a bond length matrix.
-   * This calls either the covalent or the bond matrix criterion.
+   * This calls element-version of getMinMaxDistance().
    * \param *Walker first BondedParticle
    * \param *OtherWalker second BondedParticle
-   * \param &MinDistance lower bond bound on return
-   * \param &MaxDistance upper bond bound on return
+   * \param &MinMaxDistance Range for interval on return
    * \param IsAngstroem whether units are in angstroem or bohr radii
    */
-  void getMinMaxDistance(const BondedParticle * const Walker, const BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem);
+  void getMinMaxDistance(
+      const BondedParticle * const Walker,
+      const BondedParticle * const OtherWalker,
+      range<double> &MinMaxDistance,
+      bool IsAngstroem) const;
+
+  /** Returns SQUARED bond criterion for given pair based on a bond length matrix.
+   * This calls element-version of getMinMaxDistance() and squares the values
+   * of either interval end.
+   * \param *Walker first BondedParticle
+   * \param *OtherWalker second BondedParticle
+   * \param &MinMaxDistance Range for interval on return
+   * \param IsAngstroem whether units are in angstroem or bohr radii
+   */
+  void getMinMaxDistanceSquared(
+      const BondedParticle * const Walker,
+      const BondedParticle * const OtherWalker,
+      range<double> &MinMaxDistance,
+      bool IsAngstroem) const;
 
   /** Creates the adjacency list for a given \a Range of iterable atoms.
@@ -291,4 +305,13 @@
   static const double BondThreshold;
 
+  /** Returns the BondLengthMatrix entry for a given index pair.
+   * \param firstelement index/atom number of first element (row index)
+   * \param secondelement index/atom number of second element (column index)
+   * \note matrix is of course symmetric.
+   */
+  double GetBondLength(
+      int firstelement,
+      int secondelement) const;
+
   /** Returns bond criterion for given pair based on a bond length matrix.
    * The matrix should be contained in \a this BondGraph and contain an element-
@@ -296,18 +319,38 @@
    * \param *Walker first BondedParticle
    * \param *OtherWalker second BondedParticle
-   * \param &MinDistance lower bond bound on return
-   * \param &MaxDistance upper bond bound on return
+   * \param &MinMaxDistance Range for interval on return
    * \param IsAngstroem whether units are in angstroem or bohr radii
    */
-  void BondLengthMatrixMinMaxDistance(const BondedParticle * const Walker, const BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem);
-
-  /** Returns bond criterion for given pair based on covalent radius.
-   * \param *Walker first BondedParticle
-   * \param *OtherWalker second BondedParticle
-   * \param &MinDistance lower bond bound on return
-   * \param &MaxDistance upper bond bound on return
+  void getMinMaxDistance(
+      const element * const Walker,
+      const element * const OtherWalker,
+      range<double> &MinMaxDistance,
+      bool IsAngstroem) const;
+
+  /** Returns bond criterion for given pair of elements based on a bond length matrix.
+   * The matrix should be contained in \a this BondGraph and contain an element-
+   * to-element length.
+   * \param *Walker first element
+   * \param *OtherWalker second element
+   * @param MinMaxDistance reference to range type set on return
    * \param IsAngstroem whether units are in angstroem or bohr radii
    */
-  void CovalentMinMaxDistance(const BondedParticle * const Walker, const BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem);
+  void BondLengthMatrixMinMaxDistance(
+      const element * const Walker,
+      const element * const OtherWalker,
+      range<double> &DistanceInterval,
+      bool IsAngstroem) const;
+
+  /** Returns bond criterion for given pair of elements based on covalent radius.
+   * \param *Walker first element
+   * \param *OtherWalker second element
+   * @param MinMaxDistance reference to range type set on return
+   * \param IsAngstroem whether units are in angstroem or bohr radii
+   */
+  void CovalentMinMaxDistance(
+      const element * const Walker,
+      const element * const OtherWalker,
+      range<double> &DistanceInterval,
+      bool IsAngstroem) const;
 
 
Index: src/molecule.cpp
===================================================================
--- src/molecule.cpp	(revision 0cbad258eb8c0251e3a78b10e2b68fdd0a5d2791)
+++ src/molecule.cpp	(revision 300220077f0507b7ef3d400de839792167c20b51)
@@ -344,13 +344,8 @@
    // the problem is not the H being out of the box, but InBondvector have the wrong direction
    // due to TopReplacement or Origin being on the wrong side!
-  double MinBondDistance;
-  double MaxBondDistance;
-  World::getInstance().getBondGraph()->getMinMaxDistance(
-      TopOrigin,
-      TopReplacement,
-      MinBondDistance,MaxBondDistance,IsAngstroem);
-  std::cout << "bondlength > MaxBondDistance: " << bondlength << " > " <<  MaxBondDistance << std::endl;
-  std::cout << "bondlength < MinBondDistance: " << bondlength << " < " <<  MinBondDistance << std::endl;
-  if ((bondlength < MinBondDistance) || (bondlength > MaxBondDistance)) {
+  range<double> MinMaxBondDistance(0.,0.);
+  const BondGraph * const BG = World::getInstance().getBondGraph();
+  BG->getMinMaxDistance(TopOrigin,TopReplacement,MinMaxBondDistance,IsAngstroem);
+  if (!MinMaxBondDistance.isInRange(bondlength)) {
 //    Log() << Verbose(4) << "InBondvector is: ";
 //    InBondvector.Output(out);
@@ -359,5 +354,5 @@
     for (int i=NDIM;i--;) {
       l = TopReplacement->at(i) - TopOrigin->at(i);
-      if (fabs(l) > MaxBondDistance) { // is component greater than bond distance (check against min not useful here)
+      if (fabs(l) > MinMaxBondDistance.last) { // is component greater than bond distance (check against min not useful here)
         Orthovector1[i] = (l < 0) ? -1. : +1.;
       } // (signs are correct, was tested!)
Index: src/molecule_fragmentation.cpp
===================================================================
--- src/molecule_fragmentation.cpp	(revision 0cbad258eb8c0251e3a78b10e2b68fdd0a5d2791)
+++ src/molecule_fragmentation.cpp	(revision 300220077f0507b7ef3d400de839792167c20b51)
@@ -1811,8 +1811,7 @@
           tmp = fabs(Binder->leftatom->at(i) - Binder->rightatom->at(i));
           //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
-          double MinBondDistance;
-          double MaxBondDistance;
-          BG->getMinMaxDistance(Binder->leftatom, Binder->rightatom, MinBondDistance, MaxBondDistance, true);
-          if ((tmp < MinBondDistance) || ((tmp > MaxBondDistance))) {
+          range<double> MinMaxDistance(0.,0.);
+          BG->getMinMaxDistance(Binder->leftatom, Binder->rightatom, MinMaxDistance, true);
+          if (!MinMaxDistance.isInRange(tmp)) {
             DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl);
             flag = true;
@@ -1827,8 +1826,7 @@
       for (int i=NDIM;i--;) {
         tmp = Binder->leftatom->at(i) - Binder->rightatom->at(i);
-        double MinBondDistance;
-        double MaxBondDistance;
-        BG->getMinMaxDistance(Binder->leftatom, Binder->rightatom, MinBondDistance, MaxBondDistance, true);
-        if (fabs(tmp) > MaxBondDistance)  // check against Min is not useful for components
+        range<double> MinMaxDistance(0.,0.);
+        BG->getMinMaxDistance(Binder->leftatom, Binder->rightatom, MinMaxDistance, true);
+        if (fabs(tmp) > MinMaxDistance.last)  // check against Min is not useful for components
           Translationvector[i] = (tmp < 0) ? +1. : -1.;
       }
Index: src/molecule_geometry.cpp
===================================================================
--- src/molecule_geometry.cpp	(revision 0cbad258eb8c0251e3a78b10e2b68fdd0a5d2791)
+++ src/molecule_geometry.cpp	(revision 300220077f0507b7ef3d400de839792167c20b51)
@@ -393,8 +393,7 @@
             for (int j=0;j<NDIM;j++) {
               tmp = (*iter)->at(j) - (*Runner)->GetOtherAtom(*iter)->at(j);
-              double MinBondDistance;
-              double MaxBondDistance;
-              BG->getMinMaxDistance((*iter), (*Runner)->GetOtherAtom(*iter), MinBondDistance, MaxBondDistance, true);
-              if (fabs(tmp) > MaxBondDistance) {  // check against Min is not useful for components
+              range<double> MinMaxBondDistance(0.,0.);
+              BG->getMinMaxDistance((*iter), (*Runner)->GetOtherAtom(*iter), MinMaxBondDistance, true);
+              if (fabs(tmp) > MinMaxBondDistance.last) {  // check against Min is not useful for components
                 flag = false;
                 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << (*iter)->getName() << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
