-
Notifications
You must be signed in to change notification settings - Fork 0
/
d_orientation.py
executable file
·2167 lines (1873 loc) · 77.1 KB
/
d_orientation.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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: justin
"""
import time
## set timer
time_start = time.time()
##load mandatory modules
import numpy as np
import argparse, sys
#import scipy as sc
import gemmi
mesh = 0.10
label_H="D"
##input variables:
parser=argparse.ArgumentParser()
parser.add_argument('--pdb', help='input pdb file')
parser.add_argument('--map', help='input ccp4 map')
parser.add_argument('--out', help='output file')
parser.add_argument('--wat', help='protonate water, yes or no')
args=parser.parse_args()
## process input
if args.pdb != None:
input_pdb=args.pdb
print("input pdb file is:", input_pdb)
else:
input_pdb="pdb"
print("input pdb file is:", input_pdb)
if args.map != None:
input_grid=args.map
map_ex=True
print("read from ", input_grid)
else:
input_grid="None"
map_ex= False
print("read from defalt ", input_grid)
if args.out != None:
out_file=args.out
print("output_file ",out_file)
else:
out_file="results"
print("default out_file ", out_file)
if args.wat != None:
wat=args.wat
if wat=="yes":
wat_ex=True
print("water is getting protonatet")
else:
wat_ex=False
print("water is not getting protonatet")
else:
wat_ex=False
print("water is not getting protonatet")
## reading and writeing rotines
def read_pdb(input_pdb):
## reads in pdb coordinates hardcodedt
##https://zhanglab.ccmb.med.umich.edu/BindProfX/pdb_atom_format.html
##COLUMNS DATA TYPE CONTENTS
##--------------------------------------------------------------------------------
##1 - 6 Record name "ATOM "
## 7 - 11 Integer Atom serial number.
##13 - 16 Atom Atom name.
##17 Character Alternate location indicator.
##18 - 20 Residue name Residue name.
##22 Character Chain identifier.
##23 - 26 Integer Residue sequence number.
##27 AChar Code for insertion of residues.
##31 - 38 Real(8.3) Orthogonal coordinates for X in Angstroms.
##39 - 46 Real(8.3) Orthogonal coordinates for Y in Angstroms.
##47 - 54 Real(8.3) Orthogonal coordinates for Z in Angstroms.
##55 - 60 Real(6.2) Occupancy.
##61 - 66 Real(6.2) Temperature factor (Default = 0.0).
##73 - 76 LString(4) Segment identifier, left-justified.
##77 - 78 LString(2) Element symbol, right-justified.
##79 - 80 LString(2) Charge on the atom.
print(" read pdb file")
read_pdb = open(input_pdb, "r")
org_pdb =[]
work_pdb =[]
for line in read_pdb:
idef = line[0:6].strip()
if idef=="ATOM" or idef=="HETATM":
l_pdb=[]
a = line[0:6].strip()
a_num = int(line[6:11].strip())
a_name = line[12:16].strip()
alter = line[16].strip()
res_name= line[17:20].strip()
chain = line[21].strip()
res_num = int(line[22:26].strip())
inser = line[26].strip()
x = float(line[30:38].strip())
y = float(line[38:46].strip())
z = float(line[46:54].strip())
occ = float(line[54:60].strip())
b_fac = float(line[60:66].strip())
seg_i = line[72:76].strip()
ele = line[76:78].strip()
charge = line[78:80].strip()
l_pdb.append(a)
l_pdb.append(a_num)
l_pdb.append(a_name)
l_pdb.append(alter)
l_pdb.append(res_name)
l_pdb.append(chain)
l_pdb.append(res_num)
l_pdb.append(inser)
l_pdb.append(x)
l_pdb.append(y)
l_pdb.append(z)
l_pdb.append(occ)
l_pdb.append(b_fac)
l_pdb.append(seg_i)
l_pdb.append(ele)
l_pdb.append(charge)
#[0, 1 , 2 , 3 , 4 , 5 , 6, , 7 , 8, 9,10
#[a, a_num, a_name, alter, res_name, chain, res_num, inser, x, y, z
#11 , 12 , 13 , 14 , 15
#occ, b_fac, seg_i, ele, charge]
org_pdb.append(l_pdb)
work_pdb.append(l_pdb)
# print(l_pdb)
print("close file:", input_pdb)
return org_pdb, work_pdb
def atm_to_res(pdb_read):
## change pdb from list of atoms to list of res with atoms
pdb=[]
pdb.append([pdb_read[0]])
for i in range(1,len(pdb_read)):
if pdb_read[i][6] != pdb_read[i-1][6]:
pdb.append([pdb_read[i]])
if pdb_read[i][6] == pdb_read[i-1][6]:
pdb[len(pdb)-1].append(pdb_read[i])
return pdb
def read_grid(input_grid):
#read ccp4 map with gemmi
print(input_grid)
map= gemmi.read_ccp4_map(input_grid)
print(gemmi.InfoMap())
# print("head",map.header_str)
print(map.__repr__())
# print(help(map))
print(" map is readet")
return map
def write_pdb(pdb, output):
#writes out final pdb file with D atoms
res = open(output, "w")
atm_nr=0
for i in range(len(pdb)):
for k in range(len(pdb[i])):
atm_nr = atm_nr + 1
string = str('{:6}'.format(pdb[i][k][0]))
string = string + str('{:5.0f}'.format(atm_nr))
string = string + " "
string = string + str('{:4s}'.format(str(pdb[i][k][2])))
string = string + str('{:1}'.format(pdb[i][k][3]))
string = string + str('{:3}'.format(pdb[i][k][4]))
string = string + str('{:>2}'.format(pdb[i][k][5]))
string = string + str('{:4}'.format(pdb[i][k][6]))
string = string + str('{:1}'.format(pdb[i][k][7]))
string = string + " "
string = string + str('{:8.4f}'.format(pdb[i][k][8]))
string = string + str('{:8.4f}'.format(pdb[i][k][9]))
string = string + str('{:8.4f}'.format(pdb[i][k][10]))
string = string + str('{:6.2f}'.format(pdb[i][k][11]))
string = string + str('{:6.2f}'.format(pdb[i][k][12]))
string = string + str('{:>10}'.format(pdb[i][k][13]))
string = string + str('{:>2}'.format(pdb[i][k][14]))
string = string + "\n"
res.write(string)
## work on pdb file
def treat_res(pdb,map):
#work on each residio seperatly
alerts=[["CH"],["NH"],["OH"],["SH"],["flip"],["wat"],["disordert"],[]]
# alerts =[CH,NH,OH,SH,flip]
# pdb, alerts = treat_n_nerm(pdb,map,alerts)
for res_num in range(len(pdb)):
# print("res",pdb[res_num][0][6])
if pdb[res_num][0][4]=="GLY":
pdb, alerts = treat_GLY( pdb, res_num,alerts )
if pdb[res_num][0][4]=="PRO":
pdb, alerts = treat_PRO( pdb, res_num , alerts)
if pdb[res_num][0][4]=="PHE":
pdb, alerts = treat_PHE( pdb, res_num, alerts )
if pdb[res_num][0][4]=="ALA":
pdb, alerts = treat_ALA( pdb, res_num, alerts )
if pdb[res_num][0][4]=="VAL":
pdb, alerts = treat_VAL( pdb, res_num, alerts )
if pdb[res_num][0][4]=="LEU":
pdb, alerts = treat_LEU( pdb, res_num, alerts )
if pdb[res_num][0][4]=="ILE":
pdb, alerts = treat_ILE( pdb, res_num, alerts )
if pdb[res_num][0][4]=="MET":
pdb, alerts = treat_MET( pdb, res_num, alerts )
if pdb[res_num][0][4]=="ARG":
pdb, alerts = treat_ARG( pdb, res_num, alerts )
if pdb[res_num][0][4]=="TRP":
pdb, alerts = treat_TRP( pdb, res_num, alerts )
if pdb[res_num][0][4]=="ASN":
pdb, alerts = treat_ASN( pdb, res_num,map, alerts )
if pdb[res_num][0][4]=="GLN":
pdb, alerts = treat_GLN(pdb,res_num, map, alerts)
if pdb[res_num][0][4]=="ASP":
pdb, alerts = treat_ASP( pdb, res_num,map, alerts )
if pdb[res_num][0][4]=="GLU":
pdb, alerts = treat_GLU( pdb, res_num,map, alerts )
if pdb[res_num][0][4]=="HIS" or pdb[res_num][0][4]=="HID" or \
pdb[res_num][0][4]=="HIE" or pdb[res_num][0][4]=="HIP" :
pdb, alerts = treat_HIS(pdb,res_num, map, alerts)
if pdb[res_num][0][4]=="LYS":
pdb, alerts = treat_LYS( pdb, res_num, map, alerts )
if pdb[res_num][0][4]=="SER":
pdb, alerts = treat_SER( pdb, res_num ,map, alerts)
if pdb[res_num][0][4]=="THR":
pdb, alerts = treat_THR( pdb, res_num ,map, alerts)
if pdb[res_num][0][4]=="TYR":
pdb, alerts = treat_TYR( pdb, res_num ,map, alerts)
if pdb[res_num][0][4]=="CYS":
pdb, alerts = treat_CYS( pdb, res_num, map, alerts )
if pdb[res_num][0][4]=="WAT" or pdb[res_num][0][4]=="HOH":
pdb, alerts = treat_WAT( pdb, res_num,map, alerts )
return pdb, alerts
######################################################
##All H well-defined
######################################################
def treat_GLY(pdb, res_num,alerts):
## add deteria to GLY
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
# print(pdb[res_num])
pdb = ad_CH2(pdb, res_num,alter,"N","C","CA")
return pdb, alerts
def treat_PRO(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at PRO
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH2(pdb, res_num,alter,"CD","CB","CG")
pdb = ad_CH2(pdb, res_num,alter,"N","CG","CD")
return pdb, alerts
def treat_PHE(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at PHE
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH_ar(pdb, res_num,alter,"CG","CE2","CD2")
pdb = ad_CH_ar(pdb, res_num,alter,"CD2","CZ","CE2")
pdb = ad_CH_ar(pdb, res_num,alter,"CG","CE1","CD1")
pdb = ad_CH_ar(pdb, res_num,alter,"CD1","CZ","CE1")
pdb = ad_CH_ar(pdb, res_num,alter,"CE2","CE1","CZ")
return pdb, alerts
##############################################################
##CH3 in principle free, but uninteresting
#############################################################
def treat_ALA(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at ALA
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH3(pdb, res_num,alter,"C","CA","CB")
return pdb, alerts
def treat_VAL(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at VAL
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH_R3(pdb, res_num,alter,"CG2","CG1","CB","CA")
pdb = ad_CH3(pdb, res_num,alter,"CA","CB","CG1")
pdb = ad_CH3(pdb, res_num,alter,"CA","CB","CG2")
return pdb, alerts
def treat_LEU(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at LEU
alter, alerts = find_alter(pdb,res_num,alerts)
# print("ALTER",alter)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH_R3(pdb, res_num,alter,"CD2","CD1","CG","CB")
pdb = ad_CH3(pdb, res_num,alter,"CB","CG","CD1")
pdb = ad_CH3(pdb, res_num,alter,"CB","CG","CD2")
return pdb, alerts
def treat_ILE(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at ILE
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH_R3(pdb, res_num,alter,"CG2","CG1","CB","CA")
pdb = ad_CH3(pdb, res_num,alter,"CA","CB","CG2")
pdb = ad_CH2(pdb, res_num,alter,"CD1","CB","CG1")
pdb = ad_CH3(pdb, res_num,alter,"CB","CG1","CD1")
return pdb, alerts
def treat_MET(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at MET
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH2(pdb, res_num,alter,"SD","CB","CG")
pdb = ad_CH3(pdb, res_num,alter,"CG","SD","CE")
return pdb, alerts
##############################################################
##All H well-defined
##############################################################
def treat_ARG(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at ARG
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH2(pdb, res_num,alter,"CD","CB","CG")
pdb = ad_CH2(pdb, res_num,alter,"CB","NE","CD")
pdb = ad_NH_s(pdb, res_num,alter,"CZ","CD","NE")
pdb = ad_NH2(pdb, res_num,alter,"NE","CZ","NH1")
pdb = ad_NH2(pdb, res_num,alter,"NE","CZ","NH2")
return pdb, alerts
##############################################################
## 1 well-defined H
##############################################################
def treat_TRP(pdb,res_num, alerts):
# ad hydrogen to standard psoitions at TRP
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH_ar(pdb, res_num,alter,"CG","NE1","CD1")
pdb = ad_NH_s(pdb, res_num,alter,"CE2","CD1","NE1")
pdb = ad_CH_ar(pdb, res_num,alter,"CZ3","CD2","CE3")
pdb = ad_CH_ar(pdb, res_num,alter,"CE3","CH2","CZ3")
pdb = ad_CH_ar(pdb, res_num,alter,"CZ3","CZ2","CH2")
pdb = ad_CH_ar(pdb, res_num,alter,"CE2","CH2","CZ2")
return pdb, alerts
##############################################################
## Flip possible
##############################################################
def treat_ASN(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at ASN and checks if O and N are
# fliped
alter, alerts = find_alter(pdb,res_num,alerts)
# print("Alter",alter)
if map_ex==True:
pdb,alerts = check_flip(pdb,res_num,alter,map,"ND2","OD1",alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num, alter,"CA","CG","CB")
pdb = ad_NH2(pdb, res_num,alter,"CB","CG","ND2")
return pdb, alerts
def treat_GLN(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at GLN
# print("GLN!",pdb[res_num][0])
alter, alerts = find_alter(pdb,res_num,alerts)
if map_ex==True:
pdb,alerts = check_flip(pdb,res_num,alter,map,"NE2","OE1",alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH2(pdb, res_num,alter,"CD","CB","CG")
pdb = ad_NH2(pdb, res_num,alter,"CG","CD","NE2")
return pdb, alerts
#rotines for flip in ANS and GLN
def check_flip(pdb,res_num,alter,map,N,O,alerts):
#checks if HIS is fliped based on the map
#for this the map is integratet around CD2, CE1 and ND1, NE2. If the sum of the integrated values for carbon are smaller than for nitrogen the HIS is getting flipped.
for alt in range(len(alter)):
com=ceck_bond_atoms_2(pdb,res_num,alter[alt],N,O)
if com==False:
continue
N_coord=anam_to_coord(pdb,res_num,alter[alt],N)
O_coord=anam_to_coord(pdb,res_num,alter[alt],O)
int_N=int_around_point(N_coord,map,def_r_int("N"),mesh)
int_O=int_around_point(O_coord,map,def_r_int("N"),mesh)
# print("sum_C", sum_C)
# print("sum_N", sum_N)
if int_O > int_N:
# print(alter[alt])
# print(pdb[res_num][0])
# print(pdb[res_num][1])
print("N and C are getting fliped for" ,pdb[res_num][0][5],pdb[res_num][0][4],pdb[res_num][0][6])
pdb = del_NH2(pdb,res_num, alter[alt],N_coord)
string = str(pdb[res_num][0][4])+" "+str(pdb[res_num][0][6])+" "+str(pdb[res_num][0][5])+" got flipped"
alerts[4].append(string)
for i in range(len(pdb[res_num])):
if pdb[res_num][i][3]==alter[alt]:
if pdb[res_num][i][2]==N:
# print("¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤")
# print(pdb[res_num][i][8],pdb[res_num][i][9],pdb[res_num][i][10])
pdb[res_num][i][8]=O_coord[0]
pdb[res_num][i][9]=O_coord[1]
pdb[res_num][i][10]=O_coord[2]
# print(pdb[res_num][i][8],pdb[res_num][i][9],pdb[res_num][i][10])
# print("##################")
if pdb[res_num][i][2]==O:
pdb[res_num][i][8]=N_coord[0]
pdb[res_num][i][9]=N_coord[1]
pdb[res_num][i][10]=N_coord[2]
# print(pdb[res_num][i])
return pdb, alerts
def ceck_bond_atoms_2(pdb,res_num,alt, A1, A2):
## cecks if all needet atoms to ad a D are existing in residue
com = True
res = []
for i in range(len(pdb[res_num])):
# print(len(list(pdb[res_num][i][3])))
if pdb[res_num][i][3]==alt or\
len(list(pdb[res_num][i][3]))==0:
# print(pdb[res_num][i][3],len(list(pdb[res_num][i][3])))
res.append(pdb[res_num][i][2])
elif len(list(alt))==0:
if pdb[res_num][i][3]=="A":
res.append(pdb[res_num][i][2])
# print("A1, A2, A3",A1, A2, A3)
# print("res",res)
if A1 not in res or A2 not in res:
com=False
return com
def del_NH2(pdb,res_num,alt,A_coord):
##find CH bond du A3
# H_coord=[]
ele1="N"
atom1=A_coord
cov1=ele_to_cov_rad(ele1)
for i in range(len(pdb[res_num])):
if pdb[res_num][i][3]==alt or len(list(pdb[res_num][i][3]))==0:
atom2 =np.array([pdb[res_num][i][8],pdb[res_num][i][9],pdb[res_num][i][10]])
ele2 = pdb[res_num][i][14]
cov2=ele_to_cov_rad(ele2)
d = CDist2(atom1,atom2)
dmax= cov1+cov2+0.4
if 0.5 <= d <= dmax:
if pdb[res_num][i][14] == "H" or pdb[res_num][i][14]=="D":
del pdb[res_num][i]
return pdb
##############################################################
## No on charged, 4 posible position on neutral
##############################################################
def treat_ASP(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at ASP and chek if it is
# protonatet or unprotonatet based on the mp
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
if map_ex==True:
av_CH, std_CH= int_CH(pdb,res_num,alter,map,mesh)
pdb,alerts = ad_CO2H_map(pdb, res_num,alter,map,"OD1", "CG","OD2",av_CH, std_CH, alerts)
return pdb, alerts
def treat_GLU(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at GLU
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH2(pdb, res_num,alter,"CD","CB","CG")
if map_ex==True:
av_CH, std_CH= int_CH(pdb,res_num,alter,map,mesh)
pdb,alerts=ad_CO2H_map(pdb,res_num,alter,map,"OE1","CD","OE2",av_CH, std_CH,alerts)
return pdb, alerts
def ad_CO2H_map(pdb, res_num,alter,map, A1, A2, A3,av_CH,std_CH,alerts):
# chekc if CO2- group is protonatet
for alt in range(len(alter)):
com = check(pdb,res_num, alter[alt],A1, A2, A3, 2)
if com == False:
return pdb
r = 0.997
Ad_l=[106.2,114.9]
Dd_l=[0,180]
A1xyz = anam_to_coord(pdb,res_num,alter[alt],A1)
A2xyz = anam_to_coord(pdb,res_num,alter[alt],A2)
A3xyz = anam_to_coord(pdb,res_num,alter[alt],A3)
H_coords=[]
for k in range(len(Dd_l)):
H_coords.append([ZtoXYZ(A1xyz,A2xyz,A3xyz,r,Ad_l[k],Dd_l[k]),A3])
H_coords.append([ZtoXYZ(A3xyz,A2xyz,A1xyz,r,Ad_l[k],Dd_l[k]),A1])
r_int=def_r_int("H")
int_H_l=[]
for k in range(len(H_coords)):
int_H_l.append([H_coords[k][0],int_around_point(H_coords[k][0],map,r_int,mesh),H_coords[k][1]])
test_H=[0,0,0]
# print("int_H_l",int_H_l)
for i in range(len(int_H_l)):
if int_H_l[i][1]> test_H[1]:
test_H[0]=int_H_l[i][0]
test_H[1]=int_H_l[i][1]
test_H[2]=int_H_l[i][2]
# print("av_CH std_CH test_H[1]",av_CH, std_CH, test_H[1])
if (av_CH -1*std_CH) <= test_H[1] and test_H[1]> 0:
# print("test_H[2]",test_H[1],av_CH,std_CH)
nam=list(test_H[2])
if len(nam)<=2:
name=nam[1]
else:
name = nam[1]#+nam[2]
name1 = label_H+name+"2"
# name1 ="H"+test_H[2]
# print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!",nam[2],"######################################")
pdb = add_to_pdb(pdb,res_num,alter[alt], test_H[2], test_H[0], name1,test_H[1])
#
if nam[2]=="1":
for i in range(len(pdb[res_num])):
if pdb[res_num][i][2]==A1 and pdb[res_num][i][3]==alter[alt]:
O1=i
if pdb[res_num][i][2]==A3 and pdb[res_num][i][3]==alter[alt]:
O2=i
pdb[res_num][O1][2]=A3
pdb[res_num][O2][2]=A1
print(name1 ,"is addet to ",test_H[2],res_num)
string=str(name1)+" is addet to "+str(pdb[res_num][0][4])+" "+str(pdb[res_num][0][6])+" "+str(pdb[res_num][0][5])
alerts[2].append(string)
# else:
# string=str(pdb[res_num][0][4])+" "+str(pdb[res_num][0][6])+" "+str(pdb[res_num][0][5])+" is charged"
# alerts[2].append(string)
return pdb, alerts
##############################################################
## Hid, Hie, Hip and flip
##############################################################
def treat_HIS(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at HIS
alter, alerts = find_alter(pdb,res_num,alerts)
if map_ex==True:
pdb,alerts =check_flip_HIS(pdb,res_num,alter,map,alerts)
proto = pdb[res_num][0][4]
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH_ar(pdb, res_num,alter,"ND1","NE2","CE1")
pdb = ad_CH_ar(pdb, res_num,alter,"CG","NE2","CD2")
if map_ex==True:
av_CH,sig_CH= int_CH(pdb,res_num,alter,map,mesh)
pdb,alerts = ad_NH_s_map(pdb, res_num,alter,map,"CE1","CD2","NE2",av_CH,sig_CH,alerts)
pdb,alerts = ad_NH_s_map(pdb, res_num,alter,map,"CE1","CG","ND1",av_CH,sig_CH,alerts)
else:
if proto == "HIS" or\
proto == "HIE" or proto == "HIP":
pdb = ad_NH_s(pdb, res_num,alter,"CE1","CD2","NE2")
if proto == "HID" or proto == "HIP":
pdb = ad_NH_s(pdb, res_num,alter,"CE1","CG","ND1")
return pdb, alerts
##############################################################
## 3 H on a ring; may be deprotonated
##############################################################
def treat_LYS(pdb,res_num, map, alerts):
# ad hydrogen to standard psoitions at LYS
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","CG","CB")
pdb = ad_CH2(pdb, res_num,alter,"CD","CB","CG")
pdb = ad_CH2(pdb, res_num,alter,"CE","CG","CD")
pdb = ad_CH2(pdb, res_num,alter,"NZ","CD","CE")
if map_ex==True:
av_CH,sig_CH= int_CH(pdb,res_num,alter,map,mesh)
pdb = ad_NH3_map(pdb,res_num,alter,"CD","CE","NZ",map,av_CH,sig_CH)
else:
pdb = ad_NH3(pdb, res_num,alter,"CD","CE","NZ")
return pdb, alerts
def treat_n_nerm(pdb,map,alerts):
## protonates NH3 as Nterminal
res_num=0
alter, alerts = find_alter(pdb,res_num,alerts)
if map_ex==True:
pdb = ad_NH3_map_ter(pdb,res_num,alter,"C","CA","N",map)
else:
pdb = ad_NH3(pdb, res_num,alter,"C","CA","N")
return pdb, alerts
##############################################################
## 1 H on a ring
##############################################################
def treat_SER(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at SER
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","OG","CB")
if map_ex==True:
pdb, alerts = ad_OH_map(pdb, res_num,alter,"CA","CB","OG",map, alerts)
else:
pdb = ad_OH(pdb, res_num,alter,"CA","CB","OG")
return pdb, alerts
def treat_THR(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at THR
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH_R3(pdb, res_num,alter,"CG2","OG1","CB","CA")
pdb = ad_CH3(pdb, res_num,alter,"CA","CB","CG2")
if map_ex==True:
pdb, alerts = ad_OH_map(pdb, res_num,alter,"CA","CB","OG1",map, alerts)
else:
pdb = ad_OH(pdb, res_num,alter,"CA","CB","OG1")
return pdb, alerts
def treat_TYR(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at TYR
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num, alter,"CA","CG","CB")
pdb = ad_CH_ar(pdb, res_num,alter,"CE2","CG","CD2")
pdb = ad_CH_ar(pdb, res_num,alter,"CZ","CD2","CE2")
pdb = ad_CH_ar(pdb, res_num,alter,"CD1","CZ","CE1")
pdb = ad_CH_ar(pdb, res_num,alter,"CG","CE1","CD1")
if map_ex==True:
pdb, alerts = ad_OH_map(pdb, res_num,alter,"CE1","CZ","OH",map, alerts)
else:
pdb = ad_OH(pdb, res_num,alter,"CE1","CZ","OH")
return pdb, alerts
##############################################################
## 1 H on a ring; may be deprotonated
##############################################################
def treat_CYS(pdb,res_num, map, alerts):
# ad hydrogen to standard psoitions at CYS
alter, alerts = find_alter(pdb,res_num,alerts)
pdb = ad_NH(pdb,res_num,alter)
pdb = ad_CH_R3(pdb, res_num,alter,"C","N","CA","CB")
pdb = ad_CH2(pdb, res_num,alter,"CA","SG","CB")
if map_ex==True:
pdb, alerts = ad_SH_map(pdb, res_num,alter,"CA","CB","SG",map,alerts)
else:
pdb = ad_SH(pdb, res_num,alter,"CA","CB","SG")
return pdb, alerts
##############################################################
## 2 H on a sphere
##############################################################
def treat_WAT(pdb,res_num,map, alerts):
# ad hydrogen to standard psoitions at WAT
if map_ex==True and wat_ex==True:
alter, alerts = find_alter(pdb,res_num,alerts)
print("alter",alter)
sphere=def_sphere(0.98, 20)
r_int=def_r_int("H")
coord_O=[pdb[res_num][0][8],pdb[res_num][0][9],pdb[res_num][0][10]]
# print(pdb[res_num])
# print(coord_O)
int_sphere_l=int_sphere(sphere,map,coord_O,r_int)
best_fit=find_best_fit(int_sphere_l,coord_O)
if best_fit[2]<= best_fit[0][2]:
print("integratet value is to small hydrogens are not aded")
return pdb , alerts
print("best_fit","sum",best_fit[2],"H1",best_fit[0][1],"H2",best_fit[1][1],"O",best_fit[0][2])
pdb = add_to_pdb(pdb,res_num,alter[0], "O", best_fit[0][0], "H2",best_fit[1][1])
pdb = add_to_pdb(pdb,res_num,alter[0], "O", best_fit[1][0], "H1",best_fit[0][1])
return pdb, alerts
def find_best_fit(l_int, coord_O):
# finds atom pair with best fit in 104,5 +- 5 degree
pairs=[]
# bes_fit=[]
g_opt=104.5
g_sig=10
int_sum=-1000
for i in range(len(l_int)):
v1=twoP_to_vec(coord_O,l_int[i][0])
for k in range(i,len(l_int)):
v2=twoP_to_vec(coord_O,l_int[k][0])
ang=C2Angle(v1,v2)
if g_opt-g_sig <= ang <= g_opt+g_sig:
pairs.append([l_int[i],l_int[k],l_int[i][1]+l_int[k][1]])
print("len(pairs)",len(pairs))
for i in range(len(pairs)):
if int_sum < pairs[i][2]:
int_sum=pairs[i][2]
best_fit=pairs[i]
return best_fit
def int_sphere(sphere,map,coord_O,r_int):
#integrates for all points in list sphere on map
int_sphere_l=[]
# r_int_O=ele_to_cov_rad("O")
int_O=int_around_point(coord_O,map,r_int, mesh)
for i in range(len(sphere)):
H=[sphere[i][0]+coord_O[0],sphere[i][1]+coord_O[1],sphere[i][2]+coord_O[2]]
int_H=int_around_point(H,map,r_int, mesh)
int_sphere_l.append([H,int_H,int_O])
return int_sphere_l
def def_sphere(r,deg):
#defines sphere wit radius r around 0,0,0
sphere=[]
for teth in range(0,180,deg):
for phi in range(0,360,deg):
x=r*np.sin(np.radians(teth))*np.cos(np.radians(phi))
y=r*np.sin(np.radians(teth))*np.sin(np.radians(phi))
z=r*np.cos(np.radians(teth))
sphere.append([x,y,z])
print("len(sphere)",len(sphere))
return sphere
## rotiens to work on residues
def find_alter(pdb,res_num,alerts):
## finds alternative conformations in residue
alter=[]
for i in range(len(pdb[res_num])):
alter.append(pdb[res_num][i][3])
alter=list(dict.fromkeys(alter))
if len(alter)>=2:
string=str(pdb[res_num][0][4])+" "+str(pdb[res_num][0][6])+" "+str(pdb[res_num][0][5])+" is disordert"
alerts[6].append(string)
# print("alter",alter)
return alter, alerts
def ad_NH(pdb,res_num,alter):
## ad HN if a naiboring resiue is existing
# print("ad_NH_print alter",alter,pdb[res_num][0][6])
for alt in range(len(alter)):
# res=pdb[res_num][0][6]
## print("RES",res)
# for i in range(len(pdb)):
# for k in range(len(pdb[res_num])):
# if pdb[i][k][6]== res-1 and pdb[i][k][2].strip()=="C" and pdb[res_num][0][5]==pdb[i][k][5]:
com = ceck_bond_atoms_N(pdb,res_num,res_num,alter[alt],"N","CA", "C")
# if len(alter)>1:
# print("alter[alt],com",alter[alt],com)
if com == False:
print("missing atoms to locate NH")
return pdb
# print(pdb[res_num])
# print("alter,res:num", alter[alt],res_num)
# nr_b=nr_bonds(pdb,res_num,alter[alt],"N")
# ext_H=False
# print("alter",alter)
ext_H=check_extH_N(pdb,res_num,"N",alter[alt])
if ext_H == True:
print("NH not, H is already existing!!!!!!!!!!!!!!!!")
# print("at residue",pdb[res_num][0][6])
# if alter[alt]=="B":
# print("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")
# print("Res_num",pdb[i][k][6])
return pdb
int_H=0
Nxyz = anam_to_coord(pdb,res_num,alter[alt],"N")
# print(pdb[res_num])
CAxyz = anam_to_coord(pdb,res_num,alter[alt],"CA")
Cxyz = anam_to_coord(pdb,res_num-1,alter[alt],"C")
r=1.016
Ad=117.7
Dd=180
# if alter[alt]=="B":
# print("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")
# print("Res_num",pdb[i][k][6])
# if alter[alt]=="A":
# print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
# print("res:num",pdb[i][k][6])
H = ZtoXYZ(Cxyz,CAxyz,Nxyz,r,Ad,Dd)
if map_ex==True:
int_H=int_around_point(H,map,def_r_int("H"), mesh)
pdb = add_to_pdb(pdb,res_num,alter[alt],"N",H,label_H,int_H)
return pdb
def check_extH_N(pdb,res_num,atom,alt):
# cheks if H of NH is existing
ext=False
atom1, ele1 =anam_to_coord_ele(pdb,res_num,alt,atom)
cov1=ele_to_cov_rad(ele1)
# print("atom1, ele1",atom1, ele1,alt)
# print("find NH ex", pdb[res_num][0])
for i in range(len(pdb[res_num])):
if pdb[res_num][i][3]==alt:# or len(list(pdb[res_num][i][3]))==0:
# print(alt)
# print("test alt",alt)
if pdb[res_num][i][14]=="H" or pdb[res_num][i][14]=="D":
atom2 =np.array([pdb[res_num][i][8],pdb[res_num][i][9],pdb[res_num][i][10]])
ele2 = pdb[res_num][i][14]
cov2=ele_to_cov_rad(ele2)
d = CDist2(atom1,atom2)
dmax= cov1+cov2+0.4
if 0.5 <= d <= dmax:
ext=True
# print("ATOM2", pdb[res_num][i])
return ext
def ad_CA(pdb,res_num,alter):
#add HCA at standard positons
for alt in range(len(alter)):
com= check(pdb,res_num,alter[alt],"C","N","CA", 3)
print("ALTER",alter)
print("len(alter",len(alter))
if len(alter)>1:
print("alter,com,QQQQQQQQQQQQ", alter,com)
if com == False:
return pdb
if len(alter)>1:
print("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ")
CAxyz = anam_to_coord(pdb,res_num,alter[alt],"CA")
Nxyz = anam_to_coord(pdb,res_num,alter[alt],"N")
Cxyz = anam_to_coord(pdb,res_num,alter[alt],"C")
r = 1.095
Ad = 109
Dd= -121.5
HCA = ZtoXYZ(Nxyz,Cxyz,CAxyz,r,Ad,Dd)
int_H=0
if map_ex==True:
int_H=int_around_point(HCA,map,def_r_int("H"), mesh)
pdb = add_to_pdb(pdb,res_num,alter[alt],"CA",HCA,"HA",int_H)
return pdb
def ad_CH3(pdb, res_num,alter, A1, A2, A3):
# ad 3H as CH3 group to A3
for alt in range(len(alter)):
# print("alter[alt]",alter[alt])
com = check(pdb,res_num,alter[alt],A1, A2, A3, 1)
# print(com)
if com == False:
return pdb
# print( pdb[res_num])
# print("A2", A2)
r = 1.095
Ad = 109
Dd = 180
Dd1 = 60
A1xyz = anam_to_coord(pdb,res_num,alter[alt],A1)
A2xyz = anam_to_coord(pdb,res_num,alter[alt],A2)
A3xyz = anam_to_coord(pdb,res_num,alter[alt],A3)
adH1 = ZtoXYZ(A1xyz,A2xyz,A3xyz,r,Ad,Dd)
adH2 = ZtoXYZ(A1xyz,A2xyz,A3xyz,r,Ad,Dd1)
adH3 = ZtoXYZ(A1xyz,A2xyz,A3xyz,r,Ad,-Dd1)
nam=list(A3)
if len(nam)<=2:
name=nam[1]
else:
name = nam[1]+nam[2]
name1 = label_H+name+"1"
name2 = label_H+name+"2"
name3 = label_H+name+"3"
int_H1=int_H2=int_H3=0
if map_ex==True:
int_H1=int_around_point(adH1,map,def_r_int("H"), mesh)
int_H2=int_around_point(adH2,map,def_r_int("H"), mesh)
int_H3=int_around_point(adH3,map,def_r_int("H"), mesh)
# print("adH1",adH1)
pdb = add_to_pdb(pdb,res_num,alter[alt], A3, adH1, name1,int_H1)
pdb = add_to_pdb(pdb,res_num,alter[alt], A3, adH2, name2,int_H2)
pdb = add_to_pdb(pdb,res_num,alter[alt], A3, adH3, name3,int_H3)
return pdb
def ad_NH3(pdb, res_num,alter, A1, A2, A3):
# ad 3H as NH3+ group to A3
for alt in range(len(alter)):
com = check(pdb,res_num,alter[alt],A1, A2, A3, 1)
if com == False:
return pdb
# print( pdb[res_num])
# print("A2", A2)
r = 1.019
Ad = 109
Dd = 180
Dd1 = 60
A1xyz = anam_to_coord(pdb,res_num,alter[alt],A1)
A2xyz = anam_to_coord(pdb,res_num,alter[alt],A2)
A3xyz = anam_to_coord(pdb,res_num,alter[alt],A3)
adH1 = ZtoXYZ(A1xyz,A2xyz,A3xyz,r,Ad,Dd)
adH2 = ZtoXYZ(A1xyz,A2xyz,A3xyz,r,Ad,Dd1)
adH3 = ZtoXYZ(A1xyz,A2xyz,A3xyz,r,Ad,-Dd1)
nam=list(A3)
if len(nam)<=2:
name=nam[1]
else:
name = nam[1]+nam[2]
name1 = label_H+name+"1"
name2 = label_H+name+"2"
name3 = label_H+name+"3"
int_H1=int_H2=int_H3=0
if map_ex==True:
int_H1=int_around_point(adH1,map,def_r_int("H"), mesh)
int_H2=int_around_point(adH2,map,def_r_int("H"), mesh)
int_H3=int_around_point(adH3,map,def_r_int("H"), mesh)
pdb = add_to_pdb(pdb,res_num,alter[alt], A3, adH1, name1,int_H1)
pdb = add_to_pdb(pdb,res_num,alter[alt], A3, adH2, name2,int_H2)
pdb = add_to_pdb(pdb,res_num,alter[alt], A3, adH3, name3,int_H3)
return pdb
def ad_NH3_map(pdb, res_num,alter, A1, A2, A3,map,av_CH,sig_CH):
# ad 3H as NH3+ group to A3
for alt in range(len(alter)):
com = check(pdb,res_num,alter[alt],A1, A2, A3, 1)
if com == False:
return pdb
# print( pdb[res_num])
# print("A2", A2)
r = 1.019
Ad = 109
Dd = 180
r_int=def_r_int("H")
A1xyz = anam_to_coord(pdb,res_num,alter[alt],A1)
A2xyz = anam_to_coord(pdb,res_num,alter[alt],A2)