From e8db20b697ceb79accea34d6d7041951e3670931 Mon Sep 17 00:00:00 2001
From: Gerardo Tauriello <gerardo.tauriello@unibas.ch>
Date: Mon, 10 Sep 2018 11:07:42 +0200
Subject: [PATCH] mmCIF reader fix: removed restrictions on data block
 identifier.

---
 modules/io/src/mol/mmcif_reader.cc    | 16 +---------------
 modules/io/src/mol/mmcif_reader.hh    | 10 +---------
 modules/io/tests/test_mmcif_reader.cc | 24 ------------------------
 3 files changed, 2 insertions(+), 48 deletions(-)

diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc
index 905e28442..b473c96ca 100644
--- a/modules/io/src/mol/mmcif_reader.cc
+++ b/modules/io/src/mol/mmcif_reader.cc
@@ -97,26 +97,12 @@ void MMCifReader::SetRestrictChains(const String& restrict_chains)
   restrict_chains_ = restrict_chains;
 }
 
-bool MMCifReader::IsValidPDBIdent(const StringRef& pdbid)
-{
-  if (pdbid.length() == PDBID_LEN && isdigit(pdbid[0])) {
-    return true;
-  }
-  return false;
-}
-
 bool MMCifReader::OnBeginData(const StringRef& data_name) 
 {
   LOG_DEBUG("MCIFFReader: " << profile_);
   Profile profile_import("MMCifReader::OnBeginData");
 
-  // check for PDB id
-  if (!this->IsValidPDBIdent(data_name)) {
-    throw IOException(this->FormatDiagnostic(STAR_DIAG_ERROR,
-                         "No valid PDB id found for data block, read instead \'"
-                                             + data_name.str() + "\'",
-                                             this->GetCurrentLinenum()));
-  }
+  // IDs in mmCIF files can be any string, so no restrictions here
 
   this->ClearState();
 
diff --git a/modules/io/src/mol/mmcif_reader.hh b/modules/io/src/mol/mmcif_reader.hh
index edd249f38..163972b60 100644
--- a/modules/io/src/mol/mmcif_reader.hh
+++ b/modules/io/src/mol/mmcif_reader.hh
@@ -187,13 +187,6 @@ protected:
      }
   } // tested
 
-  /// \brief Check a PDB id to be of length 4 and start with a digit
-  ///
-  /// \param pdbid putative PDB id
-  ///
-  /// \return true for a valid id, false otherwise
-  bool IsValidPDBIdent(const StringRef& pdbid);
-
   /// \brief fetch values identifying atoms
   ///
   /// \param[in]  columns data row
@@ -353,8 +346,7 @@ protected:
 private:
   /// \enum magic numbers of this class
   typedef enum {
-    PDBID_LEN=4,         ///< length of a PDB id
-    MAX_ITEMS_IN_ROW=18, ///< count for possible items in a loop row
+    MAX_ITEMS_IN_ROW=18 ///< count for possible items in a loop row
   } MMCifMagicNos;
 
   /// \enum items of the atom_site category
diff --git a/modules/io/tests/test_mmcif_reader.cc b/modules/io/tests/test_mmcif_reader.cc
index 69210a1b9..e4129c2ab 100644
--- a/modules/io/tests/test_mmcif_reader.cc
+++ b/modules/io/tests/test_mmcif_reader.cc
@@ -51,7 +51,6 @@ public:
 
   using MMCifReader::OnBeginLoop;
   using MMCifReader::OnEndData;
-  using MMCifReader::IsValidPDBIdent;
   using MMCifReader::ParseAtomIdent;
   using MMCifReader::ParseAndAddAtom;
   using MMCifReader::ParseEntity;
@@ -113,29 +112,6 @@ conop::CompoundLibPtr SetDefaultCompoundLib() {
 
 BOOST_AUTO_TEST_SUITE( io );
 
-BOOST_AUTO_TEST_CASE(mmcif_isvalidpdbident)
-{
-  mol::EntityHandle eh=mol::CreateEntity();
-
-  // on changing the tests for a PDB id in mmcif files, extend this unit test
-  BOOST_TEST_MESSAGE("  Running mmcif_isvalidpdbident tests...");
-  std::ifstream s("testfiles/mmcif/atom_site.mmcif");
-  TestMMCifReaderProtected tmmcif_p(s, eh);
-  StringRef id = StringRef("1FOO", 4);
-  BOOST_TEST_MESSAGE("    Testing valid id ('"+ id.str() +"')...");
-  BOOST_CHECK(tmmcif_p.IsValidPDBIdent(id));
-  BOOST_TEST_MESSAGE("    done.");
-  id = StringRef("this is to long for a PDB id", 28);
-  BOOST_TEST_MESSAGE("    Testing oversized PDB id ('"+ id.str() +"')...");
-  BOOST_CHECK(!tmmcif_p.IsValidPDBIdent(id));
-  BOOST_TEST_MESSAGE("    done.");
-  id = StringRef("nFOO", 4);
-  BOOST_TEST_MESSAGE("    Testing PDB id with missing number ('"
-                     + id.str() + "')...");
-  BOOST_CHECK(!tmmcif_p.IsValidPDBIdent(id));
-  BOOST_TEST_MESSAGE("    done.");
-}
-
 BOOST_AUTO_TEST_CASE(mmcif_trystoreidx)
 {
   mol::EntityHandle eh = mol::CreateEntity();
-- 
GitLab