From dce93795d9049c46e289fd6140167c7653086422 Mon Sep 17 00:00:00 2001
From: Stefan Bienert <stefan.bienert@unibas.ch>
Date: Fri, 26 Feb 2016 14:58:57 +0100
Subject: [PATCH] Added InChI to comoundslib, enabled name in compoundslib

---
 modules/conop/src/compound_lib.cc     | 10 ++++++++--
 modules/io/src/mol/chemdict_parser.cc | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/modules/conop/src/compound_lib.cc b/modules/conop/src/compound_lib.cc
index 079c5e1a5..09b667b77 100644
--- a/modules/conop/src/compound_lib.cc
+++ b/modules/conop/src/compound_lib.cc
@@ -221,8 +221,14 @@ void CompoundLib::AddCompound(const CompoundPtr& compound)
     Date modi_date=compound->GetModificationDate();
     crea_date_str=crea_date.ToString();
     modi_date_str=modi_date.ToString();
-    sqlite3_bind_text(stmt, 7, crea_date_str.c_str(), crea_date_str.length(), NULL);
-    sqlite3_bind_text(stmt, 8, modi_date_str.c_str(), modi_date_str.length(), NULL);
+    sqlite3_bind_text(stmt, 7, crea_date_str.c_str(), crea_date_str.length(),
+                      NULL);
+    sqlite3_bind_text(stmt, 8, modi_date_str.c_str(), modi_date_str.length(),
+                      NULL);
+    sqlite3_bind_text(stmt, 9, compound->GetName().c_str(),
+                      compound->GetName().length(), NULL);
+    sqlite3_bind_text(stmt, 10, compound->GetInchi().c_str(),
+                      compound->GetInchi().length(), NULL);
   } else {
     LOG_ERROR(sqlite3_errmsg(conn_));
     sqlite3_finalize(stmt);
diff --git a/modules/io/src/mol/chemdict_parser.cc b/modules/io/src/mol/chemdict_parser.cc
index 3b878bbc4..841beb4b7 100644
--- a/modules/io/src/mol/chemdict_parser.cc
+++ b/modules/io/src/mol/chemdict_parser.cc
@@ -38,6 +38,11 @@ bool ChemdictParser::OnBeginLoop(const StarLoopDesc& header)
     indices_[ATOM_ID2]=header.GetIndex("atom_id_2");
     indices_[BOND_ORDER]=header.GetIndex("value_order");
     return true;
+  } else if (header.GetCategory()=="pdbx_chem_comp_descriptor") {
+    loop_type_=DESC_SPEC;
+    indices_[DESC_TYPE]=header.GetIndex("type");
+    indices_[DESC]=header.GetIndex("descriptor");
+    return true;
   }
   loop_type_=DONT_KNOW;
   return false;
@@ -68,6 +73,17 @@ void ChemdictParser::OnDataRow(const StarLoopDesc& header,
       std::swap(bond.atom_one, bond.atom_two);
     }
     compound_->AddBond(bond);
+  } else if (loop_type_==DESC_SPEC) {
+    if (columns[indices_[DESC_TYPE]] == StringRef("InChI", 5)) {
+      // for type InChi check prefix 'InChI='
+      if (columns[indices_[DESC]].substr(0, 6) != StringRef("InChI=", 6)) {
+        std::cout << "InChI problem: compound " << compound_->GetID()
+                  << " has an InChI descriptor not starting with the "
+                     "'InChI=' prefix." << std::endl;
+        return;
+      }
+      compound_->SetInchi(columns[indices_[DESC]].substr(6).str());
+    }
   }
 }
 
-- 
GitLab