Commit 637b795a by Maarten L. Hekkelman

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

parents d88d5205 4de981a3
...@@ -321,13 +321,6 @@ class atom ...@@ -321,13 +321,6 @@ class atom
friend std::ostream &operator<<(std::ostream &os, const atom &atom); friend std::ostream &operator<<(std::ostream &os, const atom &atom);
// /// \brief Synchronize data with underlying cif data
// void sync()
// {
// if (m_impl)
// m_impl->prefetch();
// }
private: private:
friend class structure; friend class structure;
...@@ -341,25 +334,6 @@ class atom ...@@ -341,25 +334,6 @@ class atom
std::shared_ptr<atom_impl> m_impl; std::shared_ptr<atom_impl> m_impl;
}; };
// template <>
// inline std::string atom::get_property<std::string>(const std::string_view name) const
// {
// return get_property(name);
// }
// template <>
// inline int atom::get_property<int>(const std::string_view name) const
// {
// auto v = impl().get_property(name);
// return v.empty() ? 0 : stoi(v);
// }
// template <>
// inline float atom::get_property<float>(const std::string_view name) const
// {
// return stof(impl().get_property(name));
// }
inline void swap(atom &a, atom &b) inline void swap(atom &a, atom &b)
{ {
a.swap(b); a.swap(b);
...@@ -949,4 +923,11 @@ class structure ...@@ -949,4 +923,11 @@ class structure
std::vector<residue> m_non_polymers; std::vector<residue> m_non_polymers;
}; };
// --------------------------------------------------------------------
/// \brief Reconstruct all missing categories for an assumed PDBx file.
/// Some people believe that simply dumping some atom records is enough.
/// \param db The cif::datablock that hopefully contains some valid data
void reconstruct_pdbx(datablock &db);
} // namespace cif::mm } // namespace cif::mm
...@@ -618,20 +618,20 @@ float monomer::phi() const ...@@ -618,20 +618,20 @@ float monomer::phi() const
{ {
float result = 360; float result = 360;
try if (m_index > 0)
{ {
if (m_index > 0) auto &prev = m_polymer->operator[](m_index - 1);
if (prev.m_seq_id + 1 == m_seq_id)
{ {
auto &prev = m_polymer->operator[](m_index - 1); auto a1 = prev.C();
if (prev.m_seq_id + 1 == m_seq_id) auto a2 = N();
result = static_cast<float>(dihedral_angle(prev.C().get_location(), N().get_location(), CAlpha().get_location(), C().get_location())); auto a3 = CAlpha();
auto a4 = C();
if (a1 and a2 and a3 and a4)
result = dihedral_angle(a1.get_location(), a2.get_location(), a3.get_location(), a4.get_location());
} }
} }
catch (const std::exception &ex)
{
if (VERBOSE > 0)
std::cerr << ex.what() << std::endl;
}
return result; return result;
} }
...@@ -640,20 +640,20 @@ float monomer::psi() const ...@@ -640,20 +640,20 @@ float monomer::psi() const
{ {
float result = 360; float result = 360;
try if (m_index + 1 < m_polymer->size())
{ {
if (m_index + 1 < m_polymer->size()) auto &next = m_polymer->operator[](m_index + 1);
if (m_seq_id + 1 == next.m_seq_id)
{ {
auto &next = m_polymer->operator[](m_index + 1); auto a1 = N();
if (m_seq_id + 1 == next.m_seq_id) auto a2 = CAlpha();
result = static_cast<float>(dihedral_angle(N().get_location(), CAlpha().get_location(), C().get_location(), next.N().get_location())); auto a3 = C();
auto a4 = next.N();
if (a1 and a2 and a3 and a4)
result = dihedral_angle(a1.get_location(), a2.get_location(), a3.get_location(), a4.get_location());
} }
} }
catch (const std::exception &ex)
{
if (VERBOSE > 0)
std::cerr << ex.what() << std::endl;
}
return result; return result;
} }
...@@ -935,17 +935,17 @@ float monomer::omega(const monomer &a, const monomer &b) ...@@ -935,17 +935,17 @@ float monomer::omega(const monomer &a, const monomer &b)
{ {
float result = 360; float result = 360;
try auto a1 = a.get_atom_by_atom_id("CA");
{ auto a2 = a.get_atom_by_atom_id("C");
auto a3 = b.get_atom_by_atom_id("N");
auto a4 = b.get_atom_by_atom_id("CA");
if (a1 and a2 and a3 and a4)
result = static_cast<float>(dihedral_angle( result = static_cast<float>(dihedral_angle(
a.get_atom_by_atom_id("CA").get_location(), a1.get_location(),
a.get_atom_by_atom_id("C").get_location(), a2.get_location(),
b.get_atom_by_atom_id("N").get_location(), a3.get_location(),
b.get_atom_by_atom_id("CA").get_location())); a4.get_location()));
}
catch (...)
{
}
return result; return result;
} }
...@@ -974,8 +974,12 @@ polymer::polymer(structure &s, const std::string &entityID, const std::string &a ...@@ -974,8 +974,12 @@ polymer::polymer(structure &s, const std::string &entityID, const std::string &a
for (auto r : poly_seq_scheme.find("asym_id"_key == asym_id)) for (auto r : poly_seq_scheme.find("asym_id"_key == asym_id))
{ {
int seqID; int seqID;
std::optional<int> pdbSeqNum;
std::string compoundID, authSeqID, pdbInsCode; std::string compoundID, authSeqID, pdbInsCode;
cif::tie(seqID, authSeqID, compoundID, pdbInsCode) = r.get("seq_id", "auth_seq_num", "mon_id", "pdb_ins_code"); cif::tie(seqID, authSeqID, compoundID, pdbInsCode, pdbSeqNum) = r.get("seq_id", "auth_seq_num", "mon_id", "pdb_ins_code", "pdb_seq_num");
if (authSeqID.empty() and pdbSeqNum.has_value())
authSeqID = std::to_string(*pdbSeqNum);
size_t index = size(); size_t index = size();
...@@ -2773,4 +2777,14 @@ void structure::validate_atoms() const ...@@ -2773,4 +2777,14 @@ void structure::validate_atoms() const
assert(atoms.empty()); assert(atoms.empty());
} }
// --------------------------------------------------------------------
void reconstruct_pdbx(datablock &db)
{
if (db.get("atom_site") == nullptr)
throw std::runtime_error("Cannot reconstruct PDBx file, atom data missing");
}
} // namespace pdbx } // namespace pdbx
...@@ -3819,41 +3819,48 @@ void PDBFileParser::ConstructEntities() ...@@ -3819,41 +3819,48 @@ void PDBFileParser::ConstructEntities()
for (std::string monID : monIds) for (std::string monID : monIds)
{ {
std::string authMonID, authSeqNum, authInsCode; std::string authMonID, authSeqNum, authInsCode{'.'};
if (res.mSeen) if (res.mSeen)
{ {
authMonID = monID; authMonID = monID;
authSeqNum = std::to_string(res.mSeqNum); authSeqNum = std::to_string(res.mSeqNum);
if (res.mIcode != ' ' and res.mIcode != 0) if (res.mIcode != ' ' and res.mIcode != 0)
authInsCode = std::string{ res.mIcode }; authInsCode = std::string{ res.mIcode };
cat->emplace({
{ "asym_id", asymID },
{ "entity_id", mMolID2EntityID[chain.mMolID] },
{ "seq_id", seqID },
{ "mon_id", monID },
{ "ndb_seq_num", seqID },
{ "pdb_seq_num", res.mSeqNum },
{ "auth_seq_num", authSeqNum },
{ "pdb_mon_id", authMonID },
{ "auth_mon_id", authMonID },
{ "pdb_strand_id", std::string{ chain.mDbref.chainID } },
{ "pdb_ins_code", authInsCode },
{ "hetero", res.mAlts.empty() ? "n" : "y" } });
} }
else else
{ {
authMonID = res.mMonID;
authSeqNum = std::to_string(res.mSeqNum);
if (res.mIcode != ' ' and res.mIcode != 0) if (res.mIcode != ' ' and res.mIcode != 0)
authInsCode = std::string{ res.mIcode } + "A"; authInsCode = std::string{ res.mIcode } + "A";
else
authInsCode = "A";
}
if (authInsCode.empty())
authInsCode = ".";
cat->emplace({ cat->emplace({
{ "asym_id", asymID }, { "asym_id", asymID },
{ "entity_id", mMolID2EntityID[chain.mMolID] }, { "entity_id", mMolID2EntityID[chain.mMolID] },
{ "seq_id", seqID }, { "seq_id", seqID },
{ "mon_id", monID }, { "mon_id", monID },
{ "ndb_seq_num", seqID }, { "ndb_seq_num", seqID },
{ "pdb_seq_num", res.mSeqNum }, { "pdb_seq_num", res.mSeqNum },
{ "auth_seq_num", authSeqNum }, { "auth_seq_num", "." },
{ "pdb_mon_id", authMonID }, { "pdb_mon_id", "." },
{ "auth_mon_id", authMonID }, { "auth_mon_id", "." },
{ "pdb_strand_id", std::string{ chain.mDbref.chainID } }, { "pdb_strand_id", std::string{ chain.mDbref.chainID } },
{ "pdb_ins_code", authInsCode }, { "pdb_ins_code", authInsCode },
{ "hetero", res.mAlts.empty() ? "n" : "y" } }); { "hetero", res.mAlts.empty() ? "n" : "y" } });
}
} }
} }
} }
...@@ -6239,4 +6246,4 @@ file read(const std::filesystem::path &file) ...@@ -6239,4 +6246,4 @@ file read(const std::filesystem::path &file)
} }
} }
} // namespace pdbx } // namespace pdbx
\ No newline at end of file
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