Index: src/Fragmentation/AdaptivityMap.cpp
===================================================================
--- src/Fragmentation/AdaptivityMap.cpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
+++ src/Fragmentation/AdaptivityMap.cpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -0,0 +1,176 @@
+/*
+ * 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.
+ */
+
+/*
+ * AdaptivityMap.cpp
+ *
+ *  Created on: Oct 20, 2011
+ *      Author: heber
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "AdaptivityMap.hpp"
+
+#include <fstream>
+
+#include "CodePatterns/Log.hpp"
+
+#include "atom.hpp"
+#include "Helpers/defs.hpp"
+#include "Helpers/helpers.hpp"
+#include "molecule.hpp"
+
+/** Constructor of class AdaptivityMap.
+ *
+ */
+AdaptivityMap::AdaptivityMap()
+{}
+
+/** Destructor of class AdaptivityMap.
+ *
+ */
+AdaptivityMap::~AdaptivityMap()
+{}
+
+/** Inserts a (\a No, \a value) pair into the list, overwriting present one.
+ * Note if values are equal, No will decided on which is first
+ * \param *out output stream for debugging
+ * \param &AdaptiveCriteriaList list to insert into
+ * \param &IndexedKeySetList list to find key set for a given index \a No
+ * \param FragOrder current bond order of fragment
+ * \param No index of keyset
+ * \param value energy value
+ */
+void AdaptivityMap::InsertIntoAdaptiveCriteriaList(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, int FragOrder, int No, double Value) const
+{
+  const_iterator marker = find(No);    // find keyset to Frag No.
+  if (marker != end()) {  // if found
+    Value *= 1 + MYEPSILON*(*((*marker).second.begin()));     // in case of equal energies this makes them not equal without changing anything actually
+    // as the smallest number in each set has always been the root (we use global id to keep the doubles away), seek smallest and insert into AtomMask
+    std::pair <map<int, pair<double,int> >::iterator, bool> InsertedElement = AdaptiveCriteriaList->insert( make_pair(*((*marker).second.begin()), pair<double,int>( fabs(Value), FragOrder) ));
+    std::map<int, pair<double,int> >::iterator PresentItem = InsertedElement.first;
+    if (!InsertedElement.second) { // this root is already present
+      if ((*PresentItem).second.second < FragOrder)  // if order there is lower, update entry with higher-order term
+        //if ((*PresentItem).second.first < (*runner).first)    // as higher-order terms are not always better, we skip this part (which would always include this site into adaptive increase)
+        {  // if value is smaller, update value and order
+        (*PresentItem).second.first = fabs(Value);
+        (*PresentItem).second.second = FragOrder;
+        DoLog(2) && (Log() << Verbose(2) << "Updated element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
+      } else {
+        DoLog(2) && (Log() << Verbose(2) << "Did not update element " <<  (*PresentItem).first << " as " << FragOrder << " is less than or equal to " << (*PresentItem).second.second << "." << endl);
+      }
+    } else {
+      DoLog(2) && (Log() << Verbose(2) << "Inserted element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
+    }
+  } else {
+    DoLog(1) && (Log() << Verbose(1) << "No Fragment under No. " << No << "found." << endl);
+  }
+};
+
+
+/** Scans the adaptive order file and insert (index, value) into map.
+ * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
+ * \return adaptive criteria list from file
+ */
+std::map<int, std::pair<double,int> > * AdaptivityMap::ScanAdaptiveFileIntoMap(std::string &path)
+{
+  std::map<int, pair<double,int> > *AdaptiveCriteriaList = new std::map<int, pair<double,int> >;
+  int No = 0, FragOrder = 0;
+  double Value = 0.;
+  char buffer[MAXSTRINGSIZE];
+  std::string filename = path + ENERGYPERFRAGMENT;
+  std::ifstream InputFile(filename.c_str());
+
+  if (InputFile.fail()) {
+    DoeLog(1) && (eLog() << Verbose(1) << "Cannot find file " << filename << "." << endl);
+    return AdaptiveCriteriaList;
+  }
+
+  if (CountLinesinFile(InputFile) > 0) {
+    // each line represents a fragment root (Atom::Nr) id and its energy contribution
+    InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
+    InputFile.getline(buffer, MAXSTRINGSIZE);
+    while(!InputFile.eof()) {
+      InputFile.getline(buffer, MAXSTRINGSIZE);
+      if (strlen(buffer) > 2) {
+        //Log() << Verbose(2) << "Scanning: " << buffer << endl;
+        stringstream line(buffer);
+        line >> FragOrder;
+        line >> ws >> No;
+        line >> ws >> Value; // skip time entry
+        line >> ws >> Value;
+        No -= 1;  // indices start at 1 in file, not 0
+        //Log() << Verbose(2) << " - yields (" << No << "," << Value << ", " << FragOrder << ")" << endl;
+
+        // clean the list of those entries that have been superceded by higher order terms already
+        InsertIntoAdaptiveCriteriaList(AdaptiveCriteriaList, FragOrder, No, Value);
+      }
+    }
+    // close and done
+    InputFile.close();
+    InputFile.clear();
+  }
+
+  return AdaptiveCriteriaList;
+};
+
+/** Maps adaptive criteria list back onto (Value, (Root Nr., Order))
+ * (i.e. sorted by value to pick the highest ones)
+ * \param *out output stream for debugging
+ * \param &AdaptiveCriteriaList list to insert into
+ * \param *mol molecule with atoms
+ * \return remapped list
+ */
+std::map<double, std::pair<int,int> >  * AdaptivityMap::ReMapAdaptiveCriteriaListToValue(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, molecule *mol)
+{
+  atom *Walker = NULL;
+  std::map<double, std::pair<int,int> > *FinalRootCandidates = new std::map<double, std::pair<int,int> > ;
+  DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);
+  for(std::map<int, std::pair<double,int> >::iterator runner = AdaptiveCriteriaList->begin(); runner != AdaptiveCriteriaList->end(); runner++) {
+    Walker = mol->FindAtom((*runner).first);
+    if (Walker != NULL) {
+      //if ((*runner).second.second >= Walker->AdaptiveOrder) { // only insert if this is an "active" root site for the current order
+      if (!Walker->MaxOrder) {
+        DoLog(2) && (Log() << Verbose(2) << "(" << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "])" << endl);
+        FinalRootCandidates->insert( make_pair( (*runner).second.first, pair<int,int>((*runner).first, (*runner).second.second) ) );
+      } else {
+        DoLog(2) && (Log() << Verbose(2) << "Excluding (" << *Walker << ", " << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "]), as it has reached its maximum order." << endl);
+      }
+    } else {
+      DoeLog(0) && (eLog()<< Verbose(0) << "Atom No. " << (*runner).second.first << " was not found in this molecule." << endl);
+      performCriticalExit();
+    }
+  }
+  return FinalRootCandidates;
+};
+
+/** Counts lines in file.
+ * Note we are scanning lines from current position, not from beginning.
+ * \param InputFile file to be scanned.
+ */
+int AdaptivityMap::CountLinesinFile(std::ifstream &InputFile) const
+{
+  char *buffer = new char[MAXSTRINGSIZE];
+  int lines=0;
+
+  int PositionMarker = InputFile.tellg();  // not needed as Inputfile is copied, given by value, not by ref
+  // count the number of lines, i.e. the number of fragments
+  InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
+  InputFile.getline(buffer, MAXSTRINGSIZE);
+  while(!InputFile.eof()) {
+    InputFile.getline(buffer, MAXSTRINGSIZE);
+    lines++;
+  }
+  InputFile.seekg(PositionMarker, ios::beg);
+  delete[](buffer);
+  return lines;
+};
Index: src/Fragmentation/AdaptivityMap.hpp
===================================================================
--- src/Fragmentation/AdaptivityMap.hpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
+++ src/Fragmentation/AdaptivityMap.hpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -0,0 +1,38 @@
+/*
+ * AdaptivityMap.hpp
+ *
+ *  Created on: Oct 20, 2011
+ *      Author: heber
+ */
+
+#ifndef ADAPTIVITYMAP_HPP_
+#define ADAPTIVITYMAP_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iosfwd>
+#include <string>
+
+#include <map>
+
+#include "Fragmentation/KeySet.hpp"
+
+class molecule;
+
+class AdaptivityMap : public std::map<int, KeySet>
+{
+public:
+  AdaptivityMap();
+  ~AdaptivityMap();
+
+  void InsertIntoAdaptiveCriteriaList(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, int FragOrder, int No, double Value) const;
+  std::map<int, std::pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path);
+  std::map<double, std::pair<int,int> >  * ReMapAdaptiveCriteriaListToValue(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, molecule *mol);
+  int CountLinesinFile(std::ifstream &InputFile) const;
+};
+
+
+#endif /* ADAPTIVITYMAP_HPP_ */
Index: src/Fragmentation/Fragmentation.cpp
===================================================================
--- src/Fragmentation/Fragmentation.cpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
+++ src/Fragmentation/Fragmentation.cpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -28,4 +28,5 @@
 #include "Element/element.hpp"
 #include "Element/periodentafel.hpp"
