-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlscore.py
2478 lines (2046 loc) · 146 KB
/
dlscore.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
#######################################################################
# DLSCORE.py #
# #
# First version of DLSCORE #
# Required deep learning libraries: Tensorflow and Keras #
# #
# Output: A list of dictionaries #
# #
# To run in a terminal, type "python dlscore.py -h" for options. #
# #
# To run within a script: #
# from dlscore import * #
# ds = dlscore(ligand='ligand_file.pdbqt', #
# receptor='protein_file.pdbqt', #
# vina_executable='vina exectuable file' #
# nb_nets = 2 (Optional. Default value is 10)) #
# output = ds.get_output() #
# #
# Author: Mahmudulla Hassan #
# Department of Computer Science and School of Pharmacy #
# The University of Texas at El Paso, TX, USA #
# Last modified: 06/06/2018 #
# #
#######################################################################
import numpy as np
import textwrap
import math
import os
import sys
import textwrap
import glob
import pickle
import csv
import re
import keras
from keras import metrics
from keras.models import Sequential, model_from_json
import keras.backend as K
import pickle
import h5py
# ignore warning from tensorflow
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# Get the directories
current_dir = os.path.dirname(os.path.realpath(__file__))
networks_dir = os.path.join(current_dir, "networks/refined")
mgltools_dir = os.path.join(current_dir, "mgltools")
vina_path = os.path.join(current_dir, "autodock_vina_1_1_2_linux_x86/bin/vina")
verbose = False
# The ffnet class was derived from the ffnet python package developed by Marek Wojciechowski (http://ffnet.sourceforge.net/).
# As Mr. Wojciechowski's program was released under the GPL license, NNScore is likewise GPL licensed.
class ffnet:
def load(self, net_array):
self.outno = net_array['outno']
self.eni = net_array['eni']
self.weights = net_array['weights']
self.conec = net_array['conec']
self.deo = net_array['deo']
self.inno = net_array['inno']
self.units = {}
self.output = {}
def normcall(self, input):
#Takes single input pattern and returns network output
#This have the same functionality as recall but now input and
#output are normalized inside the function.
#eni = [ai, bi], eno = [ao, bo] - parameters of linear mapping
self.input = input
#set input units
self.setin()
#print("FROM FFNET PROP: MAX INPUT: ", np.max(self.input))
#print("INPUT: ", input)
#print("UNITS: ", self.units)
#propagate signals
self.prop()
#get output
self.getout()
return self.output[1]
def setin(self):
#normalize and set input units
for k in range(1,len(self.inno) + 1):
self.units[self.inno[k]] = self.eni[k][1] * self.input[k-1] + self.eni[k][2] # because self.input is a python list, and the others were inputted from a fortran-format file
#print("K: ", k, " len(self.inno): ", len(self.inno), " self.inno[k]: ", self.inno[k], " self.eni[k][1]: ", self.eni[k][1], " self.eni[k][2]: ", self.eni[k][2])
#print("input[", k-1, "] = ", self.input[k-1])
def prop(self):
#Gets conec and units with input already set
#and calculates all activations.
#Identity input and sigmoid activation function for other units
#is assumed
#propagate signals with sigmoid activation function
if len(self.conec) > 0:
ctrg = self.conec[1][2]
self.units[ctrg] = 0.0
for xn in range(1,len(self.conec) + 1):
src = self.conec[xn][1]
trg = self.conec[xn][2]
# if next unit
if trg != ctrg:
self.units[ctrg] = 1.0/(1.0+math.exp(-self.units[ctrg]))
ctrg = trg
if src == 0: # handle bias
self.units[ctrg] = self.weights[xn]
else:
self.units[ctrg] = self.units[src] * self.weights[xn]
else:
if src == 0: # handle bias
self.units[ctrg] = self.units[ctrg] + self.weights[xn]
else:
self.units[ctrg] = self.units[ctrg] + self.units[src] * self.weights[xn]
self.units[ctrg] = 1.0/(1.0+math.exp(-self.units[ctrg])) # for last unit
def getout(self):
#get and denormalize output units
for k in range(1,len(self.outno)+1):
self.output[k] = self.deo[k][1] * self.units[self.outno[k]] + self.deo[k][2]
def dl_nets(nb_nets):
""" Yields feed forward nerual nets from the network directory """
# Read the networks
with open(os.path.join(networks_dir, "sorted_models.pickle"), 'rb') as f:
model_files = pickle.load(f)
with open(os.path.join(networks_dir, "sorted_weights.pickle"), 'rb') as f:
weight_files = pickle.load(f)
assert(len(model_files) == len(weight_files)), 'Number of model files and the weight files are not the same.'
for i, (model, weight) in enumerate(zip(model_files, weight_files)):
if i==nb_nets:
break
# Load the network
with open(os.path.join(networks_dir, model), 'r') as json_file:
loaded_model = model_from_json(json_file.read())
# Load the weights
loaded_model.load_weights(os.path.join(networks_dir, weight))
# Compile the network
#loaded_model.compile(
# loss='mean_squared_error',
# optimizer=keras.optimizers.Adam(lr=0.001),
# metrics=[metrics.mse])
yield loaded_model
class point:
x=99999.0
y=99999.0
z=99999.0
def __init__ (self, x, y ,z):
self.x = x
self.y = y
self.z = z
def copy_of(self):
return point(self.x, self.y, self.z)
def dist_to(self,apoint):
return math.sqrt(math.pow(self.x - apoint.x,2) + math.pow(self.y - apoint.y,2) + math.pow(self.z - apoint.z,2))
def Magnitude(self):
return self.dist_to(point(0,0,0))
def CreatePDBLine(self, index):
output = "ATOM "
output = output + str(index).rjust(6) + "X".rjust(5) + "XXX".rjust(4)
output = output + ("%.3f" % self.x).rjust(18)
output = output + ("%.3f" % self.y).rjust(8)
output = output + ("%.3f" % self.z).rjust(8)
output = output + "X".rjust(24)
return output
class atom:
def __init__ (self):
self.atomname = ""
self.residue = ""
self.coordinates = point(99999, 99999, 99999)
self.element = ""
self.PDBIndex = ""
self.line=""
self.atomtype=""
self.IndeciesOfAtomsConnecting=[]
self.charge = 0
self.resid = 0
self.chain = ""
self.structure = ""
self.comment = ""
def copy_of(self):
theatom = atom()
theatom.atomname = self.atomname
theatom.residue = self.residue
theatom.coordinates = self.coordinates.copy_of()
theatom.element = self.element
theatom.PDBIndex = self.PDBIndex
theatom.line= self.line
theatom.atomtype= self.atomtype
theatom.IndeciesOfAtomsConnecting = self.IndeciesOfAtomsConnecting[:]
theatom.charge = self.charge
theatom.resid = self.resid
theatom.chain = self.chain
theatom.structure = self.structure
theatom.comment = self.comment
return theatom
def CreatePDBLine(self, index):
output = "ATOM "
output = output + str(index).rjust(6) + self.atomname.rjust(5) + self.residue.rjust(4)
output = output + ("%.3f" % self.coordinates.x).rjust(18)
output = output + ("%.3f" % self.coordinates.y).rjust(8)
output = output + ("%.3f" % self.coordinates.z).rjust(8)
output = output + self.element.rjust(24)
return output
def NumberOfNeighbors(self):
return len(self.IndeciesOfAtomsConnecting)
def AddNeighborAtomIndex(self, index):
if not (index in self.IndeciesOfAtomsConnecting):
self.IndeciesOfAtomsConnecting.append(index)
def SideChainOrBackBone(self): # only really applies to proteins, assuming standard atom names
if self.atomname.strip() == "CA" or self.atomname.strip() == "C" or self.atomname.strip() == "O" or self.atomname.strip() == "N":
return "BACKBONE"
else:
return "SIDECHAIN"
def ReadPDBLine(self, Line):
self.line = Line
self.atomname = Line[11:16].strip()
if len(self.atomname)==1:
self.atomname = self.atomname + " "
elif len(self.atomname)==2:
self.atomname = self.atomname + " "
elif len(self.atomname)==3:
self.atomname = self.atomname + " " # This line is necessary for babel to work, though many PDBs in the PDB would have this line commented out
self.coordinates = point(float(Line[30:38]), float(Line[38:46]), float(Line[46:54]))
# now atom type (for pdbqt)
self.atomtype = Line[77:79].strip().upper()
if Line[69:76].strip() != "":
self.charge = float(Line[69:76])
else:
self.charge = 0.0
if self.element == "": # try to guess at element from name
two_letters = self.atomname[0:2].strip().upper()
if two_letters=='BR':
self.element='BR'
elif two_letters=='CL':
self.element='CL'
elif two_letters=='BI':
self.element='BI'
elif two_letters=='AS':
self.element='AS'
elif two_letters=='AG':
self.element='AG'
elif two_letters=='LI':
self.element='LI'
#elif two_letters=='HG':
# self.element='HG'
elif two_letters=='MG':
self.element='MG'
elif two_letters=='MN':
self.element='MN'
elif two_letters=='RH':
self.element='RH'
elif two_letters=='ZN':
self.element='ZN'
elif two_letters=='FE':
self.element='FE'
else: #So, just assume it's the first letter.
# Any number needs to be removed from the element name
self.element = self.atomname
self.element = self.element.replace('0','')
self.element = self.element.replace('1','')
self.element = self.element.replace('2','')
self.element = self.element.replace('3','')
self.element = self.element.replace('4','')
self.element = self.element.replace('5','')
self.element = self.element.replace('6','')
self.element = self.element.replace('7','')
self.element = self.element.replace('8','')
self.element = self.element.replace('9','')
self.element = self.element.replace('@','')
self.element = self.element[0:1].strip().upper()
self.PDBIndex = Line[6:12].strip()
self.residue = Line[16:20]
self.residue = " " + self.residue[-3:] # this only uses the rightmost three characters, essentially removing unique rotamer identification
if Line[23:26].strip() != "": self.resid = int(Line[23:26])
else: self.resid = 1
self.chain = Line[21:22]
if self.residue.strip() == "": self.residue = " MOL"
class PDB:
def __init__ (self):
self.AllAtoms={}
self.NonProteinAtoms = {}
self.max_x = -9999.99
self.min_x = 9999.99
self.max_y = -9999.99
self.min_y = 9999.99
self.max_z = -9999.99
self.min_z = 9999.99
self.rotateable_bonds_count = 0
self.functions = MathFunctions()
self.protein_resnames = ["ALA", "ARG", "ASN", "ASP", "ASH", "ASX", "CYS", "CYM", "CYX", "GLN", "GLU", "GLH", "GLX", "GLY", "HIS", "HID", "HIE", "HIP", "ILE", "LEU", "LYS", "LYN", "MET", "PHE", "PRO", "SER", "THR", "TRP", "TYR", "VAL"]
self.aromatic_rings = []
self.charges = [] # a list of points
self.OrigFileName = ""
def LoadPDB_from_file(self, FileName, line_header=""):
self.line_header=line_header
# Now load the file into a list
file = open(FileName,"r")
lines = file.readlines()
file.close()
self.LoadPDB_from_list(lines, self.line_header)
def LoadPDB_from_list(self, lines, line_header=""):
self.line_header=line_header
autoindex = 1
self.__init__()
atom_already_loaded = [] # going to keep track of atomname_resid_chain pairs, to make sure redundants aren't loaded. This basically
# gets rid of rotomers, I think.
for t in range(0,len(lines)):
line=lines[t]
if "between atoms" in line and " A " in line:
self.rotateable_bonds_count = self.rotateable_bonds_count + 1
if len(line) >= 7:
if line[0:4]=="ATOM" or line[0:6]=="HETATM": # Load atom data (coordinates, etc.)
TempAtom = atom()
TempAtom.ReadPDBLine(line)
key = TempAtom.atomname.strip() + "_" + str(TempAtom.resid) + "_" + TempAtom.residue.strip() + "_" + TempAtom.chain.strip() # this string unique identifies each atom
if key in atom_already_loaded and TempAtom.residue.strip() in self.protein_resnames: # so this is a receptor atom that has already been loaded once
print(self.line_header + "WARNING: Duplicate receptor atom detected: \"" + TempAtom.line.strip()+ "\". Not loading this duplicate.")
#print ""
if not key in atom_already_loaded or not TempAtom.residue.strip() in self.protein_resnames: # so either the atom hasn't been loaded, or else it's a non-receptor atom
# so note that non-receptor atoms can have redundant names, but receptor atoms cannot.
# This is because protein residues often contain rotamers
atom_already_loaded.append(key) # so each atom can only be loaded once. No rotamers.
self.AllAtoms[autoindex] = TempAtom # So you're actually reindexing everything here.
if not TempAtom.residue[-3:] in self.protein_resnames: self.NonProteinAtoms[autoindex] = TempAtom
autoindex = autoindex + 1
self.CheckProteinFormat()
self.CreateBondsByDistance() # only for the ligand, because bonds can be inferred based on atomnames from PDB
self.assign_aromatic_rings()
self.assign_charges()
def printout(self, thestring):
lines = textwrap.wrap(thestring, 80)
for line in lines:
print(line)
def SavePDB(self, filename):
f = open(filename, 'w')
towrite = self.SavePDBString()
if towrite.strip() == "": towrite = "ATOM 1 X XXX 0.000 0.000 0.000 X" # just so no PDB is empty, VMD will load them all
f.write(towrite)
f.close()
def SavePDBString(self):
ToOutput = ""
# write coordinates
for atomindex in self.AllAtoms:
ToOutput = ToOutput + self.AllAtoms[atomindex].CreatePDBLine(atomindex) + "\n"
return ToOutput
def AddNewAtom(self, atom):
# first get available index
t = 1
while t in self.AllAtoms.keys():
t = t + 1
# now add atom
self.AllAtoms[t] = atom
def connected_atoms_of_given_element(self, index, connected_atom_element):
atom = self.AllAtoms[index]
connected_atoms = []
for index2 in atom.IndeciesOfAtomsConnecting:
atom2 = self.AllAtoms[index2]
if atom2.element == connected_atom_element:
connected_atoms.append(index2)
return connected_atoms
def connected_heavy_atoms(self, index):
atom = self.AllAtoms[index]
connected_atoms = []
for index2 in atom.IndeciesOfAtomsConnecting:
atom2 = self.AllAtoms[index2]
if atom2.element != "H": connected_atoms.append(index2)
return connected_atoms
def CheckProteinFormat(self):
curr_res = ""
first = True
residue = []
for atom_index in self.AllAtoms:
atom = self.AllAtoms[atom_index]
key = atom.residue + "_" + str(atom.resid) + "_" + atom.chain
if first == True:
curr_res = key
first = False
if key != curr_res:
self.CheckProteinFormat_process_residue(residue, last_key)
residue = []
curr_res = key
residue.append(atom.atomname.strip())
last_key = key
self.CheckProteinFormat_process_residue(residue, last_key)
def CheckProteinFormat_process_residue(self, residue, last_key):
temp = last_key.strip().split("_")
resname = temp[0]
real_resname = resname[-3:]
resid = temp[1]
chain = temp[2]
if real_resname in self.protein_resnames: # so it's a protein residue
if not "N" in residue:
self.printout('WARNING: There is no atom named "N" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine secondary structure. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "C" in residue:
self.printout('WARNING: There is no atom named "C" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine secondary structure. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CA" in residue:
self.printout('WARNING: There is no atom named "CA" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine secondary structure. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "GLU" or real_resname == "GLH" or real_resname == "GLX":
if not "OE1" in residue:
self.printout('WARNING: There is no atom named "OE1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "OE2" in residue:
self.printout('WARNING: There is no atom named "OE2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "ASP" or real_resname == "ASH" or real_resname == "ASX":
if not "OD1" in residue:
self.printout('WARNING: There is no atom named "OD1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "OD2" in residue:
self.printout('WARNING: There is no atom named "OD2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "LYS" or real_resname == "LYN":
if not "NZ" in residue:
self.printout('WARNING: There is no atom named "NZ" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-cation and salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "ARG":
if not "NH1" in residue:
self.printout('WARNING: There is no atom named "NH1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-cation and salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "NH2" in residue:
self.printout('WARNING: There is no atom named "NH2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-cation and salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "HIS" or real_resname == "HID" or real_resname == "HIE" or real_resname == "HIP":
if not "NE2" in residue:
self.printout('WARNING: There is no atom named "NE2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-cation and salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "ND1" in residue:
self.printout('WARNING: There is no atom named "ND1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-cation and salt-bridge interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "PHE":
if not "CG" in residue:
self.printout('WARNING: There is no atom named "CG" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CD1" in residue:
self.printout('WARNING: There is no atom named "CD1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CD2" in residue:
self.printout('WARNING: There is no atom named "CD2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CE1" in residue:
self.printout('WARNING: There is no atom named "CE1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CE2" in residue:
self.printout('WARNING: There is no atom named "CE2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CZ" in residue:
self.printout('WARNING: There is no atom named "CZ" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "TYR":
if not "CG" in residue:
self.printout('WARNING: There is no atom named "CG" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CD1" in residue:
self.printout('WARNING: There is no atom named "CD1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CD2" in residue:
self.printout('WARNING: There is no atom named "CD2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CE1" in residue:
self.printout('WARNING: There is no atom named "CE1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CE2" in residue:
self.printout('WARNING: There is no atom named "CE2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CZ" in residue:
self.printout('WARNING: There is no atom named "CZ" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "TRP":
if not "CG" in residue:
self.printout('WARNING: There is no atom named "CG" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CD1" in residue:
self.printout('WARNING: There is no atom named "CD1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CD2" in residue:
self.printout('WARNING: There is no atom named "CD2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "NE1" in residue:
self.printout('WARNING: There is no atom named "NE1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CE2" in residue:
self.printout('WARNING: There is no atom named "CE2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CE3" in residue:
self.printout('WARNING: There is no atom named "CE3" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CZ2" in residue:
self.printout('WARNING: There is no atom named "CZ2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CZ3" in residue:
self.printout('WARNING: There is no atom named "CZ3" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CH2" in residue:
self.printout('WARNING: There is no atom named "CH2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if real_resname == "HIS" or real_resname == "HID" or real_resname == "HIE" or real_resname == "HIP":
if not "CG" in residue:
self.printout('WARNING: There is no atom named "CG" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "ND1" in residue:
self.printout('WARNING: There is no atom named "ND1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CD2" in residue:
self.printout('WARNING: There is no atom named "CD2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "CE1" in residue:
self.printout('WARNING: There is no atom named "CE1" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
if not "NE2" in residue:
self.printout('WARNING: There is no atom named "NE2" in the protein residue ' + last_key + '. Please use standard naming conventions for all protein residues. This atom is needed to determine pi-pi and pi-cation interactions. If this residue is far from the active site, this warning may not affect the NNScore.')
print("")
# Functions to determine the bond connectivity based on distance
# ==============================================================
def CreateBondsByDistance(self):
for AtomIndex1 in self.NonProteinAtoms:
atom1 = self.NonProteinAtoms[AtomIndex1]
if not atom1.residue[-3:] in self.protein_resnames: # so it's not a protein residue
for AtomIndex2 in self.NonProteinAtoms:
if AtomIndex1 != AtomIndex2:
atom2 = self.NonProteinAtoms[AtomIndex2]
if not atom2.residue[-3:] in self.protein_resnames: # so it's not a protein residue
dist = self.functions.distance(atom1.coordinates, atom2.coordinates)
if (dist < self.BondLength(atom1.element, atom2.element) * 1.2):
atom1.AddNeighborAtomIndex(AtomIndex2)
atom2.AddNeighborAtomIndex(AtomIndex1)
def BondLength(self, element1, element2):
'''Bond lengths taken from Handbook of Chemistry and Physics. The information provided there was very specific,
so I tried to pick representative examples and used the bond lengths from those. Sitautions could arise where these
lengths would be incorrect, probably slight errors (<0.06) in the hundreds.'''
distance = 0.0
if element1 == "C" and element2 == "C": distance = 1.53
if element1 == "N" and element2 == "N": distance = 1.425
if element1 == "O" and element2 == "O": distance = 1.469
if element1 == "S" and element2 == "S": distance = 2.048
if (element1 == "C" and element2 == "H") or (element1 == "H" and element2 == "C"): distance = 1.059
if (element1 == "C" and element2 == "N") or (element1 == "N" and element2 == "C"): distance = 1.469
if (element1 == "C" and element2 == "O") or (element1 == "O" and element2 == "C"): distance = 1.413
if (element1 == "C" and element2 == "S") or (element1 == "S" and element2 == "C"): distance = 1.819
if (element1 == "N" and element2 == "H") or (element1 == "H" and element2 == "N"): distance = 1.009
if (element1 == "N" and element2 == "O") or (element1 == "O" and element2 == "N"): distance = 1.463
if (element1 == "O" and element2 == "S") or (element1 == "S" and element2 == "O"): distance = 1.577
if (element1 == "O" and element2 == "H") or (element1 == "H" and element2 == "O"): distance = 0.967
if (element1 == "S" and element2 == "H") or (element1 == "H" and element2 == "S"): distance = 2.025/1.5 # This one not from source sited above. Not sure where it's from, but it wouldn't ever be used in the current context ("AutoGrow")
if (element1 == "S" and element2 == "N") or (element1 == "N" and element2 == "S"): distance = 1.633
if (element1 == "C" and element2 == "F") or (element1 == "F" and element2 == "C"): distance = 1.399
if (element1 == "C" and element2 == "CL") or (element1 == "CL" and element2 == "C"): distance = 1.790
if (element1 == "C" and element2 == "BR") or (element1 == "BR" and element2 == "C"): distance = 1.910
if (element1 == "C" and element2 == "I") or (element1 == "I" and element2 == "C"): distance=2.162
if (element1 == "S" and element2 == "BR") or (element1 == "BR" and element2 == "S"): distance = 2.321
if (element1 == "S" and element2 == "CL") or (element1 == "CL" and element2 == "S"): distance = 2.283
if (element1 == "S" and element2 == "F") or (element1 == "F" and element2 == "S"): distance = 1.640
if (element1 == "S" and element2 == "I") or (element1 == "I" and element2 == "S"): distance= 2.687
if (element1 == "P" and element2 == "BR") or (element1 == "BR" and element2 == "P"): distance = 2.366
if (element1 == "P" and element2 == "CL") or (element1 == "CL" and element2 == "P"): distance = 2.008
if (element1 == "P" and element2 == "F") or (element1 == "F" and element2 == "P"): distance = 1.495
if (element1 == "P" and element2 == "I") or (element1 == "I" and element2 == "P"): distance= 2.490
if (element1 == "P" and element2 == "O") or (element1 == "O" and element2 == "P"): distance= 1.6 # estimate based on eye balling Handbook of Chemistry and Physics
if (element1 == "N" and element2 == "BR") or (element1 == "BR" and element2 == "N"): distance = 1.843
if (element1 == "N" and element2 == "CL") or (element1 == "CL" and element2 == "N"): distance = 1.743
if (element1 == "N" and element2 == "F") or (element1 == "F" and element2 == "N"): distance = 1.406
if (element1 == "N" and element2 == "I") or (element1 == "I" and element2 == "N"): distance= 2.2
if (element1 == "SI" and element2 == "BR") or (element1 == "BR" and element2 == "SI"): distance = 2.284
if (element1 == "SI" and element2 == "CL") or (element1 == "CL" and element2 == "SI"): distance = 2.072
if (element1 == "SI" and element2 == "F") or (element1 == "F" and element2 == "SI"): distance = 1.636
if (element1 == "SI" and element2 == "P") or (element1 == "P" and element2 == "SI"): distance= 2.264
if (element1 == "SI" and element2 == "S") or (element1 == "S" and element2 == "SI"): distance= 2.145
if (element1 == "SI" and element2 == "SI") or (element1 == "SI" and element2 == "SI"): distance= 2.359
if (element1 == "SI" and element2 == "C") or (element1 == "C" and element2 == "SI"): distance= 1.888
if (element1 == "SI" and element2 == "N") or (element1 == "N" and element2 == "SI"): distance= 1.743
if (element1 == "SI" and element2 == "O") or (element1 == "O" and element2 == "SI"): distance= 1.631
return distance;
# Functions to identify positive charges
# ======================================
def assign_charges(self):
# Get all the quartinary amines on non-protein residues (these are the only non-protein groups that will be identified as positively charged)
AllCharged = []
for atom_index in self.NonProteinAtoms:
atom = self.NonProteinAtoms[atom_index]
if atom.element == "MG" or atom.element == "MN" or atom.element == "RH" or atom.element == "ZN" or atom.element == "FE" or atom.element == "BI" or atom.element == "AS" or atom.element == "AG":
chrg = self.charged(atom.coordinates, [atom_index], True)
self.charges.append(chrg)
if atom.element == "N":
if atom.NumberOfNeighbors() == 4: # a quartinary amine, so it's easy
indexes = [atom_index]
indexes.extend(atom.IndeciesOfAtomsConnecting)
chrg = self.charged(atom.coordinates, indexes, True) # so the indicies stored is just the index of the nitrogen and any attached atoms
self.charges.append(chrg)
elif atom.NumberOfNeighbors() == 3: # maybe you only have two hydrogen's added, by they're sp3 hybridized. Just count this as a quartinary amine, since I think the positive charge would be stabalized.
nitrogen = atom
atom1 = self.AllAtoms[atom.IndeciesOfAtomsConnecting[0]]
atom2 = self.AllAtoms[atom.IndeciesOfAtomsConnecting[1]]
atom3 = self.AllAtoms[atom.IndeciesOfAtomsConnecting[2]]
angle1 = self.functions.angle_between_three_points(atom1.coordinates, nitrogen.coordinates, atom2.coordinates) * 180.0 / math.pi
angle2 = self.functions.angle_between_three_points(atom1.coordinates, nitrogen.coordinates, atom3.coordinates) * 180.0 / math.pi
angle3 = self.functions.angle_between_three_points(atom2.coordinates, nitrogen.coordinates, atom3.coordinates) * 180.0 / math.pi
average_angle = (angle1 + angle2 + angle3) / 3
if math.fabs(average_angle - 109.0) < 5.0:
indexes = [atom_index]
indexes.extend(atom.IndeciesOfAtomsConnecting)
chrg = self.charged(nitrogen.coordinates, indexes, True) # so indexes added are the nitrogen and any attached atoms.
self.charges.append(chrg)
if atom.element == "C": # let's check for guanidino-like groups (actually H2N-C-NH2, where not CN3.)
if atom.NumberOfNeighbors() == 3: # the carbon has only three atoms connected to it
nitrogens = self.connected_atoms_of_given_element(atom_index,"N")
if len(nitrogens) >= 2: # so carbon is connected to at least two nitrogens
# now we need to count the number of nitrogens that are only connected to one heavy atom (the carbon)
nitrogens_to_use = []
all_connected = atom.IndeciesOfAtomsConnecting[:]
not_isolated = -1
for atmindex in nitrogens:
if len(self.connected_heavy_atoms(atmindex)) == 1:
nitrogens_to_use.append(atmindex)
all_connected.remove(atmindex)
if len(all_connected) > 0: not_isolated = all_connected[0] # get the atom that connects this charged group to the rest of the molecule, ultimately to make sure it's sp3 hybridized
if len(nitrogens_to_use) == 2 and not_isolated != -1: # so there are at two nitrogens that are only connected to the carbon (and probably some hydrogens)
# now you need to make sure not_isolated atom is sp3 hybridized
not_isolated_atom = self.AllAtoms[not_isolated]
if (not_isolated_atom.element == "C" and not_isolated_atom.NumberOfNeighbors()==4) or (not_isolated_atom.element == "O" and not_isolated_atom.NumberOfNeighbors()==2) or not_isolated_atom.element == "N" or not_isolated_atom.element == "S" or not_isolated_atom.element == "P":
pt = self.AllAtoms[nitrogens_to_use[0]].coordinates.copy_of()
pt.x = pt.x + self.AllAtoms[nitrogens_to_use[1]].coordinates.x
pt.y = pt.y + self.AllAtoms[nitrogens_to_use[1]].coordinates.y
pt.z = pt.z + self.AllAtoms[nitrogens_to_use[1]].coordinates.z
pt.x = pt.x / 2.0
pt.y = pt.y / 2.0
pt.z = pt.z / 2.0
indexes = [atom_index]
indexes.extend(nitrogens_to_use)
indexes.extend(self.connected_atoms_of_given_element(nitrogens_to_use[0],"H"))
indexes.extend(self.connected_atoms_of_given_element(nitrogens_to_use[1],"H"))
chrg = self.charged(pt, indexes, True) # True because it's positive
self.charges.append(chrg)
if atom.element == "C": # let's check for a carboxylate
if atom.NumberOfNeighbors() == 3: # a carboxylate carbon will have three items connected to it.
oxygens = self.connected_atoms_of_given_element(atom_index,"O")
if len(oxygens) == 2: # a carboxylate will have two oxygens connected to it.
# now, each of the oxygens should be connected to only one heavy atom (so if it's connected to a hydrogen, that's okay)
if len(self.connected_heavy_atoms(oxygens[0])) == 1 and len(self.connected_heavy_atoms(oxygens[1])) == 1:
# so it's a carboxylate! Add a negative charge.
pt = self.AllAtoms[oxygens[0]].coordinates.copy_of()
pt.x = pt.x + self.AllAtoms[oxygens[1]].coordinates.x
pt.y = pt.y + self.AllAtoms[oxygens[1]].coordinates.y
pt.z = pt.z + self.AllAtoms[oxygens[1]].coordinates.z
pt.x = pt.x / 2.0
pt.y = pt.y / 2.0
pt.z = pt.z / 2.0
chrg = self.charged(pt, [oxygens[0], atom_index, oxygens[1]], False)
self.charges.append(chrg)
if atom.element == "P": # let's check for a phosphate or anything where a phosphorus is bound to two oxygens where both oxygens are bound to only one heavy atom (the phosphorus). I think this will get several phosphorus substances.
oxygens = self.connected_atoms_of_given_element(atom_index,"O")
if len(oxygens) >=2: # the phosphorus is bound to at least two oxygens
# now count the number of oxygens that are only bound to the phosphorus
count = 0
for oxygen_index in oxygens:
if len(self.connected_heavy_atoms(oxygen_index)) == 1: count = count + 1
if count >=2: # so there are at least two oxygens that are only bound to the phosphorus
indexes = [atom_index]
indexes.extend(oxygens)
chrg = self.charged(atom.coordinates, indexes, False)
self.charges.append(chrg)
if atom.element == "S": # let's check for a sulfonate or anything where a sulfur is bound to at least three oxygens and at least three are bound to only the sulfur (or the sulfur and a hydrogen).
oxygens = self.connected_atoms_of_given_element(atom_index,"O")
if len(oxygens) >=3: # the sulfur is bound to at least three oxygens
# now count the number of oxygens that are only bound to the sulfur
count = 0
for oxygen_index in oxygens:
if len(self.connected_heavy_atoms(oxygen_index)) == 1: count = count + 1
if count >=3: # so there are at least three oxygens that are only bound to the sulfur
indexes = [atom_index]
indexes.extend(oxygens)
chrg = self.charged(atom.coordinates, indexes, False)
self.charges.append(chrg)
# Now that you've found all the positive charges in non-protein residues, it's time to look for aromatic rings in protein residues
curr_res = ""
first = True
residue = []
for atom_index in self.AllAtoms:
atom = self.AllAtoms[atom_index]
key = atom.residue + "_" + str(atom.resid) + "_" + atom.chain
if first == True:
curr_res = key
first = False
if key != curr_res:
self.assign_charged_from_protein_process_residue(residue, last_key)
residue = []
curr_res = key
residue.append(atom_index)
last_key = key
self.assign_charged_from_protein_process_residue(residue, last_key)
def assign_charged_from_protein_process_residue(self, residue, last_key):
temp = last_key.strip().split("_")
resname = temp[0]
real_resname = resname[-3:]
resid = temp[1]
chain = temp[2]
if real_resname == "LYS" or real_resname == "LYN": # regardless of protonation state, assume it's charged.
for index in residue:
atom = self.AllAtoms[index]
if atom.atomname.strip() == "NZ":
# quickly go through the residue and get the hydrogens attached to this nitrogen to include in the index list
indexes = [index]
for index2 in residue:
atom2 = self.AllAtoms[index2]
if atom2.atomname.strip() == "HZ1": indexes.append(index2)
if atom2.atomname.strip() == "HZ2": indexes.append(index2)
if atom2.atomname.strip() == "HZ3": indexes.append(index2)
chrg = self.charged(atom.coordinates, indexes, True)
self.charges.append(chrg)
break
if real_resname == "ARG":
charge_pt = point(0.0,0.0,0.0)
count = 0.0
indices = []
for index in residue:
atom = self.AllAtoms[index]
if atom.atomname.strip() == "NH1":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "NH2":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "2HH2": indices.append(index)
if atom.atomname.strip() == "1HH2": indices.append(index)
if atom.atomname.strip() == "CZ": indices.append(index)
if atom.atomname.strip() == "2HH1": indices.append(index)
if atom.atomname.strip() == "1HH1": indices.append(index)
if count != 0.0:
charge_pt.x = charge_pt.x / count
charge_pt.y = charge_pt.y / count
charge_pt.z = charge_pt.z / count
if charge_pt.x != 0.0 or charge_pt.y != 0.0 or charge_pt.z != 0.0:
chrg = self.charged(charge_pt, indices, True)
self.charges.append(chrg)
if real_resname == "HIS" or real_resname == "HID" or real_resname == "HIE" or real_resname == "HIP": # regardless of protonation state, assume it's charged. This based on "The Cation-Pi Interaction," which suggests protonated state would be stabalized. But let's not consider HIS when doing salt bridges.
charge_pt = point(0.0,0.0,0.0)
count = 0.0
indices = []
for index in residue:
atom = self.AllAtoms[index]
if atom.atomname.strip() == "NE2":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "ND1":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "HE2": indices.append(index)
if atom.atomname.strip() == "HD1": indices.append(index)
if atom.atomname.strip() == "CE1": indices.append(index)
if atom.atomname.strip() == "CD2": indices.append(index)
if atom.atomname.strip() == "CG": indices.append(index)
if count != 0.0:
charge_pt.x = charge_pt.x / count
charge_pt.y = charge_pt.y / count
charge_pt.z = charge_pt.z / count
if charge_pt.x != 0.0 or charge_pt.y != 0.0 or charge_pt.z != 0.0:
chrg = self.charged(charge_pt, indices, True)
self.charges.append(chrg)
if real_resname == "GLU" or real_resname == "GLH" or real_resname == "GLX": # regardless of protonation state, assume it's charged. This based on "The Cation-Pi Interaction," which suggests protonated state would be stabalized.
charge_pt = point(0.0,0.0,0.0)
count = 0.0
indices = []
for index in residue:
atom = self.AllAtoms[index]
if atom.atomname.strip() == "OE1":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "OE2":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "CD": indices.append(index)
if count != 0.0:
charge_pt.x = charge_pt.x / count
charge_pt.y = charge_pt.y / count
charge_pt.z = charge_pt.z / count
if charge_pt.x != 0.0 or charge_pt.y != 0.0 or charge_pt.z != 0.0:
chrg = self.charged(charge_pt, indices, False) # False because it's a negative charge
self.charges.append(chrg)
if real_resname == "ASP" or real_resname == "ASH" or real_resname == "ASX": # regardless of protonation state, assume it's charged. This based on "The Cation-Pi Interaction," which suggests protonated state would be stabalized.
charge_pt = point(0.0,0.0,0.0)
count = 0.0
indices = []
for index in residue:
atom = self.AllAtoms[index]
if atom.atomname.strip() == "OD1":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "OD2":
charge_pt.x = charge_pt.x + atom.coordinates.x
charge_pt.y = charge_pt.y + atom.coordinates.y
charge_pt.z = charge_pt.z + atom.coordinates.z
indices.append(index)
count = count + 1.0
if atom.atomname.strip() == "CG": indices.append(index)
if count != 0.0:
charge_pt.x = charge_pt.x / count
charge_pt.y = charge_pt.y / count
charge_pt.z = charge_pt.z / count
if charge_pt.x != 0.0 or charge_pt.y != 0.0 or charge_pt.z != 0.0:
chrg = self.charged(charge_pt, indices, False) # False because it's a negative charge
self.charges.append(chrg)
class charged():
def __init__(self, coordinates, indices, positive):
self.coordinates = coordinates
self.indices = indices
self.positive = positive # true or false to specifiy if positive or negative charge
# Functions to identify aromatic rings
# ====================================
def add_aromatic_marker(self, indicies_of_ring):
# first identify the center point
points_list = []
total = len(indicies_of_ring)
x_sum = 0.0
y_sum = 0.0
z_sum = 0.0
for index in indicies_of_ring:
atom = self.AllAtoms[index]
points_list.append(atom.coordinates)
x_sum = x_sum + atom.coordinates.x
y_sum = y_sum + atom.coordinates.y
z_sum = z_sum + atom.coordinates.z
if total == 0: return # to prevent errors in some cases
center = point(x_sum / total, y_sum / total, z_sum / total)
# now get the radius of the aromatic ring