Commit 6e3b85f4 by Maarten L. Hekkelman

getResidue, again

parent 58f1b626
...@@ -650,12 +650,15 @@ class Structure ...@@ -650,12 +650,15 @@ class Structure
} }
/// \brief Get a the residue for atom \a atom /// \brief Get a the residue for atom \a atom
Residue &getResidue(const mmcif::Atom &atom); Residue &getResidue(const mmcif::Atom &atom)
{
return getResidue(atom.labelAsymID(), atom.labelCompID(), atom.labelSeqID(), atom.authSeqID());
}
/// \brief Get a the residue for atom \a atom /// \brief Get a the residue for atom \a atom
const Residue &getResidue(const mmcif::Atom &atom) const const Residue &getResidue(const mmcif::Atom &atom) const
{ {
return const_cast<Structure*>(this)->getResidue(atom); return getResidue(atom.labelAsymID(), atom.labelCompID(), atom.labelSeqID(), atom.authSeqID());
} }
// map between auth and label locations // map between auth and label locations
......
...@@ -1460,43 +1460,35 @@ void Structure::loadData() ...@@ -1460,43 +1460,35 @@ void Structure::loadData()
// place atoms in residues // place atoms in residues
using key_type = std::tuple<std::string, int>; using key_type = std::tuple<std::string, int, std::string>;
using map_type = std::map<key_type, Residue *>; std::map<key_type, Residue *> resMap;
map_type resMap;
for (auto &poly : mPolymers) for (auto &poly : mPolymers)
{ {
for (auto &res : poly) for (auto &res : poly)
resMap[{res.asymID(), res.seqID()}] = &res; resMap[{res.asymID(), res.seqID(), res.authSeqID()}] = &res;
} }
for (auto &res : mNonPolymers) for (auto &res : mNonPolymers)
resMap[{res.asymID(), (res.isWater() ? std::stoi(res.mAuthSeqID) : res.seqID())}] = &res; resMap[{res.asymID(), res.seqID(), res.mAuthSeqID}] = &res;
std::set<std::string> sugars; std::set<std::string> sugars;
for (auto &branch : mBranches) for (auto &branch : mBranches)
{ {
for (auto &sugar : branch) for (auto &sugar : branch)
{ {
resMap[{sugar.asymID(), sugar.num()}] = &sugar; resMap[{sugar.asymID(), sugar.seqID(), sugar.authSeqID()}] = &sugar;
sugars.insert(sugar.compoundID()); sugars.insert(sugar.compoundID());
} }
} }
for (auto &atom : mAtoms) for (auto &atom : mAtoms)
{ {
key_type k(atom.labelAsymID(), atom.isWater() ? std::stoi(atom.authSeqID()) : atom.labelSeqID()); key_type k(atom.labelAsymID(), atom.labelSeqID(), atom.authSeqID());
auto ri = resMap.find(k); auto ri = resMap.find(k);
if (ri == resMap.end() and sugars.count(atom.labelCompID()))
{
k = { atom.labelAsymID(), std::stoi(atom.authSeqID()) };
ri = resMap.find(k);
}
if (ri == resMap.end()) if (ri == resMap.end())
{ {
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::cerr << "Missing residue for atom " << atom << std::endl; std::cerr << "Missing residue for atom " << atom << std::endl;
...@@ -1747,75 +1739,75 @@ Residue &Structure::getResidue(const std::string &asymID, const std::string &com ...@@ -1747,75 +1739,75 @@ Residue &Structure::getResidue(const std::string &asymID, const std::string &com
throw std::out_of_range("Could not find residue " + asymID + '/' + std::to_string(seqID) + '-' + authSeqID); throw std::out_of_range("Could not find residue " + asymID + '/' + std::to_string(seqID) + '-' + authSeqID);
} }
Residue &Structure::getResidue(const mmcif::Atom &atom) // Residue &Structure::getResidue(const mmcif::Atom &atom)
{ // {
using namespace cif::literals; // using namespace cif::literals;
auto asymID = atom.labelAsymID(); // auto asymID = atom.labelAsymID();
auto entityID = atom.labelEntityID(); // auto entityID = atom.labelEntityID();
auto type = mDb["entity"].find1<std::string>("id"_key == entityID, "type"); // auto type = mDb["entity"].find1<std::string>("id"_key == entityID, "type");
if (type == "water") // if (type == "water")
{ // {
auto authSeqID = atom.authSeqID(); // auto authSeqID = atom.authSeqID();
for (auto &res : mNonPolymers) // for (auto &res : mNonPolymers)
{ // {
if (res.asymID() != asymID or res.authSeqID() != authSeqID) // if (res.asymID() != asymID or res.authSeqID() != authSeqID)
continue; // continue;
return res; // return res;
} // }
throw std::out_of_range("Could not find water " + asymID + '/' + authSeqID); // throw std::out_of_range("Could not find water " + asymID + '/' + authSeqID);
} // }
else if (type == "branched") // else if (type == "branched")
{ // {
auto authSeqID = std::stoi(atom.authSeqID()); // auto authSeqID = std::stoi(atom.authSeqID());
for (auto &branch : mBranches) // for (auto &branch : mBranches)
{ // {
if (branch.asymID() != asymID) // if (branch.asymID() != asymID)
continue; // continue;
for (auto &sugar : branch) // for (auto &sugar : branch)
{ // {
if (sugar.asymID() == asymID and sugar.num() == authSeqID) // if (sugar.asymID() == asymID and sugar.num() == authSeqID)
return sugar; // return sugar;
} // }
} // }
throw std::out_of_range("Could not find sugar residue " + asymID + '/' + std::to_string(authSeqID)); // throw std::out_of_range("Could not find sugar residue " + asymID + '/' + std::to_string(authSeqID));
} // }
else if (type == "polymer") // else if (type == "polymer")
{ // {
auto seqID = atom.labelSeqID(); // auto seqID = atom.labelSeqID();
for (auto &poly : mPolymers) // for (auto &poly : mPolymers)
{ // {
if (poly.asymID() != asymID) // if (poly.asymID() != asymID)
continue; // continue;
for (auto &res : poly) // for (auto &res : poly)
{ // {
if (res.seqID() == seqID) // if (res.seqID() == seqID)
return res; // return res;
} // }
} // }
throw std::out_of_range("Could not find residue " + asymID + '/' + std::to_string(seqID)); // throw std::out_of_range("Could not find residue " + asymID + '/' + std::to_string(seqID));
} // }
for (auto &res : mNonPolymers) // for (auto &res : mNonPolymers)
{ // {
if (res.asymID() != asymID) // if (res.asymID() != asymID)
continue; // continue;
return res; // return res;
} // }
throw std::out_of_range("Could not find residue " + asymID); // throw std::out_of_range("Could not find residue " + asymID);
} // }
std::tuple<char, int, char> Structure::MapLabelToAuth( std::tuple<char, int, char> Structure::MapLabelToAuth(
const std::string &asymID, int seqID) const const std::string &asymID, int seqID) const
......
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