Skip to content
Snippets Groups Projects
Commit bf46ad1a authored by BIOPZ-Johner Niklaus's avatar BIOPZ-Johner Niklaus
Browse files

Added charges to compounds and their atoms in the compound_lib.

parent c83dc484
Branches
Tags
No related merge requests found
......@@ -69,6 +69,17 @@ char get_chemtype(CompoundPtr compound)
return char(compound->GetChemType());
}
int get_charge(CompoundPtr compound)
{
return int(compound->GetCharge());
}
void set_charge(CompoundPtr compound, int c)
{
compound->SetCharge(c);
}
CompoundPtr find_compound(CompoundLibPtr comp_lib,
const String& tlc, const String& dialect)
{
......@@ -95,6 +106,9 @@ void export_Compound() {
return_value_policy<copy_const_reference>())
.def("SetOneLetterCode", &Compound::SetOneLetterCode)
.def("GetOneLetterCode", &Compound::GetOneLetterCode)
.def("GetCharge", &Compound::GetCharge)
.def("SetCharge", &Compound::SetCharge)
.add_property("three_letter_code", make_function(&Compound::GetID, return_value_policy<copy_const_reference>()))
.add_property("name",
......@@ -129,6 +143,7 @@ void export_Compound() {
.def_readonly("is_leaving", &AtomSpec::is_leaving)
.def_readonly("is_aromatic", &AtomSpec::is_aromatic)
.def_readonly("ordinal", &AtomSpec::ordinal)
.def_readonly("charge", &AtomSpec::charge)
;
class_<BondSpec>("BondSpec", no_init)
......
......@@ -76,17 +76,19 @@ struct DLLEXPORT_OST_CONOP AtomSpec {
alt_name(),
element(),
is_leaving(false),
is_aromatic()
is_aromatic(),
charge()
{
}
AtomSpec(int o, const String& n, const String& a, const String& e,
bool l, bool r):
bool l, bool r, int c):
ordinal(o),
name(n),
alt_name(a),
element(e),
is_leaving(l),
is_aromatic(r)
is_aromatic(r),
charge(c)
{}
int ordinal;
String name;
......@@ -94,10 +96,11 @@ struct DLLEXPORT_OST_CONOP AtomSpec {
String element;
bool is_leaving;
bool is_aromatic;
int charge;
bool operator==(const AtomSpec& rhs) const {
return ordinal==rhs.ordinal && name==rhs.name && alt_name==rhs.alt_name &&
element==rhs.element && is_leaving==rhs.is_leaving &&
rhs.is_aromatic==rhs.is_aromatic;
rhs.is_aromatic==rhs.is_aromatic && charge==rhs.charge;
}
bool operator!=(const AtomSpec& rhs) const {
return !this->operator==(rhs);
......@@ -152,7 +155,8 @@ public:
chem_type_(),
dialect_(Compound::PDB),
creation_date_(),
mod_date_()
mod_date_(),
charge_()
{
}
......@@ -241,6 +245,10 @@ public:
const String& GetFormula() { return formula_; }
void SetCharge(int charge) { charge_=charge; }
int GetCharge() { return charge_; }
const BondSpecList& GetBondSpecs() const {
return bond_specs_;
}
......@@ -275,6 +283,7 @@ private:
Dialect dialect_;
Date creation_date_;
Date mod_date_;
int charge_;
};
typedef std::map<String, CompoundPtr> CompoundMap;
......
......@@ -49,7 +49,8 @@ const char* CREATE_CMD[]={
" formula VARCHAR(64) NOT NULL, "
" pdb_initial TIMESTAMP, "
" pdb_modified TIMESTAMP, "
" name VARCHAR(256) "
" name VARCHAR(256), "
" charge INT "
");",
" CREATE UNIQUE INDEX IF NOT EXISTS commpound_tlc_index ON chem_compounds "
" (tlc, dialect)",
......@@ -62,7 +63,8 @@ const char* CREATE_CMD[]={
" is_aromatic VARCHAR(1) NOT NULL, "
" stereo_conf VARCHAR(1) NOT NULL, "
" is_leaving VARCHAR(1) NOT NULL, "
" ordinal INT "
" ordinal INT, "
" charge INT "
");",
" CREATE INDEX IF NOT EXISTS atom_name_index ON atoms "
" (compound_id, name, alt_name)",
......@@ -85,13 +87,13 @@ 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, name) "
" VALUES (?, ?, ?, ?, ?, ?, DATE(?), DATE(?), ?)";
" (tlc, olc, dialect, chem_class, chem_type, formula, pdb_initial, pdb_modified, name, charge) "
" VALUES (?, ?, ?, ?, ?, ?, DATE(?), DATE(?), ?, ?)";
const char* INSERT_ATOM_STATEMENT="INSERT INTO atoms "
" (compound_id, name, alt_name, element, is_aromatic, stereo_conf, "
" is_leaving, ordinal) "
" VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
" is_leaving, ordinal, charge) "
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
const char* INSERT_BOND_STATEMENT="insert into bonds "
" (compound_id, atom_one, atom_two, bond_order, stereo_conf) "
......@@ -222,6 +224,8 @@ void CompoundLib::AddCompound(const CompoundPtr& compound)
modi_date_str=modi_date.ToString();
sqlite3_bind_text(stmt, 7, crea_date_str.c_str(), crea_date_str.length(), NULL);
sqlite3_bind_text(stmt, 8, modi_date_str.c_str(), modi_date_str.length(), NULL);
int charge=compound->GetCharge();
sqlite3_bind_int(stmt, 10, charge);
} else {
LOG_ERROR(sqlite3_errmsg(conn_));
sqlite3_finalize(stmt);
......@@ -255,6 +259,7 @@ void CompoundLib::AddCompound(const CompoundPtr& compound)
sqlite3_bind_int(stmt, 6, 0);
sqlite3_bind_int(stmt, 7, a.is_leaving);
sqlite3_bind_int(stmt, 8, a.ordinal);
sqlite3_bind_int(stmt, 9, a.charge);
retval=sqlite3_step(stmt);
assert(retval==SQLITE_DONE);
atom_ids[a.ordinal]=sqlite3_last_insert_rowid(conn_);
......@@ -363,7 +368,7 @@ CompoundLibPtr CompoundLib::Load(const String& database, bool readonly)
}
void CompoundLib::LoadAtomsFromDB(CompoundPtr comp, int pk) const {
String aq=str(format("SELECT name, alt_name, element, ordinal, is_leaving "
String aq=str(format("SELECT name, alt_name, element, ordinal, is_leaving, charge "
"FROM atoms WHERE compound_id=%d "
"ORDER BY ordinal ASC") % pk);
sqlite3_stmt* stmt;
......@@ -379,6 +384,7 @@ void CompoundLib::LoadAtomsFromDB(CompoundPtr comp, int pk) const {
atom_sp.element=String(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
atom_sp.ordinal=sqlite3_column_int(stmt, 3);
atom_sp.is_leaving=bool(sqlite3_column_int(stmt, 4)!=0);
atom_sp.charge=sqlite3_column_int(stmt, 5);
comp->AddAtom(atom_sp);
}
} else {
......@@ -421,7 +427,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";
String query="SELECT id, tlc, olc, chem_class, dialect, formula, charge";
if(chem_type_available_) {
query+=", chem_type";
if(name_available_) {
......@@ -450,11 +456,12 @@ 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);
compound->SetCharge(sqlite3_column_int(stmt, 6));
if(chem_type_available_) {
compound->SetChemType(mol::ChemType(sqlite3_column_text(stmt, 6)[0]));
compound->SetChemType(mol::ChemType(sqlite3_column_text(stmt, 7)[0]));
}
if (name_available_) {
const char* name=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 7));
const char* name=reinterpret_cast<const char*>(sqlite3_column_text(stmt, 8));
if (name) {
compound->SetName(name);
}
......
This diff is collapsed.
......@@ -22,7 +22,7 @@ bool ChemdictParser::OnBeginData(const StringRef& data_name)
}
bool ChemdictParser::OnBeginLoop(const StarLoopDesc& header)
{
{
if (header.GetCategory()=="chem_comp_atom") {
loop_type_=ATOM_SPEC;
indices_[ATOM_NAME]=header.GetIndex("atom_id");
......@@ -30,7 +30,8 @@ bool ChemdictParser::OnBeginLoop(const StarLoopDesc& header)
indices_[ELE]=header.GetIndex("type_symbol");
indices_[IS_LEAVING]=header.GetIndex("pdbx_leaving_atom_flag");
indices_[IS_AROMATIC]=header.GetIndex("pdbx_aromatic_flag");
indices_[ORDINAL]=header.GetIndex("pdbx_ordinal");
indices_[ORDINAL]=header.GetIndex("pdbx_ordinal");
indices_[CHARGE]=header.GetIndex("charge");
return true;
} else if (header.GetCategory()=="chem_comp_bond") {
loop_type_=BOND_SPEC;
......@@ -54,6 +55,7 @@ void ChemdictParser::OnDataRow(const StarLoopDesc& header,
atom.ordinal=columns[indices_[ORDINAL]].to_int().second-1;
atom.element=columns[indices_[ELE]].str();
atom.is_aromatic=columns[indices_[IS_AROMATIC]][0]=='Y';
atom.charge=columns[indices_[CHARGE]].to_int().second;
compound_->AddAtom(atom);
atom_map_[atom.name]=atom.ordinal;
} else if (loop_type_==BOND_SPEC) {
......@@ -126,6 +128,10 @@ void ChemdictParser::OnDataItem(const StarDataItem& item)
} else if (item.GetName()==StringRef("pdbx_modified_date", 18)) {
compound_->SetModificationDate(Date::FromString(item.GetValue()));
}
else if (item.GetName()==StringRef("pdbx_formal_charge", 18)) {
compound_->SetCharge(item.GetValue().to_int().second);
//std::cout << compound_->GetID() << compound_->GetCharge() << "\n" ;
}
} else if (item.GetName()==StringRef("atom_id", 7)) {
atom_.name=item.GetValue().str();
} else if (item.GetName()==StringRef("alt_atom_id", 11)) {
......
......@@ -75,12 +75,13 @@ private:
IS_LEAVING=4,
ELE=5,
STEREO_CONF=6,
CHARGE=7,
ATOM_ID1=0,
ATOM_ID2=1,
BOND_ORDER=2
} PropIndex;
char last_;
int indices_[10];
int indices_[11];
bool insert_;
static std::map<String, mol::ChemClass> tm_;
static std::map<String, mol::ChemType> xtm_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment