Commit f3878b37 by maarten

backup

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@171 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent 6c935996
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include "libcif++/AtomType.h" #include "cif++/AtomType.h"
namespace libcif namespace libcif
{ {
......
#pragma once #pragma once
#include "libcif++/cif++.h" #include "cif++/Cif++.h"
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -30,4 +30,4 @@ struct PDBRecord ...@@ -30,4 +30,4 @@ struct PDBRecord
// -------------------------------------------------------------------- // --------------------------------------------------------------------
void ReadPDBFile(std::istream& pdbFile, cif::file& cifFile); void ReadPDBFile(std::istream& pdbFile, cif::File& cifFile);
...@@ -86,10 +86,10 @@ class Atom ...@@ -86,10 +86,10 @@ class Atom
std::string id() const; std::string id() const;
AtomType type() const; AtomType type() const;
point location() const; Point location() const;
const compound& comp() const; const Compound& comp() const;
const entity& ent() const; const Entity& ent() const;
bool isWater() const; bool isWater() const;
int charge() const; int charge() const;
...@@ -125,13 +125,13 @@ typedef std::vector<Atom> AtomView; ...@@ -125,13 +125,13 @@ typedef std::vector<Atom> AtomView;
class Residue : public std::enable_shared_from_this<Residue> class Residue : public std::enable_shared_from_this<Residue>
{ {
public: public:
Residue(const compound& cmp) : mCompound(cmp) {} Residue(const Compound& cmp) : mCompound(cmp) {}
const compound& comp() const { return mCompound; } const Compound& comp() const { return mCompound; }
virtual AtomView atoms(); virtual AtomView atoms();
private: private:
const compound& mCompound; const Compound& mCompound;
}; };
//// -------------------------------------------------------------------- //// --------------------------------------------------------------------
...@@ -211,13 +211,13 @@ class File : public std::enable_shared_from_this<File> ...@@ -211,13 +211,13 @@ class File : public std::enable_shared_from_this<File>
void load(boost::filesystem::path p); void load(boost::filesystem::path p);
void save(boost::filesystem::path p); void save(boost::filesystem::path p);
structure* model(size_t nr = 1); Structure* model(size_t nr = 1);
struct FileImpl& impl() const { return *mImpl; } struct FileImpl& impl() const { return *mImpl; }
std::vector<const entity*> entities(); std::vector<const Entity*> entities();
cif::datablock& data(); cif::Datablock& data();
private: private:
...@@ -226,13 +226,13 @@ class File : public std::enable_shared_from_this<File> ...@@ -226,13 +226,13 @@ class File : public std::enable_shared_from_this<File>
// -------------------------------------------------------------------- // --------------------------------------------------------------------
class structure class Structure
{ {
public: public:
structure(File& p, uint32 modelNr = 1); Structure(File& p, uint32 modelNr = 1);
structure(const structure&); Structure(const Structure&);
structure& operator=(const structure&); Structure& operator=(const Structure&);
~structure(); ~Structure();
File& getFile() const; File& getFile() const;
...@@ -240,7 +240,7 @@ class structure ...@@ -240,7 +240,7 @@ class structure
AtomView waters() const; AtomView waters() const;
Atom getAtomById(std::string id) const; Atom getAtomById(std::string id) const;
Atom getAtomByLocation(point pt, float maxDistance) const; Atom getAtomByLocation(Point pt, float maxDistance) const;
Atom getAtomForLabel(const std::string& atomId, const std::string& asymId, Atom getAtomForLabel(const std::string& atomId, const std::string& asymId,
const std::string& compId, int seqId, const std::string& altId = ""); const std::string& compId, int seqId, const std::string& altId = "");
......
// Lib for working with structures as contained in mmCIF and PDB files // Lib for working with structures as contained in mmCIF and PDB files
#include "libcif/config.h" #include "cif++/Config.h"
#include <map> #include <map>
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include "libcif/compound.h" #include "cif++/Cif++.h"
#include "libcif/cif++.h" #include "cif++/Compound.h"
using namespace std; using namespace std;
namespace ba = boost::algorithm; namespace ba = boost::algorithm;
...@@ -18,38 +18,38 @@ namespace fs = boost::filesystem; ...@@ -18,38 +18,38 @@ namespace fs = boost::filesystem;
namespace libcif namespace libcif
{ {
class compound_factory class CompoundFactory
{ {
public: public:
static compound_factory& instance(); static CompoundFactory& instance();
const compound* create(string id); const Compound* create(string id);
private: private:
compound_factory(); CompoundFactory();
~compound_factory(); ~CompoundFactory();
static compound_factory* sInstance; static CompoundFactory* sInstance;
fs::path m_clibd_mon; fs::path mClibdMon;
vector<compound*> m_compounds; vector<Compound*> mCompounds;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// compound // Compound
string compound::formula() const string Compound::formula() const
{ {
string result; string result;
map<string,uint32> atoms; map<string,uint32> atoms;
float charge_sum = 0; float chargeSum = 0;
for (auto r: m_atoms) for (auto r: mAtoms)
{ {
atoms[atom_type_traits(r.type_symbol).symbol()] += 1; atoms[AtomTypeTraits(r.typeSymbol).symbol()] += 1;
charge_sum += r.partial_charge; chargeSum += r.partialCharge;
} }
auto c = atoms.find("C"); auto c = atoms.find("C");
...@@ -83,24 +83,24 @@ string compound::formula() const ...@@ -83,24 +83,24 @@ string compound::formula() const
result += to_string(a.second); result += to_string(a.second);
} }
int charge = lrint(charge_sum); int charge = lrint(chargeSum);
if (charge != 0) if (charge != 0)
result += ' ' + to_string(charge); result += ' ' + to_string(charge);
return result; return result;
} }
int compound::charge() const int Compound::charge() const
{ {
float result = 0; float result = 0;
for (auto r: m_atoms) for (auto r: mAtoms)
result += r.partial_charge; result += r.partialCharge;
return lrint(result); return lrint(result);
} }
string compound::type() const string Compound::type() const
{ {
string result; string result;
...@@ -123,78 +123,78 @@ string compound::type() const ...@@ -123,78 +123,78 @@ string compound::type() const
// pyranose // pyranose
// saccharide // saccharide
if (cif::iequals(m_id, "gly")) if (cif::iequals(mId, "gly"))
result = "peptide linking"; result = "peptide linking";
else if (cif::iequals(m_group, "l-peptide") or cif::iequals(m_group, "L-peptide linking") or cif::iequals(m_group, "peptide")) else if (cif::iequals(mGroup, "l-peptide") or cif::iequals(mGroup, "L-peptide linking") or cif::iequals(mGroup, "peptide"))
result = "L-peptide linking"; result = "L-peptide linking";
else if (cif::iequals(m_group, "DNA")) else if (cif::iequals(mGroup, "DNA"))
result = "DNA linking"; result = "DNA linking";
else if (cif::iequals(m_group, "RNA")) else if (cif::iequals(mGroup, "RNA"))
result = "RNA linking"; result = "RNA linking";
return result; return result;
} }
bool compound::is_water() const bool Compound::isWater() const
{ {
return m_id == "HOH" or m_id == "H2O"; return mId == "HOH" or mId == "H2O";
} }
comp_atom compound::get_atom_by_id(const string& atom_id) const CompoundAtom Compound::getAtomById(const string& atomId) const
{ {
comp_atom result; CompoundAtom result;
for (auto& a: m_atoms) for (auto& a: mAtoms)
{ {
if (a.id == atom_id) if (a.id == atomId)
{ {
result = a; result = a;
break; break;
} }
} }
if (result.id != atom_id) if (result.id != atomId)
throw out_of_range("No atom " + atom_id + " in compound " + m_id); throw out_of_range("No atom " + atomId + " in Compound " + mId);
return result; return result;
} }
const compound* compound::create(const string& id) const Compound* Compound::create(const string& id)
{ {
return compound_factory::instance().create(id); return CompoundFactory::instance().create(id);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// a factory class to generate compounds // a factory class to generate compounds
compound_factory* compound_factory::sInstance = nullptr; CompoundFactory* CompoundFactory::sInstance = nullptr;
compound_factory::compound_factory() CompoundFactory::CompoundFactory()
{ {
const char* clibd_mon = getenv("CLIBD_MON"); const char* clibdMon = getenv("CLIBD_MON");
if (clibd_mon == nullptr) if (clibdMon == nullptr)
throw runtime_error("Cannot locate peptide list, please souce the CCP4 environment"); throw runtime_error("Cannot locate peptide list, please souce the CCP4 environment");
m_clibd_mon = clibd_mon; mClibdMon = clibdMon;
} }
compound_factory::~compound_factory() CompoundFactory::~CompoundFactory()
{ {
} }
compound_factory& compound_factory::instance() CompoundFactory& CompoundFactory::instance()
{ {
if (sInstance == nullptr) if (sInstance == nullptr)
sInstance = new compound_factory(); sInstance = new CompoundFactory();
return *sInstance; return *sInstance;
} }
// id is the three letter code // id is the three letter code
const compound* compound_factory::create(std::string id) const Compound* CompoundFactory::create(std::string id)
{ {
ba::to_upper(id); ba::to_upper(id);
compound* result = nullptr; Compound* result = nullptr;
for (auto cmp: m_compounds) for (auto cmp: mCompounds)
{ {
if (cmp->id() == id) if (cmp->id() == id)
{ {
...@@ -205,11 +205,11 @@ const compound* compound_factory::create(std::string id) ...@@ -205,11 +205,11 @@ const compound* compound_factory::create(std::string id)
if (result == nullptr) if (result == nullptr)
{ {
fs::path resFile = m_clibd_mon / ba::to_lower_copy(id.substr(0, 1)) / (id + ".cif"); fs::path resFile = mClibdMon / ba::to_lower_copy(id.substr(0, 1)) / (id + ".cif");
fs::ifstream file(resFile); fs::ifstream file(resFile);
if (file.is_open()) if (file.is_open())
{ {
cif::file cf; cif::File cf;
try try
{ {
...@@ -222,20 +222,20 @@ const compound* compound_factory::create(std::string id) ...@@ -222,20 +222,20 @@ const compound* compound_factory::create(std::string id)
} }
auto& list = cf["comp_list"]; auto& list = cf["comp_list"];
auto row = list["chem_comp"][cif::key("id") == id]; auto row = list["chem_comp"][cif::Key("id") == id];
string name, group; string name, group;
uint32 number_atoms_all, number_atoms_nh; uint32 numberAtomsAll, numberAtomsNh;
cif::tie(name, group, number_atoms_all, number_atoms_nh) = cif::tie(name, group, numberAtomsAll, numberAtomsNh) =
row.get("name", "group", "number_atoms_all", "number_atoms_nh"); row.get("name", "group", "number_atoms_all", "number_atoms_nh");
ba::trim(name); ba::trim(name);
ba::trim(group); ba::trim(group);
auto& comp_atoms = cf["comp_" + id]["chem_comp_atom"]; auto& compoundAtoms = cf["comp_" + id]["chem_comp_atom"];
vector<comp_atom> atoms; vector<CompoundAtom> atoms;
for (auto row: comp_atoms) for (auto row: compoundAtoms)
{ {
string id, symbol, energy; string id, symbol, energy;
float charge; float charge;
...@@ -243,18 +243,18 @@ const compound* compound_factory::create(std::string id) ...@@ -243,18 +243,18 @@ const compound* compound_factory::create(std::string id)
cif::tie(id, symbol, energy, charge) = row.get("atom_id", "type_symbol", "type_energy", "partial_charge"); cif::tie(id, symbol, energy, charge) = row.get("atom_id", "type_symbol", "type_energy", "partial_charge");
atoms.push_back({ atoms.push_back({
id, atom_type_traits(symbol).type(), energy, charge id, AtomTypeTraits(symbol).type(), energy, charge
}); });
} }
auto& comp_bonds = cf["comp_" + id]["chem_comp_bond"]; auto& compBonds = cf["comp_" + id]["chem_comp_bond"];
map<tuple<string,string>,float> bonds; map<tuple<string,string>,float> bonds;
for (auto row: comp_bonds) for (auto row: compBonds)
{ {
string atom_id_1, atom_id_2, type; string atomId_1, atomId_2, type;
cif::tie(atom_id_1, atom_id_2, type) = row.get("atom_id_1", "atom_id_2", "type"); cif::tie(atomId_1, atomId_2, type) = row.get("atom_id_1", "atom_id_2", "type");
float value = 0; float value = 0;
if (type == "single") value = 1; if (type == "single") value = 1;
...@@ -268,29 +268,29 @@ const compound* compound_factory::create(std::string id) ...@@ -268,29 +268,29 @@ const compound* compound_factory::create(std::string id)
value = 1.0; value = 1.0;
} }
bonds[make_tuple(atom_id_1, atom_id_2)] = value; bonds[make_tuple(atomId_1, atomId_2)] = value;
} }
result = new compound(id, name, group, move(atoms), move(bonds)); result = new Compound(id, name, group, move(atoms), move(bonds));
m_compounds.push_back(result); mCompounds.push_back(result);
} }
} }
return result; return result;
} }
bool compound::atoms_bonded(const string& atom_id_1, const string& atom_id_2) const bool Compound::atomsBonded(const string& atomId_1, const string& atomId_2) const
{ {
return m_bonds.count(make_tuple(atom_id_1, atom_id_2)) or m_bonds.count(make_tuple(atom_id_2, atom_id_1)); return mBonds.count(make_tuple(atomId_1, atomId_2)) or mBonds.count(make_tuple(atomId_2, atomId_1));
} }
float compound::atom_bond_value(const string& atom_id_1, const string& atom_id_2) const float Compound::atomBondValue(const string& atomId_1, const string& atomId_2) const
{ {
auto i = m_bonds.find(make_tuple(atom_id_1, atom_id_2)); auto i = mBonds.find(make_tuple(atomId_1, atomId_2));
if (i == m_bonds.end()) if (i == mBonds.end())
i = m_bonds.find(make_tuple(atom_id_2, atom_id_1)); i = mBonds.find(make_tuple(atomId_2, atomId_1));
return i == m_bonds.end() ? 0 : i->second; return i == mBonds.end() ? 0 : i->second;
} }
} }
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