Commit f7b98c05 by Maarten L. Hekkelman

refactored AtomImpl

parent c4f3b1cd
...@@ -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);
...@@ -92,46 +163,33 @@ class Atom ...@@ -92,46 +163,33 @@ class Atom
void rotate(Quaternion q); void rotate(Quaternion q);
// 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 +198,6 @@ class Atom ...@@ -140,13 +198,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 +209,10 @@ class Atom ...@@ -158,16 +209,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 +223,30 @@ class Atom ...@@ -178,21 +223,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; };
template <>
inline std::string Atom::get_property<std::string>(const std::string_view name) const
{
return mImpl->get_property(name);
}
struct AtomImpl *mImpl_; template <>
inline int Atom::get_property<int>(const std::string_view name) const
{
auto v = mImpl->get_property(name);
return v.empty() ? 0 : stoi(v);
}
// cached values template <>
std::string mAtomID; inline float Atom::get_property<float>(const std::string_view name) const
std::string mCompID; {
std::string mAsymID; return stof(mImpl->get_property(name));
int mSeqID; }
std::string mAltID;
std::string mAuthSeqID;
};
inline void swap(mmcif::Atom &a, mmcif::Atom &b) inline void swap(mmcif::Atom &a, mmcif::Atom &b)
{ {
...@@ -216,19 +270,16 @@ typedef std::vector<Atom> AtomView; ...@@ -216,19 +270,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, Residue(const Structure &structure, const std::string &compoundID,
const std::string &asymID); const std::string &asymID, int seqID = 0, const std::string &authSeqID = {})
: mStructure(&structure)
// constructor for a residue with a sequence number , mCompoundID(compoundID)
Residue(const Structure &structure, const std::string &compoundID, , mAsymID(asymID)
const std::string &asymID, int seqID, const std::string &authSeqID); , 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;
......
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