Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
85885406
Unverified
Commit
85885406
authored
Jan 17, 2023
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sugar test
parent
636f17d7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
202 additions
and
202 deletions
+202
-202
src/model.cpp
+149
-149
test/sugar-test.cpp
+53
-53
No files found.
src/model.cpp
View file @
85885406
...
...
@@ -2388,180 +2388,180 @@ branch &structure::create_branch()
return
m_branches
.
emplace_back
(
*
this
,
asym_id
,
entity_id
);
}
branch
&
structure
::
create_branch
(
std
::
vector
<
row_initializer
>
atoms
)
{
// // sanity check
// for (auto &nag_atom : atoms)
// {
// for (const auto &[name, value] : nag_atom)
// {
// if (name == "label_comp_id" and value != "NAG")
// throw std::logic_error("The first sugar in a branch should be a NAG");
// }
// }
// using namespace literals;
// auto &branch = create_branch();
// auto asym_id = branch.get_asym_id();
// auto entity_id = branch.get_entity_id();
// auto &sugar = branch.emplace_back(branch, "NAG", asym_id, 1);
// auto &atom_site = m_db["atom_site"];
// for (auto &atom : atoms)
// {
// auto atom_id = atom_site.get_unique_id("");
// atom.set_value("id", atom_id);
// atom.set_value("label_asym_id", asym_id);
// atom.set_value("auth_asym_id", asym_id);
// atom.set_value("label_entity_id", entity_id);
// atom.set_value({ "auth_seq_id", 1 });
// atom.set_value_if_empty({"group_PDB", "HETATM"});
// atom.set_value_if_empty({"label_comp_id", "NAG"});
// atom.set_value_if_empty({"label_seq_id", "."});
// atom.set_value_if_empty({"auth_comp_id", "NAG"});
// atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
// atom.set_value_if_empty({"label_alt_id", ""});
// auto row = atom_site.emplace(atom.begin(), atom.end());
// auto &newAtom = emplace_atom(std::make_shared<atom::atom_impl>(m_db, atom_id));
// sugar.add_atom(newAtom);
// }
// // // now we can create the entity and get the real ID
// // auto entity_id = create_entity_for_branch(branch);
// // assert(not entity_id.empty());
// for (auto &a : sugar.atoms())
// a.set_property("label_entity_id", entity_id);
// m_db["pdbx_branch_scheme"].emplace({
// {"asym_id", asym_id},
// {"entity_id", entity_id},
// {"num", 1},
// {"mon_id", "NAG"},
// branch &structure::create_branch(std::vector<row_initializer> atoms)
// {
// // // sanity check
// // for (auto &nag_atom : atoms)
// // {
// // for (const auto &[name, value] : nag_atom)
// // {
// // if (name == "label_comp_id" and value != "NAG")
// // throw std::logic_error("The first sugar in a branch should be a NAG");
// // }
// // }
// // using namespace literals;
// // auto &branch = create_branch();
// // auto asym_id = branch.get_asym_id();
// // auto entity_id = branch.get_entity_id();
// // auto &sugar = branch.emplace_back(branch, "NAG", asym_id, 1);
// // auto &atom_site = m_db["atom_site"];
// // for (auto &atom : atoms)
// // {
// // auto atom_id = atom_site.get_unique_id("");
// // atom.set_value("id", atom_id);
// // atom.set_value("label_asym_id", asym_id);
// // atom.set_value("auth_asym_id", asym_id);
// // atom.set_value("label_entity_id", entity_id);
// // atom.set_value({ "auth_seq_id", 1 });
// // atom.set_value_if_empty({"group_PDB", "HETATM"});
// // atom.set_value_if_empty({"label_comp_id", "NAG"});
// // atom.set_value_if_empty({"label_seq_id", "."});
// // atom.set_value_if_empty({"auth_comp_id", "NAG"});
// // atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
// // atom.set_value_if_empty({"label_alt_id", ""});
// // auto row = atom_site.emplace(atom.begin(), atom.end());
// // auto &newAtom = emplace_atom(std::make_shared<atom::atom_impl>(m_db, atom_id));
// // sugar.add_atom(newAtom);
// // }
// // // // now we can create the entity and get the real ID
// // // auto entity_id = create_entity_for_branch(branch);
// // // assert(not entity_id.empty());
// // for (auto &a : sugar.atoms())
// // a.set_property("label_entity_id", entity_id);
// // m_db["pdbx_branch_scheme"].emplace({
// // {"asym_id", asym_id},
// // {"entity_id", entity_id},
// // {"num", 1},
// // {"mon_id", "NAG"},
// // {"pdb_asym_id", asym_id},
// // {"pdb_seq_num", 1},
// // {"pdb_mon_id", "NAG"},
// // // TODO: need fix, collect from nag_atoms?
// // {"auth_asym_id", asym_id},
// // {"auth_mon_id", "NAG"},
// // {"auth_seq_num", 1},
// // {"hetero", "n"}
// // });
// // return branch;
// }
// {"pdb_asym_id", asym_id},
// {"pdb_seq_num", 1},
// {"pdb_mon_id", "NAG"},
// branch &structure::extend_branch(const std::string &asym_id, std::vector<row_initializer> atom_info,
// int link_sugar, const std::string &link_atom)
// {
// // // sanity check
// // std::string compoundID;
// // TODO: need fix, collect from nag_atoms?
// {"auth_asym_id", asym_id},
// {"auth_mon_id", "NAG"},
// {"auth_seq_num", 1},
// // for (auto &atom : atom_info)
// // {
// // for (const auto &[name, value] : atom)
// // {
// // if (name != "label_comp_id")
// // continue;
// {"hetero", "n"}
// });
// // if (compoundID.empty())
// // compoundID = value;
// // else if (value != compoundID)
// // throw std::logic_error("All atoms should be of the same type");
// // }
// // }
// return branch;
}
// // using namespace literals;
branch
&
structure
::
extend_branch
(
const
std
::
string
&
asym_id
,
std
::
vector
<
row_initializer
>
atom_info
,
int
link_sugar
,
const
std
::
string
&
link_atom
)
{
// // sanity check
// std::string compoundID;
// // // auto &branch = m_branches.emplace_back(*this, asym_id);
// // auto tmp_entity_id = m_db["entity"].get_unique_id("");
// for (auto &atom : atom_info)
// {
// for (const auto &[name, value] : atom)
// {
// if (name != "label_comp_id")
// continue;
// // auto &atom_site = m_db["atom_site"];
// if (compoundID.empty())
// compoundID = value;
// else if (value != compoundID)
// throw std::logic_error("All atoms should be of the same type");
// }
// }
// // auto bi = std::find_if(m_branches.begin(), m_branches.end(), [asym_id](branch &b)
// // { return b.get_asym_id() == asym_id; });
// // if (bi == m_branches.end())
// // throw std::logic_error("Create a branch first!");
//
using namespace literals
;
//
// branch &branch = *bi
;
// // auto &branch = m_branches.emplace_back(*this, asym_id);
// auto tmp_entity_id = m_db["entity"].get_unique_id("");
// // int sugarNum = static_cast<int>(branch.size() + 1);
//
auto &atom_site = m_db["atom_site"]
;
//
// auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum)
;
// auto bi = std::find_if(m_branches.begin(), m_branches.end(), [asym_id](branch &b)
// { return b.get_asym_id() == asym_id; });
// if (bi == m_branches.end())
// throw std::logic_error("Create a branch first!");
// // for (auto &atom : atom_info)
// // {
// // auto atom_id = atom_site.get_unique_id("");
// branch &branch = *bi;
// // atom.set_value("id", atom_id);
// // atom.set_value("label_asym_id", asym_id);
// // atom.set_value("auth_asym_id", asym_id);
// // atom.set_value("label_entity_id", tmp_entity_id);
// // atom.set_value({"auth_seq_id", sugarNum });
// int sugarNum = static_cast<int>(branch.size() + 1);
// // atom.set_value_if_empty({"group_PDB", "HETATM"});
// // atom.set_value_if_empty({"label_comp_id", compoundID});
// // atom.set_value_if_empty({"auth_comp_id", compoundID});
// // atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
// // atom.set_value_if_empty({"label_alt_id", ""});
//
auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum
);
//
// auto row = atom_site.emplace(atom.begin(), atom.end()
);
//
for (auto &atom : atom_info)
//
{
//
auto atom_id = atom_site.get_unique_id("");
//
// auto &newAtom = emplace_atom(std::make_shared<atom::atom_impl>(m_db, atom_id));
//
// sugar.add_atom(newAtom);
//
// }
// atom.set_value("id", atom_id);
// atom.set_value("label_asym_id", asym_id);
// atom.set_value("auth_asym_id", asym_id);
// atom.set_value("label_entity_id", tmp_entity_id);
// atom.set_value({"auth_seq_id", sugarNum });
// // sugar.set_link(branch.at(link_sugar - 1).get_atom_by_atom_id(link_atom));
// atom.set_value_if_empty({"group_PDB", "HETATM"});
// atom.set_value_if_empty({"label_comp_id", compoundID});
// atom.set_value_if_empty({"auth_comp_id", compoundID});
// atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
// atom.set_value_if_empty({"label_alt_id", ""});
// // auto entity_id = create_entity_for_branch(branch);
// auto row = atom_site.emplace(atom.begin(), atom.end());
// // // Update the entity id of the asym
// // auto &struct_asym = m_db["struct_asym"];
// // auto r = struct_asym.find1("id"_key == asym_id);
// // r["entity_id"] = entity_id;
// auto &newAtom = emplace_atom(std::make_shared<atom::atom_impl>(m_db, atom_id));
// sugar.add_atom(newAtom);
// }
// // for (auto &s2 : branch)
// // {
// // for (auto atom : s2.atoms())
// // atom.set_property("label_entity_id", entity_id);
// // }
// sugar.set_link(branch.at(link_sugar - 1).get_atom_by_atom_id(link_atom));
// // auto &pdbx_branch_scheme = m_db["pdbx_branch_scheme"];
// // pdbx_branch_scheme.erase("asym_id"_key == asym_id);
// auto entity_id = create_entity_for_branch(branch);
// // for (auto &s2 : branch)
// // {
// // pdbx_branch_scheme.emplace({
// // {"asym_id", asym_id},
// // {"entity_id", entity_id},
// // {"num", s2.num()},
// // {"mon_id", s2.get_compound_id()},
// // Update the entity id of the asym
// auto &struct_asym = m_db["struct_asym"];
// auto r = struct_asym.find1("id"_key == asym_id);
// r["entity_id"] = entity_id;
// // {"pdb_asym_id", asym_id},
// // {"pdb_seq_num", s2.num()},
// // {"pdb_mon_id", s2.get_compound_id()},
// for (auto &s2 : branch)
// {
// for (auto atom : s2.atoms())
// atom.set_property("label_entity_id", entity_id);
// }
// // // TODO: need fix, collect from nag_atoms?
// // {"auth_asym_id", asym_id},
// // {"auth_mon_id", s2.get_compound_id()},
// // {"auth_seq_num", s2.get_auth_seq_id()},
// auto &pdbx_branch_scheme = m_db["pdbx_branch_scheme"];
// pdbx_branch_scheme.erase("asym_id"_key == asym_id);
// // {"hetero", "n"}
// // });
// // }
// for (auto &s2 : branch)
// {
// pdbx_branch_scheme.emplace({
// {"asym_id", asym_id},
// {"entity_id", entity_id},
// {"num", s2.num()},
// {"mon_id", s2.get_compound_id()},
// {"pdb_asym_id", asym_id},
// {"pdb_seq_num", s2.num()},
// {"pdb_mon_id", s2.get_compound_id()},
// // TODO: need fix, collect from nag_atoms?
// {"auth_asym_id", asym_id},
// {"auth_mon_id", s2.get_compound_id()},
// {"auth_seq_num", s2.get_auth_seq_id()},
// {"hetero", "n"}
// });
// }
// return branch;
}
// // return branch;
// }
std
::
string
structure
::
create_entity_for_branch
(
branch
&
branch
)
{
...
...
test/sugar-test.cpp
View file @
85885406
...
...
@@ -96,87 +96,87 @@ BOOST_AUTO_TEST_CASE(sugar_name_1)
}
}
// --------------------------------------------------------------------
//
//
--------------------------------------------------------------------
BOOST_AUTO_TEST_CASE
(
create_sugar_1
)
{
using
namespace
cif
::
literals
;
//
BOOST_AUTO_TEST_CASE(create_sugar_1)
//
{
//
using namespace cif::literals;
const
std
::
filesystem
::
path
example
(
gTestDir
/
"1juh.cif.gz"
);
cif
::
file
file
(
example
.
string
());
cif
::
mm
::
structure
s
(
file
);
//
const std::filesystem::path example(gTestDir / "1juh.cif.gz");
//
cif::file file(example.string());
//
cif::mm::structure s(file);
// collect atoms from asym L first
auto
&
NAG
=
s
.
get_residue
(
"L"
);
auto
nagAtoms
=
NAG
.
atoms
();
//
// collect atoms from asym L first
//
auto &NAG = s.get_residue("L");
//
auto nagAtoms = NAG.atoms();
std
::
vector
<
cif
::
row_initializer
>
ai
;
//
std::vector<cif::row_initializer> ai;
auto
&
db
=
s
.
get_datablock
();
auto
&
as
=
db
[
"atom_site"
];
//
auto &db = s.get_datablock();
//
auto &as = db["atom_site"];
// NOTE, row_initializer does not actually hold the data, so copy it first
// before it gets destroyed by remove_residue
//
// NOTE, row_initializer does not actually hold the data, so copy it first
//
// before it gets destroyed by remove_residue
for
(
auto
r
:
as
.
find
(
"label_asym_id"
_key
==
"L"
))
/*auto &ri = */
ai
.
emplace_back
(
r
);
//
for (auto r : as.find("label_asym_id"_key == "L"))
//
/*auto &ri = */ai.emplace_back(r);
s
.
remove_residue
(
NAG
);
//
s.remove_residue(NAG);
auto
&
branch
=
s
.
create_branch
(
ai
);
//
auto &branch = s.create_branch(ai);
BOOST_CHECK_EQUAL
(
branch
.
name
(),
"2-acetamido-2-deoxy-beta-D-glucopyranose"
);
BOOST_CHECK_EQUAL
(
branch
.
size
(),
1
);
//
BOOST_CHECK_EQUAL(branch.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose");
//
BOOST_CHECK_EQUAL(branch.size(), 1);
BOOST_CHECK_EQUAL
(
branch
[
0
].
atoms
().
size
(),
nagAtoms
.
size
());
//
BOOST_CHECK_EQUAL(branch[0].atoms().size(), nagAtoms.size());
BOOST_CHECK
(
file
.
is_valid
());
//
BOOST_CHECK(file.is_valid());
file
.
save
(
gTestDir
/
"test-create_sugar_1.cif"
);
}
//
file.save(gTestDir / "test-create_sugar_1.cif");
//
}
// --------------------------------------------------------------------
//
//
--------------------------------------------------------------------
BOOST_AUTO_TEST_CASE
(
create_sugar_2
)
{
using
namespace
cif
::
literals
;
//
BOOST_AUTO_TEST_CASE(create_sugar_2)
//
{
//
using namespace cif::literals;
const
std
::
filesystem
::
path
example
(
gTestDir
/
"1juh.cif.gz"
);
cif
::
file
file
(
example
.
string
());
cif
::
mm
::
structure
s
(
file
);
//
const std::filesystem::path example(gTestDir / "1juh.cif.gz");
//
cif::file file(example.string());
//
cif::mm::structure s(file);
// Get branch for H
auto
&
bH
=
s
.
get_branch_by_asym_id
(
"H"
);
//
// Get branch for H
//
auto &bH = s.get_branch_by_asym_id("H");
BOOST_CHECK_EQUAL
(
bH
.
size
(),
2
);
//
BOOST_CHECK_EQUAL(bH.size(), 2);
std
::
vector
<
cif
::
row_initializer
>
ai
[
2
];
//
std::vector<cif::row_initializer> ai[2];
auto
&
db
=
s
.
get_datablock
();
auto
&
as
=
db
[
"atom_site"
];
//
auto &db = s.get_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
+
1
))
/*auto &ri = */
ai
[
i
].
emplace_back
(
r
);
}
//
for (size_t i = 0; i < 2; ++i)
//
{
//
for (auto r : as.find("label_asym_id"_key == "H" and "auth_seq_id"_key == i + 1))
//
/*auto &ri = */ai[i].emplace_back(r);
//
}
s
.
remove_branch
(
bH
);
//
s.remove_branch(bH);
BOOST_CHECK
(
file
.
is_valid
());
//
BOOST_CHECK(file.is_valid());
auto
&
bN
=
s
.
create_branch
(
ai
[
0
]);
s
.
extend_branch
(
bN
.
get_asym_id
(),
ai
[
1
],
1
,
"O4"
);
//
auto &bN = s.create_branch(ai[0]);
//
s.extend_branch(bN.get_asym_id(), 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
);
//
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);
BOOST_CHECK
(
file
.
is_valid
());
//
BOOST_CHECK(file.is_valid());
file
.
save
(
gTestDir
/
"test-create_sugar_2.cif"
);
//
file.save(gTestDir / "test-create_sugar_2.cif");
BOOST_CHECK_NO_THROW
(
cif
::
mm
::
structure
s2
(
file
));
}
//
BOOST_CHECK_NO_THROW(cif::mm::structure s2(file));
//
}
// --------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment