Index: src/Actions/PotentialAction/FitPartialChargesAction.cpp
===================================================================
--- src/Actions/PotentialAction/FitPartialChargesAction.cpp	(revision 8eafd64de847c412cea243836c585caec4d84cbb)
+++ src/Actions/PotentialAction/FitPartialChargesAction.cpp	(revision f33ef915fce26ae43109c53c58932747bc589748)
@@ -395,9 +395,15 @@
 }
 
+bool isNotHydrogen(const atom * const _atom)
+{
+  return (_atom->getElementNo() != (atomicNumber_t) 1);
+}
+
 ActionState::ptr PotentialFitPartialChargesAction::performCall()
 {
   // check for selected atoms
   const World &world = const_cast<const World &>(World::getInstance());
-  if (world.beginAtomSelection() == world.endAtomSelection()) {
+  const std::vector<const atom *> selected_atoms = world.getSelectedAtoms();
+  if (selected_atoms.empty()) {
     STATUS("There are no atoms selected for fitting partial charges to.");
     return Action::failure;
@@ -407,9 +413,15 @@
   const AtomFragmentsMap &atomfragments = AtomFragmentsMap::getConstInstance();
   if (!atomfragments.checkCompleteness()) {
-    STATUS("AtomFragmentsMap failed internal consistency check, missing forcekeysets?");
+    ELOG(0, "AtomFragmentsMap failed internal consistency check, missing forcekeysets?");
     return Action::failure;
   }
-  std::set<KeySet> fragments =
-      accumulateKeySetsForAtoms( atomfragments.getMap(), world.getSelectedAtoms());
+  const std::set<KeySet> fragments =
+      accumulateKeySetsForAtoms( atomfragments.getMap(), selected_atoms);
+  const size_t NoNonHydrogens =
+      std::count_if(selected_atoms.begin(), selected_atoms.end(), isNotHydrogen);
+  if (fragments.size() < NoNonHydrogens) {
+    ELOG(0, "Obtained fewer fragments than there are atoms, has AtomFragments been loaded?");
+    return Action::failure;
+  }
 
   // reduce given fragments to homologous graphs to avoid multiple fittings
@@ -430,14 +442,15 @@
   /// obtain average charge for each atom the fitted charges over all its fragments
   detail::fitted_charges_t fitted_charges;
-  for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
-      atomiter != world.endAtomSelection(); ++atomiter) {
+  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
+      atomiter != selected_atoms.end(); ++atomiter) {
+    const atomId_t walkerid = (*atomiter)->getId();
     const double average_charge = fitAverageChargeToAtom(
-        atomiter->second, atomfragments, keyset_graphs, fittedcharges_per_fragment);
+        *atomiter, atomfragments, keyset_graphs, fittedcharges_per_fragment);
 
     if (average_charge != 0.) {
-      LOG(2, "DEBUG: For atom " << atomiter->first << " we have an average charge of "
+      LOG(2, "DEBUG: For atom " << *atomiter << " we have an average charge of "
           << average_charge);
 
-      fitted_charges.insert( std::make_pair(atomiter->first, average_charge) );
+      fitted_charges.insert( std::make_pair(walkerid, average_charge) );
     }
   }
@@ -455,15 +468,16 @@
   detail::GraphIndices_t GraphIndices;
   const AtomFragmentsMap::AtomFragmentsMap_t &atommap = atomfragments.getMap();
-  for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
-      atomiter != world.endAtomSelection(); ++atomiter) {
+  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
+      atomiter != selected_atoms.end(); ++atomiter) {
     // use the non-hydrogen here
-    const atomId_t walkerid = getNonHydrogenSurrogate(atomiter->second)->getId();
-    if (walkerid != atomiter->first)
+    const atomId_t walkerid = (*atomiter)->getId();
+    const atomId_t surrogateid = getNonHydrogenSurrogate(*atomiter)->getId();
+    if (surrogateid != walkerid)
       continue;
     const AtomFragmentsMap::AtomFragmentsMap_t::const_iterator keysetsiter =
-        atommap.find(atomiter->first);
+        atommap.find(walkerid);
     ASSERT(keysetsiter != atommap.end(),
         "PotentialFitPartialChargesAction::performCall() - we checked already that "
-        +toString(walkerid)+" should be present!");
+        +toString(surrogateid)+" should be present!");
     const AtomFragmentsMap::keysets_t & keysets = keysetsiter->second;
 
@@ -486,23 +500,24 @@
     }
 
