Commit 1f08498d by Maarten L. Hekkelman

Merge branch 'develop' of github.com:PDB-REDO/libcifpp into develop

parents 49ba714a 85fd9296
......@@ -511,7 +511,7 @@ class Branch : public std::vector<Sugar>
std::string name() const;
float weight() const;
std::string asymID() const { return mAsymID; }
std::string asymID() const { return mAsymID; }
Structure &structure() { return *mStructure; }
const Structure &structure() const { return *mStructure; }
......@@ -601,12 +601,12 @@ class Structure
const Polymer &getPolymerByAsymID(const std::string &asymID) const
{
return const_cast<Structure*>(this)->getPolymerByAsymID(asymID);
return const_cast<Structure *>(this)->getPolymerByAsymID(asymID);
}
const std::list<Branch> &branches() const { return mBranches; }
std::list<Branch> &branches() { return mBranches; }
Branch &getBranchByAsymID(const std::string &asymID);
const Branch &getBranchByAsymID(const std::string &asymID) const;
......@@ -624,13 +624,25 @@ class Structure
/// \brief Return the atom closest to point \a p with atom type \a type in a residue of type \a res_type
Atom getAtomByPositionAndType(Point p, std::string_view type, std::string_view res_type) const;
/// \brief Get a non-poly residue for an asym with id \a asymID
Residue &getResidue(const std::string &asymID)
{
return getResidue(asymID, 0, "");
}
/// \brief Get a non-poly residue for an asym with id \a asymID
const Residue &getResidue(const std::string &asymID) const
{
return getResidue(asymID, 0, "");
}
/// \brief Get a residue for an asym with id \a asymID seq id \a seqID and authSeqID \a authSeqID
Residue &getResidue(const std::string &asymID, int seqID, const std::string &authSeqID);
/// \brief Get a the single residue for an asym with id \a asymID seq id \a seqID and authSeqID \a authSeqID
const Residue &getResidue(const std::string &asymID, int seqID, const std::string &authSeqID) const
{
return const_cast<Structure*>(this)->getResidue(asymID, seqID, authSeqID);
return const_cast<Structure *>(this)->getResidue(asymID, seqID, authSeqID);
}
/// \brief Get a residue for an asym with id \a asymID, compound id \a compID, seq id \a seqID and authSeqID \a authSeqID
......@@ -639,16 +651,7 @@ class Structure
/// \brief Get a residue for an asym with id \a asymID, compound id \a compID, seq id \a seqID and authSeqID \a authSeqID
const Residue &getResidue(const std::string &asymID, const std::string &compID, int seqID, const std::string &authSeqID) const
{
return const_cast<Structure*>(this)->getResidue(asymID, compID, seqID, authSeqID);
}
/// \brief Get a the single residue for an asym with id \a asymID
Residue &getResidue(const std::string &asymID);
/// \brief Get a the single residue for an asym with id \a asymID
const Residue &getResidue(const std::string &asymID) const
{
return const_cast<Structure*>(this)->getResidue(asymID);
return const_cast<Structure *>(this)->getResidue(asymID, compID, seqID, authSeqID);
}
/// \brief Get a the residue for atom \a atom
......@@ -665,8 +668,8 @@ class Structure
// Actions
void removeAtom(Atom &a);
void swapAtoms(Atom &a1, Atom &a2); // swap the labels for these atoms
void moveAtom(Atom &a, Point p); // move atom to a new location
void swapAtoms(Atom a1, Atom a2); // swap the labels for these atoms
void moveAtom(Atom a, Point p); // move atom to a new location
void changeResidue(Residue &res, const std::string &newCompound,
const std::vector<std::tuple<std::string, std::string>> &remappedAtoms);
......@@ -692,10 +695,10 @@ class Structure
std::string createNonpoly(const std::string &entity_id, std::vector<std::vector<cif::Item>> &atom_info);
/// \brief Create a new (sugar) branch with one first NAG containing atoms \a nag_atoms
Branch& createBranch(std::vector<std::vector<cif::Item>> &nag_atoms);
Branch &createBranch(std::vector<std::vector<cif::Item>> &nag_atoms);
/// \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<std::vector<cif::Item>> &atoms);
Branch &extendBranch(const std::string &asym_id, std::vector<std::vector<cif::Item>> &atoms);
/// \brief Remove a residue, can be monomer or nonpoly
///
......
......@@ -1625,26 +1625,13 @@ Polymer &Structure::getPolymerByAsymID(const std::string &asymID)
throw std::runtime_error("Polymer with asym id " + asymID + " not found");
}
Residue &Structure::getResidue(const std::string &asymID)
{
for (auto &res : mNonPolymers)
{
if (res.asymID() != asymID)
continue;
return res;
}
throw std::out_of_range("Could not find residue " + asymID);
}
Residue &Structure::getResidue(const std::string &asymID, int seqID, const std::string &authSeqID)
{
if (seqID == 0)
{
for (auto &res : mNonPolymers)
{
if (res.asymID() == asymID and res.authSeqID() == authSeqID)
if (res.asymID() == asymID and (authSeqID.empty() or res.authSeqID() == authSeqID))
return res;
}
}
......@@ -1835,11 +1822,7 @@ void Structure::removeAtom(Atom &a)
assert(L <= R);
}
// void Structure::removeResidue(const std::string &asym_id, int seq_id)
// {
// }
void Structure::swapAtoms(Atom &a1, Atom &a2)
void Structure::swapAtoms(Atom a1, Atom a2)
{
cif::Datablock &db = datablock();
auto &atomSites = db["atom_site"];
......@@ -1867,7 +1850,7 @@ void Structure::swapAtoms(Atom &a1, Atom &a2)
l3.swap(l4);
}
void Structure::moveAtom(Atom &a, Point p)
void Structure::moveAtom(Atom a, Point p)
{
a.location(p);
}
......
......@@ -321,4 +321,26 @@ BOOST_AUTO_TEST_CASE(atom_numbers_1)
}
BOOST_ASSERT(ai == atoms.end());
}
\ No newline at end of file
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(test_load_1)
{
using namespace cif::literals;
const std::filesystem::path example(gTestDir / ".." / "examples" / "1cbs.cif.gz");
mmcif::File file(example.string());
auto &db = file.data();
mmcif::Structure s(file);
BOOST_CHECK(s.polymers().size() == 1);
auto &pdbx_poly_seq_scheme = db["pdbx_poly_seq_scheme"];
for (auto &poly : s.polymers())
{
BOOST_CHECK_EQUAL(poly.size(), pdbx_poly_seq_scheme.find("asym_id"_key == poly.asymID()).size());
}
}
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