Commit 4732004b by Maarten L. Hekkelman

Merge branch 'develop' into trunk

parents d4bd3faa faa9cd04
...@@ -792,7 +792,7 @@ class Row ...@@ -792,7 +792,7 @@ class Row
} }
void assign(const std::vector<Item> &values); void assign(const std::vector<Item> &values);
void assign(std::string_view name, const std::string &value, bool updateLinked); void assign(std::string_view name, const std::string &value, bool updateLinked, bool validate = true);
bool operator==(const Row &rhs) const bool operator==(const Row &rhs) const
{ {
...@@ -814,7 +814,7 @@ class Row ...@@ -814,7 +814,7 @@ class Row
friend std::ostream &operator<<(std::ostream &os, const Row &row); friend std::ostream &operator<<(std::ostream &os, const Row &row);
private: private:
void assign(size_t column, const std::string &value, bool updateLinked); void assign(size_t column, const std::string &value, bool updateLinked, bool validate = true);
void assign(const Item &i, bool updateLinked); void assign(const Item &i, bool updateLinked);
static void swap(size_t column, ItemRow *a, ItemRow *b); static void swap(size_t column, ItemRow *a, ItemRow *b);
...@@ -2152,6 +2152,7 @@ class Category ...@@ -2152,6 +2152,7 @@ class Category
std::vector<ItemColumn> mColumns; std::vector<ItemColumn> mColumns;
ItemRow *mHead; ItemRow *mHead;
ItemRow *mTail; ItemRow *mTail;
size_t mLastUniqueNr = 0;
class CatIndex *mIndex; class CatIndex *mIndex;
std::vector<Linked> mParentLinks, mChildLinks; std::vector<Linked> mParentLinks, mChildLinks;
......
...@@ -60,30 +60,101 @@ class File; ...@@ -60,30 +60,101 @@ class File;
class Atom class Atom
{ {
private:
struct AtomImpl : public std::enable_shared_from_this<AtomImpl>
{
AtomImpl(cif::Datablock &db, const std::string &id, cif::Row row);
// constructor for a symmetry copy of an atom
AtomImpl(const AtomImpl &impl, const Point &loc, const std::string &sym_op);
AtomImpl(const AtomImpl &i) = default;
void prefetch();
int compare(const AtomImpl &b) const;
bool getAnisoU(float anisou[6]) const;
void moveTo(const Point &p);
const Compound &comp() const;
const std::string get_property(const std::string_view name) const;
void set_property(const std::string_view name, const std::string &value);
const cif::Datablock &mDb;
std::string mID;
AtomType mType;
std::string mAtomID;
std::string mCompID;
std::string mAsymID;
int mSeqID;
std::string mAltID;
std::string mAuthSeqID;
Point mLocation;
int mRefcount;
cif::Row mRow;
mutable std::vector<std::tuple<std::string,cif::detail::ItemReference>> mCachedRefs;
mutable const Compound *mCompound = nullptr;
bool mSymmetryCopy = false;
bool mClone = false;
std::string mSymmetryOperator = "1_555";
};
public: public:
Atom();
Atom(struct AtomImpl *impl); Atom() {}
Atom(const Atom &rhs);
Atom(std::shared_ptr<AtomImpl> impl)
: mImpl(impl) {}
Atom(const Atom &rhs)
: mImpl(rhs.mImpl) {}
Atom(cif::Datablock &db, cif::Row &row); Atom(cif::Datablock &db, cif::Row &row);
// a special constructor to create symmetry copies // a special constructor to create symmetry copies
Atom(const Atom &rhs, const Point &symmmetry_location, const std::string &symmetry_operation); Atom(const Atom &rhs, const Point &symmmetry_location, const std::string &symmetry_operation);
~Atom(); explicit operator bool() const { return (bool)mImpl; }
explicit operator bool() const { return mImpl_ != nullptr; }
// return a copy of this atom, with data copied instead of referenced // return a copy of this atom, with data copied instead of referenced
Atom clone() const; Atom clone() const
{
auto copy = std::make_shared<AtomImpl>(*mImpl);
copy->mClone = true;
return Atom(copy);
}
Atom &operator=(const Atom &rhs) = default;
template <typename T>
T get_property(const std::string_view name) const;
Atom &operator=(const Atom &rhs); void set_property(const std::string_view name, const std::string &value)
{
mImpl->set_property(name, value);
}
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, int> = 0>
void property(const std::string_view name, const T &value)
{
set_property(name, std::to_string(value));
}
const std::string &id() const; const std::string &id() const { return mImpl->mID; }
AtomType type() const; AtomType type() const { return mImpl->mType; }
Point location() const; Point location() const { return mImpl->mLocation; }
void location(Point p); void location(Point p) { mImpl->moveTo(p); }
/// \brief Translate the position of this atom by \a t /// \brief Translate the position of this atom by \a t
void translate(Point t); void translate(Point t);
...@@ -91,47 +162,40 @@ class Atom ...@@ -91,47 +162,40 @@ class Atom
/// \brief Rotate the position of this atom by \a q /// \brief Rotate the position of this atom by \a q
void rotate(Quaternion q); void rotate(Quaternion q);
/// \brief Translate and rotate the position of this atom by \a t and \a q
void translateAndRotate(Point t, Quaternion q);
/// \brief Translate, rotate and translate again the coordinates this atom by \a t1 , \a q and \a t2
void translateRotateAndTranslate(Point t1, Quaternion q, Point t2);
// for direct access to underlying data, be careful! // for direct access to underlying data, be careful!
const cif::Row getRow() const; const cif::Row getRow() const { return mImpl->mRow; }
const cif::Row getRowAniso() const; const cif::Row getRowAniso() const;
// Atom symmetryCopy(const Point& d, const clipper::RTop_orth& rt); bool isSymmetryCopy() const { return mImpl->mSymmetryCopy; }
bool isSymmetryCopy() const; std::string symmetry() const { return mImpl->mSymmetryOperator; }
std::string symmetry() const;
// const clipper::RTop_orth& symop() const;
const Compound &comp() const; const Compound &comp() const { return mImpl->comp(); }
bool isWater() const; bool isWater() const { return mImpl->mCompID == "HOH" or mImpl->mCompID == "H2O" or mImpl->mCompID == "WAT"; }
int charge() const; int charge() const;
float uIso() const; float uIso() const;
bool getAnisoU(float anisou[6]) const; bool getAnisoU(float anisou[6]) const { return mImpl->getAnisoU(anisou); }
float occupancy() const; float occupancy() const;
template <typename T>
T property(const std::string_view name) const;
void property(const std::string_view name, const std::string &value);
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, int> = 0>
void property(const std::string_view name, const T &value)
{
property(name, std::to_string(value));
}
// specifications // specifications
const std::string& labelAtomID() const { return mAtomID; } const std::string& labelAtomID() const { return mImpl->mAtomID; }
const std::string& labelCompID() const { return mCompID; } const std::string& labelCompID() const { return mImpl->mCompID; }
const std::string& labelAsymID() const { return mAsymID; } const std::string& labelAsymID() const { return mImpl->mAsymID; }
std::string labelEntityID() const; std::string labelEntityID() const;
int labelSeqID() const { return mSeqID; } int labelSeqID() const { return mImpl->mSeqID; }
const std::string& labelAltID() const { return mAltID; } const std::string& labelAltID() const { return mImpl->mAltID; }
bool isAlternate() const { return not mAltID.empty(); } bool isAlternate() const { return not mImpl->mAltID.empty(); }
std::string authAtomID() const; std::string authAtomID() const;
std::string authCompID() const; std::string authCompID() const;
std::string authAsymID() const; std::string authAsymID() const;
const std::string& authSeqID() const { return mAuthSeqID; } const std::string& authSeqID() const { return mImpl->mAuthSeqID; }
std::string pdbxAuthInsCode() const; std::string pdbxAuthInsCode() const;
std::string pdbxAuthAltID() const; std::string pdbxAuthAltID() const;
...@@ -140,13 +204,6 @@ class Atom ...@@ -140,13 +204,6 @@ class Atom
bool operator==(const Atom &rhs) const; bool operator==(const Atom &rhs) const;
// // get clipper format Atom
// clipper::Atom toClipper() const;
// Radius calculation based on integrating the density until perc of electrons is found
void calculateRadius(float resHigh, float resLow, float perc);
float radius() const;
// access data in compound for this atom // access data in compound for this atom
// convenience routine // convenience routine
...@@ -158,16 +215,10 @@ class Atom ...@@ -158,16 +215,10 @@ class Atom
void swap(Atom &b) void swap(Atom &b)
{ {
std::swap(mImpl_, b.mImpl_); std::swap(mImpl, b.mImpl);
std::swap(mAtomID, b.mAtomID);
std::swap(mCompID, b.mCompID);
std::swap(mAsymID, b.mAsymID);
std::swap(mSeqID, b.mSeqID);
std::swap(mAltID, b.mAltID);
std::swap(mAuthSeqID, b.mAuthSeqID);
} }
int compare(const Atom &b) const; int compare(const Atom &b) const { return mImpl->compare(*b.mImpl); }
bool operator<(const Atom &rhs) const bool operator<(const Atom &rhs) const
{ {
...@@ -178,21 +229,30 @@ class Atom ...@@ -178,21 +229,30 @@ class Atom
private: private:
friend class Structure; friend class Structure;
void setID(int id); void setID(int id);
AtomImpl *impl(); std::shared_ptr<AtomImpl> mImpl;
const AtomImpl *impl() const; };
struct AtomImpl *mImpl_; template <>
inline std::string Atom::get_property<std::string>(const std::string_view name) const
{
return mImpl->get_property(name);
}
// cached values template <>
std::string mAtomID; inline int Atom::get_property<int>(const std::string_view name) const
std::string mCompID; {
std::string mAsymID; auto v = mImpl->get_property(name);
int mSeqID; return v.empty() ? 0 : stoi(v);
std::string mAltID; }
std::string mAuthSeqID;
}; template <>
inline float Atom::get_property<float>(const std::string_view name) const
{
return stof(mImpl->get_property(name));
}
inline void swap(mmcif::Atom &a, mmcif::Atom &b) inline void swap(mmcif::Atom &a, mmcif::Atom &b)
{ {
...@@ -216,19 +276,16 @@ typedef std::vector<Atom> AtomView; ...@@ -216,19 +276,16 @@ typedef std::vector<Atom> AtomView;
class Residue class Residue
{ {
public: public:
// constructors should be private, but that's not possible for now (needed in emplace) // constructor
// constructor for waters
Residue(const Structure &structure, const std::string &compoundID,
const std::string &asymID, const std::string &authSeqID);
// constructor for a residue without a sequence number
Residue(const Structure &structure, const std::string &compoundID,
const std::string &asymID);
// constructor for a residue with a sequence number
Residue(const Structure &structure, const std::string &compoundID, Residue(const Structure &structure, const std::string &compoundID,
const std::string &asymID, int seqID, const std::string &authSeqID); const std::string &asymID, int seqID = 0, const std::string &authSeqID = {})
: mStructure(&structure)
, mCompoundID(compoundID)
, mAsymID(asymID)
, mSeqID(seqID)
, mAuthSeqID(authSeqID)
{
}
Residue(const Residue &rhs) = delete; Residue(const Residue &rhs) = delete;
Residue &operator=(const Residue &rhs) = delete; Residue &operator=(const Residue &rhs) = delete;
...@@ -552,6 +609,12 @@ class Structure ...@@ -552,6 +609,12 @@ class Structure
/// \brief Rotate the coordinates of all atoms in the structure by \a q /// \brief Rotate the coordinates of all atoms in the structure by \a q
void rotate(Quaternion t); void rotate(Quaternion t);
/// \brief Translate and rotate the coordinates of all atoms in the structure by \a t and \a q
void translateAndRotate(Point t, Quaternion q);
/// \brief Translate, rotate and translate again the coordinates of all atoms in the structure by \a t1 , \a q and \a t2
void translateRotateAndTranslate(Point t1, Quaternion q, Point t2);
const std::vector<Residue> &getNonPolymers() const { return mNonPolymers; } const std::vector<Residue> &getNonPolymers() const { return mNonPolymers; }
const std::vector<Residue> &getBranchResidues() const { return mBranchResidues; } const std::vector<Residue> &getBranchResidues() const { return mBranchResidues; }
......
...@@ -180,7 +180,10 @@ bool CompoundBondMap::bonded(const std::string &compoundID, const std::string &a ...@@ -180,7 +180,10 @@ bool CompoundBondMap::bonded(const std::string &compoundID, const std::string &a
auto compound = mmcif::CompoundFactory::instance().create(compoundID); auto compound = mmcif::CompoundFactory::instance().create(compoundID);
if (not compound) if (not compound)
{
if (cif::VERBOSE >= 0)
std::cerr << "Missing compound bond info for " << compoundID << std::endl; std::cerr << "Missing compound bond info for " << compoundID << std::endl;
}
else else
{ {
for (auto &atom : compound->bonds()) for (auto &atom : compound->bonds())
...@@ -308,7 +311,7 @@ BondMap::BondMap(const Structure &p) ...@@ -308,7 +311,7 @@ BondMap::BondMap(const Structure &p)
{ {
if (c == "HOH" or c == "H2O" or c == "WAT") if (c == "HOH" or c == "H2O" or c == "WAT")
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "skipping water in bond map calculation" << std::endl; std::cerr << "skipping water in bond map calculation" << std::endl;
continue; continue;
} }
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
#include <numeric> #include <numeric>
#include <regex> #include <regex>
#include <set> #include <set>
#include <shared_mutex>
#include <stack> #include <stack>
#include <tuple> #include <tuple>
#include <unordered_map> #include <unordered_map>
#include <shared_mutex>
#include <filesystem> #include <filesystem>
...@@ -570,36 +570,6 @@ void Datablock::write(std::ostream &os, const std::vector<std::string> &order) ...@@ -570,36 +570,6 @@ void Datablock::write(std::ostream &os, const std::vector<std::string> &order)
cat.write(os); cat.write(os);
} }
// // mmcif support, sort of. First write the 'entry' Category
// // and if it exists, _AND_ we have a Validator, write out the
// // auditConform record.
//
// for (auto& cat: mCategories)
// {
// if (cat.name() == "entry")
// {
// cat.write(os);
//
// if (mValidator != nullptr)
// {
// Category auditConform(*this, "audit_conform", nullptr);
// auditConform.emplace({
// { "dict_name", mValidator->dictName() },
// { "dict_version", mValidator->dictVersion() }
// });
// auditConform.write(os);
// }
//
// break;
// }
// }
//
// for (auto& cat: mCategories)
// {
// if (cat.name() != "entry" and cat.name() != "audit_conform")
// cat.write(os);
// }
} }
bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
...@@ -669,7 +639,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) ...@@ -669,7 +639,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
while (catB_i != catB.end()) while (catB_i != catB.end())
missingA.push_back(*catB_i++); missingA.push_back(*catB_i++);
if (not (missingA.empty() and missingB.empty())) if (not(missingA.empty() and missingB.empty()))
{ {
if (cif::VERBOSE > 1) if (cif::VERBOSE > 1)
{ {
...@@ -706,7 +676,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) ...@@ -706,7 +676,7 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
++catA_i; ++catA_i;
else else
{ {
if (not (*dbA.get(*catA_i) == *dbB.get(*catB_i))) if (not(*dbA.get(*catA_i) == *dbB.get(*catB_i)))
{ {
if (cif::VERBOSE > 1) if (cif::VERBOSE > 1)
{ {
...@@ -724,10 +694,10 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB) ...@@ -724,10 +694,10 @@ bool operator==(const cif::Datablock &dbA, const cif::Datablock &dbB)
return result; return result;
} }
std::ostream& operator<<(std::ostream &os, const Datablock &data) std::ostream &operator<<(std::ostream &os, const Datablock &data)
{ {
// whoohoo... this sucks! // whoohoo... this sucks!
const_cast<Datablock&>(data).write(os); const_cast<Datablock &>(data).write(os);
return os; return os;
} }
...@@ -1162,7 +1132,7 @@ void CatIndex::reconstruct() ...@@ -1162,7 +1132,7 @@ void CatIndex::reconstruct()
insert(r.mData); insert(r.mData);
// maybe reconstruction can be done quicker by using the following commented code. // maybe reconstruction can be done quicker by using the following commented code.
// however, I've not had the time to think of a way to std::set the red/black flag correctly in that case. // however, I've not had the time to think of a way to set the red/black flag correctly in that case.
// std::vector<ItemRow*> rows; // std::vector<ItemRow*> rows;
// transform(mCat.begin(), mCat.end(), backInserter(rows), // transform(mCat.begin(), mCat.end(), backInserter(rows),
...@@ -1254,82 +1224,15 @@ size_t CatIndex::size() const ...@@ -1254,82 +1224,15 @@ size_t CatIndex::size() const
return result; return result;
} }
//bool CatIndex::isValid() const
//{
// bool result = true;
//
// if (mRoot != nullptr)
// {
// uint32_t minBlack = numeric_limits<uint32_t>::max();
// uint32_t maxBlack = 0;
//
// assert(not mRoot->mRed);
//
// result = isValid(mRoot, false, 0, minBlack, maxBlack);
// assert(minBlack == maxBlack);
// }
//
// return result;
//}
//
//bool CatIndex::validate(entry* h, bool isParentRed, uint32_t blackDepth, uint32_t& minBlack, uint32_t& maxBlack) const
//{
// bool result = true;
//
// if (h->mRed)
// assert(not isParentRed);
// else
// ++blackDepth;
//
// if (isParentRed)
// assert(not h->mRed);
//
// if (h->mLeft != nullptr and h->mRight != nullptr)
// {
// if (isRed(h->mLeft))
// assert(not isRed(h->mRight));
// if (isRed(h->mRight))
// assert(not isRed(h->mLeft));
// }
//
// if (h->mLeft != nullptr)
// {
// assert(mComp(h->mLeft->mRow, h->mRow) < 0);
// validate(h->mLeft, h->mRed, blackDepth, minBlack, maxBlack);
// }
// else
// {
// if (minBlack > blackDepth)
// minBlack = blackDepth;
// if (maxBlack < blackDepth)
// maxBlack = blackDepth;
// }
//
// if (h->mRight != nullptr)
// {
// assert(mComp(h->mRight->mRow, h->mRow) > 0);
// validate(h->mRight, h->mRight, blackDepth, minBlack, maxBlack);
// }
// else
// {
// if (minBlack > blackDepth)
// minBlack = blackDepth;
// if (maxBlack < blackDepth)
// maxBlack = blackDepth;
// }
//}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
RowSet::RowSet(Category &cat) RowSet::RowSet(Category &cat)
: mCat(&cat) : mCat(&cat)
// , mCond(nullptr)
{ {
} }
RowSet::RowSet(Category &cat, Condition &&cond) RowSet::RowSet(Category &cat, Condition &&cond)
: mCat(&cat) : mCat(&cat)
// , mCond(new Condition(std::forward<Condition>(cond)))
{ {
cond.prepare(cat); cond.prepare(cat);
...@@ -1343,21 +1246,17 @@ RowSet::RowSet(Category &cat, Condition &&cond) ...@@ -1343,21 +1246,17 @@ RowSet::RowSet(Category &cat, Condition &&cond)
RowSet::RowSet(const RowSet &rhs) RowSet::RowSet(const RowSet &rhs)
: mCat(rhs.mCat) : mCat(rhs.mCat)
, mItems(rhs.mItems) , mItems(rhs.mItems)
// , mCond(nullptr)
{ {
} }
RowSet::RowSet(RowSet &&rhs) RowSet::RowSet(RowSet &&rhs)
: mCat(rhs.mCat) : mCat(rhs.mCat)
, mItems(std::move(rhs.mItems)) , mItems(std::move(rhs.mItems))
// , mCond(rhs.mCond)
{ {
// rhs.mCond = nullptr;
} }
RowSet::~RowSet() RowSet::~RowSet()
{ {
// delete mCond;
} }
RowSet &RowSet::operator=(const RowSet &rhs) RowSet &RowSet::operator=(const RowSet &rhs)
...@@ -1469,7 +1368,7 @@ void Category::updateLinks() ...@@ -1469,7 +1368,7 @@ void Category::updateLinks()
auto childCat = mDb.get(link->mChildCategory); auto childCat = mDb.get(link->mChildCategory);
if (childCat == nullptr) if (childCat == nullptr)
continue; continue;
mChildLinks.push_back({ childCat, link }); mChildLinks.push_back({childCat, link});
} }
for (auto link : mValidator->getLinksForChild(mName)) for (auto link : mValidator->getLinksForChild(mName))
...@@ -1477,7 +1376,7 @@ void Category::updateLinks() ...@@ -1477,7 +1376,7 @@ void Category::updateLinks()
auto parentCat = mDb.get(link->mParentCategory); auto parentCat = mDb.get(link->mParentCategory);
if (parentCat == nullptr) if (parentCat == nullptr)
continue; continue;
mParentLinks.push_back({ parentCat, link }); mParentLinks.push_back({parentCat, link});
} }
} }
} }
...@@ -1497,7 +1396,7 @@ size_t Category::getColumnIndex(std::string_view name) const ...@@ -1497,7 +1396,7 @@ size_t Category::getColumnIndex(std::string_view name) const
break; break;
} }
if (VERBOSE and result == mColumns.size() and mCatValidator != nullptr) // validate the name, if it is known at all (since it was not found) if (VERBOSE > 0 and result == mColumns.size() and mCatValidator != nullptr) // validate the name, if it is known at all (since it was not found)
{ {
auto iv = mCatValidator->getValidatorForItem(name); auto iv = mCatValidator->getValidatorForItem(name);
if (iv == nullptr) if (iv == nullptr)
...@@ -1543,21 +1442,6 @@ size_t Category::addColumn(std::string_view name) ...@@ -1543,21 +1442,6 @@ size_t Category::addColumn(std::string_view name)
return result; return result;
} }
// RowSet Category::find(Condition&& cond)
// {
// RowSet result(*this);
// cond.prepare(*this);
// for (auto r: *this)
// {
// if (cond(*this, r))
// result.push_back(r);
// }
// return result;
// }
void Category::reorderByIndex() void Category::reorderByIndex()
{ {
if (mIndex != nullptr) if (mIndex != nullptr)
...@@ -1601,11 +1485,13 @@ std::string Category::getUniqueID(std::function<std::string(int)> generator) ...@@ -1601,11 +1485,13 @@ std::string Category::getUniqueID(std::function<std::string(int)> generator)
if (mCatValidator != nullptr and mCatValidator->mKeys.size() == 1) if (mCatValidator != nullptr and mCatValidator->mKeys.size() == 1)
key = mCatValidator->mKeys.front(); key = mCatValidator->mKeys.front();
size_t nr = size(); // calling size() often is a waste of resources
if (mLastUniqueNr == 0)
mLastUniqueNr = size();
for (;;) for (;;)
{ {
std::string result = generator(int(nr++)); std::string result = generator(static_cast<int>(mLastUniqueNr++));
if (exists(Key(key) == result)) if (exists(Key(key) == result))
continue; continue;
...@@ -1665,21 +1551,6 @@ Row Category::operator[](Condition &&cond) ...@@ -1665,21 +1551,6 @@ Row Category::operator[](Condition &&cond)
return result; return result;
} }
// RowSet Category::find(Condition&& cond)
// {
// // return RowSet(*this, std::forward<Condition>(cond));
// RowSet result(*this);
// cond.prepare(*this);
// for (auto r: *this)
// {
// if (cond(*this, r))
// result.insert(result.end(), r);
// }
// return result;
// }
bool Category::exists(Condition &&cond) const bool Category::exists(Condition &&cond) const
{ {
bool result = false; bool result = false;
...@@ -2340,7 +2211,7 @@ void Category::validateLinks() const ...@@ -2340,7 +2211,7 @@ void Category::validateLinks() const
if (not hasParent(r, *parentCat, *link)) if (not hasParent(r, *parentCat, *link))
++missing; ++missing;
if (missing) if (missing and VERBOSE >= 0)
{ {
std::cerr << "Links for " << link->mLinkGroupLabel << " are incomplete" << std::endl std::cerr << "Links for " << link->mLinkGroupLabel << " are incomplete" << std::endl
<< " There are " << missing << " items in " << mName << " that don't have matching parent items in " << parentCat->mName << std::endl; << " There are " << missing << " items in " << mName << " that don't have matching parent items in " << parentCat->mName << std::endl;
...@@ -2412,22 +2283,22 @@ bool operator==(const Category &a, const Category &b) ...@@ -2412,22 +2283,22 @@ bool operator==(const Category &a, const Category &b)
bool result = true; bool result = true;
// set<std::string> tagsA(a.fields()), tagsB(b.fields()); // set<std::string> tagsA(a.fields()), tagsB(b.fields());
// //
// if (tagsA != tagsB) // if (tagsA != tagsB)
// std::cout << "Unequal number of fields" << std::endl; // std::cout << "Unequal number of fields" << std::endl;
auto& validator = a.getValidator(); auto &validator = a.getValidator();
auto catValidator = validator.getValidatorForCategory(a.name()); auto catValidator = validator.getValidatorForCategory(a.name());
if (catValidator == nullptr) if (catValidator == nullptr)
throw std::runtime_error("missing cat validator"); throw std::runtime_error("missing cat validator");
typedef std::function<int(const char*,const char*)> compType; typedef std::function<int(const char *, const char *)> compType;
std::vector<std::tuple<std::string,compType>> tags; std::vector<std::tuple<std::string, compType>> tags;
auto keys = catValidator->mKeys; auto keys = catValidator->mKeys;
std::vector<size_t> keyIx; std::vector<size_t> keyIx;
for (auto& tag: a.fields()) for (auto &tag : a.fields())
{ {
auto iv = catValidator->getValidatorForItem(tag); auto iv = catValidator->getValidatorForItem(tag);
if (iv == nullptr) if (iv == nullptr)
...@@ -2437,7 +2308,8 @@ bool operator==(const Category &a, const Category &b) ...@@ -2437,7 +2308,8 @@ bool operator==(const Category &a, const Category &b)
throw std::runtime_error("missing type validator"); throw std::runtime_error("missing type validator");
tags.push_back(std::make_tuple(tag, std::bind(&cif::ValidateType::compare, tv, std::placeholders::_1, std::placeholders::_2))); tags.push_back(std::make_tuple(tag, std::bind(&cif::ValidateType::compare, tv, std::placeholders::_1, std::placeholders::_2)));
auto pred = [tag](const std::string& s) -> bool { return cif::iequals(tag, s) == 0; }; auto pred = [tag](const std::string &s) -> bool
{ return cif::iequals(tag, s) == 0; };
if (find_if(keys.begin(), keys.end(), pred) == keys.end()) if (find_if(keys.begin(), keys.end(), pred) == keys.end())
keyIx.push_back(tags.size() - 1); keyIx.push_back(tags.size() - 1);
} }
...@@ -2445,11 +2317,11 @@ bool operator==(const Category &a, const Category &b) ...@@ -2445,11 +2317,11 @@ bool operator==(const Category &a, const Category &b)
// a.reorderByIndex(); // a.reorderByIndex();
// b.reorderByIndex(); // b.reorderByIndex();
auto rowEqual = [&](const cif::Row& ra, const cif::Row& rb) auto rowEqual = [&](const cif::Row &ra, const cif::Row &rb)
{ {
int d = 0; int d = 0;
for (auto kix: keyIx) for (auto kix : keyIx)
{ {
std::string tag; std::string tag;
compType compare; compType compare;
...@@ -2496,7 +2368,7 @@ bool operator==(const Category &a, const Category &b) ...@@ -2496,7 +2368,7 @@ bool operator==(const Category &a, const Category &b)
std::vector<std::string> missingA, missingB, different; std::vector<std::string> missingA, missingB, different;
for (auto& tt: tags) for (auto &tt : tags)
{ {
std::string tag; std::string tag;
compType compare; compType compare;
...@@ -2505,8 +2377,12 @@ bool operator==(const Category &a, const Category &b) ...@@ -2505,8 +2377,12 @@ bool operator==(const Category &a, const Category &b)
// make it an option to compare unapplicable to empty or something // make it an option to compare unapplicable to empty or something
const char* ta = ra[tag].c_str(); if (strcmp(ta, ".") == 0 or strcmp(ta, "?") == 0) ta = ""; const char *ta = ra[tag].c_str();
const char* tb = rb[tag].c_str(); if (strcmp(tb, ".") == 0 or strcmp(tb, "?") == 0) tb = ""; if (strcmp(ta, ".") == 0 or strcmp(ta, "?") == 0)
ta = "";
const char *tb = rb[tag].c_str();
if (strcmp(tb, ".") == 0 or strcmp(tb, "?") == 0)
tb = "";
if (compare(ta, tb) != 0) if (compare(ta, tb) != 0)
{ {
...@@ -2527,18 +2403,6 @@ bool operator==(const Category &a, const Category &b) ...@@ -2527,18 +2403,6 @@ bool operator==(const Category &a, const Category &b)
return result; return result;
} }
// auto Category::iterator::operator++() -> iterator&
// {
// mCurrent = Row(mCurrent.data()->mNext);
// return *this;
// }
// auto Category::const_iterator::operator++() -> const_iterator&
// {
// mCurrent = Row(mCurrent.data()->mNext);
// return *this;
// }
namespace detail namespace detail
{ {
...@@ -2900,7 +2764,7 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st ...@@ -2900,7 +2764,7 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st
} }
// cannot update this... // cannot update this...
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Cannot update child " << childCat->mName << "." << childTag << " with value " << value << std::endl; std::cerr << "Cannot update child " << childCat->mName << "." << childTag << " with value " << value << std::endl;
} }
...@@ -3009,21 +2873,22 @@ void Row::assign(const Item &value, bool skipUpdateLinked) ...@@ -3009,21 +2873,22 @@ void Row::assign(const Item &value, bool skipUpdateLinked)
assign(value.name(), value.value(), skipUpdateLinked); assign(value.name(), value.value(), skipUpdateLinked);
} }
void Row::assign(std::string_view name, const std::string &value, bool skipUpdateLinked) void Row::assign(std::string_view name, const std::string &value, bool skipUpdateLinked, bool validate)
{ {
try try
{ {
auto cat = mData->mCategory; auto cat = mData->mCategory;
assign(cat->addColumn(name), value, skipUpdateLinked); assign(cat->addColumn(name), value, skipUpdateLinked, validate);
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Could not assign value '" << value << "' to column _" << mData->mCategory->name() << '.' << name << std::endl; std::cerr << "Could not assign value '" << value << "' to column _" << mData->mCategory->name() << '.' << name << std::endl;
throw; throw;
} }
} }
void Row::assign(size_t column, const std::string &value, bool skipUpdateLinked) void Row::assign(size_t column, const std::string &value, bool skipUpdateLinked, bool validate)
{ {
if (mData == nullptr) if (mData == nullptr)
throw std::logic_error("invalid Row, no data assigning value '" + value + "' to column with index " + std::to_string(column)); throw std::logic_error("invalid Row, no data assigning value '" + value + "' to column with index " + std::to_string(column));
...@@ -3049,7 +2914,7 @@ void Row::assign(size_t column, const std::string &value, bool skipUpdateLinked) ...@@ -3049,7 +2914,7 @@ void Row::assign(size_t column, const std::string &value, bool skipUpdateLinked)
std::string oldStrValue = oldValue ? oldValue : ""; std::string oldStrValue = oldValue ? oldValue : "";
// check the value // check the value
if (col.mValidator) if (col.mValidator and validate)
(*col.mValidator)(value); (*col.mValidator)(value);
// If the field is part of the Key for this Category, remove it from the index // If the field is part of the Key for this Category, remove it from the index
...@@ -3181,7 +3046,7 @@ void Row::assign(size_t column, const std::string &value, bool skipUpdateLinked) ...@@ -3181,7 +3046,7 @@ void Row::assign(size_t column, const std::string &value, bool skipUpdateLinked)
auto rows_n = childCat->find(std::move(cond_n)); auto rows_n = childCat->find(std::move(cond_n));
if (not rows_n.empty()) if (not rows_n.empty())
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Will not rename in child category since there are already rows that link to the parent" << std::endl; std::cerr << "Will not rename in child category since there are already rows that link to the parent" << std::endl;
continue; continue;
...@@ -3387,7 +3252,7 @@ void Row::swap(size_t cix, ItemRow *a, ItemRow *b) ...@@ -3387,7 +3252,7 @@ void Row::swap(size_t cix, ItemRow *a, ItemRow *b)
} }
else else
{ {
if (VERBOSE) if (VERBOSE > 0)
std::cerr << "In " << childCat->mName << " changing " << linkChildColName << ": " << r[linkChildColName].as<std::string>() << " => " << (i ? i->mText : "") << std::endl; std::cerr << "In " << childCat->mName << " changing " << linkChildColName << ": " << r[linkChildColName].as<std::string>() << " => " << (i ? i->mText : "") << std::endl;
r[linkChildColName] = i ? i->mText : ""; r[linkChildColName] = i ? i->mText : "";
} }
...@@ -3496,6 +3361,7 @@ File::File(const std::filesystem::path &path, bool validate) ...@@ -3496,6 +3361,7 @@ File::File(const std::filesystem::path &path, bool validate)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error while loading file " << path << std::endl; std::cerr << "Error while loading file " << path << std::endl;
throw; throw;
} }
...@@ -3564,6 +3430,7 @@ void File::load(const std::filesystem::path &p) ...@@ -3564,6 +3430,7 @@ void File::load(const std::filesystem::path &p)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error loading file " << path << std::endl; std::cerr << "Error loading file " << path << std::endl;
throw; throw;
} }
...@@ -3660,7 +3527,7 @@ bool File::isValid() ...@@ -3660,7 +3527,7 @@ bool File::isValid()
{ {
if (mValidator == nullptr) if (mValidator == nullptr)
{ {
if (VERBOSE) if (VERBOSE > 0)
std::cerr << "No dictionary loaded explicitly, loading default" << std::endl; std::cerr << "No dictionary loaded explicitly, loading default" << std::endl;
loadDictionary(); loadDictionary();
......
...@@ -753,6 +753,7 @@ class Ff : public FBase ...@@ -753,6 +753,7 @@ class Ff : public FBase
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Failed to write '" << s << "' as a double, this indicates an error in the code for writing PDB files" << std::endl; std::cerr << "Failed to write '" << s << "' as a double, this indicates an error in the code for writing PDB files" << std::endl;
os << s; os << s;
} }
...@@ -2329,6 +2330,7 @@ void WriteRemark200(std::ostream& pdbFile, Datablock& db) ...@@ -2329,6 +2330,7 @@ void WriteRemark200(std::ostream& pdbFile, Datablock& db)
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
} }
} }
...@@ -2390,6 +2392,7 @@ void WriteRemark280(std::ostream& pdbFile, Datablock& db) ...@@ -2390,6 +2392,7 @@ void WriteRemark280(std::ostream& pdbFile, Datablock& db)
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
} }
} }
......
...@@ -288,7 +288,7 @@ SacParser::CIFToken SacParser::getNextToken() ...@@ -288,7 +288,7 @@ SacParser::CIFToken SacParser::getNextToken()
mState = eStateTextField + 1; mState = eStateTextField + 1;
else if (ch == kEOF) else if (ch == kEOF)
error("unterminated textfield"); error("unterminated textfield");
else if (not isAnyPrint(ch)) else if (not isAnyPrint(ch) and cif::VERBOSE >= 0)
// error("invalid character in text field '" + string({ static_cast<char>(ch) }) + "' (" + to_string((int)ch) + ")"); // error("invalid character in text field '" + string({ static_cast<char>(ch) }) + "' (" + to_string((int)ch) + ")");
std::cerr << "invalid character in text field '" << std::string({static_cast<char>(ch)}) << "' (" << ch << ") line: " << mLineNr << std::endl; std::cerr << "invalid character in text field '" << std::string({static_cast<char>(ch)}) << "' (" << ch << ") line: " << mLineNr << std::endl;
break; break;
...@@ -1220,7 +1220,7 @@ void DictParser::linkItems() ...@@ -1220,7 +1220,7 @@ void DictParser::linkItems()
{ {
for (auto &iv : cv.mItemValidators) for (auto &iv : cv.mItemValidators)
{ {
if (iv.mType == nullptr) if (iv.mType == nullptr and cif::VERBOSE >= 0)
std::cerr << "Missing item_type for " << iv.mTag << std::endl; std::cerr << "Missing item_type for " << iv.mTag << std::endl;
} }
} }
...@@ -1255,6 +1255,7 @@ void DictParser::loadDictionary() ...@@ -1255,6 +1255,7 @@ void DictParser::loadDictionary()
} }
catch (const std::exception &) catch (const std::exception &)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error parsing dictionary" << std::endl; std::cerr << "Error parsing dictionary" << std::endl;
throw; throw;
} }
......
...@@ -1237,7 +1237,7 @@ std::filesystem::path gDataDir; ...@@ -1237,7 +1237,7 @@ std::filesystem::path gDataDir;
void addDataDirectory(std::filesystem::path dataDir) void addDataDirectory(std::filesystem::path dataDir)
{ {
if (VERBOSE and not fs::exists(dataDir)) if (VERBOSE > 0 and not fs::exists(dataDir))
std::cerr << "The specified data directory " << dataDir << " does not exist" << std::endl; std::cerr << "The specified data directory " << dataDir << " does not exist" << std::endl;
gDataDir = dataDir; gDataDir = dataDir;
} }
......
...@@ -354,7 +354,7 @@ void Validator::reportError(const std::string &msg, bool fatal) const ...@@ -354,7 +354,7 @@ void Validator::reportError(const std::string &msg, bool fatal) const
{ {
if (mStrict or fatal) if (mStrict or fatal)
throw ValidationError(msg); throw ValidationError(msg);
else if (VERBOSE) else if (VERBOSE > 0)
std::cerr << msg << std::endl; std::cerr << msg << std::endl;
} }
......
...@@ -193,7 +193,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string ...@@ -193,7 +193,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string
bond.type = BondType::delo; bond.type = BondType::delo;
else else
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Unimplemented chem_comp_bond.type " << btype << " in " << id << std::endl; std::cerr << "Unimplemented chem_comp_bond.type " << btype << " in " << id << std::endl;
bond.type = BondType::sing; bond.type = BondType::sing;
} }
...@@ -520,7 +520,7 @@ Compound *CCDCompoundFactoryImpl::create(const std::string &id) ...@@ -520,7 +520,7 @@ Compound *CCDCompoundFactoryImpl::create(const std::string &id)
} }
} }
if (result == nullptr and cif::VERBOSE) if (result == nullptr and cif::VERBOSE > 0)
std::cerr << "Could not locate compound " << id << " in the CCD components file" << std::endl; std::cerr << "Could not locate compound " << id << " in the CCD components file" << std::endl;
return result; return result;
...@@ -645,13 +645,13 @@ CompoundFactory::CompoundFactory() ...@@ -645,13 +645,13 @@ CompoundFactory::CompoundFactory()
auto ccd = cif::loadResource("components.cif"); auto ccd = cif::loadResource("components.cif");
if (ccd) if (ccd)
mImpl.reset(new CCDCompoundFactoryImpl(mImpl)); mImpl.reset(new CCDCompoundFactoryImpl(mImpl));
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
std::cerr << "CCD components.cif file was not found" << std::endl; std::cerr << "CCD components.cif file was not found" << std::endl;
const char *clibd_mon = getenv("CLIBD_MON"); const char *clibd_mon = getenv("CLIBD_MON");
if (clibd_mon != nullptr and fs::is_directory(clibd_mon)) if (clibd_mon != nullptr and fs::is_directory(clibd_mon))
mImpl.reset(new CCP4CompoundFactoryImpl(clibd_mon)); mImpl.reset(new CCP4CompoundFactoryImpl(clibd_mon));
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
std::cerr << "CCP4 monomers library not found, CLIBD_MON is not defined" << std::endl; std::cerr << "CCP4 monomers library not found, CLIBD_MON is not defined" << std::endl;
} }
...@@ -695,6 +695,7 @@ void CompoundFactory::setDefaultDictionary(const std::filesystem::path &inDictFi ...@@ -695,6 +695,7 @@ void CompoundFactory::setDefaultDictionary(const std::filesystem::path &inDictFi
} }
catch (const std::exception &) catch (const std::exception &)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error loading dictionary " << inDictFile << std::endl; std::cerr << "Error loading dictionary " << inDictFile << std::endl;
throw; throw;
} }
...@@ -715,6 +716,7 @@ void CompoundFactory::pushDictionary(const std::filesystem::path &inDictFile) ...@@ -715,6 +716,7 @@ void CompoundFactory::pushDictionary(const std::filesystem::path &inDictFile)
} }
catch (const std::exception &) catch (const std::exception &)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error loading dictionary " << inDictFile << std::endl; std::cerr << "Error loading dictionary " << inDictFile << std::endl;
throw; throw;
} }
......
...@@ -268,6 +268,7 @@ int PDBRecord::vI(int columnFirst, int columnLast) ...@@ -268,6 +268,7 @@ int PDBRecord::vI(int columnFirst, int columnLast)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Trying to parse '" << std::string(mValue + columnFirst - 7, mValue + columnLast - 7) << '\'' << std::endl; std::cerr << "Trying to parse '" << std::string(mValue + columnFirst - 7, mValue + columnLast - 7) << '\'' << std::endl;
throw; throw;
} }
...@@ -337,7 +338,7 @@ std::tuple<std::string, std::string> SpecificationListParser::GetNextSpecificati ...@@ -337,7 +338,7 @@ std::tuple<std::string, std::string> SpecificationListParser::GetNextSpecificati
} }
else if (not isspace(ch)) else if (not isspace(ch))
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "skipping invalid character in SOURCE ID: " << ch << std::endl; std::cerr << "skipping invalid character in SOURCE ID: " << ch << std::endl;
} }
break; break;
...@@ -354,7 +355,7 @@ std::tuple<std::string, std::string> SpecificationListParser::GetNextSpecificati ...@@ -354,7 +355,7 @@ std::tuple<std::string, std::string> SpecificationListParser::GetNextSpecificati
case eColon: case eColon:
if (ch == ';') if (ch == ';')
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Empty value for SOURCE: " << id << std::endl; std::cerr << "Empty value for SOURCE: " << id << std::endl;
state = eStart; state = eStart;
} }
...@@ -418,7 +419,7 @@ std::tuple<std::string, std::string> SpecificationListParser::GetNextSpecificati ...@@ -418,7 +419,7 @@ std::tuple<std::string, std::string> SpecificationListParser::GetNextSpecificati
case eError: case eError:
if (ch == ';') if (ch == ';')
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Skipping invalid header line: '" << std::string(start, mP) << std::endl; std::cerr << "Skipping invalid header line: '" << std::string(start, mP) << std::endl;
state = eStart; state = eStart;
} }
...@@ -832,7 +833,7 @@ class PDBFileParser ...@@ -832,7 +833,7 @@ class PDBFileParser
if (not mChainSeq2AsymSeq.count(key)) if (not mChainSeq2AsymSeq.count(key))
{ {
ec = error::make_error_code(error::pdbErrors::residueNotFound); ec = error::make_error_code(error::pdbErrors::residueNotFound);
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Residue " << chainID << resSeq << iCode << " could not be mapped" << std::endl; std::cerr << "Residue " << chainID << resSeq << iCode << " could not be mapped" << std::endl;
} }
else else
...@@ -929,7 +930,7 @@ class PDBFileParser ...@@ -929,7 +930,7 @@ class PDBFileParser
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
ec = error::make_error_code(error::pdbErrors::invalidDate); ec = error::make_error_code(error::pdbErrors::invalidDate);
} }
...@@ -1160,6 +1161,7 @@ void PDBFileParser::PreParseInput(std::istream &is) ...@@ -1160,6 +1161,7 @@ void PDBFileParser::PreParseInput(std::istream &is)
if (is.eof()) if (is.eof())
break; break;
if (cif::VERBOSE > 0)
std::cerr << "Line number " << lineNr << " is empty!" << std::endl; std::cerr << "Line number " << lineNr << " is empty!" << std::endl;
getline(is, lookahead); getline(is, lookahead);
...@@ -1278,6 +1280,7 @@ void PDBFileParser::PreParseInput(std::istream &is) ...@@ -1278,6 +1280,7 @@ void PDBFileParser::PreParseInput(std::istream &is)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Dropping FORMUL line (" << (lineNr - 1) << ") with invalid component number '" << value.substr(1, 3) << '\'' << std::endl; std::cerr << "Dropping FORMUL line (" << (lineNr - 1) << ") with invalid component number '" << value.substr(1, 3) << '\'' << std::endl;
continue; continue;
// throw_with_nested(std::runtime_error("Invalid component number '" + value.substr(1, 3) + '\'')); // throw_with_nested(std::runtime_error("Invalid component number '" + value.substr(1, 3) + '\''));
...@@ -1305,6 +1308,7 @@ void PDBFileParser::PreParseInput(std::istream &is) ...@@ -1305,6 +1308,7 @@ void PDBFileParser::PreParseInput(std::istream &is)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error parsing FORMUL at line " << lineNr << std::endl; std::cerr << "Error parsing FORMUL at line " << lineNr << std::endl;
throw; throw;
} }
...@@ -1412,6 +1416,7 @@ void PDBFileParser::PreParseInput(std::istream &is) ...@@ -1412,6 +1416,7 @@ void PDBFileParser::PreParseInput(std::istream &is)
if (not dropped.empty()) if (not dropped.empty())
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Dropped unsupported records: " << ba::join(dropped, ", ") << std::endl; std::cerr << "Dropped unsupported records: " << ba::join(dropped, ", ") << std::endl;
} }
...@@ -1440,7 +1445,7 @@ void PDBFileParser::Match(const std::string &expected, bool throwIfMissing) ...@@ -1440,7 +1445,7 @@ void PDBFileParser::Match(const std::string &expected, bool throwIfMissing)
{ {
if (throwIfMissing) if (throwIfMissing)
throw std::runtime_error("Expected record " + expected + " but found " + mRec->mName); throw std::runtime_error("Expected record " + expected + " but found " + mRec->mName);
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Expected record " + expected + " but found " + mRec->mName << std::endl; std::cerr << "Expected record " + expected + " but found " + mRec->mName << std::endl;
} }
} }
...@@ -1575,6 +1580,7 @@ void PDBFileParser::ParseTitle() ...@@ -1575,6 +1580,7 @@ void PDBFileParser::ParseTitle()
if (not iequals(key, "MOL_ID") and mCompounds.empty()) if (not iequals(key, "MOL_ID") and mCompounds.empty())
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Ignoring invalid COMPND record" << std::endl; std::cerr << "Ignoring invalid COMPND record" << std::endl;
break; break;
} }
...@@ -1625,7 +1631,7 @@ void PDBFileParser::ParseTitle() ...@@ -1625,7 +1631,7 @@ void PDBFileParser::ParseTitle()
// auto colon = s.find(": "); // auto colon = s.find(": ");
// if (colon == std::string::npos) // if (colon == std::string::npos)
// { // {
// if (cif::VERBOSE) // if (cif::VERBOSE > 0)
// std::cerr << "invalid source field, missing colon (" << s << ')' << std::endl; // std::cerr << "invalid source field, missing colon (" << s << ')' << std::endl;
// continue; // continue;
// } // }
...@@ -1713,7 +1719,7 @@ void PDBFileParser::ParseTitle() ...@@ -1713,7 +1719,7 @@ void PDBFileParser::ParseTitle()
// NUMMDL // NUMMDL
if (mRec->is("NUMMDL")) if (mRec->is("NUMMDL"))
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "skipping unimplemented NUMMDL record" << std::endl; std::cerr << "skipping unimplemented NUMMDL record" << std::endl;
GetNextRecord(); GetNextRecord();
} }
...@@ -1816,7 +1822,7 @@ void PDBFileParser::ParseTitle() ...@@ -1816,7 +1822,7 @@ void PDBFileParser::ParseTitle()
// SPRSDE // SPRSDE
if (mRec->is("SPRSDE")) if (mRec->is("SPRSDE"))
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "skipping unimplemented SPRSDE record" << std::endl; std::cerr << "skipping unimplemented SPRSDE record" << std::endl;
GetNextRecord(); GetNextRecord();
} }
...@@ -2265,7 +2271,7 @@ void PDBFileParser::ParseRemarks() ...@@ -2265,7 +2271,7 @@ void PDBFileParser::ParseRemarks()
state = eMCP; state = eMCP;
else if (subtopic == "CHIRAL CENTERS") else if (subtopic == "CHIRAL CENTERS")
state = eChC; state = eChC;
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
throw std::runtime_error("Unknown subtopic in REMARK 500: " + subtopic); throw std::runtime_error("Unknown subtopic in REMARK 500: " + subtopic);
headerSeen = false; headerSeen = false;
...@@ -2342,7 +2348,7 @@ void PDBFileParser::ParseRemarks() ...@@ -2342,7 +2348,7 @@ void PDBFileParser::ParseRemarks()
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Dropping REMARK 500 at line " << mRec->mLineNr << " due to invalid symmetry operation" << std::endl; std::cerr << "Dropping REMARK 500 at line " << mRec->mLineNr << " due to invalid symmetry operation" << std::endl;
continue; continue;
} }
...@@ -2675,7 +2681,7 @@ void PDBFileParser::ParseRemarks() ...@@ -2675,7 +2681,7 @@ void PDBFileParser::ParseRemarks()
case sStart: case sStart:
if (s == "SITE") if (s == "SITE")
state = sID; state = sID;
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
throw std::runtime_error("Invalid REMARK 800 record, expected SITE"); throw std::runtime_error("Invalid REMARK 800 record, expected SITE");
break; break;
...@@ -2685,7 +2691,7 @@ void PDBFileParser::ParseRemarks() ...@@ -2685,7 +2691,7 @@ void PDBFileParser::ParseRemarks()
id = m[1].str(); id = m[1].str();
state = sEvidence; state = sEvidence;
} }
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
throw std::runtime_error("Invalid REMARK 800 record, expected SITE_IDENTIFIER"); throw std::runtime_error("Invalid REMARK 800 record, expected SITE_IDENTIFIER");
break; break;
...@@ -2695,7 +2701,7 @@ void PDBFileParser::ParseRemarks() ...@@ -2695,7 +2701,7 @@ void PDBFileParser::ParseRemarks()
evidence = m[1].str(); evidence = m[1].str();
state = sDesc; state = sDesc;
} }
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
throw std::runtime_error("Invalid REMARK 800 record, expected SITE_IDENTIFIER"); throw std::runtime_error("Invalid REMARK 800 record, expected SITE_IDENTIFIER");
break; break;
...@@ -2906,7 +2912,7 @@ void PDBFileParser::ParseRemark200() ...@@ -2906,7 +2912,7 @@ void PDBFileParser::ParseRemark200()
collectionDate = pdb2cifDate(rm200("DATE OF DATA COLLECTION", diffrnNr), ec); collectionDate = pdb2cifDate(rm200("DATE OF DATA COLLECTION", diffrnNr), ec);
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << ec.message() << " for pdbx_collection_date" << std::endl; std::cerr << ec.message() << " for pdbx_collection_date" << std::endl;
// The date field can become truncated when multiple values are available // The date field can become truncated when multiple values are available
...@@ -3025,7 +3031,7 @@ void PDBFileParser::ParseRemark200() ...@@ -3025,7 +3031,7 @@ void PDBFileParser::ParseRemark200()
else if (inRM200({"HIGHEST RESOLUTION SHELL, RANGE LOW (A)", "COMPLETENESS FOR SHELL (%)", else if (inRM200({"HIGHEST RESOLUTION SHELL, RANGE LOW (A)", "COMPLETENESS FOR SHELL (%)",
"R MERGE FOR SHELL (I)", "R SYM FOR SHELL (I)", "<I/SIGMA(I)> FOR SHELL", "DATA REDUNDANCY IN SHELL"})) "R MERGE FOR SHELL (I)", "R SYM FOR SHELL (I)", "<I/SIGMA(I)> FOR SHELL", "DATA REDUNDANCY IN SHELL"}))
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Not writing reflns_shell record since d_res_high is missing" << std::endl; std::cerr << "Not writing reflns_shell record since d_res_high is missing" << std::endl;
} }
} }
...@@ -3595,7 +3601,7 @@ void PDBFileParser::ConstructEntities() ...@@ -3595,7 +3601,7 @@ void PDBFileParser::ConstructEntities()
{ {
auto &r = chain.mResiduesSeen[lastResidueIndex + 1]; auto &r = chain.mResiduesSeen[lastResidueIndex + 1];
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cerr << "Detected residues that cannot be aligned to SEQRES" << std::endl std::cerr << "Detected residues that cannot be aligned to SEQRES" << std::endl
<< "First residue is " << chain.mDbref.chainID << ':' << r.mSeqNum << r.mIcode << std::endl; << "First residue is " << chain.mDbref.chainID << ':' << r.mSeqNum << r.mIcode << std::endl;
...@@ -4005,7 +4011,7 @@ void PDBFileParser::ConstructEntities() ...@@ -4005,7 +4011,7 @@ void PDBFileParser::ConstructEntities()
tie(asym, labelSeq, std::ignore) = MapResidue(seqadv.chainID, seqadv.seqNum, seqadv.iCode, ec); tie(asym, labelSeq, std::ignore) = MapResidue(seqadv.chainID, seqadv.seqNum, seqadv.iCode, ec);
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "dropping unmatched SEQADV record" << std::endl; std::cerr << "dropping unmatched SEQADV record" << std::endl;
continue; continue;
} }
...@@ -4319,7 +4325,7 @@ void PDBFileParser::ConstructEntities() ...@@ -4319,7 +4325,7 @@ void PDBFileParser::ConstructEntities()
tie(asymID, seq, std::ignore) = MapResidue(chainID, seqNum, iCode, ec); tie(asymID, seq, std::ignore) = MapResidue(chainID, seqNum, iCode, ec);
if (ec) // no need to write a modres if it could not be found if (ec) // no need to write a modres if it could not be found
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "dropping unmapped MODRES record" << std::endl; std::cerr << "dropping unmapped MODRES record" << std::endl;
continue; continue;
} }
...@@ -4415,7 +4421,7 @@ void PDBFileParser::ConstructEntities() ...@@ -4415,7 +4421,7 @@ void PDBFileParser::ConstructEntities()
tie(asymID, seqNr, isPolymer) = MapResidue(unobs.chain, unobs.seq, unobs.iCode, ec); tie(asymID, seqNr, isPolymer) = MapResidue(unobs.chain, unobs.seq, unobs.iCode, ec);
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "error mapping unobserved residue" << std::endl; std::cerr << "error mapping unobserved residue" << std::endl;
continue; continue;
} }
...@@ -4676,7 +4682,7 @@ void PDBFileParser::ParseSecondaryStructure() ...@@ -4676,7 +4682,7 @@ void PDBFileParser::ParseSecondaryStructure()
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Could not map residue for HELIX " << vI(8, 10) << std::endl; std::cerr << "Could not map residue for HELIX " << vI(8, 10) << std::endl;
} }
else else
...@@ -4791,7 +4797,7 @@ void PDBFileParser::ParseSecondaryStructure() ...@@ -4791,7 +4797,7 @@ void PDBFileParser::ParseSecondaryStructure()
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Dropping SHEET record " << vI(8, 10) << std::endl; std::cerr << "Dropping SHEET record " << vI(8, 10) << std::endl;
} }
else else
...@@ -4827,7 +4833,7 @@ void PDBFileParser::ParseSecondaryStructure() ...@@ -4827,7 +4833,7 @@ void PDBFileParser::ParseSecondaryStructure()
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "skipping unmatched pdbx_struct_sheet_hbond record" << std::endl; std::cerr << "skipping unmatched pdbx_struct_sheet_hbond record" << std::endl;
} }
else else
...@@ -4927,7 +4933,7 @@ void PDBFileParser::ParseConnectivtyAnnotation() ...@@ -4927,7 +4933,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Dropping SSBOND " << vI(8, 10) << std::endl; std::cerr << "Dropping SSBOND " << vI(8, 10) << std::endl;
continue; continue;
} }
...@@ -4948,7 +4954,7 @@ void PDBFileParser::ParseConnectivtyAnnotation() ...@@ -4948,7 +4954,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Dropping SSBOND " << vI(8, 10) << " due to invalid symmetry operation" << std::endl; std::cerr << "Dropping SSBOND " << vI(8, 10) << " due to invalid symmetry operation" << std::endl;
continue; continue;
} }
...@@ -4993,7 +4999,7 @@ void PDBFileParser::ParseConnectivtyAnnotation() ...@@ -4993,7 +4999,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
if (mRec->is("LINK ") or mRec->is("LINKR ")) if (mRec->is("LINK ") or mRec->is("LINKR "))
{ {
if (cif::VERBOSE and mRec->is("LINKR ")) if (cif::VERBOSE > 0 and mRec->is("LINKR "))
std::cerr << "Accepting non-standard LINKR record, but ignoring extra information" << std::endl; std::cerr << "Accepting non-standard LINKR record, but ignoring extra information" << std::endl;
// 1 - 6 Record name "LINK " // 1 - 6 Record name "LINK "
...@@ -5046,7 +5052,7 @@ void PDBFileParser::ParseConnectivtyAnnotation() ...@@ -5046,7 +5052,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Dropping LINK record at line " << mRec->mLineNr << std::endl; std::cerr << "Dropping LINK record at line " << mRec->mLineNr << std::endl;
continue; continue;
} }
...@@ -5062,7 +5068,7 @@ void PDBFileParser::ParseConnectivtyAnnotation() ...@@ -5062,7 +5068,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
} }
catch (const std::invalid_argument &) catch (const std::invalid_argument &)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Distance value '" << distance << "' is not a valid float in LINK record" << std::endl; std::cerr << "Distance value '" << distance << "' is not a valid float in LINK record" << std::endl;
swap(ccp4LinkID, distance); // assume this is a ccp4_link_id... oh really? swap(ccp4LinkID, distance); // assume this is a ccp4_link_id... oh really?
} }
...@@ -5078,7 +5084,7 @@ void PDBFileParser::ParseConnectivtyAnnotation() ...@@ -5078,7 +5084,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Dropping LINK record at line " << mRec->mLineNr << " due to invalid symmetry operation" << std::endl; std::cerr << "Dropping LINK record at line " << mRec->mLineNr << " due to invalid symmetry operation" << std::endl;
continue; continue;
} }
...@@ -5149,7 +5155,7 @@ void PDBFileParser::ParseConnectivtyAnnotation() ...@@ -5149,7 +5155,7 @@ void PDBFileParser::ParseConnectivtyAnnotation()
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Dropping CISPEP record at line " << mRec->mLineNr << std::endl; std::cerr << "Dropping CISPEP record at line " << mRec->mLineNr << std::endl;
continue; continue;
} }
...@@ -5215,7 +5221,7 @@ void PDBFileParser::ParseMiscellaneousFeatures() ...@@ -5215,7 +5221,7 @@ void PDBFileParser::ParseMiscellaneousFeatures()
if (ec) if (ec)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "skipping struct_site_gen record" << std::endl; std::cerr << "skipping struct_site_gen record" << std::endl;
} }
else else
...@@ -5518,7 +5524,7 @@ void PDBFileParser::ParseCoordinate(int modelNr) ...@@ -5518,7 +5524,7 @@ void PDBFileParser::ParseCoordinate(int modelNr)
{ {
if (groupPDB == "HETATM") if (groupPDB == "HETATM")
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Changing atom from HETATM to ATOM at line " << mRec->mLineNr << std::endl; std::cerr << "Changing atom from HETATM to ATOM at line " << mRec->mLineNr << std::endl;
groupPDB = "ATOM"; groupPDB = "ATOM";
} }
...@@ -5527,7 +5533,7 @@ void PDBFileParser::ParseCoordinate(int modelNr) ...@@ -5527,7 +5533,7 @@ void PDBFileParser::ParseCoordinate(int modelNr)
{ {
if (groupPDB == "ATOM") if (groupPDB == "ATOM")
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Changing atom from ATOM to HETATM at line " << mRec->mLineNr << std::endl; std::cerr << "Changing atom from ATOM to HETATM at line " << mRec->mLineNr << std::endl;
groupPDB = "HETATM"; groupPDB = "HETATM";
} }
...@@ -5698,6 +5704,7 @@ void PDBFileParser::Parse(std::istream &is, cif::File &result) ...@@ -5698,6 +5704,7 @@ void PDBFileParser::Parse(std::istream &is, cif::File &result)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error parsing REMARK 3" << std::endl; std::cerr << "Error parsing REMARK 3" << std::endl;
throw; throw;
} }
...@@ -5750,12 +5757,12 @@ void PDBFileParser::Parse(std::istream &is, cif::File &result) ...@@ -5750,12 +5757,12 @@ void PDBFileParser::Parse(std::istream &is, cif::File &result)
if ((symm1.empty() or symm1 == "1_555") and (symm2.empty() or symm2 == "1_555")) if ((symm1.empty() or symm1 == "1_555") and (symm2.empty() or symm2 == "1_555"))
distance = static_cast<float>(mmcif::Distance(mmcif::Point{x1, y1, z1}, mmcif::Point{x2, y2, z2})); distance = static_cast<float>(mmcif::Distance(mmcif::Point{x1, y1, z1}, mmcif::Point{x2, y2, z2}));
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
std::cerr << "Cannot calculate distance for link since one of the atoms is in another dimension" << std::endl; std::cerr << "Cannot calculate distance for link since one of the atoms is in another dimension" << std::endl;
} }
catch (std::exception &ex) catch (std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Error finding atom for LINK distance calculation: " << ex.what() << std::endl; std::cerr << "Error finding atom for LINK distance calculation: " << ex.what() << std::endl;
} }
...@@ -5764,10 +5771,13 @@ void PDBFileParser::Parse(std::istream &is, cif::File &result) ...@@ -5764,10 +5771,13 @@ void PDBFileParser::Parse(std::istream &is, cif::File &result)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
{
std::cerr << "Error parsing PDB"; std::cerr << "Error parsing PDB";
if (mRec != nullptr) if (mRec != nullptr)
std::cerr << " at line " << mRec->mLineNr; std::cerr << " at line " << mRec->mLineNr;
std::cerr << std::endl; std::cerr << std::endl;
}
throw; throw;
} }
} }
...@@ -5947,7 +5957,7 @@ int PDBFileParser::PDBChain::AlignResToSeqRes() ...@@ -5947,7 +5957,7 @@ int PDBFileParser::PDBChain::AlignResToSeqRes()
switch (tb(x, y)) switch (tb(x, y))
{ {
case -1: case -1:
// if (cif::VERBOSE) // if (cif::VERBOSE > 0)
// std::cerr << "A residue found in the ATOM records " // std::cerr << "A residue found in the ATOM records "
// << "(" << ry[y].mMonID << " @ " << mDbref.chainID << ":" << ry[y].mSeqNum // << "(" << ry[y].mMonID << " @ " << mDbref.chainID << ":" << ry[y].mSeqNum
// << ((ry[y].mIcode == ' ' or ry[y].mIcode == 0) ? "" : std::string{ ry[y].mIcode }) << ")" // << ((ry[y].mIcode == ' ' or ry[y].mIcode == 0) ? "" : std::string{ ry[y].mIcode }) << ")"
...@@ -6034,7 +6044,6 @@ void ReadPDBFile(std::istream &pdbFile, cif::File &cifFile) ...@@ -6034,7 +6044,6 @@ void ReadPDBFile(std::istream &pdbFile, cif::File &cifFile)
p.Parse(pdbFile, cifFile); p.Parse(pdbFile, cifFile);
if (not cifFile.isValid()) if (not cifFile.isValid() and cif::VERBOSE >= 0)
// throw std::runtime_error("Resulting mmCIF file is invalid");
std::cerr << "Resulting mmCIF file is not valid!" << std::endl; std::cerr << "Resulting mmCIF file is not valid!" << std::endl;
} }
...@@ -1320,7 +1320,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab ...@@ -1320,7 +1320,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab
if (line != "REFINEMENT.") if (line != "REFINEMENT.")
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Unexpected data in REMARK 3" << std::endl; std::cerr << "Unexpected data in REMARK 3" << std::endl;
return false; return false;
} }
...@@ -1332,7 +1332,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab ...@@ -1332,7 +1332,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab
if (not std::regex_match(line, m, rxp)) if (not std::regex_match(line, m, rxp))
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Expected valid PROGRAM line in REMARK 3" << std::endl; std::cerr << "Expected valid PROGRAM line in REMARK 3" << std::endl;
return false; return false;
} }
...@@ -1367,6 +1367,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab ...@@ -1367,6 +1367,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab
} }
catch(const std::exception& e) catch(const std::exception& e)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error parsing REMARK 3 with " << parser->program() << std::endl std::cerr << "Error parsing REMARK 3 with " << parser->program() << std::endl
<< e.what() << '\n'; << e.what() << '\n';
score = 0; score = 0;
...@@ -1411,7 +1412,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab ...@@ -1411,7 +1412,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab
tryParser(new TNT_Remark3Parser(program, expMethod, r, db)); tryParser(new TNT_Remark3Parser(program, expMethod, r, db));
else if (ba::starts_with(program, "X-PLOR")) else if (ba::starts_with(program, "X-PLOR"))
tryParser(new XPLOR_Remark3Parser(program, expMethod, r, db)); tryParser(new XPLOR_Remark3Parser(program, expMethod, r, db));
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
std::cerr << "Skipping unknown program (" << program << ") in REMARK 3" << std::endl; std::cerr << "Skipping unknown program (" << program << ") in REMARK 3" << std::endl;
} }
...@@ -1420,6 +1421,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab ...@@ -1420,6 +1421,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab
bool guessProgram = scores.empty() or scores.front().score < 0.9f;; bool guessProgram = scores.empty() or scores.front().score < 0.9f;;
if (guessProgram) if (guessProgram)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Unknown or untrusted program in REMARK 3, trying all parsers to see if there is a match" << std::endl; std::cerr << "Unknown or untrusted program in REMARK 3, trying all parsers to see if there is a match" << std::endl;
tryParser(new BUSTER_TNT_Remark3Parser("BUSTER-TNT", expMethod, r, db)); tryParser(new BUSTER_TNT_Remark3Parser("BUSTER-TNT", expMethod, r, db));
...@@ -1444,7 +1446,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab ...@@ -1444,7 +1446,7 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab
auto& best = scores.front(); auto& best = scores.front();
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Choosing " << best.parser->program() << " version '" << best.parser->version() << "' as refinement program. Score = " << best.score << std::endl; std::cerr << "Choosing " << best.parser->program() << " version '" << best.parser->version() << "' as refinement program. Score = " << best.score << std::endl;
auto& software = db["software"]; auto& software = db["software"];
......
...@@ -1240,7 +1240,7 @@ void DSSPImpl::calculateSecondaryStructure() ...@@ -1240,7 +1240,7 @@ void DSSPImpl::calculateSecondaryStructure()
auto r1 = findRes(asym1, seq1); auto r1 = findRes(asym1, seq1);
if (r1 == mResidues.end()) if (r1 == mResidues.end())
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Missing (incomplete?) residue for SS bond when trying to find " << asym1 << '/' << seq1 << std::endl; std::cerr << "Missing (incomplete?) residue for SS bond when trying to find " << asym1 << '/' << seq1 << std::endl;
continue; continue;
// throw std::runtime_error("Invalid file, missing residue for SS bond"); // throw std::runtime_error("Invalid file, missing residue for SS bond");
...@@ -1249,7 +1249,7 @@ void DSSPImpl::calculateSecondaryStructure() ...@@ -1249,7 +1249,7 @@ void DSSPImpl::calculateSecondaryStructure()
auto r2 = findRes(asym2, seq2); auto r2 = findRes(asym2, seq2);
if (r2 == mResidues.end()) if (r2 == mResidues.end())
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Missing (incomplete?) residue for SS bond when trying to find " << asym2 << '/' << seq2 << std::endl; std::cerr << "Missing (incomplete?) residue for SS bond when trying to find " << asym2 << '/' << seq2 << std::endl;
continue; continue;
// throw std::runtime_error("Invalid file, missing residue for SS bond"); // throw std::runtime_error("Invalid file, missing residue for SS bond");
...@@ -1300,7 +1300,7 @@ void DSSPImpl::calculateSecondaryStructure() ...@@ -1300,7 +1300,7 @@ void DSSPImpl::calculateSecondaryStructure()
{ {
if (a == b) if (a == b)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "In the SS bonds list, the residue " << a->mM << " is bonded to itself" << std::endl; std::cerr << "In the SS bonds list, the residue " << a->mM << " is bonded to itself" << std::endl;
continue; continue;
} }
...@@ -1483,7 +1483,7 @@ SecondaryStructureType DSSP::operator()(const std::string &inAsymID, int inSeqID ...@@ -1483,7 +1483,7 @@ SecondaryStructureType DSSP::operator()(const std::string &inAsymID, int inSeqID
{ return r.mM.asymID() == inAsymID and r.mM.seqID() == inSeqID; }); { return r.mM.asymID() == inAsymID and r.mM.seqID() == inSeqID; });
if (i != mImpl->mResidues.end()) if (i != mImpl->mResidues.end())
result = i->mSecondaryStructure; result = i->mSecondaryStructure;
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
std::cerr << "Could not find secondary structure for " << inAsymID << ':' << inSeqID << std::endl; std::cerr << "Could not find secondary structure for " << inAsymID << ':' << inSeqID << std::endl;
return result; return result;
} }
...@@ -1501,7 +1501,7 @@ double DSSP::accessibility(const std::string &inAsymID, int inSeqID) const ...@@ -1501,7 +1501,7 @@ double DSSP::accessibility(const std::string &inAsymID, int inSeqID) const
{ return r.mM.asymID() == inAsymID and r.mM.seqID() == inSeqID; }); { return r.mM.asymID() == inAsymID and r.mM.seqID() == inSeqID; });
if (i != mImpl->mResidues.end()) if (i != mImpl->mResidues.end())
result = i->mSecondaryStructure; result = i->mSecondaryStructure;
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
std::cerr << "Could not find secondary structure for " << inAsymID << ':' << inSeqID << std::endl; std::cerr << "Could not find secondary structure for " << inAsymID << ':' << inSeqID << std::endl;
return result; return result;
} }
...@@ -1526,7 +1526,7 @@ bool DSSP::isAlphaHelixEndBeforeStart(const std::string &inAsymID, int inSeqID) ...@@ -1526,7 +1526,7 @@ bool DSSP::isAlphaHelixEndBeforeStart(const std::string &inAsymID, int inSeqID)
if (i != mImpl->mResidues.end() and i + 1 != mImpl->mResidues.end()) if (i != mImpl->mResidues.end() and i + 1 != mImpl->mResidues.end())
result = i->GetHelixFlag(HelixType::rh_alpha) == Helix::End and (i + 1)->GetHelixFlag(HelixType::rh_alpha) == Helix::Start; result = i->GetHelixFlag(HelixType::rh_alpha) == Helix::End and (i + 1)->GetHelixFlag(HelixType::rh_alpha) == Helix::Start;
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
std::cerr << "Could not find secondary structure for " << inAsymID << ':' << inSeqID << std::endl; std::cerr << "Could not find secondary structure for " << inAsymID << ':' << inSeqID << std::endl;
return result; return result;
......
...@@ -108,8 +108,8 @@ void FileImpl::load_data(const char *data, size_t length) ...@@ -108,8 +108,8 @@ void FileImpl::load_data(const char *data, size_t length)
// And validate, otherwise lots of functionality won't work // And validate, otherwise lots of functionality won't work
// if (mData.getValidator() == nullptr) // if (mData.getValidator() == nullptr)
mData.loadDictionary("mmcif_pdbx_v50"); mData.loadDictionary("mmcif_pdbx_v50");
if (not mData.isValid()) if (not mData.isValid() and cif::VERBOSE >= 0)
std::cerr << "Invalid mmCIF file" << (cif::VERBOSE ? "." : " use --verbose option to see errors") << std::endl; std::cerr << "Invalid mmCIF file" << (cif::VERBOSE > 0 ? "." : " use --verbose option to see errors") << std::endl;
} }
void FileImpl::load(const std::filesystem::path &path) void FileImpl::load(const std::filesystem::path &path)
...@@ -140,14 +140,14 @@ void FileImpl::load(const std::filesystem::path &path) ...@@ -140,14 +140,14 @@ void FileImpl::load(const std::filesystem::path &path)
{ {
try try
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "unrecognized file extension, trying cif" << std::endl; std::cerr << "unrecognized file extension, trying cif" << std::endl;
mData.load(in); mData.load(in);
} }
catch (const cif::CifParserError &e) catch (const cif::CifParserError &e)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Not cif, trying plain old PDB" << std::endl; std::cerr << "Not cif, trying plain old PDB" << std::endl;
// pffft... // pffft...
...@@ -169,6 +169,7 @@ void FileImpl::load(const std::filesystem::path &path) ...@@ -169,6 +169,7 @@ void FileImpl::load(const std::filesystem::path &path)
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Error trying to load file " << path << std::endl; std::cerr << "Error trying to load file " << path << std::endl;
throw; throw;
} }
...@@ -179,8 +180,8 @@ void FileImpl::load(const std::filesystem::path &path) ...@@ -179,8 +180,8 @@ void FileImpl::load(const std::filesystem::path &path)
// And validate, otherwise lots of functionality won't work // And validate, otherwise lots of functionality won't work
// if (mData.getValidator() == nullptr) // if (mData.getValidator() == nullptr)
mData.loadDictionary("mmcif_pdbx_v50"); mData.loadDictionary("mmcif_pdbx_v50");
if (not mData.isValid()) if (not mData.isValid() and cif::VERBOSE >= 0)
std::cerr << "Invalid mmCIF file" << (cif::VERBOSE ? "." : " use --verbose option to see errors") << std::endl; std::cerr << "Invalid mmCIF file" << (cif::VERBOSE > 0 ? "." : " use --verbose option to see errors") << std::endl;
} }
void FileImpl::save(const std::filesystem::path &path) void FileImpl::save(const std::filesystem::path &path)
...@@ -202,72 +203,44 @@ void FileImpl::save(const std::filesystem::path &path) ...@@ -202,72 +203,44 @@ void FileImpl::save(const std::filesystem::path &path)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Atom // Atom
struct AtomImpl Atom::AtomImpl::AtomImpl(cif::Datablock &db, const std::string &id, cif::Row row)
{
AtomImpl(const AtomImpl &i)
: mDb(i.mDb)
, mID(i.mID)
, mType(i.mType)
, mLocation(i.mLocation)
, mRefcount(1)
, mRow(i.mRow)
, mCachedRefs(i.mCachedRefs)
, mCompound(i.mCompound)
, mRadius(i.mRadius)
, mSymmetryCopy(i.mSymmetryCopy)
, mClone(true)
{
}
AtomImpl(cif::Datablock &db, const std::string &id)
: mDb(db)
, mID(id)
, mRefcount(1)
, mCompound(nullptr)
{
auto &cat = db["atom_site"];
mRow = cat[cif::Key("id") == mID];
}
AtomImpl(cif::Datablock &db, cif::Row &row)
: mDb(db)
, mID(row["id"].as<std::string>())
, mRefcount(1)
, mRow(row)
, mCompound(nullptr)
{
}
AtomImpl(cif::Datablock &db, const std::string &id, cif::Row row)
: mDb(db) : mDb(db)
, mID(id) , mID(id)
, mRefcount(1) , mRefcount(1)
, mRow(row) , mRow(row)
, mCompound(nullptr) , mCompound(nullptr)
{ {
} prefetch();
}
AtomImpl(const AtomImpl &impl, const Point &loc, const std::string &sym_op) // constructor for a symmetry copy of an atom
Atom::AtomImpl::AtomImpl(const AtomImpl &impl, const Point &loc, const std::string &sym_op)
: mDb(impl.mDb) : mDb(impl.mDb)
, mID(impl.mID) , mID(impl.mID)
, mType(impl.mType) , mType(impl.mType)
, mAtomID(impl.mAtomID)
, mCompID(impl.mCompID)
, mAsymID(impl.mAsymID)
, mSeqID(impl.mSeqID)
, mAltID(impl.mAltID)
, mAuthSeqID(impl.mAuthSeqID)
, mLocation(loc) , mLocation(loc)
, mRefcount(1) , mRefcount(1)
, mRow(impl.mRow) , mRow(impl.mRow)
, mCachedRefs(impl.mCachedRefs) , mCachedRefs(impl.mCachedRefs)
, mCompound(impl.mCompound) , mCompound(impl.mCompound)
, mRadius(impl.mRadius)
, mSymmetryCopy(true) , mSymmetryCopy(true)
, mSymmetryOperator(sym_op) , mSymmetryOperator(sym_op)
{ {
} }
void prefetch(std::string &atomID, std::string &compID, std::string &asymID, int &seqID, std::string &altID, std::string &authSeqID) void Atom::AtomImpl::prefetch()
{ {
// Prefetch some data // Prefetch some data
std::string symbol; std::string symbol;
cif::tie(symbol, atomID, compID, asymID, seqID, altID, authSeqID) = cif::tie(symbol, mAtomID, mCompID, mAsymID, mSeqID, mAltID, mAuthSeqID) =
mRow.get("type_symbol", "label_atom_id", "label_comp_id", "label_asym_id", "label_seq_id", "label_alt_id", "auth_seq_id"); mRow.get("type_symbol", "label_atom_id", "label_comp_id", "label_asym_id", "label_seq_id", "label_alt_id", "auth_seq_id");
if (symbol != "X") if (symbol != "X")
...@@ -277,21 +250,23 @@ struct AtomImpl ...@@ -277,21 +250,23 @@ struct AtomImpl
cif::tie(x, y, z) = mRow.get("Cartn_x", "Cartn_y", "Cartn_z"); cif::tie(x, y, z) = mRow.get("Cartn_x", "Cartn_y", "Cartn_z");
mLocation = Point(x, y, z); mLocation = Point(x, y, z);
} }
void reference() int Atom::AtomImpl::compare(const AtomImpl &b) const
{ {
++mRefcount; int d = mAsymID.compare(b.mAsymID);
} if (d == 0)
d = mSeqID - b.mSeqID;
if (d == 0)
d = mAtomID.compare(b.mAtomID);
if (d == 0)
d = mAuthSeqID.compare(b.mAuthSeqID);
void release() return d;
{ }
if (--mRefcount <= 0)
delete this;
}
bool getAnisoU(float anisou[6]) const bool Atom::AtomImpl::getAnisoU(float anisou[6]) const
{ {
bool result = false; bool result = false;
auto cat = mDb.get("atom_site_anisotrop"); auto cat = mDb.get("atom_site_anisotrop");
...@@ -304,38 +279,32 @@ struct AtomImpl ...@@ -304,38 +279,32 @@ struct AtomImpl
r.get("U[1][1]", "U[1][2]", "U[1][3]", "U[2][2]", "U[2][3]", "U[3][3]"); r.get("U[1][1]", "U[1][2]", "U[1][3]", "U[2][2]", "U[2][3]", "U[3][3]");
result = true; result = true;
} }
catch(const std::exception& e) catch (const std::exception &e)
{ {
} }
} }
return result; return result;
} }
void moveTo(const Point &p) void Atom::AtomImpl::moveTo(const Point &p)
{ {
assert(not mSymmetryCopy); assert(not mSymmetryCopy);
if (mSymmetryCopy) if (mSymmetryCopy)
throw std::runtime_error("Moving symmetry copy"); throw std::runtime_error("Moving symmetry copy");
if (not mClone) if (not mClone)
{ {
property("Cartn_x", std::to_string(p.getX())); mRow.assign("Cartn_x", std::to_string(p.getX()), true, false);
property("Cartn_y", std::to_string(p.getY())); mRow.assign("Cartn_y", std::to_string(p.getY()), true, false);
property("Cartn_z", std::to_string(p.getZ())); mRow.assign("Cartn_z", std::to_string(p.getZ()), true, false);
} }
// boost::format kPosFmt("%.3f");
//
// mRow["Cartn_x"] = (kPosFmt % p.getX()).str();
// mRow["Cartn_y"] = (kPosFmt % p.getY()).str();
// mRow["Cartn_z"] = (kPosFmt % p.getZ()).str();
mLocation = p; mLocation = p;
} }
const Compound &comp() const const Compound &Atom::AtomImpl::comp() const
{ {
if (mCompound == nullptr) if (mCompound == nullptr)
{ {
std::string compID; std::string compID;
...@@ -343,7 +312,7 @@ struct AtomImpl ...@@ -343,7 +312,7 @@ struct AtomImpl
mCompound = CompoundFactory::instance().create(compID); mCompound = CompoundFactory::instance().create(compID);
if (cif::VERBOSE and mCompound == nullptr) if (cif::VERBOSE > 0 and mCompound == nullptr)
std::cerr << "Compound not found: '" << compID << '\'' << std::endl; std::cerr << "Compound not found: '" << compID << '\'' << std::endl;
} }
...@@ -351,15 +320,10 @@ struct AtomImpl ...@@ -351,15 +320,10 @@ struct AtomImpl
throw std::runtime_error("no compound"); throw std::runtime_error("no compound");
return *mCompound; return *mCompound;
} }
float radius() const
{
return mRadius;
}
const std::string property(const std::string_view name) const const std::string Atom::AtomImpl::get_property(const std::string_view name) const
{ {
for (auto &&[tag, ref] : mCachedRefs) for (auto &&[tag, ref] : mCachedRefs)
{ {
if (tag == name) if (tag == name)
...@@ -368,10 +332,10 @@ struct AtomImpl ...@@ -368,10 +332,10 @@ struct AtomImpl
mCachedRefs.emplace_back(name, mRow[name]); mCachedRefs.emplace_back(name, mRow[name]);
return std::get<1>(mCachedRefs.back()).as<std::string>(); return std::get<1>(mCachedRefs.back()).as<std::string>();
} }
void property(const std::string_view name, const std::string &value) void Atom::AtomImpl::set_property(const std::string_view name, const std::string &value)
{ {
for (auto &&[tag, ref] : mCachedRefs) for (auto &&[tag, ref] : mCachedRefs)
{ {
if (tag != name) if (tag != name)
...@@ -383,262 +347,93 @@ struct AtomImpl ...@@ -383,262 +347,93 @@ struct AtomImpl
mCachedRefs.emplace_back(name, mRow[name]); mCachedRefs.emplace_back(name, mRow[name]);
std::get<1>(mCachedRefs.back()) = value; std::get<1>(mCachedRefs.back()) = value;
}
const cif::Datablock &mDb;
std::string mID;
AtomType mType;
Point mLocation;
int mRefcount;
cif::Row mRow;
mutable std::vector<std::tuple<std::string,cif::detail::ItemReference>> mCachedRefs;
mutable const Compound *mCompound = nullptr;
float mRadius = std::nanf("4");
bool mSymmetryCopy = false;
bool mClone = false;
std::string mSymmetryOperator = "1_555";
// clipper::RTop_orth mRTop;
// Point mD;
// int32_t mRTix;
};
//Atom::Atom(const File& f, const std::string& id)
// : mImpl(new AtomImpl(f, id))
//{
//}
//
Atom::Atom()
: Atom(nullptr)
{
}
Atom::Atom(AtomImpl *impl)
: mImpl_(impl)
{
if (mImpl_)
mImpl_->prefetch(mAtomID, mCompID, mAsymID, mSeqID, mAltID, mAuthSeqID);
} }
Atom::Atom(cif::Datablock &db, cif::Row &row) Atom::Atom(cif::Datablock &db, cif::Row &row)
: Atom(new AtomImpl(db, row)) : Atom(std::make_shared<AtomImpl>(db, row["id"].as<std::string>(), row))
{ {
} }
Atom::Atom(const Atom &rhs, const Point &loc, const std::string &sym_op) Atom::Atom(const Atom &rhs, const Point &loc, const std::string &sym_op)
: Atom(new AtomImpl(*rhs.mImpl_, loc, sym_op)) : Atom(std::make_shared<AtomImpl>(*rhs.mImpl, loc, sym_op))
{ {
} }
Atom::Atom(const Atom &rhs)
: mImpl_(rhs.mImpl_)
, mAtomID(rhs.mAtomID)
, mCompID(rhs.mCompID)
, mAsymID(rhs.mAsymID)
, mSeqID(rhs.mSeqID)
, mAltID(rhs.mAltID)
, mAuthSeqID(rhs.mAuthSeqID)
{
if (mImpl_)
mImpl_->reference();
}
Atom::~Atom()
{
if (mImpl_)
mImpl_->release();
}
AtomImpl *Atom::impl()
{
if (mImpl_ == nullptr)
throw std::runtime_error("atom is not set");
return mImpl_;
}
const AtomImpl *Atom::impl() const
{
if (mImpl_ == nullptr)
throw std::runtime_error("atom is not set");
return mImpl_;
}
Atom Atom::clone() const
{
return Atom(mImpl_ ? new AtomImpl(*mImpl_) : nullptr);
}
Atom &Atom::operator=(const Atom &rhs)
{
if (this != &rhs)
{
if (mImpl_)
mImpl_->release();
mImpl_ = rhs.mImpl_;
mAtomID = rhs.mAtomID;
mCompID = rhs.mCompID;
mAsymID = rhs.mAsymID;
mSeqID = rhs.mSeqID;
mAltID = rhs.mAltID;
mAuthSeqID = rhs.mAuthSeqID;
if (mImpl_)
mImpl_->reference();
}
return *this;
}
const cif::Row Atom::getRow() const
{
return mImpl_->mRow;
}
const cif::Row Atom::getRowAniso() const const cif::Row Atom::getRowAniso() const
{ {
auto &db = mImpl_->mDb; auto &db = mImpl->mDb;
auto cat = db.get("atom_site_anisotrop"); auto cat = db.get("atom_site_anisotrop");
if (not cat) if (not cat)
return {}; return {};
else else
return cat->find1(cif::Key("id") == mImpl_->mID); return cat->find1(cif::Key("id") == mImpl->mID);
}
template <>
std::string Atom::property<std::string>(const std::string_view name) const
{
return impl()->property(name);
}
template <>
int Atom::property<int>(const std::string_view name) const
{
auto v = impl()->property(name);
return v.empty() ? 0 : stoi(v);
}
template <>
float Atom::property<float>(const std::string_view name) const
{
return stof(impl()->property(name));
}
void Atom::property(const std::string_view name, const std::string &value)
{
impl()->property(name, value);
}
const std::string &Atom::id() const
{
return impl()->mID;
}
AtomType Atom::type() const
{
return impl()->mType;
}
int Atom::charge() const
{
return property<int>("pdbx_formal_charge");
} }
float Atom::uIso() const float Atom::uIso() const
{ {
float result; float result;
if (not property<std::string>("U_iso_or_equiv").empty()) if (not get_property<std::string>("U_iso_or_equiv").empty())
result = property<float>("U_iso_or_equiv"); result = get_property<float>("U_iso_or_equiv");
else if (not property<std::string>("B_iso_or_equiv").empty()) else if (not get_property<std::string>("B_iso_or_equiv").empty())
result = property<float>("B_iso_or_equiv") / static_cast<float>(8 * kPI * kPI); result = get_property<float>("B_iso_or_equiv") / static_cast<float>(8 * kPI * kPI);
else else
throw std::runtime_error("Missing B_iso or U_iso"); throw std::runtime_error("Missing B_iso or U_iso");
return result; return result;
} }
bool Atom::getAnisoU(float anisou[6]) const std::string Atom::labelID() const
{
return impl()->getAnisoU(anisou);
}
float Atom::occupancy() const
{ {
return property<float>("occupancy"); return mImpl->mCompID + '_' + mImpl->mAsymID + '_' + std::to_string(mImpl->mSeqID) + ':' + mImpl->mAtomID;
} }
// const std::string& Atom::labelAtomID() const std::string Atom::pdbID() const
// {
// return impl()->mAtomID;
// }
// const std::string& Atom::labelCompID() const
// {
// return impl()->mCompID;
// }
// const std::string& Atom::labelAsymID() const
// {
// return impl()->mAsymID;
// }
std::string Atom::labelEntityID() const
{ {
return property<std::string>("label_entity_id"); return get_property<std::string>("auth_comp_id") + '_' +
get_property<std::string>("auth_asym_id") + '_' +
get_property<std::string>("auth_seq_id") +
get_property<std::string>("pdbx_PDB_ins_code");
} }
std::string Atom::authAsymID() const int Atom::charge() const
{ {
return property<std::string>("auth_asym_id"); return get_property<int>("pdbx_formal_charge");
} }
std::string Atom::authAtomID() const float Atom::occupancy() const
{ {
return property<std::string>("auth_atom_id"); return get_property<float>("occupancy");
} }
std::string Atom::pdbxAuthAltID() const std::string Atom::labelEntityID() const
{ {
return property<std::string>("pdbx_auth_alt_id"); return get_property<std::string>("label_entity_id");
} }
std::string Atom::pdbxAuthInsCode() const std::string Atom::authAtomID() const
{ {
return property<std::string>("pdbx_PDB_ins_code"); return get_property<std::string>("auth_atom_id");
} }
std::string Atom::authCompID() const std::string Atom::authCompID() const
{ {
return property<std::string>("auth_comp_id"); return get_property<std::string>("auth_comp_id");
} }
std::string Atom::labelID() const std::string Atom::authAsymID() const
{
return mCompID + '_' + mAsymID + '_' + std::to_string(mSeqID) + ':' + mAtomID;
}
std::string Atom::pdbID() const
{ {
return property<std::string>("auth_comp_id") + '_' + return get_property<std::string>("auth_asym_id");
property<std::string>("auth_asym_id") + '_' +
property<std::string>("auth_seq_id") +
property<std::string>("pdbx_PDB_ins_code");
} }
Point Atom::location() const std::string Atom::pdbxAuthInsCode() const
{ {
return impl()->mLocation; return get_property<std::string>("pdbx_PDB_ins_code");
} }
void Atom::location(Point p) std::string Atom::pdbxAuthAltID() const
{ {
impl()->moveTo(p); return get_property<std::string>("pdbx_auth_alt_id");
} }
void Atom::translate(Point t) void Atom::translate(Point t)
...@@ -655,89 +450,32 @@ void Atom::rotate(Quaternion q) ...@@ -655,89 +450,32 @@ void Atom::rotate(Quaternion q)
location(loc); location(loc);
} }
// Atom Atom::symmetryCopy(const Point& d, const clipper::RTop_orth& rt) void Atom::translateAndRotate(Point t, Quaternion q)
// {
// return Atom(new AtomImpl(*impl(), d, rt));
// }
// bool Atom::isSymmetryCopy() const
// {
// return impl()->mSymmetryCopy;
// }
// std::string Atom::symmetry() const
// {
// return clipper::Symop(impl()->mRTop).format() + "\n" + impl()->mRTop.format();
// }
bool Atom::isSymmetryCopy() const
{
return mImpl_->mSymmetryCopy;
}
std::string Atom::symmetry() const
{ {
return mImpl_->mSymmetryOperator; auto loc = location();
} loc += t;
loc.rotate(q);
// const clipper::RTop_orth& Atom::symop() const location(loc);
// {
// return impl()->mRTop;
// }
const Compound &Atom::comp() const
{
return impl()->comp();
} }
bool Atom::isWater() const void Atom::translateRotateAndTranslate(Point t1, Quaternion q, Point t2)
{ {
(void)impl(); auto loc = location();
return mCompID == "HOH" or mCompID == "H2O" or mCompID == "WAT"; loc += t1;
loc.rotate(q);
loc += t2;
location(loc);
} }
bool Atom::operator==(const Atom &rhs) const bool Atom::operator==(const Atom &rhs) const
{ {
return impl() == rhs.impl() or return mImpl == rhs.mImpl or
(&impl()->mDb == &rhs.impl()->mDb and impl()->mID == rhs.impl()->mID); (&mImpl->mDb == &rhs.mImpl->mDb and mImpl->mID == rhs.mImpl->mID);
}
// clipper::Atom Atom::toClipper() const
// {
// return impl()->toClipper();
// }
// void Atom::calculateRadius(float resHigh, float resLow, float perc)
// {
// AtomShape shape(*this, resHigh, resLow, false);
// impl()->mRadius = shape.radius();
// // verbose
// if (cif::VERBOSE > 1)
// cout << "Calculated radius for " << AtomTypeTraits(impl()->mType).name() << " with charge " << charge() << " is " << impl()->mRadius << std::endl;
// }
float Atom::radius() const
{
return impl()->mRadius;
}
int Atom::compare(const Atom &b) const
{
int d = mAsymID.compare(b.mAsymID);
if (d == 0)
d = mSeqID - b.mSeqID;
if (d == 0)
d = mAtomID.compare(b.mAtomID);
if (d == 0)
d = mAuthSeqID.compare(b.mAuthSeqID);
return d;
} }
void Atom::setID(int id) void Atom::setID(int id)
{ {
impl()->mID = std::to_string(id); mImpl->mID = std::to_string(id);
} }
std::ostream &operator<<(std::ostream &os, const Atom &atom) std::ostream &operator<<(std::ostream &os, const Atom &atom)
...@@ -755,66 +493,6 @@ std::ostream &operator<<(std::ostream &os, const Atom &atom) ...@@ -755,66 +493,6 @@ std::ostream &operator<<(std::ostream &os, const Atom &atom)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// residue // 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)
{
// for (auto &a : mStructure->atoms())
// {
// if (a.labelAsymID() != mAsymID or
// a.labelCompID() != mCompoundID)
// continue;
// 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);
// }
// assert(not mAtoms.empty());
}
Residue::Residue(const Structure &structure, const std::string &compoundID, const std::string &asymID)
: Residue(structure, compoundID, asymID, 0, {})
{
}
Residue::Residue(const Structure &structure, const std::string &compoundID,
const std::string &asymID, int seqID, const std::string &authSeqID)
: mStructure(&structure)
, mCompoundID(compoundID)
, mAsymID(asymID)
, mSeqID(seqID)
, mAuthSeqID(authSeqID)
{
assert(mCompoundID != "HOH");
// for (auto &a : mStructure->atoms())
// {
// if (mSeqID > 0 and a.labelSeqID() != mSeqID)
// continue;
// if (a.labelAsymID() != mAsymID or
// a.labelCompID() != mCompoundID)
// continue;
// mAtoms.push_back(a);
// }
}
Residue::Residue(Residue &&rhs) Residue::Residue(Residue &&rhs)
: mStructure(rhs.mStructure) : mStructure(rhs.mStructure)
, mCompoundID(std::move(rhs.mCompoundID)) , mCompoundID(std::move(rhs.mCompoundID))
...@@ -823,13 +501,13 @@ Residue::Residue(Residue &&rhs) ...@@ -823,13 +501,13 @@ Residue::Residue(Residue &&rhs)
, mAuthSeqID(rhs.mAuthSeqID) , mAuthSeqID(rhs.mAuthSeqID)
, mAtoms(std::move(rhs.mAtoms)) , mAtoms(std::move(rhs.mAtoms))
{ {
//std::cerr << "move constructor residue" << std::endl; // std::cerr << "move constructor residue" << std::endl;
rhs.mStructure = nullptr; rhs.mStructure = nullptr;
} }
Residue &Residue::operator=(Residue &&rhs) Residue &Residue::operator=(Residue &&rhs)
{ {
//std::cerr << "move assignment residue" << std::endl; // std::cerr << "move assignment residue" << std::endl;
mStructure = rhs.mStructure; mStructure = rhs.mStructure;
rhs.mStructure = nullptr; rhs.mStructure = nullptr;
mCompoundID = std::move(rhs.mCompoundID); mCompoundID = std::move(rhs.mCompoundID);
...@@ -843,7 +521,7 @@ Residue &Residue::operator=(Residue &&rhs) ...@@ -843,7 +521,7 @@ Residue &Residue::operator=(Residue &&rhs)
Residue::~Residue() Residue::~Residue()
{ {
//std::cerr << "~Residue" << std::endl; // std::cerr << "~Residue" << std::endl;
} }
std::string Residue::entityID() const std::string Residue::entityID() const
...@@ -957,7 +635,7 @@ AtomView Residue::unique_atoms() const ...@@ -957,7 +635,7 @@ AtomView Residue::unique_atoms() const
firstAlt = alt; firstAlt = alt;
else if (alt != firstAlt) else if (alt != firstAlt)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "skipping alternate atom " << atom << std::endl; std::cerr << "skipping alternate atom " << atom << std::endl;
continue; continue;
} }
...@@ -1163,7 +841,7 @@ float Monomer::phi() const ...@@ -1163,7 +841,7 @@ float Monomer::phi() const
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
} }
...@@ -1185,7 +863,7 @@ float Monomer::psi() const ...@@ -1185,7 +863,7 @@ float Monomer::psi() const
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
} }
...@@ -1209,7 +887,7 @@ float Monomer::alpha() const ...@@ -1209,7 +887,7 @@ float Monomer::alpha() const
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << ex.what() << std::endl; std::cerr << ex.what() << std::endl;
} }
...@@ -1237,7 +915,7 @@ float Monomer::kappa() const ...@@ -1237,7 +915,7 @@ float Monomer::kappa() const
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "When trying to calculate kappa for " << asymID() << ':' << seqID() << ": " std::cerr << "When trying to calculate kappa for " << asymID() << ':' << seqID() << ": "
<< ex.what() << std::endl; << ex.what() << std::endl;
} }
...@@ -1260,7 +938,7 @@ float Monomer::tco() const ...@@ -1260,7 +938,7 @@ float Monomer::tco() const
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "When trying to calculate tco for " << asymID() << ':' << seqID() << ": " std::cerr << "When trying to calculate tco for " << asymID() << ':' << seqID() << ": "
<< ex.what() << std::endl; << ex.what() << std::endl;
} }
...@@ -1279,7 +957,7 @@ float Monomer::omega() const ...@@ -1279,7 +957,7 @@ float Monomer::omega() const
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "When trying to calculate omega for " << asymID() << ':' << seqID() << ": " std::cerr << "When trying to calculate omega for " << asymID() << ':' << seqID() << ": "
<< ex.what() << std::endl; << ex.what() << std::endl;
} }
...@@ -1350,7 +1028,7 @@ float Monomer::chi(size_t nr) const ...@@ -1350,7 +1028,7 @@ float Monomer::chi(size_t nr) const
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
result = 0; result = 0;
} }
...@@ -1516,7 +1194,7 @@ Polymer::Polymer(const Structure &s, const std::string &entityID, const std::str ...@@ -1516,7 +1194,7 @@ Polymer::Polymer(const Structure &s, const std::string &entityID, const std::str
ix[seqID] = index; ix[seqID] = index;
emplace_back(*this, index, seqID, authSeqID, compoundID); emplace_back(*this, index, seqID, authSeqID, compoundID);
} }
else if (cif::VERBOSE) else if (cif::VERBOSE > 0)
{ {
Monomer m{*this, index, seqID, authSeqID, compoundID}; Monomer m{*this, index, seqID, authSeqID, compoundID};
std::cerr << "Dropping alternate residue " << m << std::endl; std::cerr << "Dropping alternate residue " << m << std::endl;
...@@ -1598,7 +1276,7 @@ File::~File() ...@@ -1598,7 +1276,7 @@ File::~File()
delete mImpl; delete mImpl;
} }
cif::Datablock& File::createDatablock(const std::string_view name) cif::Datablock &File::createDatablock(const std::string_view name)
{ {
auto db = new cif::Datablock(name); auto db = new cif::Datablock(name);
...@@ -1661,7 +1339,7 @@ Structure::Structure(File &f, size_t modelNr, StructureOpenOptions options) ...@@ -1661,7 +1339,7 @@ Structure::Structure(File &f, size_t modelNr, StructureOpenOptions options)
cif::tie(model_nr) = atomCat.front().get("pdbx_PDB_model_num"); cif::tie(model_nr) = atomCat.front().get("pdbx_PDB_model_num");
if (model_nr and *model_nr != mModelNr) if (model_nr and *model_nr != mModelNr)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "No atoms loaded for model 1, trying model " << *model_nr << std::endl; std::cerr << "No atoms loaded for model 1, trying model " << *model_nr << std::endl;
mModelNr = *model_nr; mModelNr = *model_nr;
loadAtomsForModel(options); loadAtomsForModel(options);
...@@ -1669,7 +1347,10 @@ Structure::Structure(File &f, size_t modelNr, StructureOpenOptions options) ...@@ -1669,7 +1347,10 @@ Structure::Structure(File &f, size_t modelNr, StructureOpenOptions options)
} }
if (mAtoms.empty()) if (mAtoms.empty())
{
if (cif::VERBOSE >= 0)
std::cerr << "Warning: no atoms loaded" << std::endl; std::cerr << "Warning: no atoms loaded" << std::endl;
}
else else
loadData(); loadData();
} }
...@@ -1692,7 +1373,7 @@ void Structure::loadAtomsForModel(StructureOpenOptions options) ...@@ -1692,7 +1373,7 @@ void Structure::loadAtomsForModel(StructureOpenOptions options)
if ((options bitand StructureOpenOptions::SkipHydrogen) and type_symbol == "H") if ((options bitand StructureOpenOptions::SkipHydrogen) and type_symbol == "H")
continue; continue;
mAtoms.emplace_back(new AtomImpl(*db, id, a)); mAtoms.emplace_back(std::make_shared<Atom::AtomImpl>(*db, id, a));
} }
} }
...@@ -1736,7 +1417,7 @@ void Structure::loadData() ...@@ -1736,7 +1417,7 @@ void Structure::loadData()
r.get("asym_id", "mon_id", "pdb_seq_num"); r.get("asym_id", "mon_id", "pdb_seq_num");
if (monID == "HOH") if (monID == "HOH")
mNonPolymers.emplace_back(*this, monID, asymID, pdbSeqNum); mNonPolymers.emplace_back(*this, monID, asymID, 0, pdbSeqNum);
else if (mNonPolymers.empty() or mNonPolymers.back().asymID() != asymID) else if (mNonPolymers.empty() or mNonPolymers.back().asymID() != asymID)
mNonPolymers.emplace_back(*this, monID, asymID); mNonPolymers.emplace_back(*this, monID, asymID);
} }
...@@ -1749,35 +1430,35 @@ void Structure::loadData() ...@@ -1749,35 +1430,35 @@ void Structure::loadData()
cif::tie(asymID, monID, num) = cif::tie(asymID, monID, num) =
r.get("asym_id", "mon_id", "num"); r.get("asym_id", "mon_id", "num");
mBranchResidues.emplace_back(*this, monID, asymID, num); mBranchResidues.emplace_back(*this, monID, asymID, 0, num);
} }
// place atoms in residues // place atoms in residues
using key_type = std::tuple<std::string,std::string,int>; using key_type = std::tuple<std::string, std::string, int>;
using map_type = std::map<key_type,Residue*>; using map_type = std::map<key_type, Residue *>;
map_type resMap; map_type resMap;
for (auto &poly : mPolymers) for (auto &poly : mPolymers)
{ {
for (auto &res : poly) for (auto &res : poly)
resMap[{ res.asymID(), res.compoundID(), res.seqID() }] = &res; resMap[{res.asymID(), res.compoundID(), res.seqID()}] = &res;
} }
for (auto &res : mNonPolymers) for (auto &res : mNonPolymers)
resMap[{ res.asymID(), res.compoundID(), (res.isWater() ? std::stoi(res.mAuthSeqID) : res.seqID()) }] = &res; resMap[{res.asymID(), res.compoundID(), (res.isWater() ? std::stoi(res.mAuthSeqID) : res.seqID())}] = &res;
for (auto &res : mBranchResidues) for (auto &res : mBranchResidues)
resMap[{ res.asymID(), res.compoundID(), res.seqID() }] = &res; resMap[{res.asymID(), res.compoundID(), res.seqID()}] = &res;
for (auto &atom: mAtoms) for (auto &atom : mAtoms)
{ {
key_type k(atom.labelAsymID(), atom.labelCompID(), atom.isWater() ? std::stoi(atom.authSeqID()) : atom.labelSeqID()); key_type k(atom.labelAsymID(), atom.labelCompID(), atom.isWater() ? std::stoi(atom.authSeqID()) : atom.labelSeqID());
auto ri = resMap.find(k); auto ri = resMap.find(k);
if (ri == resMap.end()) if (ri == resMap.end())
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Missing residue for atom " << atom << std::endl; std::cerr << "Missing residue for atom " << atom << std::endl;
assert(false); assert(false);
...@@ -1836,7 +1517,7 @@ AtomView Structure::waters() const ...@@ -1836,7 +1517,7 @@ AtomView Structure::waters() const
for (auto &a : mAtoms) for (auto &a : mAtoms)
{ {
if (a.property<std::string>("label_entity_id") == waterEntityID) if (a.get_property<std::string>("label_entity_id") == waterEntityID)
result.push_back(a); result.push_back(a);
} }
...@@ -1965,7 +1646,7 @@ const Residue &Structure::getResidue(const std::string &asymID, const std::strin ...@@ -1965,7 +1646,7 @@ const Residue &Structure::getResidue(const std::string &asymID, const std::strin
Residue &Structure::getResidue(const std::string &asymID, const std::string &compID, int seqID) Residue &Structure::getResidue(const std::string &asymID, const std::string &compID, int seqID)
{ {
return const_cast<Residue&>(const_cast<Structure const&>(*this).getResidue(asymID, compID, seqID)); return const_cast<Residue &>(const_cast<Structure const &>(*this).getResidue(asymID, compID, seqID));
} }
const Residue &Structure::getResidue(const std::string &asymID) const const Residue &Structure::getResidue(const std::string &asymID) const
...@@ -1983,7 +1664,7 @@ const Residue &Structure::getResidue(const std::string &asymID) const ...@@ -1983,7 +1664,7 @@ const Residue &Structure::getResidue(const std::string &asymID) const
Residue &Structure::getResidue(const std::string &asymID) Residue &Structure::getResidue(const std::string &asymID)
{ {
return const_cast<Residue&>(const_cast<Structure const&>(*this).getResidue(asymID)); return const_cast<Residue &>(const_cast<Structure const &>(*this).getResidue(asymID));
} }
File &Structure::getFile() const File &Structure::getFile() const
...@@ -2169,8 +1850,7 @@ std::string Structure::insertCompound(const std::string &compoundID, bool isEnti ...@@ -2169,8 +1850,7 @@ std::string Structure::insertCompound(const std::string &compoundID, bool isEnti
auto r = chemComp.find(cif::Key("id") == compoundID); auto r = chemComp.find(cif::Key("id") == compoundID);
if (r.empty()) if (r.empty())
{ {
chemComp.emplace({ chemComp.emplace({{"id", compoundID},
{"id", compoundID},
{"name", compound->name()}, {"name", compound->name()},
{"formula", compound->formula()}, {"formula", compound->formula()},
{"formula_weight", compound->formulaWeight()}, {"formula_weight", compound->formulaWeight()},
...@@ -2186,19 +1866,17 @@ std::string Structure::insertCompound(const std::string &compoundID, bool isEnti ...@@ -2186,19 +1866,17 @@ std::string Structure::insertCompound(const std::string &compoundID, bool isEnti
{ {
entity_id = pdbxEntityNonpoly.find1<std::string>("comp_id"_key == compoundID, "entity_id"); entity_id = pdbxEntityNonpoly.find1<std::string>("comp_id"_key == compoundID, "entity_id");
} }
catch(const std::exception& ex) catch (const std::exception &ex)
{ {
auto &entity = db["entity"]; auto &entity = db["entity"];
entity_id = entity.getUniqueID(""); entity_id = entity.getUniqueID("");
entity.emplace({ entity.emplace({{"id", entity_id},
{"id", entity_id},
{"type", "non-polymer"}, {"type", "non-polymer"},
{"pdbx_description", compound->name()}, {"pdbx_description", compound->name()},
{"formula_weight", compound->formulaWeight()}}); {"formula_weight", compound->formulaWeight()}});
pdbxEntityNonpoly.emplace({ pdbxEntityNonpoly.emplace({{"entity_id", entity_id},
{"entity_id", entity_id},
{"name", compound->name()}, {"name", compound->name()},
{"comp_id", compoundID}}); {"comp_id", compoundID}});
} }
...@@ -2207,65 +1885,6 @@ std::string Structure::insertCompound(const std::string &compoundID, bool isEnti ...@@ -2207,65 +1885,6 @@ std::string Structure::insertCompound(const std::string &compoundID, bool isEnti
return entity_id; return entity_id;
} }
// // --------------------------------------------------------------------
// Structure::residue_iterator::residue_iterator(const Structure* s, poly_iterator polyIter, size_t polyResIndex, size_t nonPolyIndex)
// : mStructure(*s), mPolyIter(polyIter), mPolyResIndex(polyResIndex), mNonPolyIndex(nonPolyIndex)
// {
// while (mPolyIter != mStructure.mPolymers.end() and mPolyResIndex == mPolyIter->size())
// ++mPolyIter;
// }
// auto Structure::residue_iterator::operator*() -> reference
// {
// if (mPolyIter != mStructure.mPolymers.end())
// return (*mPolyIter)[mPolyResIndex];
// else
// return mStructure.mNonPolymers[mNonPolyIndex];
// }
// auto Structure::residue_iterator::operator->() -> pointer
// {
// if (mPolyIter != mStructure.mPolymers.end())
// return &(*mPolyIter)[mPolyResIndex];
// else
// return &mStructure.mNonPolymers[mNonPolyIndex];
// }
// Structure::residue_iterator& Structure::residue_iterator::operator++()
// {
// if (mPolyIter != mStructure.mPolymers.end())
// {
// ++mPolyResIndex;
// if (mPolyResIndex >= mPolyIter->size())
// {
// ++mPolyIter;
// mPolyResIndex = 0;
// }
// }
// else
// ++mNonPolyIndex;
// return *this;
// }
// Structure::residue_iterator Structure::residue_iterator::operator++(int)
// {
// auto result = *this;
// operator++();
// return result;
// }
// bool Structure::residue_iterator::operator==(const Structure::residue_iterator& rhs) const
// {
// return mPolyIter == rhs.mPolyIter and mPolyResIndex == rhs.mPolyResIndex and mNonPolyIndex == rhs.mNonPolyIndex;
// }
// bool Structure::residue_iterator::operator!=(const Structure::residue_iterator& rhs) const
// {
// return mPolyIter != rhs.mPolyIter or mPolyResIndex != rhs.mPolyResIndex or mNonPolyIndex != rhs.mNonPolyIndex;
// }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
void Structure::removeAtom(Atom &a) void Structure::removeAtom(Atom &a)
...@@ -2312,7 +1931,7 @@ void Structure::swapAtoms(Atom &a1, Atom &a2) ...@@ -2312,7 +1931,7 @@ void Structure::swapAtoms(Atom &a1, Atom &a2)
auto l2 = r2["label_atom_id"]; auto l2 = r2["label_atom_id"];
l1.swap(l2); l1.swap(l2);
std::swap(a1.mAtomID, a2.mAtomID); std::swap(a1.mImpl->mAtomID, a2.mImpl->mAtomID);
auto l3 = r1["auth_atom_id"]; auto l3 = r1["auth_atom_id"];
auto l4 = r2["auth_atom_id"]; auto l4 = r2["auth_atom_id"];
...@@ -2402,6 +2021,7 @@ void Structure::changeResidue(Residue &res, const std::string &newCompound, ...@@ -2402,6 +2021,7 @@ void Structure::changeResidue(Residue &res, const std::string &newCompound,
{ return a.labelAtomID() == a1; }); { return a.labelAtomID() == a1; });
if (i == atoms.end()) if (i == atoms.end())
{ {
if (cif::VERBOSE >= 0)
std::cerr << "Missing atom for atom ID " << a1 << std::endl; std::cerr << "Missing atom for atom ID " << a1 << std::endl;
continue; continue;
} }
...@@ -2442,50 +2062,47 @@ std::string Structure::createNonpoly(const std::string &entity_id, const std::ve ...@@ -2442,50 +2062,47 @@ std::string Structure::createNonpoly(const std::string &entity_id, const std::ve
auto &struct_asym = db["struct_asym"]; auto &struct_asym = db["struct_asym"];
std::string asym_id = struct_asym.getUniqueID(); std::string asym_id = struct_asym.getUniqueID();
struct_asym.emplace({ struct_asym.emplace({{"id", asym_id},
{ "id", asym_id }, {"pdbx_blank_PDB_chainid_flag", "N"},
{ "pdbx_blank_PDB_chainid_flag", "N" }, {"pdbx_modified", "N"},
{ "pdbx_modified", "N" }, {"entity_id", entity_id},
{ "entity_id", entity_id }, {"details", "?"}});
{ "details", "?" }
});
std::string comp_id = db["pdbx_entity_nonpoly"].find1<std::string>("entity_id"_key == entity_id, "comp_id"); std::string comp_id = db["pdbx_entity_nonpoly"].find1<std::string>("entity_id"_key == entity_id, "comp_id");
auto &atom_site = db["atom_site"]; auto &atom_site = db["atom_site"];
for (auto& atom: atoms) auto &res = mNonPolymers.emplace_back(*this, comp_id, asym_id);
for (auto &atom : atoms)
{ {
auto atom_id = atom_site.getUniqueID(""); auto atom_id = atom_site.getUniqueID("");
auto &&[row, inserted ] = atom_site.emplace({ auto &&[row, inserted] = atom_site.emplace({{"group_PDB", atom.get_property<std::string>("group_PDB")},
{ "group_PDB", atom.property<std::string>("group_PDB") }, {"id", atom_id},
{ "id", atom_id }, {"type_symbol", atom.get_property<std::string>("type_symbol")},
{ "type_symbol", atom.property<std::string>("type_symbol") }, {"label_atom_id", atom.get_property<std::string>("label_atom_id")},
{ "label_atom_id", atom.property<std::string>("label_atom_id") }, {"label_alt_id", atom.get_property<std::string>("label_alt_id")},
{ "label_alt_id", atom.property<std::string>("label_alt_id") }, {"label_comp_id", comp_id},
{ "label_comp_id", comp_id }, {"label_asym_id", asym_id},
{ "label_asym_id", asym_id }, {"label_entity_id", entity_id},
{ "label_entity_id", entity_id }, {"label_seq_id", "."},
{ "label_seq_id", "." }, {"pdbx_PDB_ins_code", ""},
{ "pdbx_PDB_ins_code", "" }, {"Cartn_x", atom.get_property<std::string>("Cartn_x")},
{ "Cartn_x", atom.property<std::string>("Cartn_x") }, {"Cartn_y", atom.get_property<std::string>("Cartn_y")},
{ "Cartn_y", atom.property<std::string>("Cartn_y") }, {"Cartn_z", atom.get_property<std::string>("Cartn_z")},
{ "Cartn_z", atom.property<std::string>("Cartn_z") }, {"occupancy", atom.get_property<std::string>("occupancy")},
{ "occupancy", atom.property<std::string>("occupancy") }, {"B_iso_or_equiv", atom.get_property<std::string>("B_iso_or_equiv")},
{ "B_iso_or_equiv", atom.property<std::string>("B_iso_or_equiv") }, {"pdbx_formal_charge", atom.get_property<std::string>("pdbx_formal_charge")},
{ "pdbx_formal_charge", atom.property<std::string>("pdbx_formal_charge") }, {"auth_seq_id", ""},
{ "auth_seq_id", "" }, {"auth_comp_id", comp_id},
{ "auth_comp_id", comp_id }, {"auth_asym_id", asym_id},
{ "auth_asym_id", asym_id }, {"auth_atom_id", atom.get_property<std::string>("label_atom_id")},
{ "auth_atom_id", atom.property<std::string>("label_atom_id") }, {"pdbx_PDB_model_num", 1}});
{ "pdbx_PDB_model_num", 1 }
}); auto &newAtom = mAtoms.emplace_back(std::make_shared<Atom::AtomImpl>(db, atom_id, row));
res.addAtom(newAtom);
mAtoms.emplace_back(new AtomImpl(db, atom_id, row)); }
}
mNonPolymers.emplace_back(*this, comp_id, asym_id);
return asym_id; return asym_id;
} }
...@@ -2563,7 +2180,7 @@ void Structure::cleanupEmptyCategories() ...@@ -2563,7 +2180,7 @@ void Structure::cleanupEmptyCategories()
{ {
// is this correct? // is this correct?
std::set<std::string> asym_ids; std::set<std::string> asym_ids;
for (const auto &[ asym_id ] : db["pdbx_branch_scheme"].find<std::string>("entity_id"_key == id, "asym_id")) for (const auto &[asym_id] : db["pdbx_branch_scheme"].find<std::string>("entity_id"_key == id, "asym_id"))
asym_ids.insert(asym_id); asym_ids.insert(asym_id);
count = asym_ids.size(); count = asym_ids.size();
} }
...@@ -2574,14 +2191,26 @@ void Structure::cleanupEmptyCategories() ...@@ -2574,14 +2191,26 @@ void Structure::cleanupEmptyCategories()
void Structure::translate(Point t) void Structure::translate(Point t)
{ {
for (auto& a: mAtoms) for (auto &a : mAtoms)
a.translate(t); a.translate(t);
} }
void Structure::rotate(Quaternion q) void Structure::rotate(Quaternion q)
{ {
for (auto& a: mAtoms) for (auto &a : mAtoms)
a.rotate(q); a.rotate(q);
} }
void Structure::translateAndRotate(Point t, Quaternion q)
{
for (auto &a : mAtoms)
a.translateAndRotate(t, q);
}
void Structure::translateRotateAndTranslate(Point t1, Quaternion q, Point t2)
{
for (auto &a : mAtoms)
a.translateRotateAndTranslate(t1, q, t2);
}
} // namespace mmcif } // namespace mmcif
...@@ -248,7 +248,7 @@ struct TLSSelectionNot : public TLSSelection ...@@ -248,7 +248,7 @@ struct TLSSelectionNot : public TLSSelection
for (auto& r: residues) for (auto& r: residues)
r.selected = not r.selected; r.selected = not r.selected;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "NOT" << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "NOT" << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -267,7 +267,7 @@ struct TLSSelectionAll : public TLSSelection ...@@ -267,7 +267,7 @@ struct TLSSelectionAll : public TLSSelection
for (auto& r: residues) for (auto& r: residues)
r.selected = true; r.selected = true;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "ALL" << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "ALL" << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -287,7 +287,7 @@ struct TLSSelectionChain : public TLSSelectionAll ...@@ -287,7 +287,7 @@ struct TLSSelectionChain : public TLSSelectionAll
for (auto& r: residues) for (auto& r: residues)
r.selected = allChains or r.chainID == m_chain; r.selected = allChains or r.chainID == m_chain;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "CHAIN " << m_chain << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "CHAIN " << m_chain << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -307,7 +307,7 @@ struct TLSSelectionResID : public TLSSelectionAll ...@@ -307,7 +307,7 @@ struct TLSSelectionResID : public TLSSelectionAll
for (auto& r: residues) for (auto& r: residues)
r.selected = r.seqNr == m_seq_nr and r.iCode == m_icode; r.selected = r.seqNr == m_seq_nr and r.iCode == m_icode;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "ResID " << m_seq_nr << (m_icode ? std::string { m_icode} : "") << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "ResID " << m_seq_nr << (m_icode ? std::string { m_icode} : "") << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -331,7 +331,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll ...@@ -331,7 +331,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll
(r.seqNr <= m_last or m_last == kResidueNrWildcard)); (r.seqNr <= m_last or m_last == kResidueNrWildcard));
} }
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "Range " << m_first << ':' << m_last << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "Range " << m_first << ':' << m_last << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -374,7 +374,7 @@ struct TLSSelectionRangeID : public TLSSelectionAll ...@@ -374,7 +374,7 @@ struct TLSSelectionRangeID : public TLSSelectionAll
} }
} }
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "Through " << m_first << ':' << m_last << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "Through " << m_first << ':' << m_last << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -407,7 +407,7 @@ struct TLSSelectionUnion : public TLSSelection ...@@ -407,7 +407,7 @@ struct TLSSelectionUnion : public TLSSelection
for (auto ai = a.begin(), bi = b.begin(), ri = residues.begin(); ri != residues.end(); ++ai, ++bi, ++ri) for (auto ai = a.begin(), bi = b.begin(), ri = residues.begin(); ri != residues.end(); ++ai, ++bi, ++ri)
ri->selected = ai->selected or bi->selected; ri->selected = ai->selected or bi->selected;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "Union" << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "Union" << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -440,7 +440,7 @@ struct TLSSelectionIntersection : public TLSSelection ...@@ -440,7 +440,7 @@ struct TLSSelectionIntersection : public TLSSelection
for (auto ai = a.begin(), bi = b.begin(), ri = residues.begin(); ri != residues.end(); ++ai, ++bi, ++ri) for (auto ai = a.begin(), bi = b.begin(), ri = residues.begin(); ri != residues.end(); ++ai, ++bi, ++ri)
ri->selected = ai->selected and bi->selected; ri->selected = ai->selected and bi->selected;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "Intersection" << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "Intersection" << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -462,7 +462,7 @@ struct TLSSelectionByName : public TLSSelectionAll ...@@ -462,7 +462,7 @@ struct TLSSelectionByName : public TLSSelectionAll
for (auto& r: residues) for (auto& r: residues)
r.selected = r.name == m_name; r.selected = r.name == m_name;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "Name " << m_name << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "Name " << m_name << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -488,7 +488,7 @@ struct TLSSelectionByElement : public TLSSelectionAll ...@@ -488,7 +488,7 @@ struct TLSSelectionByElement : public TLSSelectionAll
for (auto& r: residues) for (auto& r: residues)
r.selected = iequals(r.name, m_element); r.selected = iequals(r.name, m_element);
if (cif::VERBOSE) if (cif::VERBOSE > 0)
{ {
std::cout << std::string(indentLevel * 2, ' ') << "Element " << m_element << std::endl; std::cout << std::string(indentLevel * 2, ' ') << "Element " << m_element << std::endl;
DumpSelection(residues, indentLevel); DumpSelection(residues, indentLevel);
...@@ -890,7 +890,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse() ...@@ -890,7 +890,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse()
Match(pt_EOLN); Match(pt_EOLN);
if (extraParenthesis) if (extraParenthesis and cif::VERBOSE > 0)
std::cerr << "WARNING: too many closing parenthesis in TLS selection statement" << std::endl; std::cerr << "WARNING: too many closing parenthesis in TLS selection statement" << std::endl;
return result; return result;
...@@ -931,7 +931,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor() ...@@ -931,7 +931,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
case '(': case '(':
Match('('); Match('(');
result = ParseAtomSelection(); result = ParseAtomSelection();
if (m_lookahead == pt_EOLN) if (m_lookahead == pt_EOLN and cif::VERBOSE > 0)
std::cerr << "WARNING: missing closing parenthesis in TLS selection statement" << std::endl; std::cerr << "WARNING: missing closing parenthesis in TLS selection statement" << std::endl;
else else
Match(')'); Match(')');
...@@ -1033,7 +1033,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor() ...@@ -1033,7 +1033,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
result.reset(new TLSSelectionRangeID(from, to, icode_from, icode_to)); result.reset(new TLSSelectionRangeID(from, to, icode_from, icode_to));
else else
{ {
if (cif::VERBOSE and (icode_from or icode_to)) if (cif::VERBOSE > 0 and (icode_from or icode_to))
std::cerr << "Warning, ignoring insertion codes" << std::endl; std::cerr << "Warning, ignoring insertion codes" << std::endl;
result.reset(new TLSSelectionRangeSeq(from, to)); result.reset(new TLSSelectionRangeSeq(from, to));
...@@ -1231,6 +1231,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup() ...@@ -1231,6 +1231,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
std::tie(chain2, seqNr2) = ParseAtom(); std::tie(chain2, seqNr2) = ParseAtom();
if (chain1 != chain2) if (chain1 != chain2)
{ {
if (cif::VERBOSE > 0)
std::cerr << "Warning, ranges over multiple chains detected" << std::endl; std::cerr << "Warning, ranges over multiple chains detected" << std::endl;
TLSSelectionPtr sc1(new TLSSelectionChain(chain1)); TLSSelectionPtr sc1(new TLSSelectionChain(chain1));
...@@ -1289,7 +1290,7 @@ std::tuple<std::string,int> TLSSelectionParserImplBuster::ParseAtom() ...@@ -1289,7 +1290,7 @@ std::tuple<std::string,int> TLSSelectionParserImplBuster::ParseAtom()
Match(':'); Match(':');
std::string atom = m_value_s; std::string atom = m_value_s;
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Warning: ignoring atom ID '" << atom << "' in TLS selection" << std::endl; std::cerr << "Warning: ignoring atom ID '" << atom << "' in TLS selection" << std::endl;
Match(bt_IDENT); Match(bt_IDENT);
...@@ -1810,6 +1811,7 @@ class TLSSelectionParser ...@@ -1810,6 +1811,7 @@ class TLSSelectionParser
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
if (cif::VERBOSE >= 0)
std::cerr << "ParseError: " << ex.what() << std::endl; std::cerr << "ParseError: " << ex.what() << std::endl;
} }
...@@ -1834,14 +1836,14 @@ TLSSelectionPtr ParseSelectionDetails(const std::string& program, const std::str ...@@ -1834,14 +1836,14 @@ TLSSelectionPtr ParseSelectionDetails(const std::string& program, const std::str
if (not result) if (not result)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Falling back to old BUSTER" << std::endl; std::cerr << "Falling back to old BUSTER" << std::endl;
result = busterOld.Parse(selection); result = busterOld.Parse(selection);
} }
if (not result) if (not result)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Falling back to PHENIX" << std::endl; std::cerr << "Falling back to PHENIX" << std::endl;
result = phenix.Parse(selection); result = phenix.Parse(selection);
} }
...@@ -1852,35 +1854,35 @@ TLSSelectionPtr ParseSelectionDetails(const std::string& program, const std::str ...@@ -1852,35 +1854,35 @@ TLSSelectionPtr ParseSelectionDetails(const std::string& program, const std::str
if (not result) if (not result)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Falling back to BUSTER" << std::endl; std::cerr << "Falling back to BUSTER" << std::endl;
result = buster.Parse(selection); result = buster.Parse(selection);
} }
if (not result) if (not result)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Falling back to old BUSTER" << std::endl; std::cerr << "Falling back to old BUSTER" << std::endl;
result = busterOld.Parse(selection); result = busterOld.Parse(selection);
} }
} }
else else
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "No known program specified, trying PHENIX" << std::endl; std::cerr << "No known program specified, trying PHENIX" << std::endl;
result = phenix.Parse(selection); result = phenix.Parse(selection);
if (not result) if (not result)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Falling back to BUSTER" << std::endl; std::cerr << "Falling back to BUSTER" << std::endl;
result = buster.Parse(selection); result = buster.Parse(selection);
} }
if (not result) if (not result)
{ {
if (cif::VERBOSE) if (cif::VERBOSE > 0)
std::cerr << "Falling back to old BUSTER" << std::endl; std::cerr << "Falling back to old BUSTER" << std::endl;
result = busterOld.Parse(selection); result = busterOld.Parse(selection);
} }
......
...@@ -179,3 +179,23 @@ _struct_asym.details ? ...@@ -179,3 +179,23 @@ _struct_asym.details ?
<< structure.getFile().data() << std::endl; << structure.getFile().data() << std::endl;
} }
} }
// // --------------------------------------------------------------------
// BOOST_AUTO_TEST_CASE(test_load_1)
// {
// mmcif::File cf(gTestDir / "5v3g.cif.gz");
// mmcif::Structure s(cf);
// for (auto &poly : s.polymers())
// {
// std::cout << std::string(80, '=') << std::endl;
// for (auto &res : poly)
// {
// std::cout << res << std::endl;
// for (auto &atom : res.atoms())
// std::cout << " " << atom << std::endl;
// }
// }
// }
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