-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParserPDB.py
More file actions
143 lines (108 loc) · 5 KB
/
Copy pathParserPDB.py
File metadata and controls
143 lines (108 loc) · 5 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# -*- coding : utf8 -*-
"""
Authors: Maud De Tollenaere & Severine Liegeois
Contact: de.tollenaere.maud@gmail.com & sliegeois@yahoo.fr
Date: 02/05/2017
Description: Script containing functions useful for parsing PDB files (i.e. 3D structures of proteins).
"""
def PDBparser(pdbFile, list_dom):
"""
Parse un fichier pdb au format ATOM en un dictionnaire utilisable par Python.
:param pdbFile: Fichier pdb (format ATOM) contenant les coordonnees des atomes d'une proteine.
:param list_dom: Liste des domaines a traiter.
:return: Un dictionnaire utilisable par Python.
"""
with open(pdbFile) as f:
molecule = {} # dictionnaire le plus externe
chainList = []
cptAlt = False
for line in f:
if line[:4:] == 'ATOM': # si la ligne commence par 'ATOM'
if cptAlt == False:
alt = line[16]
cptAlt = True
if line[16] == alt:
chaine = line[72:76].strip()
if chaine in list_dom:
if chaine not in chainList:
chainList.append(chaine)
molecule[chaine] = {}
resList = []
curres = line[22:26].strip()
if curres not in resList:
resList.append(curres)
molecule[chaine][curres] = {}
atomList = []
molecule[chaine][curres]['resname'] = line[17:20].strip()
atom = line[12:16].strip()
if atom not in atomList:
atomList.append(atom)
molecule[chaine][curres][atom] = {}
molecule[chaine]['reslist'] = resList
molecule[chaine][curres]['atomlist'] = atomList
molecule[chaine][curres][atom]['x'] = float(line[30:38])
molecule[chaine][curres][atom]['y'] = float(line[38:46])
molecule[chaine][curres][atom]['z'] = float(line[46:54])
molecule[chaine][curres][atom]['id'] = line[6:11].strip()
return molecule
def PDBparserConf(list, list_dom):
"""
Parse une liste contenant les donnees du fichier pdb correspondant a une conformation d'une proteine.
:param list: Liste contenant les donnees du fichier pdb pour une conformation de proteine.
:param list_dom: Liste des domaines a traiter.
:return: Un dictionnaire utilisable par Python.
"""
molecule = {} # dictionnaire le plus externe
chainList = []
cptAlt = False
for line in list:
if line[:4:] == 'ATOM': # si la ligne commence par 'ATOM'
if cptAlt == False:
alt = line[16]
cptAlt = True
if line[16] == alt:
chaine = line[72:76].strip()
if chaine in list_dom:
if chaine not in chainList:
chainList.append(chaine)
molecule[chaine] = {}
resList = []
curres = line[22:26].strip()
if curres not in resList:
resList.append(curres)
molecule[chaine][curres] = {}
atomList = []
molecule[chaine][curres]['resname'] = line[17:20].strip()
atom = line[12:16].strip()
if atom not in atomList:
atomList.append(atom)
molecule[chaine][curres][atom] = {}
molecule[chaine]['reslist'] = resList
molecule[chaine][curres]['atomlist'] = atomList
molecule[chaine][curres][atom]['x'] = float(line[30:38])
molecule[chaine][curres][atom]['y'] = float(line[38:46])
molecule[chaine][curres][atom]['z'] = float(line[46:54])
molecule[chaine][curres][atom]['id'] = line[6:11].strip()
return molecule
def PDBparserMulti(pdbFile, list_dom):
"""
Parse un fichier pdb au format ATOM contenant plusieurs proteines en un dictionnaire.
:param pdbFile: Fichier pbd (format ATOM) contenant plusieurs proteines.
:param list_dom: Liste des domaines a traiter.
:return: Un dictionnaire utilisable par Python.
"""
with open(pdbFile) as f:
frames = {} # dictionnaire contenant toutes les conformations
conf = [] # donnees du pdb correspondant a la conformation
model = ""
for line in f:
if "MODEL" in line:
if model != "":
frames[model] = PDBparserConf(conf, list_dom)
conf = []
model = line[10:14].strip()
else:
conf.append(line)
frames[model] = PDBparserConf(conf, list_dom) # on parse la derniere conformation
return frames