From 378e71de8e4cfeaf9196d8cf68ac3ef192a2ac1b Mon Sep 17 00:00:00 2001
From: Stefan Bienert <stefan.bienert@unibas.ch>
Date: Wed, 5 Sep 2018 15:51:24 +0200
Subject: [PATCH] Used new cytation type handling in mmCIF reader

---
 modules/io/src/mol/mmcif_reader.cc    | 30 +++++++++++----------------
 modules/io/tests/test_mmcif_reader.cc |  6 +++---
 2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc
index 2df3966fa..1bd0011c8 100644
--- a/modules/io/src/mol/mmcif_reader.cc
+++ b/modules/io/src/mol/mmcif_reader.cc
@@ -797,31 +797,25 @@ void MMCifReader::ParseCitation(const std::vector<StringRef>& columns)
       cit.SetISBN(columns[indices_[BOOK_ID_ISBN]].str());
     }
   }
+  if (indices_[JOURNAL_ABBREV] != -1) {
+    if ((columns[indices_[JOURNAL_ABBREV]] != StringRef(".", 1)) &&
+        (columns[indices_[JOURNAL_ABBREV]][0] != '?')) {
+          cit.SetPublishedIn(columns[indices_[JOURNAL_ABBREV]].str());
+          cit.SetCitationTypeJournal();
+        }
+  }
   if (indices_[BOOK_TITLE] != -1) {
     // this is only set in few PDB entries and RCSB overrides it with
     // the journal_abbrev for their citations
     // -> as of August 1, 2017, 5 entries known: 5b1j, 5b1k, 5fax, 5fbz, 5ffn
     //    -> all those have journal_abbrev set
     if ((columns[indices_[BOOK_TITLE]] != StringRef(".", 1)) &&
-        (columns[indices_[BOOK_TITLE]][0]!='?')) {
+        (columns[indices_[BOOK_TITLE]][0] != '?')) {
+      // This will override published_in if already set by journal_abbrev. We
+      // consider this OK for now since usually the book title is copied to
+      // the journal_abbrev attribute.
       cit.SetPublishedIn(columns[indices_[BOOK_TITLE]].str());
-    }
-  }
-  if (indices_[JOURNAL_ABBREV] != -1) {
-    if (columns[indices_[JOURNAL_ABBREV]] != StringRef(".", 1)) {
-      const String journal_abbrev = columns[indices_[JOURNAL_ABBREV]].str();
-      const String published_in = cit.GetPublishedIn();
-      if (published_in.length() > 0 && published_in != journal_abbrev) {
-        LOG_WARNING(this->FormatDiagnostic(STAR_DIAG_WARNING,
-                                           "The 'published_in' field was "
-                                           "already set by citation.book_title "
-                                           "'" + published_in + "'! "
-                                           "This will be overwritten by "
-                                           "citation.journal_abbrev '" +
-                                           journal_abbrev + "'.",
-                                           this->GetCurrentLinenum()));
-      }
-      cit.SetPublishedIn(journal_abbrev);
+      cit.SetCitationTypeBook();
     }
   }
   if (indices_[JOURNAL_VOLUME] != -1) {
diff --git a/modules/io/tests/test_mmcif_reader.cc b/modules/io/tests/test_mmcif_reader.cc
index 69210a1b9..233403c61 100644
--- a/modules/io/tests/test_mmcif_reader.cc
+++ b/modules/io/tests/test_mmcif_reader.cc
@@ -598,6 +598,7 @@ BOOST_AUTO_TEST_CASE(mmcif_citation_tests)
   BOOST_CHECK_EQUAL(cit.GetID(), String("Foo"));
   BOOST_CHECK_EQUAL(cit.GetYear(), 1979);
   BOOST_CHECK_EQUAL(cit.GetPublishedIn(), String("The Guide"));
+  BOOST_CHECK_EQUAL(cit.IsCitationTypeBook(), true);
 
   // ensure that we override book_title if not properly given
   columns.pop_back();
@@ -609,8 +610,7 @@ BOOST_AUTO_TEST_CASE(mmcif_citation_tests)
   BOOST_CHECK_EQUAL(tmmcif_p.GetInfo().GetCitations().back().GetPublishedIn(),
                     String("Hitch"));
 
-  // ensure that we override book_title if journal given
-  // (def. behavior on RCSB webpage)
+  // ensure that we override journal if book_title given
   columns.pop_back();
   columns.pop_back();
   columns.push_back(StringRef("The Guide", 9));
@@ -618,7 +618,7 @@ BOOST_AUTO_TEST_CASE(mmcif_citation_tests)
 
   BOOST_CHECK_NO_THROW(tmmcif_p.ParseCitation(columns));
   BOOST_CHECK_EQUAL(tmmcif_p.GetInfo().GetCitations().back().GetPublishedIn(),
-                    String("Hitch"));
+                    String("The Guide"));
 
   BOOST_TEST_MESSAGE("  done.");
 }
-- 
GitLab