diff --git a/modules/io/doc/mmcif.rst b/modules/io/doc/mmcif.rst index 63bfd882298c4ef22dae31c1ef2d29919296863f..c4c361bda053584f6e89f9dc0c9e0342c0b68c94 100644 --- a/modules/io/doc/mmcif.rst +++ b/modules/io/doc/mmcif.rst @@ -172,7 +172,7 @@ of the annotation available. :type citation: :class:`MMCifInfoCitation` - .. method:: AddAuthorsToCitation(id, authors) + .. method:: AddAuthorsToCitation(id, authors, fault_tolerant=False) Adds a list of authors to a specific citation. @@ -180,6 +180,10 @@ of the annotation available. :type id: :class:`str` :param authors: List of authors. :type authors: :class:`~ost.StringList` + :param fault_tolerant: Logs a warning if *id* is not found and proceeds + without setting anything if set to True. Raises + otherwise. + :type fault_tolerant: :class:`bool` .. method:: GetCitations() diff --git a/modules/io/pymod/export_mmcif_io.cc b/modules/io/pymod/export_mmcif_io.cc index 954240725a665b5cce55ab3951b3375047bda253..ae6e956fa612f8b9c83575696c48abdea4b0fcc5 100644 --- a/modules/io/pymod/export_mmcif_io.cc +++ b/modules/io/pymod/export_mmcif_io.cc @@ -403,7 +403,7 @@ void export_mmcif_io() .def("GetRFree", &MMCifInfo::GetRFree) .def("SetRWork", &MMCifInfo::SetRWork) .def("GetRWork", &MMCifInfo::GetRWork) - .def("AddAuthorsToCitation", &MMCifInfo::AddAuthorsToCitation) + .def("AddAuthorsToCitation", &MMCifInfo::AddAuthorsToCitation, (arg("id"), arg("list"), arg("fault_tolerant")=false)) .def("AddOperation", &MMCifInfo::AddOperation) .def("GetOperations", make_function(&MMCifInfo::GetOperations, return_value_policy<copy_const_reference>())) diff --git a/modules/io/src/mol/mmcif_info.cc b/modules/io/src/mol/mmcif_info.cc index ce93b67789ce168b1c77eaf04105da03967c1f63..576e05912bb0073c9d93215d12ced3747353a2c8 100644 --- a/modules/io/src/mol/mmcif_info.cc +++ b/modules/io/src/mol/mmcif_info.cc @@ -19,6 +19,7 @@ #include <ost/io/io_exception.hh> #include <ost/io/mol/mmcif_info.hh> +#include <ost/log.hh> namespace ost { namespace io { @@ -76,7 +77,8 @@ String MMCifInfo::GetMMCifEntityIdTr(String cif) const return tr_it->second; } -void MMCifInfo::AddAuthorsToCitation(StringRef id, std::vector<String> list) +void MMCifInfo::AddAuthorsToCitation(StringRef id, std::vector<String> list, + bool fault_tolerant) { // find citation std::vector<MMCifInfoCitation>::iterator cit_it; @@ -88,7 +90,12 @@ void MMCifInfo::AddAuthorsToCitation(StringRef id, std::vector<String> list) } } - throw IOException("No citation for identifier '" + id.str() + "' found."); + if(fault_tolerant) { + LOG_WARNING("No citation for identifier '" + id.str() + "' found. " + "Couldn't set author list."); + } else { + throw IOException("No citation for identifier '" + id.str() + "' found."); + } } void MMCifInfo::AddBioUnit(MMCifInfoBioUnit bu) diff --git a/modules/io/src/mol/mmcif_info.hh b/modules/io/src/mol/mmcif_info.hh index 916954323af8c2cbee20eaec252a80b70117c081..351f27bc0dd60858b3a773c8953d59ba52ab9a6a 100644 --- a/modules/io/src/mol/mmcif_info.hh +++ b/modules/io/src/mol/mmcif_info.hh @@ -988,7 +988,8 @@ public: /// /// \param id identifier of the citation to be modified. /// \param list list of authors to be added. - void AddAuthorsToCitation(StringRef id, std::vector<String> list); //unit test + void AddAuthorsToCitation(StringRef id, std::vector<String> list, + bool fault_tolerant=false); //unit test /// \brief Get the list of citations stored in an info object. /// diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc index de1dbf8c6678263aecbb3a1a2ab4bb9671ac5f82..527f68fbef1e4c42ca0e32a5d918cce94c5b61d8 100644 --- a/modules/io/src/mol/mmcif_reader.cc +++ b/modules/io/src/mol/mmcif_reader.cc @@ -1844,7 +1844,8 @@ void MMCifReader::OnEndData() for (atm_it = authors_map_.begin(); atm_it != authors_map_.end(); ++atm_it) { info_.AddAuthorsToCitation(StringRef(atm_it->first.c_str(), atm_it->first.length()), - atm_it->second.second); + atm_it->second.second, + profile_.fault_tolerant); } bool found; diff --git a/modules/io/tests/test_io_mmcif.py b/modules/io/tests/test_io_mmcif.py index 20162281d3584abb31dfb024edb01c50baebe068..a1b21770993e27e37adbd15d258f99e9ce831316 100644 --- a/modules/io/tests/test_io_mmcif.py +++ b/modules/io/tests/test_io_mmcif.py @@ -1,3 +1,4 @@ +import os import unittest import subprocess import ost @@ -312,6 +313,15 @@ class TestMMCifInfo(unittest.TestCase): blinks = info.GetEntityBranchByChain('C') self.assertEqual(len(blinks), 0) + def test_mmcif_fault_tolerant_citation(self): + + p = os.path.join("testfiles", "mmcif", "AF-A0A024L8A3-F1-model_v4.cif.gz") + with self.assertRaises(Exception): + ent, seqres, info = io.LoadMMCIF(p, seqres=True, info=True) + ent, seqres, info = io.LoadMMCIF(p, seqres=True, info=True, + fault_tolerant=True) + + if __name__== '__main__': from ost import testutils testutils.RunTests() diff --git a/modules/io/tests/testfiles/mmcif/AF-A0A024L8A3-F1-model_v4.cif.gz b/modules/io/tests/testfiles/mmcif/AF-A0A024L8A3-F1-model_v4.cif.gz new file mode 100755 index 0000000000000000000000000000000000000000..b3d49495138579e3828572d2105e83197dcbbca2 Binary files /dev/null and b/modules/io/tests/testfiles/mmcif/AF-A0A024L8A3-F1-model_v4.cif.gz differ