Browse Source

cleaner output

Thomas Forest 4 years ago
parent
commit
314a12386b

BIN
src/__pycache__/atom.cpython-37.pyc View File


BIN
src/__pycache__/geom.cpython-37.pyc View File


BIN
src/__pycache__/pdb.cpython-37.pyc View File


BIN
src/__pycache__/structure.cpython-37.pyc View File


+ 507 - 0
src/chem.py View File

@@ -0,0 +1,507 @@
1
+import math
2
+#from structure import *
3
+from geom import *
4
+
5
+class Atom:
6
+
7
+    def dist_atoms(self, atom2):
8
+        return(math.sqrt((self.coord_x-atom2.coord_x)**2 +
9
+                         (self.coord_y-atom2.coord_y)**2 +
10
+                         (self.coord_z-atom2.coord_z)**2))
11
+
12
+
13
+    def __init__(self, atom_id, atom_name, res_name, chain_id,
14
+                 res_seq_nb, insertion_code, coordinates):
15
+        self.atom_id = atom_id
16
+        self.atom_name = atom_name
17
+        self.res_name = res_name
18
+        self.chain_id = chain_id
19
+        self.res_seq_nb = res_seq_nb
20
+        self.insertion_code = insertion_code
21
+        self.coord_x = coordinates[0]
22
+        self.coord_y = coordinates[1]
23
+        self.coord_z = coordinates[2]
24
+        self.coords = coordinates
25
+
26
+class Structure:
27
+    def __init__(self, res):
28
+        self.res = res
29
+
30
+class Turn(Structure):
31
+
32
+    def __init__(self, turn_type, res):
33
+        self.turn_type = turn_type
34
+        Structure.res = res
35
+                        
36
+class Bridge(Structure):
37
+
38
+    def __init__(self, bridge_type, res_num, res_partner, indices):
39
+        self.bridge_type = bridge_type
40
+        self.res_num = res_num
41
+        self.res_partner = res_partner
42
+        Structure.res = res_num
43
+        self.i = indices[0]
44
+        self.j = indices[1]
45
+
46
+class Helix(Structure):
47
+
48
+    def __init__(self, residues, res_num, helix_type):
49
+        self.residues = residues
50
+        self.res_num = res_num
51
+        Structure.res = res_num
52
+        self.helix_type = helix_type
53
+
54
+        
55
+class Residue:
56
+    def __init__(self, atoms_list, indice):
57
+        self.atoms = {}
58
+        for atom in atoms_list:
59
+            self.atoms[atom.atom_name] = atom
60
+            self.resid = atom.res_seq_nb
61
+            self.res_name = atom.res_name
62
+            self.res_letter = self.get_amino_letter(atom.res_name)
63
+            self.chain_id = atom.chain_id
64
+            self.insertion_code = atom.insertion_code
65
+            self.indice = indice
66
+            
67
+    def get_amino_letter(self, res_name):
68
+        code3 = ['ALA', 'ARG', 'ASN', 'ASP', 'CYS', 'GLU', 'GLN', 'GLY',
69
+                 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER',
70
+                 'THR', 'TRP', 'TYR', 'VAL']
71
+
72
+
73
+        code1 = ['A','R','N','D','C','E','Q','G','H','I','L','K','M','F','P',
74
+                 'S','T','W','Y','V']
75
+
76
+        return code1[code3.index(res_name)]
77
+
78
+    def h_bond(self, res2):
79
+        if("H" not in res2.atoms.keys()):
80
+            return(False)
81
+        # dimensionnal factor, in kcal/mole
82
+        f = 332
83
+        # partial charges
84
+        q1 = 0.42
85
+        q2 = 0.20
86
+        # distance between O-N atoms, in angströms
87
+        r_ON = self.atoms["O"].dist_atoms(res2.atoms["N"])
88
+        # distance between C-H atoms, in angströms
89
+        r_CH = self.atoms["C"].dist_atoms(res2.atoms["H"])
90
+        # distance between O-H atoms, in angströms
91
+        r_OH = self.atoms["O"].dist_atoms(res2.atoms["H"])
92
+        # distance between C-N atoms, in angströms
93
+        r_CN = self.atoms["C"].dist_atoms(res2.atoms["N"])
94
+        # electrostatic interaction energy, in kcal/mole
95
+        E = q1*q2*(1/r_ON + 1/r_CH - 1/r_OH - 1/r_CN)*f
96
+        return(E)
97
+
98
+    def get_turns(self, residues):
99
+        """
100
+        Get all the turns from a specific residue.
101
+        """
102
+        turns = {}
103
+        i = residues.index(self)
104
+        k = 0
105
+        for j in range(3,6):
106
+                if(i+j<len(residues)):
107
+                    if(self.h_bond(residues[i+j])<-0.5):
108
+                        k = j
109
+        if k != 0:    
110
+            #print(k,"TURN", residues[i].resid, residues[i+k].resid)
111
+            return Turn(k,residues[i].resid)
112
+
113
+        return False
114
+
115
+    def get_bends(self, residues):
116
+        i = residues.index(self)
117
+        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))))
122
+            if(angle>70):
123
+                return [angle, 'S']
124
+            return [angle, '']
125
+        else:
126
+            return [360.0, '']
127
+
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):
191
+        """
192
+        Return if there is an helix at a given residue,
193
+        as well as its type.
194
+        """
195
+        i = residues.index(self)
196
+        # if there are no turns or it is the first residue, skip
197
+        if i == 0:
198
+            return False
199
+        
200
+        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)
203
+        return(False)
204
+
205
+    def get_ladder(self, residues):
206
+        #ladders = {}
207
+        i = residues.index(self)
208
+        if i != 0:
209
+            if self.get_bridges(residues):
210
+                if (residues[i-1].get_bridges(residues)):
211
+                    local_bridge = self.get_bridges(residues)
212
+                    consec_bridge = residues[i-1].get_bridges(residues)
213
+                    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,
216
+                                  'end':local_bridge.res_num,
217
+                                  'bridges':[consec_bridge, local_bridge]}
218
+                        return ladder
219
+        return False   
220
+
221
+    def get_tco(self, residues):
222
+        i = residues.index(self)
223
+        if(i!=0):
224
+            res2 = residues[i-1]
225
+            CO_res1 = vector_from_pos(self.atoms["C"].coords,
226
+                                      self.atoms["O"].coords)
227
+            CO_res2 = vector_from_pos(res2.atoms["C"].coords,
228
+                                      res2.atoms["O"].coords)
229
+            angle = vector_angles(CO_res1, CO_res2)
230
+        else:
231
+            angle = math.pi/2
232
+        return(math.cos(angle))
233
+
234
+    def get_chirality(self, residues):
235
+        i = residues.index(self)
236
+        if (i >=1 and i < len(residues)-2):
237
+            chirality = {}
238
+            angle = calc_dihedral(residues[i-1].atoms["CA"].coords,
239
+                                  residues[i].atoms["CA"].coords,
240
+                                  residues[i+1].atoms["CA"].coords,
241
+                                  residues[i+2].atoms["CA"].coords)
242
+
243
+            if(angle>0 and angle<=180):
244
+                sign="+"
245
+
246
+            if(angle<=0 and angle > -180):
247
+                sign="-"
248
+
249
+        else:
250
+            angle = 360.0
251
+            sign = ''
252
+
253
+        return [angle, sign]
254
+    
255
+    def get_phi_psi(self, residues):
256
+        i = residues.index(self)  
257
+        if(i==0):
258
+            phi = 360.0
259
+        else:
260
+            phi = calc_dihedral(residues[i-1].atoms["C"].coords,
261
+                                residues[i].atoms["N"].coords,
262
+                                residues[i].atoms["CA"].coords,
263
+                                residues[i].atoms["C"].coords)
264
+        if(i==len(residues)-1):
265
+            psi = 360.0
266
+        else:
267
+            psi = calc_dihedral(residues[i].atoms["N"].coords,
268
+                                residues[i].atoms["CA"].coords,
269
+                                residues[i].atoms["C"].coords,
270
+                                residues[i+1].atoms["N"].coords)
271
+
272
+        return((phi, psi))
273
+def get_bridges(residues):
274
+    bridges = {}
275
+    bridge = {}
276
+    strongest_bridge = {}
277
+    for i in range(1,len(residues)-4):
278
+        E_min = 0
279
+        for j in range(i+2,len(residues)-1):
280
+            # select triplet with the minimal energy 
281
+            
282
+            if(residues[i-1].h_bond(residues[j])<-0.5
283
+               and residues[j].h_bond(residues[i+1])<-0.5):
284
+                bridge = {'res1':residues[i-1].h_bond(residues[j]),
285
+                          'res2':residues[j].h_bond(residues[i+1]),
286
+                          'ipos':residues[i].resid,
287
+                          'jpos':residues[j].resid,
288
+                          'i':residues[i].indice,
289
+                          'j':residues[j].indice,
290
+                          'btype':"para"}
291
+                   
292
+            if(residues[j-1].h_bond(residues[i])<-0.5
293
+               and residues[i].h_bond(residues[j+1])<-0.5):
294
+                bridge = {'res1':residues[j-1].h_bond(residues[i]),
295
+                          'res2':residues[i].h_bond(residues[j+1]),
296
+                          'ipos':residues[i].resid,
297
+                          'jpos':residues[j].resid,
298
+                          'i':residues[i].indice,
299
+                          'j':residues[j].indice,
300
+                          'btype':"para"}
301
+
302
+            if(residues[i].h_bond(residues[j])<-0.5
303
+               and residues[j].h_bond(residues[i])<-0.5):
304
+                bridge = {'res1':residues[i].h_bond(residues[j]),
305
+                          'res2':residues[j].h_bond(residues[i]),
306
+                          'ipos':residues[i].resid,
307
+                          'jpos':residues[j].resid,
308
+                          'i':residues[i].indice,
309
+                          'j':residues[j].indice,
310
+                          'btype':"anti"}
311
+                    
312
+            if(residues[i-1].h_bond(residues[j+1])<-0.5
313
+               and residues[j-1].h_bond(residues[i+1])<-0.5):
314
+                bridge = {'res1':residues[i-1].h_bond(residues[j+1]),
315
+                          'res2':residues[j-1].h_bond(residues[i+1]),
316
+                          'ipos':residues[i].resid,
317
+                          'jpos':residues[j].resid,
318
+                          'i':residues[i].indice,
319
+                          'j':residues[j].indice,
320
+                          'btype':"anti"}
321
+
322
+            if(bridge):
323
+                if(bridge['res1']+bridge['res2']<E_min):
324
+                    E_min = bridge['res1']+bridge['res2']
325
+                    strongest_bridge = bridge
326
+                    coord_bridge = [i,j]
327
+                    bridge = {}
328
+
329
+        # finally add the strongest bridge at i and j pos
330
+        if(strongest_bridge):
331
+
332
+            bridges[strongest_bridge['i']] = (Bridge(strongest_bridge['btype'],
333
+                                                     strongest_bridge['ipos'],
334
+                                                     strongest_bridge['jpos'],
335
+                                                     [strongest_bridge['i'],
336
+                                                      strongest_bridge['j']]))
337
+                                              
338
+            bridges[strongest_bridge['j']] = (Bridge(strongest_bridge['btype'],
339
+                                                     strongest_bridge['ipos'],
340
+                                                     strongest_bridge['jpos'],
341
+                                                     [strongest_bridge['i'],
342
+                                                      strongest_bridge['j']]))
343
+    if(len(bridges)>0):
344
+        return(bridges)
345
+    else:
346
+        return(False)
347
+
348
+def get_ladders(bridges, residues):
349
+    ladders = {}
350
+    i = 1
351
+    while i < len(residues):
352
+        k = 1
353
+        if i in bridges.keys():
354
+            temp_bridges = [bridges[i]]
355
+            while ((i+k in bridges.keys()) and
356
+                   (bridges[i].bridge_type == bridges[i+k].bridge_type)):
357
+                temp_bridges.append(bridges[i+k])
358
+                k+=1
359
+        if k>1:
360
+            #print("ladder", bridges[i].res_num, bridges[i+k-1].res_num)
361
+            ladders[i] = {'start':bridges[i].res_num,
362
+                          'end':bridges[i+k-1].res_num,
363
+                          'bridges':temp_bridges,
364
+                          'i':i,
365
+                          'j':i+k-1}
366
+            i+=k-1
367
+        else:
368
+            i+=1
369
+    return ladders
370
+
371
+def connected_ladders(ladd_1, ladd_2):
372
+    links = []
373
+    for bridge in ladd_1['bridges']:
374
+        if bridge.res_partner in res_list(ladd_2):
375
+            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
388
+
389
+
390
+def get_sheets(ladders):
391
+    """
392
+    Bridges between ladders.
393
+    Check if 1 bridge between one ladder and one or more other ladders.
394
+    Iterate over all residues of one ladder and check if bridge with other residues
395
+    of the other ladders.
396
+    """
397
+    ladds = [ elem for elem in ladders.values() ]
398
+    sheets = {}
399
+
400
+    corresp = {}
401
+    for ladd1 in ladds:
402
+        for ladd2 in ladds:
403
+            if connected_ladders(ladd1, ladd2)!=False:
404
+                corresp_list = [ elem for elem in corresp.keys() ]
405
+                if ladd1['i'] not in corresp_list and ladd2['i'] not in corresp_list:
406
+                    ind = len(sheets.keys())
407
+                    sheets[ind] = []
408
+                    sheets[ind].append(ladd1)
409
+                    sheets[ind].append(ladd2)
410
+                    corresp[ladd1['i']] = ind
411
+                    corresp[ladd2['i']] = ind
412
+                elif ladd2 not in corresp_list and ladd1 in corresp_list:
413
+                    sheets[corresp[ladd1['i']]].append(ladd2)
414
+                    corresp[ladd2['i']] = corresp[ladd1['i']]
415
+                elif ladd1 not in corresp_list and ladd2 in corresp_list:
416
+                    sheets[corresp[ladd2['i']]].append(ladd1)
417
+                    corresp[ladd1['i']] = corresp[ladd2['i']]
418
+                    
419
+    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
+               
438
+def res_list(ladder):
439
+    # TODO : method in ladder class
440
+    l=[]
441
+    for i in range(ladder['i'], ladder['j']):
442
+        l.append(i)
443
+    return(l)
444
+
445
+def build_turns_patterns(residues):
446
+    turns_3 = {}
447
+    turns_4 = {}
448
+    turns_5 = {}
449
+    for i,res in enumerate(residues):
450
+        turn = residues[i].get_turns(residues)
451
+        if(turn):
452
+            for k in range(turn.turn_type):
453
+                if turn.turn_type == 3:
454
+                    turns_3[i+1+k] = turn.turn_type
455
+                if turn.turn_type == 4:
456
+                    turns_4[i+1+k] = turn.turn_type
457
+                if turn.turn_type == 5:
458
+                    turns_5[i+1+k] = turn.turn_type
459
+    return[turns_3, turns_4, turns_5]
460
+
461
+def build_helix_patterns(residues):
462
+    helix_3 = {}
463
+    helix_4 = {}
464
+    helix_5 = {}
465
+    for i,res in enumerate(residues):
466
+        helix = residues[i].get_helix(residues)
467
+        if(helix):
468
+            helix_type = residues[i].get_helix(residues)[0]
469
+            helix_pos = residues[i].get_helix(residues)[1]
470
+            #print("TYPE", helix_type)
471
+            for k in range(helix_type):
472
+                if helix_type == 3:
473
+                    helix_3[i+1+k] = "G"
474
+                if helix_type == 4:
475
+                    helix_4[i+1+k] = "H"
476
+                if helix_type == 5:
477
+                    helix_5[i+1+k] = "I"
478
+        #print(helix_3)
479
+    return[helix_3, helix_4, helix_5]
480
+
481
+def print_helix_pattern(residues, res, helix):
482
+    i = residues.index(res)+1
483
+    if i in helix.keys():
484
+        return (helix[i])
485
+    else:
486
+        return(' ')
487
+
488
+def print_turn_pattern(residues, res, turns):
489
+    i = residues.index(res)+1
490
+    if i in turns.keys() and not i-1 in turns.keys():
491
+        return(">")
492
+    elif i in turns.keys() and i-1 in turns.keys():
493
+        return(turns[i])
494
+    elif i not in turns.keys() and i-1 in turns.keys():
495
+        return("<")
496
+    else:
497
+        return(' ')
498
+    
499
+def raw_ladders_print(ladders, ):
500
+    for ladd1 in ladders:
501
+        ladd_1 = ladders[ladd1]
502
+        for ladd2 in ladders:
503
+            ladd_2 = ladders[ladd2]
504
+            for bridge in ladd_1['bridges']:
505
+                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'])
507
+

