Index: src/Fragmentation/BondsPerShortestPath.cpp
===================================================================
--- src/Fragmentation/BondsPerShortestPath.cpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
+++ src/Fragmentation/BondsPerShortestPath.cpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -0,0 +1,208 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2010 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * BondsPerShortestPath.cpp
+ *
+ *  Created on: Oct 18, 2011
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "BondsPerShortestPath.hpp"
+
+#include "CodePatterns/Log.hpp"
+
+#include "atom.hpp"
+#include "Bond/bond.hpp"
+#include "Element/element.hpp"
+
+BondsPerShortestPath::BondsPerShortestPath(int _Order) :
+  Order(_Order)
+{
+  InitialiseSPList();
+}
+
+BondsPerShortestPath::~BondsPerShortestPath()
+{
+  // free Order-dependent entries of UniqueFragments structure for next loop cycle
+  FreeSPList();
+}
+
+/** Allocates memory for BondsPerShortestPath::BondsPerSPList.
+ * \sa BondsPerShortestPath::FreeSPList()
+ */
+void BondsPerShortestPath::InitialiseSPList()
+{
+  BondsPerSPList.resize(Order);
+  BondsPerSPCount = new int[Order];
+  for (int i=Order;i--;) {
+    BondsPerSPCount[i] = 0;
+  }
+};
+
+/** Free's memory for for BondsPerShortestPath::BondsPerSPList.
+ * \sa BondsPerShortestPath::InitialiseSPList()
+ */
+void BondsPerShortestPath::FreeSPList()
+{
+  delete[](BondsPerSPCount);
+};
+
+/** Sets FragmenSearch to initial value.
+ * Sets BondsPerShortestPath::ShortestPathList entries to zero, BondsPerShortestPath::BondsPerSPCount to zero (except zero level to 1) and
+ * adds initial bond BondsPerShortestPath::Root to BondsPerShortestPath::Root to BondsPerShortestPath::BondsPerSPList
+ * \param *_Root root node, self loop becomes first bond
+ * \sa BondsPerShortestPath::FreeSPList()
+ */
+void BondsPerShortestPath::SetSPList(atom *_Root)
+{
+  // prepare root level (SP = 0) and a loop bond denoting Root
+  for (int i=Order;i--;)
+    BondsPerSPCount[i] = 0;
+  BondsPerSPCount[0] = 1;
+  bond *Binder = new bond(_Root, _Root);
+  BondsPerSPList[0].push_back(Binder);
+};
+
+/** Resets BondsPerShortestPath::ShortestPathList and cleans bonds from BondsPerShortestPath::BondsPerSPList.
+ * \sa BondsPerShortestPath::InitialiseSPList()
+ */
+void BondsPerShortestPath::ResetSPList()
+{
+  DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
+  for(int i=Order;i--;) {
+    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
+    // delete added bonds
+    for (BondsPerSP::iterator iter = BondsPerSPList[i].begin();
+        iter != BondsPerSPList[i].end();
+        ++iter) {
+      delete(*iter);
+    }
+    BondsPerSPList[i].clear();
+    // also start and end node
+    DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
+  }
+};
+
+
+/** Fills the Bonds per Shortest Path List and set the vertex labels.
+ * \param _RootKeyNr index of root node
+ * \param RestrictedKeySet Restricted vertex set to use in context of molecule
+ */
+void BondsPerShortestPath::FillSPListandLabelVertices(int _RootKeyNr, KeySet &RestrictedKeySet)
+{
+  // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
+  // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
+  // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
+  // (EdgeinSPLevel) of this tree ...
+  // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
+  // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
+  int AtomKeyNr = -1;
+  atom *Walker = NULL;
+  atom *OtherWalker = NULL;
+  atom *Predecessor = NULL;
+  bond *Binder = NULL;
+  int RootKeyNr = _RootKeyNr;
+  int RemainingWalkers = -1;
+  int SP = -1;
+
+  DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);
+  for (SP = 0; SP < (Order-1); SP++) {
+    DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << BondsPerSPCount[SP] << " item(s)");
+    if (SP > 0) {
+      DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << BondsPerSPCount[SP-1] << " item(s)." << endl);
+      BondsPerSPCount[SP] = 0;
+    } else
+      DoLog(0) && (Log() << Verbose(0) << "." << endl);
+
+    RemainingWalkers = BondsPerSPCount[SP];
+    for (BondsPerSP::const_iterator CurrentEdge = BondsPerSPList[SP].begin();
+        CurrentEdge != BondsPerSPList[SP].end();
+        ++CurrentEdge) { /// start till end of this SP level's list
+      RemainingWalkers--;
+      Walker = (*CurrentEdge)->rightatom;    // rightatom is always the one more distant
+      Predecessor = (*CurrentEdge)->leftatom;    // ... and leftatom is predecessor
+      AtomKeyNr = Walker->getNr();
+      DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->getNr() << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);
+      // check for new sp level
+      // go through all its bonds
+      DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);
+      const BondList& ListOfBonds = Walker->getListOfBonds();
+      for (BondList::const_iterator Runner = ListOfBonds.begin();
+          Runner != ListOfBonds.end();
+          ++Runner) {
+        OtherWalker = (*Runner)->GetOtherAtom(Walker);
+        if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())
+  #ifdef ADDHYDROGEN
+         && (OtherWalker->getType()->getAtomicNumber() != 1)
+  #endif
+                                                              ) {  // skip hydrogens and restrict to fragment
+          DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << "." << endl);
+          // set the label if not set (and push on root stack as well)
+          if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
+            // add the bond in between to the SP list
+            Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
+            BondsPerSPList[SP+1].push_back(Binder);
+            BondsPerSPCount[SP+1]++;
+            DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << BondsPerSPCount[SP+1] << " item(s)." << endl);
+          } else {
+            if (OtherWalker != Predecessor)
+              DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << "." << endl);
+            else
+              DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);
+          }
+        } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
+      }
+    }
+  }
+};
+
+/** prints the Bonds per Shortest Path list in BondsPerShortestPath.
+ */
+void BondsPerShortestPath::OutputSPList()
+{
+  DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
+  for(int i=1;i<Order;i++) {    // skip the root edge in the printing
+    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
+    for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
+        Binder != BondsPerSPList[i].end();
+        ++Binder) {
+      DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
+    }
+  }
+};
+
+/** Simply counts all bonds in all BondsPerShortestPath::BondsPerSPList lists.
+ */
+int BondsPerShortestPath::CountNumbersInBondsList()
+{
+  int SP = -1;  // the Root <-> Root edge must be subtracted!
+  for(int i=Order;i--;) { // sum up all found edges
+    for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
+        Binder != BondsPerSPList[i].end();
+        ++Binder) {
+      SP++;
+    }
+  }
+  return SP;
+};
+
+/** Getter for BondsPerShortestPath::Order.
+ *
+ * @return returns BondsPerShortestPath::Order
+ */
+int BondsPerShortestPath::getOrder() const
+{
+  return Order;
+}
Index: src/Fragmentation/BondsPerShortestPath.hpp
===================================================================
--- src/Fragmentation/BondsPerShortestPath.hpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
+++ src/Fragmentation/BondsPerShortestPath.hpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -0,0 +1,52 @@
+/*
+ * BondsPerShortestPath.hpp
+ *
+ *  Created on: Oct 18, 2011
+ *      Author: heber
+ */
+
+#ifndef BONDSPERSHORTESTPATH_HPP_
+#define BONDSPERSHORTESTPATH_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <list>
+#include <vector>
+
+#include "graph.hpp"
+
+class atom;
+class bond;
+
+class BondsPerShortestPath
+{
+public:
+  explicit BondsPerShortestPath(int _Order);
+  ~BondsPerShortestPath();
+
+  void InitialiseSPList();
+  void FreeSPList();
+  void SetSPList(atom *_Root);
+  void ResetSPList();
+  void FillSPListandLabelVertices(int _RootKeyNr, KeySet &RestrictedKeySet);
+  void OutputSPList();
+  int CountNumbersInBondsList();
+
+  int getOrder() const;
+
+  typedef std::list<bond*> BondsPerSP;
+  typedef std::vector< BondsPerSP > AllSPBonds;
+
+  int *BondsPerSPCount;
+  AllSPBonds BondsPerSPList;
+
+private:
+  //!> bond order (limits BFS exploration and "number of digits" in power set generation
+  int Order;
+};
+
+
+#endif /* BONDSPERSHORTESTPATH_HPP_ */
Index: src/Fragmentation/Makefile.am
===================================================================
--- src/Fragmentation/Makefile.am	(revision d0b375b2180798e3740178ea430700a3329073f6)
+++ src/Fragmentation/Makefile.am	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -3,4 +3,5 @@
 
 FRAGMENTATIONSOURCE = \
