From b52e85cf1992b0d2bf3eed219b3d0695feba7a3e Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Fri, 26 Feb 2016 17:01:43 +0100 Subject: [PATCH] Retrieve InChIs via FindCompound in C++ --- modules/conop/src/compound_lib.cc | 23 +++++++++++++++++++++++ modules/conop/src/compound_lib.hh | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/modules/conop/src/compound_lib.cc b/modules/conop/src/compound_lib.cc index 508c31bd6..e2cf22263 100644 --- a/modules/conop/src/compound_lib.cc +++ b/modules/conop/src/compound_lib.cc @@ -366,6 +366,12 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly) static_cast<int>(aq.length()), &stmt, NULL); lib->name_available_ = retval==SQLITE_OK; + // check if InChIs are available + aq="SELECT inchi_code FROM chem_compounds LIMIT 1"; + retval=sqlite3_prepare_v2(lib->conn_, aq.c_str(), + static_cast<int>(aq.length()), + &stmt, NULL); + lib->inchi_available_ = retval==SQLITE_OK; lib->creation_date_ = lib->GetCreationDate(); lib->ost_version_used_ = lib->GetOSTVersionUsed(); @@ -432,12 +438,18 @@ CompoundPtr CompoundLib::FindCompound(const String& id, return i->second; } String query="SELECT id, tlc, olc, chem_class, dialect, formula"; + int col_offset = 0; if(chem_type_available_) { query+=", chem_type"; + col_offset+=1; if(name_available_) { query+=", name"; + col_offset+=1; } } + if(inchi_available_) { + query+=", inchi_code, inchi_key"; + } query+=" FROM chem_compounds" " WHERE tlc='"+id+"' AND dialect='"+String(1, char(dialect))+"'"; @@ -469,6 +481,16 @@ CompoundPtr CompoundLib::FindCompound(const String& id, compound->SetName(name); } } + if (inchi_available_) { + const char* inchi_code=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6+col_offset)); + if (inchi_code) { + compound->SetInchi(inchi_code); + } + const char* inchi_key=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6+col_offset+1)); + if (inchi_key) { + compound->SetInchiKey(inchi_key); + } + } // Load atoms and bonds this->LoadAtomsFromDB(compound, pk); this->LoadBondsFromDB(compound, pk); @@ -492,6 +514,7 @@ CompoundLib::CompoundLib(): conn_(NULL), chem_type_available_(false), name_available_(), + inchi_available_(), creation_date_(), ost_version_used_() { diff --git a/modules/conop/src/compound_lib.hh b/modules/conop/src/compound_lib.hh index fef48b1a7..8b6c44486 100644 --- a/modules/conop/src/compound_lib.hh +++ b/modules/conop/src/compound_lib.hh @@ -57,8 +57,9 @@ private: private: mutable CompoundMap compound_cache_; sqlite3* conn_; - bool chem_type_available_; // weather pdbx_type is available in db - bool name_available_; // weather name is available in db + bool chem_type_available_; // wether pdbx_type is available in db + bool name_available_; // wether name is available in db + bool inchi_available_; //whether inchi is available in db Date creation_date_; String ost_version_used_; }; -- GitLab