src/atom.py → src/chem.py~ View File

@@ -1,5 +1,7 @@
1 1
 import math
2
-from structure import *
2
+#from structure import *
3
+from geom import *
4
+
3 5
 class Atom:
4 6
 
5 7
     def dist_atoms(self, atom2):
@@ -21,6 +23,35 @@ class Atom:
21 23
         self.coord_z = coordinates[2]
22 24
         self.coords = coordinates
23 25
 
26
+class Structure:
27
+    def __init__(self, res):
28
+        self.res = res
29
+
30
+class Turn(Structure):
31
+
32
+    def __init__(self, turn_type, res):
33
+        self.turn_type = turn_type
34
+        Structure.res = res
35
+                        
36
+class Bridge(Structure):
37
+
38
+    def __init__(self, bridge_type, res_num, res_partner, indices):
39
+        self.bridge_type = bridge_type
40
+        self.res_num = res_num
41
+        self.res_partner = res_partner
42
+        Structure.res = res_num
43
+        self.i = indices[0]
44
+        self.j = indices[1]
45
+
46
+class Helix(Structure):
47
+
48
+    def __init__(self, residues, res_num, helix_type):
49
+        self.residues = residues
50
+        self.res_num = res_num
51
+        Structure.res = res_num
52
+        self.helix_type = helix_type
53
+
54
+        
24 55
 class Residue:
