Browse Source

Cleaning commented artefacts

Thomas Forest 5 years ago
parent
commit
7f7d8aca98
2 changed files with 12 additions and 116 deletions
  1. 11 113
      src/chem.py
  2. 1 3
      src/pdb.py

+ 11 - 113
src/chem.py View File

1
 import math
1
 import math
2
-#from structure import *
3
 from geom import *
2
 from geom import *
4
 
3
 
5
 class Atom:
4
 class Atom:
107
                     if(self.h_bond(residues[i+j])<-0.5):
106
                     if(self.h_bond(residues[i+j])<-0.5):
108
                         k = j
107
                         k = j
109
         if k != 0:    
108
         if k != 0:    
110
-            #print(k,"TURN", residues[i].resid, residues[i+k].resid)
111
             return Turn(k,residues[i].resid)
109
             return Turn(k,residues[i].resid)
112
 
110
 
113
         return False
111
         return False
115
     def get_bends(self, residues):
113
     def get_bends(self, residues):
116
         i = residues.index(self)
114
         i = residues.index(self)
117
         if i >=2 and i <len(residues)-2:
115
         if i >=2 and i <len(residues)-2:
118
-            angle = math.degrees(vector_angles(vectors_substr(position_vector(residues[i].atoms["CA"].coords),
119
-                                                              position_vector(residues[i-2].atoms["CA"].coords)),
120
-                                               vectors_substr(position_vector(residues[i+2].atoms["CA"].coords),
121
-                                                              position_vector(residues[i].atoms["CA"].coords))))
116
+            angle = math.degrees(vector_angles(
117
+                vectors_substr(position_vector(residues[i].atoms["CA"].coords),
118
+                               position_vector(residues[i-2].atoms["CA"].coords)),
119
+                vectors_substr(position_vector(residues[i+2].atoms["CA"].coords),
120
+                               position_vector(residues[i].atoms["CA"].coords))))
122
             if(angle>70):
121
             if(angle>70):
123
                 return [angle, 'S']
122
                 return [angle, 'S']
124
             return [angle, '']
123
             return [angle, '']
125
         else:
124
         else:
126
             return [360.0, '']
125
             return [360.0, '']
127
 
126
 
128
-    def get_bridges(self, residues):
129
-        bridges = {}
130
-        bridge = {}
131
-        strongest_bridge = {}
132
-        i = residues.index(self)
133
-        if(i >= 1 and i < len(residues)-4):
134
-            E_min = 0
135
-            for j in range(i+2,len(residues)-1):
136
-                # select triplet with the minimal energy 
137
-
138
-                if(residues[i-1].h_bond(residues[j])<-0.5
139
-                   and residues[j].h_bond(residues[i+1])<-0.5):
140
-                    bridge = {'res1':residues[i-1].h_bond(residues[j]),
141
-                              'res2':residues[j].h_bond(residues[i+1]),
142
-                              'ipos':residues[i].resid,
143
-                              'jpos':residues[j].resid,
144
-                              'btype':"para"}
145
-
146
-                if(residues[j-1].h_bond(residues[i])<-0.5
147
-                   and residues[i].h_bond(residues[j+1])<-0.5):
148
-                    bridge = {'res1':residues[j-1].h_bond(residues[i]),
149
-                              'res2':residues[i].h_bond(residues[j+1]),
150
-                              'ipos':residues[i].resid,
151
-                              'jpos':residues[j].resid,
152
-                              'btype':"para"}
153
-
154
-                if(residues[i].h_bond(residues[j])<-0.5
155
-                   and residues[j].h_bond(residues[i])<-0.5):
156
-                    bridge = {'res1':residues[i].h_bond(residues[j]),
157
-                              'res2':residues[j].h_bond(residues[i]),
158
-                              'ipos':residues[i].resid,
159
-                              'jpos':residues[j].resid,
160
-                              'btype':"anti"}
161
-
162
-                if(residues[i-1].h_bond(residues[j+1])<-0.5
163
-                   and residues[j-1].h_bond(residues[i+1])<-0.5):
164
-                    bridge = {'res1':residues[i-1].h_bond(residues[j+1]),
165
-                              'res2':residues[j-1].h_bond(residues[i+1]),
166
-                              'ipos':residues[i].resid,
167
-                              'jpos':residues[j].resid,
168
-                              'btype':"anti"}
169
-
170
-                if(bridge):
171
-                    if(bridge['res1']+bridge['res2']<E_min):
172
-                        E_min = bridge['res1']+bridge['res2']
173
-                        strongest_bridge = bridge
174
-                        bridge = {}
175
-                        coord_bridge = [i,j]
176
-            # finally add the strongest bridge at i and j pos
177
-            if(strongest_bridge):
178
-                bridges[coord_bridge[0]] = (Bridge(strongest_bridge['btype'],
179
-                                                   strongest_bridge['ipos'],
180
-                                                   strongest_bridge['jpos']))
181
-                
182
-                bridges[coord_bridge[1]] = (Bridge(strongest_bridge['btype'],
183
-                                                   strongest_bridge['jpos'],
184
-                                                   strongest_bridge['ipos']))
185
-        if(len(bridges)>0):
186
-            return(bridges[coord_bridge[0]])
187
-        else:
188
-            return(False)
189
-
190
     def get_helix(self, residues):
