Commit 8a60bae3 by Maarten L. Hekkelman

non-throwing remove_residue

add chem_comp for sugars
parent fa27a11f
...@@ -842,10 +842,7 @@ class structure ...@@ -842,10 +842,7 @@ class structure
/// ///
/// \param asym_id The asym ID /// \param asym_id The asym ID
/// \param seq_id The sequence ID /// \param seq_id The sequence ID
void remove_residue(const std::string &asym_id, int seq_id, const std::string &auth_seq_id) void remove_residue(const std::string &asym_id, int seq_id, const std::string &auth_seq_id);
{
remove_residue(get_residue(asym_id, seq_id, auth_seq_id));
}
/// \brief Create a new non-polymer entity, returns new ID /// \brief Create a new non-polymer entity, returns new ID
/// \param mon_id The mon_id for the new nonpoly, must be an existing and known compound from CCD /// \param mon_id The mon_id for the new nonpoly, must be an existing and known compound from CCD
......
...@@ -1222,6 +1222,22 @@ sugar &branch::construct_sugar(const std::string &compound_id) ...@@ -1222,6 +1222,22 @@ sugar &branch::construct_sugar(const std::string &compound_id)
{ {
auto &db = m_structure->get_datablock(); auto &db = m_structure->get_datablock();
auto compound = compound_factory::instance().create(compound_id);
if (compound == nullptr)
throw std::runtime_error("Trying to insert unknown compound " + compound_id + " (not found in CCD)");
auto &chemComp = db["chem_comp"];
auto r = chemComp.find(key("id") == compound_id);
if (r.empty())
{
chemComp.emplace({
{"id", compound_id},
{"name", compound->name()},
{"formula", compound->formula()},
{"formula_weight", compound->formula_weight()},
{"type", compound->type()}});
}
sugar &result = emplace_back(*this, compound_id, m_asym_id, size() + 1); sugar &result = emplace_back(*this, compound_id, m_asym_id, size() + 1);
db["pdbx_branch_scheme"].emplace({ db["pdbx_branch_scheme"].emplace({
...@@ -2017,6 +2033,51 @@ void structure::change_residue(residue &res, const std::string &newCompound, ...@@ -2017,6 +2033,51 @@ void structure::change_residue(residue &res, const std::string &newCompound,
} }
} }
void structure::remove_residue(const std::string &asym_id, int seq_id, const std::string &auth_seq_id)
{
if (seq_id == 0)
{
for (auto &res : m_non_polymers)
{
if (res.get_asym_id() == asym_id and (auth_seq_id.empty() or res.get_auth_seq_id() == auth_seq_id))
{
remove_residue(res);
return;
}
}
}
for (auto &poly : m_polymers)
{
if (poly.get_asym_id() != asym_id)
continue;
for (auto &res : poly)
{
if (res.get_seq_id() == seq_id)
{
remove_residue(res);
return;
}
}
}
for (auto &branch : m_branches)
{
if (branch.get_asym_id() != asym_id)
continue;
for (auto &sugar : branch)
{
if (sugar.get_asym_id() == asym_id and sugar.get_auth_seq_id() == auth_seq_id)
{
remove_residue(sugar);
return;
}
}
}
}
void structure::remove_residue(residue &res) void structure::remove_residue(residue &res)
{ {
using namespace literals; using namespace literals;
......
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