Browse Source

fixed indices of ladders

Thomas Forest 5 years ago
parent
commit
a242afd662
4 changed files with 156 additions and 122 deletions
  1. 132 109
      src/atom.py
  2. 11 9
      src/dssp.py
  3. 10 3
      src/pdb.py
  4. 3 1
      src/structure.py

+ 132 - 109
src/atom.py View File

22
         self.coords = coordinates
22
         self.coords = coordinates
23
 
23
 
24
 class Residue:
24
 class Residue:
25
-    def __init__(self, atoms_list):
25
+    def __init__(self, atoms_list, indice):
26
         self.atoms = {}
26
         self.atoms = {}
27
         for atom in atoms_list:
27
         for atom in atoms_list:
28
             self.atoms[atom.atom_name] = atom
28
             self.atoms[atom.atom_name] = atom
30
             self.res_name = atom.res_name
30
             self.res_name = atom.res_name
31
             self.chain_id = atom.chain_id
31
             self.chain_id = atom.chain_id
32
             self.insertion_code = atom.insertion_code
32
             self.insertion_code = atom.insertion_code
33
+            self.indice = indice
33
             
34
             
34
             
35
             
35
     def h_bond(self, res2):
36
     def h_bond(self, res2):
120
             # finally add the strongest bridge at i and j pos
121
             # finally add the strongest bridge at i and j pos
121
             if(strongest_bridge):
122
             if(strongest_bridge):
122
                 bridges[coord_bridge[0]] = (Bridge(strongest_bridge['btype'],
123
                 bridges[coord_bridge[0]] = (Bridge(strongest_bridge['btype'],
123
-                                                            strongest_bridge['ipos'],
124
-                                                            strongest_bridge['jpos']))
124
+                                                   strongest_bridge['ipos'],
125
+                                                   strongest_bridge['jpos']))
126
+                
125
                 bridges[coord_bridge[1]] = (Bridge(strongest_bridge['btype'],
127
                 bridges[coord_bridge[1]] = (Bridge(strongest_bridge['btype'],
126
-                                                            strongest_bridge['jpos'],
127
-                                                            strongest_bridge['ipos']))
128
+                                                   strongest_bridge['jpos'],
129
+                                                   strongest_bridge['ipos']))
128
         if(len(bridges)>0):
130
         if(len(bridges)>0):
129
             return(bridges[coord_bridge[0]])
131
             return(bridges[coord_bridge[0]])
130
         else:
132
         else:
145
             return(self.get_turns(residues).turn_type, residues[i].resid)
147
             return(self.get_turns(residues).turn_type, residues[i].resid)
146
         return(False)
148
         return(False)
147
 
149
 
148
-    def get_helix2(self, residues):
149
-        """
150
-        Return if there is an helix at a given residue,
151
-        as well as its type.
152
-        """
153
-        i = residues.index(self)
154
-        # if there are no turns or it is the first residue, skip
155
-        if i == 0:
156
-            return False
157
-        
158
-        if(i in turns.keys() and i-1 in turns.keys()):
159
-            print(turns[i].turn_type,"- HELIX at", residues[i].resid)
160
-            return(turns[i].turn_type, residues[i].resid)
161
-        return(False)
162
-    
163
-    def get_ladders(self, residues, ladders={}):
164
-        #ladders = {}
165
-        i = residues.index(self)
166
-        if i != 0:
167
-            if self.get_bridges(residues):
168
-                if (residues[i-1].get_bridges(residues)):
169
-                    local_bridge = self.get_bridges(residues)
170
-                    consec_bridge = residues[i-1].get_bridges(residues)
171
-                    if local_bridge.bridge_type == consec_bridge.bridge_type:
172
-                        print("ladder", consec_bridge.res_num, local_bridge.res_num)
173
-                        ladders[i] = {'start':i-1,
174
-                                      'end':i,
175
-                                      'bridges':[consec_bridge, local_bridge]}
176
-        return ladders
177
-
178
     def get_ladder(self, residues):
150
     def get_ladder(self, residues):
179
         #ladders = {}
151
         #ladders = {}
180
         i = residues.index(self)
152
         i = residues.index(self)
189
                                   'end':local_bridge.res_num,
161
                                   'end':local_bridge.res_num,
190
                                   'bridges':[consec_bridge, local_bridge]}
162
                                   'bridges':[consec_bridge, local_bridge]}
191
                         return ladder
163
                         return ladder
192
-        return False
164
+        return False   
193
 
165
 
