Index: src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp
===================================================================
--- src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp	(revision 5026148ed739f29b2229d07be76ad31aca20fe30)
+++ src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp	(revision a13f2bb2167e2b7f751acdd3c12df751bb03a105)
@@ -78,4 +78,5 @@
     QObject *parent) :
   QObject(parent),
+  BondNodeParentMaps(std::vector<BondNodeParentMap_t>(2)),
   selectionMode(SelectAtom),
   board(_board)
@@ -164,5 +165,5 @@
     const ObservedValue_Index_t atomid = _atom->getIndex();
     boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
-    AtomNodeParentMap.insert( std::make_pair(atomid, (ObservedValue_Index_t)NULL) );
+    AtomNodeParentMap.left.insert( std::make_pair(atomid, (ObservedValue_Index_t)NULL) );
   }
 
@@ -184,6 +185,6 @@
   {
     boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
-    AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(atomid);
-    ASSERT (parentiter != AtomNodeParentMap.end(),
+    AtomNodeParentMap_t::left_iterator parentiter = AtomNodeParentMap.left.find(atomid);
+    ASSERT (parentiter != AtomNodeParentMap.left.end(),
         "GLWorldScene::insertAtom() - parent to atom id "+toString(atomid)+" unknown?");
     const ObservedValue_Index_t parentindex = parentiter->second;
@@ -235,5 +236,5 @@
   {
     boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
-    AtomNodeParentMap.erase(_atomid);
+    AtomNodeParentMap.left.erase(_atomid);
   }
   emit changed();
@@ -256,10 +257,16 @@
     const ObservedValue_Index_t bondid = _bond->getIndex();
     boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
-    std::vector<ObservedValue_Index_t> parents(2, (ObservedValue_Index_t)NULL);
     if ((_bond->getLeftAtom() != NULL) && (_bond->getLeftAtom()->getMoleculeRef() != NULL))
-      parents[0] = _bond->getLeftAtom()->getMoleculeRef()->getIndex();
+      BondNodeParentMaps[0].left.insert(
+          std::make_pair(bondid, _bond->getLeftAtom()->getMoleculeRef()->getIndex()) );
+    else
+      BondNodeParentMaps[0].left.insert(
+          std::make_pair(bondid, (ObservedValue_Index_t)NULL) );
     if ((_bond->getRightAtom() != NULL) && (_bond->getRightAtom()->getMoleculeRef() != NULL))
-      parents[1] = _bond->getRightAtom()->getMoleculeRef()->getIndex();
-    BondNodeParentMap.insert( std::make_pair(bondid, parents) );
+      BondNodeParentMaps[1].left.insert(
+          std::make_pair(bondid, _bond->getRightAtom()->getMoleculeRef()->getIndex()) );
+    else
+      BondNodeParentMaps[1].left.insert(
+          std::make_pair(bondid, (ObservedValue_Index_t)NULL) );
   }
 
@@ -280,26 +287,25 @@
 
   const ObservedValue_Index_t bondid = _bond->getIndex();
-  std::vector<QObject *> parents(2, static_cast<QObject *>(this));
+#ifdef NDEBUG
+  BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
+  ASSERT( iter == BondsinSceneMap.end(),
+    "GLWorldScene::insertBond() - bond "+toString(bondid)+" is already known.");
+#endif
   {
     boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
-    BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
-    ASSERT (parentiter != BondNodeParentMap.end(),
-        "GLWorldScene::insertBond() - parent to bond id "+toString(bondid)+" unknown?");
-    const std::vector<ObservedValue_Index_t> &molindices = parentiter->second;
-    for (size_t i = 0; i < molindices.size(); ++i) {
-      if (molindices[i] != (ObservedValue_Index_t)NULL) {
-        const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molindices[i]);
+    for (size_t i=0;i<2;++i) {
+      BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[i].left.find(bondid);
+      ASSERT (parentiter != BondNodeParentMaps[i].left.end(),
+          "GLWorldScene::insertBond() - parent to bond id "+toString(bondid)+" unknown?");
+      QObject *parent = this;
+      if (parentiter->second != (ObservedValue_Index_t)NULL) {
+        const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentiter->second);
         if (moliter != MoleculesinSceneMap.end())
-          parents[i] = moliter->second;
+          parent = moliter->second;
       }
-    }
-
-    BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
-    ASSERT( iter == BondsinSceneMap.end(),
-        "GLWorldScene::insertBond() - bond "+toString(bondid)+" is already known.");
-    for (size_t i=0;i<2;++i) {
+
       GLMoleculeObject_bond *bondObject = new GLMoleculeObject_bond(
               GLMoleculeObject::meshCylinder,
-              parents[i],
+              parent,
               _bond,
               bondsides[i]);
@@ -334,5 +340,6 @@
   {
     boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
-    BondNodeParentMap.erase(_bondid);
+    BondNodeParentMaps[0].left.erase(_bondid);
+    BondNodeParentMaps[1].left.erase(_bondid);
   }
 
@@ -390,9 +397,9 @@
   MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
   ASSERT( iter == MoleculesinSceneMap.end(),
-      "GLWorldScene::insertMolecule() - molecule's id "+toString(_mol->getMolIndex())
+      "GLWorldScene::insertMolecule() - molecule's id "+toString(molid)
       +" already present.");
 
   // add new object
-  LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _mol->getMolIndex());
+  LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << molid);
   GLMoleculeObject_molecule *molObject =
       new GLMoleculeObject_molecule(
@@ -402,5 +409,33 @@
   ASSERT( molObject != NULL,
       "GLWorldScene::insertMolecule - could not create molecule object for "
-      +toString(_mol->getMolIndex()));
+      +toString(molid));
+
+  // check all atoms for not yet assigned parents
+  {
+    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
+    std::pair<AtomNodeParentMap_t::right_const_iterator, AtomNodeParentMap_t::right_const_iterator> iters =
+        AtomNodeParentMap.right.equal_range(molid);
+    for (AtomNodeParentMap_t::right_const_iterator iter = iters.first;
+        iter != iters.second; ++iter) {
+      AtomNodeMap::const_iterator atomiter = AtomsinSceneMap.find(iter->second);
+      if (atomiter != AtomsinSceneMap.end())
+        resetParent(atomiter->second, molObject);
+    }
+  }
+  // check all bonds for not yet assigned parents
+  {
+    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
+    for (size_t i=0;i<2;++i) {
+      std::pair<BondNodeParentMap_t::right_const_iterator, BondNodeParentMap_t::right_const_iterator> iters =
+          BondNodeParentMaps[i].right.equal_range(molid);
+      for (BondNodeParentMap_t::right_const_iterator iter = iters.first;
+          iter != iters.second; ++iter) {
+        BondNodeMap::const_iterator bonditer = BondsinSceneMap.find(iter->second);
+        if (bonditer != BondsinSceneMap.end())
+          resetParent(bonditer->second, molObject);
+      }
+    }
+  }
+
 #ifndef NDEBUG
   std::pair<MoleculeNodeMap::iterator, bool> inserter =
@@ -453,4 +488,20 @@
 }
 
