|
@@ -1,12 +1,9 @@
|
1
|
1
|
import sys
|
2
|
2
|
#import collections
|
3
|
|
-
|
4
|
|
-
|
5
|
3
|
# custom imports
|
6
|
4
|
from atom import *
|
7
|
5
|
|
8
|
6
|
class PDBFile:
|
9
|
|
-
|
10
|
7
|
def getContent(self, filename):
|
11
|
8
|
with open(filename) as f:
|
12
|
9
|
return(f.readlines())
|
|
@@ -31,36 +28,31 @@ class PDBFile:
|
31
|
28
|
return(Metadata)
|
32
|
29
|
|
33
|
30
|
def getAtoms(self):
|
34
|
|
- self.ATOMS = []
|
35
|
|
- self.RESIDUES = []
|
36
|
|
- tempAtoms = []
|
|
31
|
+ self.atoms = []
|
|
32
|
+ self.residues = []
|
|
33
|
+ temp_atoms = []
|
37
|
34
|
for line in self.rawLines:
|
38
|
35
|
if line.startswith("ATOM" or "HETATM"):
|
39
|
|
- atom = Atom(ATOM_ID = int(line[6:11].strip()),
|
40
|
|
- ATOM_NAME = line[12:16].strip(),
|
41
|
|
- ALT_LOCAT = line[16:17].strip(),
|
42
|
|
- RES_NAME = line[17:20].strip(),
|
43
|
|
- CHAIN_ID = line[21:22].strip(),
|
44
|
|
- RES_SEQ_NB = int(line[22:26].strip()),
|
45
|
|
- RES_INSER_CODE = line[26:27].strip(),
|
46
|
|
- COORD_X = float(line[30:38].strip()),
|
47
|
|
- COORD_Y = float(line[38:46].strip()),
|
48
|
|
- COORD_Z = float(line[46:54].strip()),
|
49
|
|
- OCCUPANCY = float(line[54:60].strip()),
|
50
|
|
- TEMP_FACT = float(line[60:66].strip()),
|
51
|
|
- ELEM_SYMBOL = line[76:78].strip(),
|
52
|
|
- ATOM_CHARGE = line[78:80].strip())
|
53
|
|
- self.ATOMS.append(atom)
|
|
36
|
+ atom = Atom(atom_id = int(line[6:11].strip()),
|
|
37
|
+ atom_name = line[12:16].strip(),
|
|
38
|
+ res_name = line[17:20].strip(),
|
|
39
|
+ chain_id = line[21:22].strip(),
|
|
40
|
+ res_seq_nb = int(line[22:26].strip()),
|
|
41
|
+ coordinates = [float(line[30:38].strip()),
|
|
42
|
+ float(line[38:46].strip()),
|
|
43
|
+ float(line[46:54].strip()),
|
|
44
|
+ ])
|
|
45
|
+ self.atoms.append(atom)
|
54
|
46
|
# get the current indice of atom
|
55
|
|
- i = self.ATOMS.index(atom)
|
|
47
|
+ i = self.atoms.index(atom)
|
56
|
48
|
# if this is a brand new residue
|
57
|
|
- if(len(self.ATOMS)>1
|
58
|
|
- and atom.RES_SEQ_NB != self.ATOMS[i-1].RES_SEQ_NB):
|
59
|
|
- self.RESIDUES.append(Residue(tempAtoms))
|
60
|
|
- tempAtoms=[]
|
61
|
|
- tempAtoms.append(atom)
|
|
49
|
+ if(len(self.atoms)>1
|
|
50
|
+ and atom.res_seq_nb != self.atoms[i-1].res_seq_nb):
|
|
51
|
+ self.residues.append(Residue(temp_atoms))
|
|
52
|
+ temp_atoms=[]
|
|
53
|
+ temp_atoms.append(atom)
|
62
|
54
|
# last residue
|
63
|
|
- self.RESIDUES.append(Residue(tempAtoms))
|
|
55
|
+ self.residues.append(Residue(temp_atoms))
|
64
|
56
|
|
65
|
57
|
def __init__(self, filename):
|
66
|
58
|
self.rawLines = self.getContent(filename)
|
|
@@ -76,4 +68,4 @@ if __name__ == "__main__":
|
76
|
68
|
"call structure and parameters.")
|
77
|
69
|
else:
|
78
|
70
|
pdbFile = PDBFile(sys.argv[1])
|
79
|
|
- print(pdbFile.RESIDUES[0].ATOMS["N"].COORD_X)
|
|
71
|
+ print(pdbFile.residues[15].atoms["C"].coord_x)
|