+#include "Fragmentation/AdaptivityMap.hpp"
 #include "Fragmentation/fragmentation_helpers.hpp"
 #include "Fragmentation/Graph.hpp"
@@ -464,8 +465,8 @@
       return false;
     }
-    map<int,KeySet> *IndexKeySetList = GlobalKeySetList->GraphToIndexedKeySet();
+    AdaptivityMap * IndexKeySetList = GlobalKeySetList->GraphToAdaptivityMap();
 
     // parse the EnergyPerFragment file
-    map<int, pair<double,int> > *AdaptiveCriteriaList = ScanAdaptiveFileIntoMap(path, *IndexKeySetList); // (Root No., (Value, Order)) !
+    std::map<int, std::pair<double,int> > *AdaptiveCriteriaList = IndexKeySetList->ScanAdaptiveFileIntoMap(path); // (Root No., (Value, Order)) !
     if (AdaptiveCriteriaList->empty()) {
       DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl);
@@ -481,5 +482,5 @@
     }
     // then map back onto (Value, (Root Nr., Order)) (i.e. sorted by value to pick the highest ones)
-    map<double, pair<int,int> > *FinalRootCandidates = ReMapAdaptiveCriteriaListToValue(AdaptiveCriteriaList, mol);
+    std::map<double, std::pair<int,int> > *FinalRootCandidates = IndexKeySetList->ReMapAdaptiveCriteriaListToValue(AdaptiveCriteriaList, mol);
 
     // pick the ones still below threshold and mark as to be adaptively updated
