Index: src/AtomIdSet.cpp
===================================================================
--- src/AtomIdSet.cpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
+++ src/AtomIdSet.cpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
@@ -0,0 +1,202 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * AtomIdSet.cpp
+ *
+ *  Created on: Feb 21, 2012
+ *      Author: heber
+ */
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "AtomIdSet.hpp"
+
+#include <boost/foreach.hpp>
+
+#include "Atom/atom.hpp"
+#include "Descriptors/AtomIdDescriptor.hpp"
+#include "World.hpp"
+
+atom * FromIdToAtom::operator()(atomId_t id) const {
+  return World::getInstance().getAtom(AtomById(id));
+}
+
+/** Constructor for class AtomIdSet.
+ *
+ * @param _atoms atoms to put into this set
+ */
+AtomIdSet::AtomIdSet(const atomIdSet &_atoms) :
+    atoms(_atoms)
+{}
+
+/** Constructor for class AtomIdSet.
+ *
+ * @param _atoms atoms to put into this set
+ */
+AtomIdSet::AtomIdSet(const std::vector<atom *> &_atoms)
+{
+  BOOST_FOREACH(const atom * _atom, _atoms) {
+    insert(_atom->getId());
+  }
+}
+
+/** Constructor for class AtomIdSet.
+ *
+ */
+AtomIdSet::AtomIdSet()
+{}
+
+/** Destructor for class AtomIdSet.
+ *
+ */
+AtomIdSet::~AtomIdSet()
+{}
+
+/** Returns iterator to first atim via a transform_iterator.
+ *
+ * @return iterator to first atom in this set
+ */
+AtomIdSet::iterator AtomIdSet::begin(){
+  return iterator(atoms.begin(), FromIdToAtom());
+}
+
+/** Returns constant iterator to first atim via a transform_iterator.
+ *
+ * @return const iterator to first atom in this set
+ */
+AtomIdSet::const_iterator AtomIdSet::begin() const{
+  return const_iterator(atoms.begin(), FromIdToAtom());
+}
+
+/** Returns iterator to one beyond last atom via a transform_iterator.
+ *
+ * @return iterator to one beyond last atom in this set
+ */
+AtomIdSet::iterator AtomIdSet::end(){
+  return iterator(atoms.end(), FromIdToAtom());
+}
+
+/** Returns constant iterator to one beyond last atom via a transform_iterator.
+ *
+ * @return const iterator to one beyond last atom in this set
+ */
+AtomIdSet::const_iterator AtomIdSet::end() const{
+  return const_iterator(atoms.end(), FromIdToAtom());
+}
+
+/** Returns true if this set is empty.
+ *
+ * @return true - set is empty, false - there is at least one atom
+ */
+bool AtomIdSet::empty() const
+{
+  return (atoms.empty());
+}
+
+/** Returns the number of members of this set.
+ *
+ * @return number of members in set
+ */
+size_t AtomIdSet::size() const
+{
+  // set has unique members, hence just return its size
+  return atoms.size();
+}
+
+/** Returns the iterator to the atom \a *key.
+ *
+ * @param key atom to find
+ * @return iterator to atom if found, to end() - else
+ */
+AtomIdSet::const_iterator AtomIdSet::find(const atom * const key) const
+{
+  return const_iterator(atoms.find(key->getId()), FromIdToAtom());
+}
+
+/** Returns the iterator to the atom \a *key.
+ *
+ * @param id atomic id to find
+ * @return iterator to atom if found, to end() - else
+ */
+AtomIdSet::const_iterator AtomIdSet::find(const atomId_t &id) const
+{
+  return const_iterator(atoms.find(id), FromIdToAtom());
+}
+
+/** Inserts a given atom into the set.
+ *
+ * @param key atom to insert
+ * @return pair of iterator and bool that states whether element is already present (true) or not (false)
+ */
+std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atom * const key)
+{
+  std::pair<atomIdSet::iterator, bool> iter =
+      atoms.insert(key->getId());
+  std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
+
+  return retiter;
+}
+
+/** Inserts a given atom into the set.
+ *
+ * @param id atomic id to insert
+ * @return pair of iterator and bool that states whether element is already present (true) or not (false)
+ */
+std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atomId_t &id)
+{
+  std::pair<atomIdSet::iterator, bool> iter =
+      atoms.insert(id);
+  std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
+
+  return retiter;
+}
+
+AtomIdSet::const_iterator AtomIdSet::erase(AtomIdSet::const_iterator &loc)
+{
+  const_iterator iter = loc;
+  ++iter;
+  atom * const _atom = const_cast<atom *>(*loc);
+  atoms.erase( _atom->getId() );
+  return iter;
+}
+
+/** Erase an atom from the list.
+ *
+ * @param *key key to atom in list
+ * @return iterator to just after removed item (compliant with standard)
+ */
+AtomIdSet::const_iterator AtomIdSet::erase(const atom * const key)
+{
+  const_iterator iter = find(key);
+  if (iter != end()){
+    ++iter;
+    atoms.erase( key->getId() );
+  }
+  return iter;
+}
+
+/** Erase an atom from the list.
+ *
+ * @param id atomic id atom in list to erase
+ * @return iterator to just after removed item (compliant with standard)
+ */
+AtomIdSet::const_iterator AtomIdSet::erase(const atomId_t &id)
+{
+  atomIdSet::const_iterator iter = atoms.find(id);
+  if (iter != atoms.end()){
+    ++iter;
+    atoms.erase( id );
+  }
+  return iterator(iter, FromIdToAtom());
+}
Index: src/AtomIdSet.hpp
===================================================================
--- src/AtomIdSet.hpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
+++ src/AtomIdSet.hpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
@@ -0,0 +1,76 @@
+/*
+ * AtomIdSet.hpp
+ *
+ *  Created on: Feb 21, 2012
+ *      Author: heber
+ */
+
+#ifndef ATOMIDSET_HPP_
+#define ATOMIDSET_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <boost/iterator/transform_iterator.hpp>
+
+#include <set>
+#include <vector>
+
+#include "types.hpp"
+
+class atom;
+struct FromIdToAtom :
+  public std::unary_function<atom *, atomId_t>
+{
+    atom * operator()(atomId_t id) const;
+};
+
+/** AtomIdSet is a set of atomic ids that however behave as a set of atoms.
+ *
+ * This class represents an iterable set of atoms that is however only stored as
+ * ids internally.
+ */
+class AtomIdSet
+{
+public:
+  typedef std::set<atomId_t> atomIdSet;
+  typedef boost::transform_iterator<FromIdToAtom, atomIdSet::iterator, atom *, atomId_t> iterator;
+  typedef boost::transform_iterator<FromIdToAtom, atomIdSet::const_iterator, const atom *, atomId_t const &> const_iterator;
+
+  AtomIdSet(const atomIdSet &_atoms);
+  AtomIdSet(const std::vector<atom *> &_atoms);
+  AtomIdSet();
+  ~AtomIdSet();
+
+  iterator begin();
+  const_iterator begin() const;
+  iterator end();
+  const_iterator end() const;
+  bool empty() const;
+  size_t size() const;
+  const_iterator find(const atom * const key) const;
+  const_iterator find(const atomId_t &id) const;
+  std::pair<iterator, bool> insert(const atom * const key);
+  std::pair<iterator, bool> insert(const atomId_t &id);
+  const_iterator erase(const_iterator &loc);
+  const_iterator erase(const atom * const key);
+  const_iterator erase(const atomId_t &id);
+
+  /** Getter for internal set of atoms.
+   *
+   * @return set of atomic ids
+   */
+  const atomIdSet & getAtomIds() const {
+    return atoms;
+  }
+
+private:
+  //!> internal atoms stored by their ids
+  atomIdSet atoms;
+};
+
+
+#endif /* ATOMIDSET_HPP_ */
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision d927abb3d77a2859e44f0802e7b32cf4c5385ec6)
+++ src/Makefile.am	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
@@ -154,4 +154,5 @@
   ${THERMOSTATSOURCE} \
   ${TESSELATIONSOURCE} \
