From 812e856c7672fe41790d4e8b31510b963f793006 Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavier.robin@unibas.ch> Date: Wed, 26 Jul 2023 10:37:33 +0200 Subject: [PATCH] refactor: explicitly drop pre-1.5.0 compound libs --- modules/conop/doc/compoundlib.rst | 12 ++--- modules/conop/src/compound_lib.cc | 83 ++++++++++--------------------- modules/conop/src/compound_lib.hh | 7 +-- 3 files changed, 33 insertions(+), 69 deletions(-) diff --git a/modules/conop/doc/compoundlib.rst b/modules/conop/doc/compoundlib.rst index 539096827..fcad2af47 100644 --- a/modules/conop/doc/compoundlib.rst +++ b/modules/conop/doc/compoundlib.rst @@ -11,13 +11,13 @@ information for the :class:`rule-based processor <RuleBasedBuilder>`. The compound definitions for standard PDB files are taken from the components.cif dictionary provided by the PDB. The dictionary is updated with every PDB release and augmented with the compound definitions of newly -crystallized compounds. - -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. +crystallized compounds. Follow :ref:`these instructions <mmcif-convert>` to +build the compound library. +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() diff --git a/modules/conop/src/compound_lib.cc b/modules/conop/src/compound_lib.cc index 816521f53..094eb454a 100644 --- a/modules/conop/src/compound_lib.cc +++ b/modules/conop/src/compound_lib.cc @@ -36,6 +36,11 @@ namespace ost { namespace conop { namespace { +/* +This is the oldest version (GetCreationDate) of compound libraries we support. +*/ +const String COMPAT_VERSION = "1.5.0"; + /* COMMENT ON CREATE_CMD @@ -390,27 +395,9 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly) LOG_ERROR(sqlite3_errmsg(lib->db_->ptr)); return CompoundLibPtr(); } - // check if column chem_type exists in database - String aq="SELECT chem_type FROM chem_compounds LIMIT 1"; + String aq; sqlite3_stmt* stmt; - retval=sqlite3_prepare_v2(lib->db_->ptr, aq.c_str(), - 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); + std::stringstream ss; // check if SMILES are available aq="SELECT smiles FROM chem_compounds LIMIT 1"; retval=sqlite3_prepare_v2(lib->db_->ptr, aq.c_str(), @@ -429,6 +416,13 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly) lib->creation_date_ = lib->GetCreationDate(); 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; } @@ -498,23 +492,7 @@ CompoundPtr CompoundLib::FindCompound(const String& id, if (i!=compound_cache_.end()) { return i->second; } - String query="SELECT id, tlc, olc, chem_class, dialect, formula"; - 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; - } + String query="SELECT id, tlc, olc, chem_class, dialect, formula, chem_type, name, inchi_code, inchi_key"; if(smiles_available_) { query+=", smiles"; } @@ -540,27 +518,19 @@ CompoundPtr CompoundLib::FindCompound(const String& id, compound->SetDialect(Compound::Dialect(sqlite3_column_text(stmt, 4)[0])); const char* f=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 5)); compound->SetFormula(f); - if(chem_type_available_) { - compound->SetChemType(mol::ChemType(sqlite3_column_text(stmt, 6)[0])); - } - if (name_available_) { - const char* name=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 7)); - if (name) { - compound->SetName(name); - } + 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); + const char* inchi_code=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 8)); + if (inchi_code) { + compound->SetInchi(inchi_code); } - if (inchi_available_) { - const char* inchi_code=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6+col_offset_inchi)); - if (inchi_code) { - 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); - } + const char* inchi_key=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 9)); + if (inchi_key) { + compound->SetInchiKey(inchi_key); } 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) { compound->SetSMILES(smiles); } @@ -587,9 +557,6 @@ CompoundLib::CompoundLib(): CompoundLibBase(), db_(new Database), compound_cache_(), - chem_type_available_(false), - name_available_(), - inchi_available_(), smiles_available_(), charges_available_(), creation_date_(), diff --git a/modules/conop/src/compound_lib.hh b/modules/conop/src/compound_lib.hh index ee76aea30..8786ce810 100644 --- a/modules/conop/src/compound_lib.hh +++ b/modules/conop/src/compound_lib.hh @@ -55,11 +55,8 @@ private: struct Database; Database* db_; mutable CompoundMap compound_cache_; - 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 - bool smiles_available_; //whether smiles are available in db - bool charges_available_; //whether atom charges are available in db + bool smiles_available_; //whether smiles are available in db - introduced in 2.6.0 + bool charges_available_; //whether atom charges are available in db - introduced in 2.6.0 Date creation_date_; String ost_version_used_; }; -- GitLab