194
-    def get_sheets(self, residues):
195
-        """
196
-        Bridges between ladders.
197
-        Check if 1 bridge between one ladder and one or more other ladders.
198
-        Iterate over all residues of one ladder and check if bridge with other residues
199
-        of the other ladders.
200
-        """
201
-        sheets = {}
202
-        sheet_start = residues.index(self)
203
-        j=sheet_start
204
-        k=2
205
-        if(self.get_ladder(residues)):
206
-            local_ladder = self.get_ladder(residues)
207
-            while j < len(residues)-2:
208
-                k = 2
209
-                while residues[j+k].get_ladder(residues):
210
-                    if(residues[j+k].get_bridges(residues)):
211
-                        j = j+k     
212
-                    k+=1
213
-                if(k>):
214
-                    last = j
215
-                j+=1
216
-                print(j)
217
-        if(k>2):                
218
-            sheet_end = last      
219
-                        
220
-            print("SHEET", sheet_start, sheet_end)       
166
+def get_bridges(residues):
167
+    bridges = {}
168
+    bridge = {}
169
+    strongest_bridge = {}
170
+    for i in range(1,len(residues)-4):
171
+        E_min = 0
172
+        for j in range(i+2,len(residues)-1):
173
+            # select triplet with the minimal energy 
221
 
174
 
222
-    def get_sheets2(self):
223
-        """
224
-        Bridges between ladders.
225
-        Check if 1 bridge between one ladder and one or more other ladders.
226
-        Iterate over all residues of one ladder and check if bridge with other residues
227
-        of the other ladders.
228
-        """
229
-        sheets = {}
230
-        for ladder in ladders:
231
-            for ladd2 in ladders:
232
-                for bridge in ladders[ladder]['bridges']:
233
-                    if bridge.res_partner in res_list(ladders[ladd2]):
234
-                        print("ladder",ladders[ladder]['start'], ladders[ladder]['end'],"bridge",bridge.res_num, bridge.res_partner,
235
-                        "ladder 2",ladders[ladd2]['start'], ladders[ladd2]['end'])
236
-                #print("stop ladder 2")
237
-            print("stop ladder 1")            
175
+            if(residues[i-1].h_bond(residues[j])<-0.5
176
+               and residues[j].h_bond(residues[i+1])<-0.5):
177
+                bridge = {'res1':residues[i-1].h_bond(residues[j]),
178
+                          'res2':residues[j].h_bond(residues[i+1]),
179
+                          'ipos':residues[i].resid,
180
+                          'jpos':residues[j].resid,
181
+                          'i':residues[i].indice,
182
+                          'j':residues[j].indice,
183
+                          'btype':"para"}
184
+                   
185
+            if(residues[j-1].h_bond(residues[i])<-0.5
186
+               and residues[i].h_bond(residues[j+1])<-0.5):
187
+                bridge = {'res1':residues[j-1].h_bond(residues[i]),
188
+                          'res2':residues[i].h_bond(residues[j+1]),
189
+                          'ipos':residues[i].resid,
190
+                          'jpos':residues[j].resid,
191
+                          'i':residues[i].indice,
192
+                          'j':residues[j].indice,
193
+                          'btype':"para"}
238
 
194
 
239
-            
195
+            if(residues[i].h_bond(residues[j])<-0.5
196
+               and residues[j].h_bond(residues[i])<-0.5):
197
+                bridge = {'res1':residues[i].h_bond(residues[j]),
198
+                          'res2':residues[j].h_bond(residues[i]),
199
+                          'ipos':residues[i].resid,
200
+                          'jpos':residues[j].resid,
201
+                          'i':residues[i].indice,
202
+                          'j':residues[j].indice,
203
+                          'btype':"anti"}
204
+                    
205
+            if(residues[i-1].h_bond(residues[j+1])<-0.5
206
+               and residues[j-1].h_bond(residues[i+1])<-0.5):
207
+                bridge = {'res1':residues[i-1].h_bond(residues[j+1]),
208
+                          'res2':residues[j-1].h_bond(residues[i+1]),
209
+                          'ipos':residues[i].resid,
210
+                          'jpos':residues[j].resid,
211
+                          'i':residues[i].indice,
212
+                          'j':residues[j].indice,
213
+                          'btype':"anti"}
214
+
215
+            if(bridge):
216
+                if(bridge['res1']+bridge['res2']<E_min):
217
+                    E_min = bridge['res1']+bridge['res2']
218
+                    strongest_bridge = bridge
219
+                    coord_bridge = [i,j]
220
+                    bridge = {}
221
+        # finally add the strongest bridge at i and j pos
222
+        if(strongest_bridge):
223
+            bridges[strongest_bridge['i']] = (Bridge(strongest_bridge['btype'],
224
+                                                     strongest_bridge['ipos'],
225
+                                                     strongest_bridge['jpos'],
226
+                                                     [strongest_bridge['i'],
227
+                                                      strongest_bridge['j']]))
228
+            bridges[strongest_bridge['j']] = (Bridge(strongest_bridge['btype'],
229
+                                               strongest_bridge['jpos'],
230
+                                               strongest_bridge['ipos'],
231
+                                               [strongest_bridge['i'],
232
+                                               strongest_bridge['j']]))
233
+    if(len(bridges)>0):
234
+        return(bridges)
235
+    else:
236
+        return(False)
237
+
238
+def get_ladders(bridges, residues):
239
+    ladders = {}
240
+    i = 1
241
+    while i < len(residues):
242
+        k = 1
243
+        if i in bridges.keys():
244
+            temp_bridges = [bridges[i]]
245
+            while ((i+k in bridges.keys()) and
246
+                   (bridges[i].bridge_type == bridges[i+k].bridge_type)):
247
+                temp_bridges.append(bridges[i+k])
248
+                k+=1
249
+        if k>1:
250
+            #print("ladder", bridges[i].res_num, bridges[i+k-1].res_num)
251
+            ladders[i] = {'start':bridges[i].res_num,
252
+                          'end':bridges[i+k-1].res_num,
253
+                          'bridges':temp_bridges,
254
+                          'i':i,
255
+                          'j':i+k-1}
256
+            i+=k-1
257
+        else:
258
+            i+=1
259
+    return ladders
260
+
261
+def connected_ladders(ladd_1, ladd_2):
262
+    links = []
263
+    for bridge in ladd_1['bridges']:
264
+        if bridge.res_partner in res_list(ladd_2):
265
+            return([ladd_1['i'], ladd_1['j'], bridge.i, bridge.j,
266
+                    ladd_2['i'], ladd_2['j']])
267
+
268
+    return False
240
 