+  AtomIdSet.cpp \
   Box.cpp \
   Box_BoundaryConditions.cpp \
@@ -175,4 +176,5 @@
   ${THERMOSTATHEADER} \
   ${TESSELATIONHEADER} \
+  AtomIdSet.hpp \
   Box.hpp \
   Box_BoundaryConditions.hpp \
Index: src/unittests/AtomIdSetUnitTest.cpp
===================================================================
--- src/unittests/AtomIdSetUnitTest.cpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
+++ src/unittests/AtomIdSetUnitTest.cpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
@@ -0,0 +1,148 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * AtomIdSetUnitTest.cpp
+ *
+ *  Created on: Feb 21, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include <algorithm>
+
+#include "Atom/atom.hpp"
+#include "AtomIdSet.hpp"
+#include "CodePatterns/Assert.hpp"
+#include "World.hpp"
+
+#include "AtomIdSetUnitTest.hpp"
+
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( AtomIdSetUnittest );
+
+size_t AtomIdSetUnittest::MaxAtoms = 6;
+
+void AtomIdSetUnittest::setUp(){
+  // failing asserts should be thrown
+  ASSERT_DO(Assert::Throw);
+
+  atomVector.resize((size_t)MaxAtoms);
+  std::generate_n(atomVector.begin(), MaxAtoms,
+      boost::bind(&World::createAtom, boost::ref(World::getInstance())));
+}
+
+void AtomIdSetUnittest::tearDown()
+{
+  World::purgeInstance();
+}
+
+void AtomIdSetUnittest::inserteraseTest()
+{
+  // insert all
+  for (size_t i=0; i< MaxAtoms; ++i) {
+    atoms.insert(atomVector[i]);
+  }
+  CPPUNIT_ASSERT_EQUAL( (size_t)MaxAtoms, atoms.size() );
+
+  // erase them again
+  for (size_t i=0; i< MaxAtoms; ++i) {
+    atoms.erase(atomVector[i]);
+  }
+  CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
+
+  {
+    // use atomVector in cstor
+    AtomIdSet otherAtoms(atomVector);
+    CPPUNIT_ASSERT_EQUAL( (size_t)MaxAtoms, otherAtoms.size() );
+  }
+}
+
+void AtomIdSetUnittest::positionTest()
+{
+  // non-const iterators
+  CPPUNIT_ASSERT( atoms.begin() == atoms.end() );
+
+  // const iterators
+  {
+    AtomIdSet::const_iterator beg_iter = atoms.begin();
+    AtomIdSet::const_iterator end_iter = atoms.end();
+    CPPUNIT_ASSERT( beg_iter == end_iter );
+  }
+
+  // insert an element
+  atoms.insert(atomVector[0]);
+  CPPUNIT_ASSERT( atoms.begin() != atoms.end() );
+
+  {
+    AtomIdSet::const_iterator beg_iter = atoms.begin();
+    AtomIdSet::const_iterator end_iter = atoms.end();
+    CPPUNIT_ASSERT( beg_iter != end_iter );
+    ++beg_iter;
+    CPPUNIT_ASSERT( beg_iter == end_iter );
+  }
+}
+
+void AtomIdSetUnittest::findTest()
+{
+  // search for atom
+  atoms.insert(atomVector[0]);
+  CPPUNIT_ASSERT( atoms.find(atomVector[0]) == atoms.begin() );
+  CPPUNIT_ASSERT( atoms.find(atomVector[0]) != atoms.end() );
+  atoms.erase(atomVector[0]);
+
+  // search for key
+  atoms.insert(atomVector[0]->getId());
+  CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) == atoms.begin() );
+  CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) != atoms.end() );
+  atoms.erase(atomVector[0]->getId());
+}
+
+
+void AtomIdSetUnittest::emptyTest()
+{
+  // initially empty
+  CPPUNIT_ASSERT( atoms.empty() );
+
+  // filled with one then no more
+  atoms.insert(atomVector[0]);
+  CPPUNIT_ASSERT( !atoms.empty() );
+
+  // erase and again empty
+  atoms.erase(atomVector[0]);
+  CPPUNIT_ASSERT( atoms.empty() );
+}
+
+void AtomIdSetUnittest::sizeTest()
+{
+  // initially empty
+  CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
+
+  // filled with one, then no more
+  atoms.insert(atomVector[0]);
+  CPPUNIT_ASSERT_EQUAL( (size_t)1, atoms.size() );
+
+  // erase and again empty
+  atoms.erase(atomVector[0]);
+  CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
+}
+
Index: src/unittests/AtomIdSetUnitTest.hpp
===================================================================
--- src/unittests/AtomIdSetUnitTest.hpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
+++ src/unittests/AtomIdSetUnitTest.hpp	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
@@ -0,0 +1,52 @@
+/*
+ * AtomIdSetUnitTest.hpp
+ *
+ *  Created on: Feb 21, 2012
+ *      Author: heber
+ */
+
+#ifndef ATOMIDSETUNITTEST_HPP_
+#define ATOMIDSETUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <vector>
+
+class atom;
+
+#include "AtomIdSet.hpp"
+
+class AtomIdSetUnittest : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( AtomIdSetUnittest );
+  CPPUNIT_TEST ( inserteraseTest );
+  CPPUNIT_TEST ( positionTest );
+  CPPUNIT_TEST ( findTest );
+  CPPUNIT_TEST ( emptyTest );
+  CPPUNIT_TEST ( sizeTest );
+  CPPUNIT_TEST_SUITE_END();
+
+public:
+  void setUp();
+  void tearDown();
+
+  void inserteraseTest();
+  void positionTest();
+  void findTest();
+  void emptyTest();
+  void sizeTest();
+
+private:
+  std::vector<atom *> atomVector;
+  AtomIdSet atoms;
+
+  static size_t MaxAtoms;
+};
+
+#endif /* ATOMIDSETUNITTEST_HPP_ */
Index: src/unittests/Makefile.am
===================================================================
--- src/unittests/Makefile.am	(revision d927abb3d77a2859e44f0802e7b32cf4c5385ec6)
+++ src/unittests/Makefile.am	(revision 5e65342e2c81c65880890589b38aca41fb13097c)
@@ -28,4 +28,5 @@
 
 GENERALTESTS = \
+  AtomIdSetUnitTest \
   BoxUnitTest \
   Box_BoundaryConditionsTest \
@@ -81,4 +82,5 @@
 	${UIELEMENTSMENUTESTSSOURCES} \
 	stubs/ObserverStub.cpp \
+	AtomIdSetUnitTest.cpp \
   BoxUnitTest.cpp \
 	Box_BoundaryConditionsUnitTest.cpp \
@@ -103,4 +105,5 @@
 	${UIELEMENTSMENUTESTSHEADERS} \
 	stubs/ObserverStub.hpp \
+	AtomIdSetUnitTest.hpp \
   BoxUnitTest.hpp \
 	Box_BoundaryConditionsUnitTest.hpp \
@@ -120,4 +123,9 @@
 	../libMolecuilderHelpers.la \
 	$(top_builddir)/LinearAlgebra/src/LinearAlgebra/libLinearAlgebra.la
+
+AtomIdSetUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	AtomIdSetUnitTest.cpp \
+	AtomIdSetUnitTest.hpp
+AtomIdSetUnitTest_LDADD =  $(ALLLIBS)
 
 Box_BoundaryConditionsTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