+	Fragmentation/BondsPerShortestPath.cpp \
 	Fragmentation/EnergyMatrix.cpp \
 	Fragmentation/ForceMatrix.cpp \
@@ -14,4 +15,5 @@
 
 FRAGMENTATIONHEADER = \
+	Fragmentation/BondsPerShortestPath.hpp \
 	Fragmentation/defs.hpp \
 	Fragmentation/EnergyMatrix.hpp \
Index: src/Fragmentation/PowerSetGenerator.cpp
===================================================================
--- src/Fragmentation/PowerSetGenerator.cpp	(revision d0b375b2180798e3740178ea430700a3329073f6)
+++ src/Fragmentation/PowerSetGenerator.cpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -31,6 +31,7 @@
  *
  */
-PowerSetGenerator::PowerSetGenerator() :
-  FragmentSearch(NULL)
+PowerSetGenerator::PowerSetGenerator(class UniqueFragments *_FragmentSearch, int Order) :
+  BondsPerSPList(Order),
+  FragmentSearch(_FragmentSearch)
 {}
 
@@ -44,5 +45,4 @@
 
 /** Clears the touched list
- * \param *out output stream for debugging
  * \param verbosity verbosity level
  * \param *&TouchedList touched list
@@ -60,5 +60,4 @@
 
 /** Adds the current combination of the power set to the snake stack.
- * \param *out output stream for debugging
  * \param verbosity verbosity level
  * \param CurrentCombination
@@ -141,5 +140,4 @@
 
 /** Remove all items that were added on this SP level.
- * \param *out output stream for debugging
  * \param verbosity verbosity level
  * \param *FragmentSet snake stack to remove from
@@ -172,30 +170,27 @@
  * Note that we may use the fact that the atoms are SP-ordered on the atomstack. I.e. when popping always the last, we first get all
  * with SP of 2, then those with SP of 3, then those with SP of 4 and so on.
- * \param *_FragmentSearch helpful structure containing additional information
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
  * \param RestrictedKeySet Restricted vertex set to use in context of molecule
  * \return number of inserted fragments
  * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore
  */
