Skip to content
Snippets Groups Projects
Commit b52e85cf authored by Bienchen's avatar Bienchen
Browse files

Retrieve InChIs via FindCompound in C++

parent 0419848b
No related branches found
No related tags found
No related merge requests found
......@@ -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_()
{
......
......@@ -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_;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment