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.