-int PowerSetGenerator::operator()(struct UniqueFragments *_FragmentSearch, int Order, KeySet RestrictedKeySet)
-{
-  FragmentSearch = _FragmentSearch;
+int PowerSetGenerator::operator()(KeySet &RestrictedKeySet)
+{
   int Counter = FragmentSearch->FragmentCounter; // mark current value of counter
 
   DoLog(0) && (Log() << Verbose(0) << endl);
-  DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch->getRoot() << "." << endl);
-
-  FragmentSearch->SetSPList(Order);
+  DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << BondsPerSPList.getOrder() << " at Root " << *FragmentSearch->getRoot() << "." << endl);
+
+  BondsPerSPList.SetSPList(FragmentSearch->getRoot());
 
   // do a BFS search to fill the SP lists and label the found vertices
-  FragmentSearch->FillSPListandLabelVertices(Order, RestrictedKeySet);
+  BondsPerSPList.FillSPListandLabelVertices(FragmentSearch->getRoot()->GetTrueFather()->getNr(), RestrictedKeySet);
 
   // outputting all list for debugging
-  FragmentSearch->OutputSPList(Order);
+  BondsPerSPList.OutputSPList();
 
   // creating fragments with the found edge sets  (may be done in reverse order, faster)
-  int SP = FragmentSearch->CountNumbersInBondsList(Order);
+  int SP = BondsPerSPList.CountNumbersInBondsList();
   DoLog(0) && (Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl);
