|
@@ -0,0 +1,68 @@
|
|
1
|
+import sys
|
|
2
|
+#import collections
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+# custom imports
|
|
6
|
+from atom import *
|
|
7
|
+
|
|
8
|
+class PDBFile:
|
|
9
|
+
|
|
10
|
+ def getContent(self, filename):
|
|
11
|
+ with open(filename) as f:
|
|
12
|
+ return(f.readlines())
|
|
13
|
+
|
|
14
|
+ def getHeader(self):
|
|
15
|
+ #Metadata = collections.namedtuple("Metadata", ["header", "compound", "source", "author"])
|
|
16
|
+ Metadata = {}
|
|
17
|
+ for line in self.rawLines:
|
|
18
|
+ # no need to continue if meta are complete
|
|
19
|
+ if(len(Metadata) <4):
|
|
20
|
+ if(line[0:10] == "HEADER "):
|
|
21
|
+ Metadata['header']=line
|
|
22
|
+ elif(line[0:10] == "COMPND 2"):
|
|
23
|
+ Metadata['compound']=line
|
|
24
|
+ elif(line[0:10] == "SOURCE 2"):
|
|
25
|
+ Metadata['source']=line
|
|
26
|
+ elif(line[0:10] == "AUTHOR "):
|
|
27
|
+ Metadata['author']=line
|
|
28
|
+ else:
|
|
29
|
+ # if meta are complete, stop parsing
|
|
30
|
+ break
|
|
31
|
+ return(Metadata)
|
|
32
|
+
|
|
33
|
+ def getAtoms(self):
|
|
34
|
+ self.ATOMS = []
|
|
35
|
+
|
|
36
|
+ for line in self.rawLines:
|
|
37
|
+ if line.startswith("ATOM" or "HETATM"):
|
|
38
|
+ atom = Atom(ATOM_ID = int(line[6:11].strip()),
|
|
39
|
+ ATOM_NAME = line[12:16].strip(),
|
|
40
|
+ ALT_LOCAT = line[16:17].strip(),
|
|
41
|
+ RES_NAME = line[17:20].strip(),
|
|
42
|
+ CHAIN_ID = line[21:22].strip(),
|
|
43
|
+ RES_SEQ_NB = int(line[22:26].strip()),
|
|
44
|
+ RES_INSER_CODE = line[26:27].strip(),
|
|
45
|
+ COORD_X = float(line[30:38].strip()),
|
|
46
|
+ COORD_Y = float(line[38:46].strip()),
|
|
47
|
+ COORD_Z = float(line[46:54].strip()),
|
|
48
|
+ OCCUPANCY = float(line[54:60].strip()),
|
|
49
|
+ TEMP_FACT = float(line[60:66].strip()),
|
|
50
|
+ ELEM_SYMBOL = line[76:78].strip(),
|
|
51
|
+ ATOM_CHARGE = line[78:80].strip())
|
|
52
|
+ self.ATOMS.append(atom)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+ def __init__(self, filename):
|
|
56
|
+ self.rawLines = self.getContent(filename)
|
|
57
|
+ self.Metadata = self.getHeader()
|
|
58
|
+ self.getAtoms()
|
|
59
|
+ for elem in self.Metadata :
|
|
60
|
+ print(self.Metadata[elem], end="")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+if __name__ == "__main__":
|
|
64
|
+ if(len(sys.argv)<2):
|
|
65
|
+ print("Not enough arguments! Run with --help to learn more about proper"
|
|
66
|
+ "call structure and parameters.")
|
|
67
|
+ else:
|
|
68
|
+ pdbFile = PDBFile(sys.argv[1])
|