Index: src/Actions/FragmentationAction/FragmentationAction.cpp
===================================================================
--- src/Actions/FragmentationAction/FragmentationAction.cpp	(revision 94d5ac60852caf3933c959f8314ca0be3d3a7c51)
+++ src/Actions/FragmentationAction/FragmentationAction.cpp	(revision 3501d220b42c41a509f1636a333c1770e161d572)
@@ -44,5 +44,7 @@
 
 #include <iostream>
+#include <map>
 #include <string>
+#include <vector>
 
 #include "Actions/FragmentationAction/FragmentationAction.hpp"
@@ -56,7 +58,8 @@
 Action::state_ptr FragmentationFragmentationAction::performCall() {
   clock_t start,end;
-  molecule *mol = NULL;
-  int ExitFlag = 0;
+  int ExitFlag = -1;
+  World &world = World::getInstance();
 
+  // inform about used parameters
   LOG(0, "STATUS: Fragmenting molecular system with current connection matrix maximum bond distance "
       << params.distance.get() << " up to "
@@ -65,19 +68,55 @@
       << params.types.get() << "." << std::endl);
 
+  // check for selected atoms
+  if (world.beginAtomSelection() == world.endAtomSelection()) {
+    ELOG(1, "There are not atoms selected for fragmentation.");
+    return Action::failure;
+  }
+
+  // go through all atoms, note down their molecules and group them
+  typedef std::multimap<molecule *, atom *> clusters_t;
+  clusters_t clusters;
+  for (World::AtomSelectionConstIterator iter = world.beginAtomSelection();
+      iter != world.endAtomSelection(); ++iter) {
+    clusters.insert( std::make_pair(iter->second->getMolecule(), iter->second) );
+  }
+  LOG(1, "INFO: There are " << clusters.size()  << " molecules to consider.");
+
   DepthFirstSearchAnalysis DFS;
-  for (World::MoleculeSelectionConstIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
-    mol = iter->second;
-    ASSERT(mol != NULL, "No molecule has been picked for fragmentation.");
-    LOG(2, "INFO: Fragmenting molecule with bond distance " << params.distance.get() << " angstroem, order of " << params.order.get() << ".");
-    start = clock();
-    if (mol->hasBondStructure()) {
-      Fragmentation Fragmenter(mol, params.DoSaturation.get() ? DoSaturate : DontSaturate);
-      Fragmenter.setOutputTypes(params.types.get());
-      ExitFlag = Fragmenter.FragmentMolecule(params.order.get(), params.prefix.get(), DFS);
+  start = clock();
+  // go through all keys (i.e. all molecules)
+  clusters_t::const_iterator advanceiter;
+  for (clusters_t::const_iterator iter = clusters.begin();
+      iter != clusters.end();
+      iter = advanceiter) {
+    // get iterator to past last atom in this molecule
+    molecule * mol = iter->first;
+    advanceiter = clusters.upper_bound(mol);
+
+    // copy molecule's atoms' ids as parameters to Fragmentation's AtomMask
+    std::vector<atomId_t> mols_atomids;
+    std::transform(iter, advanceiter, std::back_inserter(mols_atomids),
+        boost::bind( &atom::getNr,
+            boost::bind( &clusters_t::value_type::second, _1 ))
+    );
+    LOG(2, "INFO: Fragmenting in molecule " << mol->getName() << " in " << clusters.count(mol) 
+        << " atoms, out of " << mol->getAtomCount() << ".");
+    Fragmentation Fragmenter(mol, params.DoSaturation.get() ? DoSaturate : DontSaturate);
+    Fragmenter.setOutputTypes(params.types.get());
+
+    // perform fragmentation
+    LOG(0, std::endl << " ========== Fragmentation of molecule " << mol->getName() << " ========================= ");
+    {
+      const int tempFlag = Fragmenter.FragmentMolecule(mols_atomids, params.order.get(), params.prefix.get(), DFS);
+      if ((ExitFlag == 2) && (tempFlag != 2))
+        ExitFlag = tempFlag; // if there is one molecule that needs further fragmentation, it overrides others
+      if (ExitFlag == -1)
+        ExitFlag = tempFlag; // if we are the first, we set the standard
     }
-    World::getInstance().setExitFlag(ExitFlag);
-    end = clock();
-    LOG(0, "STATUS: Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s.");
   }
+  World::getInstance().setExitFlag(ExitFlag);
+  end = clock();
+  LOG(0, "STATUS: Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s.");
+
   return Action::success;
 }
