Index: src/molecule_fragmentation.cpp
===================================================================
--- src/molecule_fragmentation.cpp	(revision 9d83b69ef70cf27f82b8fcaaf764866bcda9a143)
+++ src/molecule_fragmentation.cpp	(revision 03c77c8433e48594a1c472d7a86b4e799d81c363)
@@ -28,5 +28,4 @@
 #include "element.hpp"
 #include "Helpers/helpers.hpp"
-#include "lists.hpp"
 #include "CodePatterns/Verbose.hpp"
 #include "CodePatterns/Log.hpp"
@@ -1105,9 +1104,10 @@
  * \param SetDimension maximum number of bits in power set
  * \param *FragmentSet snake stack to remove from
+ * \param &BondsSet set of bonds
  * \param *&TouchedList touched list
  * \param TouchedIndex currently touched
  * \return number of set bits
  */
-int AddPowersetToSnakeStack(int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, bond **BondsSet, int *&TouchedList, int &TouchedIndex)
+int AddPowersetToSnakeStack(int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, std::vector<bond *> &BondsSet, int *&TouchedList, int &TouchedIndex)
 {
   atom *OtherWalker = NULL;
@@ -1137,18 +1137,18 @@
 
 /** Counts the number of elements in a power set.
- * \param *SetFirst
- * \param *SetLast
+ * \param SetFirst begin iterator first bond
+ * \param SetLast end iterator
  * \param *&TouchedList touched list
  * \param TouchedIndex currently touched
  * \return number of elements
  */
-int CountSetMembers(bond *SetFirst, bond *SetLast, int *&TouchedList, int TouchedIndex)
+int CountSetMembers(std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex)
 {
   int SetDimension = 0;
-  bond *Binder = SetFirst;    // start node for this level
-  while (Binder->next != SetLast) {    // compare to end node of this level
-    Binder = Binder->next;
+  for( std::list<bond *>::const_iterator Binder = SetFirst;
+      Binder != SetLast;
+      ++Binder) {
     for (int k=TouchedIndex;k--;) {
-      if (Binder->Contains(TouchedList[k]))   // if we added this very endpiece
+      if ((*Binder)->Contains(TouchedList[k]))   // if we added this very endpiece
         SetDimension++;
     }
@@ -1157,21 +1157,21 @@
 };
 
-/** Counts the number of elements in a power set.
- * \param *BondsList bonds list to fill
- * \param *SetFirst
- * \param *SetLast
+/** Fills a list of bonds from another
+ * \param *BondsList bonds array/vector to fill
+ * \param SetFirst begin iterator first bond
+ * \param SetLast end iterator
  * \param *&TouchedList touched list
  * \param TouchedIndex currently touched
  * \return number of elements
  */
-int FillBondsList(bond **BondsList, bond *SetFirst, bond *SetLast, 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)
 {
   int SetDimension = 0;
-  bond *Binder = SetFirst;    // start node for this level
-  while (Binder->next != SetLast) {    // compare to end node of this level
-    Binder = Binder->next;
+  for( std::list<bond *>::const_iterator Binder = SetFirst;
+      Binder != SetLast;
+      ++Binder) {
     for (int k=0;k<TouchedIndex;k++) {
-      if (Binder->leftatom->nr == TouchedList[k])   // leftatom is always the close one
-        BondsList[SetDimension++] = Binder;
+      if ((*Binder)->leftatom->nr == TouchedList[k])   // leftatom is always the closer one
+        BondsList[SetDimension++] = (*Binder);
     }
   }
@@ -1210,11 +1210,11 @@
  *  -# removes all items added into the snake stack (in UniqueFragments structure) added during level (root
 distance) and current set
- * \param *out output stream for debugging
  * \param FragmentSearch UniqueFragments structure with all values needed
  * \param RootDistance current shortest path level, whose set of edges is represented by **BondsSet
+ * \param BondsSet array of bonds to check
  * \param SetDimension Number of possible bonds on this level (i.e. size of the array BondsSet[])
  * \param SubOrder remaining number of allowed vertices to add
  */
-void molecule::SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder)
+void molecule::SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder)
 {
   int verbosity = 0; //FragmentSearch->ANOVAOrder-SubOrder;
@@ -1258,9 +1258,10 @@
 
           // first count the members in the subset
-          SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
+          SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
 
           // then allocate and fill the list
-          bond *BondsList[SubSetDimension];
-          SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
+          std::vector<bond *> BondsList;
+          BondsList.resize(SubSetDimension);
+          SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
 
           // then iterate
@@ -1300,11 +1301,7 @@
 void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch)
 {
-  FragmentSearch.BondsPerSPList = new bond* [Order * 2];
+  FragmentSearch.BondsPerSPList.resize(Order);
   FragmentSearch.BondsPerSPCount = new int[Order];
   for (int i=Order;i--;) {
-    FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
-    FragmentSearch.BondsPerSPList[2*i+1] = new bond();  // end node
-    FragmentSearch.BondsPerSPList[2*i]->next = FragmentSearch.BondsPerSPList[2*i+1];     // intertwine these two
-    FragmentSearch.BondsPerSPList[2*i+1]->previous = FragmentSearch.BondsPerSPList[2*i];
     FragmentSearch.BondsPerSPCount[i] = 0;
   }
@@ -1320,9 +1317,4 @@
 {
   delete[](FragmentSearch.BondsPerSPCount);
-  for (int i=Order;i--;) {
-    delete(FragmentSearch.BondsPerSPList[2*i]);
-    delete(FragmentSearch.BondsPerSPList[2*i+1]);
-  }
-  delete[](FragmentSearch.BondsPerSPList);
 };
 
@@ -1345,5 +1337,5 @@
   FragmentSearch.BondsPerSPCount[0] = 1;
   bond *Binder = new bond(FragmentSearch.Root, FragmentSearch.Root);
-  add(Binder, FragmentSearch.BondsPerSPList[1]);
+  FragmentSearch.BondsPerSPList[0].push_back(Binder);
 };
 
@@ -1356,17 +1348,21 @@
 void ResetSPList(int Order, struct UniqueFragments &FragmentSearch)
 {
-  bond *Binder = NULL;
   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 << ": ");
-    Binder = FragmentSearch.BondsPerSPList[2*i];
-    while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
-      Binder = Binder->next;
+    for (UniqueFragments::BondsPerSP::const_iterator iter = FragmentSearch.BondsPerSPList[i].begin();
+        iter != FragmentSearch.BondsPerSPList[i].end();
+        ++iter) {
       // Log() << Verbose(0) << "Removing atom " << Binder->leftatom->nr << " and " << Binder->rightatom->nr << "." << endl; // make sure numbers are local
-      FragmentSearch.ShortestPathList[Binder->leftatom->nr] = -1;
-      FragmentSearch.ShortestPathList[Binder->rightatom->nr] = -1;
+      FragmentSearch.ShortestPathList[(*iter)->leftatom->nr] = -1;
+      FragmentSearch.ShortestPathList[(*iter)->rightatom->nr] = -1;
     }
     // delete added bonds
-    cleanup(FragmentSearch.BondsPerSPList[2*i], FragmentSearch.BondsPerSPList[2*i+1]);
+    for (UniqueFragments::BondsPerSP::iterator iter = FragmentSearch.BondsPerSPList[i].begin();
+        iter != FragmentSearch.BondsPerSPList[i].end();
+        ++iter) {
+      delete(*iter);
+    }
+    FragmentSearch.BondsPerSPList[i].clear();
     // also start and end node
     DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
@@ -1394,5 +1390,4 @@
   atom *OtherWalker = NULL;
   atom *Predecessor = NULL;
-  bond *CurrentEdge = NULL;
   bond *Binder = NULL;
   int RootKeyNr = FragmentSearch.Root->GetTrueFather()->nr;
@@ -1410,10 +1405,10 @@
 
     RemainingWalkers = FragmentSearch.BondsPerSPCount[SP];
-    CurrentEdge = FragmentSearch.BondsPerSPList[2*SP];    /// start of this SP level's list
-    while (CurrentEdge->next != FragmentSearch.BondsPerSPList[2*SP+1]) {    /// end of this SP level's list
-      CurrentEdge = CurrentEdge->next;
+    for (UniqueFragments::BondsPerSP::const_iterator CurrentEdge = FragmentSearch.BondsPerSPList[SP].begin();
+        CurrentEdge != FragmentSearch.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
+      Walker = (*CurrentEdge)->rightatom;    // rightatom is always the one more distant
+      Predecessor = (*CurrentEdge)->leftatom;    // ... and leftatom is predecessor
       AtomKeyNr = Walker->nr;
       DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->nr << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);
@@ -1438,5 +1433,5 @@
             // 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
-            add(Binder, FragmentSearch.BondsPerSPList[2*(SP+1)+1]);
+            FragmentSearch.BondsPerSPList[SP+1].push_back(Binder);
             FragmentSearch.BondsPerSPCount[SP+1]++;
             DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << FragmentSearch.BondsPerSPCount[SP+1] << " item(s)." << endl);
@@ -1460,11 +1455,10 @@
 void OutputSPList(int Order, struct UniqueFragments &FragmentSearch)
 {
-  bond *Binder = NULL;
   DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
   for(int i=1;i<Order;i++) {    // skip the root edge in the printing
-    Binder = FragmentSearch.BondsPerSPList[2*i];
     DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
-    while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
-      Binder = Binder->next;
+    for (UniqueFragments::BondsPerSP::const_iterator Binder = FragmentSearch.BondsPerSPList[i].begin();
+        Binder != FragmentSearch.BondsPerSPList[i].end();
+        ++Binder) {
       DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
     }
@@ -1479,10 +1473,9 @@
 int CountNumbersInBondsList(int Order, struct UniqueFragments &FragmentSearch)
 {
-  bond *Binder = NULL;
   int SP = -1;  // the Root <-> Root edge must be subtracted!
   for(int i=Order;i--;) { // sum up all found edges
-    Binder = FragmentSearch.BondsPerSPList[2*i];
-    while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
-      Binder = Binder->next;
+    for (UniqueFragments::BondsPerSP::const_iterator Binder = FragmentSearch.BondsPerSPList[i].begin();
+        Binder != FragmentSearch.BondsPerSPList[i].end();
+        ++Binder) {
       SP++;
     }
@@ -1531,8 +1524,9 @@
 
     // prepare the subset and call the generator
-    bond* BondsList[FragmentSearch.BondsPerSPCount[0]];
-    for(int i=0;i<FragmentSearch.BondsPerSPCount[0];i++)
-      BondsList[i] = NULL;
-    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
+    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(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
@@ -1797,5 +1791,5 @@
 {
   bond *Binder = NULL;
-  bond *OtherBinder = NULL;
+  //bond *OtherBinder = NULL;
   atom *Walker = NULL;
   atom *OtherWalker = NULL;
@@ -1803,5 +1797,5 @@
   enum Shading *ColorList = NULL;
   double tmp;
-  bool LastBond = true; // only needed to due list construct
+  //bool LastBond = true; // only needed to due list construct
   Vector Translationvector;
   //std::deque<atom *> *CompStack = NULL;
@@ -1829,12 +1823,4 @@
           //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
           if (tmp > BondDistance) {
-//            OtherBinder = Binder->next; // note down binding partner for later re-insertion
-//            if (OtherBinder != NULL) {
-//              LastBond = false;
-//            } else {
-//              OtherBinder = Binder->previous;
-//              LastBond = true;
-//            }
-//            unlink(Binder);   // unlink bond
             DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl);
             flag = true;
@@ -1877,14 +1863,14 @@
         }
       }
-      // re-add bond
-      if (OtherBinder == NULL) { // is the only bond?
-        //Do nothing
-      } else {
-        if (!LastBond) {
-          link(Binder, OtherBinder);
-        } else {
-          link(OtherBinder, Binder);
-        }
-      }
+//      // re-add bond
+//      if (OtherBinder == NULL) { // is the only bond?
+//        //Do nothing
+//      } else {
+//        if (!LastBond) {
+//          link(Binder, OtherBinder); // no more implemented bond::previous ...
+//        } else {
+//          link(OtherBinder, Binder); // no more implemented bond::previous ...
+//        }
+//      }
     } else {
       DoLog(3) && (Log() << Verbose(3) << "No corrections for this fragment." << endl);
