1 |
gezelter |
1182 |
#include "PDBReader.hpp" |
2 |
|
|
|
3 |
|
|
PDBReader::PDBReader(void) { |
4 |
|
|
} |
5 |
|
|
|
6 |
|
|
PDBReader::~PDBReader(void) { |
7 |
|
|
gzclose(PDBfile); |
8 |
|
|
} |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
void PDBReader::setPDBfile(const char *fname) { |
12 |
|
|
PDBfile = gzopen(fname, "r"); |
13 |
|
|
if (PDBfile == Z_NULL) { |
14 |
|
|
printf("Could not open PDB file %s\n", fname); |
15 |
|
|
exit(-1); |
16 |
|
|
} |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
vector<VDWAtom*> PDBReader::getAtomList() { |
20 |
|
|
|
21 |
|
|
char numstr[9]; |
22 |
|
|
char resIDstr[6]; |
23 |
|
|
char buf[150]; |
24 |
|
|
double pos[3]; |
25 |
|
|
char aType[4]; |
26 |
|
|
char resName[3]; |
27 |
|
|
int id, resID, ta; |
28 |
|
|
VDWAtom* atom; |
29 |
|
|
|
30 |
|
|
ta = getTotAtoms(); |
31 |
|
|
theAtoms.reserve(ta); |
32 |
|
|
|
33 |
|
|
gzrewind(PDBfile); |
34 |
|
|
|
35 |
|
|
while (!gzeof(PDBfile)) { |
36 |
|
|
gzgets(PDBfile, buf, 150); |
37 |
|
|
if (!strcmp(buf, "END") || |
38 |
|
|
!strncmp(buf, "END ", 4) || |
39 |
|
|
!strncmp(buf, "TER ", 4) || |
40 |
|
|
!strncmp(buf, "ENDMDL", 6)) break; |
41 |
|
|
if (!strncmp(buf, "ATOM ", 6) || !strncmp(buf, "HETATM", 6)) { |
42 |
|
|
|
43 |
|
|
atom = new VDWAtom(); |
44 |
|
|
|
45 |
|
|
memset(numstr, 0, 9 * sizeof(char)); |
46 |
|
|
strncpy(numstr, buf + 30, 8); |
47 |
|
|
pos[0] = atof(numstr); |
48 |
|
|
|
49 |
|
|
memset(numstr, 0, 9 * sizeof(char)); |
50 |
|
|
strncpy(numstr, buf + 38, 8); |
51 |
|
|
pos[1] = atof(numstr); |
52 |
|
|
|
53 |
|
|
memset(numstr, 0, 9 * sizeof(char)); |
54 |
|
|
strncpy(numstr, buf + 46, 8); |
55 |
|
|
pos[2] = atof(numstr); |
56 |
|
|
|
57 |
|
|
atom->setPos(pos); |
58 |
|
|
|
59 |
|
|
memset(aType, 0, 4 * sizeof(char)); |
60 |
|
|
strncpy(aType, buf + 12, 3); |
61 |
|
|
printf("string in aType = %s\n", aType); |
62 |
|
|
atom->setType(aType); |
63 |
|
|
|
64 |
|
|
memset(resName, 0, 3 * sizeof(char)); |
65 |
|
|
strncpy(resName, buf + 17, 2); |
66 |
|
|
atom->setResName(resName); |
67 |
|
|
|
68 |
|
|
memset(resIDstr, 0, 6 * sizeof(char)); |
69 |
|
|
strncpy(resIDstr, buf + 22, 4); |
70 |
|
|
resID = atoi(resIDstr); |
71 |
|
|
atom->setResID(resID); |
72 |
|
|
|
73 |
|
|
theAtoms.push_back(atom); |
74 |
|
|
|
75 |
|
|
printf("%s\t%lf\t%lf\t%lf\n", atom->getType(), pos[0], pos[1], pos[2]); |
76 |
|
|
|
77 |
|
|
} |
78 |
|
|
} // while |
79 |
|
|
return theAtoms; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
unsigned int PDBReader::getTotAtoms(void) { |
83 |
|
|
char buf[150]; |
84 |
|
|
unsigned int ta = 0; |
85 |
|
|
gzrewind(PDBfile); |
86 |
|
|
while (!gzeof(PDBfile)) { |
87 |
|
|
gzgets(PDBfile,buf,150); |
88 |
|
|
if (!strcmp(buf, "END") || |
89 |
|
|
!strncmp(buf, "END ", 4) || |
90 |
|
|
!strncmp(buf, "TER ", 4) || |
91 |
|
|
!strncmp(buf, "ENDMDL", 6)) break; |
92 |
|
|
if (!strncmp(buf, "ATOM ", 6) || !strncmp(buf, "HETATM", 6)) |
93 |
|
|
ta++; |
94 |
|
|
} |
95 |
|
|
return ta; |
96 |
|
|
} |