diff --git a/modules/gfx/src/entity.cc b/modules/gfx/src/entity.cc index 7094c5d579f609a3695b39c62aac1620fd03d1ac..6c613225463b6a0da0777ecc3d2e5f4ea3215655 100644 --- a/modules/gfx/src/entity.cc +++ b/modules/gfx/src/entity.cc @@ -453,7 +453,7 @@ bool Entity::OnSelect(const geom::Line3& line, geom::Vec3& result, if(av.IsValid()) { LOG_DEBUG("de-selected atom: " << sel); sel_.RemoveAtom(av); - if(av.GetResidue().GetAtomCount()==0){ + if(!av.GetResidue().HasAtoms()){ av.GetResidue().GetChain().RemoveResidue(av.GetResidue()); } } else { @@ -614,7 +614,7 @@ void Entity::OnRenderModeChange() for (RendererMap::iterator i=renderer_.begin(), e=renderer_.end(); i!=e; ++i) { mol::EntityView rv=i->second->GetFullView(); - if (rv.IsValid() && rv.GetAtomCount()>0) { + if (rv.IsValid() && rv.HasAtoms()) { i->second->SetSelection(mol::Intersection(sel_, rv)); } i->second->UpdateViews(); @@ -1004,7 +1004,7 @@ void Entity::set_static_max_rad() bool Entity::HasSelection() const { - return (sel_.IsValid() && sel_.GetAtomCount()>0); + return (sel_.IsValid() && sel_.HasAtoms()); } namespace { diff --git a/modules/gfx/src/impl/entity_renderer.cc b/modules/gfx/src/impl/entity_renderer.cc index fb22e24a375988bdcb36bf8b9b1b9b0e34695fef..9b623cc11455a1a93737045f576e3279cf6d3637 100644 --- a/modules/gfx/src/impl/entity_renderer.cc +++ b/modules/gfx/src/impl/entity_renderer.cc @@ -113,7 +113,7 @@ void EntityRenderer::SubstractView(const mol::EntityView& view) void EntityRenderer::ClearViews() { - if (full_view_.IsValid() && full_view_.GetAtomCount()>0) { + if (full_view_.IsValid() && full_view_.HasAtoms()) { full_view_=full_view_.CreateEmptyView(); if(effective_view_.IsValid()){ effective_view_=effective_view_.CreateEmptyView(); @@ -127,7 +127,7 @@ void EntityRenderer::ClearViews() bool EntityRenderer::HasDataToRender() const { - return effective_view_ && effective_view_.GetAtomCount()>0; + return effective_view_ && effective_view_.HasAtoms(); } mol::EntityView EntityRenderer::GetFullView() @@ -163,7 +163,7 @@ void EntityRenderer::Export(Exporter* ex) bool EntityRenderer::HasSelection() const { - return (sel_.IsValid() && sel_.GetAtomCount()>0); + return (sel_.IsValid() && sel_.HasAtoms()); } void EntityRenderer::SetSelection(const mol::EntityView& sel) diff --git a/modules/mol/alg/src/trajectory_analysis.cc b/modules/mol/alg/src/trajectory_analysis.cc index a4ce2026b2248fd2ea8144c170e13b2cca46198f..1ef9b565142bc48336dc4c76e1ce7e4e37100539 100644 --- a/modules/mol/alg/src/trajectory_analysis.cc +++ b/modules/mol/alg/src/trajectory_analysis.cc @@ -159,10 +159,10 @@ std::vector<Real> AnalyzeMinDistance(const CoordGroupHandle& traj, const Entity // each frame in a trajectory and returns it as a vector. { CheckHandleValidity(traj); - if (view1.GetAtomCount()==0){ + if (!view1.HasAtoms()){ throw Error("first EntityView is empty"); } - if (view2.GetAtomCount()==0){ + if (!view2.HasAtoms()){ throw Error("second EntityView is empty"); } std::vector<Real> dist; @@ -183,10 +183,10 @@ std::vector<Real> AnalyzeMinDistanceBetwCenterOfMassAndView(const CoordGroupHand // of a second set of atoms (view_cm) for each frame in a trajectory and returns it as a vector. { CheckHandleValidity(traj); - if (view_cm.GetAtomCount()==0){ + if (!view_cm.HasAtoms()){ throw Error("first EntityView is empty"); } - if (view_atoms.GetAtomCount()==0){ + if (!view_atoms.HasAtoms()){ throw Error("second EntityView is empty"); } std::vector<Real> dist, masses_cm; @@ -210,10 +210,10 @@ std::vector<Real> AnalyzeAromaticRingInteraction(const CoordGroupHandle& traj, c // center of mass - heavy atom distance betweent he two rings { CheckHandleValidity(traj); - if (view_ring1.GetAtomCount()==0){ + if (!view_ring1.HasAtoms()){ throw Error("first EntityView is empty"); } - if (view_ring2.GetAtomCount()==0){ + if (!view_ring2.HasAtoms()){ throw Error("second EntityView is empty"); } std::vector<Real> dist, masses_ring1,masses_ring2; @@ -238,7 +238,7 @@ std::vector<Real> AnalyzeAromaticRingInteraction(const CoordGroupHandle& traj, c //the last residue of the selection, usually the direction of the alpha-helix { CheckHandleValidity(traj); - if (prot_seg.GetAtomCount()==0){ + if (!prot_seg.HasAtoms()){ throw Error("EntityView is empty"); } std::vector<unsigned long> indices_ca; @@ -265,7 +265,7 @@ std::vector<Real> AnalyzeAromaticRingInteraction(const CoordGroupHandle& traj, c geom::Vec3List& centers, unsigned int stride) { CheckHandleValidity(traj); - if (prot_seg.GetAtomCount()==0){ + if (!prot_seg.HasAtoms()){ throw Error("EntityView is empty"); } std::vector<unsigned long> indices_ca; @@ -286,7 +286,7 @@ std::vector<Real> AnalyzeAromaticRingInteraction(const CoordGroupHandle& traj, c geom::Vec3List& origins, unsigned int stride) { CheckHandleValidity(traj); - if (prot_seg.GetAtomCount()==0){ + if (!prot_seg.HasAtoms()){ throw Error("EntityView is empty"); } std::vector<unsigned long> indices_ca; @@ -307,7 +307,7 @@ std::vector<Real> AnalyzeAromaticRingInteraction(const CoordGroupHandle& traj, c unsigned int stride) { CheckHandleValidity(traj); - if (prot_seg.GetAtomCount()==0){ + if (!prot_seg.HasAtoms()){ throw Error("EntityView is empty"); } std::vector<unsigned long> indices_c,indices_o, indices_n, indices_ca; diff --git a/modules/mol/base/src/chain_view.cc b/modules/mol/base/src/chain_view.cc index 355bd6cf5963f68a3a42fdf587c7ec60f2ed9c80..b8fc1b55b23ffc281df02cd52efc104dbd7cd260 100644 --- a/modules/mol/base/src/chain_view.cc +++ b/modules/mol/base/src/chain_view.cc @@ -383,16 +383,18 @@ geom::Vec3 ChainView::GetCenterOfAtoms() const { this->CheckValidity(); geom::Vec3 center; - if(this->GetAtomCount() > 0) { + if(this->HasAtoms()) { + int atom_count = 0; ResidueViewList::const_iterator i; for (i=data_->residues.begin(); i!=data_->residues.end(); ++i) { ResidueView r=*i; for (AtomViewList::const_iterator j=r.GetAtomList().begin(), e2=r.GetAtomList().end(); j!=e2; ++j) { center+=j->GetPos(); + atom_count+=1; } } - center/=this->GetAtomCount(); + center/=atom_count; } return center; } @@ -402,7 +404,7 @@ geom::Vec3 ChainView::GetCenterOfMass() const this->CheckValidity(); geom::Vec3 center; Real mass = this->GetMass(); - if(this->GetAtomCount() > 0 && mass > 0) { + if(this->HasAtoms() && mass > 0) { ResidueViewList::const_iterator i; for (i=data_->residues.begin(); i!=data_->residues.end(); ++i) { ResidueView r=*i; @@ -451,5 +453,18 @@ EntityView ChainView::Select(const String& q, QueryFlags flags) const { } else return this->GetEntity().Select(Query("cname='"+Impl()->GetName()+"'"), flags); } + + +bool ChainView::HasAtoms() const { + this->CheckValidity(); + for (ResidueViewList::const_iterator it=data_->residues.begin(), + e=data_->residues.end(); it!=e; ++it) { + if ((*it).HasAtoms()) { + return true; + } + } + return false; +} + }} // ns diff --git a/modules/mol/base/src/chain_view.hh b/modules/mol/base/src/chain_view.hh index 70bd305aa1c17884f062a2b0721c97cb1cea7340..3f9ea30bab6d8db628a2152bc8a8a08fccfd4691 100644 --- a/modules/mol/base/src/chain_view.hh +++ b/modules/mol/base/src/chain_view.hh @@ -199,6 +199,7 @@ public: bool operator==(const ChainView& rhs) const; bool operator!=(const ChainView& rhs) const; + bool HasAtoms() const; //@} private: ChainViewDataPtr data_; diff --git a/modules/mol/base/src/entity_view.cc b/modules/mol/base/src/entity_view.cc index d81940ee1bfc89228a9db78163ac410b95a96738..3a9918cde865d2a171fd687487c4a7f751be6756 100644 --- a/modules/mol/base/src/entity_view.cc +++ b/modules/mol/base/src/entity_view.cc @@ -161,7 +161,7 @@ int EntityView::GetResidueCount() const geom::Vec3 EntityView::GetCenterOfAtoms() const { geom::Vec3 center; - if (this->GetAtomCount()>0) { + if (this->HasAtoms()) { unsigned int counter=0; AtomViewIter it=this->AtomsBegin(); for(; it!=this->AtomsEnd(); ++it, ++counter) { @@ -176,7 +176,7 @@ geom::Vec3 EntityView::GetCenterOfMass() const { geom::Vec3 center; Real mass = this->GetMass(); - if (this->GetAtomCount()>0 && mass>0) { + if (this->HasAtoms() && mass>0) { AtomViewIter it=this->AtomsBegin(); for(; it!=this->AtomsEnd(); ++it) { center+=(*it).GetPos()*(*it).GetMass(); @@ -755,7 +755,7 @@ geom::AlignedCuboid EntityView::GetBounds() const this->CheckValidity(); geom::Vec3 mmin( std::numeric_limits<Real>::max()); geom::Vec3 mmax(-std::numeric_limits<Real>::max()); - if (this->GetAtomCount()) { + if (this->HasAtoms()) { for(AtomViewIter it=AtomsBegin(); it!=this->AtomsEnd(); ++it) { mmax=geom::Max(mmax, (*it).GetPos()); mmin=geom::Min(mmin, (*it).GetPos()); @@ -912,5 +912,18 @@ AtomView EntityView::FindAtom(const AtomHandle& atom) const return this->ViewForHandle(atom); } +bool EntityView::HasAtoms() const +{ + this->CheckValidity(); + for (ChainViewList::const_iterator it=data_->chains.begin(), + e=data_->chains.end(); + it!=e; ++it) { + if ((*it).HasAtoms()) { + return true; + } + } + return false; +} + }} // ns diff --git a/modules/mol/base/src/entity_view.hh b/modules/mol/base/src/entity_view.hh index 56136733b06abfca2abc5bf12c3f299f6de9e002..458e6d40fac928ac1c93b381a4fc1f2e1777d45f 100644 --- a/modules/mol/base/src/entity_view.hh +++ b/modules/mol/base/src/entity_view.hh @@ -341,6 +341,9 @@ public: EntityView CreateFullView() const; /// \brief create empty view EntityView CreateEmptyView() const; + + /// \brief true if view contains at least one atom + bool HasAtoms() const; #ifdef _MSC_VER // alternative routines for msvc AtomView AddXAtom(const AtomHandle& ah, ViewAddFlags flags=0); diff --git a/modules/mol/base/src/residue_view.cc b/modules/mol/base/src/residue_view.cc index 406854a1f0f077c61080c320320e82577765e625..21eea91de4f4ae8d5dcdd1348454321cad3252ba 100644 --- a/modules/mol/base/src/residue_view.cc +++ b/modules/mol/base/src/residue_view.cc @@ -281,4 +281,9 @@ AtomView ResidueView::FindAtom(const AtomHandle& handle) const return this->ViewForHandle(handle); } +bool ResidueView::HasAtoms() const { + this->CheckValidity(); + return data_->atoms.size()>0; +} + }} //ns diff --git a/modules/mol/base/src/residue_view.hh b/modules/mol/base/src/residue_view.hh index 1727e87719c93b1d437352d861e8674c6cd72963..289096413eccb5392fd895c2c99b3a0fc7e87435 100644 --- a/modules/mol/base/src/residue_view.hh +++ b/modules/mol/base/src/residue_view.hh @@ -183,6 +183,7 @@ public: bool operator!=(const ResidueView& rhs) const; + bool HasAtoms() const; protected: /// \brief set the index of residiue view in chain /// should be called from chainview whenever indexes change