-
Notifications
You must be signed in to change notification settings - Fork 18
/
GOPY.py
2410 lines (2305 loc) · 130 KB
/
GOPY.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
# -----------------------------------------------------------
# GOPY - A tool for building 2D graphene-based computational models
#
# Released under GNU Public License (GPL)
# email [email protected]
# -----------------------------------------------------------
import os
from scipy import spatial
import random
import math
import numpy as np
import sys
class Typical_Bond:
def __init__(self, length, specific_id):
self.length = length
self.identity = specific_id
CX_CX_sg = Typical_Bond(1.418, "CXCXGGGGGG")
CX_CY_sg_C1A = Typical_Bond(1.418, "CXCYGGGC1A")
CX_CY_sg_H1A = Typical_Bond(1.418, "CXCYGGGH1A")
CX_CY_sg_E1A = Typical_Bond(1.418, "CXCYGGGE1A")
CX_COOH = Typical_Bond(1.520, "CXC4GGGC1A")
CY_COOH = Typical_Bond(1.520, "CYC4C1AC1A")
CX_OH = Typical_Bond(1.49, "CXOLGGGH1A")
CY_OH = Typical_Bond(1.49, "CYOLH1AH1A")
CX_OS = Typical_Bond(1.460, "CXOEGGGE1A")
CY_OS = Typical_Bond(1.460, "CYOEE1AE1A")
C4_OOH = Typical_Bond(1.210, "C4OJC1AC1A")
C4_OH = Typical_Bond(1.32 ,"C4OKC1AC1A")
O_H = Typical_Bond(0.967, "OLHKH1AH1A")
O_H_2 = Typical_Bond(0.967, "OKHKC1AC1A")
bond_list_1 = [CX_CX_sg, CX_CY_sg_C1A, CX_CY_sg_E1A, CX_CY_sg_H1A, CX_COOH, CY_COOH, CX_OH, CY_OH, CX_OS, CY_OS, CX_OH, CY_OH, C4_OOH, C4_OH, O_H, O_H_2]
CX_N2 = Typical_Bond(1.475, "CXN2GGGP1A")
CY_N2 = Typical_Bond(1.475, "CYN2P1AP1A")
N2_C6 = Typical_Bond(1.475, "N2C6P1AP1A")
C6_C5 = Typical_Bond(1.540, "C6C5P1AP1A")
C5_O2 = Typical_Bond(1.430, "C5O2P1AP1A")
O2_C4 = Typical_Bond(1.430, "O2C4P1AP1A")
C4_C3 = Typical_Bond(1.540, "C4C3P1AP1A")
C3_O1 = Typical_Bond(1.430, "C3O1P1AP1A")
O1_C2 = Typical_Bond(1.430, "O1C2P1AP1A")
C2_C1 = Typical_Bond(1.540, "C2C1P1AP1A")
C1_N1 = Typical_Bond(1.475, "C1N1P1AP1A")
N2_H15 = Typical_Bond(1.01, "N2H15P1AP1A")
C6_H14 = Typical_Bond(1.09, "C6H14P1AP1A")
C6_H13 = Typical_Bond(1.09, "C6H13P1AP1A")
C5_H12 = Typical_Bond(1.09, "C5H12P1AP1A")
C5_H11 = Typical_Bond(1.09, "C5H11P1AP1A")
C4_H10 = Typical_Bond(1.09, "C4H10P1AP1A")
C4_H9 = Typical_Bond(1.09, "C4H9P1AP1A")
C3_H8 = Typical_Bond(1.09, "C3H8P1AP1A")
C3_H7 = Typical_Bond(1.09, "C3H7P1AP1A")
C2_H6 = Typical_Bond(1.09, "C2H6P1AP1A")
C2_H5 = Typical_Bond(1.09, "C2H5P1AP1A")
C1_H4 = Typical_Bond(1.09, "C1H4P1AP1A")
C1_H3 = Typical_Bond(1.09, "C1H3P1AP1A")
N1_H2 = Typical_Bond(1.01, "N1H2P1AP1A")
N1_H1 = Typical_Bond(1.01, "N1H1P1AP1A")
bond_list_2 = [CX_CX_sg, CX_CY_sg_C1A, CX_CY_sg_E1A, CX_CY_sg_H1A, CX_COOH, CY_COOH, CX_OH, CY_OH, CX_OS, CY_OS, CX_OH, CY_OH, C4_OOH, C4_OH, O_H, O_H_2, CX_N2, CY_N2, N2_C6, C6_C5, C5_O2, O2_C4, C4_C3, C3_O1, O1_C2, C2_C1, C1_N1, N2_H15, C6_H14, C6_H13, C5_H12, C5_H11, C4_H10, C4_H9, C3_H8, C3_H7, C2_H6, C2_H5, C1_H4, C1_H3, N1_H2, N1_H1]
gen_NH = Typical_Bond(1.010, "NH")
gen_NO = Typical_Bond(1.060, "NO")
gen_NC = Typical_Bond(1.475, "NC")
gen_NN = Typical_Bond(1.450, "NN")
gen_OH = Typical_Bond(0.970, "OH")
gen_OC = Typical_Bond(1.160, "OH")
gen_OO = Typical_Bond(1.490, "OO")
gen_CH = Typical_Bond(1.090, "CH")
gen_CC = Typical_Bond(1.540, "CC")
gen_HH = Typical_Bond(0.740, "HH")
bond_list_3 = [gen_NH, gen_NO, gen_NC, gen_NN, gen_OH, gen_OC, gen_OO, gen_CH, gen_CC, gen_HH]
class Atom:
"""
This is the Atom class. All atom objects are expected to contain the usual parameters
written in a PDB file: atom number, atom name, residue name, residue number and XYZ
coordinates.
"""
def __init__(self, atom_number, atom_name, residue_name, residue_number, x, y, z):
self.atom_number = atom_number
self.atom_name = atom_name
self.residue_name = residue_name
self.residue_number = residue_number
self.x = x
self.y = y
self.z = z
### PRSTINE GRAPHENE ###
def add_atom(atom_list, atom_name, residue_name, residue_number, x, y, z, atom_number):
"""
Adds an atom to the atom list. The atom comes with all the information usually found in a PDB file.
"""
atom_list.append(Atom(atom_number, atom_name, residue_name, residue_number, x, y, z))
return atom_list
def remove_atom(atom_list, atom):
"""
Removes an atom from the atom list.
"""
del atom_list[atom.atom_number - 1]
del atom
return atom_list
def generate_pristine_graphene(x_dim, y_dim, filename1):
"""
This is the function used to generate a pristine graphene sheet. To fit PDB standards, all
distances are expressed in Angstroms.
"""
y_number = round(y_dim / 1.228)
x_number = int(x_dim / 2.127)
x_addition = (x_dim / 2.127 ) % 1
list_of_coords = []
a = 0
b = 0
c = 0
list_of_coords = fill_row(list_of_coords, y_number, a,b,c, [], 5, prev = False)
for i in range(1,x_number):
if (i == x_number-1):
if (i % 2 == 1):
a += 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [], 6, prev = True)
fill_hexagon(list_of_coords, -1.228, b, c, [0, 1, 3, 4, 5], full=6, prev=False)
if (i % 2 == 0):
a -= 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [], 6, prev = False)
fill_hexagon(list_of_coords, y_number*1.228, b, c, [0, 1, 3, 4, 5], full=6, prev=False)
elif (i % 2 == 1):
a += 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [], 6, prev = True)
elif (i % 2 == 0):
a -= 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [], 6, prev = False)
list_x_steps = [0, 0.33, 0.66, 1]
x_step = min(list_x_steps, key=lambda x:abs(x-x_addition))
if (x_step == 0.33):
list_of_coords = fill_row(list_of_coords, y_number, 0, 0, 0, [], 6, prev = False)
fill_hexagon(list_of_coords, y_number*1.228, 0, 0, [0, 1, 2, 3, 4], full=6, prev=False)
elif (x_step == 0.66):
if (x_number % 2 == 1):
a += 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [2], 6, prev = True)
elif (x_number % 2 == 0):
a -= 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [2], 6, prev = False)
elif (x_step == 1):
if (x_number % 2 == 1):
a += 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [], 6, prev = True)
elif (x_number % 2 == 0):
a -= 1.228
b += 2.127
list_of_coords = fill_row(list_of_coords, y_number, a, b, c, [], 6, prev = False)
writepdb3(list_of_coords, filename1)
print('done.')
return list_of_coords
def writepdb3(list_of_coords, name):
"""
This is the function used to write a PDB file using the list of coordinates from generate_pristine_graphene.
"""
list_of_coords2 = []
for elem in range(len(list_of_coords)):
if (list_of_coords[elem] not in list_of_coords2):
list_of_coords2.append(list_of_coords[elem])
os.chdir(os.getcwd())
if ((".pdb" not in name) and (".PDB" not in name)):
string = str(name) + ".pdb"
else:
string = str(name)
with open(string, 'a') as le_file:
for element in range(len(list_of_coords)):
temp_atom = Atom(element, "CX", "GGG", element, list_of_coords[element][0], list_of_coords[element][1], list_of_coords[element][2])
line = "ATOM" + lw2(7, str(temp_atom.atom_number)) + str(temp_atom.atom_number) + lw(4, str(temp_atom.atom_name)) + str(temp_atom.atom_name) + " " + str(temp_atom.residue_name) + lw(6, str(temp_atom.residue_number)) + str(temp_atom.residue_number) + lw(12, str(temp_atom.x)) + str(temp_atom.x) + lw(8, str(temp_atom.y)) + str(temp_atom.y) + lw(8, str(temp_atom.z)) + str(temp_atom.z) + " 1.00 0.00 "
del temp_atom
le_file.write(line + '\n')
return list_of_coords
def lw2(max_no, str_obj):
"""Function used to add white spaces when writing the PDB file from writepdb3."""
x = max_no - len(str_obj)
y = 0
string = ''
for y in range(x):
string = string + ' '
return string
def fill_row(list_of_coords, halves, a,b,c, takeout, full=6, prev = False):
"""Used to fill a row of hexagons given a starting point XYZ coords. (here a,b,c) and the number of "halves" of a hexagon to add."""
for i in range(int(halves / 2 )):
list_of_coords = fill_hexagon(list_of_coords, a, b, c, takeout, full, prev)
a += 2.456
if ((halves % 2 == 1) and (prev == False)):
takeout.append(3)
takeout.append(4)
list_of_coords = fill_hexagon(list_of_coords, a, b, c, takeout, full, prev)
return list_of_coords
def toString(triplet):
return([str(triplet[0]), str(triplet[1]), str(triplet[2])])
def check_me(triplet, list_of_coords):
"""Used to make sure atoms are within range of where they are supposed to be - and to provide a small error tolerance if necessary."""
c = True
for element in list_of_coords:
if (float(triplet[0])*0.99 <= float(element[0]) <= float(triplet[0])*1.01):
if (float(triplet[1])*0.99 <= float(element[1]) <= float(triplet[1])*1.01):
if (float(triplet[2])*0.99 <= float(element[2]) <= float(triplet[2])*1.01):
c = False
return c
def fill_hexagon(list_of_coords, a, b, c, takeout, full = 6, prev = False):
"""Given the XYZ coordinates (here a,b,c) of a carbon atom, this function is used to find the coordinates of the other atoms making up the hexagon.
Takeout takes out one of the 6 atoms making up the hexagon. "prev" is used to know whether the row is an odd number row or not."""
list_of_vertices = [[a, b, c], [a, b + 1.418, c], [a + 1.228, b + 2.127, c], [a + 2.456, b + 1.418, c], [a + 2.456, b, c], [a + 1.228, b - 0.705, c]]
for element in range(full):
if (check_me(list_of_vertices[element], list_of_coords) and (int(element) not in takeout)):
list_of_coords.append(list_of_vertices[element])
if ((prev == True) and (check_me([a - 1.228, b - 0.705, 0], list_of_coords))):
if ((2 not in takeout) and (check_me([a - 1.228, b + 2.127, 0], list_of_coords))):
list_of_coords.append([a - 1.228, b + 2.127, 0])
list_of_coords.append([a - 1.228, b - 0.705, 0])
for elem in range(len(list_of_coords)):
list_of_coords[elem] = ["%.3f" % float(elem2) for elem2 in list_of_coords[elem]]
return list_of_coords
def pristine_coords_to_objects(list_of_coords):
"""Function used to take the list of coordinates and add an Atom object instance for each coordinate triplet"""
list_of_objects = []
for element in range(len(list_of_coords)):
list_of_objects.append(Atom(element, "CX", "GGG", element, list_of_coords[element][0], list_of_coords[element][1], list_of_coords[element][2]))
return list_of_objects
def read_in_graphene(pdbfile):
"""Reads in a PG layer where C atom name is 'CX', residue name is 'GGG'"""
with open(pdbfile, "r") as f:
filedata = f.read()
filedata = filedata.replace("C GRA X", "CX GGG ")
content = filedata.splitlines()
atom_lines = [x.split() for x in content if (('ATOM' in str(x)) and ('GGG' in str(x)) and ('CX' in str(x)))]
atoms = [Atom(int(str(atom_lines[x][1])), str(atom_lines[x][2]), str(atom_lines[x][3]), int(str(atom_lines[x][1])), float(str(atom_lines[x][5])), float(str(atom_lines[x][6])), float(str(atom_lines[x][7]))) for x in range(len(atom_lines))]
return atoms
def read_in_GO(pdbfile):
"""Reads in a GO layer where C atom name is "CX", residue name is 'GGG'
Expected carboyl residue name: C1A; Expected epoxy residue name: E1A; Expected hydroxyl residue name: H1A;"""
with open(pdbfile, "r") as f:
filedata = f.read()
filedata = filedata.replace("C GRA X", "CX GGG ")
content = filedata.splitlines()
atom_lines = [x.split() for x in content if (('ATOM' in str(x)) and (('C1A' in str(x)) or ('E1A' in str(x)) or ('H1A' in str(x)) or ('GGG' in str(x))))]
atoms = [Atom(int(str(atom_lines[x][1])), str(atom_lines[x][2]), str(atom_lines[x][3]), int(str(atom_lines[x][4])), float(str(atom_lines[x][5])), float(str(atom_lines[x][6])), float(str(atom_lines[x][7]))) for x in range(len(atom_lines))]
return atoms
def calculate_3D_distance_2_atoms(atom1, atom2):
return spatial.distance.euclidean((atom1.x, atom1.y, atom1.z), (atom2.x, atom2.y, atom2.z))
def calculate_3D_distance_2_centers(x1, y1, z1, x2, y2, z2):
return spatial.distance.euclidean((x1, y1, z1), (x2, y2, z2))
def get_bond_id(atom1, atom2):
"""Creates bond_id of two atoms, taking into account their residue names and atom_names."""
id1 = [str(atom1.atom_name) + str(atom2.atom_name) + str(atom1.residue_name) + str(atom2.residue_name), str(atom2.atom_name) + str(atom1.atom_name) + str(atom2.residue_name) + str(atom1.residue_name)]
return id1
def check_bond(atom1, atom2):
"""A potential bond between two atoms is verified in the bond_list taking into account its id resulting from get_bond_id and distance between the two atoms."""
check = False
for bond in bond_list:
if (((bond.identity == get_bond_id(atom1, atom2)[0]) or (bond.identity == get_bond_id(atom1, atom2)[1])) and 0.975 * bond.length <= calculate_3D_distance_2_atoms(atom1, atom2) <= 1.025 * bond.length):
check = True
break
return check
def check_if_no_bond(atom1, atom2, bond_list, bond_generic):
"""Similar to check_bond, but using two specified bond_lists from the three available. Used when placing hydrogen atoms in add_rGO_PEG_NH2"""
check = False
for bond in bond_list:
if ((bond.identity == get_bond_id(atom1, atom2)[0]) or (bond.identity == get_bond_id(atom1, atom2)[1]) and calculate_3D_distance_2_atoms(atom1, atom2) > 1.05 * bond.length):
check = True
for bond in bond_generic:
if (((atom1.atom_name[0] + atom2.atom_name[0]) == bond.identity) or (atom2.atom_name[0] + atom1.atom_name[0] == bond.identity) and (calculate_3D_distance_2_atoms(atom1, atom2) > 1.05 * bond.length)):
check = True
return check
def check_connected(chosen_atom, identified_bonds):
"""Based on the get_bond_id output, determine whether an atom is connected to a functional group. Used when removing functional groups."""
check = False
for bond in identified_bonds:
if (("E1AE1A" in str(get_bond_id(chosen_atom, bond[0])[0])) or ("C1AC1A" in str(get_bond_id(chosen_atom, bond[0])[0])) or ("H1AH1A" in str(get_bond_id(chosen_atom, bond[0])[0])) or ("P1AP1A" in str(get_bond_id(chosen_atom, bond[0])[0]))):
check = True
return check
def identify_bonds(chosen_atom, atom_list):
"""The identify_bonds function finds the neighbours of the given atom in a distance based manner.
This distance is different for when placing GO groups to when placing PEG-NH2 chains and also when placing hydrogens vs the skeleton of the PEG-NH2 chains.
The function then uses the check_bond function to identify valid bonds."""
list_of_hydrogens = ['H15', 'H14', 'H13', 'H12', 'H11', 'H10', 'H9', 'H8', 'H7', 'H6', 'H5', 'H4', 'H3', 'H2', 'H1']
if ((chosen_atom.atom_name not in list_of_hydrogens) and (chosen_atom.residue_name != "P1A")):
nearby_atoms_crude = [atom for atom in atom_list if ((abs(chosen_atom.x - atom.x) <= 2) and (abs(chosen_atom.y - atom.y) <= 2) and (abs(chosen_atom.z - atom.z) <= 2))]
nearby_atoms = [atom for atom in nearby_atoms_crude if (0 < calculate_3D_distance_2_atoms(chosen_atom,atom) <= 2)]
identified_bonds = [[atom, calculate_3D_distance_2_atoms(chosen_atom, atom)] for atom in nearby_atoms if (check_bond(chosen_atom, atom) == True)]
elif ((chosen_atom.atom_name not in list_of_hydrogens) and (chosen_atom.residue_name == "P1A")):
nearby_atoms_crude = [atom for atom in atom_list if ((abs(chosen_atom.x - atom.x) <= 2) and (abs(chosen_atom.y - atom.y) <= 2) and (abs(chosen_atom.z - atom.z) <= 2))]
nearby_atoms = [atom for atom in nearby_atoms_crude if (0 < calculate_3D_distance_2_atoms(chosen_atom,atom) <= 1.8)]
identified_bonds = [[atom, calculate_3D_distance_2_atoms(chosen_atom, atom)] for atom in nearby_atoms if (check_bond(chosen_atom, atom) == True)]
else:
nearby_atoms_crude = [atom for atom in atom_list if ((abs(chosen_atom.x - atom.x) <= 1.6) and (abs(chosen_atom.y - atom.y) <= 1.6) and (abs(chosen_atom.z - atom.z) <= 1.6))]
nearby_atoms = [atom for atom in nearby_atoms_crude if (0 < calculate_3D_distance_2_atoms(chosen_atom,atom) <= 1.6)]
identified_bonds = [[atom, calculate_3D_distance_2_atoms(chosen_atom, atom)] for atom in nearby_atoms if (check_bond(chosen_atom, atom) == True)]
for elements in nearby_atoms:
if (check_if_no_bond(chosen_atom, elements, bond_list, bond_list_3) == True):
nearby_atoms.remove(elements)
if (len(nearby_atoms) == len(identified_bonds)):
return identified_bonds
else:
return []
def top_or_down():
"""Random top or below draw."""
ct = random.randint(1,2)
if (ct == 1):
return 1
else:
return -1
def get_map_anywhere(atom_list):
"""Creates a list of all available atoms which are not connected to functional groups."""
anywhere_map = [atom for atom in atom_list if (check_connected(atom, identify_bonds(atom, atom_list)) == False)]
return anywhere_map
def get_map_central(atom_list):
"""Creates a list of all available atoms which are not connected to a functional group and do not represent an edge of any kind (thus 3 bonds required)."""
central_map = [atom for atom in atom_list if ((len(identify_bonds(atom, atom_list)) == 3) and (check_connected(atom, identify_bonds(atom, atom_list)) == False))]
return central_map
def get_map_edge(atom_list):
"""Creates a list of all edge atoms (thus 1 or 2 bonds) which are not connected to functional groups."""
edge_map = [atom for atom in atom_list if ((0 < len(identify_bonds(atom, atom_list)) < 3) and (check_connected(atom, identify_bonds(atom, atom_list)) == False))]
return edge_map
def pick_to_add(no_cooh, no_epoxy, no_hydroxyl):
"""Random pick."""
make_list = ["carboxyl", "epoxy", "hydroxyl"]
if (no_cooh == 0):
make_list.remove("carboxyl")
if (no_epoxy == 0):
make_list.remove("epoxy")
if (no_hydroxyl == 0):
make_list.remove("hydroxyl")
if (make_list == []):
return "done"
else:
return make_list
def create_GO(init_file, no_COOH, no_epoxy, no_OH, filename1):
"""Function used to create the GO morphology. The three functional groups are placed in no specific order, picking the next to be added at random.
One may want to place COOH groups first due to limited space, however this is rarely an issue. 50 attempts are made for each placement. After 50 attempts
the placement is considered done (despite there being no successful placement) and the function moves to the next functional group to place.
After placement, there is a rewriting of the PDB file where each CX atom connected to a functional group becomes a CY atom and new atom numbers are given
to take into account the CX atoms replaced by CY. """
global atoms
global bond_list
bond_list = bond_list_1
atoms = read_in_graphene(init_file)
global anywhere_map
anywhere_map = get_map_anywhere(atoms)
global edge_map
edge_map = get_map_edge(atoms)
list_residue_numbers = [x.residue_number for x in atoms]
added_functional_groups = max(list_residue_numbers)
must_add = no_COOH + no_epoxy + no_OH
while (must_add > 0):
print("Left to add: ", "cooh: ", no_COOH, "epoxy: ", no_epoxy, "hydroxyl: ", no_OH)
chosen = random.choice(pick_to_add(no_COOH, no_epoxy, no_OH))
if (chosen == "carboxyl"):
attempt = 0
while (attempt < 50):
old_length = len(atoms)
new_atoms = add_carboxyl(random_pick_spot("carboxyl", edge_map, anywhere_map), atoms, added_functional_groups, top_or_down())
if (old_length != len(new_atoms)):
atoms = new_atoms
added_functional_groups += 1
must_add -= 1
no_COOH -= 1
attempt = 1888
else:
attempt += 1
if (attempt == 50):
must_add = -1
elif (chosen == "epoxy"):
attempt = 0
while (attempt < 50):
old_length = len(atoms)
new_atoms = add_epoxy(random_pick_spot("epoxy", edge_map, anywhere_map), atoms, added_functional_groups, top_or_down())
if (old_length != len(new_atoms)):
atoms = new_atoms
added_functional_groups += 1
must_add -= 1
no_epoxy -= 1
attempt = 1888
else:
attempt += 1
if (attempt == 50):
must_add = -1
elif (chosen == "hydroxyl"):
attempt = 0
while (attempt < 50):
old_length = len(atoms)
new_atoms = add_hydroxyl(random_pick_spot("hydroxyl", edge_map, anywhere_map), atoms, added_functional_groups, top_or_down())
if (old_length != len(new_atoms)):
atoms = new_atoms
added_functional_groups += 1
must_add -= 1
no_OH -=1
attempt = 1888
else:
attempt += 1
if (attempt == 50):
must_add = -1
atno = 1
new_list = []
for atom in atoms:
if (atom.atom_name == "CX"):
New_CX = Atom(atno, "CX", "GGG", atno, atom.x, atom.y, atom.z)
new_list.append(New_CX)
atno += 1
for atom in atoms:
if (atom.atom_name == "C4"):
check = False
for atom_CY in atoms:
if ((atom_CY.atom_name == "CY") and (atom_CY.residue_name == "C1A") and (atom_CY.residue_number == atom.residue_number)):
for atom_OJ in atoms:
if ((atom_OJ.atom_name == "OJ") and (atom_OJ.residue_name == "C1A") and (atom_OJ.residue_number == atom.residue_number)):
for atom_OK in atoms:
if ((atom_OK.atom_name == "OK") and (atom_OK.residue_name == "C1A") and (atom_OK.residue_number == atom.residue_number)):
for atom_HK in atoms:
if ((atom_HK.atom_name == "HK") and (atom_HK.residue_name == "C1A") and (atom_HK.residue_number == atom.residue_number)):
New_CY = Atom(atno + 0, "CY", "C1A", atom.residue_number, atom_CY.x, atom_CY.y, atom_CY.z )
New_C4 = Atom(atno + 1, "C4", "C1A", atom.residue_number, atom.x, atom.y, atom.z)
New_OJ = Atom(atno + 2, "OJ", "C1A", atom.residue_number, atom_OJ.x, atom_OJ.y, atom_OJ.z)
New_OK = Atom(atno + 3, "OK", "C1A", atom.residue_number, atom_OK.x, atom_OK.y, atom_OK.z)
New_HK = Atom(atno + 4, "HK", "C1A", atom.residue_number, atom_HK.x, atom_HK.y, atom_HK.z)
atno += 5
new_list.append(New_CY); new_list.append(New_C4); new_list.append(New_OJ); new_list.append(New_OK); new_list.append(New_HK);
check = True
break
if (check == True):
break
if (check == True):
break
if (check == True):
break
elif (atom.atom_name == "OE"):
check = False
for atom_CY in atoms:
if ((atom_CY.atom_name == "CY") and (atom_CY.residue_name == "E1A") and (atom_CY.residue_number == atom.residue_number)):
for atom_CY2 in atoms:
if ((atom_CY2.atom_name == "CZ") and (atom_CY2.residue_name == "E1A") and (atom_CY2.residue_number == atom.residue_number) and (atom_CY2 != atom_CY)):
New_CY = Atom( atno + 0, "CY", "E1A", atom.residue_number, atom_CY.x, atom_CY.y, atom_CY.z)
New_CY2 = Atom(atno + 1, "CZ", "E1A", atom.residue_number, atom_CY2.x, atom_CY2.y, atom_CY2.z)
New_OE = Atom( atno + 2, "OE", "E1A", atom.residue_number, atom.x, atom.y, atom.z)
atno += 3
new_list.append(New_CY); new_list.append(New_CY2); new_list.append(New_OE);
check = True
break
if (check == True):
break
elif (atom.atom_name == "OL"):
check = False
for atom_CY in atoms:
if ((atom_CY.atom_name == "CY") and (atom_CY.residue_name == "H1A") and (atom_CY.residue_number == atom.residue_number)):
for atom_HK in atoms:
if ((atom_HK.atom_name == "HK") and (atom_HK.residue_name == "H1A") and (atom_HK.residue_number == atom.residue_number)):
New_CY = Atom(atno + 0, "CY", "H1A", atom.residue_number, atom_CY.x, atom_CY.y, atom_CY.z)
New_OL = Atom(atno + 1, "OL", "H1A", atom.residue_number, atom.x, atom.y, atom.z)
New_HK = Atom(atno + 2, "HK", "H1A", atom.residue_number, atom_HK.x, atom_HK.y, atom_HK.z)
atno += 3
new_list.append(New_CY); new_list.append(New_OL); new_list.append(New_HK);
check = True
break
if (check == True):
break
atoms = new_list.copy()
writepdb(atoms, filename1)
sum_c1a = 0; sum_e1a = 0; sum_h1a = 0; sum_ggg = 0
for atom in atoms:
if (atom.residue_name == "C1A"):
sum_c1a += 1
elif (atom.residue_name == "E1A"):
sum_e1a += 1
elif (atom.residue_name == "H1A"):
sum_h1a += 1
elif (atom.residue_name == "GGG"):
sum_ggg += 1
print("Placed:")
print("carboxyl: ", sum_c1a/5)
print("epoxy: ", sum_e1a/3)
print("hydroxyl: ", sum_h1a/3)
print("graphene atoms (CX - GGG) left: ", sum_ggg)
return 'done.'
def random_pick_spot(spot, map_edge, map_anywhere):
if (spot == "carboxyl"):
atom = random.choice(map_edge)
elif (spot == "epoxy"):
atom = random.choice(map_anywhere)
elif (spot == "hydroxyl"):
atom = random.choice(map_anywhere)
return atom
def add_carboxyl(atom, atom_list, added_functional_groups, ct):
"""Function used to add carboxyl atoms. Atom placement follows a geometrical approach.
Atom - chosen CX atom. Atom_list - the atom list so far. Added_functional_groups - the number of functional groups added so far. Ct - the random top or below coordinate.
Adds 4 atoms and replaces 1 (5 in total).
"""
global anywhere_map
global edge_map
current_size = len(atom_list)
placed = 0
alpha = random.randint(0,359)
x = atom.x
y = atom.y
z = atom.z
while (placed <= 359):
alpha += 1
carbon_atom = Atom(current_size + 1, 'C4', 'C1A', str(added_functional_groups + 1), float("{0:.3f}".format(x)), float("{0:.3f}".format(y)), float("{0:.3f}".format(ct * 1.52 + z)))
atom_list.append(carbon_atom)
if ((len(identify_bonds(carbon_atom, atom_list)) == 1) and (identify_bonds(carbon_atom, atom_list)[0][0].atom_number == atom.atom_number)):
h = math.sin(math.radians(60)) * 1.20
oxygen_atom_1 = Atom(current_size + 2, 'OJ', 'C1A', str(added_functional_groups + 1), float("{0:.3f}".format(carbon_atom.x - math.cos(math.radians(alpha)) * h)), float("{0:.3f}".format(carbon_atom.y - math.sin(math.radians(alpha)) * h)), float("{0:.3f}".format(carbon_atom.z + ct * math.cos(math.radians(60)) * 1.20)))
atom_list.append(oxygen_atom_1)
if ((len(identify_bonds(oxygen_atom_1, atom_list)) == 1) and (identify_bonds(oxygen_atom_1, atom_list)[0][0].atom_number == carbon_atom.atom_number)):
h = math.sin(math.radians(60)) * 1.34
oxygen_atom_2 = Atom(current_size + 3, 'OK', 'C1A', str(added_functional_groups + 1), float("{0:.3f}".format(carbon_atom.x - math.cos(math.radians(alpha + 180)) * h)), float("{0:.3f}".format(carbon_atom.y - math.sin(math.radians(alpha+180)) * h)), float("{0:.3f}".format(carbon_atom.z + ct * math.cos(math.radians(60)) * 1.34)) )
atom_list.append(oxygen_atom_2)
if ((len(identify_bonds(oxygen_atom_2, atom_list)) == 1) and (identify_bonds(oxygen_atom_2, atom_list)[0][0].atom_number == carbon_atom.atom_number)):
hydrogen_atom = Atom(current_size + 4, 'HK', 'C1A', str(added_functional_groups + 1), float("{0:.3f}".format(oxygen_atom_2.x)), float("{0:.3f}".format(oxygen_atom_2.y)), float("{0:.3f}".format(oxygen_atom_2.z+ct*0.98)))
atom_list.append(hydrogen_atom)
if ((len(identify_bonds(hydrogen_atom, atom_list)) == 1) and (identify_bonds(hydrogen_atom, atom_list)[0][0].atom_number == oxygen_atom_2.atom_number)):
placed = 888
if atom in edge_map: edge_map.remove(atom)
if atom in anywhere_map: anywhere_map.remove(atom)
CY = Atom(atom.atom_number, 'CY', 'C1A', carbon_atom.residue_number, atom.x, atom.y, atom.z)
atom_list.append(CY)
atom_list.remove(atom)
del atom
else:
placed += 5
del hydrogen_atom
del atom_list[current_size + 3]
del oxygen_atom_2
del atom_list[current_size + 2]
del oxygen_atom_1
del atom_list[current_size + 1]
del carbon_atom
del atom_list[current_size + 0]
else:
placed += 5
del oxygen_atom_2
del atom_list[current_size + 2]
del oxygen_atom_1
del atom_list[current_size + 1]
del carbon_atom
del atom_list[current_size + 0]
else:
placed += 5
del oxygen_atom_1
del atom_list[current_size + 1]
del carbon_atom
del atom_list[current_size + 0]
else:
placed += 5
del carbon_atom
del atom_list[current_size + 0]
return atom_list
def add_epoxy(atom, atom_list, added_functional_groups, ct):
"""Function used to add epoxy atoms. Atom placement follows a geometrical approach.
Atom - chosen CX atom. Atom_list - the atom list so far. Added_functional_groups - the number of functional groups added so far. Ct - the random top or below coordinate.
Ads 1 atom and replaces 2 (3 in total)."""
global anywhere_map
global edge_map
current_size = len(atom_list)
list_of_n = [x[0] for x in identify_bonds(atom, atom_list) if (x[0].atom_name != "CY")]
if (len(list_of_n) != 0):
atom2 = random.choice(list_of_n)
epoxy_atom = Atom( current_size + 1, 'OE', 'E1A', str(added_functional_groups + 1), float("{0:.3f}".format(abs(atom.x - atom2.x) / 2 + min(atom.x, atom2.x))), float("{0:.3f}".format(abs(atom.y - atom2.y) / 2 + min(atom.y, atom2.y))), float("{0:.3f}".format(ct * 1.46 * math.sin(math.radians(60)))) )
atom_list.append(epoxy_atom)
if ((len(identify_bonds(epoxy_atom, atom_list)) == 2) and ((identify_bonds(epoxy_atom, atom_list)[0][0].atom_number == atom.atom_number) or (identify_bonds(epoxy_atom, atom_list)[1][0].atom_number == atom.atom_number)) and ((identify_bonds(epoxy_atom, atom_list)[0][0].atom_number == atom2.atom_number) or ((identify_bonds(epoxy_atom, atom_list)[1][0].atom_number == atom2.atom_number)))):
CY = Atom(atom.atom_number, 'CY', 'E1A', epoxy_atom.residue_number, atom.x, atom.y, atom.z)
CY2 = Atom(atom2.atom_number, 'CZ', 'E1A', epoxy_atom.residue_number, atom2.x, atom2.y, atom2.z)
atom_list.remove(atom); atom_list.remove(atom2)
atom_list.append(CY); atom_list.append(CY2)
if atom in edge_map: edge_map.remove(atom)
if atom in anywhere_map: anywhere_map.remove(atom)
if atom2 in edge_map: edge_map.remove(atom2)
if atom2 in anywhere_map: anywhere_map.remove(atom2)
else:
atom_list.remove(epoxy_atom)
del epoxy_atom
return atom_list
def add_hydroxyl(atom, atom_list, added_functional_groups, ct):
"""Function used to add hydroxyl atoms. Atom placement follows a geometrical approach.
Atom - chosen CX atom. Atom_list - the atom list so far. Added_functional_groups - the number of functional groups added so far. Ct - the random top or below coordinate.
Ads 2 atom and replaces 1 (3 in total)."""
global anywhere_map
global edge_map
current_size = len(atom_list)
placed = 0
alpha = random.randint(0,359)
while (placed <= 359):
alpha += 1
oxygen_atom = Atom(current_size + 1, 'OL', 'H1A', str(added_functional_groups + 1), atom.x, atom.y, ct * 1.49 + atom.z)
atom_list.append(oxygen_atom)
if ((len(identify_bonds(oxygen_atom, atom_list)) == 1) and (identify_bonds(oxygen_atom, atom_list)[0][0].atom_number == atom.atom_number)):
h = math.sin(math.radians(19)) * 0.98
h_sp = math.cos(math.radians(19)) * 0.98
hydrogen_atom = Atom(current_size + 2, 'HK', 'H1A', str(added_functional_groups + 1), float("{0:.3f}".format(oxygen_atom.x - math.cos(math.radians(alpha)) * h_sp)), float("{0:.3f}".format(oxygen_atom.y - math.sin(math.radians(alpha)) * h_sp)), float("{0:.3f}".format(oxygen_atom.z + ct * h)))
atom_list.append(hydrogen_atom)
if ((len(identify_bonds(hydrogen_atom, atom_list)) == 1) and (identify_bonds(hydrogen_atom, atom_list)[0][0].atom_number == oxygen_atom.atom_number)):
placed = 888
if atom in edge_map: edge_map.remove(atom)
if atom in anywhere_map: anywhere_map.remove(atom)
CY = Atom(atom.atom_number, 'CY', 'H1A', oxygen_atom.residue_number, atom.x, atom.y, atom.z)
atom_list.append(CY)
atom_list.remove(atom)
del atom
else:
placed += 5
del hydrogen_atom
del atom_list[current_size + 1]
del oxygen_atom
del atom_list[current_size + 0]
else:
placed += 5
del oxygen_atom
del atom_list[current_size + 0]
return atom_list
def get_hydroxyl_map(atom_list):
"""Creates list of hydroxyl groups. Used when removing functional groups (eg. in rGO-PEG-NH2). Does not include CY atoms."""
hydroxyl_map = [[atom_list[x], atom_list[x+1]] for x in range(len(atom_list)-1) if ((atom_list[x].residue_name == atom_list[x+1].residue_name == "H1A") and (atom_list[x].residue_number == atom_list[x+1].residue_number ) and (atom_list[x].atom_name != "CY" != atom_list[x+1].atom_name != atom_list[x].atom_name))]
return hydroxyl_map
def get_epoxy_map(atom_list):
"""Creates list of epoxy groups. Used when removing functional groups (eg. in rGO-PEG-NH2). Does not include the CY atoms."""
epoxy_map = [[atom_list[x]] for x in range(len(atom_list)) if ((atom_list[x].residue_name == "E1A") and (atom_list[x].atom_name != "CY"))]
return epoxy_map
def get_carboxyl_map(atom_list):
"""Creates list of carboxyl groups. Used when removing functional groups (eg. in rGO-PEG-NH2). Does not include CY atoms."""
carboxyl_map = [[atom_list[x], atom_list[x+1], atom_list[x+2], atom_list[x+3]] for x in range(len(atom_list)-3) if ((atom_list[x].residue_name == atom_list[x+1].residue_name == atom_list[x+2].residue_name == atom_list[x+3].residue_name == "C1A") and (atom_list[x].residue_number == atom_list[x+1].residue_number == atom_list[x+2].residue_number == atom_list[x+3].residue_number) and (atom_list[x].atom_name != "CY" != atom_list[x+1].atom_name != atom_list[x+2].atom_name != "CY" != atom_list[x+3].atom_name ))]
return carboxyl_map
def remove_functional_groups(pct_C1A, pct_E1A, pct_H1A, atom_list):
"""Used to remove *pct_C1A* of present carboyl groups etc."""
carboxyl_map = get_carboxyl_map(atom_list)
epoxy_map = get_epoxy_map(atom_list)
hydroxyl_map = get_hydroxyl_map(atom_list)
remove_C1A = round(len(carboxyl_map) * pct_C1A)
remove_E1A = round(len(epoxy_map) * pct_E1A)
remove_H1A = round(len(hydroxyl_map) * pct_H1A)
while (remove_C1A > 0):
remove_C1A -= 1
remove_group = random.choice(carboxyl_map)
carboxyl_map.remove(remove_group)
for element in remove_group:
atom_list.remove(element)
del element
while (remove_E1A > 0):
remove_E1A -= 1
remove_group = random.choice(epoxy_map)
epoxy_map.remove(remove_group)
for element in remove_group:
atom_list.remove(element)
del element
while (remove_H1A > 0):
remove_H1A -= 1
remove_group = random.choice(hydroxyl_map)
hydroxyl_map.remove(remove_group)
for element in remove_group:
atom_list.remove(element)
del element
return atom_list
def find_highest_resnum(atom_list):
"""Used to find the highest / last residue number."""
resnum = 0
for element in atom_list:
if (int(element.residue_number) > int(resnum)):
resnum = int(element.residue_number)
return resnum
def find_conn_CXCY(atom, atom_list):
"""Once a functional group is removed (such as epoxy or hydroxyl) and it is going to be replaced by a -NH-PEG-NH2 chain, one needs to know
the exact atom to which to connect the new functional group and whether it was connected above or below. This function serves that."""
le_list = []
for element in identify_bonds(atom, atom_list):
if ((element[0].atom_name == "CX") or (element[0].atom_name == "CY")):
if (atom.z - element[0].z > 0):
le_list.append([element[0], 1])
else:
le_list.append([element[0], -1])
return le_list
def fix_sphere_m (center_x, center_y, center_z, radius, centers, radii, len_points):
"""Using the given XYZ coordinates as the center of the sphere, and the typical bond distance of the two atoms of interest
we plot random points on a sphere. In a similar manner, we then imagine the spheres of nearby atoms (centers and radii) and
test the distance between each random point and nearby atoms. If too small, the points get removed.
Len_points refers to how many random points one should plot/place."""
g_x = []
g_y = []
g_z = []
points = [hydrogen_coord_gen(center_x, center_y, center_z, radius) for i in range(0, len_points)]
x = [points[i][0] for i in range(0, len(points))]
y = [points[i][1] for i in range(0, len(points))]
z = [points[i][2] for i in range(0, len(points))]
for i in range(0, len(points)):
check = 0
j = 0
while (j <= (len(centers) - 1) and (check == 0)):
if (calculate_3D_distance_2_centers(x[i], y[i], z[i], centers[j][0], centers[j][1], centers[j][2]) < radii[j]):
check += 1
j += 1
if (check == 0):
g_x.append(x[i])
g_y.append(y[i])
g_z.append(z[i])
return g_x, g_y, g_z
def fix_sphere_h (center_x, center_y, center_z, radius, centers, radii, len_points, list_of_a):
"""Similar to above, yet takes into account through list_of_a the neighbouring skeleton atoms of the PEG-NH2 chains so that they are not missed by accident.
This was necessary as an optimization of the *radii* or bond length as these had to be tweaked and played with slightly."""
g_x = []
g_y = []
g_z = []
points = [hydrogen_coord_gen(center_x, center_y, center_z, radius) for i in range(0, len_points)]
x = [points[i][0] for i in range(0, len(points))]
y = [points[i][1] for i in range(0, len(points))]
z = [points[i][2] for i in range(0, len(points))]
for i in range(0, len(points)):
check = 0
check_b = 0
j = 0
while (j <= (len(centers) - 1) and (check == 0)):
if (calculate_3D_distance_2_centers(x[i], y[i], z[i], centers[j][0], centers[j][1], centers[j][2]) < radii[j]):
check += 1
j += 1
h = 0
while ((check_b == 0) and (h <= len(list_of_a) -1)):
if (calculate_3D_distance_2_centers(x[i], y[i], z[i], list_of_a[h].x, list_of_a[h].y, list_of_a[h].z) <= 1.50):
check_b += 1
h += 1
if ((check == 0) and (check_b == 0)):
g_x.append(x[i])
g_y.append(y[i])
g_z.append(z[i])
return g_x, g_y, g_z
def detect_neighbours_hydrogen(central_atom, atom_list):
"Returns list of nighbour atoms up to 2,5A"""
nearby_atoms_crude = [atom for atom in atom_list if ((abs(central_atom.x - atom.x) <= 2.5) and (abs(central_atom.y - atom.y) <= 2.5) and (abs(central_atom.z - atom.z) <= 2.5))]
nearby_atoms = [atom for atom in nearby_atoms_crude if (0 < calculate_3D_distance_2_atoms(central_atom, atom) <= 2.5)]
return nearby_atoms
def quick_sphere(center_x, center_y, center_z, radius, no_points):
points = []
points = [hydrogen_coord_gen(center_x, center_y, center_z, radius) for i in range(0, no_points)]
x = [points[i][0] for i in range(0, len(points))]
y = [points[i][1] for i in range(0, len(points))]
z = [points[i][2] for i in range(0, len(points))]
return x, y, z
def hydrogen_coord_gen(atomx, atomy, atomz, r):
"""Generates random XYZ points on a sphere centered at atomx, atomy, atomz with radius r"""
theta = np.random.uniform(0, 2 * np.pi)
cosalpha = np.random.uniform(-1, 1)
alpha = np.arccos(cosalpha)
x = atomx + r * np.cos(theta) * np.sin(alpha)
y = atomy + r * np.sin(theta) * np.sin(alpha)
z = atomz + r * np.cos(alpha)
return [x, y, z]
def plot_points_on_sphere(points_x, points_y, points_z, center_x, center_y, center_z, radius):
"""Plotting function. Used to create images in the manuscript."""
from mayavi import mlab
mlab.figure(1, bgcolor=(1,1,1), fgcolor=(0,0,0), size=(800,800))
return mlab.points3d(points_x, points_y, points_z, scale_factor=0.05, color=(0.25, 0.75, 0.77))
def repick(g1_x, g1_y, g1_z):
"""Repick point from the random points plotted on the sphere. Usually due to not being able to find place for a second hydrogen etc."""
i = random.randint(0, len(g1_x) - 1)
x = g1_x[i]
y = g1_y[i]
z = g1_z[i]
return x, y, z
def find_CX_neighbours(list_of_atoms, atom_list):
"""As the PEG-NH2 chains can have a more or less random conformation, some of them may bend along the graphene layer.
This function returns a list of the CX or CY graphene atoms nearby a PEG-NH2 chain."""
my_list = []
atom_numbers = []
for atom in list_of_atoms:
for element in identify_bonds(atom, atom_list):
if (((element[0].atom_name == "CX") or (element[0].atom_name == "CY")) and (element[0].atom_number not in atom_numbers)):
my_list.append(element[0])
atom_numbers.append(element[0].atom_number)
return my_list
def compose_listofr(atom_name, listofn):
"""Typical distances between certain atom pairs (N, O, C, H).
Was used to tweak the distance with neighbouring spheres (see fix_sphere_m or fix_sphere_h) and improve the outcome."""
c = 1.06
c2 = 1.4
listofr = []
for x in range(len(listofn)):
if (atom_name[0] == "N"):
if (listofn[x].atom_name[0] == "H"):
listofr.append(1.010*c)
if (listofn[x].atom_name[0] == "O"):
listofr.append(1.060*c)
if (listofn[x].atom_name[0] == "C"):
listofr.append(1.475*c)
if (listofn[x].atom_name[0] == "N"):
listofr.append(1.450*c)
if (atom_name[0] == "O"):
if (listofn[x].atom_name[0] == "H"):
listofr.append(0.970*c)
if (listofn[x].atom_name[0] == "O"):
listofr.append(1.490*c)
if (listofn[x].atom_name[0] == "C"):
listofr.append(1.160*c)
if (listofn[x].atom_name[0] == "N"):
listofr.append(1.060*c)
if (atom_name[0] == "C"):
if (listofn[x].atom_name[0] == "H"):
listofr.append(1.090*c)
if (listofn[x].atom_name[0] == "O"):
listofr.append(1.160*c)
if (listofn[x].atom_name[0] == "C"):
listofr.append(1.540*c)
if (listofn[x].atom_name[0] == "N"):
listofr.append(1.475*c)
if (atom_name[0] == "H"):
if (listofn[x].atom_name[0] == "H"):
listofr.append(0.740*c2)
if (listofn[x].atom_name[0] == "O"):
listofr.append(0.970*c2)
if (listofn[x].atom_name[0] == "C"):
listofr.append(1.090*c2)
if (listofn[x].atom_name[0] == "N"):
listofr.append(1.010*c2)
return listofr
def add_NH_PEG_NH2(GO_file, pct_C1A, pct_E1A, pct_H1A, filename1):
"""The function used to place NH-PEG-NH2 chains with the formula: -NH-(C2H4O)2-NH2.
Needs a GO PDB file to start from. pct_C1A, pct_E1A and pct_H1A represent how many functional groups will be removed from the GO (between 0 (none) and 1 (all)).
After removal, all atoms are re-numbered and then the chains are placed. Each chain has 25 atoms to place so it can take a while to place one."""
global remember_me
global bond_list
bond_list = bond_list_1
atom_list = read_in_GO(GO_file)
carboxyl_map = get_carboxyl_map(atom_list)
epoxy_map = get_epoxy_map(atom_list)
hydroxyl_map = get_hydroxyl_map(atom_list)
remove_C1A = round(len(carboxyl_map) * pct_C1A)
remove_E1A = round(len(epoxy_map) * pct_E1A)
remove_H1A = round(len(hydroxyl_map) * pct_H1A)
list_of_CXCY_epoxy = []
list_of_CXCY_hydroxyl = []
while (remove_C1A > 0):
remove_C1A -= 1
remove_group = random.choice(carboxyl_map)
carboxyl_map.remove(remove_group)
for element in remove_group:
atom_list.remove(element)
del element
while (remove_E1A > 0):
remove_E1A -= 1
remove_group = random.choice(epoxy_map)
epoxy_map.remove(remove_group)
for element in remove_group:
CXCY_epoxy = find_conn_CXCY(element, atom_list)
if (CXCY_epoxy != []):
list_of_CXCY_epoxy.append(CXCY_epoxy)
atom_list.remove(element)
del element
while (remove_H1A > 0):
remove_H1A -= 1
remove_group = random.choice(hydroxyl_map)
hydroxyl_map.remove(remove_group)
for element in remove_group:
CXCY_hydroxyl = find_conn_CXCY(element, atom_list)
if (CXCY_hydroxyl != []):
list_of_CXCY_hydroxyl.append(CXCY_hydroxyl)
atom_list.remove(element)
del element
atno = 1
resno = 1
new_list = []
for atom in atom_list:
if ((atom.atom_name == "CX") or (atom.atom_name == "CY")):
New_CX = Atom(atno, "CX", "GGG", resno, atom.x, atom.y, atom.z)
new_list.append(New_CX)
atno += 1
resno += 1
for atom in atom_list:
if (atom.atom_name == "C4"):
check = False
for atom_OJ in atom_list:
if ((atom_OJ.atom_name == "OJ") and (atom_OJ.residue_name == "C1A") and (atom_OJ.residue_number == atom.residue_number)):
for atom_OK in atom_list:
if ((atom_OK.atom_name == "OK") and (atom_OK.residue_name == "C1A") and (atom_OK.residue_number == atom.residue_number)):
for atom_HK in atom_list:
if ((atom_HK.atom_name == "HK") and (atom_HK.residue_name == "C1A") and (atom_HK.residue_number == atom.residue_number)):
New_C4 = Atom(atno + 0, "C4", "C1A", resno, atom.x, atom.y, atom.z)
New_OJ = Atom(atno + 1, "OJ", "C1A", resno, atom_OJ.x, atom_OJ.y, atom_OJ.z)
New_OK = Atom(atno + 2, "OK", "C1A", resno, atom_OK.x, atom_OK.y, atom_OK.z)
New_HK = Atom(atno + 3, "HK", "C1A", resno, atom_HK.x, atom_HK.y, atom_HK.z)
atno += 4
resno += 1
new_list.append(New_C4); new_list.append(New_OJ); new_list.append(New_OK); new_list.append(New_HK);
check = True
break
if (check == True):
break
if (check == True):
break
elif (atom.atom_name == "OE"):
New_OE = Atom(atno + 0, "OE", "E1A", resno, atom.x, atom.y, atom.z)
atno += 1
resno += 1
new_list.append(New_OE);
elif (atom.atom_name == "OL"):
check = False
for atom_HK in atom_list:
if ((atom_HK.atom_name == "HK") and (atom_HK.residue_name == "H1A") and (atom_HK.residue_number == atom.residue_number)):
New_OL = Atom(atno + 0, "OL", "H1A", resno, atom.x, atom.y, atom.z)
New_HK = Atom(atno + 1, "HK", "H1A", resno, atom_HK.x, atom_HK.y, atom_HK.z)
atno += 2
resno += 1
new_list.append(New_OL); new_list.append(New_HK);
check = True
break
atom_list = new_list.copy()
atoms = new_list.copy()
bond_list = bond_list_2 + bond_list_3
suma = 0
quick_list = list_of_CXCY_epoxy + list_of_CXCY_hydroxyl
new_quick_list = []
for element in quick_list:
for atom in atom_list:
if ((atom.x == element[0][0].x) and (atom.y == element[0][0].y) and (atom.z == element[0][0].z)):
new_quick_list.append([[atom, element[0][1]]])
progress = 1
for element in new_quick_list:
print("Progress: ", progress/(len(new_quick_list))*100, "%")
progress +=1
goto = 100
points_max = 1500
suma += 1
ct = element[0][1]
resnum = find_highest_resnum(atom_list)
current_size = len(atom_list)
attempt_N1 = goto
listofa = find_CX_neighbours([element[0][0]], atoms)
listofn = [[atom.x, atom.y, atom.z] for atom in listofa]