diff --git a/modules/conop/src/compound_lib.cc b/modules/conop/src/compound_lib.cc index 508c31bd68f6453875a7f9128cabafeaa3f67b96..e2cf22263aa88071b425f686cd0d7a9666ef112c 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 fef48b1a766899cff3e4097fe68e70a0031291b8..8b6c444868de16503e4d2d37fd22297d467e3d3c 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_; };