127
     def get_helix(self, residues):
191
         """
128
         """
192
         Return if there is an helix at a given residue,
129
         Return if there is an helix at a given residue,
198
             return False
135
             return False
199
         
136
         
200
         if(self.get_turns(residues) and residues[i-1].get_turns(residues)):
137
         if(self.get_turns(residues) and residues[i-1].get_turns(residues)):
201
-            #print(self.get_turns(residues).turn_type,"- HELIX at", residues[i].indice)
202
             return(self.get_turns(residues).turn_type, residues[i].indice)
138
             return(self.get_turns(residues).turn_type, residues[i].indice)
203
         return(False)
139
         return(False)
204
 
140
 
205
     def get_ladder(self, residues):
141
     def get_ladder(self, residues):
206
-        #ladders = {}
207
         i = residues.index(self)
142
         i = residues.index(self)
208
         if i != 0:
143
         if i != 0:
209
             if self.get_bridges(residues):
144
             if self.get_bridges(residues):
211
                     local_bridge = self.get_bridges(residues)
146
                     local_bridge = self.get_bridges(residues)
212
                     consec_bridge = residues[i-1].get_bridges(residues)
147
                     consec_bridge = residues[i-1].get_bridges(residues)
213
                     if local_bridge.bridge_type == consec_bridge.bridge_type:
148
                     if local_bridge.bridge_type == consec_bridge.bridge_type:
214
-                        #print("ladder", consec_bridge.res_num, local_bridge.res_num)
215
                         ladder = {'start':consec_bridge.res_num,
149
                         ladder = {'start':consec_bridge.res_num,
216
                                   'end':local_bridge.res_num,
150
                                   'end':local_bridge.res_num,
217
                                   'bridges':[consec_bridge, local_bridge]}
151
                                   'bridges':[consec_bridge, local_bridge]}
278
         E_min = 0
212
         E_min = 0
279
         for j in range(i+2,len(residues)-1):
213
         for j in range(i+2,len(residues)-1):
280
             # select triplet with the minimal energy 
214
             # select triplet with the minimal energy 
281
-            
282
             if(residues[i-1].h_bond(residues[j])<-0.5
215
             if(residues[i-1].h_bond(residues[j])<-0.5
283
                and residues[j].h_bond(residues[i+1])<-0.5):
216
                and residues[j].h_bond(residues[i+1])<-0.5):
