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 @@
#include <vector>
#include <map>
#include "libcif++/AtomType.h"
#include "cif++/AtomType.h"
namespace libcif
{
......
#pragma once
#include "libcif++/cif++.h"
#include "cif++/Cif++.h"
// --------------------------------------------------------------------
......@@ -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
std::string id() const;
AtomType type() const;
point location() const;
Point location() const;
const compound& comp() const;
const entity& ent() const;
const Compound& comp() const;
const Entity& ent() const;
bool isWater() const;
int charge() const;
......@@ -125,13 +125,13 @@ typedef std::vector<Atom> AtomView;
class Residue : public std::enable_shared_from_this<Residue>
{
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();
private:
const compound& mCompound;
const Compound& mCompound;
};
//// --------------------------------------------------------------------
......@@ -211,13 +211,13 @@ class File : public std::enable_shared_from_this<File>
void load(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; }
std::vector<const entity*> entities();
std::vector<const Entity*> entities();
cif::datablock& data();
cif::Datablock& data();
private:
......@@ -226,13 +226,13 @@ class File : public std::enable_shared_from_this<File>
// --------------------------------------------------------------------
class structure
class Structure
{
public:
structure(File& p, uint32 modelNr = 1);
structure(const structure&);
structure& operator=(const structure&);
~structure();
Structure(File& p, uint32 modelNr = 1);
Structure(const Structure&);
Structure& operator=(const Structure&);
~Structure();
File& getFile() const;
......@@ -240,7 +240,7 @@ class structure
AtomView waters() 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,
const std::string& compId, int seqId, const std::string& altId = "");
......
// Lib for working with structures as contained in mmCIF and PDB files
#include "libcif/config.h"
#include "cif++/Config.h"
#include <map>
......@@ -8,8 +8,8 @@
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include "libcif/compound.h"
#include "libcif/cif++.h"
#include "cif++/Cif++.h"
#include "cif++/Compound.h"
using namespace std;
namespace ba = boost::algorithm;
......@@ -18,38 +18,38 @@ namespace fs = boost::filesystem;
namespace libcif
{
class compound_factory
class CompoundFactory
{
public:
static compound_factory& instance();
const compound* create(string id);
static CompoundFactory& instance();
const Compound* create(string id);
private:
compound_factory();
~compound_factory();
CompoundFactory();
~CompoundFactory();
static compound_factory* sInstance;
static CompoundFactory* sInstance;
fs::path m_clibd_mon;
vector<compound*> m_compounds;
fs::path mClibdMon;
vector<Compound*> mCompounds;
};
// --------------------------------------------------------------------
// compound
// Compound
string compound::formula() const
string Compound::formula() const
{
string result;
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;
charge_sum += r.partial_charge;
atoms[AtomTypeTraits(r.typeSymbol).symbol()] += 1;
chargeSum += r.partialCharge;
}
auto c = atoms.find("C");
......@@ -83,24 +83,24 @@ string compound::formula() const
result += to_string(a.second);
}
int charge = lrint(charge_sum);
int charge = lrint(chargeSum);
if (charge != 0)
result += ' ' + to_string(charge);
return result;
}
int compound::charge() const
int Compound::charge() const
{
float result = 0;
for (auto r: m_atoms)
result += r.partial_charge;
for (auto r: mAtoms)
result += r.partialCharge;
return lrint(result);
}
string compound::type() const
string Compound::type() const
{
string result;
......@@ -123,78 +123,78 @@ string compound::type() const
// pyranose
// saccharide
if (cif::iequals(m_id, "gly"))
if (cif::iequals(mId, "gly"))
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";
else if (cif::iequals(m_group, "DNA"))
else if (cif::iequals(mGroup, "DNA"))
result = "DNA linking";
else if (cif::iequals(m_group, "RNA"))
else if (cif::iequals(mGroup, "RNA"))
result = "RNA linking";
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;
for (auto& a: m_atoms)
CompoundAtom result;
for (auto& a: mAtoms)
{
if (a.id == atom_id)
if (a.id == atomId)
{
result = a;
break;
}
}
if (result.id != atom_id)
throw out_of_range("No atom " + atom_id + " in compound " + m_id);
if (result.id != atomId)
throw out_of_range("No atom " + atomId + " in Compound " + mId);
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
compound_factory* compound_factory::sInstance = nullptr;
CompoundFactory* CompoundFactory::sInstance = nullptr;
compound_factory::compound_factory()
CompoundFactory::CompoundFactory()
{
const char* clibd_mon = getenv("CLIBD_MON");
if (clibd_mon == nullptr)
const char* clibdMon = getenv("CLIBD_MON");
if (clibdMon == nullptr)
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)
sInstance = new compound_factory();
sInstance = new CompoundFactory();
return *sInstance;
}
// 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);
compound* result = nullptr;
Compound* result = nullptr;
for (auto cmp: m_compounds)
for (auto cmp: mCompounds)
{
if (cmp->id() == id)
{
......@@ -205,11 +205,11 @@ const compound* compound_factory::create(std::string id)
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);
if (file.is_open())
{
cif::file cf;
cif::File cf;
try
{
......@@ -222,20 +222,20 @@ const compound* compound_factory::create(std::string id)
}
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;
uint32 number_atoms_all, number_atoms_nh;
cif::tie(name, group, number_atoms_all, number_atoms_nh) =
uint32 numberAtomsAll, numberAtomsNh;
cif::tie(name, group, numberAtomsAll, numberAtomsNh) =
row.get("name", "group", "number_atoms_all", "number_atoms_nh");
ba::trim(name);
ba::trim(group);
auto& comp_atoms = cf["comp_" + id]["chem_comp_atom"];
auto& compoundAtoms = cf["comp_" + id]["chem_comp_atom"];
vector<comp_atom> atoms;
for (auto row: comp_atoms)
vector<CompoundAtom> atoms;
for (auto row: compoundAtoms)
{
string id, symbol, energy;
float charge;
......@@ -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");
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;
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;
if (type == "single") value = 1;
......@@ -268,29 +268,29 @@ const compound* compound_factory::create(std::string id)
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));
m_compounds.push_back(result);
result = new Compound(id, name, group, move(atoms), move(bonds));
mCompounds.push_back(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));
if (i == m_bonds.end())
i = m_bonds.find(make_tuple(atom_id_2, atom_id_1));
auto i = mBonds.find(make_tuple(atomId_1, atomId_2));
if (i == mBonds.end())
i = mBonds.find(make_tuple(atomId_2, atomId_1));
return i == m_bonds.end() ? 0 : i->second;
return i == mBonds.end() ? 0 : i->second;
}
}
......@@ -29,7 +29,7 @@ namespace libcif
struct FileImpl
{
cif::File mData;
cif::datablock* mDb = nullptr;
cif::Datablock* mDb = nullptr;
void load(fs::path p);
void save(fs::path p);
......@@ -71,7 +71,7 @@ void FileImpl::load(fs::path p)
mData.load(in);
}
catch (const cif::cifParserError& e)
catch (const cif::CifParserError& e)
{
if (VERBOSE)
cerr << "Not cif, trying plain old PDB" << endl;
......@@ -130,22 +130,22 @@ void FileImpl::save(fs::path p)
// --------------------------------------------------------------------
// atom
// Atom
struct atomImpl
struct AtomImpl
{
atomImpl(const File& f, const string& id)
AtomImpl(const File& f, const string& id)
: mFile(f), mId(id), mRefcount(1), mCompound(nullptr)
{
auto& db = *mFile.impl().mDb;
auto& cat = db["atom_site"];
mRow = cat[cif::key("id") == mId];
mRow = cat[cif::Key("id") == mId];
prefetch();
}
atomImpl(const file& f, const string& id, cif::row row)
AtomImpl(const File& f, const string& id, cif::Row row)
: mFile(f), mId(id), mRefcount(1), mRow(row), mCompound(nullptr)
{
prefetch();
......@@ -157,12 +157,12 @@ struct atomImpl
string symbol;
cif::tie(symbol) = mRow.get("type_symbol");
mType = atomTypeTraits(symbol).type();
mType = AtomTypeTraits(symbol).type();
float x, y, z;
cif::tie(x, y, z) = mRow.get("Cartn_x", "Cartn_y", "Cartn_z");
mLocation = point(x, y, z);
mLocation = Point(x, y, z);
try
{
......@@ -182,14 +182,14 @@ struct atomImpl
delete this;
}
const compound& comp()
const Compound& comp()
{
if (mCompound == nullptr)
{
string compId;
cif::tie(compId) = mRow.get("label_comp_id");
mCompound = compound::create(compId);
mCompound = Compound::create(compId);
}
if (mCompound == nullptr)
......@@ -203,44 +203,44 @@ struct atomImpl
return mCompound != nullptr and mCompound->isWater();
}
const file& mFile;
const File& mFile;
string mId;
int mRefcount;
cif::row mRow;
const compound* mCompound;
point mLocation;
atomType mType;
cif::Row mRow;
const Compound* mCompound;
Point mLocation;
AtomType mType;
// const entity& mEntity;
// std::string mAsymId;
// std::string mAtomId;
// point mLoc;
// Point mLoc;
// propertyList mProperties;
};
atom::atom(const file& f, const string& id)
: mImpl(new atomImpl(f, id))
Atom::Atom(const File& f, const string& id)
: mImpl(new AtomImpl(f, id))
{
}
atom::atom(atomImpl* impl)
Atom::Atom(AtomImpl* impl)
: mImpl(impl)
{
}
atom::atom(const atom& rhs)
Atom::Atom(const Atom& rhs)
: mImpl(rhs.mImpl)
{
mImpl->reference();
}
atom::~atom()
Atom::~Atom()
{
if (mImpl)
mImpl->release();
}
atom& atom::operator=(const atom& rhs)
Atom& Atom::operator=(const Atom& rhs)
{
if (this != &rhs)
{
......@@ -252,17 +252,17 @@ atom& atom::operator=(const atom& rhs)
return *this;
}
string atom::id() const
string Atom::id() const
{
return mImpl->mId;
}
atomType atom::type() const
AtomType Atom::type() const
{
return mImpl->mType;
}
int atom::charge() const
int Atom::charge() const
{
int charge;
cif::tie(charge) = mImpl->mRow.get("pdbx_formal_charge");
......@@ -270,7 +270,7 @@ int atom::charge() const
return charge;
}
string atom::labelAtomId() const
string Atom::labelAtomId() const
{
string atomId;
cif::tie(atomId) = mImpl->mRow.get("label_atom_id");
......@@ -278,7 +278,7 @@ string atom::labelAtomId() const
return atomId;
}
string atom::labelCompId() const
string Atom::labelCompId() const
{
string compId;
cif::tie(compId) = mImpl->mRow.get("label_comp_id");
......@@ -286,7 +286,7 @@ string atom::labelCompId() const
return compId;
}
string atom::labelAsymId() const
string Atom::labelAsymId() const
{
string asymId;
cif::tie(asymId) = mImpl->mRow.get("label_asym_id");
......@@ -294,7 +294,7 @@ string atom::labelAsymId() const
return asymId;
}
int atom::labelSeqId() const
int Atom::labelSeqId() const
{
int seqId;
cif::tie(seqId) = mImpl->mRow.get("label_seq_id");
......@@ -302,7 +302,7 @@ int atom::labelSeqId() const
return seqId;
}
string atom::authAsymId() const
string Atom::authAsymId() const
{
string asymId;
cif::tie(asymId) = mImpl->mRow.get("auth_asym_id");
......@@ -310,7 +310,7 @@ string atom::authAsymId() const
return asymId;
}
int atom::authSeqId() const
int Atom::authSeqId() const
{
int seqId;
cif::tie(seqId) = mImpl->mRow.get("auth_seq_id");
......@@ -318,35 +318,35 @@ int atom::authSeqId() const
return seqId;
}
point atom::location() const
Point Atom::location() const
{
return mImpl->mLocation;
}
const compound& atom::comp() const
const Compound& Atom::comp() const
{
return mImpl->comp();
}
bool atom::isWater() const
bool Atom::isWater() const
{
return mImpl->isWater();
}
boost::any atom::property(const std::string& name) const
boost::any Atom::property(const std::string& name) const
{
string s = mImpl->mRow[name].as<string>();
return boost::any(s);
}
bool atom::operator==(const atom& rhs) const
bool Atom::operator==(const Atom& rhs) const
{
return mImpl == rhs.mImpl or
(&mImpl->mFile == &rhs.mImpl->mFile and mImpl->mId == rhs.mImpl->mId);
}
const file& atom::getFile() const
const File& Atom::getFile() const
{
assert(mImpl);
return mImpl->mFile;
......@@ -355,7 +355,7 @@ const file& atom::getFile() const
// --------------------------------------------------------------------
// residue
//atomView residue::atoms()
//AtomView residue::Atoms()
//{
// assert(false);
//}
......@@ -367,25 +367,25 @@ const file& atom::getFile() const
// polymer
// --------------------------------------------------------------------
// file
// File
file::file()
File::File()
: mImpl(new FileImpl)
{
}
File::file(fs::path file)
File::File(fs::path File)
: mImpl(new FileImpl)
{
load(file);
load(File);
}
file::~file()
File::~File()
{
delete mImpl;
}
void file::load(fs::path p)
void File::load(fs::path p)
{
mImpl->load(p);
......@@ -412,7 +412,7 @@ void file::load(fs::path p)
// auto& atomSites = db["atom_site"];
// for (auto& atomSite: atomSites)
// {
// atomPtr ap(new atom(this, atom_site));
// AtomPtr ap(new Atom(this, atom_site));
//
// string entity_id = atom_site["entity_id"];
//
......@@ -441,12 +441,12 @@ void file::load(fs::path p)
}
void file::save(boost::filesystem::path file)
void File::save(boost::filesystem::path File)
{
mImpl->save(file);
mImpl->save(File);
}
cif::datablock& file::data()
cif::Datablock& File::data()
{
assert(mImpl);
assert(mImpl->mDb);
......@@ -458,11 +458,11 @@ cif::datablock& file::data()
}
// --------------------------------------------------------------------
// structure
// Structure
struct structureImpl
struct StructureImpl
{
structureImpl(structure& s, file& f, uint32 modelNr)
StructureImpl(Structure& s, File& f, uint32 modelNr)
: mFile(&f), mModelNr(modelNr)
{
auto& db = *mFile->impl().mDb;
......@@ -473,20 +473,20 @@ struct structureImpl
auto modelNr = a["pdbx_PDB_model_num"];
if (modelNr.empty() or modelNr.as<uint32>() == mModelNr)
mAtoms.emplace_back(new atomImpl(f, a["id"].as<string>(), a));
mAtoms.emplace_back(new AtomImpl(f, a["id"].as<string>(), a));
}
}
void removeAtom(atom& a);
void removeAtom(Atom& a);
file* mFile;
File* mFile;
uint32 mModelNr;
atomView mAtoms;
AtomView mAtoms;
};
void structureImpl::removeAtom(atom& a)
void StructureImpl::removeAtom(Atom& a)
{
cif::datablock& db = *mFile->impl().mDb;
cif::Datablock& db = *mFile->impl().mDb;
auto& atomSites = db["atom_site"];
......@@ -505,24 +505,24 @@ void structureImpl::removeAtom(atom& a)
mAtoms.erase(remove(mAtoms.begin(), mAtoms.end(), a), mAtoms.end());
}
structure::structure(file& f, uint32 modelNr)
: mImpl(new structureImpl(*this, f, modelNr))
Structure::Structure(File& f, uint32 modelNr)
: mImpl(new StructureImpl(*this, f, modelNr))
{
}
structure::~structure()
Structure::~Structure()
{
delete mImpl;
}
atomView structure::atoms() const
AtomView Structure::atoms() const
{
return mImpl->mAtoms;
}
atomView structure::waters() const
AtomView Structure::waters() const
{
atomView result;
AtomView result;
auto& db = *getFile().impl().mDb;
......@@ -549,7 +549,7 @@ atomView structure::waters() const
return result;
}
atom structure::getAtomById(string id) const
Atom Structure::getAtomById(string id) const
{
for (auto& a: mImpl->mAtoms)
{
......@@ -560,12 +560,12 @@ atom structure::getAtomById(string id) const
throw out_of_range("Could not find atom with id " + id);
}
file& structure::getFile() const
File& Structure::getFile() const
{
return *mImpl->mFile;
}
//tuple<string,string> structure::MapLabelToAuth(
//tuple<string,string> Structure::MapLabelToAuth(
// const string& asymId, int seqId)
//{
// auto& db = *getFile().impl().mDb;
......@@ -574,8 +574,8 @@ file& structure::getFile() const
// bool found = false;
//
// for (auto r: db["pdbx_poly_seq_scheme"].find(
// cif::key("asym_id") == asym_id and
// cif::key("seq_id") == seq_id))
// cif::Key("asym_id") == asym_id and
// cif::Key("seq_id") == seq_id))
// {
// string auth_asym_id, pdb_mon_id, pdb_ins_code;
// int pdb_seq_num;
......@@ -590,9 +590,9 @@ file& structure::getFile() const
// }
//
// for (auto r: db["pdbx_nonpoly_scheme"].find(
// cif::key("asym_id") == asym_id and
// cif::key("seq_id") == seq_id and
// cif::key("mon_id") == mon_id))
// cif::Key("asym_id") == asym_id and
// cif::Key("seq_id") == seq_id and
// cif::Key("mon_id") == mon_id))
// {
// string pdb_strand_id, pdb_mon_id, pdb_ins_code;
// int pdb_seq_num;
......@@ -609,7 +609,7 @@ file& structure::getFile() const
// return result;
//}
tuple<string,int,string,string> structure::MapLabelToPDB(
tuple<string,int,string,string> Structure::MapLabelToPDB(
const string& asymId, int seqId, const string& monId)
{
auto& db = *getFile().impl().mDb;
......@@ -617,9 +617,9 @@ tuple<string,int,string,string> structure::MapLabelToPDB(
tuple<string,int,string,string> result;
for (auto r: db["pdbx_poly_seq_scheme"].find(
cif::key("asym_id") == asymId and
cif::key("seq_id") == seqId and
cif::key("mon_id") == monId))
cif::Key("asym_id") == asymId and
cif::Key("seq_id") == seqId and
cif::Key("mon_id") == monId))
{
string pdbStrandId, pdbMonId, pdbInsCode;
int pdbSeqNum;
......@@ -633,9 +633,9 @@ tuple<string,int,string,string> structure::MapLabelToPDB(
}
for (auto r: db["pdbx_nonpoly_scheme"].find(
cif::key("asym_id") == asymId and
cif::key("seq_id") == seqId and
cif::key("mon_id") == monId))
cif::Key("asym_id") == asymId and
cif::Key("seq_id") == seqId and
cif::Key("mon_id") == monId))
{
string pdbStrandId, pdbMonId, pdbInsCode;
int pdbSeqNum;
......@@ -654,7 +654,7 @@ tuple<string,int,string,string> structure::MapLabelToPDB(
// --------------------------------------------------------------------
// actions
void structure::removeAtom(atom& a)
void Structure::removeAtom(Atom& a)
{
mImpl->removeAtom(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