diff --git a/modules/gui/src/scene_menu.cc b/modules/gui/src/scene_menu.cc index 59706446935595833c11ecd2732556c3c855451e..7952b8c47ff7eb92cbb1e2d856bf50c5601a0c7a 100644 --- a/modules/gui/src/scene_menu.cc +++ b/modules/gui/src/scene_menu.cc @@ -29,8 +29,14 @@ namespace ost { namespace gui { SceneMenu::SceneMenu() { context_menu_=new QMenu(); select_menu_=context_menu_->addMenu("Select"); - QAction* a=select_menu_->addAction("Around Atom"); + QAction* a=select_menu_->addAction("Atom"); + connect(a, SIGNAL(triggered()), this, SLOT(SelectAtom())); + a=select_menu_->addAction("Residue"); + connect(a, SIGNAL(triggered()), this, SLOT(SelectResidue())); + a=select_menu_->addAction("Around Atom"); connect(a, SIGNAL(triggered()), this, SLOT(SelectAroundAtom())); + a=select_menu_->addAction("Around Residue"); + connect(a, SIGNAL(triggered()), this, SLOT(SelectAroundResidue())); a=select_menu_->addAction("Backbone"); connect(a, SIGNAL(triggered()), this, SLOT(SelectBackbone())); a=select_menu_->addAction("Sidechains"); @@ -76,6 +82,32 @@ void SceneMenu::SelectAroundAtom() e->SetSelection(v); } +void SceneMenu::SelectAroundResidue() +{ + gfx::EntityP e=dyn_cast<gfx::Entity>(picked_.first); + mol::EntityView v=e->GetView().CreateEmptyView(); + v.AddAtom(picked_.second); + v=v.ExtendViewToResidues(); + v=v.ExtendViewToSurrounding(0.5); + e->SetSelection(v.ExtendViewToResidues()); +} + +void SceneMenu::SelectAtom() +{ + gfx::EntityP e=dyn_cast<gfx::Entity>(picked_.first); + mol::EntityView v=e->GetView().CreateEmptyView(); + v.AddAtom(picked_.second); + e->SetSelection(v); +} + +void SceneMenu::SelectResidue() +{ + gfx::EntityP e=dyn_cast<gfx::Entity>(picked_.first); + mol::EntityView v=e->GetView().CreateEmptyView(); + v.AddAtom(picked_.second); + e->SetSelection(v.ExtendViewToResidues()); +} + void SceneMenu::Select(const String& str) { gfx::EntityP e=dyn_cast<gfx::Entity>(picked_.first); diff --git a/modules/gui/src/scene_menu.hh b/modules/gui/src/scene_menu.hh index 0b212bad940db904428bcf12ade5357ea2ed8088..8b8d1f402c579c164e93761e96e191292fbd1b3e 100644 --- a/modules/gui/src/scene_menu.hh +++ b/modules/gui/src/scene_menu.hh @@ -43,6 +43,9 @@ public slots: void SelectSidechains(); void SelectLigands(); void SelectAroundAtom(); + void SelectAroundResidue(); + void SelectAtom(); + void SelectResidue(); void Select(const String& str); void UnSelect(); void CenterOnAtom(); diff --git a/modules/mol/base/pymod/export_entity_view.cc b/modules/mol/base/pymod/export_entity_view.cc index 3b3eadab25854ee278194bd82119bfb2861e291e..4eadd54cdcb121c0507ffd2a4f0bdfb06f43f6d3 100644 --- a/modules/mol/base/pymod/export_entity_view.cc +++ b/modules/mol/base/pymod/export_entity_view.cc @@ -86,6 +86,8 @@ void export_EntityView() class_<EntityView, bases<EntityBase> >("EntityView", init<>()) .def("Copy", &EntityView::Copy) + .def("ExtendViewToResidues", &EntityView::ExtendViewToResidues) + .def("ExtendViewToSurrounding", &EntityView::ExtendViewToSurrounding) .def("FindChain", find_chain_str) .def("FindResidue", &EntityView::FindResidue) .def("FindAtom", find_atom_a) diff --git a/modules/mol/base/src/entity_view.cc b/modules/mol/base/src/entity_view.cc index d81d02d986e7651354fadde6feeef814b2a4958f..945230d2f2779b172c02bc4ffc341fb2d3c96a73 100644 --- a/modules/mol/base/src/entity_view.cc +++ b/modules/mol/base/src/entity_view.cc @@ -773,6 +773,42 @@ void EntityView::RemoveAtomInternal(const AtomView& av) data_->handle_to_view.erase(av.GetHandle().GetHashCode()); } +EntityView EntityView::ExtendViewToResidues() const +{ + this->CheckValidity(); + EntityView view=this->CreateEmptyView(); + ResidueViewList residues=this->GetResidueList(); + ResidueViewList::const_iterator res_it; + for (res_it=residues.begin(); res_it!=residues.end(); ++res_it) { + view.AddResidue((*res_it).GetHandle(), + mol::ViewAddFlag::INCLUDE_ALL|mol::ViewAddFlag::CHECK_DUPLICATES); + } + view.AddAllInclusiveBonds(); + return view; +} + +EntityView EntityView::ExtendViewToSurrounding(Real gap) const +{ + this->CheckValidity(); + EntityView view=this->CreateEmptyView(); + AtomViewList atoms=this->GetAtomList(); + AtomViewList::const_iterator atm_it; + Real max_dist=5+gap; + for (atm_it=atoms.begin(); atm_it!=atoms.end(); ++atm_it) { + view.AddAtom((*atm_it),mol::ViewAddFlag::INCLUDE_ALL|mol::ViewAddFlag::CHECK_DUPLICATES); + AtomHandleList prot_atoms=this->GetHandle().FindWithin((*atm_it).GetPos(),max_dist); + AtomHandleList::const_iterator protatm_it; + for (protatm_it=prot_atoms.begin(); protatm_it!=prot_atoms.end(); ++protatm_it){ + Real dist=geom::Distance((*atm_it).GetPos(), (*protatm_it).GetPos()); + if (dist <= (*atm_it).GetRadius() + (*protatm_it).GetRadius() + gap) { + view.AddAtom((*protatm_it),mol::ViewAddFlag::INCLUDE_ALL|mol::ViewAddFlag::CHECK_DUPLICATES); + } + } + } + view.AddAllInclusiveBonds(); + return view; +} + namespace { class EntityViewDumper : public EntityVisitor { diff --git a/modules/mol/base/src/entity_view.hh b/modules/mol/base/src/entity_view.hh index 6e3aa7bf8b07f102436f172e0ce1ff2ce618c724..e9566a1c2f3c756fbf003031ad4a0d6f01df05b2 100644 --- a/modules/mol/base/src/entity_view.hh +++ b/modules/mol/base/src/entity_view.hh @@ -286,6 +286,16 @@ public: Real GetAngle(const AtomView& a1, const AtomView& a2, const AtomView& a3) const; + /// \brief Extend current view to include all atoms of each residue where + /// at least one atom is selected currently + EntityView ExtendViewToResidues() const; + + /// \brief Extend current view to include all atoms that are within the sum + /// of their vdw radii + gap + /// + /// Include all atoms within: at1.GetRadius() + at2.GetRadius() + gap + EntityView ExtendViewToSurrounding(Real gap) const; + /// \brief returns a string containing a human-readable summary of the /// entity view String Dump() const;