+/** This converts safely index into a GLMoleculeObject_molecule.
+ *
+ * \param _MoleculesinSceneMap all present molecules
+ * \param _molid index to look for
+ * \return MolObject or NULL when not found
+ */
+GLMoleculeObject_molecule *GLWorldScene::getMoleculeObject(
+    const ObservedValue_Index_t _molid) const
+{
+  const MoleculeNodeMap::const_iterator moliter = MoleculesinSceneMap.find(_molid);
+  if (moliter != MoleculesinSceneMap.end())
+    return moliter->second;
+  else
+    return NULL;
+}
+
 /** Changes the parent of an object in the scene.
  *
@@ -463,30 +514,20 @@
   boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
   const ObservedValue_Index_t walkerid = walker->getIndex();
-  AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(walkerid);
-  ASSERT( parentiter != AtomNodeParentMap.end(),
+  AtomNodeParentMap_t::left_iterator parentiter = AtomNodeParentMap.left.find(walkerid);
+  ASSERT( parentiter != AtomNodeParentMap.left.end(),
       "GLWorldScene::reparentAtom() - could not find object to id "+toString(walkerid));
 
   // change parent entry
+  AtomNodeParentMap.left.erase(parentiter);
   if (walker->getMoleculeRef() != NULL)
-    parentiter->second = walker->getMoleculeRef()->getIndex();
+    AtomNodeParentMap.left.insert( std::make_pair(walkerid, walker->getMoleculeRef()->getIndex()) );
   else
-    parentiter->second = NULL;
-  parentiter = AtomNodeParentMap.find(walkerid);
-
-  // reset parent if atom exists
-  AtomNodeMap::iterator atomiter = AtomsinSceneMap.find(walkerid);
-  if (atomiter != AtomsinSceneMap.end()) {
-    QObject *parent = this;
-    if (parentiter->second != NULL) {
-      MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentiter->second);
-      if (moliter != MoleculesinSceneMap.end())
-        parent = moliter->second;
-      else {
-        // molecule does not yet exist
-        ASSERT(0, "GLWorldScene::reparentAtom() - molecule not existent not implemented.");
-      }
-    }
-    atomiter->second->setParent(parent);
-  }
+    AtomNodeParentMap.left.insert( std::make_pair(walkerid, (ObservedValue_Index_t)NULL) );
+  parentiter = AtomNodeParentMap.left.find(walkerid);
+
+  const AtomNodeMap::iterator atomiter = AtomsinSceneMap.find(walkerid);
+  if (atomiter != AtomsinSceneMap.end())
+    resetParent(atomiter->second, getMoleculeObject(parentiter->second));
+  // else atom does not yet exist
 }
 
@@ -539,31 +580,39 @@
 {
   boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
+  const size_t dim = (_side == GLMoleculeObject_bond::left) ? 0 : 1;
   const ObservedValue_Index_t bondid = _bond->getIndex();
-  BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
-  ASSERT( parentiter != BondNodeParentMap.end(),
+  BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[dim].left.find(bondid);
+  ASSERT( parentiter != BondNodeParentMaps[dim].left.end(),
       "GLWorldScene::reparentBond() - could not find object to id "+toString(bondid));
 
   // change parent entry
-  const size_t dim = (_side == GLMoleculeObject_bond::left) ? 0 : 1;
+  BondNodeParentMaps[dim].left.erase(bondid);
   if ((_atom != NULL) && (_atom->getMoleculeRef() != NULL))
-    parentiter->second[dim] = _atom->getMoleculeRef()->getIndex();
+    BondNodeParentMaps[dim].left.insert( std::make_pair( bondid, _atom->getMoleculeRef()->getIndex()));
   else
-    parentiter->second[dim] = NULL;
+    BondNodeParentMaps[dim].left.insert( std::make_pair( bondid, (ObservedValue_Index_t)NULL) );
+  parentiter = BondNodeParentMaps[dim].left.find(bondid);
 
   // reset parent
-  GLMoleculeObject_bond *bondobj = getBondInScene(bondid, _side);
-  if (bondobj != NULL) {
+  resetParent(getBondInScene(bondid, _side), getMoleculeObject(parentiter->second));
+}
+
+/** Resets the parent of an GLMoleculeObject.
+ *
+ * \param _obj object to reparent
+ * \param _molid index of parent molecule
+ */
+void GLWorldScene::resetParent(
+    GLMoleculeObject *_obj,
+    GLMoleculeObject_molecule *_molobj)
+{
+  if (_obj != NULL) {
     QObject *parent = this;
-    if (parentiter->second[dim] != NULL) {
-      MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentiter->second[dim]);
-      if (moliter != MoleculesinSceneMap.end())
-        parent = moliter->second;
-      else {
-        // molecule does not yet exist
-        ASSERT(0, "GLWorldScene::reparentAtom() - molecule not existent not implemented.");
-      }
-    }
-    bondobj->setParent(parent);
-  }
+    if (_molobj != NULL)
+      parent = _molobj;
+    // else: molecule does not yet exist: is done when molecule is instantiated
+    _obj->setParent(parent);
+  }
+  // else object does not yet exist
 }
 
