Index: src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.cpp
===================================================================
--- src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.cpp	(revision 675cd611bd03a5b8b2837d1811ebb901240fc57e)
+++ src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.cpp	(revision 0588e9997198820786bc31f4c69ab48e55ac174a)
@@ -42,6 +42,8 @@
 
 #include <boost/foreach.hpp>
+#include <boost/lambda/lambda.hpp>
 #include <boost/mpl/remove.hpp>
 
+#include <algorithm>
 #include <fstream>
 #include <iostream>
@@ -100,4 +102,24 @@
 }
 
+/** Print cycle correction from received results.
+ *
+ * @param results summed up results container
+ */
+void printReceivedCycleResults(
+    const FragmentationShortRangeResults &results)
+{
+  typedef boost::mpl::remove<
+        boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type,
+      MPQCDataFused::energy_eigenhistogram>::type
+    MPQCDataEnergyVector_noeigenvalues_t;
+  const std::string energyresult =
+      writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
+          results.Result_Energy_fused, results.getMaxLevel());
+  LOG(2, "DEBUG: Energy table is \n" << energyresult);
+  std::string filename;
+  filename += FRAGMENTPREFIX + std::string("_CycleEnergy.dat");
+  writeToFile(filename, energyresult);
+}
+
 /** Print (short range) energy, forces, and timings from received results.
  *
@@ -324,7 +346,36 @@
 }
 
+// this it taken from
+// http://stackoverflow.com/questions/2291802/is-there-a-c-iterator-that-can-iterate-over-a-file-line-by-line
+namespace detail
+{
+  /** Extend the string class by a friend function.
+   *
+   */
+  class Line : public std::string
+  {
+    friend std::istream & operator>>(std::istream & is, Line & line)
+    {
+      return std::getline(is, line);
+    }
+  };
+}
+
+/** Parse the given stream line-by-line, passing each to \a dest.
+ *
+ * \param is stream to parse line-wise
+ * \param dest output iterator
+ */
+template<class OutIt>
+void read_lines(std::istream& is, OutIt dest)
+{
+    typedef std::istream_iterator<detail::Line> InIt;
+    std::copy(InIt(is), InIt(), dest);
+}
+
+
 ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performCall() {
 
-  // if file is given, parse from file into resultscontainer
+  /// if file is given, parse from file into ResultsContainer
   FragmentationResultContainer& container = FragmentationResultContainer::getInstance();
   if (!params.resultsfile.get().empty()) {
@@ -342,5 +393,5 @@
   }
 
-  // get data and keysets from ResultsContainer
+  /// get data and keysets from ResultsContainer
   const std::map<JobId_t, MPQCData> &shortrangedata = container.getShortRangeResults();
   const KeySetsContainer &keysets = container.getKeySets();
@@ -354,8 +405,115 @@
   }
 
+  /// calculate normal contributions with (if present) cycles coming at their
+  /// respective bond order.
   std::vector<bool> ValueMask(shortrangedata.size(), true);
   FragmentationShortRangeResults shortrangeresults(shortrangedata, keysets, forcekeysets, ValueMask);
   shortrangeresults(shortrangedata);
   printReceivedShortResults(shortrangeresults);
