-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuildCstruct1_2.py
executable file
·1229 lines (1110 loc) · 40 KB
/
buildCstruct1_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
'''
buildCstruct 1.2
Authors: Andrea Minoia, Martin Voegele
Date: January 27th 2018
********************************************
Description:
Build allotropes structures of carbon, namely graphite sheets and
carbon nanotubes. Non-periodic structure are saturated with hydrogens.
Functional groups (OH, COOH, COO-) can be added to CNTs.
Syntax:
buildCstruct.py [options] outfile
The available options are:
--version
shows program's version number and exit.
-c, --credits
display credits.
-s, --structure
specify the kind of structure to build. Valid structures are: armcnt, zigzagcnt and hopg.
-p, --periodicity
build a periodic structure for TINKER.
-g, --geometry
specify the geometry of the structure. For CNTs, use -g index_n cnt_length while
for hopg use -g size_x size_y (see examples below).
Size_x, size_y and cnt_length are in Angstom.
-f, --functionalization
specify the functionalization (only for CNT since version 1.2)
--xyz
save structure in XYZ format (version >= 1.1 only).
--gro
save structure in gromacs GRO format (version >= 1.1 only).
--mol2
save structure in mol2 format (version >= 1.2 only).
outfile
is the name of the file where to save the structure.
Requirements:
Require numpy installed
Known issues and limitations:
1) Build single wall CNT and rectangular slab of graphtie HOPG only.
2) Build armchair and zigzag CNT only
Changelog:
+ v 1.2 - January 2018 (Martin Voegele):
- Modified H adding, so there are no clashes between hydrogens.
- Added support for mol2 format
- Added partial charges
- Added COOH, COO- and OH groups for CNTs (ooption -f)
+ v 1.1 - March 2010 (Andrea Minoia):
- improved connectivity search algorithm
- added support for XYZ format
- added support for gromacs GRO format
+ v 1.0 - April 2009 (Andrea Minoia):
- first release of buildCstruct
License:
Freeware. You can use, modify and redistribute the source.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Contacts:
You liked this program? You have suggestions?
Drop me a mail at minoiaa_at_gmail.com
Don't forget to visit the wiki: http://chembytes.wikidot.com
'''
#import modules
from sys import argv, exit,path, version
from optparse import OptionParser as OP
try:
from numpy import zeros, pi, sin, cos, modf, ceil, sqrt
except:
print "Numpy not installed or not in python path. I give up..."
exit(10)
from string import lower
from os import path as path_os
from os import system
'''
#===============================================================================
# SUBROUTINES
#===============================================================================
'''
def getdist(at1,at2):
''' Calculate distance between two particles
'''
dist_at=sqrt((at2[0]-at1[0])**2+(at2[1]-at1[1])**2+(at2[2]-at1[2])**2)
return dist_at
def filecheck(file):
''' Check if infile exists
'''
if path_os.isfile(file) == 0:
found=False
else:
found=True
return found
def backup_file(file):
'''check if file exists. if not open file
for writing, otherwhise backup the old one in
#infile_x# with x progressive number
'''
tmpvar=file
count=0
while 1:
found=filecheck(file)
if found:
count+=1
file=tmpvar+'_bak-'+str(count)
else:
break
if file !=tmpvar:
system('mv '+tmpvar+' '+file)
def write_tnk(file,data):
'''write TINKER xyz/arc
'''
file.write(" "+str(len(data))+"\n")
for line in data:
outline="%3s %-3s%12.6f%12.6f%12.6f%6s%6s" % (line[0],line[1],float(line[2])\
,float(line[3]),float(line[4]),line[5],line[6])
for i in range(7,len(line)):
outline=outline+"%6s" % line[i]
file.write(outline+"\n")
return
def parsecmd():
description="Build allotropic structures of Carbon, namely\
graphite hopg and armchair/zigzag carbon nanotubes.\n Output file can\
be saved in TINKER, XYZ, MOL2 or Gromacs GRO formats. Structures can also be periodic.\n"
usage = "usage: %prog [options] output_file"
#parse command line
parser=OP(version='%prog 1.2',description=description, usage=usage)
parser.add_option('-c','--credits',dest='credits',action='store_true',
default=False,help='display credits')
parser.add_option('-s','--struct',dest='structure',default='none',
help='define structure: armcnt, zigzagcnt, hopg')
parser.add_option('-p','--periodic',dest='pbc',action='store_true',
default=False, help='build periodic structure for Tinker')
parser.add_option('-g','--geometry',dest='geometry',nargs=2,type='float',
help='define the geometry for the structure')
parser.add_option('-f','--funct',dest='functionalization',default='none',
help='define functionalization: none, oh, cooh, coo- (only implemented for cnt)')
parser.add_option('--xyz',dest='xyz',action='store_true',
help='write xyz file. This is FAST.')
parser.add_option('--gro',dest='gro',action='store_true',
help='write gromacs gro file. This is FAST too ;).')
parser.add_option('--mol2',dest='mol2',action='store_true',
help='write mol2 file.')
(options, args) = parser.parse_args(argv[1:])
#manage parse errors
if options.credits: #display credits and quit
credits="\n**********************************\n\
Andrea Minoia, Martin Voegele\n\
Contacts: minoiaa_at_gmail.com\
http://chembytes.wikidot.com\
\n*********************************\n"
print credits
exit(0)
if len(args)==0: #arguments missing
parser.exit(parser.print_help())
if len(args)>1: #check if more than one argument (NOT OPTION) has been parsed
parser.error('You have given me more than one argument '+str(args)+'... dunno what to do...\n')
if lower(options.structure) != 'hopg' and lower(options.structure) !='armcnt'\
and lower(options.structure) !='zigzagcnt':
parser.error('Uknown structure: valid structures are hopg, armcnt and zigzagcnt')
return options, args
def armcnt(n,l,ccbond,funct):
''' build armchair carbon nanotube
'''
atc=[]
circ1=[]
circ2=[]
if funct=="oh":
c1charge=-0.28
c1acharge=0.24
c2charge=0.01
elif funct=="coo":
c1charge=-0.34
c1acharge=-0.09
c2charge=0.03
elif funct=="cooh":
c1charge=-0.12
c1acharge=-0.1
c2charge=0.03
else:
c1charge=-0.16
c1acharge=-0.16
c2charge=0.03
cmcharge=0.0
dx=ccbond*cos(120/2*(pi/180.0))
dy=ccbond*sin(120/2*(pi/180.0))
radius=(n*(2*dx+ccbond)+n*ccbond)/(2*pi)
ycoord=+dy
natoms=2*n
#create circumferences
for i in range(n):
circ1.append(2*dx+ccbond)
circ1.append(ccbond)
circ2.append(ccbond)
circ2.append(2*dx+ccbond)
#adjust the circumferences
circ1.insert(0,0.0)
circ1.pop()
circ2.insert(0,dx)
circ2.pop()
#Build CNT
while ycoord>-l:
ycoord-=dy
arc=0.0
# Assign suitable charges to the first and last two carbon rings
if ycoord==0:
ccharge_circ1a=c1acharge
ccharge_circ1=c1charge
ccharge_circ2a=c2charge
ccharge_circ2=c2charge
elif ycoord<-l+dy:
ccharge_circ1a=c2charge
ccharge_circ1=c2charge
ccharge_circ2a=c1acharge
ccharge_circ2=c1charge
else:
ccharge_circ1=cmcharge
ccharge_circ2=cmcharge
ccharge_circ1a=cmcharge
ccharge_circ2a=cmcharge
# Make coordinates
for i in range(natoms):
if modf(float(i)/2.0)[0]==0:
newccharge=ccharge_circ1a
else:
newccharge=ccharge_circ1
tmpcoords=['C']
arc+=circ1[i]
theta=arc/radius
tmpcoords.append(radius*cos(theta))
tmpcoords.append(ycoord)
tmpcoords.append(radius*sin(theta))
tmpcoords.append('C.ar')
tmpcoords.append(newccharge)
atc.append(tmpcoords)
ycoord-=dy
arc=0.0
for i in range(natoms):
if modf(float(i)/2.0)[0]==0:
newccharge=ccharge_circ2a
else:
newccharge=ccharge_circ2
tmpcoords=['C']
arc+=circ2[i]
theta=arc/radius
tmpcoords.append(radius*cos(theta))
tmpcoords.append(ycoord)
tmpcoords.append(radius*sin(theta))
tmpcoords.append('C.ar')
tmpcoords.append(newccharge)
atc.append(tmpcoords)
pbc_l=abs(ycoord)+dy
print '\n*******************************'
print 'armchair CNT: n= ',n,' l (ang)= ',abs(ycoord)
print 'periodicity (if apply) (ang)= ',pbc_l
print 'diameter (ang): ',2*radius
return atc,natoms,pbc_l,len(atc)
def zigzagcnt(n,l,ccbond,funct):
''' build zigzag carbon nanotube
'''
atc=[]
circ1=[]
circ2=[]
if funct=="oh":
c1charge=-0.10
c1acharge=0.2
c2charge=-0.04
elif funct=="coo":
c1charge=-0.43
c1acharge=-0.33
c2charge=0.09
elif funct=="cooh":
c1charge=-0.14
c1acharge=-0.14
c2charge=0.06
else:
c1charge=-0.30
c1acharge=-0.30
c2charge=0.14
cmcharge=0.0
dy=ccbond*cos(120/2*(pi/180.0))
dx=ccbond*sin(120/2*(pi/180.0))
radius=(n*2*dx)/(2*pi)
ycoord=+ccbond
#create circumferences
for i in range(n):
circ1.append(2*dx)
#adjust the circumferences
circ1.pop()
circ2=list(circ1) #copy list!!! circ2=circ1 make duplicate and are both modified in the same way
circ1.insert(0,0.0)
circ2.insert(0,dx)
#Build CNT
while ycoord>-l:
ycoord-=ccbond
arc=0.0
# Assign suitable charges to the first and last two carbon rings
if ycoord==0:
ccharge_circ1a=c1acharge
ccharge_circ1=c1charge
ccharge_circ2a=c2charge
ccharge_circ2=c2charge
ccharge_circ3a=cmcharge
ccharge_circ3=cmcharge
ccharge_circ4a=cmcharge
ccharge_circ4=cmcharge
elif ycoord<-l+dy:
ccharge_circ1a=cmcharge
ccharge_circ1=cmcharge
ccharge_circ2a=cmcharge
ccharge_circ2=cmcharge
ccharge_circ3a=c2charge
ccharge_circ3=c2charge
ccharge_circ4a=c1acharge
ccharge_circ4=c1charge
else:
ccharge_circ1=cmcharge
ccharge_circ2=cmcharge
ccharge_circ3=cmcharge
ccharge_circ4=cmcharge
ccharge_circ1a=cmcharge
ccharge_circ2a=cmcharge
ccharge_circ3a=cmcharge
ccharge_circ4a=cmcharge
for i in range(n):
if modf(float(i)/2.0)[0]==0:
newccharge=ccharge_circ1a
else:
newccharge=ccharge_circ1
tmpcoords=['C']
arc+=circ1[i]
theta=arc/radius
tmpcoords.append(radius*cos(theta))
tmpcoords.append(ycoord)
tmpcoords.append(radius*sin(theta))
tmpcoords.append('C.ar')
tmpcoords.append(newccharge)
atc.append(tmpcoords)
ycoord-=dy
arc=0.0
for i in range(n):
if modf(float(i)/2.0)[0]==0:
newccharge=ccharge_circ2a
else:
newccharge=ccharge_circ2
tmpcoords=['C']
arc+=circ2[i]
theta=arc/radius
tmpcoords.append(radius*cos(theta))
tmpcoords.append(ycoord)
tmpcoords.append(radius*sin(theta))
tmpcoords.append('C.ar')
tmpcoords.append(newccharge)
atc.append(tmpcoords)
ycoord-=ccbond
arc=0.0
for i in range(n):
if modf(float(i)/2.0)[0]==0:
newccharge=ccharge_circ3a
else:
newccharge=ccharge_circ3
tmpcoords=['C']
arc+=circ2[i]
theta=arc/radius
tmpcoords.append(radius*cos(theta))
tmpcoords.append(ycoord)
tmpcoords.append(radius*sin(theta))
tmpcoords.append('C.ar')
tmpcoords.append(newccharge)
atc.append(tmpcoords)
ycoord-=dy
arc=0.0
for i in range(n):
if modf(float(i)/2.0)[0]==0:
newccharge=ccharge_circ4a
else:
newccharge=ccharge_circ4
tmpcoords=['C']
arc+=circ1[i]
theta=arc/radius
tmpcoords.append(radius*cos(theta))
tmpcoords.append(ycoord)
tmpcoords.append(radius*sin(theta))
tmpcoords.append('C.ar')
tmpcoords.append(newccharge)
atc.append(tmpcoords)
pbc_l=abs(ycoord)+ccbond
print '\n*******************************'
print 'zigzag CNT: n= ',n,' l (ang)= ',abs(ycoord)
print 'periodicity (if apply) (ang)= ',pbc_l
print 'diameter (ang): ',2*radius
return atc,n,pbc_l,len(atc)
def graphite(x,y,ccbond):
''' generate single square sheet of graphite HOPG
'''
atc=[]
dx=ccbond*cos(120/2*(pi/180.0))
dy=ccbond*sin(120/2*(pi/180.0))
ycoord=+dy
xcoords1=[]
xcoord=0.00
xcoords1.append(xcoord)
#build 1st row for X
while xcoord<=x:
xcoord+=ccbond+2*dx
xcoords1.append(xcoord)
xcoord+=ccbond
xcoords1.append(xcoord)
xcoords1.pop() #remove last element, i.e. the bond exceeding the size
#build 2nd row for X
xcoord=dx
xcoords2=[]
xcoords2.append(xcoord)
while xcoord<=x+dx:
xcoord+=ccbond
xcoords2.append(xcoord)
xcoord+=ccbond+2*dx
xcoords2.append(xcoord)
xcoords2.pop() #remove last element, i.e. the bond exceeding the size
while ycoord>-y:
ycoord-=dy
for coord in xcoords1:
tmpcoords=['C']
tmpcoords.append(coord)
tmpcoords.append(ycoord)
tmpcoords.append(0.00)
atc.append(tmpcoords)
ycoord-=dy
for coord in xcoords2:
tmpcoords=['C']
tmpcoords.append(coord)
tmpcoords.append(ycoord)
tmpcoords.append(0.00)
atc.append(tmpcoords)
print '\n*******************************'
print 'HOPG graphite: a= ',atc[len(xcoords1)-1][1],' b= ',abs(ycoord)
a_pbc=atc[len(xcoords1)-1][1]+ccbond
b_pbc=abs(ycoord)+dy
print 'Periodic (if apply) (ang): a= ',a_pbc, ' b= ',b_pbc
return atc,len(xcoords1),a_pbc,b_pbc,len(atc)
def connect(coords,natx,pbcx,pbcy,nohcoords):
'''build connectivity for graphite and nanotube:
'''
Ccov_r = 0.77 #covalent radius carbon
Hcov_r = 0.32 #covalent radius Hydrogen
Ocov_r = 0.66 #covalent radius Oxygen
btollcc = (2*Ccov_r)*15/100 #bond tollerance of 15%
btollch = (Hcov_r+Ccov_r)*5/100 #bond tollerance of 5%
btolloh = (Hcov_r+Ocov_r)*5/100 #bond tollerance of 5%
btollco = (Ccov_r+Ocov_r)*5/100 #bond tollerance of 5%
bondcc=[2*Ccov_r-btollcc,2*Ccov_r+btollcc]
bondch=[(Hcov_r+Ccov_r)-btollch,(Hcov_r+Ccov_r)+btollch]
bondco=[(Ocov_r+Ccov_r)-btollco,(Ocov_r+Ccov_r)+btollco]
bondoh=[(Hcov_r+Ocov_r)-btolloh,(Hcov_r+Ocov_r)+btolloh]
connect=zeros((len(coords),3),int) #init connectivity matrix
bondlist=[]
bondnumber=0
#find connectivity, based on distance
for i in xrange(len(coords)):
for j in xrange(i+1,i+2*natx):
if j<nohcoords:
at1=[coords[i][1],coords[i][2],coords[i][3]]
at2=[coords[j][1],coords[j][2],coords[j][3]]
bond=getdist(at1,at2)
if bond >= bondcc[0] and bond < bondcc[1]:
if i < j:
bondnumber+=1
tmpbond=[bondnumber,i+1,j+1,'ar']
bondlist.append(tmpbond)
for k in range(3):
if connect[i][k]== 0:
connect[i][k]=j+1 #index run from zero, not 1
break
else:
pass
for k in range(3):
if connect[j][k]== 0:
connect[j][k]=i+1 #index run from zero, not 1
break
else:
pass
if len(coords)!=nohcoords: #there are hydrogens
for j in xrange(nohcoords,len(coords)):
at1=[coords[i][1],coords[i][2],coords[i][3]]
at2=[coords[j][1],coords[j][2],coords[j][3]]
bond=getdist(at1,at2)
if ( ( bond >= bondch[0] and bond < bondch[1] ) or ( bond >= bondco[0] and bond < bondco[1] ) or ( bond >= bondoh[0] and bond < bondoh[1] ) or ( coords[i][0]=='C' and coords[j][0]=='C' and bond >= bondcc[0] and bond < bondcc[1] ) ) :
if i < j:
bondnumber+=1
tmpbond=[bondnumber,i+1,j+1,'1']
bondlist.append(tmpbond)
for k in range(3):
if connect[i][k]== 0:
connect[i][k]=j+1 #index run from zero, not 1
break
else:
pass
for k in range(3):
if connect[j][k]== 0:
connect[j][k]=i+1 #index run from zero, not 1
break
else:
pass
#make periodic (TINKER) the structure
if pbcx:
#cicle periodicity along X
for i in xrange(len(coords)):
for j in xrange(i,len(coords)):
if coords[i][1]==0 and j-i==natx-1:
for k in range(3):
if connect[i][k]== 0:
connect[i][k]=j+1 #index run from zero, not 1
break
else:
pass
for k in range(3):
if connect[j][k]== 0:
connect[j][k]=i+1 #index run from zero, not 1
break
else:
pass
if pbcy:
i=0
#cicle periodicity along Y
while coords[i][2]==0.0:
j=len(coords)-natx+i
for k in range(3):
if connect[i][k]== 0:
connect[i][k]=j+1 #index run from zero, not 1
break
else:
pass
for k in range(3):
if connect[j][k]== 0:
connect[j][k]=i+1 #index run from zero, not 1
break
else:
pass
i+=1
# print connect, bondlist
return connect, bondlist
def data4tnk(coords,conn):
''' Prepare all the data to be written in
tinker format
'''
data=[]
for i in range(len(coords)):
tmp=[i+1] #progressive index
for j in range(4): #coordinates
tmp.append(coords[i][j])
tmp.append('0') #atom type
for j in range(3): #connectivity
if conn[i][j]==0:
pass
else:
tmp.append(conn[i][j])
data.append(tmp)
return data
def add_COO(coords,natx,structure,is_protonated):
'''Add COO- groups and hydrogens to nonperiodic structures
'''
Hcov_r = 0.32
Ocov_r = 0.66
Ccov_r = 0.77
chbond=Hcov_r+Ccov_r # 1.087
cobond=Ccov_r+Ocov_r # 1.362
ohbond=Ocov_r+Hcov_r # 0.974
ccbond=2*Ccov_r
if structure =="hopg":
print "COO functionalization is not yet implemented for option hopg."
exit(1)
elif structure == 'zigzagcnt':
if is_protonated:
h1charge=0.19
c0charge=0.72
o1charge=-0.58
o2charge=-0.63
hocharge=0.46
else:
h1charge=0.39
c0charge=0.91
o1charge=-0.86
o2charge=-0.86
for i in range(len(coords)-natx,len(coords)):
if modf(float(i)/2.0)[0]==0: # COO-/COOH is added to every second C
Ox1=cobond*cos(i*2*pi/natx-pi/4)
Oz1=cobond*sin(i*2*pi/natx-pi/4)
Ox2=cobond*cos(i*2*pi/natx+pi/4)
Oz2=cobond*sin(i*2*pi/natx+pi/4)
#HOx=ohbond*cos(i*2*pi/natx+pi/4)
#HOz=ohbond*sin(i*2*pi/natx+pi/4)
tmpcoords=['C']
tmpcoords.append(coords[i][1])
tmpcoords.append(coords[i][2]-ccbond)
tmpcoords.append(coords[i][3])
tmpcoords.append('C.2')
tmpcoords.append(c0charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox1)
tmpcoords.append(coords[i][2]-ccbond)
tmpcoords.append(coords[i][3]+Oz1)
tmpcoords.append('O.co2')
tmpcoords.append(o1charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox2)
tmpcoords.append(coords[i][2]-ccbond)
tmpcoords.append(coords[i][3]+Oz2)
tmpcoords.append('O.co2')
tmpcoords.append(o2charge)
coords.append(tmpcoords)
if is_protonated:
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Ox2)
tmpcoords.append(coords[i][2]-ccbond-ohbond)
tmpcoords.append(coords[i][3]+Oz2)
tmpcoords.append('H')
tmpcoords.append(hocharge)
coords.append(tmpcoords)
else:
tmpcoords=['H']
tmpcoords.append(coords[i][1])
tmpcoords.append(coords[i][2]-chbond)
tmpcoords.append(coords[i][3])
tmpcoords.append('H')
tmpcoords.append(h1charge)
coords.append(tmpcoords)
for i in range(natx):
if modf(float(i)/2.0)[0]==0: # COO- is added to every second C
Ox1=cobond*cos(i*2*pi/natx-pi/4)
Oz1=cobond*sin(i*2*pi/natx-pi/4)
Ox2=cobond*cos(i*2*pi/natx+pi/4)
Oz2=cobond*sin(i*2*pi/natx+pi/4)
#HOx=ohbond*cos(i*2*pi/natx+pi/4)
#HOz=ohbond*sin(i*2*pi/natx+pi/4)
tmpcoords=['C']
tmpcoords.append(coords[i][1])
tmpcoords.append(+ccbond)
tmpcoords.append(coords[i][3])
tmpcoords.append('C.2')
tmpcoords.append(c0charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox1)
tmpcoords.append(+ccbond)
tmpcoords.append(coords[i][3]+Oz1)
tmpcoords.append('O.co2')
tmpcoords.append(o1charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox2)
tmpcoords.append(+ccbond)
tmpcoords.append(coords[i][3]+Oz2)
tmpcoords.append('O.co2')
tmpcoords.append(o2charge)
coords.append(tmpcoords)
if is_protonated:
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Ox2)
tmpcoords.append(coords[i][2]+ccbond+ohbond)
tmpcoords.append(coords[i][3]+Oz2)
tmpcoords.append('H')
tmpcoords.append(hocharge)
coords.append(tmpcoords)
else:
tmpcoords=['H']
tmpcoords.append(coords[i][1])
tmpcoords.append(+chbond)
tmpcoords.append(coords[i][3])
tmpcoords.append('H')
tmpcoords.append(h1charge)
coords.append(tmpcoords)
elif structure == 'armcnt':
if is_protonated:
hocharge=0.44 # not assigned yet (all charges are diferent for coo and cooh)
h1charge=0.17
c0charge=0.7
o1charge=-0.55
o2charge=-0.6
else:
h1charge=0.22
c0charge=0.83
o1charge=-0.84
o2charge=-0.84
Hxz=chbond*cos(120/2*pi/180)
Hy1=chbond*sin(120/2*pi/180)
Cxz=ccbond*cos(120/2*pi/180)
Cy1=ccbond*sin(120/2*pi/180)
for i in xrange(natx): #upper border
Hx1=Hxz*cos(i*2*pi/natx)
Hz1=Hxz*sin(i*2*pi/natx)
Cx1=Cxz*cos(i*2*pi/natx)
Cz1=Cxz*sin(i*2*pi/natx)
Ox1=Cx1+cobond*cos(i*2*pi/natx - pi/4)
Oz1=Cz1+cobond*sin(i*2*pi/natx - pi/4)
Oy1=Cy1
Ox2=Cx1+cobond*cos(i*2*pi/natx + pi/4)
Oz2=Cz1+cobond*sin(i*2*pi/natx + pi/4)
Oy2=Cy1
HOx=ohbond*cos(i*2*pi/natx+pi/4)
HOz=ohbond*sin(i*2*pi/natx+pi/4)
if modf(float(i)/2.0)[0]==0: # COO- is added to every second C
# if i==1:
tmpcoords=['C']
tmpcoords.append(coords[i][1]+Cx1)
tmpcoords.append(coords[i][2]+Cy1)
tmpcoords.append(coords[i][3]+Cz1)
tmpcoords.append('C.2')
tmpcoords.append(c0charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox1)
tmpcoords.append(coords[i][2]+Oy1)
tmpcoords.append(coords[i][3]+Oz1)
tmpcoords.append('O.co2')
tmpcoords.append(o1charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox2)
tmpcoords.append(coords[i][2]+Oy2)
tmpcoords.append(coords[i][3]+Oz2)
tmpcoords.append('O.co2')
tmpcoords.append(o2charge)
coords.append(tmpcoords)
if is_protonated:
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Ox2+HOx)
tmpcoords.append(coords[i][2]+Oy2)
tmpcoords.append(coords[i][3]+Oz2+HOz)
tmpcoords.append('H')
tmpcoords.append(hocharge)
coords.append(tmpcoords)
else:
tmpcoords=['H']
tmpcoords.append(coords[i][1]) # +Hx1
tmpcoords.append(coords[i][2]+chbond) # +Hy1
tmpcoords.append(coords[i][3]) # +Hz1
tmpcoords.append('H')
tmpcoords.append(h1charge)
coords.append(tmpcoords)
if is_protonated:
added_atoms=int(2.5*natx)
else:
added_atoms=int(2*natx) # COO- is added to every second C
# added_atoms=int(2+natx)
for i in xrange(len(coords)-added_atoms-natx,len(coords)-added_atoms): #bottom border
Hx1=Hxz*cos(i*2*pi/natx)
Hz1=Hxz*sin(i*2*pi/natx)
Cx1=Cxz*cos(i*2*pi/natx)
Cz1=Cxz*sin(i*2*pi/natx)
Ox1=Cx1+cobond*cos(i*2*pi/natx - pi/4)
Oz1=Cz1+cobond*sin(i*2*pi/natx - pi/4)
Oy1=Cy1
Ox2=Cx1+cobond*cos(i*2*pi/natx + pi/4)
Oz2=Cz1+cobond*sin(i*2*pi/natx + pi/4)
Oy2=Cy1
HOx=ohbond*cos(i*2*pi/natx+pi/4)
HOz=ohbond*sin(i*2*pi/natx+pi/4)
if modf(float(i)/2.0)[0]==0: # COO- is added to every second C
# if i==len(coords)-added_atoms-natx/2:
tmpcoords=['C']
tmpcoords.append(coords[i][1]+Cx1) #update x even
tmpcoords.append(coords[i][2]-Cy1)
tmpcoords.append(coords[i][3]+Cz1)
tmpcoords.append('C.2')
tmpcoords.append(c0charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox1)
tmpcoords.append(coords[i][2]-Oy1)
tmpcoords.append(coords[i][3]+Oz1)
tmpcoords.append('O.co2')
tmpcoords.append(o1charge)
coords.append(tmpcoords)
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox2)
tmpcoords.append(coords[i][2]-Oy2)
tmpcoords.append(coords[i][3]+Oz2)
tmpcoords.append('O.co2')
tmpcoords.append(o2charge)
coords.append(tmpcoords)
if is_protonated:
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Ox2+HOx)
tmpcoords.append(coords[i][2]-Oy2)
tmpcoords.append(coords[i][3]+Oz2+HOz)
tmpcoords.append('H')
tmpcoords.append(hocharge)
coords.append(tmpcoords)
else:
tmpcoords=['H']
tmpcoords.append(coords[i][1]) # +Hx1
tmpcoords.append(coords[i][2]-chbond) # -Hy1
tmpcoords.append(coords[i][3]) # +Hz1
tmpcoords.append('H')
tmpcoords.append(h1charge)
coords.append(tmpcoords)
def add_H(coords,natx,structure,funct_OH):
'''
Add hydrogens to nonperiodic structures
'''
Hcov_r = 0.32
Ocov_r = 0.66
Ccov_r = 0.77
chbond=Hcov_r+Ccov_r # 1.087
cobond=Ccov_r+Ocov_r # 1.362
ohbond=Ocov_r+Hcov_r # 0.974
Hxz=chbond*cos(120/2*pi/180)
Hy1=chbond*sin(120/2*pi/180)
Oxz=cobond*cos(120/2*pi/180)
Oy1=cobond*sin(120/2*pi/180)
if structure =="hopg" or structure=="armcnt": #saturate hopg in y direction or armchair cnt
if funct_OH:
h1charge=0.18
o1charge=-0.53
h2charge=0.37
else:
h1charge=0.13
for i in xrange(natx): #upper border
Hx1=Hxz*cos(i*2*pi/natx)
Hz1=Hxz*sin(i*2*pi/natx)
Ox1=Oxz*cos(i*2*pi/natx)
Oz1=Oxz*sin(i*2*pi/natx)
Hx2=Ox1+ohbond*cos(i*2*pi/natx)
Hz2=Oz1+ohbond*sin(i*2*pi/natx)
Hy2=Oy1
if structure=='armcnt':
if modf(float(i)/2.0)[0]==0 and funct_OH:
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox1)
tmpcoords.append(coords[i][2]+Oy1)
tmpcoords.append(coords[i][3]+Oz1)
tmpcoords.append('O.3')
tmpcoords.append(o1charge)
coords.append(tmpcoords)
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Hx2)
tmpcoords.append(coords[i][2]+Hy2)
tmpcoords.append(coords[i][3]+Hz2)
tmpcoords.append('H')
tmpcoords.append(h2charge)
coords.append(tmpcoords)
else:
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Hx1)
tmpcoords.append(coords[i][2]+Hy1)
tmpcoords.append(coords[i][3]+Hz1)
tmpcoords.append('H')
tmpcoords.append(h1charge)
coords.append(tmpcoords)
if structure=='hopg': #set y and z for hopg
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Hx1) #update x even
tmpcoords.append(coords[i][2]+Hy1)
tmpcoords.append(0.0)
if funct_OH:
added_atoms=int(1.5*natx)
else:
added_atoms=natx
for i in xrange(len(coords)-added_atoms-natx,len(coords)-added_atoms): #bottom unsaturated border
Hx1=Hxz*cos(i*2*pi/natx)
Hz1=Hxz*sin(i*2*pi/natx)
Ox1=Oxz*cos(i*2*pi/natx)
Oz1=Oxz*sin(i*2*pi/natx)
Hx2=Ox1+ohbond*cos(i*2*pi/natx)
Hz2=Oz1+ohbond*sin(i*2*pi/natx)
if structure=='armcnt': #set y and z for hopg
if modf(float(i)/2.0)[0]==0 and funct_OH:
tmpcoords=['O']
tmpcoords.append(coords[i][1]+Ox1) #update x even
tmpcoords.append(coords[i][2]-Oy1)
tmpcoords.append(coords[i][3]+Oz1)
tmpcoords.append('O.3')
tmpcoords.append(o1charge)
coords.append(tmpcoords)
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Hx2) #update x even
tmpcoords.append(coords[i][2]-Oy1)
tmpcoords.append(coords[i][3]+Hz2)
tmpcoords.append('H')
tmpcoords.append(h2charge)
coords.append(tmpcoords)
else:
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Hx1) #update x odd
tmpcoords.append(coords[i][2]-Hy1)
tmpcoords.append(coords[i][3]+Hz1)
tmpcoords.append('H')
tmpcoords.append(h1charge)
coords.append(tmpcoords)
if structure=='hopg': #set y and z for hopg
tmpcoords=['H']
tmpcoords.append(coords[i][1]+Hx1) #update x even
tmpcoords.append(coords[i][2]-Hy1)
tmpcoords.append(0.0)
if structure =="hopg": #saturate hopg in x direction
for i in xrange(len(coords)):
if coords[i][0] == 'C':
tmpcoords=['H']
if coords[i][1]==0.0: