From 4626551395b91ed6d581b90663e4284b1022c8b4 Mon Sep 17 00:00:00 2001 From: B13nch3n <stefan.bienert@me.com> Date: Wed, 22 Jul 2020 09:45:21 +0200 Subject: [PATCH] SCHWED-4849: Allow to get branched entity information for a specific chain --- modules/io/doc/mmcif.rst | 44 +++++++++++++++++++---------- modules/io/pymod/export_mmcif_io.cc | 1 + modules/io/src/mol/mmcif_info.cc | 12 ++++++++ modules/io/src/mol/mmcif_info.hh | 10 +++++-- modules/io/src/mol/mmcif_reader.hh | 3 +- modules/io/tests/test_io_mmcif.py | 6 ++++ modules/io/tests/test_mmcif_info.cc | 7 +++++ 7 files changed, 64 insertions(+), 19 deletions(-) diff --git a/modules/io/doc/mmcif.rst b/modules/io/doc/mmcif.rst index 2a9bccd2e..510cd7d45 100644 --- a/modules/io/doc/mmcif.rst +++ b/modules/io/doc/mmcif.rst @@ -52,7 +52,8 @@ The following categories of a mmCIF file are considered by the reader: (mmCIF dictionary version >= 5) used to fill :class:`MMCifInfoRevisions` * ``pdbx_entity_branch`` and ``pdbx_entity_branch_link`` used for :class:`MMCifInfoEntityBranchLink`, a list of links is available by - :meth:`~MMCifInfo.GetEntityBranchLinks` + :meth:`~MMCifInfo.GetEntityBranchLinks` and + :meth:`~MMCifInfo.GetEntityBranchByChain` Notes: @@ -313,6 +314,18 @@ of the annotation available. information is available by the stored :class:`AtomHandles <ost.mol.AtomHandle>` of each entry. + :returns: :class:`list` of :class:`MMCifInfoEntityBranchLink` + + .. method:: GetEntityBranchByChain(chain_name) + + Get bond information for chains with branched entities. Returns all + :class:`MMCifInfoEntityBranchLink` objects in one list if chain is a + branched entity, an empty list otherwise. + + :param chain_name: Chain name to check for branch links + :type chain_name: :class:`str` + :returns: :class:`list` of :class:`MMCifInfoEntityBranchLink` + .. method:: AddEntityBranchLink(chain_name, atom1, atom2, bond_order) Add bond information for a branched entity. @@ -327,7 +340,19 @@ of the annotation available. :type bond_order: :class:`int` :returns: Nothing - .. method:: ConnectBranchLinks() + .. method:: GetEntityBranchChainNames + + Get a list of chain names which contain branched entities. + + :returns: :class:`list` of :class:`str` + + .. method:: GetEntityBranchChains + + Get a list of chains which contain branched entities. + + :returns: :class:`list` of :class:`~ost.mol.ChainHandle` + + .. method:: ConnectBranchLinks Establish all bonds stored for branched entities. @@ -1246,18 +1271,6 @@ 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` of :class:`str` - - .. method:: GetEntityBranchChains - - Get a list of chains which contain branched entities. - - :returns: :class:`list` of :class:`~ost.mol.ChainHandle` - .. method:: GetAtom1 See :attr:`atom1` @@ -1286,7 +1299,7 @@ of the annotation available. .. LocalWords: SPRSDE pdb func autofunction exptl attr pdbx oper conf spr dif .. LocalWords: biounits biounit uniprot UNP seqs AddMMCifPDBChainTr cif asym .. LocalWords: auth GetMMCifPDBChainTr AddPDBCMMCifhainTr GetPDBMMCifChainTr -.. LocalWords: GetRevisions AddRevision SetRevisionsDateOriginal GetSize +.. LocalWords: GetRevisions AddRevision SetRevisionsDateOriginal GetSize str .. LocalWords: GetNum num GetStatus GetLastDate GetFirstRelease storable .. LocalWords: cas isbn pubmed asu seqres conop casp COMPND OBSLTE LoadMMCIF .. LocalWords: SetChainList MMCifInfoTransOp ChainTypes MMCifInfoStructRef @@ -1295,3 +1308,4 @@ of the annotation available. .. LocalWords: chainintervalls GetChainIntervalList GetMethodDetails GetAtom .. LocalWords: GetOperationsIntervalList SetMethodDetails oligosaccharides .. LocalWords: SetAtom GetBondOrder SetBondOrder MMCifInfoEntityBranchLink +.. LocalWords: GetEntityBranchByChain param diff --git a/modules/io/pymod/export_mmcif_io.cc b/modules/io/pymod/export_mmcif_io.cc index ea953160f..11223672c 100644 --- a/modules/io/pymod/export_mmcif_io.cc +++ b/modules/io/pymod/export_mmcif_io.cc @@ -413,6 +413,7 @@ void export_mmcif_io() .def("GetRevisions", &MMCifInfo::GetRevisions) .def("AddEntityBranchLink", &MMCifInfo::AddEntityBranchLink) .def("GetEntityBranchLinks", &MMCifInfo::GetEntityBranchLinks) + .def("GetEntityBranchByChain", &MMCifInfo::GetEntityBranchByChain) .def("ConnectBranchLinks", &MMCifInfo::ConnectBranchLinks) .def("GetEntityBranchChainNames", &WrapGetNames) .def("GetEntityBranchChains", &MMCifInfo::GetEntityBranchChains) diff --git a/modules/io/src/mol/mmcif_info.cc b/modules/io/src/mol/mmcif_info.cc index 62ea686e6..ce93b6778 100644 --- a/modules/io/src/mol/mmcif_info.cc +++ b/modules/io/src/mol/mmcif_info.cc @@ -227,6 +227,18 @@ const std::vector<MMCifInfoEntityBranchLink> MMCifInfo::GetEntityBranchLinks() c return all_links; } +const std::vector<MMCifInfoEntityBranchLink> MMCifInfo::GetEntityBranchByChain( + const String& chain_name) const +{ + // search the requested chain + MMCifInfoEntityBranchLinkMap::const_iterator blm_it = + entity_branches_.find(chain_name); + if (blm_it != entity_branches_.end()) { + return blm_it->second; + } + return std::vector<MMCifInfoEntityBranchLink>(); +} + const std::vector<String> MMCifInfo::GetEntityBranchChainNames() const { std::vector<String> chain_names; diff --git a/modules/io/src/mol/mmcif_info.hh b/modules/io/src/mol/mmcif_info.hh index bebccefa0..b97949105 100644 --- a/modules/io/src/mol/mmcif_info.hh +++ b/modules/io/src/mol/mmcif_info.hh @@ -1181,15 +1181,19 @@ public: /// const std::vector<MMCifInfoEntityBranchLink> GetEntityBranchLinks() const; + /// \brief Check if a chain is a branched entity and return it + /// + /// \param chain_name Name of the chain to check + const std::vector<MMCifInfoEntityBranchLink> GetEntityBranchByChain( + const String& chain_name) const; + /// \brief Get the names of all chains of branched entities. /// const std::vector<String> GetEntityBranchChainNames() const; /// \brief Get the all chains of branched entities. /// -const mol::ChainHandleList GetEntityBranchChains() const; - - //GetEntityBranchByChain + const mol::ChainHandleList GetEntityBranchChains() const; /// \brief Connect all atoms listed as links for branched entities. /// diff --git a/modules/io/src/mol/mmcif_reader.hh b/modules/io/src/mol/mmcif_reader.hh index 03ceb32c9..c6e2e32fd 100644 --- a/modules/io/src/mol/mmcif_reader.hh +++ b/modules/io/src/mol/mmcif_reader.hh @@ -631,7 +631,8 @@ private: /// \brief Get an iterator for MMCifEntityDescMap by finding an element or /// inserting a new one into the map. - MMCifEntityDescMap::iterator GetEntityDescMapIterator(const String&); + /// \param entity_id ID of the entity to talk to + MMCifEntityDescMap::iterator GetEntityDescMapIterator(const String& entity_id); /// \struct assembly information typedef struct { diff --git a/modules/io/tests/test_io_mmcif.py b/modules/io/tests/test_io_mmcif.py index 0da0a4c2e..20162281d 100644 --- a/modules/io/tests/test_io_mmcif.py +++ b/modules/io/tests/test_io_mmcif.py @@ -306,6 +306,12 @@ class TestMMCifInfo(unittest.TestCase): self.assertEqual(chains[0].name, 'A') self.assertEqual(chains[1].name, 'B') + blinks = info.GetEntityBranchByChain('B') + self.assertEqual(len(blinks), 1) + self.assertEqual(blinks[0].atom1.qualified_name, "B.NAG2.C1") + blinks = info.GetEntityBranchByChain('C') + self.assertEqual(len(blinks), 0) + 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 a2b78b054..5370d2ce1 100644 --- a/modules/io/tests/test_mmcif_info.cc +++ b/modules/io/tests/test_mmcif_info.cc @@ -377,6 +377,13 @@ BOOST_AUTO_TEST_CASE(mmcif_info) BOOST_CHECK(chains[0].GetName() == "A"); BOOST_CHECK(chains[1].GetName() == "B"); + // check retrieval of links by chain name + std::vector<MMCifInfoEntityBranchLink> cblinks = + info.GetEntityBranchByChain("A"); + BOOST_CHECK(cblinks.size() == 1); + cblinks = info.GetEntityBranchByChain("C"); + BOOST_CHECK(cblinks.size() == 0); + BOOST_TEST_MESSAGE(" done."); } -- GitLab