25 56
     def __init__(self, atoms_list, indice):
26 57
         self.atoms = {}

+ 77 - 95
src/dssp.py View File

@@ -1,104 +1,86 @@
1 1
 import pdb
2
-import atom
3 2
 import sys
4 3
 from structure import *
5
-from atom import *
6
-
7
-def print_dssp():
8
-
9
-    empt_line=" " * 145
10
-
4
+from chem import *
5
+import argparse
6
+
7
+from datetime import date
8
+
9
+def print_dssp(pdb_file, verbose=False, raw_ladd=False):
10
+    # gets export date
11
+    export_date = date.today().strftime("%d/%m/%Y")
12
+      
13
+    ################### OUTPUT ####################
14
+    # print DSSP-style formatted header of PDB file
15
+    print("################### DSSP OUTPUT ####################\n####",
16
+          "Exported on",export_date,
17
+          "\n####################################################")
18
+    for elem in pdb_file.get_header() : 
19
+        print(pdb_file.get_header()[elem], end="")
20
+
21
+    # Get preliminary data for print loop
22
+    residues = pdb_file.residues
23
+    bridges = get_bridges(residues)
24
+    ladders = get_ladders(bridges, residues)
25
+    sheets = get_sheets(ladders)  
26
+    helix = build_helix_patterns(residues)
27
+    # iterating over residues
28
+    # print header of table
29
+    print('   # RESIDUE AA  STRUCTURE     BP1   TCO   KAPPA  ALPHA   ' \
30
+    'PHI    PSI    X-CA   Y-CA   Z-CA')
31
+    for i,res in enumerate(residues):
32
+        #res.get_turns(residues, turns)
33
+        kappa = res.get_bends(residues)[0]
34
+        bend_symbol = res.get_bends(residues)[1]
35
+        t_co = res.get_tco(residues)
36
+        alpha = res.get_chirality(residues)[0]
37
+        chirality = res.get_chirality(residues)[1]
38
+        phi = res.get_phi_psi(residues)[0]
39
+        psi = res.get_phi_psi(residues)[1]
40
+        x_ca = res.atoms["CA"].coord_x
41
+        y_ca = res.atoms["CA"].coord_y
42
+        z_ca = res.atoms["CA"].coord_z
43
+        turns = build_turns_patterns(residues)
44
+        turn_3 = print_turn_pattern(residues, res, turns[0])
45
+        turn_4 = print_turn_pattern(residues, res, turns[1])
46
+        turn_5 = print_turn_pattern(residues, res, turns[2])
47
+        helix_3 = print_helix_pattern(residues, res, helix[0])
48
+        helix_4 = print_helix_pattern(residues, res, helix[1])
49
+        helix_5 = print_helix_pattern(residues, res, helix[2])
50
+        if i in bridges.keys():
51
+            bp1 = bridges[i].j
52
+        else:
53
+            bp1 = 0
54
+       
55
+        print('{0: >5}{1: >5}{2: >2}{3: >2}{4: >2}{5: >2}{6: >2}{7: >2}'\
56
+              '{8: >2}{9: >2}{10: >2}{11: >1}{12: >5}{13: >7}{14: >7}' \
57
+              '{15: >7}{16: >7}{17: >7}{18: >7}{19: >7}'\
58
+              '{20: >7}'.format(i+1, res.resid,
59
+                                res.chain_id,
60
+                                res.res_letter,
61
+                                helix_3, helix_4,
62
+                                helix_5, turn_3,
63
+                                turn_4, turn_5, bend_symbol,
64
+                                chirality, bp1,round(t_co, 3),
65
+                                round(kappa,1), round(alpha, 1),
66
+                                round(phi, 1), round(psi,1),
67
+                                round(x_ca,1), round(y_ca,1),
68
+                                round(z_ca,1)))
69
+    if(raw_ladd):
70
+        raw_ladders_print(ladders)
71
+
72
+parser = argparse.ArgumentParser()
11 73
 if(len(sys.argv)<2):
