Index: src/Actions/FragmentationAction/FragmentationAutomationAction.cpp
===================================================================
--- src/Actions/FragmentationAction/FragmentationAutomationAction.cpp	(revision 0398bd3f86573bb724b71c8e05ebaeadda50c7c7)
+++ src/Actions/FragmentationAction/FragmentationAutomationAction.cpp	(revision 995e2f630769a5f3b1bfaa3010c8e6eb0e1f0a9e)
@@ -198,10 +198,10 @@
 /** Creates a lookup from FragmentJob::id to the true fragment  number.
  *
- * @param results result with job ids
+ * @param jobids vector with job ids
  * @param MatrixNrLookup Lookup up-map, filled on return
  * @param FragmentCounter total number of fragments on return
  */
 void createMatrixNrLookup(
-    const std::vector<FragmentResult::ptr> &results,
+    const std::vector<JobId_t> &jobids,
     std::map< JobId_t, size_t > &MatrixNrLookup,
     size_t &FragmentCounter)
@@ -210,22 +210,13 @@
   MatrixNrLookup.clear();
   FragmentCounter = 0;
-  {
-    // bring ids in order ...
-    typedef std::map< JobId_t, FragmentResult::ptr> IdResultMap_t;
-    IdResultMap_t IdResultMap;
-    for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
-        iter != results.end(); ++iter) {
-  #ifndef NDEBUG
-      std::pair< IdResultMap_t::iterator, bool> inserter =
-  #endif
-      IdResultMap.insert( make_pair((*iter)->getId(), *iter) );
-      ASSERT( inserter.second,
-          "ExtractMPQCDataFromResults() - two results have same id "
-          +toString((*iter)->getId())+".");
-    }
-    // ... and fill lookup
-    for(IdResultMap_t::const_iterator iter = IdResultMap.begin();
-        iter != IdResultMap.end(); ++iter)
-      MatrixNrLookup.insert( make_pair(iter->first, FragmentCounter++) );
+  for (std::vector<JobId_t>::const_iterator iter = jobids.begin();
+      iter != jobids.end(); ++iter) {
+#ifndef NDEBUG
+    std::pair< std::map< JobId_t, size_t >::iterator, bool> inserter =
+#endif
+        MatrixNrLookup.insert( std::make_pair(*iter, FragmentCounter++) );
+    ASSERT( inserter.second,
+        "createMatrixNrLookup() - two results have same id "
+        +toString(*iter)+".");
   }
   LOG(1, "INFO: There are " << FragmentCounter << " fragments.");