+
+  /// now do we need to calculate the cycle contribution
+  // check whether there are cycles in container or else in file
+  KeySetsContainer cycles = container.getCycles();
+  if (cycles.KeySets.empty()) {
+    // parse from file if cycles is empty
+    boost::filesystem::path filename(
+        params.prefix.get() + std::string(CYCLEKEYSETFILE));
+    if (boost::filesystem::exists(filename)) {
+      LOG(1, "INFO: Parsing cycles file " << filename.string() << ".");
+      // parse file line by line
+      std::ifstream File;
+      File.open(filename.string().c_str());
+      typedef std::istream_iterator<detail::Line> InIt;
+      for (InIt iter = InIt(File); iter != InIt(); ++iter) {
+        KeySetsContainer::IntVector cycle;
+        std::stringstream line(*iter);
+        while (line.good()) {
+          int id;
+          line >> id >> ws;
+          cycle.push_back(id);
+        }
+        if (!cycle.empty()) {
+          LOG(2, "DEBUG: Adding cycle " << cycle << ".");
+          cycles.insert( cycle, cycle.size());
+        }
+      }
+      File.close();
+    } else {
+      LOG(1, "INFO: Cycles file not found at " << filename.string() << ".");
+    }
+  }
+
+  // copy the shortrangeresults such that private MaxLevel is set in
+  // FragmentationShortRangeResults
+  FragmentationShortRangeResults cycleresults(shortrangeresults);
+  // calculate energy if cycles are calculated fully at each level already
+  if (!cycles.KeySets.empty()) {
+    // gather cycle sizes
+    std::vector<size_t> cyclesizes(cycles.KeySets.size());
+    std::transform(
+        cycles.KeySets.begin(), cycles.KeySets.end(),
+        cyclesizes.begin(),
+        boost::bind(&KeySetsContainer::IntVector::size, boost::lambda::_1)
+    );
+    // get maximum
+    std::vector<size_t>::const_iterator maximum_size =
+        std::max_element(cyclesizes.begin(), cyclesizes.end());
+
+    // loop from level 1 to max ring size and gather corrections
+    for (size_t level = 1; level <= *maximum_size; ++level) {
+      // create ValueMask for this level by stepping through each keyset and checking size
+      std::vector<bool> localValueMask(shortrangedata.size(), false);
+      size_t index=0;
+      KeySetsContainer::ArrayOfIntVectors::const_iterator keysetsiter = keysets.KeySets.begin();
+      KeySetsContainer::ArrayOfIntVectors::const_iterator cyclesiter = cycles.KeySets.begin();
+      for (; (keysetsiter != keysets.KeySets.end()) && (cyclesiter != cycles.KeySets.end());) {
+        if (cyclesiter->size() > keysetsiter->size()) {
+          // add if not greater than level in size
+          if ((*keysetsiter).size() <= level)
+            localValueMask[index] = true;
+          ++keysetsiter;
+          ++index;
+        } else if (cyclesiter->size() < keysetsiter->size()) {
+          ++cyclesiter;
+        } else { // both sets have same size
+          if (*cyclesiter > *keysetsiter) {
+            // add if not greater than level in size
+            if ((*keysetsiter).size() <= level)
+              localValueMask[index] = true;
+            ++keysetsiter;
+            ++index;
+          } else if (*cyclesiter < *keysetsiter) {
+            ++cyclesiter;
+          } else {
+            // also always add all cycles
+            localValueMask[index] = true;
+            ++cyclesiter;
+            ++keysetsiter;
+            ++index;
+          }
+        }
+      }
+      // activate rest if desired by level
+      for (; keysetsiter != keysets.KeySets.end(); ++keysetsiter) {
+        if ((*keysetsiter).size() <= level)
+          localValueMask[index] = true;
+        ++index;
+      }
+      LOG(2, "DEBUG: ValueMask for cycle correction at level " << level << " is "
+          << localValueMask << ".");
+      // create FragmentationShortRangeResults
+      FragmentationShortRangeResults localresults(shortrangedata, keysets, forcekeysets, localValueMask);
+      // and perform summation
+      localresults(shortrangedata);
+      // finally, extract the corrections
+      cycleresults.Result_Energy_fused[level-1] =
+          localresults.Result_Energy_fused.back();
+      cycleresults.Result_Time_fused[level-1] =
+          localresults.Result_Time_fused.back();
+      cycleresults.Result_Force_fused[level-1] =
+          localresults.Result_Force_fused.back();
+    }
+    printReceivedCycleResults(cycleresults);
+  }
 
   // adding obtained forces
Index: src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.def
===================================================================
--- src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.def	(revision 675cd611bd03a5b8b2837d1811ebb901240fc57e)
+++ src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.def	(revision 0588e9997198820786bc31f4c69ab48e55ac174a)
@@ -8,4 +8,5 @@
 // all includes and forward declarations necessary for non-integral types below
 #include <boost/filesystem/path.hpp>
+#include <string>
 
 #include "Parameters/Validators/DummyValidator.hpp"
@@ -14,12 +15,13 @@
 // ValueStorage by the token "Z" -> first column: int, Z, "Z"
 // "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
-#define paramtypes (boost::filesystem::path)(bool)
-#define paramtokens ("fragment-resultfile")("store-grids")
-#define paramdescriptions ("parse fragment results from the given file")("whether to store sampled grids in homology files")
-#define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT("0"))
-#define paramreferences (resultsfile)(DoStoreGrids)
+#define paramtypes (boost::filesystem::path)(bool)(std::string)
+#define paramtokens ("fragment-resultfile")("store-grids")("fragment-prefix")
+#define paramdescriptions ("parse fragment results from the given file")("whether to store sampled grids in homology files")("prefix of each fragment file")
+#define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT("0"))(NOPARAM_DEFAULT)
+#define paramreferences (resultsfile)(DoStoreGrids)(prefix)
 #define paramvalids \
 (DummyValidator< boost::filesystem::path >()) \