12 74
     print("Not enough arguments! Run with --help to learn more about proper"
13 75
           "call structure and parameters.")
14 76
 else:
77
+    parser.add_argument("file", type=str, help="input file in PDB format")
78
+    parser.add_argument("-v","--verbose", help="add ladders verbose output",
79
+                        action="store_true")
80
+    args = parser.parse_args()
15 81
     pdb_file = pdb.PDBFile(sys.argv[1])
16
-  
17
-    #turns = get_turns(pdb_file.residues)
18
-    #get_helix(pdb_file.residues, turns)
19
-    #get_bends(pdb_file.residues)
20
-    # get_chirality(pdb_file.residues)
21
-
22
-
23
-    # print("NBRIDGES",len(bridges))
24
-
25
-    # bridges = get_bridges(pdb_file.residues)
26
-
27
-    # get_bonds(pdb_file.residues)
28
-
29
-
30
-    # e_min = 0
31
-    # for res in residues:
32
-    #     ene = residues[1].h_bond(res)
33
-    #     if ene <= e_min:
34
-    #         e_min = ene
35
-    #         best_res = res
36
-    #print(residues[1].resid, best_res.resid,e_min)
37
-
38
-    #get_phi_psi(residues)
39
-    #print(residues[2].atoms, residues[0].resid, residues[1].resid)
40
-    #print(get_TCO(residues[2],residues[3]))
41
-
42
-
43
-# for i,ladder in enumerate(ladders.values()):
44
-#     print(chr(65+i))
45
-    
46
-# for ind, sheet in sheets.items():
47
-#     print(ind, sheet)
48
-#     for ladder in sheet:
49
-#         print(ladder['start'], ladder['end'])
50
-
51
-
52
-################### OUTPUT ####################
53
-# print DSSP-style formatted header of PDB file
54
-for elem in pdb_file.get_header() : 
55
-    print(pdb_file.get_header()[elem], end="")
56
-
57
-# Get preliminary data for print loop
58
-residues = pdb_file.residues
59
-bridges = get_bridges(residues)
60
-ladders = get_ladders(bridges, residues)
61
-sheets = get_sheets(ladders)  
62
-helix = build_helix_patterns(residues)
63
-# iterating over residues
64
-
65
-
66
-for i,res in enumerate(residues):
67
-    #res.get_turns(residues, turns)
68
-    kappa = res.get_bends(residues)[0]
69
-    bend_symbol = res.get_bends(residues)[1]
70
-    t_co = res.get_tco(residues)
71
-    alpha = res.get_chirality(residues)[0]
72
-    chirality = res.get_chirality(residues)[1]
73
-    phi = res.get_phi_psi(residues)[0]
74
-    psi = res.get_phi_psi(residues)[1]
75
-    x_ca = res.atoms["CA"].coord_x
76
-    y_ca = res.atoms["CA"].coord_y
77
-    z_ca = res.atoms["CA"].coord_z
78
-    turns = build_turns_patterns(residues)
79
-    turn_3 = print_turn_pattern(residues, res, turns[0])
80
-    turn_4 = print_turn_pattern(residues, res, turns[1])
81
-    turn_5 = print_turn_pattern(residues, res, turns[2])
82
-    helix_3 = print_helix_pattern(residues, res, helix[0])
83
-    helix_4 = print_helix_pattern(residues, res, helix[1])
84
-    helix_5 = print_helix_pattern(residues, res, helix[2])
85
-    if i in bridges.keys():
86
-        bp1 = bridges[i].j
82
+    if(args.verbose):
83
+        print_dssp(pdb_file, raw_ladd=True)
87 84
     else:
