-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmolecule-dsrpdb.cpp
55 lines (45 loc) · 1.66 KB
/
molecule-dsrpdb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "molecule.h"
#include "xerror.h"
#include <boost/format.hpp>
#include <iostream>
#include <string>
#include <dsrpdb/PDB.h>
#include <dsrpdb/Model.h>
#include <dsrpdb/Protein.h>
/// Molecule
std::vector<Molecule*> Molecule::readPdbFile(const std::string &fname) {
std::vector<Molecule*> res;
// read into dsrpdb::PDB
std::ifstream file;
file.open(fname);
dsrpdb::PDB pdb(file, true/*print_errors*/);
if (pdb.number_of_models() == 0)
ERROR(str(boost::format("The PDB file '%1%' doesn't have any molecules in it") % fname));
auto dsrpdbAtomTypeToOurs = [](auto type) {
switch (type) {
case dsrpdb::Atom::C: return C;
case dsrpdb::Atom::N: return N;
case dsrpdb::Atom::H: return H;
case dsrpdb::Atom::O: return O;
case dsrpdb::Atom::S: return S;
default: ERROR("Unknown atom type in the PDB file");
}
};
for (unsigned m = 0; m < pdb.number_of_models(); m++) {
auto &model = pdb.model(m);
auto molecule = new Molecule("");
for (unsigned c = 0; c < model.number_of_chains(); c++) {
auto &chain = model.chain(c);
//std::cout << "chain#" << c << ": number_of_residues=" << chain.number_of_residues() << std::endl;
//residueCount += chain.number_of_residues();
for (auto a = chain.atoms_begin(), ae = chain.atoms_end(); a != ae; ++a) {
auto &atom = *a;
molecule->add(Atom(dsrpdbAtomTypeToOurs(atom.second.type()), Vec3(atom.second.cartesian_coords()[0], atom.second.cartesian_coords()[1], atom.second.cartesian_coords()[2])));
}
}
molecule->detectBonds();
molecule->setIdx(str(boost::format("%1%#%2%") % fname % (m+1)));
res.push_back(molecule);
}
return res;
}