Commit 5525103a by Maarten L. Hekkelman

backup

parent af125bdd
......@@ -176,6 +176,7 @@ class Item
, mValue(rhs.mValue)
{
}
Item(Item &&rhs) noexcept
: mName(std::move(rhs.mName))
, mValue(std::move(rhs.mValue))
......
......@@ -747,14 +747,14 @@ class Structure
/// \brief Create a new (sugar) branch with one first NAG containing atoms constructed from \a nag_atom_info
Branch &createBranch(std::vector<std::vector<cif::Item>> &nag_atom_info);
/// \brief Create a new (sugar) branch with one first NAG containing atoms \a nag_atoms
Branch &createBranch(std::vector<Atom> &nag_atoms);
/// \brief Extend an existing (sugar) branch identified by \a asymID with one sugar containing atoms constructed from \a atom_info
Branch &extendBranch(const std::string &asym_id, std::vector<std::vector<cif::Item>> &atom_info);
/// \brief Extend an existing (sugar) branch identified by \a asymID with one sugar containing atoms \a atoms
Branch &extendBranch(const std::string &asym_id, std::vector<Atom> &atoms);
///
/// \param asym_id The asym id of the branch to extend
/// \param atom_info Array containing the info for the atoms to construct for the new sugar
/// \param link_sugar The sugar to link to, note: this is the sugar number (1 based)
/// \param link_atom The atom id of the atom linked in the sugar
Branch &extendBranch(const std::string &asym_id, std::vector<std::vector<cif::Item>> &atom_info,
int link_sugar, const std::string &link_atom);
/// \brief Remove \a branch
void removeBranch(Branch &branch);
......
......@@ -96,7 +96,7 @@ bool isUnquotedString(const char *s)
// but be careful it does not contain e.g. stop_
if (result)
{
const std::regex reservedRx(R"((^(?:data|save)|.*(?:loop|stop|global))_.+)", std::regex_constants::icase);
static const std::regex reservedRx(R"((^(?:data|save)|.*(?:loop|stop|global))_.+)", std::regex_constants::icase);
result = not std::regex_match(ss, reservedRx);
}
......
......@@ -2259,6 +2259,10 @@ Branch& Structure::createBranch(std::vector<std::vector<cif::Item>> &nag_atoms)
auto &struct_asym = db["struct_asym"];
std::string asym_id = struct_asym.getUniqueID();
auto &branch = mBranches.emplace_back(*this, asym_id);
auto &sugar = branch.emplace_back(branch, "NAG", asym_id, 1);
auto tmp_entity_id = db["entity"].getUniqueID("");
auto &atom_site = db["atom_site"];
auto appendUnlessSet = [](std::vector<cif::Item> &ai, cif::Item &&i)
......@@ -2267,8 +2271,6 @@ Branch& Structure::createBranch(std::vector<std::vector<cif::Item>> &nag_atoms)
ai.emplace_back(std::move(i));
};
std::vector<Atom> atoms;
for (auto &atom : nag_atoms)
{
auto atom_id = atom_site.getUniqueID("");
......@@ -2278,7 +2280,7 @@ Branch& Structure::createBranch(std::vector<std::vector<cif::Item>> &nag_atoms)
appendUnlessSet(atom, { "label_comp_id", "NAG"} );
appendUnlessSet(atom, { "label_asym_id", asym_id} );
appendUnlessSet(atom, { "label_seq_id", "."} );
// appendUnlessSet(atom, { "label_entity_id", tmp_entity_id} );
appendUnlessSet(atom, { "label_entity_id", tmp_entity_id} );
appendUnlessSet(atom, { "auth_comp_id", "NAG"} );
appendUnlessSet(atom, { "auth_asym_id", asym_id} );
appendUnlessSet(atom, { "auth_seq_id", 1} );
......@@ -2288,26 +2290,9 @@ Branch& Structure::createBranch(std::vector<std::vector<cif::Item>> &nag_atoms)
auto &&[row, inserted] = atom_site.emplace(atom.begin(), atom.end());
auto &newAtom = emplace_atom(std::make_shared<Atom::AtomImpl>(db, atom_id, row));
atoms.push_back(newAtom);
sugar.addAtom(newAtom);
}
return createBranch(atoms);
}
Branch& Structure::createBranch(std::vector<Atom> &nag_atoms)
{
using namespace cif::literals;
cif::Datablock &db = datablock();
auto &struct_asym = db["struct_asym"];
std::string asym_id = struct_asym.getUniqueID();
auto &branch = mBranches.emplace_back(*this, asym_id);
auto &sugar = branch.emplace_back(branch, "NAG", asym_id, 1);
for (auto &atom : nag_atoms)
sugar.addAtom(atom);
// now we can create the entity and get the real ID
auto entity_id = createEntityForBranch(branch);
......@@ -2342,7 +2327,8 @@ Branch& Structure::createBranch(std::vector<Atom> &nag_atoms)
return branch;
}
Branch& Structure::extendBranch(const std::string &asym_id, std::vector<std::vector<cif::Item>> &atom_info)
Branch& Structure::extendBranch(const std::string &asym_id, std::vector<std::vector<cif::Item>> &atom_info,
int link_sugar, const std::string &link_atom)
{
// sanity check
std::string compoundID;
......@@ -2376,7 +2362,15 @@ Branch& Structure::extendBranch(const std::string &asym_id, std::vector<std::vec
ai.emplace_back(std::move(i));
};
std::vector<Atom> atoms;
auto bi = std::find_if(mBranches.begin(), mBranches.end(), [asym_id](Branch &b) { return b.asymID() == asym_id; });
if (bi == mBranches.end())
throw std::logic_error("Create a branch first!");
Branch &branch = *bi;
int sugarNum = branch.size() + 1;
auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum);
for (auto &atom : atom_info)
{
......@@ -2385,41 +2379,19 @@ Branch& Structure::extendBranch(const std::string &asym_id, std::vector<std::vec
appendUnlessSet(atom, { "group_PDB", "HETATM"} );
appendUnlessSet(atom, { "id", atom_id} );
appendUnlessSet(atom, { "label_comp_id", compoundID} );
appendUnlessSet(atom, { "label_asym_id", asym_id} );
appendUnlessSet(atom, { "label_seq_id", "."} );
appendUnlessSet(atom, { "label_entity_id", tmp_entity_id} );
appendUnlessSet(atom, { "auth_comp_id", compoundID} );
appendUnlessSet(atom, { "auth_asym_id", asym_id} );
// appendUnlessSet(atom, { "auth_seq_id", sugarNum} );
appendUnlessSet(atom, { "pdbx_PDB_model_num", 1} );
appendUnlessSet(atom, { "label_alt_id", ""} );
auto &&[row, inserted] = atom_site.emplace(atom.begin(), atom.end());
auto &newAtom = emplace_atom(std::make_shared<Atom::AtomImpl>(db, atom_id, row));
atoms.push_back(newAtom);
sugar.addAtom(newAtom);
}
return extendBranch(asym_id, atoms);
}
Branch& Structure::extendBranch(const std::string &asym_id, std::vector<Atom> &atoms)
{
using namespace cif::literals;
std::string compoundID = atoms.front().labelCompID();
cif::Datablock &db = datablock();
auto bi = std::find_if(mBranches.begin(), mBranches.end(), [asym_id](Branch &b) { return b.asymID() == asym_id; });
if (bi == mBranches.end())
throw std::logic_error("Create a branch first!");
Branch &branch = *bi;
int sugarNum = branch.size() + 1;
auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum);
sugar.setLink(branch.at(link_sugar - 1).atomByID(link_atom));
auto entity_id = createEntityForBranch(branch);
......@@ -2429,9 +2401,6 @@ Branch& Structure::extendBranch(const std::string &asym_id, std::vector<Atom> &a
atom.set_property("label_entity_id", entity_id);
}
for (auto &atom : atoms)
sugar.addAtom(atom);
auto &pdbx_branch_scheme = db["pdbx_branch_scheme"];
pdbx_branch_scheme.erase("asym_id"_key == asym_id);
......@@ -2455,7 +2424,7 @@ Branch& Structure::extendBranch(const std::string &asym_id, std::vector<Atom> &a
{ "hetero", "n" }
});
}
return branch;
}
......@@ -2500,6 +2469,34 @@ std::string Structure::createEntityForBranch(Branch &branch)
});
}
auto &pdbx_entity_branch_link = mDb["pdbx_entity_branch_link"];
pdbx_entity_branch_link.erase("entity_id"_key == entityID);
for (auto &s1 : branch)
{
auto l1 = s1.getLink();
if (not l1)
continue;
auto &s2 = branch.at(std::stoi(l1.authSeqID()) - 1);
auto l2 = s2.atomByID("C1");
pdbx_entity_branch_link.emplace({
{ "link_id", pdbx_entity_branch_link.getUniqueID("") },
{ "entity_id", entityID },
{ "entity_branch_list_num_1", s2.authSeqID() },
{ "comp_id_1", s2.compoundID() },
{ "atom_id_1", l2.labelAtomID() },
{ "leaving_atom_id_1", "O1" },
{ "entity_branch_list_num_2", s1.authSeqID() },
{ "comp_id_2", s1.compoundID() },
{ "atom_id_2", l1.labelAtomID() },
{ "leaving_atom_id_2", "H" + l1.labelAtomID() },
{ "value_order", "sing" }
});
}
return entityID;
}
......
......@@ -31,6 +31,7 @@
#include "cif++/Cif++.hpp"
#include "cif++/Structure.hpp"
#include "cif++/CifValidator.hpp"
// --------------------------------------------------------------------
......@@ -113,7 +114,15 @@ BOOST_AUTO_TEST_CASE(create_sugar_1)
s.removeResidue(NAG);
auto &branch = s.createBranch(nagAtoms);
std::vector<std::vector<cif::Item>> ai;
auto &db = s.datablock();
auto &as = db["atom_site"];
for (auto r : as.find("label_asym_id"_key == "L" and "auth_seq_id"_key == 1))
ai.emplace_back(r.begin(), r.end());
auto &branch = s.createBranch(ai);
BOOST_CHECK_EQUAL(branch.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose");
BOOST_CHECK_EQUAL(branch.size(), 1);
......@@ -134,13 +143,21 @@ BOOST_AUTO_TEST_CASE(create_sugar_2)
BOOST_CHECK_EQUAL(bH.size(), 2);
auto a_sH1 = bH[0].atoms();
auto a_sH2 = bH[1].atoms();
std::vector<std::vector<cif::Item>> ai[2];
auto &db = s.datablock();
auto &as = db["atom_site"];
for (size_t i = 0; i < 2; ++i)
{
for (auto r : as.find("label_asym_id"_key == "H" and "auth_seq_id"_key == i))
ai[i].emplace_back(r.begin(), r.end());
}
s.removeBranch(bH);
auto &bN = s.createBranch(a_sH1);
s.extendBranch(bN.asymID(), a_sH2);
auto &bN = s.createBranch(ai[0]);
s.extendBranch(bN.asymID(), ai[1], 1, "O4");
BOOST_CHECK_EQUAL(bN.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose-(1-4)-2-acetamido-2-deoxy-beta-D-glucopyranose");
BOOST_CHECK_EQUAL(bN.size(), 2);
......
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