-  if (SP >= (Order-1)) {
+  if (SP >= (BondsPerSPList.getOrder()-1)) {
     // start with root (push on fragment stack)
     DoLog(0) && (Log() << Verbose(0) << "Starting fragment generation with " << *FragmentSearch->getRoot() << ", local nr is " << FragmentSearch->getRoot()->getNr() << "." << endl);
@@ -205,12 +200,12 @@
     // prepare the subset and call the generator
     std::vector<bond*> BondsList;
-    BondsList.resize(FragmentSearch->BondsPerSPCount[0]);
-    ASSERT(FragmentSearch->BondsPerSPList[0].size() != 0,
-        "molecule::PowerSetGenerator() - FragmentSearch->BondsPerSPList[0] contains no root bond.");
-    BondsList[0] = (*FragmentSearch->BondsPerSPList[0].begin());  // on SP level 0 there's only the root bond
-
-    SPFragmentGenerator(0, BondsList, FragmentSearch->BondsPerSPCount[0], Order);
+    BondsList.resize(BondsPerSPList.BondsPerSPCount[0]);
+    ASSERT(BondsPerSPList.BondsPerSPList[0].size() != 0,
+        "molecule::PowerSetGenerator() - BondsPerSPList.BondsPerSPList[0] contains no root bond.");
+    BondsList[0] = (*BondsPerSPList.BondsPerSPList[0].begin());  // on SP level 0 there's only the root bond
+
+    SPFragmentGenerator(0, BondsList, BondsPerSPList.BondsPerSPCount[0], BondsPerSPList.getOrder());
   } else {
-    DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl);
+    DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << BondsPerSPList.getOrder() << "-body fragments." << endl);
   }
 
@@ -221,5 +216,5 @@
 
   // free'ing the bonds lists
-  FragmentSearch->ResetSPList(Order);
+  BondsPerSPList.ResetSPList();
 
   // return list
@@ -283,10 +278,10 @@
 
           // first count the members in the subset
