Index: src/Graph/CheckAgainstAdjacencyFile.cpp
===================================================================
--- src/Graph/CheckAgainstAdjacencyFile.cpp	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
+++ src/Graph/CheckAgainstAdjacencyFile.cpp	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
@@ -0,0 +1,126 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2010 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * CheckAgainstAdjacencyFile.cpp
+ *
+ *  Created on: Mar 3, 2011
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include <iostream>
+
+#include "CheckAgainstAdjacencyFile.hpp"
+
+#include "atom.hpp"
+#include "Bond/bond.hpp"
+#include "CodePatterns/Assert.hpp"
+
+CheckAgainstAdjacencyFile::CheckAgainstAdjacencyFile() :
+  CurrentBonds(new int[MAXBONDS]),
+  status(true),
+  NonMatchNumber(0)
+{
+  for(int i=0;i<MAXBONDS;i++)
+    CurrentBonds[i] = 0;
+}
+
+CheckAgainstAdjacencyFile::~CheckAgainstAdjacencyFile()
+{
+  delete[](CurrentBonds);
+}
+
+void CheckAgainstAdjacencyFile::CompareBonds(const atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, std::map<int, atom*> &ListOfAtoms)
+{
+  size_t j = 0;
+  int id = -1;
+
+  //Log() << Verbose(2) << "Walker is " << *Walker << ", bond partners: ";
+  const BondList& ListOfBonds = Walker->getListOfBonds();
+  if (CurrentBondsOfAtom == ListOfBonds.size()) {
+    for (BondList::const_iterator Runner = ListOfBonds.begin();
+        Runner != ListOfBonds.end();
+        ++Runner) {
+      id = (*Runner)->GetOtherAtom(Walker)->getNr();
+      j = 0;
+      for (; (j < CurrentBondsOfAtom) && (CurrentBonds[j++] != id);)
+        ; // check against all parsed bonds
+      if (CurrentBonds[j - 1] != id) { // no match ? Then mark in ListOfAtoms
+        ListOfAtoms[AtomNr] = NULL;
+        NonMatchNumber++;
+        status = false;
+        ELOG(2, id << " can not be found in list." << endl);
+      } else {
+        //Log() << Verbose(0) << "[" << id << "]\t";
+      }
+    }
+    //Log() << Verbose(0) << endl;
+  } else {
+    LOG(0, "STATUS: Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << ListOfBonds.size() << ".");
+    status = false;
+  }
+}
+;
+
+/** Checks contents of adjacency file against bond structure in structure molecule.
+ * \param File file to parser
+ * \param ListOfAtoms map from int (index in file) to atom
+ * \return true - structure is equal, false - not equivalence
+ */
+bool CheckAgainstAdjacencyFile::operator()(std::ifstream &File, std::map<int, atom*> ListOfAtoms)
+{
+  LOG(0, "STATUS: Looking at bond structure stored in adjacency file and comparing to present one ... ");
+  if (File.fail()) {
+    LOG(1, "STATUS: Adjacency file not found." << endl);
+    return false;
+  }
+
+  char buffer[MAXSTRINGSIZE];
+  int tmp;
+  // Parse the file line by line and count the bonds
+  while (!File.eof()) {
+    File.getline(buffer, MAXSTRINGSIZE);
+    stringstream line;
+    line.str(buffer);
+    int AtomNr = -1;
+    line >> AtomNr;
+    size_t CurrentBondsOfAtom = -1; // we count one too far due to line end
+    // parse into structure
+    if (AtomNr >= 0) {
+      ASSERT(ListOfAtoms.count(AtomNr),
+          "CheckAgainstAdjacencyFile::operator() - index "
+          +toString(AtomNr)+" not present in ListOfAtoms.");
+      const atom *Walker = ListOfAtoms[AtomNr];
+      while (line >> ws >> tmp) {
+        LOG(3, "INFO: Recognized bond partner " << tmp);
+        CurrentBonds[++CurrentBondsOfAtom] = tmp;
+        ASSERT(CurrentBondsOfAtom < MAXBONDS,
+            "molecule::CheckAdjacencyFileAgainstMolecule() - encountered more bonds than allowed: "
+            +toString(CurrentBondsOfAtom)+" >= "+toString(int(MAXBONDS))+"!");
+      }
+      // compare against present bonds
+      CompareBonds(Walker, CurrentBondsOfAtom, AtomNr, ListOfAtoms);
+    } else {
+      if (AtomNr != -1)
+        ELOG(2, AtomNr << " is negative.");
+    }
+  }
+
+  if (status) { // if equal we parse the KeySetFile
+    LOG(0, "STATUS: Equal.");
+  } else
+    LOG(0, "STATUS: Not equal by " << NonMatchNumber << " atoms.");
+  return status;
+}
+;
Index: src/Graph/CheckAgainstAdjacencyFile.hpp
===================================================================
--- src/Graph/CheckAgainstAdjacencyFile.hpp	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
+++ src/Graph/CheckAgainstAdjacencyFile.hpp	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
@@ -0,0 +1,39 @@
+/*
+ * CheckAgainstAdjacencyFile.hpp
+ *
+ *  Created on: Mar 3, 2011
+ *      Author: heber
+ */
+
+#ifndef CHECKAGAINSTADJACENCYFILE_HPP_
+#define CHECKAGAINSTADJACENCYFILE_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iosfwd>
+#include <map>
+
+class atom;
+
+class CheckAgainstAdjacencyFile
+{
+public:
+  CheckAgainstAdjacencyFile();
+  ~CheckAgainstAdjacencyFile();
+
+  bool operator()(std::ifstream &File, std::map<int, atom*> ListOfAtoms);
+
+private:
+  enum {MAXBONDS=8};
+
+  int *CurrentBonds;
+  bool status;
+  int NonMatchNumber;
+
+  void CompareBonds(const atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, std::map<int, atom*> &ListOfAtoms);
+};
+
+#endif /* CHECKAGAINSTADJACENCYFILE_HPP_ */
Index: src/Graph/Makefile.am
===================================================================
--- src/Graph/Makefile.am	(revision 2d4334de0df04fbf9bf9d9b86cdd57638d71e072)
+++ src/Graph/Makefile.am	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
@@ -10,4 +10,5 @@
 	BreadthFirstSearchAdd.cpp \
 	BuildInducedSubgraph.cpp \
+	CheckAgainstAdjacencyFile.cpp \
 	ConnectedSubgraph.cpp \
 	CyclicStructureAnalysis.cpp \
@@ -17,4 +18,5 @@
 	BreadthFirstSearchAdd.hpp \
 	BuildInducedSubgraph.hpp \
+	CheckAgainstAdjacencyFile.hpp \
 	ConnectedSubgraph.hpp \
 	CyclicStructureAnalysis.hpp \
Index: src/molecule.hpp
===================================================================
--- src/molecule.hpp	(revision 2d4334de0df04fbf9bf9d9b86cdd57638d71e072)
+++ src/molecule.hpp	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
@@ -216,5 +216,4 @@
   bool StoreBondsToFile(std::string filename, std::string path = "");
   bool StoreAdjacencyToFile(std::string filename, std::string path = "");
-  bool CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms);
   bool ParseOrderAtSiteFromFile(std::string &path);
   bool StoreOrderAtSiteFile(std::string &path);
