Commit 80bb24f3 by Maarten L. Hekkelman

- changed Id to ID in all code

- change ItemReference::as to work with std::optional as well
- changed some DSSP related code
parent 34c7fd3f
......@@ -249,7 +249,11 @@ namespace detail
// ItemReference is a helper class
class ItemReference
{
public:
public:
// some conversion helper classes
template<typename T, typename = void>
struct item_value_as;
template<typename T>
ItemReference& operator=(const T& value)
......@@ -262,12 +266,15 @@ namespace detail
// operator string() const { return c_str(); }
// template<typename T, typename = void>
// T as() const;
template<typename T>
T as() const
{
return boost::lexical_cast<T>(c_str("0"));
return item_value_as<T>::convert(*this);
}
template<typename T>
int compare(const T& value) const
{
......@@ -292,6 +299,7 @@ namespace detail
// empty means either null or unknown
bool empty() const;
explicit operator bool() const { return not empty(); }
// is_null means the field contains '.'
bool is_null() const;
......@@ -325,20 +333,48 @@ namespace detail
bool mConst = false;
};
template<typename T>
struct ItemReference::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T>>>
{
static T convert(const ItemReference& ref)
{
T result = {};
if (not ref.empty())
result = boost::lexical_cast<T>(ref.c_str());
return result;
}
};
template<typename T>
struct ItemReference::item_value_as<std::optional<T>>
{
static std::optional<T> convert(const ItemReference& ref)
{
std::optional<T> result;
if (ref)
result = ref.as<T>();
return result;
}
};
template<>
inline
string ItemReference::as<string>() const
struct ItemReference::item_value_as<const char*>
{
return string(c_str(""));
}
static const char* convert(const ItemReference& ref)
{
return ref.c_str();
}
};
template<>
inline
const char* ItemReference::as<const char*>() const
struct ItemReference::item_value_as<std::string>
{
return c_str("");
}
static std::string convert(const ItemReference& ref)
{
return ref.c_str();
}
};
template<>
inline
int ItemReference::compare<string>(const string& value) const
......
......@@ -112,7 +112,7 @@ struct ValidateCategory
struct ValidateLink
{
int mLinkGroupId;
int mLinkGroupID;
std::string mParentCategory;
std::vector<std::string> mParentKeys;
std::string mChildCategory;
......
......@@ -127,7 +127,7 @@ class Compound
static void addMonomerLibraryPath(const std::string& dir);
// accessors
std::string id() const { return mId; }
std::string id() const { return mID; }
std::string name() const { return mName; }
std::string type() const;
std::string group() const { return mGroup; }
......@@ -139,7 +139,7 @@ class Compound
std::vector<CompoundPlane> planes() const { return mPlanes; }
std::vector<CompoundTorsion> torsions() const { return mTorsions; }
CompoundAtom getAtomById(const std::string& atomId) const;
CompoundAtom getAtomByID(const std::string& atomID) const;
bool atomsBonded(const std::string& atomId_1, const std::string& atomId_2) const;
float atomBondValue(const std::string& atomId_1, const std::string& atomId_2) const;
......@@ -162,7 +162,7 @@ class Compound
cif::File mCF;
std::string mId;
std::string mID;
std::string mName;
std::string mGroup;
std::vector<CompoundAtom> mAtoms;
......@@ -254,7 +254,7 @@ class Link
static const Link& create(const std::string& id);
// accessors
std::string id() const { return mId; }
std::string id() const { return mID; }
std::vector<LinkBond> bonds() const { return mBonds; }
std::vector<LinkAngle> angles() const { return mAngles; }
std::vector<LinkChiralCentre> chiralCentres() const { return mChiralCentres; }
......@@ -269,7 +269,7 @@ class Link
~Link();
std::string mId;
std::string mID;
std::vector<LinkBond> mBonds;
std::vector<LinkAngle> mAngles;
std::vector<LinkTorsion> mTorsions;
......
......@@ -5,10 +5,6 @@
#include <string>
#include <cstdint>
#define HAVE_CPP0X_TEMPLATE_ALIASES 1
#define HAVE_CPP0X_VARIADIC_TEMPLATES 1
#define HAVE_CPP0X_INITIALIZER_LISTS 1
#if defined(_MSC_VER)
// These are Microsoft Visual C++ special settings
......
......@@ -38,27 +38,6 @@ class Polymer;
class Structure;
class File;
struct SecondaryStructure;
// --------------------------------------------------------------------
// We do not want to introduce a dependency on cif++ here, we might want
// to change the backend storage in the future.
// So, in order to access the data we use properties based on boost::any
// Eventually this should be moved to std::variant, but that's only when
// c++17 is acceptable.
struct Property
{
Property() {}
Property(const std::string& name, const boost::any& value)
: name(name), value(value) {}
std::string name;
boost::any value;
};
typedef std::vector<Property> PropertyList;
// --------------------------------------------------------------------
class Atom
......@@ -101,18 +80,18 @@ class Atom
void property(const std::string& name, const T& value);
// specifications
std::string labelAtomId() const;
std::string labelCompId() const;
std::string labelAsymId() const;
int labelSeqId() const;
std::string labelAltId() const;
std::string authAtomId() const;
std::string authCompId() const;
std::string authAsymId() const;
std::string authSeqId() const;
std::string labelAtomID() const;
std::string labelCompID() const;
std::string labelAsymID() const;
int labelSeqID() const;
std::string labelAltID() const;
std::string authAtomID() const;
std::string authCompID() const;
std::string authAsymID() const;
std::string authSeqID() const;
std::string pdbxAuthInsCode() const;
std::string pdbxAuthAltId() const;
std::string pdbxAuthAltID() const;
std::string labelID() const;// label_comp_id + '_' + label_asym_id + '_' + label_seq_id
std::string pdbID() const; // auth_comp_id + '_' + auth_asym_id + '_' + auth_seq_id + pdbx_PDB_ins_code
......@@ -134,8 +113,8 @@ class Atom
// convenience routine
bool isBackBone() const
{
return labelAtomId() == "N" or labelAtomId() == "O" or
labelAtomId() == "C" or labelAtomId() == "CA";
return labelAtomID() == "N" or labelAtomID() == "O" or
labelAtomID() == "C" or labelAtomID() == "CA";
}
void swap(Atom& b)
......@@ -199,6 +178,7 @@ class Residue
const std::string& asymID() const { return mAsymID; }
int seqID() const { return mSeqID; }
std::string authAsymID() const;
std::string authSeqID() const;
std::string authInsCode() const;
......@@ -354,10 +334,24 @@ class File : public std::enable_shared_from_this<File>
// --------------------------------------------------------------------
enum class StructureOpenOptions
{
SkipHydrogen = 1 << 0
};
inline bool operator&(StructureOpenOptions a, StructureOpenOptions b)
{
return static_cast<int>(a) bitand static_cast<int>(b);
}
// --------------------------------------------------------------------
class Structure
{
public:
Structure(File& p, uint32_t modelNr = 1);
Structure(File& p, StructureOpenOptions options = {})
: Structure(p, 1, options) {}
Structure(File& p, uint32_t modelNr = 1, StructureOpenOptions options = {});
Structure& operator=(const Structure&) = delete;
~Structure();
......@@ -372,35 +366,35 @@ class Structure
const std::list<Polymer>& polymers() const { return mPolymers; }
const std::vector<Residue>& nonPolymers() const { return mNonPolymers; }
Atom getAtomById(std::string id) const;
Atom getAtomByID(std::string id) const;
// Atom getAtomByLocation(Point pt, float maxDistance) const;
Atom getAtomByLabel(const std::string& atomId, const std::string& asymId,
const std::string& compId, int seqId, const std::string& altId = "");
Atom getAtomByLabel(const std::string& atomID, const std::string& asymID,
const std::string& compID, int seqID, const std::string& altID = "");
// Atom getAtomByAuth(const std::string& atomId, const std::string& asymId,
// const std::string& compId, int seqId, const std::string& altId = "",
// Atom getAtomByAuth(const std::string& atomID, const std::string& asymID,
// const std::string& compID, int seqID, const std::string& altID = "",
// const std::string& pdbxAuthInsCode = "");
// map between auth and label locations
std::tuple<std::string,int,std::string> MapAuthToLabel(const std::string& asymId,
const std::string& seqId, const std::string& compId, const std::string& insCode = "");
std::tuple<std::string,int,std::string> MapAuthToLabel(const std::string& asymID,
const std::string& seqID, const std::string& compID, const std::string& insCode = "");
std::tuple<std::string,std::string,std::string,std::string> MapLabelToAuth(
const std::string& asymId, int seqId, const std::string& compId);
const std::string& asymID, int seqID, const std::string& compID);
// returns chain, seqnr, icode
std::tuple<char,int,char> MapLabelToAuth(
const std::string& asymId, int seqId) const;
const std::string& asymID, int seqID) const;
// returns chain,seqnr,comp,iCode
std::tuple<std::string,int,std::string,std::string> MapLabelToPDB(
const std::string& asymId, int seqId, const std::string& compId,
const std::string& asymID, int seqID, const std::string& compID,
const std::string& authSeqID) const;
std::tuple<std::string,int,std::string> MapPDBToLabel(
const std::string& asymId, int seqId, const std::string& compId, const std::string& iCode) const;
const std::string& asymID, int seqID, const std::string& compID, const std::string& iCode) const;
// Actions
void removeAtom(Atom& a);
......
......@@ -68,7 +68,7 @@ BondMap::BondMap(const Structure& p)
map<tuple<string,int,string>,string> atomMapByAsymSeqAndAtom;
for (auto& a: p.atoms())
{
auto key = make_tuple(a.labelAsymId(), a.labelSeqId(), a.labelAtomId());
auto key = make_tuple(a.labelAsymID(), a.labelSeqID(), a.labelAtomID());
atomMapByAsymSeqAndAtom[key] = a.id();
}
......@@ -78,28 +78,28 @@ BondMap::BondMap(const Structure& p)
int lastSeqID = 0;
for (auto r: db["pdbx_poly_seq_scheme"])
{
string asymId;
int seqId;
string asymID;
int seqID;
cif::tie(asymId, seqId) = r.get("asym_id", "seq_id");
cif::tie(asymID, seqID) = r.get("asym_id", "seq_id");
if (asymId != lastAsymID) // first in a new sequece
if (asymID != lastAsymID) // first in a new sequece
{
lastAsymID = asymId;
lastSeqID = seqId;
lastAsymID = asymID;
lastSeqID = seqID;
continue;
}
auto c = atomMapByAsymSeqAndAtom[make_tuple(asymId, lastSeqID, "C")];
auto n = atomMapByAsymSeqAndAtom[make_tuple(asymId, seqId, "N")];
auto c = atomMapByAsymSeqAndAtom[make_tuple(asymID, lastSeqID, "C")];
auto n = atomMapByAsymSeqAndAtom[make_tuple(asymID, seqID, "N")];
// auto c = db["atom_site"].find(cif::Key("label_asym_id") == asymId and cif::Key("label_seq_id") == lastSeqID and cif::Key("label_atom_id") == "C");
// auto c = db["atom_site"].find(cif::Key("label_asym_id") == asymID and cif::Key("label_seq_id") == lastSeqID and cif::Key("label_atom_id") == "C");
// if (c.size() != 1 and VERBOSE > 1)
// cerr << "Unexpected number (" << c.size() << ") of atoms with atom ID C in asym_id " << asymId << " with seq id " << lastSeqID << endl;
// cerr << "Unexpected number (" << c.size() << ") of atoms with atom ID C in asym_id " << asymID << " with seq id " << lastSeqID << endl;
//
// auto n = db["atom_site"].find(cif::Key("label_asym_id") == asymId and cif::Key("label_seq_id") == seqId and cif::Key("label_atom_id") == "N");
// auto n = db["atom_site"].find(cif::Key("label_asym_id") == asymID and cif::Key("label_seq_id") == seqID and cif::Key("label_atom_id") == "N");
// if (n.size() != 1 and VERBOSE > 1)
// cerr << "Unexpected number (" << n.size() << ") of atoms with atom ID N in asym_id " << asymId << " with seq id " << seqId << endl;
// cerr << "Unexpected number (" << n.size() << ") of atoms with atom ID N in asym_id " << asymID << " with seq id " << seqID << endl;
//
// if (not (c.empty() or n.empty()))
// bindAtoms(c.front()["id"].as<string>(), n.front()["id"].as<string>());
......@@ -107,7 +107,7 @@ BondMap::BondMap(const Structure& p)
if (not (c.empty() or n.empty()))
bindAtoms(c, n);
lastSeqID = seqId;
lastSeqID = seqID;
}
for (auto l: db["struct_conn"])
......@@ -166,19 +166,19 @@ BondMap::BondMap(const Structure& p)
// loop over poly_seq_scheme
for (auto r: db["pdbx_poly_seq_scheme"].find(cif::Key("mon_id") == c))
{
string asymId;
int seqId;
cif::tie(asymId, seqId) = r.get("asym_id", "seq_id");
string asymID;
int seqID;
cif::tie(asymID, seqID) = r.get("asym_id", "seq_id");
vector<Atom> rAtoms;
copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms),
[&](auto& a) { return a.labelAsymId() == asymId and a.labelSeqId() == seqId; });
[&](auto& a) { return a.labelAsymID() == asymID and a.labelSeqID() == seqID; });
for (uint32_t i = 0; i + 1 < rAtoms.size(); ++i)
{
for (uint32_t j = i + 1; j < rAtoms.size(); ++j)
{
if (compound->atomsBonded(rAtoms[i].labelAtomId(), rAtoms[j].labelAtomId()))
if (compound->atomsBonded(rAtoms[i].labelAtomID(), rAtoms[j].labelAtomID()))
bindAtoms(rAtoms[i].id(), rAtoms[j].id());
}
}
......@@ -187,20 +187,20 @@ BondMap::BondMap(const Structure& p)
// loop over pdbx_nonpoly_scheme
for (auto r: db["pdbx_nonpoly_scheme"].find(cif::Key("mon_id") == c))
{
string asymId;
cif::tie(asymId) = r.get("asym_id");
string asymID;
cif::tie(asymID) = r.get("asym_id");
vector<Atom> rAtoms;
copy_if(atoms.begin(), atoms.end(), back_inserter(rAtoms),
[&](auto& a) { return a.labelAsymId() == asymId; });
// for (auto a: db["atom_site"].find(cif::Key("label_asym_id") == asymId))
// rAtoms.push_back(p.getAtomById(a["id"].as<string>()));
[&](auto& a) { return a.labelAsymID() == asymID; });
// for (auto a: db["atom_site"].find(cif::Key("label_asym_id") == asymID))
// rAtoms.push_back(p.getAtomByID(a["id"].as<string>()));
for (uint32_t i = 0; i + 1 < rAtoms.size(); ++i)
{
for (uint32_t j = i + 1; j < rAtoms.size(); ++j)
{
if (compound->atomsBonded(rAtoms[i].labelAtomId(), rAtoms[j].labelAtomId()))
if (compound->atomsBonded(rAtoms[i].labelAtomID(), rAtoms[j].labelAtomID()))
{
uint32_t ixa = index[rAtoms[i].id()];
uint32_t ixb = index[rAtoms[j].id()];
......
......@@ -352,9 +352,8 @@ void WriteHeaderLines(ostream& pdbFile, Datablock& db)
for (auto r: cat1)
{
keywords = r["keywords"].as<string>();
if (keywords.empty())
keywords = r["pdbx_keywords"].as<string>();
keywords = r["pdbx_keywords"].as<string>();
break;
}
string date;
......@@ -404,7 +403,7 @@ void WriteHeaderLines(ostream& pdbFile, Datablock& db)
if (r["type"] != "polymer")
continue;
string entityId = r["id"].as<string>();
string entityID = r["id"].as<string>();
++molID;
cmpnd.push_back("MOL_ID: " + to_string(molID));
......@@ -412,7 +411,7 @@ void WriteHeaderLines(ostream& pdbFile, Datablock& db)
string molecule = r["pdbx_description"].as<string>();
cmpnd.push_back("MOLECULE: " + molecule);
auto poly = db["entity_poly"].find(cif::Key("entity_id") == entityId);
auto poly = db["entity_poly"].find(cif::Key("entity_id") == entityID);
if (not poly.empty())
{
string chains = poly.front()["pdbx_strand_id"].as<string>();
......@@ -424,7 +423,7 @@ void WriteHeaderLines(ostream& pdbFile, Datablock& db)
if (not fragment.empty())
cmpnd.push_back("FRAGMENT: " + fragment);
for (auto sr: db["entity_name_com"].find(cif::Key("entity_id") == entityId))
for (auto sr: db["entity_name_com"].find(cif::Key("entity_id") == entityID))
{
string syn = sr["name"].as<string>();
if (not syn.empty())
......@@ -459,7 +458,7 @@ void WriteHeaderLines(ostream& pdbFile, Datablock& db)
if (r["type"] != "polymer")
continue;
string entityId = r["id"].as<string>();
string entityID = r["id"].as<string>();
++molID;
source.push_back("MOL_ID: " + to_string(molID));
......@@ -489,7 +488,7 @@ void WriteHeaderLines(ostream& pdbFile, Datablock& db)
{ "details", "OTHER_DETAILS" }
};
for (auto gr: gen.find(cif::Key("entity_id") == entityId))
for (auto gr: gen.find(cif::Key("entity_id") == entityID))
{
for (auto m: kGenSourceMapping)
{
......@@ -514,7 +513,7 @@ void WriteHeaderLines(ostream& pdbFile, Datablock& db)
{ "details", "OTHER_DETAILS" }
};
for (auto nr: nat.find(cif::Key("entity_id") == entityId))
for (auto nr: nat.find(cif::Key("entity_id") == entityID))
{
for (auto m: kNatSourceMapping)
{
......@@ -3189,7 +3188,7 @@ tuple<int,int> WriteSecondaryStructure(ostream& pdbFile, Datablock& db)
first = false;
}
string initResName, initChainID, initICode, endResName, endChainID, endICode, curAtom, curResName, curChainId, curICode, prevAtom, prevResName, prevChainId, prevICode;
string initResName, initChainID, initICode, endResName, endChainID, endICode, curAtom, curResName, curChainID, curICode, prevAtom, prevResName, prevChainID, prevICode;
int initSeqNum, endSeqNum, curResSeq, prevResSeq;
auto r2 = db["struct_sheet_range"][cif::Key("sheet_id") == sheetID and cif::Key("id") == rangeID2];
......@@ -3223,7 +3222,7 @@ tuple<int,int> WriteSecondaryStructure(ostream& pdbFile, Datablock& db)
string compID[2];
cif::tie(compID[0], compID[1]) = h.front().get("range_2_label_comp_id", "range_1_label_comp_id");
cif::tie(curAtom, curResName, curResSeq, curChainId, curICode, prevAtom, prevResName, prevResSeq, prevChainId, prevICode)
cif::tie(curAtom, curResName, curResSeq, curChainID, curICode, prevAtom, prevResName, prevResSeq, prevChainID, prevICode)
= h.front().get("range_2_auth_atom_id", "range_2_auth_comp_id", "range_2_auth_seq_id", "range_2_auth_asym_id", "range_2_PDB_ins_code",
"range_1_auth_atom_id", "range_1_auth_comp_id", "range_1_auth_seq_id", "range_1_auth_asym_id", "range_1_PDB_ins_code");
......@@ -3245,12 +3244,12 @@ tuple<int,int> WriteSecondaryStructure(ostream& pdbFile, Datablock& db)
% sense
% curAtom
% curResName
% curChainId
% curChainID
% curResSeq
% curICode
% prevAtom
% prevResName
% prevChainId
% prevChainID
% prevResSeq
% prevICode) << endl;
}
......@@ -3727,12 +3726,12 @@ void WritePDBFile(ostream& pdbFile, cif::File& cifFile)
void WritePDBHeaderLines(std::ostream& os, cif::File& cifFile)
{
io::filtering_ostream out;
out.push(FillOutLineFilter());
out.push(os);
// io::filtering_ostream out;
// out.push(FillOutLineFilter());
// out.push(os);
auto filter = out.component<FillOutLineFilter>(0);
assert(filter);
// auto filter = out.component<FillOutLineFilter>(0);
// assert(filter);
auto& db = cifFile.firstDatablock();
......@@ -3767,9 +3766,7 @@ std::string GetPDBHEADERLine(cif::File& cifFile, int truncate_at)
for (auto r: cat1)
{
keywords = r["keywords"].as<string>();
if (keywords.empty())
keywords = r["pdbx_keywords"].as<string>();
keywords = r["pdbx_keywords"].as<string>();
if (keywords.length() > truncate_at - 40)
keywords = keywords.substr(0, truncate_at - 44) + " ...";
}
......@@ -3814,7 +3811,7 @@ std::string GetPDBCOMPNDLine(cif::File& cifFile, int truncate_at)
if (r["type"] != "polymer")
continue;
string entityId = r["id"].as<string>();
string entityID = r["id"].as<string>();
++molID;
cmpnd.push_back("MOL_ID: " + to_string(molID));
......@@ -3822,7 +3819,7 @@ std::string GetPDBCOMPNDLine(cif::File& cifFile, int truncate_at)
string molecule = r["pdbx_description"].as<string>();
cmpnd.push_back("MOLECULE: " + molecule);
auto poly = db["entity_poly"].find(cif::Key("entity_id") == entityId);
auto poly = db["entity_poly"].find(cif::Key("entity_id") == entityID);
if (not poly.empty())
{
string chains = poly.front()["pdbx_strand_id"].as<string>();
......@@ -3834,7 +3831,7 @@ std::string GetPDBCOMPNDLine(cif::File& cifFile, int truncate_at)
if (not fragment.empty())
cmpnd.push_back("FRAGMENT: " + fragment);
for (auto sr: db["entity_name_com"].find(cif::Key("entity_id") == entityId))
for (auto sr: db["entity_name_com"].find(cif::Key("entity_id") == entityID))
{
string syn = sr["name"].as<string>();
if (not syn.empty())
......@@ -3874,7 +3871,7 @@ std::string GetPDBSOURCELine(cif::File& cifFile, int truncate_at)
if (r["type"] != "polymer")
continue;
string entityId = r["id"].as<string>();
string entityID = r["id"].as<string>();
++molID;
source.push_back("MOL_ID: " + to_string(molID));
......@@ -3904,7 +3901,7 @@ std::string GetPDBSOURCELine(cif::File& cifFile, int truncate_at)
{ "details", "OTHER_DETAILS" }
};
for (auto gr: gen.find(cif::Key("entity_id") == entityId))
for (auto gr: gen.find(cif::Key("entity_id") == entityID))
{
for (auto m: kGenSourceMapping)
{
......@@ -3929,7 +3926,7 @@ std::string GetPDBSOURCELine(cif::File& cifFile, int truncate_at)
{ "details", "OTHER_DETAILS" }
};
for (auto nr: nat.find(cif::Key("entity_id") == entityId))
for (auto nr: nat.find(cif::Key("entity_id") == entityID))
{
for (auto m: kNatSourceMapping)
{
......
......@@ -930,12 +930,12 @@ void DictParser::linkItems()
for (auto& kv: linkIndex)
{
ValidateLink link;
std::tie(link.mParentCategory, link.mChildCategory, link.mLinkGroupId) = kv.first;
std::tie(link.mParentCategory, link.mChildCategory, link.mLinkGroupID) = kv.first;
std::tie(link.mParentKeys, link.mChildKeys) = linkKeys[kv.second];
// look up the label
for (auto r: linkedGroup.find(cif::Key("category_id") == link.mChildCategory and cif::Key("link_group_id") == link.mLinkGroupId))
for (auto r: linkedGroup.find(cif::Key("category_id") == link.mChildCategory and cif::Key("link_group_id") == link.mLinkGroupID))
{
link.mLinkGroupLabel = r["label"].as<string>();
break;
......
......@@ -313,7 +313,7 @@ bool StructuresAreIsomeric(vector<CompoundAtom> atomsA, const vector<CompoundBon
Compound::Compound(const std::string& file, const std::string& id,
const std::string& name, const std::string& group)
: mId(id), mName(name), mGroup(group)
: mID(id), mName(name), mGroup(group)
{
try
{
......@@ -531,7 +531,7 @@ string Compound::type() const
// pyranose
// saccharide
if (cif::iequals(mId, "gly"))
if (cif::iequals(mID, "gly"))
result = "peptide linking";
else if (cif::iequals(mGroup, "l-peptide") or cif::iequals(mGroup, "L-peptide linking") or cif::iequals(mGroup, "peptide"))
result = "L-peptide linking";
......@@ -547,7 +547,7 @@ string Compound::type() const
bool Compound::isWater() const
{
return mId == "HOH" or mId == "H2O";
return mID == "HOH" or mID == "H2O";
}
bool Compound::isSugar() const
......@@ -555,20 +555,20 @@ bool Compound::isSugar() const
return cif::iequals(mGroup, "furanose") or cif::iequals(mGroup, "pyranose");
}
CompoundAtom Compound::getAtomById(const string& atomId) const
CompoundAtom Compound::getAtomByID(const string& atomID) const
{
CompoundAtom result = {};
for (auto& a: mAtoms)
{
if (a.id == atomId)
if (a.id == atomID)
{
result = a;
break;
}
}
if (result.id != atomId)
throw out_of_range("No atom " + atomId + " in Compound " + mId);
if (result.id != atomID)
throw out_of_range("No atom " + atomID + " in Compound " + mID);
return result;
}
......@@ -612,7 +612,7 @@ bool Compound::isIsomerOf(const Compound& c) const
for (;;)
{
// easy tests first
if (mId == c.mId)
if (mID == c.mID)
{
result = true;
break;
......@@ -694,11 +694,11 @@ vector<string> Compound::isomers() const
vector<string> result;
auto& db = IsomerDB::instance();
if (db.count(mId))
if (db.count(mID))
{
result = db[mId];
result = db[mID];
auto i = find(result.begin(), result.end(), mId);
auto i = find(result.begin(), result.end(), mID);
assert(i != result.end());
result.erase(i);
......@@ -777,7 +777,7 @@ float Compound::chiralVolume(const string& centreID) const
Link::Link(cif::Datablock& db)
{
mId = db.getName();
mID = db.getName();
auto& linkBonds = db["chem_link_bond"];
......@@ -801,7 +801,7 @@ Link::Link(cif::Datablock& db)
else
{
if (cif::VERBOSE)
cerr << "Unimplemented chem_link_bond.type " << type << " in " << mId << endl;
cerr << "Unimplemented chem_link_bond.type " << type << " in " << mID << endl;
b.type = singleBond;
}
......@@ -863,7 +863,7 @@ Link::Link(cif::Datablock& db)
else
{
if (cif::VERBOSE)
cerr << "Unimplemented chem_link_chir.volume_sign " << volumeSign << " in " << mId << endl;
cerr << "Unimplemented chem_link_chir.volume_sign " << volumeSign << " in " << mID << endl;
continue;
}
......
......@@ -19,7 +19,7 @@ namespace mmcif
inline ostream& operator<<(ostream& os, const Atom& a)
{
os << a.labelAsymId() << ':' << a.labelSeqId() << '/' << a.labelAtomId();
os << a.labelAsymID() << ':' << a.labelSeqID() << '/' << a.labelAtomID();
return os;
}
......@@ -441,7 +441,7 @@ vector<Atom> DistanceMap::near(const Atom& a, float maxDistance) const
continue;
size_t ixb = mJA[i];
Atom b = structure.getAtomById(rIndex.at(ixb));
Atom b = structure.getAtomByID(rIndex.at(ixb));
if (rti > 0)
result.emplace_back(b.symmetryCopy(mD, mRtOrth.at(rti)));
......
......@@ -1166,14 +1166,14 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
}
else if (iequals(category, "pdbx_refine_tls_group"))
{
string tlsGroupId;
string tlsGroupID;
if (not mDb["pdbx_refine_tls"].empty())
tlsGroupId = mDb["pdbx_refine_tls"].back()["id"].as<string>();
tlsGroupID = mDb["pdbx_refine_tls"].back()["id"].as<string>();
cat.emplace({
{ "pdbx_refine_id", mExpMethod },
{ "id", tlsGroupId },
{ "refine_tls_id", tlsGroupId }
{ "id", tlsGroupID },
{ "refine_tls_id", tlsGroupID }
});
}
else if (iequals(category, "pdbx_refine_tls"))
......
......@@ -8,9 +8,8 @@
#include "cif++/Config.h"
#include <numeric>
#include <chrono>
#include <iomanip>
#include <future>
#include <thread>
#include <boost/algorithm/string.hpp>
......@@ -164,22 +163,22 @@ struct Res
for (auto& a: mM.atoms())
{
if (a.labelAtomId() == "CA")
if (a.labelAtomID() == "CA")
{
mCAlpha = a.location();
ExtendBox(mCAlpha, kRadiusCA + 2 * kRadiusWater);
}
else if (a.labelAtomId() == "C")
else if (a.labelAtomID() == "C")
{
mC = a.location();
ExtendBox(mC, kRadiusC + 2 * kRadiusWater);
}
else if (a.labelAtomId() == "N")
else if (a.labelAtomID() == "N")
{
mN = a.location();
ExtendBox(mN, kRadiusN + 2 * kRadiusWater);
}
else if (a.labelAtomId() == "O")
else if (a.labelAtomID() == "O")
{
mO = a.location();
ExtendBox(mO, kRadiusO + 2 * kRadiusWater);
......@@ -489,30 +488,6 @@ void CalculateAccessibilities(std::vector<Res>& inResidues, DSSP_Statistics& sta
for (auto& residue: inResidues)
stats.accessibleSurface += residue.CalculateSurface(inResidues);
// uint32_t nr_of_threads = boost::thread::hardware_concurrency();
// if (nr_of_threads <= 1)
// {
// foreach (MResidue* residue, inResidues)
// residue->CalculateSurface(inResidues);
// }
// else
// {
// MResidueQueue queue;
// boost::thread_group t;
// for (uint32 ti = 0; ti < nr_of_threads; ++ti)
// t.create_thread(boost::bind(&MProtein::CalculateAccessibility, this,
// boost::ref(queue), boost::ref(inResidues)));
// foreach (MResidue* residue, inResidues)
// queue.put(residue);
// queue.put(nullptr);
// t.join_all();
// }
}
// --------------------------------------------------------------------
......@@ -1003,51 +978,6 @@ void CalculateAlphaHelices(std::vector<Res>& inResidues, DSSP_Statistics& stats,
}
}
// // --------------------------------------------------------------------
// void CalculateSecondaryStructure(Structure& s)
// {
// auto& polymers = s.polymers();
// size_t nRes = accumulate(polymers.begin(), polymers.end(),
// 0.0, [](double s, auto& p) { return s + p.size(); });
// vector<Res> residues;
// residues.reserve(nRes);
// for (auto& p: polymers)
// {
// for (auto& m: p)
// residues.emplace_back(m);
// }
// auto fa = std::async(std::launch::async, std::bind(&CalculateAccessibilities, std::ref(residues)));
// for (size_t i = 0; i + 1 < residues.size(); ++i)
// {
// residues[i].mNext = &residues[i + 1];
// residues[i + 1].mPrev = &residues[i];
// residues[i + 1].assignHydrogen();
// }
// CalculateHBondEnergies(residues);
// CalculateBetaSheets(residues);
// CalculateAlphaHelices(residues);
// if (cif::VERBOSE)
// {
// for (auto& r: residues)
// {
// auto& m = r.mM;
// cout << m.asymID() << ':' << m.seqID() << '/' << m.compoundID() << '\t'
// << char(r.mSecondaryStructure)
// << endl;
// }
// }
// }
// --------------------------------------------------------------------
struct DSSPImpl
......@@ -1069,37 +999,6 @@ struct DSSPImpl
// --------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, const std::chrono::duration<double>& t)
{
uint64_t s = static_cast<uint64_t>(std::trunc(t.count()));
if (s > 24 * 60 * 60)
{
uint32_t days = s / (24 * 60 * 60);
os << days << "d ";
s %= 24 * 60 * 60;
}
if (s > 60 * 60)
{
uint32_t hours = s / (60 * 60);
os << hours << "h ";
s %= 60 * 60;
}
if (s > 60)
{
uint32_t minutes = s / 60;
os << minutes << "m ";
s %= 60;
}
double ss = s + 1e-6 * (t.count() - s);
os << std::fixed << std::setprecision(1) << ss << 's';
return os;
}
DSSPImpl::DSSPImpl(const Structure& s)
: mStructure(s)
, mPolymers(mStructure.polymers())
......@@ -1144,7 +1043,7 @@ DSSPImpl::DSSPImpl(const Structure& s)
mResidues[i + 1].assignHydrogen();
}
auto a = std::async(std::launch::async, &CalculateAccessibilities, std::ref(mResidues), std::ref(mStats));
std::thread ta(std::bind(&CalculateAccessibilities, std::ref(mResidues), std::ref(mStats)));
auto& db = s.getFile().data();
for (auto r: db["struct_conn"].find(cif::Key("conn_type_id") == "disulf"))
......@@ -1207,9 +1106,8 @@ DSSPImpl::DSSPImpl(const Structure& s)
mStats.nrOfSSBridges = mSSBonds.size();
mStats.nrOfIntraChainSSBridges = 0;
for (auto& ss: mSSBonds)
for (const auto& [a, b]: mSSBonds)
{
const auto& [a, b] = ss;
if (a->mM.asymID() != b->mM.asymID())
++mStats.nrOfIntraChainSSBridges;
}
......@@ -1231,7 +1129,7 @@ DSSPImpl::DSSPImpl(const Structure& s)
}
}
a.get();
ta.join();
}
// --------------------------------------------------------------------
......
......@@ -286,10 +286,10 @@ struct AtomData
{
AtomData(Atom atom, float radius)
: atom(atom)
// , asymID(atom.authAsymId())
// , asymID(atom.authAsymID())
// , seqID(atom.property<string>("auth_seq_id"))
, asymID(atom.labelAsymId())
, seqID(atom.labelSeqId())
, asymID(atom.labelAsymID())
, seqID(atom.labelSeqID())
, radius(radius) {}
Atom atom;
......@@ -584,8 +584,8 @@ vector<ResidueStatistics> StatsCollector::collect() const
if (atom.isWater())
continue;
auto k = make_tuple(atom.labelAsymId(), atom.labelSeqId(), atom.labelCompId(), atom.authSeqId());
// auto k = make_tuple(atom.authAsymId(), atom.property<string>("auth_seq_id"), atom.authCompId());
auto k = make_tuple(atom.labelAsymID(), atom.labelSeqID(), atom.labelCompID(), atom.authSeqID());
// auto k = make_tuple(atom.authAsymID(), atom.property<string>("auth_seq_id"), atom.authCompID());
if (residues.empty() or residues.back() != k)
{
......@@ -610,19 +610,19 @@ vector<ResidueStatistics> StatsCollector::collect(const string& asymID, int resF
if (authNameSpace)
{
int authSeqID = stoi(atom.authSeqId());
int authSeqID = stoi(atom.authSeqID());
if (atom.authAsymId() != asymID or authSeqID < resFirst or authSeqID > resLast)
if (atom.authAsymID() != asymID or authSeqID < resFirst or authSeqID > resLast)
continue;
}
else
{
if (atom.labelAsymId() != asymID or atom.labelSeqId() < resFirst or atom.labelSeqId() > resLast)
if (atom.labelAsymID() != asymID or atom.labelSeqID() < resFirst or atom.labelSeqID() > resLast)
continue;
}
auto k = make_tuple(atom.labelAsymId(), atom.labelSeqId(), atom.labelCompId(), atom.authSeqId());
// auto k = make_tuple(atom.authAsymId(), atom.property<string>("auth_seq_id"), atom.authCompId());
auto k = make_tuple(atom.labelAsymID(), atom.labelSeqID(), atom.labelCompID(), atom.authSeqID());
// auto k = make_tuple(atom.authAsymID(), atom.property<string>("auth_seq_id"), atom.authCompID());
if (residues.empty() or residues.back() != k)
{
......@@ -710,7 +710,7 @@ vector<ResidueStatistics> StatsCollector::collect(const vector<tuple<string,int,
++n;
auto ci = find_if(atomData.begin(), atomData.end(),
[=](auto& d) { return d.asymID == asymID and d.seqID == seqID and d.atom.labelAtomId() == compAtom.id; });
[=](auto& d) { return d.asymID == asymID and d.seqID == seqID and d.atom.labelAtomID() == compAtom.id; });
if (ci == atomData.end())
{
......@@ -749,7 +749,7 @@ vector<ResidueStatistics> StatsCollector::collect(const vector<tuple<string,int,
continue;
result.emplace_back(ResidueStatistics{d.asymID, d.seqID, "HOH",
atom.authSeqId(),
atom.authSeqID(),
(d.sums.rfSums[0] / d.sums.rfSums[1]), // rsr
d.sums.srg(), // srsr
d.sums.cc(), // rsccs
......@@ -813,7 +813,7 @@ ResidueStatistics StatsCollector::collect(const vector<Atom>& atoms) const
++n;
auto ci = find_if(atomData.begin(), atomData.end(),
[=](auto& d) { return d.asymID == atom.labelAsymId() and d.seqID == atom.labelSeqId() and d.atom.labelAtomId() == atom.labelAtomId(); });
[=](auto& d) { return d.asymID == atom.labelAsymID() and d.seqID == atom.labelSeqID() and d.atom.labelAtomID() == atom.labelAtomID(); });
if (ci == atomData.end())
continue;
......
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