-          SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
+          SubSetDimension = CountSetMembers(BondsPerSPList.BondsPerSPList[SP].begin(), BondsPerSPList.BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
 
           // then allocate and fill the list
           std::vector<bond *> BondsList;
           BondsList.resize(SubSetDimension);
-          SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
+          SubSetDimension = FillBondsList(BondsList, BondsPerSPList.BondsPerSPList[SP].begin(), BondsPerSPList.BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
 
           // then iterate
Index: src/Fragmentation/PowerSetGenerator.hpp
===================================================================
--- src/Fragmentation/PowerSetGenerator.hpp	(revision d0b375b2180798e3740178ea430700a3329073f6)
+++ src/Fragmentation/PowerSetGenerator.hpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -17,4 +17,5 @@
 #include <vector>
 
+#include "Fragmentation/BondsPerShortestPath.hpp"
 #include "graph.hpp"
 
@@ -25,9 +26,9 @@
 {
 public:
-  PowerSetGenerator();
+  PowerSetGenerator(UniqueFragments *_FragmentSearch, int Order);
   ~PowerSetGenerator();
 
   void SPFragmentGenerator(int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);
-  int operator()(struct UniqueFragments *_FragmentSearch, int Order, KeySet RestrictedKeySet);
+  int operator()(KeySet &RestrictedKeySet);
   void RemoveAllTouchedFromSnakeStack(int verbosity, KeySet *FragmentSet, int *&TouchedList, int &TouchedIndex);
   int FillBondsList(std::vector<bond *> &BondsList, std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex);
@@ -37,4 +38,6 @@
 
 private:
+  BondsPerShortestPath BondsPerSPList;
+
   class UniqueFragments *FragmentSearch;
 };
Index: src/Fragmentation/UniqueFragments.cpp
===================================================================
--- src/Fragmentation/UniqueFragments.cpp	(revision d0b375b2180798e3740178ea430700a3329073f6)
+++ src/Fragmentation/UniqueFragments.cpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -58,168 +58,4 @@
 };
 
-/** Allocates memory for UniqueFragments::BondsPerSPList.
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
- * \sa UniqueFragments::FreeSPList()
- */
-void UniqueFragments::InitialiseSPList(int Order)
-{
-  BondsPerSPList.resize(Order);
-  BondsPerSPCount = new int[Order];
-  for (int i=Order;i--;) {
-    BondsPerSPCount[i] = 0;
-  }
-};
-
-/** Free's memory for for UniqueFragments::BondsPerSPList.
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
- * \sa UniqueFragments::InitialiseSPList()
- */
-void UniqueFragments::FreeSPList(int Order)
-{
-  delete[](BondsPerSPCount);
-};
-
-/** Sets FragmenSearch to initial value.
- * Sets UniqueFragments::BondsPerSPCount to zero (except zero level to 1) and adds initial bond
- * UniqueFragments::Root to UniqueFragments::Root to UniqueFragments::BondsPerSPList
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
- * \sa UniqueFragments::FreeSPList()
- */
-void UniqueFragments::SetSPList(int Order)
-{
-  // prepare root level (SP = 0) and a loop bond denoting Root
-  for (int i=Order;i--;)
-    BondsPerSPCount[i] = 0;
-  BondsPerSPCount[0] = 1;
-  bond *Binder = new bond(Root, Root);
-  BondsPerSPList[0].push_back(Binder);
-};
-
-/** Cleans bonds from UniqueFragments::BondsPerSPList.
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
- * \sa UniqueFragments::InitialiseSPList()
- */
-void UniqueFragments::ResetSPList(int Order)
-{
-  DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
-  for(int i=Order;i--;) {
-    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
-    // delete added bonds
-    for (UniqueFragments::BondsPerSP::iterator iter = BondsPerSPList[i].begin();
-        iter != BondsPerSPList[i].end();
-        ++iter) {
-      delete(*iter);
-    }
-    BondsPerSPList[i].clear();
-    // also start and end node
-    DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
-  }
-};
-
-
-/** Fills the Bonds per Shortest Path List and set the vertex labels.
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
- * \param RestrictedKeySet Restricted vertex set to use in context of molecule
- */
-void UniqueFragments::FillSPListandLabelVertices(int Order, KeySet &RestrictedKeySet)
-{
-  // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
-  // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
-  // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
-  // (EdgeinSPLevel) of this tree ...
-  // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
-  // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
-  int AtomKeyNr = -1;
-  atom *Walker = NULL;
-  atom *OtherWalker = NULL;
-  atom *Predecessor = NULL;
-  bond *Binder = NULL;
-  int RootKeyNr = Root->GetTrueFather()->getNr();
-  int RemainingWalkers = -1;
-  int SP = -1;
-
-  DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);
-  for (SP = 0; SP < (Order-1); SP++) {
-    DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << BondsPerSPCount[SP] << " item(s)");
-    if (SP > 0) {
-      DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << BondsPerSPCount[SP-1] << " item(s)." << endl);
-      BondsPerSPCount[SP] = 0;
-    } else
-      DoLog(0) && (Log() << Verbose(0) << "." << endl);
-
-    RemainingWalkers = BondsPerSPCount[SP];
-    for (BondsPerSP::const_iterator CurrentEdge = BondsPerSPList[SP].begin();
-        CurrentEdge != BondsPerSPList[SP].end();
-        ++CurrentEdge) { /// start till end of this SP level's list
-      RemainingWalkers--;
-      Walker = (*CurrentEdge)->rightatom;    // rightatom is always the one more distant
-      Predecessor = (*CurrentEdge)->leftatom;    // ... and leftatom is predecessor
-      AtomKeyNr = Walker->getNr();
-      DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->getNr() << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);
-      // check for new sp level
-      // go through all its bonds
-      DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);
-      const BondList& ListOfBonds = Walker->getListOfBonds();
-      for (BondList::const_iterator Runner = ListOfBonds.begin();
-          Runner != ListOfBonds.end();
-          ++Runner) {
-        OtherWalker = (*Runner)->GetOtherAtom(Walker);
-        if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())
-  #ifdef ADDHYDROGEN
-         && (OtherWalker->getType()->getAtomicNumber() != 1)
-  #endif
-                                                              ) {  // skip hydrogens and restrict to fragment
-          DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << "." << endl);
-          // set the label if not set (and push on root stack as well)
-          if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
-            // add the bond in between to the SP list
-            Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
-            BondsPerSPList[SP+1].push_back(Binder);
-            BondsPerSPCount[SP+1]++;
-            DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << BondsPerSPCount[SP+1] << " item(s)." << endl);
-          } else {
-            if (OtherWalker != Predecessor)
-              DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << "." << endl);
-            else
-              DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);
-          }
-        } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
-      }
-    }
-  }
-};
-
-/** prints the Bonds per Shortest Path list in UniqueFragments.
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
- */
-void UniqueFragments::OutputSPList(int Order)
-{
-  DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
-  for(int i=1;i<Order;i++) {    // skip the root edge in the printing
-    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
-    for (UniqueFragments::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
-        Binder != BondsPerSPList[i].end();
-        ++Binder) {
-      DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
-    }
-  }
-};
-
-/** Simply counts all bonds in all UniqueFragments::BondsPerSPList lists.
- * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
- */
-int UniqueFragments::CountNumbersInBondsList(int Order)
-{
-  int SP = -1;  // the Root <-> Root edge must be subtracted!
-  for(int i=Order;i--;) { // sum up all found edges
-    for (UniqueFragments::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
-        Binder != BondsPerSPList[i].end();
-        ++Binder) {
-      SP++;
-    }
-  }
-  return SP;
-};
-
 /** Initialization for UniqueFragments.
  *
@@ -247,5 +83,5 @@
  * @return const ref to root atom.
  */
