From 04fd577167be90d364c973728f4833b4caa32f0e Mon Sep 17 00:00:00 2001 From: Juergen Haas <juergen.haas@unibas.ch> Date: Fri, 15 Jun 2012 16:34:38 +0200 Subject: [PATCH] store name in compound library --- modules/conop/pymod/export_compound.cc | 3 +++ modules/conop/src/compound.hh | 7 ++++++- modules/conop/src/compound_lib.cc | 21 ++++++++++++++++++--- modules/conop/src/compound_lib.hh | 1 + modules/io/src/mol/chemdict_parser.cc | 6 ++++++ 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/modules/conop/pymod/export_compound.cc b/modules/conop/pymod/export_compound.cc index 0b7e0dde8..ae93c6727 100644 --- a/modules/conop/pymod/export_compound.cc +++ b/modules/conop/pymod/export_compound.cc @@ -84,6 +84,9 @@ void export_Compound() { .def("GetOneLetterCode", &Compound::GetOneLetterCode) .add_property("three_letter_code", make_function(&Compound::GetID, return_value_policy<copy_const_reference>())) + .add_property("name", + make_function(&Compound::GetName, + return_value_policy<copy_const_reference>())) .add_property("id", make_function(&Compound::GetID, return_value_policy<copy_const_reference>())) .add_property("one_letter_code", &Compound::GetOneLetterCode, &Compound::SetOneLetterCode) diff --git a/modules/conop/src/compound.hh b/modules/conop/src/compound.hh index e33a7e38c..83862af3b 100644 --- a/modules/conop/src/compound.hh +++ b/modules/conop/src/compound.hh @@ -201,9 +201,13 @@ public: int GetAtomSpecIndex(const String& name) const; - const String& GetFormula() { return formula_; } + const String& GetName() { return name_; } + + void SetName(const String& name) { name_=name; } void SetFormula(const String& formula) { formula_=formula; } + + const String& GetFormula() { return formula_; } const BondSpecList& GetBondSpecs() const { return bond_specs_; @@ -231,6 +235,7 @@ private: char olc_; String tlc_; String formula_; + String name_; AtomSpecList atom_specs_; BondSpecList bond_specs_; mol::ChemClass chem_class_; diff --git a/modules/conop/src/compound_lib.cc b/modules/conop/src/compound_lib.cc index c05e60fb6..215b75ad5 100644 --- a/modules/conop/src/compound_lib.cc +++ b/modules/conop/src/compound_lib.cc @@ -44,7 +44,8 @@ const char* CREATE_CMD[]={ " chem_type VARCHAR(1), " " formula VARCHAR(64) NOT NULL, " " pdb_initial TIMESTAMP, " -" pdb_modified TIMESTAMP " +" pdb_modified TIMESTAMP, " +" name VARCHAR(256) " ");", " CREATE UNIQUE INDEX IF NOT EXISTS commpound_tlc_index ON chem_compounds " " (tlc, dialect)", @@ -80,8 +81,8 @@ const char* CREATE_CMD[]={ const char* INSERT_COMPOUND_STATEMENT="INSERT INTO chem_compounds " -" (tlc, olc, dialect, chem_class, chem_type, formula, pdb_initial, pdb_modified) " -" VALUES (?, ?, ?, ?, ?, ?, DATE(?), DATE(?))"; +" (tlc, olc, dialect, chem_class, chem_type, formula, pdb_initial, pdb_modified, name) " +" VALUES (?, ?, ?, ?, ?, ?, DATE(?), DATE(?), ?)"; const char* INSERT_ATOM_STATEMENT="INSERT INTO atoms " " (compound_id, name, alt_name, element, is_aromatic, stereo_conf, " @@ -127,6 +128,7 @@ void CompoundLib::AddCompound(const CompoundPtr& compound) sqlite3_bind_text(stmt, 7, date.c_str(), date.length(), NULL); date=ss.str(); sqlite3_bind_text(stmt, 8, date.c_str(), date.length(), NULL); + sqlite3_bind_text(stmt, 9, compound->GetName().c_str(), compound->GetName().length(), NULL); } else { LOG_ERROR(sqlite3_errmsg(conn_)); sqlite3_finalize(stmt); @@ -256,6 +258,11 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly) static_cast<int>(aq.length()), &stmt, NULL); lib->chem_type_available_ = retval==SQLITE_OK; + aq="SELECT name FROM chem_compounds LIMIT 1"; + retval=sqlite3_prepare_v2(lib->conn_, aq.c_str(), + static_cast<int>(aq.length()), + &stmt, NULL); + lib->name_available_ = retval==SQLITE_OK; return lib; } @@ -321,7 +328,11 @@ CompoundPtr CompoundLib::FindCompound(const String& id, String query="SELECT id, tlc, olc, chem_class, dialect, formula"; if(chem_type_available_) { query+=", chem_type"; + if(name_available_) { + query+=", name"; + } } + query+=" FROM chem_compounds" " WHERE tlc='"+id+"' AND dialect='"+String(1, char(dialect))+"'"; sqlite3_stmt* stmt; @@ -346,6 +357,10 @@ CompoundPtr CompoundLib::FindCompound(const String& id, 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)); + compound->SetName(name); + } // Load atoms and bonds this->LoadAtomsFromDB(compound, pk); this->LoadBondsFromDB(compound, pk); diff --git a/modules/conop/src/compound_lib.hh b/modules/conop/src/compound_lib.hh index a552c5aee..faaf6a051 100644 --- a/modules/conop/src/compound_lib.hh +++ b/modules/conop/src/compound_lib.hh @@ -53,6 +53,7 @@ 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 }; }} diff --git a/modules/io/src/mol/chemdict_parser.cc b/modules/io/src/mol/chemdict_parser.cc index a44dc7338..654204dcd 100644 --- a/modules/io/src/mol/chemdict_parser.cc +++ b/modules/io/src/mol/chemdict_parser.cc @@ -105,6 +105,12 @@ void ChemdictParser::OnDataItem(const StarDataItem& item) std::cout << "unknown pdbx_type '" << type << "' for compound " << compound_->GetID() << std::endl; } + } else if (item.GetName()==StringRef("name", 4)) { + compound_->SetName(item.GetValue().str()); + if (compound_->GetName()==""){ + std::cout << "unknown compound name, chemcomp.name field empty for compound: " + << compound_->GetID() << std::endl; + } } else if (item.GetName()==StringRef("formula", 7)) { compound_->SetFormula(item.GetValue().str()); if (compound_->GetFormula()=="H2 O") { -- GitLab