-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoclickchem.py
6239 lines (4882 loc) · 347 KB
/
autoclickchem.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
"""AutoClickChem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
AutoClickChem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Copyright 2011 Jacob D. Durrant. If you have any questions, comments, or
suggestions, please don't hesitate to contact me at jdurrant [at] ucsd [dot] edu.
The latest version of AutoClickChem can be downloaded from
http://sourceforge.net/projects/autoclickchem/
If you use AutoClickChem in your work, please cite [REFERENCE HERE]"""
import os
import sys
import glob
import pymolecule
import time
import random
import math
class StructureLocateGroups:
"""This class contains functions that aid the identification of reactive chemical groups."""
def index_of_azide(self, pdb):
"""Identifies all the azide groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified azide group.
"""
# This will return the indices of the atoms, proximal to distal. R-X-N=N=N
# So we're looking for three nitrogens without any hydrogens, arranged in a straight line.
AzideRoots = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="N" and len(atom.indecies_of_atoms_connecting)==1: # This is the terminal N
neighbor1_index = atom.indecies_of_atoms_connecting[0]
neighbor1_atom = pdb.all_atoms[neighbor1_index]
if neighbor1_atom.element=="N" and len(neighbor1_atom.indecies_of_atoms_connecting)==2: # middle N
indicies = []
for index in neighbor1_atom.indecies_of_atoms_connecting:
indicies.append(index)
indicies.remove(atom_index)
neighbor2_index = indicies[0]
neighbor2_atom = pdb.all_atoms[neighbor2_index]
if neighbor2_atom.element == "N" and len(neighbor1_atom.indecies_of_atoms_connecting)==2: # proximal N
# they have to be in a straight line
angle = atom.coordinates.angle_between_three_points(neighbor1_atom.coordinates, neighbor2_atom.coordinates) * 180 / math.pi
if abs(angle-180) < 10: # so it is in a straight line
indicies = []
for index in neighbor2_atom.indecies_of_atoms_connecting:
indicies.append(index)
indicies.remove(neighbor1_index)
neighbor3_index = indicies[0] # X described above
neighbor3_atom = pdb.all_atoms[neighbor3_index]
if neighbor3_atom.element == "C": # This is so sulfonyl azides are not detected here.
#Now, to be able to position sp2 hybridized amines correctly (azide => sp2 amine), we need one more atom index.
indicies = neighbor3_atom.indecies_of_atoms_connecting[:]
for index in indicies: # get rid of hydrogens, so that only heteroatoms remain in the list
if pdb.all_atoms[index].element == 'H': indicies.remove(index)
if index == neighbor2_index: indicies.remove(index)
neighbor4_index = indicies[0]
list = [neighbor3_index, neighbor2_index, neighbor1_index, atom_index]
if len(indicies)>0: list.append(neighbor4_index) # neighbor4 index put at end for backwards compatibility (logically, should be at beginning)
AzideRoots.append(list)
return AzideRoots
def index_of_sulfonyl_azide(self, pdb):
"""Identifies all the sulfonyl azide groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified sulfonyl azide group.
"""
# This will return the indices of the atoms, proximal to distal. R-S-N=N=N
# So we're looking for three nitrogens without any hydrogens, arranged in a straight line.
SulfonylAzideRoots = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="N" and len(atom.indecies_of_atoms_connecting)==1: # this is the terminal nitrogen of the azide group
neighbor1_index = atom.indecies_of_atoms_connecting[0]
neighbor1_atom = pdb.all_atoms[neighbor1_index] # this is the middle nitrogen of the azide group
if neighbor1_atom.element=="N" and len(neighbor1_atom.indecies_of_atoms_connecting)==2:
indicies = neighbor1_atom.indecies_of_atoms_connecting[:]
indicies.remove(atom_index)
neighbor2_index = indicies[0]
neighbor2_atom = pdb.all_atoms[neighbor2_index] # this is the proximal nitrogen of the azide group
if neighbor2_atom.element == "N" and len(neighbor1_atom.indecies_of_atoms_connecting)==2:
# they have to be in a straight line
angle = atom.coordinates.angle_between_three_points(neighbor1_atom.coordinates, neighbor2_atom.coordinates) * 180 / math.pi
if abs(angle-180) < 10: # so it is in a straight line
indicies = neighbor2_atom.indecies_of_atoms_connecting[:]
indicies.remove(neighbor1_index)
neighbor3_index = indicies[0]
neighbor3_atom = pdb.all_atoms[neighbor3_index]
if neighbor3_atom.element == "S" and neighbor3_atom.number_of_neighbors() == 4: # this is the sulfonyl part of the sulfonyl azide
# now make sure at least two of the atoms attached to this S are O's
oxygens = pdb.number_of_neighors_of_element(neighbor3_index, "O")
if oxygens >= 2:
SulfonylAzideRoots.append([neighbor3_index, neighbor2_index, neighbor1_index, atom_index])
return SulfonylAzideRoots
def index_of_thio_acid(self, pdb):
"""Identifies all the thio acid groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified thio acid group.
"""
# This will return the indices of the atoms, proximal to distal. R-C(=O)SH
ThioAcidRoots = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="C" and len(atom.indecies_of_atoms_connecting)==3 and pdb.number_of_neighors_of_element(atom_index, "O") >= 1 and pdb.number_of_neighors_of_element(atom_index, "S") >= 1:
listconnected = atom.indecies_of_atoms_connecting[:] # make a copy
for index in range(len(listconnected)):
neighbor_index = listconnected[index]
if pdb.all_atoms[neighbor_index].element == "O" and pdb.all_atoms[neighbor_index].number_of_neighbors() == 1: # so this is the carbonyl oxygen. delete it.
carbonyl_oxygen_index = neighbor_index
listconnected[index] = "DELETE"
if pdb.all_atoms[neighbor_index].element == "S" and pdb.all_atoms[neighbor_index].number_of_neighbors() == 2 and pdb.number_of_neighors_of_element(neighbor_index, "H") == 1:
sulfur_index = neighbor_index
listconnected[index] = "DELETE"
while "DELETE" in listconnected: listconnected.remove("DELETE")
first_atom_of_R_group_index = listconnected[0]
if len(listconnected) == 1: # sanity check. Makes sure the connected oxygen is a carbonyl oxygen
sulfur_atom = pdb.all_atoms[sulfur_index]
listconnected = sulfur_atom.indecies_of_atoms_connecting[:] # make a copy
listconnected.remove(atom_index)
terminal_hydrogen_index = listconnected[0]
if len(listconnected) == 1:
ThioAcidRoots.append([carbonyl_oxygen_index, atom_index, sulfur_index, terminal_hydrogen_index])
return ThioAcidRoots
def index_of_alkene(self, pdb): # identify alkenes (olefins)
"""Identifies all the alkene groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified alkene group.
"""
# 2 5
# \ /
# 1 = 4
# / \
# 3 6
# unfortunately, this is going to mess up on things like -C=C-C=C-
# the middle two will be epoxidated incorrectly.
AlkeneRoots=[]
for first_C_index in pdb.all_atoms:
first_C = pdb.all_atoms[first_C_index]
if first_C.element=="C" and first_C.number_of_neighbors() == 3: # you've found some sp2 hybridized carbon
for second_C_index in first_C.indecies_of_atoms_connecting:
second_C = pdb.all_atoms[second_C_index]
if second_C.element=="C" and second_C.number_of_neighbors() == 3: # you've found a neighboring sp2 hybridized carbon
# now make sure they are not in the same ring. It would be nice if we could include olefins in rings, ut it would be too hard to code. :(
if pdb.in_same_ring(first_C_index, second_C_index) == "FALSE":
first_connectors = first_C.indecies_of_atoms_connecting[:]
second_connectors = second_C.indecies_of_atoms_connecting[:]
first_connectors.remove(second_C_index)
second_connectors.remove(first_C_index)
items=[]
items.append(first_C_index)
for index in first_connectors:
items.append(index)
items.append(second_C_index)
for index in second_connectors:
items.append(index)
# now we need to make sure it's not in any kind of ring
if pdb.in_same_ring(items[0], items[3]) == "FALSE":
if pdb.in_same_ring(items[0], items[1]) == "FALSE":
if pdb.in_same_ring(items[3], items[4]) == "FALSE":
# now let's make sure not to include vinyl carboxylates, ketones, etc. These show up suprisingly frequently
neighbors_all = first_C.indecies_of_atoms_connecting[:]
neighbors_all.extend(second_C.indecies_of_atoms_connecting)
neighbors_all.remove(first_C_index)
neighbors_all.remove(second_C_index)
continue_ok = True
for index in neighbors_all:
neighbor_all_atom = pdb.all_atoms[index]
if neighbor_all_atom.element == "O" and neighbor_all_atom.number_of_neighbors() == 1: # so it's a carbonyl oxygen atom
continue_ok = False
break
if continue_ok == True: AlkeneRoots.append(items)
# every alkene has been identified in duplicate. remove the duplicates
toremove = []
for item1_index in range(0,len(AlkeneRoots)-1):
item1 = AlkeneRoots[item1_index]
item1_sorted=item1[:]
item1_sorted.sort()
for item2_index in range(item1_index+1,len(AlkeneRoots)):
item2 = AlkeneRoots[item2_index]
item2_sorted=item2[:]
item2_sorted.sort()
if item1_sorted == item2_sorted:
if item2 not in toremove: toremove.append(item2)
for remove_item in toremove:
AlkeneRoots.remove(remove_item)
return AlkeneRoots
def index_of_alkyne(self, pdb): # Identify an alkyne, terminal or internal
"""Identifies all the alkyne groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified alkyne group.
"""
# Think first_neighbor - first_C =- second_C - second_neighbor
AlkyneRoots=[]
for first_C_index in pdb.all_atoms:
first_C = pdb.all_atoms[first_C_index]
#print str(first_C_index) + "\t" + first_C.element + "\t" + str(len(first_C.indecies_of_atoms_connecting))
#print first_C.indecies_of_atoms_connecting
if first_C.element=="C" and len(first_C.indecies_of_atoms_connecting)==2: # so it finds the one of the sp1 hybridized carbons
neighbor1_index = first_C.indecies_of_atoms_connecting[0]
neighbor2_index = first_C.indecies_of_atoms_connecting[1]
neighbor1 = pdb.all_atoms[neighbor1_index]
neighbor2 = pdb.all_atoms[neighbor2_index]
# one of these neighbors is the other carbon of the alkyne bond. Identify it.
if neighbor1.element=="C" and len(neighbor1.indecies_of_atoms_connecting)==2: # so neighbor1 is the other carbon of the alkyne bond
second_C = neighbor1
second_C_index = neighbor1_index
do_continue="TRUE"
elif neighbor2.element=="C" and len(neighbor2.indecies_of_atoms_connecting)==2:
second_C = neighbor2 # so neighbor2 is the other carbon of the alkyne bond
second_C_index = neighbor2_index
do_continue="TRUE"
else: do_continue="FALSE" # the identified carbon is not connected to another sp1-hybridized carbon. Bond not identified here.
if do_continue == "TRUE": # so we do have an alkyne bond
# make a copy of the list of the two atoms bound to first_C
first_C_bonded = first_C.indecies_of_atoms_connecting[:]
# remove the index of second_C
first_C_bonded.remove(second_C_index)
# make a copy of the list of the two atoms bound to second_C
second_C_bonded = second_C.indecies_of_atoms_connecting[:]
# remove the index of first_C
second_C_bonded.remove(first_C_index)
first_neighbor_index = first_C_bonded[0]
first_neighbor = pdb.all_atoms[first_neighbor_index]
second_neighbor_index = second_C_bonded[0]
second_neighbor = pdb.all_atoms[second_neighbor_index]
angle1 = first_neighbor.coordinates.angle_between_three_points(first_C.coordinates, second_C.coordinates) * 180 / math.pi
angle2 = first_C.coordinates.angle_between_three_points(second_C.coordinates, second_neighbor.coordinates) * 180 / math.pi
if abs(angle1 - 180) < 10 and abs(angle2 - 180) < 10:
AlkyneRoots.append([first_neighbor_index, first_C_index, second_C_index, second_neighbor_index])
# now, because there is no directionality to this bond, everything is in duplicate. Remove the duplicates.
ToRemove = []
for index1 in range(0,len(AlkyneRoots)-1):
for index2 in range(index1 + 1, len(AlkyneRoots)):
list1 = AlkyneRoots[index1]
list2 = AlkyneRoots[index2]
if list1[0] == list2[3] and list1[1] == list2[2] and list1[2] == list2[1] and list1[3] == list2[0]:
ToRemove.append(list2)
for list in ToRemove:
AlkyneRoots.remove(list)
return AlkyneRoots
def index_of_alcohol(self, pdb): # Identify an alcohol
"""Identifies all the alcohol groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified alcohol group.
"""
# Think R - O - H (1 - 2 - 3)
AlcoholRoots=[]
for oxygen_index in pdb.all_atoms:
oxygen = pdb.all_atoms[oxygen_index]
if oxygen.element == "O" and oxygen.number_of_neighbors() == 2:
#Now, one of those neighbors needs to be a hydrogen
for hydrogen_index in oxygen.indecies_of_atoms_connecting:
hydrogen = pdb.all_atoms[hydrogen_index]
if hydrogen.element == "H":
neighbors = oxygen.indecies_of_atoms_connecting[:]
neighbors.remove(hydrogen_index)
other_index = neighbors[0]
other_atom = pdb.all_atoms[other_index]
if other_atom.element == "C": # We're only interest in alcohols attached to carbons
# We need to make sure that none of the atoms bound to the C are double-bonded oxygens. Carboxylic acids are not acceptable.
# get a list of all the neighbors
neighbors = other_atom.indecies_of_atoms_connecting[:]
IsAlcohol = "TRUE"
for index in neighbors:
if pdb.all_atoms[index].element == "O" and pdb.all_atoms[index].number_of_neighbors() == 1:
IsAlcohol = "FALSE"
if IsAlcohol== "TRUE" : AlcoholRoots.append([other_index, oxygen_index, hydrogen_index])
return AlcoholRoots
def index_of_thiol(self, pdb): # Identify an alcohol
"""Identifies all the thiol groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified thiol group.
"""
# Think R - S - H (1 - 2 - 3)
ThiolRoots=[]
for sulfur_index in pdb.all_atoms:
sulfur = pdb.all_atoms[sulfur_index]
if sulfur.element == "S" and sulfur.number_of_neighbors() == 2:
#Now, one of those neighbors needs to be a hydrogen
for hydrogen_index in sulfur.indecies_of_atoms_connecting:
hydrogen = pdb.all_atoms[hydrogen_index]
if hydrogen.element == "H":
neighbors = sulfur.indecies_of_atoms_connecting[:]
neighbors.remove(hydrogen_index)
other_index = neighbors[0] # This is the carbon the thiol is attached to (R above)
other_atom = pdb.all_atoms[other_index]
if other_atom.element == "C": # We're only interest in thiols attached to carbons
# We need to make sure that none of the atoms bound to the C are double-bonded oxygens. Thiol acids are not acceptable.
# get a list of all the neighbors
neighbors = other_atom.indecies_of_atoms_connecting[:]
IsThiol = "TRUE"
for index in neighbors:
if pdb.all_atoms[index].element == "O" and pdb.all_atoms[index].number_of_neighbors() == 1:
IsThiol = "FALSE"
if IsThiol == "TRUE" : ThiolRoots.append([other_index, sulfur_index, hydrogen_index])
return ThiolRoots
def index_of_epoxide(self, pdb): # Identify an epoxide # still needs to be tested # the epoxide cannot be part of a larger ring system
"""Identifies all the epoxide groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified epoxide group.
"""
# O(0)
# / \
# X(2) - C(1) - C(4) - X(5)
# / \
# X(3) X(6)
EpoxideRoots=[]
for oxygen_index in pdb.all_atoms:
oxygen = pdb.all_atoms[oxygen_index]
if oxygen.element == "O" and pdb.number_of_neighors_of_element(oxygen_index, "C") == 2 and oxygen.number_of_neighbors() == 2:
# now we need to see if the two carbons connected to that O are connected to each other
carbon1_index = oxygen.indecies_of_atoms_connecting[0]
carbon2_index = oxygen.indecies_of_atoms_connecting[1]
carbon1 = pdb.all_atoms[carbon1_index]
carbon2 = pdb.all_atoms[carbon2_index]
if carbon2_index in carbon1.indecies_of_atoms_connecting and carbon1_index in carbon2.indecies_of_atoms_connecting: # so they are connected
# now need to make sure that carbon1_index and carbon2_index are not in a ring together (except for the epoxide ring itself)
temp_pdb = pdb.copy_of()
temp_pdb.delete_atom(oxygen_index)
if temp_pdb.in_same_ring(carbon1_index, carbon2_index) == "FALSE":
carbon1_neighbors = carbon1.indecies_of_atoms_connecting[:]
carbon2_neighbors = carbon2.indecies_of_atoms_connecting[:]
# remove oxygen from list
carbon1_neighbors.remove(oxygen_index)
carbon2_neighbors.remove(oxygen_index)
# remove other carbon you're bound too
carbon1_neighbors.remove(carbon2_index)
carbon2_neighbors.remove(carbon1_index)
carbon1_neighbor1_index = carbon1_neighbors[0]
carbon1_neighbor2_index = carbon1_neighbors[1]
carbon2_neighbor1_index = carbon2_neighbors[0]
carbon2_neighbor2_index = carbon2_neighbors[1]
if pdb.in_same_ring(carbon1_index, carbon1_neighbor1_index) == "FALSE":
if pdb.in_same_ring(carbon2_index, carbon2_neighbor1_index) == "FALSE":
EpoxideRoots.append([oxygen_index, carbon1_index, carbon1_neighbor1_index, carbon1_neighbor2_index, carbon2_index, carbon2_neighbor1_index, carbon2_neighbor2_index])
return EpoxideRoots
def index_of_primary_amine(self, pdb): # Here's the name of the function we'll call to identify primary amines. The function accepts as input a pdb object.
"""Identifies all the primary amine groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified primary amine group.
"""
Indices_of_primary_amines = [] # Here's the list that will eventually contain the locations of all the primary amines in the pdb object.
# This is actually a list of lists. Each primary amine looks like this: R - X - N - H(2)
# To identify the amine, it's not enough just to identify the index of the N atom. We also need to identify
# the index of it's neighbor, X, and it's hydrogens as well. So, we'll be adding quadrulets to the Indices_of_primary_amines list,
# (index_N, index_X, index_H1, index_H2, ...).
# For example, say the pdb is H(2) - N - CH(2) - CH(2) - N - H(2), and the atoms have the following indicies:
# 1,2 3 4,5,6 7,8,9 10 11,12, or, just focusing on the heavy atoms...
# 3 4 7 10
# Then we want Indices_of_primary_amines to look like this in the end: [[4,3,1,2], [7,10,11,12]].
for atom_index in pdb.all_atoms: # Now, we're going to look at each of the atoms in the pdb object. For each iteration of the loop, the variable "atom_index" is the
# index of the atom we're examining.
atom = pdb.all_atoms[atom_index] # "atom_index" was only the index of the atom. Now, the "atom" variable points to the atom object itself, rather than just the index.
if atom.element=="N": # Look and see if the atom is a nitrogen.
nitrogen_index = atom_index # If it is a nitrogen, then store the index of that nitrogen in the variable "nitrogen_index"
if pdb.number_of_neighors_of_element(nitrogen_index,"H") >= atom.number_of_neighbors()-1: # If it's a primary amine, this should be true
# So ammonium is not a primary amine.
# So we are dealing with a primary amine!
if atom.number_of_neighbors() == 3 or atom.number_of_neighbors() == 4: # A primary amine should have only three atoms connected to it (assuming it's not charged)
# This conditional is actually unnecessary, but I wanted to show you how to detect the
# number of atoms connected to a given atom of interest
nitrogen_neighbors = atom.indecies_of_atoms_connecting[:] # Here's a list the indices of all the atoms connected to the nitrogen of the primary amine.
for neighbor_index in nitrogen_neighbors: # We're going to look at each neighbor. The "neighbor_index" variable contains the index of the
# neighbor we're looking at.
neighbor_atom = pdb.all_atoms[neighbor_index] # "neighbor_index" contained the index of the neighbor, but the variable "neighbor_atom" points
# to the neighbor atom object itself.
if neighbor_atom.element != "H": # So we're looking at the neighbor that is not a hydrogen, atom "X" above.
index_x = neighbor_index # We're going to save the index of this non-H atom in the variable "index_x"
nitrogen_neighbors.remove(index_x) # We're now removing the index of this non-H atom from the list, so that the only indices remaining
# in the list are the indices of the hydrogen neighbors of the amine N.
if pdb.all_atoms[index_x].element == "C": # Require that X be a carbon.
# Recall that we need to create a list identifying the atoms of this amine in the order (index_N, index_X, index_H1, index_H2)
amine_id = [nitrogen_index, index_x] # Because we removed the index of the non-H nitrogen neighbor,
for item in nitrogen_neighbors: # we know that nitrogen_neighbors[0] and nitrogen_neighbors[1]
amine_id.append(item) # correspond to the indices of the two neighboring hydrogens.
# Let's call this list a "primary-amine idenfitier."
# Having formed this identifying list, let's add this list to our growing list of "primary-amine indentifiers," Indices_of_primary_amines.
if len(nitrogen_neighbors) >=2 :
Indices_of_primary_amines.append(amine_id)
return Indices_of_primary_amines # Having identified all the primary amines in the pdb, let's return our list of "primary-amine identifiers."
def index_of_primary_amine_attached_to_S(self, pdb): # Because sulfonyl azides can be reduced to sulfonyl amines.
"""Identifies all the primary amine groups attached to sulfur atoms in a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified group.
"""
Indices_of_primary_amines = [] # Here's the list that will eventually contain the locations of all the primary amines in the pdb object.
for atom_index in pdb.all_atoms: # Now, we're going to look at each of the atoms in the pdb object. For each iteration of the loop, the variable "atom_index" is the
atom = pdb.all_atoms[atom_index] # "atom_index" was only the index of the atom. Now, the "atom" variable points to the atom object itself, rather than just the index.
if atom.element=="N": # Look and see if the atom is a nitrogen.
nitrogen_index = atom_index # If it is a nitrogen, then store the index of that nitrogen in the variable "nitrogen_index"
if pdb.number_of_neighors_of_element(nitrogen_index,"H") >= atom.number_of_neighbors()-1: # If it's a primary amine, this should be true
if atom.number_of_neighbors() == 3 or atom.number_of_neighbors() == 4: # A primary amine should have only three atoms connected to it (assuming it's not charged)
nitrogen_neighbors = atom.indecies_of_atoms_connecting[:] # Here's a list the indices of all the atoms connected to the nitrogen of the primary amine.
for neighbor_index in nitrogen_neighbors: # We're going to look at each neighbor. The "neighbor_index" variable contains the index of the
neighbor_atom = pdb.all_atoms[neighbor_index] # "neighbor_index" contained the index of the neighbor, but the variable "neighbor_atom" points
if neighbor_atom.element != "H": # So we're looking at the neighbor that is not a hydrogen, atom "X" above.
index_x = neighbor_index # We're going to save the index of this non-H atom in the variable "index_x"
nitrogen_neighbors.remove(index_x) # We're now removing the index of this non-H atom from the list, so that the only indices remaining
if pdb.all_atoms[index_x].element == "S": # Require that X be a sulfur.
# Recall that we need to create a list identifying the atoms of this amine in the order (index_N, index_X, index_H1, index_H2)
amine_id = [nitrogen_index, index_x] # Because we removed the index of the non-H nitrogen neighbor,
for item in nitrogen_neighbors: # we know that nitrogen_neighbors[0] and nitrogen_neighbors[1]
amine_id.append(item) # correspond to the indices of the two neighboring hydrogens.
if len(nitrogen_neighbors) >=2 :
Indices_of_primary_amines.append(amine_id)
return Indices_of_primary_amines # Having identified all the primary amines in the pdb, let's return our list of "primary-amine identifiers."
def index_of_secondary_amine(self, pdb):
"""Identifies all the secondary amine groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified secondary amine group.
"""
Indices_of_secondary_amines = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="N": # So looking for the nitrogen
nitrogen_index = atom_index
if pdb.number_of_neighors_of_element(nitrogen_index,"C") == 2 and pdb.number_of_neighors_of_element(nitrogen_index,"H") + pdb.number_of_neighors_of_element(nitrogen_index,"C") == atom.number_of_neighbors() and pdb.number_of_neighors_of_element(nitrogen_index,"H") >0: #so there are two C atoms attached to the nitrogen and at least 1 H
amine_id = [nitrogen_index]
nitrogen_neighbors = atom.indecies_of_atoms_connecting[:] # here's alist of all the N neighbors
# Now add in all the non-H neighbors
for neighbor_index in nitrogen_neighbors:
neighbor_atom = pdb.all_atoms[neighbor_index]
if neighbor_atom.element != "H":
amine_id.append(neighbor_index) # You only need the index of one of the non-H neighbors
# Now add the hydrogen atoms
for neighbor_index in nitrogen_neighbors:
neighbor_atom = pdb.all_atoms[neighbor_index]
if neighbor_atom.element == "H":
amine_id.append(neighbor_index) # You only need the index of one of the non-H neighbors
# Add the list
Indices_of_secondary_amines.append(amine_id)
return Indices_of_secondary_amines
def index_of_carboxylate(self, pdb): #The function accepts a pdb object as input
"""Identifies all the carboxylate groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified carboxylate group.
"""
Indices_of_carboxylates = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="C": # Look and see if the atom is a carbon
carbon_index = atom_index
if pdb.number_of_neighors_of_element(carbon_index,"O") == 2: # If it's a carboxylate, it will have two oxygens attached to it
if atom.number_of_neighbors() == 3: # A carboxylate should have only three atoms connected to it
carbon_neighbors = atom.indecies_of_atoms_connecting[:]
# remove anything that isn't an oxygen
for neighbor_index in carbon_neighbors: #Look at each neighbor and address right object to each index
neighbor_atom = pdb.all_atoms[neighbor_index]
if neighbor_atom.element != "O": carbon_neighbors.remove(neighbor_index)
# So now you have a list of the indicies of the two oxygens
if pdb.number_of_neighors_of_element(carbon_neighbors[0],"H") + pdb.number_of_neighors_of_element(carbon_neighbors[1],"H") <=1: # there should only be one hydrogen between the two oxygens
oxy1 = pdb.all_atoms[carbon_neighbors[0]]
oxy2 = pdb.all_atoms[carbon_neighbors[1]]
if oxy1.number_of_neighbors() + oxy2.number_of_neighbors() <=3: # There should be no more than 3 bonds between the two oxygens
hydro_index_1 = pdb.index_of_neighbor_of_element(carbon_neighbors[0],"H")
hydro_index_2 = pdb.index_of_neighbor_of_element(carbon_neighbors[1],"H")
if hydro_index_1 != -1 and hydro_index_2 == -1: # so carbon_neighbors[0] is the carboxylate alcohol
Indices_of_carboxylates.append([carbon_index,carbon_neighbors[1], carbon_neighbors[0], hydro_index_1])
elif hydro_index_1 == -1 and hydro_index_2 != -1: # so carbon_neighbors[1] is the carboxylate alcohol
Indices_of_carboxylates.append([carbon_index,carbon_neighbors[0], carbon_neighbors[1], hydro_index_2])
elif oxy1.number_of_neighbors() + oxy2.number_of_neighbors() == 2: # so if it's a ester, no go, but otherwise, order doesn't matter (carboxylate vs. carboxylic acid)
Indices_of_carboxylates.append([carbon_index,carbon_neighbors[0], carbon_neighbors[1], -1])
return Indices_of_carboxylates
def index_of_acylhalide(self, pdb): #The function accepts a pdb object as input
"""Identifies all the acyl halide groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified acyl halide group.
"""
Indices_of_acylhalides = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="C":
carbon_index = atom_index
if pdb.number_of_neighors_of_element(carbon_index,"O") == 1: # If it's an acylhalide, it will have one oxygen attached to it...
if pdb.number_of_neighors_of_element(carbon_index,"CL") == 1 or pdb.number_of_neighors_of_element(carbon_index,"BR") == 1 or pdb.number_of_neighors_of_element(carbon_index,"I") == 1: #...and one halide
if atom.number_of_neighbors() == 3:
carbon_neighbors = atom.indecies_of_atoms_connecting[:]
for neighbor_index in carbon_neighbors: #Look at each neighbor and address right object to each index
neighbor_atom = pdb.all_atoms[neighbor_index]
if neighbor_atom.element == "O":
oxygen_index = neighbor_index
elif neighbor_atom.element == "CL" or neighbor_atom.element == "BR" or neighbor_atom.element == "I":
halide_index = neighbor_index
acylhalide_id = [carbon_index, oxygen_index, halide_index]
Indices_of_acylhalides.append(acylhalide_id)
return Indices_of_acylhalides
def index_of_ester(self, pdb): #The function accepts a pdb object as input
"""Identifies all the ester groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified ester group.
"""
Indices_of_esters = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="C": # Look and see if the atom is a carbon
carbon_index = atom_index
if pdb.number_of_neighors_of_element(carbon_index,"O") == 2 and pdb.number_of_neighors_of_element(carbon_index,"C") == 1: # If it's a ester, it will have two oxygens attached to it and one carbon
if atom.number_of_neighbors() == 3: # A ester carbon should have only three atoms connected to it
carbon_neighbors = atom.indecies_of_atoms_connecting[:]
for neighbor_index in carbon_neighbors: #Remove non-O neighbors
neighbor_atom = pdb.all_atoms[neighbor_index]
if neighbor_atom.element != "O": #non-O neighbors are not included in the list
carbon_neighbors.remove(neighbor_index)
# So now you have a list of the indicies of the two oxygens
if pdb.number_of_neighors_of_element(carbon_neighbors[0],"C") + pdb.number_of_neighors_of_element(carbon_neighbors[1],"C") ==3: # there should only be one carbon between the two oxygens
oxy1 = pdb.all_atoms[carbon_neighbors[0]]
oxy2 = pdb.all_atoms[carbon_neighbors[1]]
oxy1_neighbors = oxy1.indecies_of_atoms_connecting[:]
oxy2_neighbors = oxy2.indecies_of_atoms_connecting[:]
oxy1_neighbors.remove(carbon_index)
oxy2_neighbors.remove(carbon_index)
if oxy1.number_of_neighbors() + oxy2.number_of_neighbors() == 3: # There should be 3 bonds between the two oxygens
if oxy1.number_of_neighbors() == 1 and oxy2.number_of_neighbors() == 2:
carbonyl_oxygen_index = carbon_neighbors[0]
non_carbonyl_oxygen_index = carbon_neighbors[1]
distal_carbon_index = oxy2_neighbors[0]
else:
carbonyl_oxygen_index = carbon_neighbors[1]
non_carbonyl_oxygen_index = carbon_neighbors[0]
distal_carbon_index = oxy1_neighbors[0]
# now check to see if it's a cyclical ester. If so, no go.
if pdb.in_same_ring(carbon_index, non_carbonyl_oxygen_index) == "FALSE": # so cyclical esters not allowed
Indices_of_esters.append([carbon_index, carbonyl_oxygen_index, non_carbonyl_oxygen_index, distal_carbon_index])
return Indices_of_esters
def index_of_carbonochloridate(self, pdb): #The function accepts a pdb object as input, the name could perhaps be misconceiving,the molecule is Cl-CO-OR
"""Identifies all the carbonochloridate groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified carbonochloridate group.
"""
Indices_of_carbonochloridate = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="C":
carbon_index = atom_index
if pdb.number_of_neighors_of_element(carbon_index,"O") == 2: # If it's a carbonochloridate, it will have one oxygen attached to it...
if pdb.number_of_neighors_of_element(carbon_index,"CL") == 1: #...and one chloride
if atom.number_of_neighbors() == 3:
carbon_neighbors = atom.indecies_of_atoms_connecting[:]
# Identify the Cl
for neighbor_index in carbon_neighbors:
neighbor_atom = pdb.all_atoms[neighbor_index]
if neighbor_atom.element == "CL":
chloride_index = neighbor_index
carbon_neighbors.remove(chloride_index)
# Identify carbonyl oxygen (list now contains only oxygens)
for neighbor_index in carbon_neighbors:
neighbor_atom = pdb.all_atoms[neighbor_index]
if neighbor_atom.number_of_neighbors() == 1:
oxygen_index = neighbor_index
carbon_neighbors.remove(oxygen_index)
# The only thing remaining is the ester oxygen
ester_oxygen = carbon_neighbors[0]
carboxylate_Cl_2_id = [carbon_index, oxygen_index, chloride_index]
Indices_of_carbonochloridate.append([ester_oxygen, carbon_index, oxygen_index, chloride_index])
return Indices_of_carbonochloridate
def index_of_acid_anhydride(self, pdb): #The function accepts a pdb object as input
"""Identifies all the acid anhydride groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified acid anhydride group.
"""
Indices_of_acid_anhydrides = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element == "O" and atom.number_of_neighbors() == 2 and pdb.number_of_neighors_of_element(atom_index,"C") == 2: # the ether oxygen
ether_oxygen_index = atom_index
ether_oxygen_neighbors = atom.indecies_of_atoms_connecting[:]
carbonyl_carbon_1_index = ether_oxygen_neighbors[0]
carbonyl_carbon_1 = pdb.all_atoms[carbonyl_carbon_1_index]
carbonyl_carbon_2_index = ether_oxygen_neighbors[1]
carbonyl_carbon_2 = pdb.all_atoms[carbonyl_carbon_2_index]
if carbonyl_carbon_1.number_of_neighbors() == 3 and carbonyl_carbon_2.number_of_neighbors() == 3:
if pdb.number_of_neighors_of_element(carbonyl_carbon_1_index,"C") == 1 and pdb.number_of_neighors_of_element(carbonyl_carbon_2_index,"C") == 1 and pdb.number_of_neighors_of_element(carbonyl_carbon_1_index,"O") == 2 and pdb.number_of_neighors_of_element(carbonyl_carbon_2_index,"O") == 2: # make sure the carbonyls are really carbonyls connected to ether oxygen
carbonyl_carbon_1_neighbors = carbonyl_carbon_1.indecies_of_atoms_connecting[:]
carbonyl_carbon_2_neighbors = carbonyl_carbon_2.indecies_of_atoms_connecting[:]
carbonyl_carbon_1_neighbors.remove(ether_oxygen_index)
carbonyl_carbon_2_neighbors.remove(ether_oxygen_index)
for neighbor_atom_index in carbonyl_carbon_1_neighbors:
neighbor_atom = pdb.all_atoms[neighbor_atom_index]
if neighbor_atom.element == "C":
carbonyl_carbon_1_neighbors.remove(neighbor_atom_index)
if neighbor_atom_index == ether_oxygen_index:
carbonyl_carbon_1_neighbors.remove(neighbor_atom_index)
for neighbor_atom_index in carbonyl_carbon_2_neighbors:
neighbor_atom = pdb.all_atoms[neighbor_atom_index]
if neighbor_atom.element == "C":
carbonyl_carbon_2_neighbors.remove(neighbor_atom_index)
if neighbor_atom_index == ether_oxygen_index:
carbonyl_carbon_2_neighbors.remove(neighbor_atom_index)
carbonyl_oxygen_1_index = carbonyl_carbon_1_neighbors[0]
carbonyl_oxygen_1 = pdb.all_atoms[carbonyl_oxygen_1_index]
carbonyl_oxygen_2_index = carbonyl_carbon_2_neighbors[0]
carbonyl_oxygen_2 = pdb.all_atoms[carbonyl_oxygen_2_index]
# now make sure the carbonyl oxygens are really carbonyl oxygens
if carbonyl_oxygen_1.element == "O" and carbonyl_oxygen_2.element == "O" and carbonyl_oxygen_1.number_of_neighbors() == 1 and carbonyl_oxygen_2.number_of_neighbors() == 1:
# now make sure it's not a cyclical acid anhydride
if pdb.in_same_ring(ether_oxygen_index, carbonyl_carbon_1_index) == "FALSE":
Indices_of_acid_anhydrides.append([ether_oxygen_index, carbonyl_carbon_1_index, carbonyl_oxygen_1_index, carbonyl_carbon_2_index, carbonyl_oxygen_2_index])
return Indices_of_acid_anhydrides
def index_of_isocyanate(self, pdb):
"""Identifies all the isocyanate groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified isocyanate group.
"""
# This will return the indices of the atoms, proximal to distal. R-X-N=C=O
isocyanateRoots = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="O" and len(atom.indecies_of_atoms_connecting)==1: # This is the terminal O
neighbor1_index = atom.indecies_of_atoms_connecting[0]
neighbor1_atom = pdb.all_atoms[neighbor1_index]
if neighbor1_atom.element=="C" and len(neighbor1_atom.indecies_of_atoms_connecting)==2: # middle C
indicies = []
for index in neighbor1_atom.indecies_of_atoms_connecting:
indicies.append(index)
indicies.remove(atom_index)
neighbor2_index = indicies[0]
neighbor2_atom = pdb.all_atoms[neighbor2_index]
if neighbor2_atom.element == "N" and len(neighbor1_atom.indecies_of_atoms_connecting)==2: # proximal N
# they have to be in a straight line
angle = atom.coordinates.angle_between_three_points(neighbor1_atom.coordinates, neighbor2_atom.coordinates) * 180 / math.pi
if abs(angle-180) < 10: # so it is in a straight line
indicies = []
for index in neighbor2_atom.indecies_of_atoms_connecting:
indicies.append(index)
indicies.remove(neighbor1_index)
neighbor3_index = indicies[0] # X described above
neighbor3_atom = pdb.all_atoms[neighbor3_index]
if neighbor3_atom.element == "C": # So X must be a carbon
# you need to get the atom attached to the isocyanate as well
isocyanateRoots.append([neighbor3_index, neighbor2_index, neighbor1_index, atom_index])
#print isocyanateRoots
return isocyanateRoots
def index_of_isothiocyanate(self, pdb):
"""Identifies all the isothiocyanate groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified isothiocyanate group.
"""
# This will return the indices of the atoms, proximal to distal. R-X-N=C=S
isothiocyanateRoots = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="S" and len(atom.indecies_of_atoms_connecting)==1: # This is the terminal S
neighbor1_index = atom.indecies_of_atoms_connecting[0]
neighbor1_atom = pdb.all_atoms[neighbor1_index]
if neighbor1_atom.element=="C" and len(neighbor1_atom.indecies_of_atoms_connecting)==2: # middle C
indicies = []
for index in neighbor1_atom.indecies_of_atoms_connecting:
indicies.append(index)
indicies.remove(atom_index)
neighbor2_index = indicies[0]
neighbor2_atom = pdb.all_atoms[neighbor2_index]
if neighbor2_atom.element == "N" and len(neighbor1_atom.indecies_of_atoms_connecting)==2: # proximal N
# they have to be in a straight line
angle = atom.coordinates.angle_between_three_points(neighbor1_atom.coordinates, neighbor2_atom.coordinates) * 180 / math.pi
if abs(angle-180) < 10: # so it is in a straight line
indicies = []
for index in neighbor2_atom.indecies_of_atoms_connecting:
indicies.append(index)
indicies.remove(neighbor1_index)
neighbor3_index = indicies[0] # X described above
neighbor3_atom = pdb.all_atoms[neighbor3_index]
if neighbor3_atom.element == "C": # So X must be a carbon
# you need to get the atom attached to the isothiocyanate as well
isothiocyanateRoots.append([neighbor3_index, neighbor2_index, neighbor1_index, atom_index])
return isothiocyanateRoots
def index_of_hydrogen(self, pdb): # Identify an hydrogen
"""Identifies all the hydrogen atoms of a specified molecular model, together with the heavy atoms to which they are bound.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified heavy-atom-hydrogen group.
"""
# Think R - X - H (1 - 2 - 3)
hydrogenRoots=[]
for hydrogen_index in pdb.all_atoms:
hydrogen = pdb.all_atoms[hydrogen_index]
if hydrogen.element == "H" and hydrogen.number_of_neighbors() == 1:
linker_index = hydrogen.indecies_of_atoms_connecting[0]
hydrogenRoots.append([linker_index, hydrogen_index])
return hydrogenRoots
def index_of_tertiary_halide(self, pdb):
"""Identifies all the tertiary halide groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified tertiary halide group.
"""
tertiary_halideRoots = []
for atom_index in pdb.all_atoms:
atom = pdb.all_atoms[atom_index]
if atom.element=="CL" or atom.element=="BR" or atom.element=="I": # This is the halide
neighbor1_index = atom.indecies_of_atoms_connecting[0]
neighbor1_atom = pdb.all_atoms[neighbor1_index]
if neighbor1_atom.element=="C" and len(neighbor1_atom.indecies_of_atoms_connecting)==4: # The halide is bonded to an sp3-hybridized carbon
if pdb.number_of_neighors_of_element(neighbor1_index,"H") == 0: # So there are no hydrogens connected to the carbon (tertiary)
carbon_neighbors = neighbor1_atom.indecies_of_atoms_connecting[:]
carbon_neighbors.remove(atom_index) # So only non-halide neighbors are present
tertiary_halideRoots.append([carbon_neighbors[0], carbon_neighbors[1], carbon_neighbors[2], neighbor1_index, atom_index])
return tertiary_halideRoots
def index_of_secondary_halide(self, pdb):
"""Identifies all the secondary halide groups of a specified molecular model.
Arguments:
pdb -- A molecular model (pymolecule.Molecule).
Returns:
A list of lists, where each list contains the indices (int) of the atoms present in an identified secondary halide group.
"""