-const atom *UniqueFragments::getRoot() const
+atom * const UniqueFragments::getRoot() const
 {
   return Root;
@@ -260,2 +96,15 @@
   Root=_root;
 }
+
+/** Sets initial values before PowerSetGenerator uses this class.
+ *
+ * @param _TEFactor total energy factor
+ * @param _Leaflet current graph to work on
+ * @param _Root root atom
+ */
+void UniqueFragments::PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root)
+{
+  TEFactor = _TEFactor;
+  Leaflet = _Leaflet;
+  Root = _Root;
+}
Index: src/Fragmentation/UniqueFragments.hpp
===================================================================
--- src/Fragmentation/UniqueFragments.hpp	(revision d0b375b2180798e3740178ea430700a3329073f6)
+++ src/Fragmentation/UniqueFragments.hpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -31,31 +31,20 @@
   ~UniqueFragments();
 
-  typedef std::list<bond*> BondsPerSP;
-  typedef std::vector< BondsPerSP > AllSPBonds;
-
   void InsertFragmentIntoGraph(); // Insert a KeySet into a Graph
-  void InitialiseSPList(int Order);
-  void FreeSPList(int Order);
-  void SetSPList(int Order);
-  void ResetSPList(int Order);
-  void FillSPListandLabelVertices(int Order, KeySet &RestrictedKeySet);
-  void OutputSPList(int Order);
-  int CountNumbersInBondsList(int Order);
   void Init(atom *_Root);
   void Cleanup();
 
-  const atom *getRoot() const;
+  atom * const getRoot() const;
   void setRoot(atom *_root);
+
+  void PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root);
 
   KeySet *FragmentSet;
   int FragmentCounter;
-  int *BondsPerSPCount;
-  double TEFactor;
-  Graph *Leaflet;
-  AllSPBonds BondsPerSPList;
-
 
 private:
   atom *Root;
+  double TEFactor;
+  Graph *Leaflet;
 
 private:
Index: src/molecule_fragmentation.cpp
===================================================================
--- src/molecule_fragmentation.cpp	(revision d0b375b2180798e3740178ea430700a3329073f6)
+++ src/molecule_fragmentation.cpp	(revision 212c179a20d30dfd1c8d9f011f4617d5bc87f1fc)
@@ -661,5 +661,4 @@
   int RootNr = 0;
   struct UniqueFragments FragmentSearch;
-  class PowerSetGenerator PSG;
 
   DoLog(0) && (Log() << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl);
@@ -702,5 +701,5 @@
 
       // initialise Order-dependent entries of UniqueFragments structure
-      FragmentSearch.InitialiseSPList(Order);
+      class PowerSetGenerator PSG(&FragmentSearch, Walker->AdaptiveOrder);
 
       // allocate memory for all lower level orders in this 1D-array of ptrs
@@ -715,9 +714,7 @@
 
       // Create list of Graphs of current Bond Order (i.e. F_{ij})
-      FragmentLowerOrdersList[RootNr][0] =  new Graph;
-      FragmentSearch.TEFactor = 1.;
-      FragmentSearch.Leaflet = FragmentLowerOrdersList[RootNr][0];      // set to insertion graph
-      FragmentSearch.setRoot(Walker);
-      NumMoleculesOfOrder[RootNr] = PSG(&FragmentSearch, Walker->AdaptiveOrder, CompleteMolecule);
+      FragmentLowerOrdersList[RootNr][0] = new Graph;
+      FragmentSearch.PrepareForPowersetGeneration(1., FragmentLowerOrdersList[RootNr][0], Walker);
+      NumMoleculesOfOrder[RootNr] = PSG(CompleteMolecule);
 
       // output resulting number
@@ -734,7 +731,4 @@
       RootStack.push_back(RootKeyNr); // put back on stack
       RootNr++;
-
-      // free Order-dependent entries of UniqueFragments structure for next loop cycle
-      FragmentSearch.FreeSPList(Order);
     }
   }
