diff --git a/modules/io/doc/mmcif.rst b/modules/io/doc/mmcif.rst index a2111f546d866d16bd91b9374b62538a23a192c8..924065a11323616a5466429d32b8be6aecdef7b6 100644 --- a/modules/io/doc/mmcif.rst +++ b/modules/io/doc/mmcif.rst @@ -1246,6 +1246,12 @@ of the annotation available. :type editor: :class:`~ost.mol.XCSEditor` :returns: Nothing + .. method:: GetEntityBranchChainNames + + Get a list of chain names which contain branched entities. + + :returns: :class:`list` od :class:`str` + .. method:: GetAtom1 See :attr:`atom1` diff --git a/modules/io/pymod/export_mmcif_io.cc b/modules/io/pymod/export_mmcif_io.cc index b8dae1b0509e0e13fc081f52d3456555bf350324..f64403548ec74202fa11ed6a89d85e795b7fd9bd 100644 --- a/modules/io/pymod/export_mmcif_io.cc +++ b/modules/io/pymod/export_mmcif_io.cc @@ -30,6 +30,20 @@ using namespace ost; using namespace ost::io; using namespace ost::mol; +template<typename T> +boost::python::list VecToList(std::vector<T>& vec){ + boost::python::list l; + for(typename std::vector<T>::iterator it=vec.begin();it!=vec.end();++it){ + l.append(*it); + } + return l; +} + +boost::python::list WrapGetNames(MMCifInfo *p){ + std::vector<String> names = p->GetEntityBranchChainNames(); + return VecToList<String>(names); +} + void export_mmcif_io() { class_<MMCifReader, boost::noncopyable>("MMCifReader", init<const String&, EntityHandle&, const IOProfile&>()) @@ -400,6 +414,7 @@ void export_mmcif_io() .def("AddEntityBranchLink", &MMCifInfo::AddEntityBranchLink) .def("GetEntityBranchLinks", &MMCifInfo::GetEntityBranchLinks) .def("ConnectBranchLinks", &MMCifInfo::ConnectBranchLinks) + .def("GetEntityBranchChainNames", &WrapGetNames) .add_property("citations", make_function(&MMCifInfo::GetCitations, return_value_policy<copy_const_reference>())) .add_property("biounits", make_function(&MMCifInfo::GetBioUnits, diff --git a/modules/io/src/mol/mmcif_info.cc b/modules/io/src/mol/mmcif_info.cc index 5db86d1cc86144d3cdeadb221b62ed2b241bebe4..1fb5ee93dc7e56b3006ef58eb3220f622f69e027 100644 --- a/modules/io/src/mol/mmcif_info.cc +++ b/modules/io/src/mol/mmcif_info.cc @@ -227,6 +227,17 @@ const std::vector<MMCifInfoEntityBranchLink> MMCifInfo::GetEntityBranchLinks() c return all_links; } +const std::vector<String> MMCifInfo::GetEntityBranchChainNames() const +{ + std::vector<String> chain_names; + MMCifInfoEntityBranchLinkMap::const_iterator blm_it; + for (blm_it = entity_branches_.begin(); + blm_it != entity_branches_.end(); ++blm_it) { + chain_names.push_back(blm_it->first); + } + return chain_names; +} + void MMCifInfo::ConnectBranchLinks() { MMCifInfoEntityBranchLinkMap::iterator blm_it; diff --git a/modules/io/src/mol/mmcif_info.hh b/modules/io/src/mol/mmcif_info.hh index 76d418147a5e5a173f7d5913160793f8489c4432..510365d4956668fcbdf817a6568c0ba457e877e8 100644 --- a/modules/io/src/mol/mmcif_info.hh +++ b/modules/io/src/mol/mmcif_info.hh @@ -1180,6 +1180,11 @@ public: /// \brief Get all links for all branched entities /// const std::vector<MMCifInfoEntityBranchLink> GetEntityBranchLinks() const; + + /// \brief Get the names of all chains of branched entities. + /// + const std::vector<String> GetEntityBranchChainNames() const; + //GetEntityBranchChains //GetEntityBranchByChain diff --git a/modules/io/tests/test_io_mmcif.py b/modules/io/tests/test_io_mmcif.py index d0f902ac48aa8b2ad744a8c189c8a96009703acd..ad16f55e10251670decc43078a74806fbe8668ac 100644 --- a/modules/io/tests/test_io_mmcif.py +++ b/modules/io/tests/test_io_mmcif.py @@ -300,6 +300,9 @@ class TestMMCifInfo(unittest.TestCase): info.ConnectBranchLinks() self.assertEqual(atom4.GetBondPartners()[0].qualified_name, "B.NAG2.C1") + chain_names = info.GetEntityBranchChainNames() + self.assertEqual(chain_names, ['A', 'B']) + if __name__== '__main__': from ost import testutils testutils.RunTests() diff --git a/modules/io/tests/test_mmcif_info.cc b/modules/io/tests/test_mmcif_info.cc index 0ab74afb94bb1c3056bdf1042a9b2c1b36f5b67c..7c5db68eea71478eaf58f90b5bd5106952a44939 100644 --- a/modules/io/tests/test_mmcif_info.cc +++ b/modules/io/tests/test_mmcif_info.cc @@ -352,7 +352,7 @@ BOOST_AUTO_TEST_CASE(mmcif_info) info.AddEntityBranchLink(ch1.GetName(), atom11, atom12, 1); info.AddEntityBranchLink(ch2.GetName(), atom21, atom22, 1); std::vector<MMCifInfoEntityBranchLink> blinks = info.GetEntityBranchLinks(); - + BOOST_CHECK(blinks.size() == 2); BOOST_CHECK(blinks[0].GetAtom1().GetQualifiedName() == "A.NAG2.C1"); BOOST_CHECK(blinks[0].GetAtom2().GetQualifiedName() == "A.NAG1.O4"); @@ -367,6 +367,11 @@ BOOST_AUTO_TEST_CASE(mmcif_info) BOOST_CHECK(atom11.GetBondPartners()[0] == atom12); BOOST_CHECK(atom22.GetBondPartners()[0] == atom21); + // check chain(name) retrieval works + std::vector<String> chain_names = info.GetEntityBranchChainNames(); + BOOST_CHECK(chain_names[0] == "A"); + BOOST_CHECK(chain_names[1] == "B"); + BOOST_TEST_MESSAGE(" done."); }