From eef9f076acaa72f58f4e88c2048bd7ebc348b4e5 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Wed, 20 Feb 2013 15:39:18 -0500
Subject: [PATCH] Fixed the atom indices in the entity generated in the
 CoordGroup::Filter function

---
 modules/mol/base/src/atom_base.cc   | 7 +++++++
 modules/mol/base/src/atom_base.hh   | 1 +
 modules/mol/base/src/coord_group.cc | 6 +++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/modules/mol/base/src/atom_base.cc b/modules/mol/base/src/atom_base.cc
index c818fbc1c..a24ca3abb 100644
--- a/modules/mol/base/src/atom_base.cc
+++ b/modules/mol/base/src/atom_base.cc
@@ -240,5 +240,12 @@ unsigned long AtomBase::GetIndex() const
   return Impl()->GetIndex();
 }
 
+void AtomBase::SetIndex(const unsigned long index) 
+{
+  this->CheckValidity();
+  return impl_->SetIndex(index);
+}
+
+  
 }} // ns
 
diff --git a/modules/mol/base/src/atom_base.hh b/modules/mol/base/src/atom_base.hh
index 137953115..4ddc13f2f 100644
--- a/modules/mol/base/src/atom_base.hh
+++ b/modules/mol/base/src/atom_base.hh
@@ -141,6 +141,7 @@ public:
   
   void SetRadius(Real radius);
   
+  void SetIndex (const unsigned long index);
   
   const geom::Mat3& GetAnisou() const;
   
diff --git a/modules/mol/base/src/coord_group.cc b/modules/mol/base/src/coord_group.cc
index 5af231a55..d02eecc27 100644
--- a/modules/mol/base/src/coord_group.cc
+++ b/modules/mol/base/src/coord_group.cc
@@ -239,8 +239,12 @@ CoordGroupHandle CoordGroupHandle::Filter(const EntityView& selected, int first,
       indices.push_back(i->GetIndex());
     }
     new_ent=CreateEntityFromView(selected, false);
+    //we have to correct the atom indices in the new entity
+    AtomHandleList new_atoms=new_ent.GetAtomList();
+    for (int i=0,e=atoms.size();i!=e;++i){
+      new_atoms[i].SetIndex(i);
+    }
   }
-
   CoordGroupHandle filtered_cg=CreateCoordGroup(new_ent.GetAtomList());
   std::vector<geom::Vec3> vecs(indices.size());
   if (last==-1) last=this->GetFrameCount();
-- 
GitLab