@@ -234,5 +225,5 @@
 /** Place results from FragmentResult into EnergyMatrix and ForceMatrix.
  *
- * @param results results with ids to associate with fragment number
+ * @param jobids jobids with ids to associate with fragment number
  * @param fragmentData MPQCData resulting from the jobs
  * @param MatrixNrLookup Lookup up-map from job id to fragment number
@@ -244,5 +235,5 @@
  */
 bool putResultsintoMatrices(
-    const std::vector<FragmentResult::ptr> &results,
+    const std::vector<JobId_t> &jobids,
     const std::vector<MPQCData> &fragmentData,
     std::map< JobId_t, size_t > &MatrixNrLookup,
@@ -252,9 +243,9 @@
     ForceMatrix &Force)
 {
-  ASSERT( results.size() == fragmentData.size(),
-      "printReceivedMPQCResults() - results and fragmentData differ in size.");
+  ASSERT( jobids.size() == fragmentData.size(),
+      "putResultsintoMatrices() - jobids and fragmentData differ in size.");
   std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
-  std::vector<FragmentResult::ptr>::const_iterator resultiter = results.begin();
-  for (; dataiter != fragmentData.end(); ++dataiter, ++resultiter) {
+  std::vector<JobId_t>::const_iterator iditer = jobids.begin();
+  for (; dataiter != fragmentData.end(); ++dataiter, ++iditer) {
     const MPQCData &extractedData = *dataiter;
     // place results into EnergyMatrix ...
@@ -264,7 +255,7 @@
       matrix[0].resize(1, extractedData.energies.total);
       if (!Energy.AddMatrix(
-          std::string("MPQCJob ")+toString((*resultiter)->getId()),
+          std::string("MPQCJob ")+toString(*iditer),
           matrix,
-          MatrixNrLookup[(*resultiter)->getId()])) {
+          MatrixNrLookup[*iditer])) {
         ELOG(1, "Adding energy matrix failed.");
         return false;
@@ -285,7 +276,7 @@
       }
       if (!Force.AddMatrix(
-          std::string("MPQCJob ")+toString((*resultiter)->getId()),
+          std::string("MPQCJob ")+toString(*iditer),
           matrix,
-          MatrixNrLookup[(*resultiter)->getId()])) {
+          MatrixNrLookup[*iditer])) {
         ELOG(1, "Adding force matrix failed.");
         return false;
@@ -310,5 +301,5 @@
 /** Print MPQCData from received results.
  *
- * @param results results with ids to associate with fragment number
+ * @param jobids jobids with ids to associate with fragment number
  * @param fragmentData MPQCData resulting from the jobs
  * @param KeySetFilename filename with keysets to associate forces correctly
@@ -318,5 +309,5 @@
  */
 bool sumUpChargeDensity(
-    const std::vector<FragmentResult::ptr> &results,
+    const std::vector<JobId_t> &jobids,
     const std::vector<MPQCData> &fragmentData,
     const std::string &KeySetFilename,
@@ -327,5 +318,5 @@
   std::map< JobId_t, size_t > MatrixNrLookup;
   size_t FragmentCounter = 0;
-  createMatrixNrLookup(results, MatrixNrLookup, FragmentCounter);
+  createMatrixNrLookup(jobids, MatrixNrLookup, FragmentCounter);
 
   // initialise keysets
@@ -344,10 +335,4 @@
   // create the map of all keysets
   SubsetMap::ptr subsetmap(new SubsetMap(*container));
-
-  // create a vector of all job ids
-  std::vector<JobId_t> jobids(results.size(), JobId::IllegalJob);
-  std::transform(results.begin(), results.end(), jobids.begin(),
-      boost::bind(&FragmentResult::getId,
-          boost::bind(&FragmentResult::ptr::operator->, _1)));
 
   /// convert all MPQCData to MPQCDataMap_t
@@ -374,5 +359,5 @@
  */
 bool printReceivedMPQCResults(
-    const std::vector<FragmentResult::ptr> &results,
+    const std::vector<JobId_t> &jobids,
     const std::vector<MPQCData> &fragmentData,
     const std::string &KeySetFilename,
@@ -383,10 +368,10 @@
   std::map< JobId_t, size_t > MatrixNrLookup;
   size_t FragmentCounter = 0;
-  createMatrixNrLookup(results, MatrixNrLookup, FragmentCounter);
+  createMatrixNrLookup(jobids, MatrixNrLookup, FragmentCounter);
 
   // place results into maps
   EnergyMatrix Energy;
   ForceMatrix Force;
-  if (!putResultsintoMatrices(results, fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
+  if (!putResultsintoMatrices(jobids, fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
     return false;
 
@@ -418,10 +403,4 @@
   // create the map of all keysets
   SubsetMap::ptr subsetmap(new SubsetMap(*container));
-
-  // create a vector of all job ids
-  std::vector<JobId_t> jobids(results.size(), JobId::IllegalJob);
-  std::transform(results.begin(), results.end(), jobids.begin(),
-      boost::bind(&FragmentResult::getId,
-          boost::bind(&FragmentResult::ptr::operator->, _1)));
 
   /// convert all MPQCData to MPQCDataMap_t
@@ -536,33 +515,4 @@
     SamplingGrid &full_sample)
 {
-  // create lookup from job nr to fragment number
-  std::map< JobId_t, size_t > MatrixNrLookup;
-  size_t FragmentCounter = 0;
-  createMatrixNrLookup(fragmentresults, MatrixNrLookup, FragmentCounter);
-
-  // initialise keysets
-  KeySetsContainer KeySet;
-  KeySetsContainer ForceKeySet;
-  {
-    // else needs keysets without hydrogens
-    std::stringstream filename;
-    filename << FRAGMENTPREFIX << KEYSETFILE;
-    if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
-  }
-
-  {
-    // forces need keysets including hydrogens
-    std::stringstream filename;
-    filename << FRAGMENTPREFIX << FORCESFILE;
-    if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
-  }
-
-  /// prepare for OrthogonalSummation
-
-  // convert KeySetContainer to IndexSetContainer
-  IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
-  // create the map of all keysets
-  SubsetMap::ptr subsetmap(new SubsetMap(*container));
-
   // create a vector of all job ids from short-range
   std::vector<JobId_t> jobids(fragmentresults.size(), JobId::IllegalJob);
@@ -570,4 +520,33 @@
       boost::bind(&FragmentResult::getId,
           boost::bind(&FragmentResult::ptr::operator->, _1)));
+
+  // create lookup from job nr to fragment number
+  std::map< JobId_t, size_t > MatrixNrLookup;
+  size_t FragmentCounter = 0;
+  createMatrixNrLookup(jobids, MatrixNrLookup, FragmentCounter);
+
+  // initialise keysets
+  KeySetsContainer KeySet;
+  KeySetsContainer ForceKeySet;
+  {
+    // else needs keysets without hydrogens
+    std::stringstream filename;
+    filename << FRAGMENTPREFIX << KEYSETFILE;
+    if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
+  }
+
+  {
+    // forces need keysets including hydrogens
+    std::stringstream filename;
+    filename << FRAGMENTPREFIX << FORCESFILE;
+    if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
+  }
+
+  /// prepare for OrthogonalSummation
+
+  // convert KeySetContainer to IndexSetContainer
+  IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
+  // create the map of all keysets
+  SubsetMap::ptr subsetmap(new SubsetMap(*container));
 
   /// convert all MPQCData to MPQCDataMap_t
@@ -805,4 +784,10 @@
       "FragmentationFragmentationAutomationAction::performCall() - please load the full molecule into the World before.");
 
+  // create a vector of all job ids
+  std::vector<JobId_t> jobids(MPQCresults.size(), JobId::IllegalJob);
+  std::transform(MPQCresults.begin(), MPQCresults.end(), jobids.begin(),
+      boost::bind(&FragmentResult::getId,
+          boost::bind(&FragmentResult::ptr::operator->, _1)));
+
   // obtain combined charge density
   LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
@@ -810,5 +795,5 @@
   Fragment full_fragment;
   sumUpChargeDensity(
-      MPQCresults,
+      jobids,
       fragmentData,
       params.path.get(),
@@ -858,5 +843,5 @@
     LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
     printReceivedMPQCResults(
-        MPQCresults,
+        jobids,
         fragmentData,
         params.path.get(),
