Skip to content
Snippets Groups Projects
Verified Commit 812e856c authored by Xavier Robin's avatar Xavier Robin
Browse files

refactor: explicitly drop pre-1.5.0 compound libs

parent ee7f24e8
No related branches found
No related tags found
No related merge requests found
...@@ -11,13 +11,13 @@ information for the :class:`rule-based processor <RuleBasedBuilder>`. ...@@ -11,13 +11,13 @@ information for the :class:`rule-based processor <RuleBasedBuilder>`.
The compound definitions for standard PDB files are taken from the The compound definitions for standard PDB files are taken from the
components.cif dictionary provided by the PDB. The dictionary is updated with components.cif dictionary provided by the PDB. The dictionary is updated with
every PDB release and augmented with the compound definitions of newly every PDB release and augmented with the compound definitions of newly
crystallized compounds. crystallized compounds. Follow :ref:`these instructions <mmcif-convert>` to
build the compound library.
If you downloaded the bundle, a recent version of the compound library is
already included. If you are compiling from source or want to incorporate the
latest compound definitions, follow :ref:`these instructions <mmcif-convert>` to
build the compound library manually.
In general, compound libraries built with older versions of OST are compatible
with newer version of OST, so it may not be necessary to rebuild a new one.
However, some functionality may not be available. Currently, compound libraries
built with OST 1.5.0 or later can be loaded.
.. function:: GetDefaultLib() .. function:: GetDefaultLib()
......
...@@ -36,6 +36,11 @@ namespace ost { namespace conop { ...@@ -36,6 +36,11 @@ namespace ost { namespace conop {
namespace { namespace {
/*
This is the oldest version (GetCreationDate) of compound libraries we support.
*/
const String COMPAT_VERSION = "1.5.0";
/* /*
COMMENT ON CREATE_CMD COMMENT ON CREATE_CMD
...@@ -390,27 +395,9 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly) ...@@ -390,27 +395,9 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly)
LOG_ERROR(sqlite3_errmsg(lib->db_->ptr)); LOG_ERROR(sqlite3_errmsg(lib->db_->ptr));
return CompoundLibPtr(); return CompoundLibPtr();
} }
// check if column chem_type exists in database String aq;
String aq="SELECT chem_type FROM chem_compounds LIMIT 1";
sqlite3_stmt* stmt; sqlite3_stmt* stmt;
retval=sqlite3_prepare_v2(lib->db_->ptr, aq.c_str(), std::stringstream ss;
static_cast<int>(aq.length()),
&stmt, NULL);
lib->chem_type_available_ = retval==SQLITE_OK;
sqlite3_finalize(stmt);
aq="SELECT name FROM chem_compounds LIMIT 1";
retval=sqlite3_prepare_v2(lib->db_->ptr, aq.c_str(),
static_cast<int>(aq.length()),
&stmt, NULL);
lib->name_available_ = retval==SQLITE_OK;
sqlite3_finalize(stmt);
// check if InChIs are available
aq="SELECT inchi_code FROM chem_compounds LIMIT 1";
retval=sqlite3_prepare_v2(lib->db_->ptr, aq.c_str(),
static_cast<int>(aq.length()),
&stmt, NULL);
lib->inchi_available_ = retval==SQLITE_OK;
sqlite3_finalize(stmt);
// check if SMILES are available // check if SMILES are available
aq="SELECT smiles FROM chem_compounds LIMIT 1"; aq="SELECT smiles FROM chem_compounds LIMIT 1";
retval=sqlite3_prepare_v2(lib->db_->ptr, aq.c_str(), retval=sqlite3_prepare_v2(lib->db_->ptr, aq.c_str(),
...@@ -429,6 +416,13 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly) ...@@ -429,6 +416,13 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly)
lib->creation_date_ = lib->GetCreationDate(); lib->creation_date_ = lib->GetCreationDate();
lib->ost_version_used_ = lib->GetOSTVersionUsed(); lib->ost_version_used_ = lib->GetOSTVersionUsed();
if (lib->ost_version_used_.compare(COMPAT_VERSION) < 0) {
ss << "Compound lib was created with an unsupported version of OST: "
<< lib->ost_version_used_
<< ". Please update your compound library.";
throw ost::Error(ss.str());
}
return lib; return lib;
} }
...@@ -498,23 +492,7 @@ CompoundPtr CompoundLib::FindCompound(const String& id, ...@@ -498,23 +492,7 @@ CompoundPtr CompoundLib::FindCompound(const String& id,
if (i!=compound_cache_.end()) { if (i!=compound_cache_.end()) {
return i->second; return i->second;
} }
String query="SELECT id, tlc, olc, chem_class, dialect, formula"; String query="SELECT id, tlc, olc, chem_class, dialect, formula, chem_type, name, inchi_code, inchi_key";
int col_offset_inchi = 0;
int col_offset_smiles = 0;
if(chem_type_available_) {
query+=", chem_type";
col_offset_inchi+=1;
col_offset_smiles+=1;
if(name_available_) {
query+=", name";
col_offset_inchi+=1;
col_offset_smiles+=1;
}
}
if(inchi_available_) {
query+=", inchi_code, inchi_key";
col_offset_smiles+=2;
}
if(smiles_available_) { if(smiles_available_) {
query+=", smiles"; query+=", smiles";
} }
...@@ -540,27 +518,19 @@ CompoundPtr CompoundLib::FindCompound(const String& id, ...@@ -540,27 +518,19 @@ CompoundPtr CompoundLib::FindCompound(const String& id,
compound->SetDialect(Compound::Dialect(sqlite3_column_text(stmt, 4)[0])); compound->SetDialect(Compound::Dialect(sqlite3_column_text(stmt, 4)[0]));
const char* f=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 5)); const char* f=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 5));
compound->SetFormula(f); compound->SetFormula(f);
if(chem_type_available_) { compound->SetChemType(mol::ChemType(sqlite3_column_text(stmt, 6)[0]));
compound->SetChemType(mol::ChemType(sqlite3_column_text(stmt, 6)[0])); const char* name=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 7));
} compound->SetName(name);
if (name_available_) { const char* inchi_code=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 8));
const char* name=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 7)); if (inchi_code) {
if (name) { compound->SetInchi(inchi_code);
compound->SetName(name);
}
} }
if (inchi_available_) { const char* inchi_key=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 9));
const char* inchi_code=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6+col_offset_inchi)); if (inchi_key) {
if (inchi_code) { compound->SetInchiKey(inchi_key);
compound->SetInchi(inchi_code);
}
const char* inchi_key=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6+col_offset_inchi+1));
if (inchi_key) {
compound->SetInchiKey(inchi_key);
}
} }
if (smiles_available_) { if (smiles_available_) {
const char* smiles=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6+col_offset_smiles)); const char* smiles=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 10));
if (smiles) { if (smiles) {
compound->SetSMILES(smiles); compound->SetSMILES(smiles);
} }
...@@ -587,9 +557,6 @@ CompoundLib::CompoundLib(): ...@@ -587,9 +557,6 @@ CompoundLib::CompoundLib():
CompoundLibBase(), CompoundLibBase(),
db_(new Database), db_(new Database),
compound_cache_(), compound_cache_(),
chem_type_available_(false),
name_available_(),
inchi_available_(),
smiles_available_(), smiles_available_(),
charges_available_(), charges_available_(),
creation_date_(), creation_date_(),
......
...@@ -55,11 +55,8 @@ private: ...@@ -55,11 +55,8 @@ private:
struct Database; struct Database;
Database* db_; Database* db_;
mutable CompoundMap compound_cache_; mutable CompoundMap compound_cache_;
bool chem_type_available_; // wether pdbx_type is available in db bool smiles_available_; //whether smiles are available in db - introduced in 2.6.0
bool name_available_; // wether name is available in db bool charges_available_; //whether atom charges are available in db - introduced in 2.6.0
bool inchi_available_; //whether inchi is available in db
bool smiles_available_; //whether smiles are available in db
bool charges_available_; //whether atom charges are available in db
Date creation_date_; Date creation_date_;
String ost_version_used_; 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