-(DummyValidator< bool >())
+(DummyValidator< bool >()) \
+(DummyValidator< std::string >())
 
 #undef statetypes
Index: tests/Python/AllActions/options.dat
===================================================================
--- tests/Python/AllActions/options.dat	(revision 675cd611bd03a5b8b2837d1811ebb901240fc57e)
+++ tests/Python/AllActions/options.dat	(revision 0588e9997198820786bc31f4c69ab48e55ac174a)
@@ -82,4 +82,5 @@
 fragment-molecule	"./"
 fragment-path	"test/"
+fragment-prefix	"BondFragment"
 fragment-resultfile	"results.dat"
 grid-level	"5"
Index: tests/regression/Fragmentation/FragmentMolecule/pre/benzene.pdb
===================================================================
--- tests/regression/Fragmentation/FragmentMolecule/pre/benzene.pdb	(revision 0588e9997198820786bc31f4c69ab48e55ac174a)
+++ tests/regression/Fragmentation/FragmentMolecule/pre/benzene.pdb	(revision 0588e9997198820786bc31f4c69ab48e55ac174a)
@@ -0,0 +1,26 @@
+REMARK created by molecuilder on Fri Sep 27 20:25:54 2013, time step 0
+ATOM      1 H01 0non 01         -1.627   0.000  -0.001  0.00  0.00           H 0
+ATOM      2 C01 0non 01         -0.547   0.000  -0.002  0.00  0.00           C 0
+ATOM      3 C02 0non 01          0.154   1.207   0.001  0.00  0.00           C 0
+ATOM      4 C03 0non 01          0.154  -1.208   0.001  0.00  0.00           C 0
+ATOM      5 C04 0non 01          1.534   1.200   0.001  0.00  0.00           C 0
+ATOM      6 C05 0non 01          1.534  -1.200   0.001  0.00  0.00           C 0
+ATOM      7 C06 0non 01          2.222   0.000  -0.002  0.00  0.00           C 0
+ATOM      8 H02 0non 01         -0.382   2.145   0.003  0.00  0.00           H 0
+ATOM      9 H03 0non 01         -0.382  -2.145   0.004  0.00  0.00           H 0
+ATOM     10 H04 0non 01          2.078   2.133   0.002  0.00  0.00           H 0
+ATOM     11 H05 0non 01          2.077  -2.133   0.003  0.00  0.00           H 0
+ATOM     12 H06 0non 01          3.302   0.000  -0.003  0.00  0.00           H 0
+CONECT    1    2                                                                
+CONECT    2    1    3    4                                                      
+CONECT    3    2    5    8                                                      
+CONECT    4    2    6    9                                                      
+CONECT    5    3    7   10                                                      
+CONECT    6    4    7   11                                                      
+CONECT    7    5    6   12                                                      
+CONECT    8    3                                                                
+CONECT    9    4                                                                
+CONECT   10    5                                                                
+CONECT   11    6                                                                
+CONECT   12    7                                                                
+END
Index: tests/regression/Fragmentation/FragmentMolecule/testsuite-fragmentation-fragment-molecule.at
===================================================================
--- tests/regression/Fragmentation/FragmentMolecule/testsuite-fragmentation-fragment-molecule.at	(revision 675cd611bd03a5b8b2837d1811ebb901240fc57e)
+++ tests/regression/Fragmentation/FragmentMolecule/testsuite-fragmentation-fragment-molecule.at	(revision 0588e9997198820786bc31f4c69ab48e55ac174a)
@@ -34,2 +34,18 @@
 
 AT_CLEANUP
+
+AT_SETUP([Fragmentation - Fragmentation with cycles])
+AT_KEYWORDS([fragmentation fragment-molecule cycle])
+
+file=benzene.pdb
+AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Fragmentation/FragmentMolecule/pre/$file $file], 0)
+AT_CHECK([chmod u+w $file], 0, [ignore], [ignore])
+AT_CHECK([../../molecuilder -i $file --update-molecules --select-all-atoms --fragment-molecule ./BondFragment --DoCyclesFull 1 --distance 2 --order 2 --output-types "xyz"], 0, [ignore], [ignore])
+AT_CHECK([ls -l BondFragment??.xyz | wc -l], 0, [13
+], [ignore])
+AT_CHECK([cat <BondFragment12.xyz | wc -l], 0, [14
+], [ignore])
+AT_CHECK([cat <BondFragmentCycles.dat | wc -w], 0, [6
+], [ignore])
+
+AT_CLEANUP
