Commit 915d6504 by Maarten L. Hekkelman

First steps, remove CCP4 info from compound

parent 5e63ca7a
......@@ -289,9 +289,10 @@ namespace detail
void swap(ItemReference& b);
template<typename T = std::string>
T as() const
auto as() const
{
return item_value_as<T>::convert(*this);
using value_type = std::remove_cv_t<std::remove_reference_t<T>>;
return item_value_as<value_type>::convert(*this);
}
template<typename T>
......@@ -337,11 +338,13 @@ namespace detail
template<typename T>
struct ItemReference::item_value_as<T, std::enable_if_t<std::is_floating_point_v<T>>>
{
static T convert(const ItemReference& ref)
using value_type = std::remove_reference_t<std::remove_cv_t<T>>;
static value_type convert(const ItemReference& ref)
{
T result = {};
value_type result = {};
if (not ref.empty())
result = static_cast<T>(std::stod(ref.c_str()));
result = static_cast<value_type>(std::stod(ref.c_str()));
return result;
}
......@@ -376,7 +379,7 @@ namespace detail
};
template<typename T>
struct ItemReference::item_value_as<T, std::enable_if_t<std::is_integral_v<T> and std::is_unsigned_v<T>>>
struct ItemReference::item_value_as<T, std::enable_if_t<std::is_integral_v<T> and std::is_unsigned_v<T> and not std::is_same_v<T, bool>>>
{
static T convert(const ItemReference& ref)
{
......@@ -417,7 +420,7 @@ namespace detail
};
template<typename T>
struct ItemReference::item_value_as<T, std::enable_if_t<std::is_integral_v<T> and std::is_signed_v<T>>>
struct ItemReference::item_value_as<T, std::enable_if_t<std::is_integral_v<T> and std::is_signed_v<T> and not std::is_same_v<T, bool>>>
{
static T convert(const ItemReference& ref)
{
......@@ -482,6 +485,25 @@ namespace detail
}
};
template<typename T>
struct ItemReference::item_value_as<T, std::enable_if_t<std::is_same_v<T, bool>>>
{
static bool convert(const ItemReference& ref)
{
bool result = false;
if (not ref.empty())
result = iequals(ref.c_str(), "y");
return result;
}
static int compare(const ItemReference& ref, bool value, bool icase)
{
bool rv = convert(ref);
return value && rv ? 0
: (rv < value ? -1 : 1);
}
};
template<size_t N>
struct ItemReference::item_value_as<char[N]>
{
......
......@@ -141,9 +141,6 @@ class Atom
// access data in compound for this atom
// the energy-type field
std::string energyType() const;
// convenience routine
bool isBackBone() const
{
......@@ -243,10 +240,6 @@ class Residue
bool isWater() const { return mCompoundID == "HOH"; }
bool isSugar() const;
bool isPyranose() const;
bool isFuranose() const;
const Structure& structure() const { return *mStructure; }
bool empty() const { return mStructure == nullptr; }
......
......@@ -457,7 +457,6 @@ class PDBFileParser
char iCode;
int numHetAtoms = 0;
std::string text;
bool sugar = false;
std::string asymID;
std::vector<PDBRecord*> atoms;
bool processed = false;
......@@ -467,14 +466,6 @@ class PDBFileParser
HET(const std::string& hetID, char chainID, int seqNum, char iCode, int numHetAtoms = 0, const std::string& text = {})
: hetID(hetID), chainID(chainID), seqNum(seqNum), iCode(iCode), numHetAtoms(numHetAtoms), text(text)
{
// just in case we don't have a CCP4 available
if (hetID == "MAN" or hetID == "BMA" or hetID == "NAG" or hetID == "NDG" or hetID == "FUC" or hetID == "FUL")
sugar = true;
else
{
auto compound = CompoundFactory::instance().create(hetID);
sugar = compound ? compound->isSugar() : false;
}
}
};
......@@ -4374,33 +4365,38 @@ void PDBFileParser::ConstructEntities()
mMod2parent.count(cc) ? mMod2parent[cc] : cc
);
std::string formula = mFormuls[cc];
if (formula.empty() and compound != nullptr)
formula = compound->formula();
else
{
const std::regex rx(R"(\d+\((.+)\))");
std::smatch m;
if (std::regex_match(formula, m, rx))
formula = m[1].str();
}
std::string name = mHetnams[cc];
if (name.empty() and compound != nullptr)
name = compound->name();
std::string type = "other";
std::string name;
std::string formula;
std::string type;
std::string nstd = ".";
std::string formulaWeight;
if (compound != nullptr)
{
name = compound->name();
type = compound->type();
if (type.empty())
type = "NON-POLYMER";
if (iequals(type, "L-peptide linking") or iequals(type, "peptide linking"))
nstd = "y";
formula = compound->formula();
formulaWeight = std::to_string(compound->formulaWeight());
}
if (name.empty())
name = mHetnams[cc];
if (type.empty())
type = "NON-POLYMER";
if (formula.empty())
{
formula = mFormuls[cc];
const std::regex rx(R"(\d+\((.+)\))");
std::smatch m;
if (std::regex_match(formula, m, rx))
formula = m[1].str();
}
if (modResSet.count(cc))
......@@ -4410,6 +4406,7 @@ void PDBFileParser::ConstructEntities()
{ "id", cc },
{ "name", name },
{ "formula", formula },
{ "formula_weight", formulaWeight },
{ "mon_nstd_flag", nstd },
{ "type", type }
});
......
......@@ -566,16 +566,6 @@ int Atom::charge() const
return property<int>("pdbx_formal_charge");
}
std::string Atom::energyType() const
{
std::string result;
if (impl() and impl()->mCompound)
result = impl()->mCompound->getAtomByID(impl()->mAtomID).typeEnergy;
return result;
}
float Atom::uIso() const
{
float result;
......@@ -1013,21 +1003,6 @@ bool Residue::isEntity() const
return a1.size() == a2.size();
}
bool Residue::isSugar() const
{
return compound().isSugar();
}
bool Residue::isPyranose() const
{
return cif::iequals(compound().group(), "pyranose");
}
bool Residue::isFuranose() const
{
return cif::iequals(compound().group(), "furanose");
}
std::string Residue::authID() const
{
std::string result;
......@@ -2101,7 +2076,7 @@ void Structure::insertCompound(const std::string& compoundID, bool isEntity)
{
auto compound = Compound::create(compoundID);
if (compound == nullptr)
throw std::runtime_error("Trying to insert unknown compound " + compoundID + " (not found in CCP4 monomers lib)");
throw std::runtime_error("Trying to insert unknown compound " + compoundID + " (not found in CCD)");
cif::Datablock& db = *mFile.impl().mDb;
......@@ -2113,6 +2088,7 @@ void Structure::insertCompound(const std::string& compoundID, bool isEntity)
{ "id", compoundID },
{ "name", compound->name() },
{ "formula", compound->formula() },
{ "formula_weight", compound->formulaWeight() },
{ "type", compound->type() }
});
}
......
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