88
-        bp1 = 0
89
-    print(i+1, res.resid, res.chain_id, res.res_letter, helix_3, helix_4, helix_5, turn_3, turn_4, turn_5, bend_symbol, chirality, bp1,round(t_co, 3), round(kappa,1),
90
-           round(alpha, 1), round(phi, 1), round(psi,1), round(x_ca,1), round(y_ca,1), round(z_ca,1))
91
-
92
-
93
-for ladd1 in ladders:
94
-    ladd_1 = ladders[ladd1]
95
-    for ladd2 in ladders:
96
-        ladd_2 = ladders[ladd2]
97
-        for bridge in ladd_1['bridges']:
98
-            if bridge.j in res_list(ladd_2):  
99
-                print("ladder", ladd_1['i'],"-",ladd_1['j'], "|", bridge.i, "...", bridge.j, "| ladder", ladd_2['i'], ladd_2['j'])
100
-
101
-# for ind, sheet in sheets.items():
102
-#     print(ind, sheet)
103
-#     for ladder in sheet:
104
-#         print(ladder['start'], ladder['end'])
85
+        print_dssp(pdb_file)
86
+    

+ 0 - 66
src/geom.py~ View File

@@ -1,66 +0,0 @@
1
-
2
-def vector_from_pos(a, b):
3
-    xAB = b[0]-a[0]
4
-    yAB = b[1]-a[1]
5
-    zAB = b[2]-a[2]
6
-    coord_AB = [xAB,yAB,zAB]
7
-    return coord_AB
8
-
9
-def vector_norm(v):
10
-    norm = math.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
11
-    return norm
12
-
13
-def dot_product(v1,v2):
14
-    dot_product = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]
15
-    return(dot_product)
16
-
17
-def position_vector(c):
18
-    vector = vector_from_pos([0,0,0],c)
19
-    return vector
20
-
21
-def vectors_substr(v1, v2):
22
-    return ([v1[0]-v2[0],
23
-             v1[1]-v2[1],
24
-             v1[2]-v2[2]])
25
-
26
-def vector_angles(v1,v2):
27
-    dot_prod = dot_product(v1,v2)
28
-    norm_v1 = vector_norm(v1)
29
-    norm_v2 = vector_norm(v2)
30
-    term = dot_prod/(abs(norm_v1)*abs(norm_v2))
31
-    rad_angle = math.acos(term)
32
-    return rad_angle
33
-
34
-def calc_dihedral(u1, u2, u3, u4):
35
-    """ Calculate dihedral angle method. From bioPython.PDB
36
-    (adapted to np.array)
37
-    Calculate the dihedral angle between 4 vectors
38
-    representing 4 connected points. The angle is in
39
-    [-pi, pi].
40
-
41
-    Adapted function of dihedral_angle_from_coordinates.py 
42
-    by Eric Alcaide.
43
-    Source : https://gist.github.com/EricAlcaide
44
-    URL : https://gist.github.com/EricAlcaide/30d6bfdb8358d3a57d010c9a501fda56
45
-    """
46
-    #convert coords to numpy arrays
47
-    u1 = np.array(u1)
48
-    u2 = np.array(u2)
49
-    u3 = np.array(u3)
50
-    u4 = np.array(u4)
51
-    
52
-    a1 = u2 - u1
53
-    a2 = u3 - u2
54
-    a3 = u4 - u3
55
-
56
-    v1 = np.cross(a1, a2)
57
-    v1 = v1 / (v1 * v1).sum(-1)**0.5
58
-    v2 = np.cross(a2, a3)
59
-    v2 = v2 / (v2 * v2).sum(-1)**0.5
60
-    porm = np.sign((v1 * a3).sum(-1))
61
-    rad = np.arccos((v1*v2).sum(-1) / ((v1**2).sum(-1) * (v2**2).sum(-1))**0.5)
62
-    if not porm == 0:
63
-        rad = rad * porm
64
-
65
-    deg_angle = rad*(180/math.pi)
66
-    return deg_angle

+ 2 - 4
src/pdb.py View File

@@ -1,5 +1,5 @@
1 1
 # custom imports
2
-from atom import *
2
+from chem import *
3 3
 # import libs
4 4
 import sys
5 5
 import pymol
@@ -67,9 +67,7 @@ class PDBFile:
67 67
         # hydrogens should represent in average 50% of total atoms...
68 68
         # We use 30% threshold...
69 69
         if(count_h/len(temp_atoms)<0.30):
70
-            #if(output_pdb==None):
71
-            print("Need to add hydrogens ! If you want the modified PDB file, " 
72
-                  "please use the -o output.pdb argument")
70
+            #Need to add hydrogens 
73 71
             self.add_hydrogens(filename)
74 72
 
75 73
     def check_hydrogens(self, atoms):