From c6ff3211d1cdddb70c546156309a5e4b1353b6f2 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Mon, 2 Nov 2020 20:03:37 +0100 Subject: [PATCH] Python export for extracting secondary structure segments from ChainHandle/ChainView --- modules/mol/alg/pymod/export_sec_structure.cc | 47 +++++++++++++++++++ modules/mol/alg/pymod/wrap_mol_alg.cc | 2 + modules/mol/alg/src/sec_structure_segments.hh | 9 ++++ 3 files changed, 58 insertions(+) diff --git a/modules/mol/alg/pymod/export_sec_structure.cc b/modules/mol/alg/pymod/export_sec_structure.cc index d79dea60c..0073a2f13 100644 --- a/modules/mol/alg/pymod/export_sec_structure.cc +++ b/modules/mol/alg/pymod/export_sec_structure.cc @@ -19,8 +19,10 @@ #include <boost/python.hpp> +#include <boost/python/suite/indexing/vector_indexing_suite.hpp> #include <ost/mol/alg/sec_struct.hh> +#include <ost/mol/alg/sec_structure_segments.hh> using namespace boost::python; @@ -34,6 +36,31 @@ void AssignSecStructHandle(ost::mol::EntityHandle& handle) { ost::mol::alg::AssignSecStruct(handle); } +ost::mol::alg::SecStructureSegments +ExtractHelicalSegments_handle(const ost::mol::ChainHandle& chain) { + return ost::mol::alg::ExtractHelicalSegments(chain); +} +ost::mol::alg::SecStructureSegments +ExtractHelicalSegments_view(const ost::mol::ChainView& chain) { + return ost::mol::alg::ExtractHelicalSegments(chain); +} +ost::mol::alg::SecStructureSegments +ExtractExtendedSegments_handle(const ost::mol::ChainHandle& chain) { + return ost::mol::alg::ExtractExtendedSegments(chain); +} +ost::mol::alg::SecStructureSegments +ExtractExtendedSegments_view(const ost::mol::ChainView& chain) { + return ost::mol::alg::ExtractExtendedSegments(chain); +} +ost::mol::alg::SecStructureSegments +ExtractSecStructureSegments_handle(const ost::mol::ChainHandle& chain) { + return ost::mol::alg::ExtractSecStructureSegments(chain); +} +ost::mol::alg::SecStructureSegments +ExtractSecStructureSegments_view(const ost::mol::ChainView& chain) { + return ost::mol::alg::ExtractSecStructureSegments(chain); +} + } // ns void export_sec_struct() { @@ -41,3 +68,23 @@ void export_sec_struct() { def("AssignSecStruct", &AssignSecStructHandle, (arg("ent"))); } +void export_sec_struct_segments() { + + class_<ost::mol::alg::SecStructureSegment>("SecStructureSegment", init<int,int,ost::mol::SecStructure>()) + .def_readwrite("first", &ost::mol::alg::SecStructureSegment::first) + .def_readwrite("last", &ost::mol::alg::SecStructureSegment::last) + .def_readwrite("ss_type", &ost::mol::alg::SecStructureSegment::ss_type) + ; + + class_<ost::mol::alg::SecStructureSegments>("SecStructureSegments", init<>()) + .def(vector_indexing_suite<ost::mol::alg::SecStructureSegments>()) + ; + + def("ExtractHelicalSegments", &ExtractHelicalSegments_handle, (arg("chain"))); + def("ExtractHelicalSegments", &ExtractHelicalSegments_view, (arg("chain"))); + def("ExtractExtendedSegments", &ExtractExtendedSegments_handle, (arg("chain"))); + def("ExtractExtendedSegments", &ExtractExtendedSegments_view, (arg("chain"))); + def("ExtractSecStructureSegments", &ExtractSecStructureSegments_handle, (arg("chain"))); + def("ExtractSecStructureSegments", &ExtractSecStructureSegments_view, (arg("chain"))); +} + diff --git a/modules/mol/alg/pymod/wrap_mol_alg.cc b/modules/mol/alg/pymod/wrap_mol_alg.cc index d36877c0f..265df5dfd 100644 --- a/modules/mol/alg/pymod/wrap_mol_alg.cc +++ b/modules/mol/alg/pymod/wrap_mol_alg.cc @@ -47,6 +47,7 @@ void export_Molck(); void export_contact_overlap(); void export_accessibility(); void export_sec_struct(); +void export_sec_struct_segments(); void export_find_membrane(); #if OST_IMG_ENABLED void export_entity_to_density(); @@ -319,6 +320,7 @@ BOOST_PYTHON_MODULE(_ost_mol_alg) export_contact_overlap(); export_accessibility(); export_sec_struct(); + export_sec_struct_segments(); export_find_membrane(); #if OST_IMG_ENABLED export_entity_to_density(); diff --git a/modules/mol/alg/src/sec_structure_segments.hh b/modules/mol/alg/src/sec_structure_segments.hh index 958c28520..dc906c075 100644 --- a/modules/mol/alg/src/sec_structure_segments.hh +++ b/modules/mol/alg/src/sec_structure_segments.hh @@ -35,6 +35,15 @@ struct DLLEXPORT_OST_MOL_ALG SecStructureSegment { SecStructureSegment(): first(0), last(0), ss_type(SecStructure::COIL) { } + bool operator==(const SecStructureSegment& rhs) const + { + return first==rhs.first && last==rhs.last && ss_type==rhs.ss_type; + } + bool operator!=(const SecStructureSegment& rhs) const + { + return !(*this==rhs); + } + /// \brief index of first residue part of the segment int first; /// \brief index of last residue part of the segment -- GitLab