Skip to content
Snippets Groups Projects
Commit c112fb49 authored by BIOPZ-Haas Juergen's avatar BIOPZ-Haas Juergen
Browse files

BZDNG-336;adding creation date and version of OST used to create compound lib...

BZDNG-336;adding creation date and version of OST used to create compound lib to compound lib;adding API to retrieve this information, calls: GetOSTVersionUsed() and GetCreationDate()
parent 3a862e10
Branches
Tags
No related merge requests found
......@@ -74,6 +74,11 @@ CompoundPtr find_compound(CompoundLibPtr comp_lib,
return comp_lib->FindCompound(tlc, tr_dialect(dialect));
}
String get_creation_date(CompoundLibPtr comp_lib)
{
return comp_lib->GetCreationDate().ToString();
}
}
void export_Compound() {
......@@ -130,6 +135,8 @@ void export_Compound() {
.def("FindCompound", &find_compound,
(arg("tlc"), arg("dialect")="PDB"))
.def("ClearCache", &CompoundLib::ClearCache)
.def("GetOSTVersionUsed", &CompoundLib::GetOSTVersionUsed)
.def("GetCreationDate", &get_creation_date, (arg("comp_lib")))
;
class_<AtomSpecList>("AtomSpecList", init<>())
......
......@@ -88,9 +88,10 @@ int main(int argc, char const *argv[])
assert(compound_lib);
conop::CompoundLibPtr in_mem_lib=in_mem ? compound_lib :
compound_lib->Copy(":memory:");
compound_lib.reset();
compound_lib.reset();
cdp.SetCompoundLib(in_mem_lib);
cdp.Parse();
in_mem_lib->SetChemLibInfo();
in_mem_lib->Copy(argv[3]);
return 0;
}
......@@ -26,7 +26,8 @@
#include <boost/format.hpp>
#include <ost/log.hh>
#include "compound_lib.hh"
#include <ost/version.hh>
#include <ost/string_ref.hh>
using boost::format;
......@@ -34,41 +35,44 @@ namespace ost { namespace conop {
namespace {
const char* CREATE_CMD[]={
const char* CREATE_CMD[]={
"CREATE TABLE IF NOT EXISTS chemlib_info ( "
" creation_date TIMESTAMP, "
" ost_version_used VARCHAR(64) NOT NULL);",
"CREATE TABLE IF NOT EXISTS chem_compounds ( "
" id INTEGER PRIMARY KEY AUTOINCREMENT, "
" tlc VARCHAR(3) NOT NULL, "
" olc VARCHAR(1) NOT NULL, "
" dialect VARCHAR(1) NOT NULL, "
" chem_class VARCHAR(1), "
" chem_type VARCHAR(1), "
" formula VARCHAR(64) NOT NULL, "
" pdb_initial TIMESTAMP, "
" pdb_modified TIMESTAMP, "
" name VARCHAR(256) "
" id INTEGER PRIMARY KEY AUTOINCREMENT, "
" tlc VARCHAR(3) NOT NULL, "
" olc VARCHAR(1) NOT NULL, "
" dialect VARCHAR(1) NOT NULL, "
" chem_class VARCHAR(1), "
" chem_type VARCHAR(1), "
" formula VARCHAR(64) NOT NULL, "
" pdb_initial TIMESTAMP, "
" pdb_modified TIMESTAMP, "
" name VARCHAR(256) "
");",
" CREATE UNIQUE INDEX IF NOT EXISTS commpound_tlc_index ON chem_compounds "
" (tlc, dialect)",
"CREATE TABLE IF NOT EXISTS atoms ( "
" id INTEGER PRIMARY KEY AUTOINCREMENT, "
" compound_id INTEGER REFERENCES chem_compounds (id) ON DELETE CASCADE, "
" name VARCHAR(4) NOT NULL, "
" alt_name VARCHAR(4) NOT NULL, "
" element VARCHAR(2) NOT NULL, "
" is_aromatic VARCHAR(1) NOT NULL, "
" stereo_conf VARCHAR(1) NOT NULL, "
" is_leaving VARCHAR(1) NOT NULL, "
" ordinal INT "
" id INTEGER PRIMARY KEY AUTOINCREMENT, "
" compound_id INTEGER REFERENCES chem_compounds (id) ON DELETE CASCADE, "
" name VARCHAR(4) NOT NULL, "
" alt_name VARCHAR(4) NOT NULL, "
" element VARCHAR(2) NOT NULL, "
" is_aromatic VARCHAR(1) NOT NULL, "
" stereo_conf VARCHAR(1) NOT NULL, "
" is_leaving VARCHAR(1) NOT NULL, "
" ordinal INT "
");",
" CREATE INDEX IF NOT EXISTS atom_name_index ON atoms "
" (compound_id, name, alt_name)",
" CREATE TABLE IF NOT EXISTS bonds ( "
" id INTEGER PRIMARY KEY AUTOINCREMENT, "
" compound_id INTEGER REFERENCES chem_compounds (id) ON DELETE CASCADE, "
" atom_one INTEGER REFERENCES atoms (id) ON DELETE CASCADE, "
" atom_two INTEGER REFERENCES atoms (id) ON DELETE CASCADE, "
" bond_order INT, "
" stereo_conf VARCHAR(1) NOT NULL "
" id INTEGER PRIMARY KEY AUTOINCREMENT, "
" compound_id INTEGER REFERENCES chem_compounds (id) ON DELETE CASCADE, "
" atom_one INTEGER REFERENCES atoms (id) ON DELETE CASCADE, "
" atom_two INTEGER REFERENCES atoms (id) ON DELETE CASCADE, "
" bond_order INT, "
" stereo_conf VARCHAR(1) NOT NULL "
" );",
" CREATE INDEX IF NOT EXISTS bond_index ON bonds (compound_id)",
" CREATE TRIGGER delete_related_objects "
......@@ -93,8 +97,104 @@ const char* INSERT_BOND_STATEMENT="insert into bonds
" (compound_id, atom_one, atom_two, bond_order, stereo_conf) "
" VALUES (?, ?, ?, ?, ?)";
const char* INSERT_CHEMLIB_INFO_STATEMENT="insert into chemlib_info "
" (creation_date, ost_version_used) "
" VALUES (DATE(?), ?)";
}
void CompoundLib::SetChemLibInfo(void){
sqlite3_stmt* stmt=NULL;
//~ if (!conn_) {
//~ LOG_ERROR(sqlite3_errmsg("Connection to DB not made"));
//~ }
int retval=sqlite3_prepare_v2(conn_, INSERT_CHEMLIB_INFO_STATEMENT,
strlen(INSERT_CHEMLIB_INFO_STATEMENT), &stmt, NULL);
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
Date date = Date(1900+timeinfo->tm_year, 1+timeinfo->tm_mon, timeinfo->tm_mday);
String date_str=date.ToString();
if (SQLITE_OK==retval) {
sqlite3_bind_text(stmt, 1, date_str.c_str(),
strlen(date_str.c_str()), NULL);
const char* ost_version = OST_VERSION_STRING;
sqlite3_bind_text(stmt, 2, ost_version,
strlen(ost_version), NULL);
} else {
std::cout << "failed" <<std::endl;
}
retval=sqlite3_step(stmt);
if (SQLITE_DONE!=retval) {
if (sqlite3_errcode(conn_)==SQLITE_CONSTRAINT) {
LOG_ERROR("chemlib info already exists");
} else {
LOG_ERROR(sqlite3_errmsg(conn_));
}
}
sqlite3_finalize(stmt);
}
Date CompoundLib::GetCreationDate(void){
String query="SELECT creation_date FROM chemlib_info";
sqlite3_stmt* stmt;
int retval=sqlite3_prepare_v2(conn_, query.c_str(),
static_cast<int>(query.length()),
&stmt, NULL);
if (SQLITE_OK==retval) {
int ret=sqlite3_step(stmt);
if (SQLITE_DONE==ret) {
sqlite3_finalize(stmt);
return Date();
}
if (SQLITE_ROW==ret) {
const char* strr = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
Date date = Date::FromString(StringRef(strr, strlen(strr)));
sqlite3_finalize(stmt);
return date;
}
assert(SQLITE_DONE==sqlite3_step(stmt));
} else {
LOG_ERROR("ERROR: " << sqlite3_errmsg(conn_));
sqlite3_finalize(stmt);
return Date();
}
sqlite3_finalize(stmt);
return Date();
}
String CompoundLib::GetOSTVersionUsed(){
String query="SELECT ost_version_used FROM chemlib_info";
sqlite3_stmt* stmt;
String version;
int retval=sqlite3_prepare_v2(conn_, query.c_str(),
static_cast<int>(query.length()),
&stmt, NULL);
if (SQLITE_OK==retval) {
int ret=sqlite3_step(stmt);
if (SQLITE_DONE==ret) {
sqlite3_finalize(stmt);
return String();
}
if (SQLITE_ROW==ret) {
version = String(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
sqlite3_finalize(stmt);
return version;
}
assert(SQLITE_DONE==sqlite3_step(stmt));
} else {
LOG_ERROR("ERROR: " << sqlite3_errmsg(conn_) << " - your compound library might be outdated!");
sqlite3_finalize(stmt);
return String();
}
sqlite3_finalize(stmt);
return String();
}
......@@ -257,6 +357,9 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly)
static_cast<int>(aq.length()),
&stmt, NULL);
lib->name_available_ = retval==SQLITE_OK;
lib->creation_date_ = lib->GetCreationDate();
lib->ost_version_used_ = lib->GetOSTVersionUsed();
return lib;
}
......
......@@ -42,18 +42,24 @@ public:
~CompoundLib();
CompoundPtr FindCompound(const String& id, Compound::Dialect dialect);
Date GetCreationDate(void);
String GetOSTVersionUsed(void);
void AddCompound(const CompoundPtr& compound);
CompoundLibPtr Copy(const String& filename) const;
void ClearCache();
void SetChemLibInfo(void);
private:
CompoundLib();
void LoadAtomsFromDB(CompoundPtr comp, int pk);
void LoadBondsFromDB(CompoundPtr comp, int pk);
private:
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
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
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