-    GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, atomiter->first) );
-
-    LOG(2, "DEBUG: Atom #" << atomiter->first << "," << *atomiter->second
-        << ". has graph indices " << AtomsGraphIndices);
+    GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, walkerid) );
+
+    LOG(2, "DEBUG: Atom #" << walkerid << "," << *atomiter << ". has graph indices "
+        << AtomsGraphIndices);
   }
   // then graphs from non-hydrogen bond partner for all hydrogens
-  for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
-      atomiter != world.endAtomSelection(); ++atomiter) {
+  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
+      atomiter != selected_atoms.end(); ++atomiter) {
     // use the non-hydrogen here
-    const atomId_t walkerid = getNonHydrogenSurrogate(atomiter->second)->getId();
-    if (walkerid == atomiter->first)
+    const atomId_t walkerid = (*atomiter)->getId();
+    const atomId_t surrogateid = getNonHydrogenSurrogate((*atomiter))->getId();
+    if (surrogateid == walkerid)
       continue;
-    detail::GraphIndices_t::right_const_iterator graphiter = GraphIndices.right.find(walkerid);
+    detail::GraphIndices_t::right_const_iterator graphiter = GraphIndices.right.find(surrogateid);
     ASSERT( graphiter != GraphIndices.right.end(),
-        "PotentialFitPartialChargesAction::performCall() - atom #"+toString(walkerid)
+        "PotentialFitPartialChargesAction::performCall() - atom #"+toString(surrogateid)
         +" not contained in GraphIndices.");
     const detail::AtomsGraphIndices_t &AtomsGraphIndices = graphiter->second;
-    GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, atomiter->first) );
-    LOG(2, "DEBUG: Hydrogen #" << atomiter->first << ", " << *atomiter->second
+    GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, walkerid) );
+    LOG(2, "DEBUG: Hydrogen #" << walkerid << ", " << *atomiter
         << ", has graph indices " << AtomsGraphIndices);
   }
@@ -516,21 +531,25 @@
       GraphIndices,
       atom_particlenames);
-  for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
-      atomiter != world.endAtomSelection(); ++atomiter) {
-    const atom * const walker = atomiter->second;
+  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
+      atomiter != selected_atoms.end(); ++atomiter) {
+    const atom * const walker = *atomiter;
+    const atomId_t walkerid = walker->getId();
     const detail::GraphIndices_t::right_const_iterator graphiter =
-        GraphIndices.right.find(atomiter->first);
+        GraphIndices.right.find(walkerid);
     ASSERT( graphiter != GraphIndices.right.end(),
-        "PotentialFitPartialChargesAction::performCall() - ");
+        "PotentialFitPartialChargesAction::performCall() - cannot find "
+        +toString(walkerid)+" in GraphIndices.");
     const detail::AtomsGraphIndices_t &graphindex = graphiter->second;
     const detail::AtomParticleNames_t::const_iterator particlesetiter =
         atom_particlenames.find(graphindex);
     ASSERT( particlesetiter != atom_particlenames.end(),
-        "PotentialFitPartialChargesAction::performCall() - ");
+        "PotentialFitPartialChargesAction::performCall() - cannot find "
+        +toString(graphindex)+" in atom_particlenames.");
     const std::map<atomicNumber_t, std::string>::const_iterator nameiter =
         particlesetiter->second.find(walker->getElementNo());
     ASSERT( nameiter != particlesetiter->second.end(),
         "PotentialFitPartialChargesAction::performCall() - ");
-    LOG(1, "INFO: atom " << *walker << " received the following particle " << nameiter->second);
+    LOG(1, "INFO: atom " << *walker << " received the following particle "
+        << nameiter->second);
   }
 