Index: src/Fragmentation/Graph.cpp
===================================================================
--- src/Fragmentation/Graph.cpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
+++ src/Fragmentation/Graph.cpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -29,4 +29,5 @@
 #include "CodePatterns/Log.hpp"
 
+#include "Fragmentation/AdaptivityMap.hpp"
 #include "Helpers/defs.hpp"
 #include "Helpers/helpers.hpp"
@@ -223,7 +224,7 @@
  * \return ref to allocated map from index to keyset
  */
-std::map<int,KeySet> * Graph::GraphToIndexedKeySet() const
-{
-  map<int,KeySet> *IndexKeySetList = new map<int,KeySet>;
+AdaptivityMap * Graph::GraphToAdaptivityMap() const
+{
+  AdaptivityMap *IndexKeySetList = new AdaptivityMap;
   for(const_iterator runner = begin(); runner != end(); runner++) {
     IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) );
Index: src/Fragmentation/Graph.hpp
===================================================================
--- src/Fragmentation/Graph.hpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
+++ src/Fragmentation/Graph.hpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -22,4 +22,6 @@
 typedef std::pair<KeySet, NumberValuePair> GraphPair;
 
+class AdaptivityMap;
+
 class Graph : public std::map <KeySet, NumberValuePair >
 {
@@ -35,5 +37,5 @@
   bool StoreTEFactorsFile(char *path);
 
-  std::map<int,KeySet> * GraphToIndexedKeySet() const;
+  AdaptivityMap * GraphToAdaptivityMap() const;
 };
 
Index: src/Fragmentation/Makefile.am
===================================================================
--- src/Fragmentation/Makefile.am	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
+++ src/Fragmentation/Makefile.am	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -3,4 +3,5 @@
 
 FRAGMENTATIONSOURCE = \
+	Fragmentation/AdaptivityMap.cpp \
 	Fragmentation/BondsPerShortestPath.cpp \
 	Fragmentation/EnergyMatrix.cpp \
@@ -18,4 +19,5 @@
 
 FRAGMENTATIONHEADER = \
+	Fragmentation/AdaptivityMap.hpp \
 	Fragmentation/BondsPerShortestPath.hpp \
 	Fragmentation/defs.hpp \
Index: src/Fragmentation/fragmentation_helpers.cpp
===================================================================
--- src/Fragmentation/fragmentation_helpers.cpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
+++ src/Fragmentation/fragmentation_helpers.cpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -29,4 +29,5 @@
 #include "Bond/bond.hpp"
 #include "Element/element.hpp"
+#include "Fragmentation/AdaptivityMap.hpp"
 #include "Fragmentation/Graph.hpp"
 #include "Fragmentation/KeySet.hpp"
@@ -37,138 +38,6 @@
 using namespace std;
 
-/** Inserts a (\a No, \a value) pair into the list, overwriting present one.
- * Note if values are equal, No will decided on which is first
- * \param *out output stream for debugging
- * \param &AdaptiveCriteriaList list to insert into
- * \param &IndexedKeySetList list to find key set for a given index \a No
- * \param FragOrder current bond order of fragment
- * \param No index of keyset
- * \param value energy value
- */
-void InsertIntoAdaptiveCriteriaList(std::map<int, pair<double,int> > *AdaptiveCriteriaList, std::map<int,KeySet> &IndexKeySetList, int FragOrder, int No, double Value)
-{
-  map<int,KeySet>::iterator marker = IndexKeySetList.find(No);    // find keyset to Frag No.
-  if (marker != IndexKeySetList.end()) {  // if found
-    Value *= 1 + MYEPSILON*(*((*marker).second.begin()));     // in case of equal energies this makes them not equal without changing anything actually
-    // as the smallest number in each set has always been the root (we use global id to keep the doubles away), seek smallest and insert into AtomMask
-    pair <map<int, pair<double,int> >::iterator, bool> InsertedElement = AdaptiveCriteriaList->insert( make_pair(*((*marker).second.begin()), pair<double,int>( fabs(Value), FragOrder) ));
-    map<int, pair<double,int> >::iterator PresentItem = InsertedElement.first;
-    if (!InsertedElement.second) { // this root is already present
-      if ((*PresentItem).second.second < FragOrder)  // if order there is lower, update entry with higher-order term
-        //if ((*PresentItem).second.first < (*runner).first)    // as higher-order terms are not always better, we skip this part (which would always include this site into adaptive increase)
-        {  // if value is smaller, update value and order
-        (*PresentItem).second.first = fabs(Value);
-        (*PresentItem).second.second = FragOrder;
-        DoLog(2) && (Log() << Verbose(2) << "Updated element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
-      } else {
-        DoLog(2) && (Log() << Verbose(2) << "Did not update element " <<  (*PresentItem).first << " as " << FragOrder << " is less than or equal to " << (*PresentItem).second.second << "." << endl);
-      }
-    } else {
-      DoLog(2) && (Log() << Verbose(2) << "Inserted element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
-    }
-  } else {
-    DoLog(1) && (Log() << Verbose(1) << "No Fragment under No. " << No << "found." << endl);
-  }
-};
-
-/** Counts lines in file.
- * Note we are scanning lines from current position, not from beginning.
- * \param InputFile file to be scanned.
- */
-int CountLinesinFile(std::ifstream &InputFile)
-{
-  char *buffer = new char[MAXSTRINGSIZE];
-  int lines=0;
-
-  int PositionMarker = InputFile.tellg();  // not needed as Inputfile is copied, given by value, not by ref
-  // count the number of lines, i.e. the number of fragments
-  InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
-  InputFile.getline(buffer, MAXSTRINGSIZE);
-  while(!InputFile.eof()) {
-    InputFile.getline(buffer, MAXSTRINGSIZE);
-    lines++;
-  }
-  InputFile.seekg(PositionMarker, ios::beg);
-  delete[](buffer);
-  return lines;
-};
 
 
-/** Scans the adaptive order file and insert (index, value) into map.
- * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
- * \param &IndexedKeySetList list to find key set for a given index \a No
- * \return adaptive criteria list from file
- */
-std::map<int, std::pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path, std::map<int,KeySet> &IndexKeySetList)
-{
-  map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >;
-  int No = 0, FragOrder = 0;
-  double Value = 0.;
-  char buffer[MAXSTRINGSIZE];
-  string filename = path + ENERGYPERFRAGMENT;
-  ifstream InputFile(filename.c_str());
-
-  if (InputFile.fail()) {
-    DoeLog(1) && (eLog() << Verbose(1) << "Cannot find file " << filename << "." << endl);
-    return AdaptiveCriteriaList;
-  }
-
-  if (CountLinesinFile(InputFile) > 0) {
-    // each line represents a fragment root (Atom::Nr) id and its energy contribution
-    InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
-    InputFile.getline(buffer, MAXSTRINGSIZE);
-    while(!InputFile.eof()) {
-      InputFile.getline(buffer, MAXSTRINGSIZE);
-      if (strlen(buffer) > 2) {
-        //Log() << Verbose(2) << "Scanning: " << buffer << endl;
-        stringstream line(buffer);
-        line >> FragOrder;
-        line >> ws >> No;
-        line >> ws >> Value; // skip time entry
-        line >> ws >> Value;
-        No -= 1;  // indices start at 1 in file, not 0
-        //Log() << Verbose(2) << " - yields (" << No << "," << Value << ", " << FragOrder << ")" << endl;
-
-        // clean the list of those entries that have been superceded by higher order terms already
-        InsertIntoAdaptiveCriteriaList(AdaptiveCriteriaList, IndexKeySetList, FragOrder, No, Value);
-      }
-    }
-    // close and done
-    InputFile.close();
-    InputFile.clear();
-  }
-
-  return AdaptiveCriteriaList;
-};
-
-/** Maps adaptive criteria list back onto (Value, (Root Nr., Order))
- * (i.e. sorted by value to pick the highest ones)
- * \param *out output stream for debugging
- * \param &AdaptiveCriteriaList list to insert into
- * \param *mol molecule with atoms
- * \return remapped list
- */
-std::map<double, std::pair<int,int> >  * ReMapAdaptiveCriteriaListToValue(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, molecule *mol)
-{
-  atom *Walker = NULL;
-  map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ;
-  DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);
-  for(map<int, pair<double,int> >::iterator runner = AdaptiveCriteriaList->begin(); runner != AdaptiveCriteriaList->end(); runner++) {
-    Walker = mol->FindAtom((*runner).first);
-    if (Walker != NULL) {
-      //if ((*runner).second.second >= Walker->AdaptiveOrder) { // only insert if this is an "active" root site for the current order
-      if (!Walker->MaxOrder) {
-        DoLog(2) && (Log() << Verbose(2) << "(" << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "])" << endl);
-        FinalRootCandidates->insert( make_pair( (*runner).second.first, pair<int,int>((*runner).first, (*runner).second.second) ) );
-      } else {
-        DoLog(2) && (Log() << Verbose(2) << "Excluding (" << *Walker << ", " << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "]), as it has reached its maximum order." << endl);
-      }
-    } else {
-      DoeLog(0) && (eLog()<< Verbose(0) << "Atom No. " << (*runner).second.first << " was not found in this molecule." << endl);
-      performCriticalExit();
-    }
-  }
-  return FinalRootCandidates;
-};
 
 /** Marks all candidate sites for update if below adaptive threshold.
Index: src/Fragmentation/fragmentation_helpers.hpp
===================================================================
--- src/Fragmentation/fragmentation_helpers.hpp	(revision 75363b3f88c851b63d6e61e7ac05f88177419a9c)
+++ src/Fragmentation/fragmentation_helpers.hpp	(revision 730d7a4efc3a2396723036e90420b93ff9ed3b03)
@@ -22,4 +22,5 @@
 typedef std::deque<int> KeyStack;
 
+class AdaptivityMap;
 class bond;
 class Graph;
@@ -27,8 +28,4 @@
 class molecule;
 
-void InsertIntoAdaptiveCriteriaList(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, std::map<int,KeySet> &IndexKeySetList, int FragOrder, int No, double Value);
-int CountLinesinFile(std::ifstream &InputFile);
-std::map<int, std::pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path, std::map<int,KeySet> &IndexKeySetList);
-std::map<double, std::pair<int,int> >  * ReMapAdaptiveCriteriaListToValue(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, molecule *mol);
 bool MarkUpdateCandidates(bool *AtomMask, std::map<double, std::pair<int,int> > &FinalRootCandidates, int Order, molecule *mol);
 void PrintAtomMask(bool *AtomMask, int AtomCount);
