Commit ac497932 by Maarten L. Hekkelman

Fix loading embedded restraint data

parent 9927b506
...@@ -550,12 +550,6 @@ class local_compound_factory_impl : public compound_factory_impl ...@@ -550,12 +550,6 @@ class local_compound_factory_impl : public compound_factory_impl
for (const auto &[id, name, threeLetterCode, group] : for (const auto &[id, name, threeLetterCode, group] :
file["comp_list"]["chem_comp"].rows<std::string, std::string, std::string, std::string>("id", "name", "three_letter_code", "group")) file["comp_list"]["chem_comp"].rows<std::string, std::string, std::string, std::string>("id", "name", "three_letter_code", "group"))
{ {
// if (std::regex_match(group, peptideRx))
// mKnownPeptides.insert(threeLetterCode);
// else if (cif::iequals(group, "DNA") or cif::iequals(group, "RNA"))
// mKnownBases.insert(threeLetterCode);
// Test if this compound is known in CCD
auto &rdb = m_local_file["comp_" + id]; auto &rdb = m_local_file["comp_" + id];
if (rdb.empty()) if (rdb.empty())
{ {
...@@ -563,129 +557,143 @@ class local_compound_factory_impl : public compound_factory_impl ...@@ -563,129 +557,143 @@ class local_compound_factory_impl : public compound_factory_impl
continue; continue;
} }
cif::datablock db(id); construct_compound(rdb, id, name, threeLetterCode, group);
}
}
float formula_weight = 0; compound *create(const std::string &id) override;
int formal_charge = 0;
std::map<std::string,size_t> formula_data;
for (size_t ord = 1; const auto &[atom_id, type_symbol, type, charge, x, y, z] : private:
rdb["chem_comp_atom"].rows<std::string, std::string, std::string, int, float, float, float>(
"atom_id", "type_symbol", "type", "charge", "x", "y", "z"))
{
auto atom = cif::atom_type_traits(type_symbol);
formula_weight += atom.weight();
formula_data[type_symbol] += 1;
db["chem_comp_atom"].emplace({
{ "comp_id", id },
{ "atom_id", atom_id },
{ "type_symbol", type_symbol },
{ "charge", charge },
{ "model_Cartn_x", x, 3 },
{ "model_Cartn_y", y, 3 },
{ "model_Cartn_z", z, 3 },
{ "pdbx_ordinal", ord++ }
});
formal_charge += charge;
}
for (size_t ord = 1; const auto &[atom_id_1, atom_id_2, type, aromatic] : compound *construct_compound(const datablock &db, const std::string &id, const std::string &name, const std::string &three_letter_code, const std::string &group);
rdb["chem_comp_bond"].rows<std::string, std::string, std::string, bool>("atom_id_1", "atom_id_2", "type", "aromatic"))
{
std::string value_order("SING");
if (cif::iequals(type, "single") or cif::iequals(type, "sing"))
value_order = "SING";
else if (cif::iequals(type, "double") or cif::iequals(type, "doub"))
value_order = "DOUB";
else if (cif::iequals(type, "triple") or cif::iequals(type, "trip"))
value_order = "TRIP";
db["chem_comp_bond"].emplace({
{ "comp_id", id },
{ "atom_id_1", atom_id_1 },
{ "atom_id_2", atom_id_2 },
{ "value_order", value_order },
{ "pdbx_aromatic_flag", aromatic },
// TODO: fetch stereo_config info from chem_comp_chir
{ "pdbx_ordinal", ord++ }
});
}
db.emplace_back(rdb["pdbx_chem_comp_descriptor"]); cif::file m_local_file;
};
std::string formula; compound *local_compound_factory_impl::create(const std::string &id)
for (bool first = true; const auto &[symbol, count]: formula_data) {
compound *result = nullptr;
for (auto &db : m_local_file)
{
if (db.name() == "comp_" + id)
{
auto chem_comp = db.get("chem_comp");
if (not chem_comp)
break;
try
{ {
if (std::exchange(first, false)) const auto &[id, name, threeLetterCode, group] =
formula += ' '; chem_comp->front().get<std::string, std::string, std::string, std::string>("id", "name", "three_letter_code", "group");
formula += symbol;
if (count > 1) result = construct_compound(db, id, name, threeLetterCode, group);
formula += std::to_string(count); }
catch (const std::exception &ex)
{
std::throw_with_nested(std::runtime_error("Error loading compound " + id));
} }
std::string type; break;
if (cif::iequals(group, "peptide") or cif::iequals(group, "l-peptide") or cif::iequals(group, "l-peptide linking"))
type = "L-PEPTIDE LINKING";
else if (cif::iequals(group, "dna"))
type = "DNA LINKING";
else if (cif::iequals(group, "rna"))
type = "RNA LINKING";
else
type = "NON-POLYMER";
db["chem_comp"].emplace({
{ "id", id },
{ "name", name },
{ "type", type },
{ "formula", formula },
{ "pdbx_formal_charge", formal_charge },
{ "formula_weight", formula_weight },
{ "three_letter_code", threeLetterCode }
});
m_compounds.push_back(new compound(db));
} }
} }
// compound *create(const std::string &id) override; return result;
}
private: compound *local_compound_factory_impl::construct_compound(const datablock &rdb, const std::string &id,
cif::file m_local_file; const std::string &name, const std::string &three_letter_code, const std::string &group)
}; {
cif::datablock db(id);
// compound *local_compound_factory_impl::create(const std::string &id) float formula_weight = 0;
// { int formal_charge = 0;
// compound *result = nullptr; std::map<std::string,size_t> formula_data;
// for (auto &db : m_local_file) for (size_t ord = 1; const auto &[atom_id, type_symbol, type, charge, x, y, z] :
// { rdb["chem_comp_atom"].rows<std::string, std::string, std::string, int, float, float, float>(
// if (db.name() == id) "atom_id", "type_symbol", "type", "charge", "x", "y", "z"))
// { {
// cif::datablock db_copy(db); auto atom = cif::atom_type_traits(type_symbol);
formula_weight += atom.weight();
// try formula_data[type_symbol] += 1;
// {
// result = new compound(db_copy, 1);
// }
// catch (const std::exception &ex)
// {
// std::throw_with_nested(std::runtime_error("Error loading compound " + id));
// }
db["chem_comp_atom"].emplace({
{ "comp_id", id },
{ "atom_id", atom_id },
{ "type_symbol", type_symbol },
{ "charge", charge },
{ "model_Cartn_x", x, 3 },
{ "model_Cartn_y", y, 3 },
{ "model_Cartn_z", z, 3 },
{ "pdbx_ordinal", ord++ }
});
// std::shared_lock lock(mMutex); formal_charge += charge;
// m_compounds.push_back(result); }
for (size_t ord = 1; const auto &[atom_id_1, atom_id_2, type, aromatic] :
rdb["chem_comp_bond"].rows<std::string, std::string, std::string, bool>("atom_id_1", "atom_id_2", "type", "aromatic"))
{
std::string value_order("SING");
// break; if (cif::iequals(type, "single") or cif::iequals(type, "sing"))
// } value_order = "SING";
// } else if (cif::iequals(type, "double") or cif::iequals(type, "doub"))
value_order = "DOUB";
else if (cif::iequals(type, "triple") or cif::iequals(type, "trip"))
value_order = "TRIP";
// return result; db["chem_comp_bond"].emplace({
// } { "comp_id", id },
{ "atom_id_1", atom_id_1 },
{ "atom_id_2", atom_id_2 },
{ "value_order", value_order },
{ "pdbx_aromatic_flag", aromatic },
// TODO: fetch stereo_config info from chem_comp_chir
{ "pdbx_ordinal", ord++ }
});
}
db.emplace_back(rdb["pdbx_chem_comp_descriptor"]);
std::string formula;
for (bool first = true; const auto &[symbol, count]: formula_data)
{
if (std::exchange(first, false))
formula += ' ';
formula += symbol;
if (count > 1)
formula += std::to_string(count);
}
std::string type;
if (cif::iequals(group, "peptide") or cif::iequals(group, "l-peptide") or cif::iequals(group, "l-peptide linking"))
type = "L-PEPTIDE LINKING";
else if (cif::iequals(group, "dna"))
type = "DNA LINKING";
else if (cif::iequals(group, "rna"))
type = "RNA LINKING";
else
type = "NON-POLYMER";
db["chem_comp"].emplace({
{ "id", id },
{ "name", name },
{ "type", type },
{ "formula", formula },
{ "pdbx_formal_charge", formal_charge },
{ "formula_weight", formula_weight },
{ "three_letter_code", three_letter_code }
});
std::shared_lock lock(mMutex);
auto result = new compound(db);
m_compounds.push_back(result);
return result;
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment