Commit d5134000 by Maarten L. Hekkelman

- fix new row iterators

- Residue constructor for sugars
parent 6f93fa37
......@@ -16,3 +16,4 @@ libtool
rsrc/lib-version.txt
version-info*.txt
src/revision.hpp
test/pdb2cif-test
......@@ -484,59 +484,8 @@ class Structure
/// Will asssign new atom_id's to all atoms. Be carefull
void sortAtoms();
// // iterator for all residues
// class residue_iterator : public std::iterator<std::forward_iterator_tag, const Residue>
// {
// public:
// typedef std::iterator<std::forward_iterator_tag, const Residue> baseType;
// typedef typename baseType::pointer pointer;
// typedef typename baseType::reference reference;
// typedef std::list<Polymer>::const_iterator poly_iterator;
// residue_iterator(const Structure* s, poly_iterator polyIter, size_t polyResIndex, size_t nonPolyIndex);
// reference operator*();
// pointer operator->();
// residue_iterator& operator++();
// residue_iterator operator++(int);
// bool operator==(const residue_iterator& rhs) const;
// bool operator!=(const residue_iterator& rhs) const;
// private:
// const Structure& mStructure;
// poly_iterator mPolyIter;
// size_t mPolyResIndex;
// size_t mNonPolyIndex;
// };
// class residue_view
// {
// public:
// residue_view(const Structure* s) : mStructure(s) {}
// residue_view(const residue_view& rhs) : mStructure(rhs.mStructure) {}
// residue_view& operator=(residue_view& rhs)
// {
// mStructure = rhs.mStructure;
// return *this;
// }
// residue_iterator begin() const { return residue_iterator(mStructure, mStructure->mPolymers.begin(), 0, 0); }
// residue_iterator end() const { return residue_iterator(mStructure, mStructure->mPolymers.end(), 0, mStructure->mNonPolymers.size()); }
// size_t size() const
// {
// size_t ps = std::accumulate(mStructure->mPolymers.begin(), mStructure->mPolymers.end(), 0UL, [](size_t s, auto& p) { return s + p.size(); });
// return ps + mStructure->mNonPolymers.size();
// }
// private:
// const Structure* mStructure;
// };
// residue_view residues() const { return residue_view(this); }
const std::vector<Residue>& getNonPolymers() const { return mNonPolymers; }
const std::vector<Residue>& getBranchResidues() const { return mBranchResidues; }
private:
friend Polymer;
......
......@@ -1741,7 +1741,17 @@ Category::iterator Category::begin()
Category::iterator Category::end()
{
return iterator(nullptr);
return iterator();
}
Category::const_iterator Category::cbegin() const
{
return const_iterator(mHead);
}
Category::const_iterator Category::cend() const
{
return const_iterator();
}
Category::const_iterator Category::begin() const
......@@ -1751,7 +1761,7 @@ Category::const_iterator Category::begin() const
Category::const_iterator Category::end() const
{
return const_iterator(nullptr);
return const_iterator();
}
bool Category::hasParent(Row r, const Category& parentCat, const ValidateLink& link) const
......
......@@ -716,21 +716,29 @@ std::ostream& operator<<(std::ostream& os, const Atom& atom)
// --------------------------------------------------------------------
// residue
// First constructor used to be for waters only, but now accepts sugars as well.
Residue::Residue(const Structure& structure, const std::string& compoundID,
const std::string& asymID, const std::string& authSeqID)
: mStructure(&structure), mCompoundID(compoundID)
, mAsymID(asymID), mAuthSeqID(authSeqID)
{
assert(mCompoundID == "HOH");
for (auto& a: mStructure->atoms())
{
if (a.labelAsymID() != mAsymID or
a.labelCompID() != mCompoundID)
continue;
if (not mAuthSeqID.empty() and a.authSeqID() != mAuthSeqID) // water!
if (compoundID == "HOH")
{
if (not mAuthSeqID.empty() and a.authSeqID() != mAuthSeqID)
continue;
}
else
{
if (mSeqID > 0 and a.labelSeqID() != mSeqID)
continue;
}
mAtoms.push_back(a);
}
......@@ -1842,6 +1850,25 @@ const Residue& Structure::getResidue(const std::string& asymID, const std::strin
}
}
if (seqID == 0)
{
for (auto& res: mNonPolymers)
{
if (res.asymID() != asymID or res.compoundID() != compID)
continue;
return res;
}
}
for (auto& res: mBranchResidues)
{
if (res.asymID() != asymID or res.compoundID() != compID or res.seqID() != seqID)
continue;
return res;
}
throw std::out_of_range("Could not find residue " + asymID + '/' + std::to_string(seqID));
}
......
......@@ -1154,6 +1154,41 @@ _test.name
// query tests
for (const auto& [id, name]: db["test"].rows<int, std::optional<std::string>>({ "id", "name" }))
{
switch (id)
{
case 1: BOOST_CHECK(name == "aap"); break;
case 2: BOOST_CHECK(name == "noot"); break;
case 3: BOOST_CHECK(name == "mies"); break;
case 4:
case 5: BOOST_CHECK(not name); break;
default:
BOOST_CHECK(false);
}
}
}
BOOST_AUTO_TEST_CASE(c3)
{
cif::VERBOSE = 1;
auto f = R"(data_TEST
#
loop_
_test.id
_test.name
1 aap
2 noot
3 mies
4 .
5 ?
)"_cf;
auto& db = f.firstDatablock();
// query tests
for (const auto& [id, name]: db["test"].find<int, std::optional<std::string>>(cif::All(), { "id", "name" }))
{
switch (id)
......
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