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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
205 additions
and
205 deletions
+205
-205
src/model.cpp
+152
-152
test/sugar-test.cpp
+53
-53
No files found.
src/model.cpp
View file @
85885406
...
@@ -2388,181 +2388,181 @@ branch &structure::create_branch()
...
@@ -2388,181 +2388,181 @@ branch &structure::create_branch()
return
m_branches
.
emplace_back
(
*
this
,
asym_id
,
entity_id
);
return
m_branches
.
emplace_back
(
*
this
,
asym_id
,
entity_id
);
}
}
branch
&
structure
::
create_branch
(
std
::
vector
<
row_initializer
>
atoms
)
// 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")
// // // sanity check
// throw std::logic_error("The first sugar in a branch should be a NAG");
// // 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;
// }
// }
// 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)
// 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("");
// // // sanity check
// // std::string compoundID;
// atom.set_value("id", atom_id);
// // for (auto &atom : atom_info)
// atom.set_value("label_asym_id", asym_id);
// // {
// atom.set_value("auth_asym_id", asym_id);
// // for (const auto &[name, value] : atom)
// atom.set_value("label_entity_id", entity_id);
// // {
// atom.set_value({ "auth_seq_id", 1 });
// // if (name != "label_comp_id")
// // continue;
//
atom.set_value_if_empty({"group_PDB", "HETATM"});
//
// if (compoundID.empty())
//
atom.set_value_if_empty({"label_comp_id", "NAG"})
;
//
// compoundID = value
;
//
atom.set_value_if_empty({"label_seq_id", "."});
//
// else if (value != compoundID)
//
atom.set_value_if_empty({"auth_comp_id", "NAG"}
);
//
// throw std::logic_error("All atoms should be of the same type"
);
//
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())
;
//
// using namespace literals
;
// auto &newAtom = emplace_atom(std::make_shared<atom::atom_impl>(m_db, atom_id));
// // // auto &branch = m_branches.emplace_back(*this, asym_id);
// sugar.add_atom(newAtom);
// // auto tmp_entity_id = m_db["entity"].get_unique_id("");
// }
// // // now we can create the entity and get the real ID
// // auto &atom_site = m_db["atom_site"];
// // auto entity_id = create_entity_for_branch(branch);
// // assert(not entity_id.empty());
// for (auto &a : sugar.atoms())
// // auto bi = std::find_if(m_branches.begin(), m_branches.end(), [asym_id](branch &b)
// a.set_property("label_entity_id", entity_id);
// // { return b.get_asym_id() == asym_id; });
// // if (bi == m_branches.end())
// // throw std::logic_error("Create a branch first!");
// m_db["pdbx_branch_scheme"].emplace({
// // branch &branch = *bi;
// {"asym_id", asym_id},
// {"entity_id", entity_id},
// {"num", 1},
// {"mon_id", "NAG"},
// {"pdb_asym_id", asym_id},
// // int sugarNum = static_cast<int>(branch.size() + 1);
// {"pdb_seq_num", 1},
// {"pdb_mon_id", "NAG"},
// // TODO: need fix, collect from nag_atoms?
// // auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum);
// {"auth_asym_id", asym_id},
// {"auth_mon_id", "NAG"},
// {"auth_seq_num", 1},
// {"hetero", "n"}
// // for (auto &atom : atom_info)
// });
// // {
// // auto atom_id = atom_site.get_unique_id("");
// return branch;
// // 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 });
branch
&
structure
::
extend_branch
(
const
std
::
string
&
asym_id
,
std
::
vector
<
row_initializer
>
atom_info
,
// // atom.set_value_if_empty({"group_PDB", "HETATM"});
int
link_sugar
,
const
std
::
string
&
link_atom
)
// // atom.set_value_if_empty({"label_comp_id", compoundID});
{
// // atom.set_value_if_empty({"auth_comp_id", compoundID});
// // sanity check
// // atom.set_value_if_empty({"pdbx_PDB_model_num", 1});
// std::string compoundID;
// // atom.set_value_if_empty({"label_alt_id", ""});
// for (auto &atom : atom_info)
// {
// for (const auto &[name, value] : atom)
// {
// if (name != "label_comp_id")
// continue;
// if (compoundID.empty())
// compoundID = value;
// else if (value != compoundID)
// throw std::logic_error("All atoms should be of the same type");
// }
// }
// using namespace literals;
// // auto &branch = m_branches.emplace_back(*this, asym_id);
// // auto row = atom_site.emplace(atom.begin(), atom.end());
// auto tmp_entity_id = m_db["entity"].get_unique_id("");
// auto &atom_site = m_db["atom_site"];
// // auto &newAtom = emplace_atom(std::make_shared<atom::atom_impl>(m_db, atom_id));
// // sugar.add_atom(newAtom);
// // }
// auto bi = std::find_if(m_branches.begin(), m_branches.end(), [asym_id](branch &b)
// // sugar.set_link(branch.at(link_sugar - 1).get_atom_by_atom_id(link_atom));
// { return b.get_asym_id() == asym_id; });
// if (bi == m_branches.end())
// throw std::logic_error("Create a branch first!");
// branch &branch = *bi;
// // auto entity_id = create_entity_for_branch(branch);
// int sugarNum = static_cast<int>(branch.size() + 1);
// auto &sugar = branch.emplace_back(branch, compoundID, asym_id, sugarNum);
// for (auto &atom : atom_info)
// {
// 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", tmp_entity_id);
// atom.set_value({"auth_seq_id", sugarNum });
// 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 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);
// }
// sugar.set_link(branch.at(link_sugar - 1).get_atom_by_atom_id(link_atom));
// auto entity_id = create_entity_for_branch(branch);
// // 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;
// for (auto &s2 : branch)
// {
// for (auto atom : s2.atoms())
// atom.set_property("label_entity_id", entity_id);
// }
// auto &pdbx_branch_scheme = m_db["pdbx_branch_scheme"];
// pdbx_branch_scheme.erase("asym_id"_key == asym_id);
// for (auto &s2 : branch)
// // // Update the entity id of the asym
// {
// // auto &struct_asym = m_db["struct_asym"];
// pdbx_branch_scheme.emplace({
// // auto r = struct_asym.find1("id"_key == asym_id);
// {"asym_id", asym_id},
// // r["entity_id"] = entity_id;
// {"entity_id", entity_id},
// {"num", s2.num()},
// // for (auto &s2 : branch)
// {"mon_id", s2.get_compound_id()},
// // {
// // for (auto atom : s2.atoms())
// {"pdb_asym_id", asym_id},
// // atom.set_property("label_entity_id", entity_id);
// {"pdb_seq_num", s2.num()},
// // }
// {"pdb_mon_id", s2.get_compound_id()},
// // auto &pdbx_branch_scheme = m_db["pdbx_branch_scheme"];
// // TODO: need fix, collect from nag_atoms?
// // pdbx_branch_scheme.erase("asym_id"_key == asym_id);
// {"auth_asym_id", asym_id},
// {"auth_mon_id", s2.get_compound_id()},
// // for (auto &s2 : branch)
// {"auth_seq_num", s2.get_auth_seq_id()},
// // {
// // pdbx_branch_scheme.emplace({
// {"hetero", "n"}
// // {"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
)
std
::
string
structure
::
create_entity_for_branch
(
branch
&
branch
)
{
{
using
namespace
literals
;
using
namespace
literals
;
...
...
test/sugar-test.cpp
View file @
85885406
...
@@ -96,87 +96,87 @@ BOOST_AUTO_TEST_CASE(sugar_name_1)
...
@@ -96,87 +96,87 @@ BOOST_AUTO_TEST_CASE(sugar_name_1)
}
}
}
}
// --------------------------------------------------------------------
//
//
--------------------------------------------------------------------
BOOST_AUTO_TEST_CASE
(
create_sugar_1
)
//
BOOST_AUTO_TEST_CASE(create_sugar_1)
{
//
{
using
namespace
cif
::
literals
;
//
using namespace cif::literals;
const
std
::
filesystem
::
path
example
(
gTestDir
/
"1juh.cif.gz"
);
//
const std::filesystem::path example(gTestDir / "1juh.cif.gz");
cif
::
file
file
(
example
.
string
());
//
cif::file file(example.string());
cif
::
mm
::
structure
s
(
file
);
//
cif::mm::structure s(file);
// collect atoms from asym L first
//
// collect atoms from asym L first
auto
&
NAG
=
s
.
get_residue
(
"L"
);
//
auto &NAG = s.get_residue("L");
auto
nagAtoms
=
NAG
.
atoms
();
//
auto nagAtoms = NAG.atoms();
std
::
vector
<
cif
::
row_initializer
>
ai
;
//
std::vector<cif::row_initializer> ai;
auto
&
db
=
s
.
get_datablock
();
//
auto &db = s.get_datablock();
auto
&
as
=
db
[
"atom_site"
];
//
auto &as = db["atom_site"];
// NOTE, row_initializer does not actually hold the data, so copy it first
//
// NOTE, row_initializer does not actually hold the data, so copy it first
// before it gets destroyed by remove_residue
//
// before it gets destroyed by remove_residue
for
(
auto
r
:
as
.
find
(
"label_asym_id"
_key
==
"L"
))
//
for (auto r : as.find("label_asym_id"_key == "L"))
/*auto &ri = */
ai
.
emplace_back
(
r
);
//
/*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.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose");
BOOST_CHECK_EQUAL
(
branch
.
size
(),
1
);
//
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
)
//
BOOST_AUTO_TEST_CASE(create_sugar_2)
{
//
{
using
namespace
cif
::
literals
;
//
using namespace cif::literals;
const
std
::
filesystem
::
path
example
(
gTestDir
/
"1juh.cif.gz"
);
//
const std::filesystem::path example(gTestDir / "1juh.cif.gz");
cif
::
file
file
(
example
.
string
());
//
cif::file file(example.string());
cif
::
mm
::
structure
s
(
file
);
//
cif::mm::structure s(file);
// Get branch for H
//
// Get branch for H
auto
&
bH
=
s
.
get_branch_by_asym_id
(
"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 &db = s.get_datablock();
auto
&
as
=
db
[
"atom_site"
];
//
auto &as = db["atom_site"];
for
(
size_t
i
=
0
;
i
<
2
;
++
i
)
//
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
))
//
for (auto r : as.find("label_asym_id"_key == "H" and "auth_seq_id"_key == i + 1))
/*auto &ri = */
ai
[
i
].
emplace_back
(
r
);
//
/*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
]);
//
auto &bN = s.create_branch(ai[0]);
s
.
extend_branch
(
bN
.
get_asym_id
(),
ai
[
1
],
1
,
"O4"
);
//
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.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.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