269
 
241
-    def get_ladders2(self, bridges, residues):
242
-        ladders = {}
243
-        i = residues.index(self)
244
-        if i != 0:
245
-            k = 1
246
-            if i in bridges.keys():
247
-                temp_bridges = [bridges[i]]
248
-                while ((i+k in bridges.keys()) and
249
-                       (bridges[i].bridge_type == bridges[i+k].bridge_type)):
250
-                    temp_bridges.append(bridges[i+k])
251
-                    k+=1
252
-            if k>1:
253
-                print("ladder", bridges[i].res_num, bridges[i+k-1].res_num)
254
-                ladders[i] = {'start':bridges[i].res_num,
255
-                              'end':bridges[i+k-1].res_num,
256
-                              'bridges':temp_bridges}
257
-                i+=k-1
258
-            else:
259
-                i+=1
260
-        return ladders
261
-    
262
 def get_sheets(ladders):
270
 def get_sheets(ladders):
263
     """
271
     """
264
     Bridges between ladders.
272
     Bridges between ladders.
266
     Iterate over all residues of one ladder and check if bridge with other residues
274
     Iterate over all residues of one ladder and check if bridge with other residues
267
     of the other ladders.
275
     of the other ladders.
268
     """
276
     """
277
+    ladds = [ elem for elem in ladders.values() ]
269
     sheets = {}
278
     sheets = {}
270
-    for ladder in ladders:
271
-        for ladd2 in ladders:
272
-            for bridge in ladders[ladder]['bridges']:
273
-                if bridge.res_partner in res_list(ladders[ladd2]):
274
-                    print("ladder",ladders[ladder]['start'], ladders[ladder]['end'],"bridge",bridge.res_num, bridge.res_partner,
275
-                    "ladder 2",ladders[ladd2]['start'], ladders[ladd2]['end'])
276
-            #print("stop ladder 2")
277
-        print("stop ladder 1")            
279
+    i = 0
280
+    while i < len(ladds):
281
+        j = i+1
282
+        ladd = ladds[i]
283
+        ladd1 = ladds[i]
284
+        ladd2 = ladds[j]
285
+
286
+        while j < len(ladds):
287
+            print(connected_ladders(ladd1, ladd2))
288
+            if connected_ladders(ladd1, ladd2)!=False:
289
+                ladd1 = ladd2
290
+                #print(connected_ladders(ladd1, ladd2)[4])
291
+                ladd2 = ladders[connected_ladders(ladd1, ladd2)[4]]
292
+            j+=1
293
+        print(ladd['i'], ladd2['i'])
294
+        i+=1
295
+    # for ladder in ladders:
296
+    #     for ladd2 in ladders:
297
+    #        if connected_ladders(ladders[ladder], ladders[ladd2]):
298
+    #            pass
299
+               #print("ladder",ladders[ladder]['i'], ladders[ladder]['j'],"bridge",bridge.i, bridge.j,
300
+               #      "ladder 2",ladders[ladd2]['i'], ladders[ladd2]['j'])
278
 
