diff --git a/modules/mol/base/src/chain_view.cc b/modules/mol/base/src/chain_view.cc index 87fd218701569abd1cf15260b93b8a09bcc081cb..bb6562c9cd5c248f9e239176cbfff617ac0a5d2d 100644 --- a/modules/mol/base/src/chain_view.cc +++ b/modules/mol/base/src/chain_view.cc @@ -221,11 +221,15 @@ void ChainView::RemoveResidue(ResidueView view) { if (!view.IsValid()) return; view.RemoveAtoms(); + int index = view.GetIndex(); ResidueViewList::iterator i=data_->residues.begin(); for (; i!=data_->residues.end(); ++i) { + int res_index = (*i).GetIndex(); if (*i==view) { data_->residues.erase(i); - return; + } + else if(index < res_index){ + (*i).SetIndex(res_index-1); } } } diff --git a/modules/mol/base/src/residue_view.cc b/modules/mol/base/src/residue_view.cc index e976652449b8cc15bf0d780c58f3fa8521e6f4c0..b9cc9b8b78bf48cb85e1db9e9dcce38f027ae429 100644 --- a/modules/mol/base/src/residue_view.cc +++ b/modules/mol/base/src/residue_view.cc @@ -37,17 +37,17 @@ namespace ost { namespace mol { class DLLEXPORT_OST_MOL ResidueViewData { public: - ResidueViewData(); - ResidueViewData(const ChainViewDataPtr& chain_data) - : chain(chain_data) { - } + ResidueViewData(int residue_index): index(residue_index){} + ResidueViewData(const ChainViewDataPtr& chain_data, int residue_index) + : chain(chain_data), index(residue_index) { } ChainViewDataWeakPtr chain; AtomViewList atoms; + int index; }; ResidueView::ResidueView(const ChainView& chain, const ResidueHandle& residue) - : ResidueBase(residue.Impl()), data_(new ResidueViewData(chain.ViewData())) { + : ResidueBase(residue.Impl()), data_(new ResidueViewData(chain.ViewData(), chain.GetResidueCount())) { } ResidueView::ResidueView(const ResidueViewDataPtr& data, @@ -185,7 +185,13 @@ bool ResidueView::operator!=(const ResidueView& rhs) const int ResidueView::GetIndex() const { this->CheckValidity(); - return this->GetChain().GetResidueIndex(this->GetNumber()); + return data_->index; +} + +void ResidueView::SetIndex(int index) +{ + this->CheckValidity(); + data_->index = index; } double ResidueView::GetMass() const diff --git a/modules/mol/base/src/residue_view.hh b/modules/mol/base/src/residue_view.hh index 4ed53d0b110399118f18b6d631c344b099aac3e5..0cd381e86e08046fa59456b6e7cf48f44bfabd03 100644 --- a/modules/mol/base/src/residue_view.hh +++ b/modules/mol/base/src/residue_view.hh @@ -37,6 +37,9 @@ namespace ost { namespace mol { /// affect the view and do not alter the structure and topology of the underlying /// \ref ResidueHandle "residue". class DLLEXPORT_OST_MOL ResidueView : public ResidueBase { + + friend class ChainView; + public: /// \brief Create invalid ResidueView ResidueView(); @@ -170,6 +173,12 @@ public: bool operator==(const ResidueView& rhs) const; bool operator!=(const ResidueView& rhs) const; + +protected: + /// \brief set the index of residiue view in chain + /// should be called from chainview whenever indexes change + void SetIndex(int index); + private: ResidueViewDataPtr data_; };