diff --git a/modules/conop/pymod/export_compound.cc b/modules/conop/pymod/export_compound.cc index 0b7e0dde8d24422a0758d91019aebf0d1252701b..ae93c67271d8cbae8a34626579940e00ef95d327 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 e33a7e38cfb840ebc5e5e050fbd7da55073e2c68..83862af3bd93e4614a2174417501afcd30a9ec90 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 c05e60fb6d2ce72343e6ab44d637526c16639707..215b75ad5e482c9cd6d7e51a11f8946cad8a48bf 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 a552c5aee7754aea6a6759911389a4931c3ec3d0..faaf6a051f7bb14bfaab9bbde95c7dedd98c0316 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 a44dc733803bf7b805d52b839c8d756b3941f929..654204dcd6591d31267b67bbde7b14ddabea19b4 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") {