Index: molecuilder/src/defs.hpp
===================================================================
--- molecuilder/src/defs.hpp	(revision 461e93c3544e40161b6999a7d39ce445da6deff7)
+++ molecuilder/src/defs.hpp	(revision a3ff7b27b58f3cdb07fefe9019035a3e59d02342)
@@ -46,5 +46,6 @@
 #define TEFACTORSFILE "TE-Factors.dat"
 #define FORCESFILE "Forces-Factors.dat"
-#define ORDERATSITEFILE "OrderAtSite.dat" 
+#define ORDERATSITEFILE "OrderAtSite.dat"
+#define ENERGYPERFRAGMENT "EnergyPerFragment.dat"
 #define FRAGMENTPREFIX "BondFragment"
 #define STANDARDCONFIG "unknown.conf"
Index: molecuilder/src/moleculelist.cpp
===================================================================
--- molecuilder/src/moleculelist.cpp	(revision 461e93c3544e40161b6999a7d39ce445da6deff7)
+++ molecuilder/src/moleculelist.cpp	(revision a3ff7b27b58f3cdb07fefe9019035a3e59d02342)
@@ -408,11 +408,12 @@
  * \param *out output stream for debugging
  * \param *&RootStack stack to be filled
+ * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site
  * \param Order desired bond order for all sites 
  * \param &FragmentCounter counts through the fragments in this MoleculeLeafClass
  * \return true - stack is non-empty, fragmentation necessary, false - stack is empty, no more sites to update
  */
-bool MoleculeLeafClass::FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, int Order, int &FragmentCounter)
-{
-  atom *Walker = NULL;
+bool MoleculeLeafClass::FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int Order, int &FragmentCounter)
+{
+  atom *Walker = NULL, *Father = NULL;
 
   if (RootStack != NULL) {
@@ -426,12 +427,14 @@
         while (Walker->next != Leaf->end) { // go through all (non-hydrogen) atoms
           Walker = Walker->next;
+          Father = Walker->GetTrueFather();
+          if (AtomMask[Father->nr]) // apply mask
       #ifdef ADDHYDROGEN
-          if (Walker->type->Z != 1) // skip hydrogen
+            if (Walker->type->Z != 1) // skip hydrogen
       #endif
-            if (Walker->GetTrueFather()->AdaptiveOrder < Order) // only if Order is still greater
-              RootStack[FragmentCounter].push_front(Walker->nr);
+              if (Father->AdaptiveOrder < Order) // only if Order is still greater
+                RootStack[FragmentCounter].push_front(Walker->nr);
         }
         if (next != NULL)
-          next->FillRootStackForSubgraphs(out, RootStack, Order, ++FragmentCounter);
+          next->FillRootStackForSubgraphs(out, RootStack, AtomMask, Order, ++FragmentCounter);
       }  else {
         *out << Verbose(1) << "Rootstack[" << FragmentCounter  << "] is NULL." << endl;
Index: molecuilder/src/molecules.cpp
===================================================================
--- molecuilder/src/molecules.cpp	(revision 461e93c3544e40161b6999a7d39ce445da6deff7)
+++ molecuilder/src/molecules.cpp	(revision a3ff7b27b58f3cdb07fefe9019035a3e59d02342)
@@ -2017,5 +2017,5 @@
     *out << Verbose(1) << "done." << endl;
   } else {
-    *out << Verbose(1) << "failed to open file" << line << "." << endl;
+    *out << Verbose(1) << "failed to open " << line << "." << endl;
     status = false;
   }
@@ -2137,24 +2137,78 @@
 /** Checks whether the OrderAtSite is still bewloe \a Order at some site.
  * \param *out output stream for debugging
- * \param &FragmentationToDo return boolean
- * \param Order desired Order
+ * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively
+ * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase
+ * \param Order desired Order if positive, desired exponent in threshold criteria if negative (0 is single-step)
+ * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
  * \return true - needs further fragmentation, false - does not need fragmentation
  */
-bool molecule::CheckOrderAtSite(ofstream *out, int Order)
-{
-  atom *Walker = NULL;
+bool molecule::CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, char *path)
+{
+  atom *Walker = start;
   bool status = false;
-  
-  Walker = start;
-  while (Walker->next != end) {
-    Walker = Walker->next;
-#ifdef ADDHYDROGEN
-    if (Walker->type->Z != 1) // skip hydrogen
-#endif
-      if (Walker->AdaptiveOrder < Order)
-        status = true;
-  }
-  if (!status)
-    *out << Verbose(1) << "Order at every site is already equal or above desired order " << Order << "." << endl;
+  ifstream InputFile;
+  stringstream line;
+  
+  if (Order < 0) { // adaptive increase of BondOrder per site
+    for(int i=0;i<AtomCount;i++)
+      AtomMask[i] = false;
+    // parse the EnergyPerFragment file
+    line.str(path);
+    line << "/" << FRAGMENTPREFIX << ENERGYPERFRAGMENT;
+    InputFile.open(line.str().c_str(), ios::in);
+    if (InputFile != NULL) {
+      char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
+      int lines = 0;
+      // count the number of lines, i.e. the number of fragments
+      while(!InputFile.eof()) {
+        InputFile.getline(buffer, MAXSTRINGSIZE);
+        lines++;
+      }
+      InputFile.clear();
+      InputFile.seekg(ios::beg);
+      map<double, int> FragmentEnergies;
+      int No;
+      int Value;
+      // each line represents a fragment root (Atom::nr) id and its energy contribution
+      while(!InputFile.eof()) {
+        InputFile.getline(buffer, MAXSTRINGSIZE);
+        InputFile >> No;
+        InputFile >> Value;
+        FragmentEnergies.insert( make_pair(Value, No) );
+      }
+      for(map<double, int>::iterator runner = FragmentEnergies.lower_bound(pow(1.,Order)); runner != FragmentEnergies.begin(); runner++) {
+        // 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
+        AtomMask[(*runner).second] = true;
+      }
+      // close and done
+      InputFile.close();
+      InputFile.clear();
+      Free((void **)&buffer, "molecule::CheckOrderAtSite: *buffer");
+    } else {
+      cerr << "Unable to parse " << FRAGMENTPREFIX << ENERGYPERFRAGMENT << " file." << endl;
+      return false;
+    }
+    // pick a given number of highest values and set AtomMask
+  } else if (Order > 0) { // global increase of Bond Order
+    while (Walker->next != end) {
+      Walker = Walker->next;
+  #ifdef ADDHYDROGEN
+      if (Walker->type->Z != 1) // skip hydrogen
+  #endif
+      {
+        AtomMask[Walker->nr] = true;  // include all (non-hydrogen) atoms
+        if (Walker->AdaptiveOrder < Order)
+          status = true;
+      }
+    }
+    if (!status)
+      *out << Verbose(1) << "Order at every site is already equal or above desired order " << Order << "." << endl;
+  } else {  // single stepping, just check
+    if (AtomMask[AtomCount] != true)  // if true, we would've done a step already
+      for(int i=0;i<=AtomCount;i++)
+        AtomMask[i] = true;
+    else
+      status = false;
+  }
  
   return status;
@@ -2226,4 +2280,5 @@
   atom **ListOfAtoms = NULL;
   atom ***ListOfLocalAtoms = NULL;
+  bool *AtomMask = NULL; 
   
   *out << endl;
@@ -2266,10 +2321,13 @@
     // ===== 6a. assign each keyset to its respective subgraph ===== 
     Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), false);
