Commit c73e18fc by maarten

first attempt for chiron

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@218 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent 17034d3b
...@@ -38,22 +38,45 @@ struct CompoundAtom ...@@ -38,22 +38,45 @@ struct CompoundAtom
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// struct containing information about the bonds
// This information comes from the CCP4 monomer library.
enum CompoundBondType { singleBond, doubleBond, tripleBond, delocalizedBond };
struct CompoundBond
{
std::string atomID[2];
CompoundBondType type;
bool aromatic;
float distance;
};
// --------------------------------------------------------------------
// struct containing information about a chiral centre
// This information comes from the CCP4 monomer library.
enum ChiralVolumeSign { negativ, positiv, both };
struct ChiralCentre
{
std::string id;
std::string atomIDCentre;
std::string atomID[3];
ChiralVolumeSign volumeSign;
};
// --------------------------------------------------------------------
// a class that contains information about a chemical compound. // a class that contains information about a chemical compound.
// This information is derived from the ccp4 monomer library by default. // This information is derived from the ccp4 monomer library by default.
// To create compounds, you'd best use the factory method. // To create compounds, you'd best use the factory method.
enum ChiralVolumeSign { negativ, positiv, both };
class Compound class Compound
{ {
public: public:
struct ChiralCentre;
Compound(const std::string& id, const std::string& name, Compound(const std::string& id, const std::string& name,
const std::string& group, std::vector<CompoundAtom>&& atoms, const std::string& group, std::vector<CompoundAtom>&& atoms,
std::map<std::tuple<std::string,std::string>,float>&& bonds, std::vector<CompoundBond>&& bonds, std::vector<ChiralCentre>&& chiralCentres)
std::vector<ChiralCentre>&& chiralCentres)
: mId(id), mName(name), mGroup(group) : mId(id), mName(name), mGroup(group)
, mAtoms(std::move(atoms)), mBonds(std::move(bonds)) , mAtoms(std::move(atoms)), mBonds(std::move(bonds))
, mChiralCentres(std::move(chiralCentres)) , mChiralCentres(std::move(chiralCentres))
...@@ -83,6 +106,7 @@ class Compound ...@@ -83,6 +106,7 @@ class Compound
std::string type() const; std::string type() const;
// std::string group() const { return mGroup; } // std::string group() const { return mGroup; }
std::vector<CompoundAtom> atoms() const { return mAtoms; } std::vector<CompoundAtom> atoms() const { return mAtoms; }
std::vector<CompoundBond> bonds() const { return mBonds; }
CompoundAtom getAtomById(const std::string& atomId) const; CompoundAtom getAtomById(const std::string& atomId) const;
...@@ -94,14 +118,6 @@ class Compound ...@@ -94,14 +118,6 @@ class Compound
int charge() const; int charge() const;
bool isWater() const; bool isWater() const;
struct ChiralCentre
{
std::string mID;
std::string mAtomIDCentre;
std::string mAtomID[3];
ChiralVolumeSign mVolumeSign;
};
std::vector<ChiralCentre> chiralCentres() const { return mChiralCentres; } std::vector<ChiralCentre> chiralCentres() const { return mChiralCentres; }
private: private:
...@@ -110,7 +126,7 @@ class Compound ...@@ -110,7 +126,7 @@ class Compound
std::string mName; std::string mName;
std::string mGroup; std::string mGroup;
std::vector<CompoundAtom> mAtoms; std::vector<CompoundAtom> mAtoms;
std::map<std::tuple<std::string,std::string>,float> mBonds; std::vector<CompoundBond> mBonds;
std::vector<ChiralCentre> mChiralCentres; std::vector<ChiralCentre> mChiralCentres;
}; };
......
...@@ -249,48 +249,51 @@ const Compound* CompoundFactory::create(std::string id) ...@@ -249,48 +249,51 @@ const Compound* CompoundFactory::create(std::string id)
auto& compBonds = cf["comp_" + id]["chem_comp_bond"]; auto& compBonds = cf["comp_" + id]["chem_comp_bond"];
map<tuple<string,string>,float> bonds; vector<CompoundBond> bonds;
for (auto row: compBonds) for (auto row: compBonds)
{ {
string atomId_1, atomId_2, type; CompoundBond b;
string type, aromatic;
cif::tie(atomId_1, atomId_2, type) = row.get("atom_id_1", "atom_id_2", "type"); cif::tie(b.atomID[0], b.atomID[1], type, b.distance, aromatic) =
row.get("atom_id_1", "atom_id_2", "type", "distance", "aromatic");
float value = 0; using cif::iequals;
if (type == "single") value = 1;
else if (type == "double") value = 2; if (iequals(type, "single")) b.type = singleBond;
else if (type == "triple") value = 3; else if (iequals(type, "double")) b.type = doubleBond;
else if (type == "deloc" or type == "aromat" or type == "aromatic") else if (iequals(type, "triple")) b.type = tripleBond;
value = 1.5; else if (iequals(type, "deloc") or iequals(type, "aromat") or iequals(type, "aromatic"))
b.type = delocalizedBond;
else else
{ {
if (VERBOSE) if (VERBOSE)
cerr << "Unimplemented chem_comp_bond.type " << type << " in file " << resFile << endl; cerr << "Unimplemented chem_comp_bond.type " << type << " in file " << resFile << endl;
value = 1.0; b.type = singleBond;
} }
bonds[make_tuple(atomId_1, atomId_2)] = value; bonds.push_back(b);
} }
auto& compChir = cf["comp_" + id]["chem_comp_chir"]; auto& compChir = cf["comp_" + id]["chem_comp_chir"];
vector<Compound::ChiralCentre> chiralCentres; vector<ChiralCentre> chiralCentres;
for (auto row: compChir) for (auto row: compChir)
{ {
Compound::ChiralCentre cc; ChiralCentre cc;
string volumeSign; string volumeSign;
cif::tie(cc.mID, cc.mAtomIDCentre, cc.mAtomID[0], cif::tie(cc.id, cc.atomIDCentre, cc.atomID[0],
cc.mAtomID[1], cc.mAtomID[2], volumeSign) = cc.atomID[1], cc.atomID[2], volumeSign) =
row.get("id", "atom_id_centre", "atom_id_1", row.get("id", "atom_id_centre", "atom_id_1",
"atom_id_2", "atom_id_3", "volume_sign"); "atom_id_2", "atom_id_3", "volume_sign");
if (volumeSign == "negativ") if (volumeSign == "negativ")
cc.mVolumeSign = negativ; cc.volumeSign = negativ;
else if (volumeSign == "positiv") else if (volumeSign == "positiv")
cc.mVolumeSign = positiv; cc.volumeSign = positiv;
else if (volumeSign == "both") else if (volumeSign == "both")
cc.mVolumeSign = both; cc.volumeSign = both;
else else
{ {
if (VERBOSE) if (VERBOSE)
...@@ -312,16 +315,26 @@ const Compound* CompoundFactory::create(std::string id) ...@@ -312,16 +315,26 @@ const Compound* CompoundFactory::create(std::string id)
bool Compound::atomsBonded(const string& atomId_1, const string& atomId_2) const bool Compound::atomsBonded(const string& atomId_1, const string& atomId_2) const
{ {
return mBonds.count(make_tuple(atomId_1, atomId_2)) or mBonds.count(make_tuple(atomId_2, atomId_1)); auto i = find_if(mBonds.begin(), mBonds.end(),
[&](const CompoundBond& b)
{
return (b.atomID[0] == atomId_1 and b.atomID[1] == atomId_2)
or (b.atomID[0] == atomId_2 and b.atomID[1] == atomId_1);
});
return i != mBonds.end();
} }
float Compound::atomBondValue(const string& atomId_1, const string& atomId_2) const float Compound::atomBondValue(const string& atomId_1, const string& atomId_2) const
{ {
auto i = mBonds.find(make_tuple(atomId_1, atomId_2)); auto i = find_if(mBonds.begin(), mBonds.end(),
if (i == mBonds.end()) [&](const CompoundBond& b)
i = mBonds.find(make_tuple(atomId_2, atomId_1)); {
return (b.atomID[0] == atomId_1 and b.atomID[1] == atomId_2)
or (b.atomID[0] == atomId_2 and b.atomID[1] == atomId_1);
});
return i == mBonds.end() ? 0 : i->second; return i != mBonds.end() ? i->distance : 0;
} }
} }
...@@ -565,7 +565,7 @@ Atom Residue::atomByID(const string& atomID) const ...@@ -565,7 +565,7 @@ Atom Residue::atomByID(const string& atomID) const
{ {
for (auto& a: atoms()) for (auto& a: atoms())
{ {
if (a.property<string>("label_atom_id") == atomID) if (a.labelAtomId() == atomID)
return a; return a;
} }
......
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