/
NCSChain.py
executable file
·742 lines (690 loc) · 23.2 KB
/
NCSChain.py
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
#!/usr/bin/python
from Bio.PDB import *
from Bio.PDB.Polypeptide import *
from Bio.Alphabet import IUPAC
from Bio import pairwise2
from Bio.pairwise2 import *
from Bio.Seq import Seq
import numpy as np
import math
import os
import sys
def getDihedral(p):
''' Reference: http://stackoverflow.com/questions/20305272/dihedral-torsion-angle-from-four-points-in-cartesian-coordinates-in-python'''
"""Praxeolitic formula
1 sqrt, 1 cross product"""
p0 = p[0]
p1 = p[1]
p2 = p[2]
p3 = p[3]
b0 = -1.0*(p1 - p0)
b1 = p2 - p1
b2 = p3 - p2
# normalize b1 so that it does not influence magnitude of vector
# rejections that come next
b1 /= np.linalg.norm(b1)
# vector rejections
# v = projection of b0 onto plane perpendicular to b1
# = b0 minus component that aligns with b1
# w = projection of b2 onto plane perpendicular to b1
# = b2 minus component that aligns with b1
v = b0 - np.dot(b0, b1)*b1
w = b2 - np.dot(b2, b1)*b1
# angle between v and w in a plane is the torsion angle
# v and w may not be normalized but that's fine since tan is y/x
x = np.dot(v, w)
y = np.dot(np.cross(b1, v), w)
return np.degrees(np.arctan2(y, x))
def getChains(fileName):
''' Get all chains in a protein
Args:
name (string), mmcif file name
Return:
chains (generator), all chains in the protein
'''
# Create a mmcif parser
parser = MMCIFParser();
# Create a structure object
name = os.path.splitext(os.path.basename(fileName))[0];
structure = parser.get_structure(name, fileName);
# Get all chains
for chain in structure.get_chains():
yield chain;
def getResidues(chain):
return list(chain.get_residues());
def getSCDist(atomDict, resName):
''' Get the distance between CA and the mass center of the side-chain
Args:
residue (residue)
'''
massCenter = getSCMassCenter(atomDict, resName);
if len(massCenter) == 0: # no atoms
return -1;
return getDist(atomDict['CA'], massCenter);
def getBlockDist(atomDict, resName):
''' Get the distance between CA and the mass center of the side-chain
Args:
residue (residue)
'''
massCenter = getBlockMassCenter(atomDict, resName);
if len(massCenter) == 0: # no atoms
return -1;
return getDist(atomDict['CA'], massCenter);
def getAtomMass(atomName):
t = atomName[0];
mN = 14.0067;
mC = 12.0107;
mO = 15.9994;
mS = 32.065;
if t == 'N':
return mN;
if t == 'C':
return mC;
if t == 'O':
return mO;
if t == 'S':
return mS;
def getBlockMassCenter(atomDict, resName):
''' Get the block center
Ref: http://formulas.tutorvista.com/physics/center-of-mass-formula.html
'''
l = [];
if resName == 'ALA':
atomList = ['CB'];
if resName == 'ARG':
atomList = ['NE', 'CZ', 'NH1', 'NH2'];
if resName == 'ASN':
atomList = ['CG', 'OD1', 'ND2'];
if resName == 'ASP':
atomList = ['CG', 'OD1', 'OD2'];
if resName == 'CYS':
atomList = ['CB', 'SG'];
if resName == 'GLU':
atomList = ['CD', 'OE1', 'OE2'];
if resName == 'GLN':
atomList = ['CD', 'OE1', 'NE2'];
if resName == 'GLY':
atomList = [];
if resName == 'HIS':
atomList = ['CG', 'ND1', 'CD2', 'CE1', 'NE2'];
if resName == 'ILE':
atomList = ['CD1'];
if resName == 'LEU':
atomList = ['CG', 'CD1', 'CD2'];
if resName == 'LYS':
atomList = ['CE', 'NZ'];
if resName == 'MET':
atomList = ['SD', 'CE'];
if resName == 'PHE':
atomList = ['CG', 'CD1', 'CD2', 'CE1', 'CE2', 'CZ'];
if resName == 'PRO':
atomList = ['CB', 'CG', 'CD'];
if resName == 'SER':
atomList = ['OG'];
if resName == 'THR':
atomList = ['CB', 'OG1', 'CG2'];
if resName == 'TRP':
atomList = ['CG', 'CD1', 'CD2', 'NE1', 'CE2', 'CE3', 'CZ2', 'CZ3', 'CH2'];
if resName == 'TYR':
atomList = ['OH'];
if resName == 'VAL':
atomList = ['CB', 'CG1', 'CG2'];
if len(atomList) == 0:
return l;
massTemp = 0;
xTemp = 0;
yTemp = 0;
zTemp = 0;
for a in atomList:
coord = atomDict[a];
m = getAtomMass(a);
massTemp += m;
xTemp += coord[0]*m;
yTemp += coord[1]*m;
zTemp += coord[2]*m;
return [xTemp/massTemp, yTemp/massTemp, zTemp/massTemp];
def getSCMassCenter(atomDict, resName):
''' Get the residue mass center
Ref: http://formulas.tutorvista.com/physics/center-of-mass-formula.html
'''
l = [];
if resName == 'ALA':
atomList = ['CB'];
if resName == 'ARG':
atomList = ['CB', 'CG', 'CD', 'NE', 'CZ', 'NH1', 'NH2'];
if resName == 'ASN':
atomList = ['CB', 'CG', 'OD1', 'ND2'];
if resName == 'ASP':
atomList = ['CB', 'CG', 'OD1', 'OD2'];
if resName == 'CYS':
atomList = ['CB', 'SG'];
if resName == 'GLU':
atomList = ['CB', 'CG', 'CD', 'OE1', 'OE2'];
if resName == 'GLN':
atomList = ['CB', 'CG', 'CD', 'OE1', 'NE2'];
if resName == 'GLY':
atomList = [];
if resName == 'HIS':
atomList = ['CB', 'CG', 'ND1', 'CD2', 'CE1', 'NE2'];
if resName == 'ILE':
atomList = ['CB', 'CG1', 'CG2', 'CD1'];
if resName == 'LEU':
atomList = ['CB', 'CG', 'CD1', 'CD2'];
if resName == 'LYS':
atomList = ['CB', 'CG', 'CD', 'CE', 'NZ'];
if resName == 'MET':
atomList = ['CB', 'CG', 'SD', 'CE'];
if resName == 'PHE':
atomList = ['CB', 'CG', 'CD1', 'CD2', 'CE1', 'CE2', 'CZ'];
if resName == 'PRO':
atomList = ['CB', 'CG', 'CD'];
if resName == 'SER':
atomList = ['CB', 'OG'];
if resName == 'THR':
atomList = ['CB', 'OG1', 'CG2'];
if resName == 'TRP':
atomList = ['CB', 'CG', 'CD1', 'CD2', 'NE1', 'CE2', 'CE3', 'CZ2', 'CZ3', 'CH2'];
if resName == 'TYR':
atomList = ['CB', 'CG', 'CD1', 'CD2', 'CE1', 'CE2', 'CZ', 'OH'];
if resName == 'VAL':
atomList = ['CB', 'CG1', 'CG2'];
if len(atomList) == 0:
return l;
massTemp = 0;
xTemp = 0;
yTemp = 0;
zTemp = 0;
for a in atomList:
coord = atomDict[a];
m = getAtomMass(a);
massTemp += m;
xTemp += coord[0]*m;
yTemp += coord[1]*m;
zTemp += coord[2]*m;
return [xTemp/massTemp, yTemp/massTemp, zTemp/massTemp];
def getDist(coord_1, coord_2):
dist = 0;
for i in xrange(3):
dist += (coord_1[i] - coord_2[i])*(coord_1[i] - coord_2[i]);
return math.sqrt(dist);
def getRotamer(residues, name):
''' Collect the data for each specific residue
Args:
residues (list), residue list
name (string), residue name
'''
with open(name+'.csv', 'a') as outputFile:
residueSize = len(residues);
for index, residue in enumerate(residues):
# Ignore the first residue and the last residue
if index == 0 or index == residueSize-1:
continue;
# Calculate phi, psi and chi for the specific residues
if residue.get_resname() == name:
angles = getPhiPsiChi(residues, index);
if len(angles) == 0:
continue;
# output protein id, chain id, residue index, residue name
line = residue.get_parent().get_parent().get_parent().get_id()+','+str(residue.get_parent().get_id())+','+str(residue.get_id()[1])+','+residue.get_resname();
# calculate dist between CA and side-chain center, dist between CA and block center
atomDict = getResidueDict(residue);
resName = residue.get_resname();
line = line+','+str(getSCDist(atomDict, resName));
line = line+','+str(getBlockDist(atomDict, resName));
# output phi, psi, chi_1
for angle in angles:
line = line+','+str(angle);
line = line+'\n';
outputFile.write(line);
def getResidueDict(residue):
''' Convert residue to a dict, key is atom name and value is coordinates '''
rDict = {};
atoms = list(residue.get_atom());
for atom in atoms:
rDict[atom.get_id()] = np.array(atom.get_coord());
return rDict;
def getPhiPsiChi(residues, index):
angles = [];
if not checkResidue(residues[index-1], residues[index-1].get_resname()):
return angles;
prevAtoms = getResidueDict(residues[index-1]); # get last residue
if not checkResidue(residues[index], residues[index].get_resname()):
return angles;
currAtoms = getResidueDict(residues[index]); # get the current residue
if not checkResidue(residues[index+1], residues[index+1].get_resname()):
return angles;
nextAtoms = getResidueDict(residues[index+1]); # get the next residue
atom_Cp = prevAtoms['C']; # C_i-1
atom_N = currAtoms['N']; # N_i
atom_CA = currAtoms['CA']; # CA_i
atom_Cc = currAtoms['C']; # C_i
atom_Nn = nextAtoms['N']; # N_i+1
phi = getDihedral([atom_Cp, atom_N, atom_CA, atom_Cc]); # phi
psi = getDihedral([atom_N, atom_CA, atom_Cc, atom_Nn]); # psi
angles.append(getAngle(phi));
angles.append(getAngle(psi));
resName = residues[index].get_resname();
atomList = [];
if resName == 'ARG': # X1, X2, X3, X4
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
atomList.append(currAtoms['CD']);
atomList.append(currAtoms['NE']);
atomList.append(currAtoms['CZ']);
if resName == 'ASN': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
if resName == 'ASP': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
if resName == 'CYS': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['SG']);
if resName == 'GLU': # X1, X2
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
atomList.append(currAtoms['CD']);
if resName == 'GLN': # X1, X2
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
atomList.append(currAtoms['CD']);
if resName == 'HIS': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
if resName == 'ILE': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG1']);
if resName == 'LEU': # X1, X2
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
atomList.append(currAtoms['CD1']);
if resName == 'LYS': # X1, X2, X3, X4
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
atomList.append(currAtoms['CD']);
atomList.append(currAtoms['CE']);
atomList.append(currAtoms['NZ']);
if resName == 'MET': # X1, X2, X3
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
atomList.append(currAtoms['SD']);
atomList.append(currAtoms['CE']);
if resName == 'PHE': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
if resName == 'PRO': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
if resName == 'SER': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['OG']);
if resName == 'THR': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['OG1']);
if resName == 'TRP': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
if resName == 'TYR': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG']);
if resName == 'VAL': # X1
atomList.append(currAtoms['N']);
atomList.append(currAtoms['CA']);
atomList.append(currAtoms['CB']);
atomList.append(currAtoms['CG1']);
angles = angles + getChi(atomList);
return angles;
def getCoord(atom):
''' Convert atom coordinates to numpy array '''
return np.array(atom.get_coord());
def getAngle(angle):
''' Convert -pi ~ pi to 0 to 2*pi '''
if angle < 0:
angle = 360 + angle;
return angle;
def getChi(atomList):
''' Get all chi angles of the side-chain of a residue '''
chi = [];
if len(atomList) < 4:
return chi;
for i in xrange(len(atomList)-3):
chi.append(getAngle(getDihedral([atomList[i], atomList[i+1], atomList[i+2], atomList[i+3]])));
return chi;
def getAtom(atoms, name):
for atom in atoms:
if atom.get_id() == name:
return atom;
def checkResidue(residue, name):
''' Validate residue
Args:
residue (Bio.PDB.Residue), residue
name (string), residue name
Return:
True/False
'''
if not residue.has_id('N'):
return False;
if not residue.has_id('CA'):
return False;
if not residue.has_id('C'):
return False;
if not residue.has_id('O'):
return False;
if name == 'ALA':
if not residue.has_id('CB'):
return False;
if name == 'ARG':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD'):
return False;
if not residue.has_id('NE'):
return False;
if not residue.has_id('CZ'):
return False;
if not residue.has_id('NH1'):
return False;
if not residue.has_id('NH2'):
return False;
if name == 'ASN':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('OD1'):
return False;
if not residue.has_id('ND2'):
return False;
if name == 'ASP':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('OD1'):
return False;
if not residue.has_id('OD2'):
return False;
if name == 'CYS':
if not residue.has_id('CB'):
return False;
if not residue.has_id('SG'):
return False;
if name == 'GLU':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD'):
return False;
if not residue.has_id('OE1'):
return False;
if not residue.has_id('OE2'):
return False;
if name == 'GLN':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD'):
return False;
if not residue.has_id('OE1'):
return False;
if not residue.has_id('NE2'):
return False;
if name == 'HIS':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('ND1'):
return False;
if not residue.has_id('CD2'):
return False;
if not residue.has_id('CE1'):
return False;
if not residue.has_id('NE2'):
return False;
if name == 'ILE':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG1'):
return False;
if not residue.has_id('CG2'):
return False;
if not residue.has_id('CD1'):
return False;
if name == 'LEU':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD1'):
return False;
if not residue.has_id('CD2'):
return False;
if name == 'LYS':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD'):
return False;
if not residue.has_id('CE'):
return False;
if not residue.has_id('NZ'):
return False;
if name == 'MET':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('SD'):
return False;
if not residue.has_id('CE'):
return False;
if name == 'PHE':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD1'):
return False;
if not residue.has_id('CD2'):
return False;
if not residue.has_id('CE1'):
return False;
if not residue.has_id('CE2'):
return False;
if not residue.has_id('CZ'):
return False;
if name == 'PRO':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD'):
return False;
if name == 'SER':
if not residue.has_id('CB'):
return False;
if not residue.has_id('OG'):
return False;
if name == 'THR':
if not residue.has_id('CB'):
return False;
if not residue.has_id('OG1'):
return False;
if not residue.has_id('CG2'):
return False;
if name == 'TRP':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD1'):
return False;
if not residue.has_id('CD2'):
return False;
if not residue.has_id('NE1'):
return False;
if not residue.has_id('CE2'):
return False;
if not residue.has_id('CE3'):
return False;
if not residue.has_id('CZ2'):
return False;
if not residue.has_id('CZ3'):
return False;
if not residue.has_id('CH2'):
return False;
if name == 'TYR':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG'):
return False;
if not residue.has_id('CD1'):
return False;
if not residue.has_id('CD2'):
return False;
if not residue.has_id('CE1'):
return False;
if not residue.has_id('CE2'):
return False;
if not residue.has_id('CZ'):
return False;
if not residue.has_id('OH'):
return False;
if name == 'VAL':
if not residue.has_id('CB'):
return False;
if not residue.has_id('CG1'):
return False;
if not residue.has_id('CG2'):
return False;
return True;
def getCifFiles(directory):
''' Get all cif files in a specific directory
Args:
directory (string), a folder name
Return:
cif file list (generator)
'''
for path, subdirs, files in os.walk(directory):
for name in files:
fileTemp, extension = os.path.splitext(name);
if extension == '.cif':
yield os.path.join(path, name)
def getResidueList():
''' Set a list of target residues
Return:
string list, residue list
'''
#l = ['PHE', 'TRP', 'TYR'];
l = ['ARG', 'ASN', 'ASP', 'CYS', 'GLU', 'GLN', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL'];
return l;
def clearOutputs(l):
for f in l:
os.remove(f+'.csv');
def chain2seq(chain):
seq = [];
for residue in chain:
if is_aa(residue.get_resname(), standard=True):
seq.append(three_to_one(residue.get_resname()))
else:
seq.append("X")
return Seq(str(''.join(seq)), IUPAC.protein)
def processFile(fileName, residueName):
''' Process a specific residue in a cif file
Args:
fileName (string), cif file name
residueName (string), specific residue name
'''
# Get the chains in a protein
chains = getChains(fileName);
chains = list(chains);
# Get the sequences for chains
seqs = []
for chain in chains:
seqs.append(chain2seq(chain));
#print 'Seq: ', len(seqs);
# Calculate identity
seqLen = len(seqs);
similar = set();
for i in range(seqLen-1):
for j in range(i+1, seqLen):
alignments = pairwise2.align.globalxx(seqs[i], seqs[j]);
#print alignments[0][2], alignments[0][4], alignments[0][2]/alignments[0][4];
if alignments[0][2]/alignments[0][4] > 0.95:
similar.add(j);
similar = list(similar);
#print 'Similar list: ', similar
# Choose the chains without above 95% similarity
c = [];
for i, chain in enumerate(chains):
if i not in similar:
c.append(chain);
chains = c;
print '# of chains: ', len(chains);
# Process each chain in the protein
for chain in chains:
residues = getResidues(chain);
getRotamer(residues, residueName);
#break; # process the first chain in a protein model
def main(residueName):
''' Generate dihedral angles for a specific residue
Args:
residueName (string), target residue
'''
# Get all cif files in a directory
cifFiles = getCifFiles(sys.argv[1]);
count = 0;
for cifFile in cifFiles:
count += 1;
print str(count)+'th: '+cifFile;
try:
processFile(cifFile, residueName);
except Exception, e:
print str(e);
if __name__ == '__main__':
''' Generate the distance between CA and side-chain centre, dihedral angles for each residue
python singleChain.py dirName
'''
l = getResidueList();# get the target residue list
for r in l:
main(r);