diff --git a/modules/mol/base/pymod/export_atom.cc b/modules/mol/base/pymod/export_atom.cc index 48695455dd9a816476e543ffdb89d24f26c4b51d..8aa81ce4e974942501427bd36c7e50b97cf6889f 100644 --- a/modules/mol/base/pymod/export_atom.cc +++ b/modules/mol/base/pymod/export_atom.cc @@ -28,6 +28,14 @@ using namespace ost::mol; #include <ost/export_helper/generic_property_def.hh> #include <ost/export_helper/vector.hh> + +namespace { + ChainHandle get_chain(AtomHandle& a) + { + return a.GetResidue().GetChain(); + } +} + void export_Atom() { class_<AtomBase> atom_base("AtomBase", no_init); @@ -81,6 +89,8 @@ void export_Atom() class_<AtomHandle, bases<AtomBase> >("AtomHandle", init<>()) .def("GetResidue",&AtomHandle::GetResidue) .add_property("residue",&AtomHandle::GetResidue) + .def("GetChain",get_chain) + .add_property("chain",get_chain) .def("GetBondList", &AtomHandle::GetBondList) .def("GetBondCount", &AtomHandle::GetBondCount) .def("GetEntity", &AtomHandle::GetEntity) diff --git a/modules/mol/base/pymod/export_atom_view.cc b/modules/mol/base/pymod/export_atom_view.cc index e0ab17b0922d7d44cf2e65a4224d10a64861b63b..ca5d6f89285132066ae9456f886d86db51140d0c 100644 --- a/modules/mol/base/pymod/export_atom_view.cc +++ b/modules/mol/base/pymod/export_atom_view.cc @@ -26,12 +26,21 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; +namespace { + ChainView get_chain(AtomView& a) + { + return a.GetResidue().GetChain(); + } +} + void export_AtomView() { class_<AtomView, bases<AtomBase> >("AtomView", init<>()) .def("GetResidue",&AtomView::GetResidue) .add_property("residue",&AtomView::GetResidue) + .def("GetChain",get_chain) + .add_property("chain",get_chain) .def(self==self) .def(self!=self) .add_property("handle", &AtomView::GetHandle) diff --git a/modules/mol/base/pymod/export_entity_view.cc b/modules/mol/base/pymod/export_entity_view.cc index 86a4682080565c40748df9e64636f755603e6266..5e3dc12d2a9c15f10d3c4b9ce0df9a922554d16b 100644 --- a/modules/mol/base/pymod/export_entity_view.cc +++ b/modules/mol/base/pymod/export_entity_view.cc @@ -30,6 +30,17 @@ using namespace ost::mol; namespace { +template<class T> +std::vector<T> from_list(const list& seq) +{ + std::vector<T> nrvo; + for (int i = 0; i < len(seq); ++i) { + nrvo.push_back(extract<T>(seq[i])); + } + return nrvo; +} + + typedef ChainView (EntityView::*StringMethod)(const String&) const; typedef ChainView (EntityView::*StringMethod)(const String&) const; typedef EntityView (EntityView::*QueryMethod)(const Query&, uint) const; @@ -45,8 +56,21 @@ StringMethod find_chain_str=&EntityView::FindChain; QSMethod select_string=&EntityView::Select; QueryMethod select_query=&EntityView::Select; -EntityView (*create_view_1)(const AtomHandleList&)=&CreateViewFromAtomList; -EntityView (*create_view_2)(const AtomViewList&)=&CreateViewFromAtomList; +EntityView create_view(const list& seq) +{ + if(len(seq)==0) return EntityView(); + extract<AtomHandle> get_handle(seq[0]); + if(get_handle.check()) { + return CreateViewFromAtomList(from_list<AtomHandle>(seq)); + } + extract<AtomView> get_view(seq[0]); + if(get_view.check()) { + return CreateViewFromAtomList(from_list<AtomView>(seq)); + } + throw Error("expected sequence of atom handles or atom views"); + return EntityView(); +} + ResidueView (EntityView::*add_res_a)(const ResidueHandle&, ViewAddFlags)=&EntityView::AddResidue; ResidueView (EntityView::*add_res_b)(const ResidueView&, @@ -164,8 +188,7 @@ void export_EntityView() def("Difference", &Difference); def("Intersection", &Intersection); - def("CreateViewFromAtoms", create_view_1); - def("CreateViewFromAtoms", create_view_2); + def("CreateViewFromAtoms", create_view); def("CreateEntityFromView", &CreateEntityFromView, arg("handle")=EntityHandle()); diff --git a/modules/mol/base/src/view_op.cc b/modules/mol/base/src/view_op.cc index a7d7e6f6dd1b6127923457118187996f7204f999..973fa768662d38a4992874bf40917a768810d19a 100644 --- a/modules/mol/base/src/view_op.cc +++ b/modules/mol/base/src/view_op.cc @@ -250,6 +250,7 @@ mol::EntityView assemble_view(const std::vector<T>& l, mol::EntityView v) { typedef typename std::vector<T>::const_iterator Iter; for (Iter i=l.begin(), e=l.end(); i!=e; ++i) { + if(!i->IsValid()) continue; if (!belongs_to_same_ent(*i, v)) throw IntegrityError(combining_not_allowed); v.AddAtom(to_handle(*i), mol::ViewAddFlag::CHECK_DUPLICATES);