Index: src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp
===================================================================
--- src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp	(revision 5026148ed739f29b2229d07be76ad31aca20fe30)
+++ src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp	(revision a13f2bb2167e2b7f751acdd3c12df751bb03a105)
@@ -20,4 +20,5 @@
 #include <iosfwd>
 
+#include <boost/bimap.hpp>
 #include <boost/thread/recursive_mutex.hpp>
 
@@ -117,4 +118,12 @@
 
 private:
+
+  GLMoleculeObject_molecule *getMoleculeObject(
+      const ObservedValue_Index_t _molid) const;
+
+  void resetParent(
+      GLMoleculeObject *_obj,
+      GLMoleculeObject_molecule *_molobj);
+
   void reparentBond(
       QtObservedBond *_bond,
@@ -140,7 +149,13 @@
 
   //!> typedef for storing the current parent to each atom node in scene, NULL indicates GLWorldScene is parent
-  typedef std::map<ObservedValue_Index_t, ObservedValue_Index_t> AtomNodeParentMap_t;
+  typedef boost::bimap<
+      boost::bimaps::set_of< ObservedValue_Index_t >,
+      boost::bimaps::multiset_of< ObservedValue_Index_t >
+  > AtomNodeParentMap_t;
   //!> typedef for storing the current parent to each bond node in scene, NULL indicates GLWorldScene is parent
-  typedef std::map<ObservedValue_Index_t, std::vector<ObservedValue_Index_t> > BondNodeParentMap_t;
+  typedef boost::bimap<
+      boost::bimaps::set_of< ObservedValue_Index_t >,
+      boost::bimaps::multiset_of< ObservedValue_Index_t >
+  > BondNodeParentMap_t;
 
   //!> mutex to ascertain atomic access to NodeParentMaps
@@ -153,5 +168,5 @@
   ShapeNodeMap ShapesinSceneMap;
   AtomNodeParentMap_t AtomNodeParentMap;
-  BondNodeParentMap_t BondNodeParentMap;
+  std::vector<BondNodeParentMap_t> BondNodeParentMaps;
 
   SelectionModeType selectionMode;