284
                 bridge = {'res1':residues[i-1].h_bond(residues[j]),
217
                 bridge = {'res1':residues[i-1].h_bond(residues[j]),
328
 
261
 
329
         # finally add the strongest bridge at i and j pos
262
         # finally add the strongest bridge at i and j pos
330
         if(strongest_bridge):
263
         if(strongest_bridge):
331
-
332
             bridges[strongest_bridge['i']] = (Bridge(strongest_bridge['btype'],
264
             bridges[strongest_bridge['i']] = (Bridge(strongest_bridge['btype'],
333
                                                      strongest_bridge['ipos'],
265
                                                      strongest_bridge['ipos'],
334
                                                      strongest_bridge['jpos'],
266
                                                      strongest_bridge['jpos'],
335
                                                      [strongest_bridge['i'],
267
                                                      [strongest_bridge['i'],
336
-                                                      strongest_bridge['j']]))
337
-                                              
268
+                                                      strongest_bridge['j']]))                                        
338
             bridges[strongest_bridge['j']] = (Bridge(strongest_bridge['btype'],
269
             bridges[strongest_bridge['j']] = (Bridge(strongest_bridge['btype'],
339
                                                      strongest_bridge['ipos'],
270
                                                      strongest_bridge['ipos'],
340
                                                      strongest_bridge['jpos'],
271
                                                      strongest_bridge['jpos'],
357
                 temp_bridges.append(bridges[i+k])
288
                 temp_bridges.append(bridges[i+k])
358
                 k+=1
289
                 k+=1
359
         if k>1:
290
         if k>1:
360
-            #print("ladder", bridges[i].res_num, bridges[i+k-1].res_num)
361
             ladders[i] = {'start':bridges[i].res_num,
291
             ladders[i] = {'start':bridges[i].res_num,
362
                           'end':bridges[i+k-1].res_num,
292
                           'end':bridges[i+k-1].res_num,
363
                           'bridges':temp_bridges,
293
                           'bridges':temp_bridges,
373
     for bridge in ladd_1['bridges']:
303
     for bridge in ladd_1['bridges']:
374
         if bridge.res_partner in res_list(ladd_2):
304
         if bridge.res_partner in res_list(ladd_2):
375
             return ladd_2
305
             return ladd_2
376
-
377
-    return False
378
-
379
-def connected_ladders2(ladd_1, ladd_2):
380
-    links = []
381
-    for bridge in ladd_1['bridges']:
382
-        if bridge.res_partner in res_list(ladd_2):
383
-            return([ladd_1['i'], ladd_1['j'], bridge.i, bridge.j,
384
-                    ladd_2['i'], ladd_2['j']])
385
-            #return ladd_2
386
-
387
     return False
306
     return False
388
 
307
 
389
-
390
 def get_sheets(ladders):
308
 def get_sheets(ladders):
391
     """
309
     """
392
     Bridges between ladders.
310
     Bridges between ladders.
396
     """
314
     """
397
     ladds = [ elem for elem in ladders.values() ]
315
     ladds = [ elem for elem in ladders.values() ]
398
     sheets = {}
316
     sheets = {}
399
-
400
     corresp = {}
317
     corresp = {}
401
     for ladd1 in ladds:
318
     for ladd1 in ladds:
402
         for ladd2 in ladds:
319
         for ladd2 in ladds:
414
                     corresp[ladd2['i']] = corresp[ladd1['i']]
331
                     corresp[ladd2['i']] = corresp[ladd1['i']]
415
                 elif ladd1 not in corresp_list and ladd2 in corresp_list:
332
                 elif ladd1 not in corresp_list and ladd2 in corresp_list:
416
                     sheets[corresp[ladd2['i']]].append(ladd1)
333
                     sheets[corresp[ladd2['i']]].append(ladd1)
417
-                    corresp[ladd1['i']] = corresp[ladd2['i']]
418
-                    
334
+                    corresp[ladd1['i']] = corresp[ladd2['i']]                   
419
     return sheets
335
     return sheets
420
-
421
-def get_sheets2(ladders):
422
-    """
423
-    Bridges between ladders.
424
-    Check if 1 bridge between one ladder and one or more other ladders.
425
-    Iterate over all residues of one ladder and check if bridge with other residues
426
-    of the other ladders.
427
-    """
428
-    sheets = {}    
429
-    for ladder in ladders:
430
-        for ladd2 in ladders:
431
-            if connected_ladders(ladders[ladder], ladders[ladd2]):
432
-                bridge_i = connected_ladders2(ladders[ladder], ladders[ladd2])[2]
433
-                bridge_j = connected_ladders2(ladders[ladder], ladders[ladd2])[3]
434
-                print("ladder",ladders[ladder]['i'], ladders[ladder]['j'],"bridge",bridge_i, bridge_j,
435
-                      "ladder 2",ladders[ladd2]['i'], ladders[ladd2]['j'])
436
-
437
-               
336
+   
438
 def res_list(ladder):
337
 def res_list(ladder):
439
-    # TODO : method in ladder class
440
     l=[]
338
     l=[]
441
     for i in range(ladder['i'], ladder['j']):
339
     for i in range(ladder['i'], ladder['j']):
442
         l.append(i)
340
         l.append(i)
467
         if(helix):
365
         if(helix):
468
             helix_type = residues[i].get_helix(residues)[0]
366
             helix_type = residues[i].get_helix(residues)[0]
469
             helix_pos = residues[i].get_helix(residues)[1]
367
             helix_pos = residues[i].get_helix(residues)[1]
470
-            #print("TYPE", helix_type)
471
             for k in range(helix_type):
368
             for k in range(helix_type):
472
                 if helix_type == 3:
369
                 if helix_type == 3:
473
                     helix_3[i+1+k] = "G"
370
                     helix_3[i+1+k] = "G"
475
                     helix_4[i+1+k] = "H"
372
                     helix_4[i+1+k] = "H"
476
                 if helix_type == 5:
373
                 if helix_type == 5:
477
                     helix_5[i+1+k] = "I"
374
                     helix_5[i+1+k] = "I"
478
-        #print(helix_3)
479
     return[helix_3, helix_4, helix_5]
375
     return[helix_3, helix_4, helix_5]
480
 
376
 
481
 def print_helix_pattern(residues, res, helix):
377
 def print_helix_pattern(residues, res, helix):
503
             ladd_2 = ladders[ladd2]
399
             ladd_2 = ladders[ladd2]
504
             for bridge in ladd_1['bridges']:
400
             for bridge in ladd_1['bridges']:
505
                 if bridge.j in res_list(ladd_2):  
401
                 if bridge.j in res_list(ladd_2):  
506
-                    print("ladder", ladd_1['i'],"-",ladd_1['j'], "|", bridge.i, "...", bridge.j, "| ladder", ladd_2['i'], ladd_2['j'])
402
+                    print("ladder", ladd_1['i'],"-", ladd_1['j'], "|",
403
+                          bridge.i, "...", bridge.j, "| ladder",
404
+                          ladd_2['i'], ladd_2['j'])
507
 
405
 

+ 1 - 3
src/pdb.py View File

110
         self.rawLines = self.get_content(filename)
110
         self.rawLines = self.get_content(filename)
111
         self.metadata = self.get_header()
111
         self.metadata = self.get_header()
112
         self.get_atoms(filename)
112
         self.get_atoms(filename)
113
-        # for elem in self.metadata : 
114
-        #     print(self.metadata[elem], end="")
115
-        
113
+