301
 
279
 def res_list(ladder):
302
 def res_list(ladder):
280
     # TODO : method in ladder class
303
     # TODO : method in ladder class

+ 11 - 9
src/dssp.py View File

24
 
24
 
25
     #turns = get_turns(pdb_file.residues)
25
     #turns = get_turns(pdb_file.residues)
26
     #get_helix(pdb_file.residues, turns)
26
     #get_helix(pdb_file.residues, turns)
27
-    get_bends(pdb_file.residues)
27
+    #get_bends(pdb_file.residues)
28
     # get_chirality(pdb_file.residues)
28
     # get_chirality(pdb_file.residues)
29
-    # bridges = get_bridges(pdb_file.residues)
30
-    # ladders = get_ladders(bridges, pdb_file.residues)
31
-    # get_sheets(ladders)  
29
+    bridges = get_bridges(pdb_file.residues)
30
+    ladders = get_ladders(bridges, pdb_file.residues)
31
+    get_sheets(ladders)  
32
 
32
 
33
     # print("NBRIDGES",len(bridges))
33
     # print("NBRIDGES",len(bridges))
34
 
34
 
47
 
47
 
48
     #get_phi_psi(residues)
48
     #get_phi_psi(residues)
49
     #print(residues[2].atoms, residues[0].resid, residues[1].resid)
49
     #print(residues[2].atoms, residues[0].resid, residues[1].resid)
50
-    print(get_TCO(residues[2],residues[3]))
50
+    #print(get_TCO(residues[2],residues[3]))
51
 
51
 
52
-    #turns = {}
53
-    ladders = {}
54
     for i,res in enumerate(residues):
52
     for i,res in enumerate(residues):
55
         # res.get_turns(residues, turns)
53
         # res.get_turns(residues, turns)
56
-        #res.get_helix(residues)
54
+        res.get_helix(residues)
57
         #res.get_bridges(residues)
55
         #res.get_bridges(residues)
58
-        res.get_ladders(residues, ladders)
56
+        #res.get_ladders(residues, ladders)
59
         #res.get_sheets(residues)
57
         #res.get_sheets(residues)
58
+
59
+for i,ladder in enumerate(ladders.values()):
60
+    print(chr(65+i))
61
+    

+ 10 - 3
src/pdb.py View File

50
                 # get the current indice of atom
50
                 # get the current indice of atom
51
                 i = self.atoms.index(atom)
51
                 i = self.atoms.index(atom)
52
                 # if this is a brand new residue
52
                 # if this is a brand new residue
53
+
54
+                if(len(self.atoms)>1 and
55
+                   (atom.res_seq_nb == self.atoms[i-1].res_seq_nb
56
+                    and atom.insertion_code!=self.atoms[i-1].insertion_code)):
57
+                    self.residues.append(Residue(temp_atoms, len(self.residues)+1))
58
+                    temp_atoms=[]
59
+                
53
                 if(len(self.atoms)>1
60
                 if(len(self.atoms)>1
54
-                   and atom.res_seq_nb != self.atoms[i-1].res_seq_nb):
55
-                    self.residues.append(Residue(temp_atoms))
61
+                   and (atom.res_seq_nb != self.atoms[i-1].res_seq_nb)):
62
+                    self.residues.append(Residue(temp_atoms, len(self.residues)+1))
56
                     temp_atoms=[]
63
                     temp_atoms=[]
57
                 temp_atoms.append(atom)
64
                 temp_atoms.append(atom)
58
         # last residue
65
         # last residue
59
-        self.residues.append(Residue(temp_atoms))
66
+        self.residues.append(Residue(temp_atoms, len(self.residues)))
60
         # hydrogens should represent in average 50% of total atoms...
67
         # hydrogens should represent in average 50% of total atoms...
61
         # We use 30% threshold...
68
         # We use 30% threshold...
62
         if(count_h/len(temp_atoms)<0.30):
69
         if(count_h/len(temp_atoms)<0.30):

+ 3 - 1
src/structure.py View File

14
                         
14
                         
15
 class Bridge(Structure):
15
 class Bridge(Structure):
16
 
16
 
17
-    def __init__(self, bridge_type, res_num, res_partner):
17
+    def __init__(self, bridge_type, res_num, res_partner, indices):
18
         self.bridge_type = bridge_type
18
         self.bridge_type = bridge_type
19
         self.res_num = res_num
19
         self.res_num = res_num
20
         self.res_partner = res_partner
20
         self.res_partner = res_partner
21
         Structure.res = res_num
21
         Structure.res = res_num
22
+        self.i = indices[0]
23
+        self.j = indices[1]
22
 
24
 
23
 class Helix(Structure):
25
 class Helix(Structure):
24
 
26