-    delete(ParsedFragmentList);
 
     KeyStack *RootStack = new KeyStack[Subgraphs->next->Count()];
-    while (CheckOrderAtSite(out, Order)) {
+    AtomMask = new bool[AtomCount+1];
+    for (int i=0;i<AtomCount;i++) // need to set to false to recognize in single-stepping (one global step set them all to true)
+      AtomMask[i] = false;
+    while (CheckOrderAtSite(out, AtomMask, ParsedFragmentList, Order)) {
+      AtomMask[AtomCount] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
       // ===== 6b. fill RootStack for each subgraph (second adaptivity check) ===== 
-      Subgraphs->next->FillRootStackForSubgraphs(out, RootStack, Order, (FragmentCounter = 0));
+      Subgraphs->next->FillRootStackForSubgraphs(out, RootStack, AtomMask, Order, (FragmentCounter = 0));
 
       // ===== 7. fill the bond fragment list =====
@@ -2293,5 +2351,7 @@
     }
     delete[](RootStack);
-  }
+    delete[](AtomMask);
+  }
+  delete(ParsedFragmentList);
   
   // free the index lookup list
Index: molecuilder/src/molecules.hpp
===================================================================
--- molecuilder/src/molecules.hpp	(revision 461e93c3544e40161b6999a7d39ce445da6deff7)
+++ molecuilder/src/molecules.hpp	(revision a3ff7b27b58f3cdb07fefe9019035a3e59d02342)
@@ -37,6 +37,7 @@
 #define KeyStack deque<int>
 #define KeySet set<int>
-#define Graph map<KeySet, pair<int, double>, KeyCompare >
-#define GraphPair pair<KeySet, pair<int, double> >
+#define NumberValuePair pair<int, double>
+#define Graph map<KeySet, NumberValuePair, KeyCompare >
+#define GraphPair pair<KeySet, NumberValuePair >
 #define KeySetTestPair pair<KeySet::iterator, bool>
 #define GraphTestPair pair<Graph::iterator, bool>
@@ -340,5 +341,5 @@
   /// Fragment molecule by two different approaches:
   void FragmentMolecule(ofstream *out, int Order, config *configuration);
-  bool CheckOrderAtSite(ofstream *out, int Order);
+  bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, char *path = NULL);
   bool StoreAdjacencyToFile(ofstream *out, char *path);
   bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
@@ -412,5 +413,5 @@
   bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
   bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
-  bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, int Order, int &FragmentCounter);
+  bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int Order, int &FragmentCounter);
   bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
   bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, int &FragmentCounter, int GlobalAtomCount, bool &FreeList);