Index: src/molecule_fragmentation.cpp
===================================================================
--- src/molecule_fragmentation.cpp	(revision 2d4334de0df04fbf9bf9d9b86cdd57638d71e072)
+++ src/molecule_fragmentation.cpp	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
@@ -30,4 +30,5 @@
 #include "element.hpp"
 #include "Graph/BondGraph.hpp"
+#include "Graph/CheckAgainstAdjacencyFile.hpp"
 #include "Graph/CyclicStructureAnalysis.hpp"
 #include "Graph/DepthFirstSearchAnalysis.hpp"
@@ -609,4 +610,5 @@
 };
 
+
 /** Performs a many-body bond order analysis for a given bond order.
  * -# parses adjacency, keysets and orderatsite files
@@ -640,5 +642,4 @@
   Graph TotalGraph;     // graph with all keysets however local numbers
   int TotalNumberOfKeySets = 0;
-  atom **ListOfAtoms = NULL;
   atom ***ListOfLocalAtoms = NULL;
   bool *AtomMask = NULL;
@@ -655,10 +656,23 @@
   // ===== 1. Check whether bond structure is same as stored in files ====
 
-  // create lookup table for Atom::Nr
-  FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount());
-
   // === compare it with adjacency file ===
-  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(prefix, ListOfAtoms);
-  delete[](ListOfAtoms);
+  {
+    std::ifstream File;
+    string filename;
+    filename = prefix + ADJACENCYFILE;
+    File.open(filename.c_str(), ios::out);
+    DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl);
+    std::map<int, atom*> ListOfAtoms;
+    std::pair<std::map<int, atom*>::iterator, bool> inserter;
+    for (const_iterator iter = begin();
+        iter != end();
+        ++iter) {
+      atom *Walker = *iter;
+      inserter = ListOfAtoms.insert( make_pair( Walker->GetTrueFather()->getNr(), Walker) );
+      FragmentationToDo = FragmentationToDo && inserter.second;
+    }
+    CheckAgainstAdjacencyFile FileChecker;
+    FragmentationToDo = FragmentationToDo && FileChecker(File, ListOfAtoms);
+  }
 
   // === reset bond degree and perform CorrectBondDegree ===
Index: src/molecule_graph.cpp
===================================================================
--- src/molecule_graph.cpp	(revision 2d4334de0df04fbf9bf9d9b86cdd57638d71e072)
+++ src/molecule_graph.cpp	(revision 13a95397b14b03aa8f1b4580623690439ed06e5a)
@@ -43,6 +43,4 @@
 #include "WorldTime.hpp"
 
-#define MAXBONDS 8
-
 
 /** Fills the bond structure of this chain list subgraphs that are derived from a complete \a *reference molecule.
@@ -198,118 +196,4 @@
 ;
 
-bool CheckAdjacencyFileAgainstMolecule_Init(std::string &path, ifstream &File, int *&CurrentBonds)
-{
-  string filename;
-  filename = path + ADJACENCYFILE;
-  File.open(filename.c_str(), ios::out);
-  DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl);
-  if (File.fail())
-    return false;
-
-  // allocate storage structure
-  CurrentBonds = new int[MAXBONDS]; // contains parsed bonds of current atom
-  for(int i=0;i<MAXBONDS;i++)
-    CurrentBonds[i] = 0;
-  return true;
-}
-;
-
-void CheckAdjacencyFileAgainstMolecule_Finalize(ifstream &File, int *&CurrentBonds)
-{
-  File.close();
-  File.clear();
-  delete[](CurrentBonds);
-}
-;
-
-void CheckAdjacencyFileAgainstMolecule_CompareBonds(bool &status, int &NonMatchNumber, atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, int *&CurrentBonds, atom **ListOfAtoms)
-{
-  size_t j = 0;
-  int id = -1;
-
-  //Log() << Verbose(2) << "Walker is " << *Walker << ", bond partners: ";
-  const BondList& ListOfBonds = Walker->getListOfBonds();
-  if (CurrentBondsOfAtom == ListOfBonds.size()) {
-    for (BondList::const_iterator Runner = ListOfBonds.begin();
-        Runner != ListOfBonds.end();
-        ++Runner) {
-      id = (*Runner)->GetOtherAtom(Walker)->getNr();
-      j = 0;
-      for (; (j < CurrentBondsOfAtom) && (CurrentBonds[j++] != id);)
-        ; // check against all parsed bonds
-      if (CurrentBonds[j - 1] != id) { // no match ? Then mark in ListOfAtoms
-        ListOfAtoms[AtomNr] = NULL;
-        NonMatchNumber++;
-        status = false;
-        DoeLog(2) && (eLog() << Verbose(2) << id << " can not be found in list." << endl);
-      } else {
-        //Log() << Verbose(0) << "[" << id << "]\t";
-      }
-    }
-    //Log() << Verbose(0) << endl;
-  } else {
-    DoLog(0) && (Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << ListOfBonds.size() << "." << endl);
-    status = false;
-  }
-}
-;
-
-/** Checks contents of adjacency file against bond structure in structure molecule.
- * \param *path path to file
- * \param **ListOfAtoms allocated (molecule::AtomCount) and filled lookup table for ids (Atom::Nr) to *Atom
- * \return true - structure is equal, false - not equivalence
- */
-bool molecule::CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms)
-{
-  ifstream File;
-  bool status = true;
-  atom *Walker = NULL;
-  int *CurrentBonds = NULL;
-  int NonMatchNumber = 0; // will number of atoms with differing bond structure
-  size_t CurrentBondsOfAtom = -1;
-  const int AtomCount = getAtomCount();
-
-  if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) {
-    DoLog(1) && (Log() << Verbose(1) << "Adjacency file not found." << endl);
-    return true;
-  }
-
-  char buffer[MAXSTRINGSIZE];
-  int tmp;
-  // Parse the file line by line and count the bonds
-  while (!File.eof()) {
-    File.getline(buffer, MAXSTRINGSIZE);
-    stringstream line;
-    line.str(buffer);
-    int AtomNr = -1;
-    line >> AtomNr;
-    CurrentBondsOfAtom = -1; // we count one too far due to line end
-    // parse into structure
-    if ((AtomNr >= 0) && (AtomNr < AtomCount)) {
-      Walker = ListOfAtoms[AtomNr];
-      while (line >> ws >> tmp) {
-        std::cout << "Recognized bond partner " << tmp << std::endl;
-        CurrentBonds[++CurrentBondsOfAtom] = tmp;
-        ASSERT(CurrentBondsOfAtom < MAXBONDS,
-            "molecule::CheckAdjacencyFileAgainstMolecule() - encountered more bonds than allowed: "
-            +toString(CurrentBondsOfAtom)+" >= "+toString(MAXBONDS)+"!");
-      }
-      // compare against present bonds
-      CheckAdjacencyFileAgainstMolecule_CompareBonds(status, NonMatchNumber, Walker, CurrentBondsOfAtom, AtomNr, CurrentBonds, ListOfAtoms);
-    } else {
-      if (AtomNr != -1)
-        DoeLog(2) && (eLog() << Verbose(2) << AtomNr << " is not valid in the range of ids [" << 0 << "," << AtomCount << ")." << endl);
-    }
-  }
-  CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds);
-
-  if (status) { // if equal we parse the KeySetFile
-    DoLog(1) && (Log() << Verbose(1) << "done: Equal." << endl);
-  } else
-    DoLog(1) && (Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl);
-  return status;
-}
-;
-
 /** Adds a bond as a copy to a given one
  * \param *left leftatom of new bond
