-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmol2mol
More file actions
executable file
·903 lines (754 loc) · 28.2 KB
/
Copy pathmol2mol
File metadata and controls
executable file
·903 lines (754 loc) · 28.2 KB
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
#!/usr/bin/python
#
#This codes is to convert cartesian molecular coordinates
# from one format to another.
# zhao_lf@yeah.net
#
# The coordinate structure of intermediate data is:
# [[elem, x, y, z],
# [elem, x, y, z],
# ...]
#
# 1. simple input syntax allowed. 1.52 2011.07.12
#
# 10. mopac input file generation. 1.81 2014.03.04
__version__ = "1.81"
__revision__ = """ 1. read unfinished nwchem opt files.\n"""
__doc__ = """\n Molecular coordinates format transferor. --Lifeng Zhao\n
"""
import sys
import os
import string
import inspect
from copy import deepcopy
def lineno():
"""Returns the current line number in our program."""
return inspect.currentframe().f_back.f_lineno
GAMESS_Settings = """ $CONTRL SCFTYP=RHF RUNTYP=OPTIMIZE DFTTYP=B3LYP $END
-$CONTRL ICHARG=1 $END
$SYSTEM MWORDS=500 MEMDDI=500 $END
-$CONTRL EXETYP=CHECK $END
$CONTRL MAXIT=200 $END
-$STATPT OPTTOL=1.0E-5 $END
$STATPT NSTEP=300 $END
$DFT DC=.T. $END
$SCF DIRSCF=.T. $END
$BASIS GBASIS=N311 NGAUSS=6 NDFUNC=1 NPFUNC=1 DIFFSP=.T. $END
$GUESS GUESS=HUCKEL $END
$ELPOT IEPOT=1 WHERE=PDC $END
$PDC PTSEL=GEODESIC $END
-CONSTR=QUPOLE $END
$DATA
--Cartesian coordinates with C1 symmetry as follows:
C1
"""
ZCharge = {'O':'8.0','N':'7.0',\
'C':'6.0','H':'1.0',\
'B':'5.0','F':'9.0',\
'Na':'11.0','NA':'11.0',\
'P':'15.0','S':'16.0',\
'Cl':'17.0','CL':'17.0',\
'CU':'29.0','RU':'44.0',\
'AU':'79.0','Au':'79.0','Se':'34.0'}
ELEMENT = ['X','H','He','Li','Be','B','C','N','O','F','Ne',\
'Na','Mg','Al','Si','P','S','Cl','Ar','K','Ca',\
'Sc','Ti','V','Cr','Mn','Fe','Co','Ni','Cu','Zn',\
'Ga','Ge','As','Se','Br','Kr','Rb','Sr','Y','Zr',\
'Nb','Mo','Tc','Ru','Rh','Pd','Ag','Cd','In','Sn',\
'Sb','Te','I','Xe','Cs','Ba',\
'La','Ce','Pr','Nb','Pm','Sm','Eu','Gd','Tb','Dy','Ho','Er','Tm','Yb','Lu',\
'Hf','Ta','W','Re','Os','Ir','Pt','Au','Hg','Tl','Pb','Bi','Po','At','Rn']
SpecialData = {'TotalCharge':0,
'Multiplicity':1,
'InputFileName':'',
'OutputFileName':'',
'Energy':0.0}
def ReadXYZ(CoordFile):
coordtemp = []
NumAtoms = CoordFile.readline()
NumAtoms = int(NumAtoms.split()[0])
for ii in range(NumAtoms):
line = CoordFile.readline()
line = CoordFile.readline()
CoordFile.seek(0)
if line.strip()!='':
sys.stdout.write(' This file seems a general xyz file.\n')
line = CoordFile.readline()
line = CoordFile.readline()
for ii in range(NumAtoms):
line = CoordFile.readline()
line = line.strip()
line = line.split()
coordtemp.append(line[0:4])
else:
sys.stdout.write(' This file seems a TINKER xyz file.\n')
line = CoordFile.readline()
for ii in range(NumAtoms):
line = CoordFile.readline()
line = line.strip()
line = line.split()
coordtemp.append(line[1:5])
return coordtemp
def ReadGJF(CoordFile):
coordtemp = []
while 1:
line = CoordFile.readline()
if line[0] == '#': break
if line == '':
print 'Error: wrong gjf or com format! \n',lineno()
coordtemp.append('Error')
if not(len(coordtemp) == 0): return 2
line = CoordFile.readline()
while 1:
if line.strip() != '': line = CoordFile.readline()
else: break
for ii in range(3): CoordFile.readline()
while 1:
line = CoordFile.readline()
if line.strip() == '': break
line = line.split()
if len(line)<4:
print "CAUTION: It seems that the .gjf file was writen in Z-Matrix format,"
print " try to convert it to cartesian format.",lineno()
return 3
if len(line)>5: coordtemp.append([line[0], line[2], line[3], line[4]])
else: coordtemp.append(line[:4])
return coordtemp
def ReadINP(CoordFile):
coordtemp = []
while 1:
line = CoordFile.readline()
if (line[1:6]=='$DATA') or (line[1:6]=='$data'): break
if line == '': return 4
CoordFile.readline()
line = CoordFile.readline()
if (len(line)<2) or (line.strip() != 'C1'):
print "Wrong .inp file format! This codes can only deal C1 symmetry!",lineno()
return 5
while 1:
line = CoordFile.readline()
line = line.split()
if (len(line)==0) or (line[0]=='$END') or (line[0]=='$end'): break
line.pop(1)
coordtemp.append(line)
return coordtemp
def ReadPDB(CoordFile):
coordtemp = []
while 1:
line = CoordFile.readline()
if len(line)>=4:
if line[0:4]=='ATOM' or line[0:6]=='HETATM':
element = line[12:16]
element = element.strip()
if element=='HC' or element=='HO' or element=='HN': element = 'H'
if ord(element[0])<58: element = element[1]
xx = line[30:38]
xx = xx.strip()
yy = line[38:46]
yy = yy.strip()
zz = line[46:54]
zz = zz.strip()
coordtemp.append([element, xx, yy, zz])
if line == '': break
return coordtemp
def ReadNWinp(CoordFile):
coordtemp = []
while 1:
line = CoordFile.readline()
if line == '': break
if len(line)>8 and line.split()[0].upper()=='GEOMETRY':
while 1:
line = CoordFile.readline()
if line.strip().upper()=='END': break
if line.strip()!='':
line = line.split()
coordtemp.append(line)
break
return coordtemp
def ReadLOG(CoordFile):
filetype = ''
while 1:
line = CoordFile.readline()
if 'GAMESS VERSION' in line:
filetype = 'gms'
break
elif 'Gaussian, Inc.' in line:
filetype = 'gau'
break
elif 'NWChem' in line:
filetype = 'nw'
break
if line == '': break
if filetype == 'gms': coordtemp = ReadGMS(CoordFile)
elif filetype == 'gau': coordtemp = ReadGAU(CoordFile)
elif filetype == 'nw' : coordtemp = ReadNWChem(CoordFile)
else:
print 'Wrong log file format! Exit!',lineno()
return 7
return coordtemp
def ReadGMS(CoordFile):
print '\nGamess file,',
CoordFile.seek(0)
coordtemp =[]
runtyp = ''
while 1:
line = CoordFile.readline()
if line=='': break
#if len(line)>=11 and line[:11]==' INPUT CARD':
if line.find('$CONTRL OPTIONS')>-1:
line = CoordFile.readline()
while 1:
line = CoordFile.readline()
if line.strip()=='': break
if line.find('RUNTYP')>-1:
line = line.split()
for wd in line:
temp = wd.split('=')
if temp[0]=='RUNTYP':
runtyp=temp[1]
break
break
CoordFile.seek(0)
if runtyp == 'OPTIMIZE':
print 'OPT job,',
while 1:
line = CoordFile.readline()
if 'EQUILIBRIUM GEOMETRY LOCATED' in line:
print 'EQUILIBRIUM GEOMETRY LOCATED'
break
if line=='':
print 'BUT equilibrium geometry NOT found! The last frame dumped.',lineno()
break
# Begin read coord:
CoordFile.seek(0)
while 1:
line = CoordFile.readline()
if line == '': break
if line.strip()=='COORDINATES OF ALL ATOMS ARE (ANGS)':
# Found a coord:
coordtemp = []
for ii in range(2): CoordFile.readline()
while 1:
line = CoordFile.readline()
if line.strip()=='': break
line = line.split()
line.pop(1)
coordtemp.append(line)
if coordtemp==[]:
CoordFile.seek(0)
IsFound = False
while 1:
line = CoordFile.readline()
if line=='':
raise Exception, " No coordinates found."
if line.upper().find('INPUT CARD> $DATA')>-1:
CoordFile.readline()
CoordFile.readline()
while 1:
line = CoordFile.readline()
if line.upper().find('INPUT CARD> $END')>-1:
IsFound = True
break
line = line[12:]
line = line.split()
line.pop(1)
coordtemp.append(line)
if IsFound:
sys.stdout.write('Coordinates converted from GAMESS input stream.\n')
return coordtemp
else: return coordtemp
def ReadGAU(CoordFile):
global SpecialData
print '\nGaussian job, end coordinations read.'
CoordFile.seek(0)
runtyp = ''
while 1:
line = CoordFile.readline()
if line=='':
raise Exception, "No coordinates found!"
if len(line)>2 and line[1]=='#':
if 'opt' in line:
runtyp = 'opt'
else:
line = CoordFile.readline()
if 'opt' in line:
runtyp = 'opt'
if line.find('Charge')>-1 and line.find('Multiplicity')>-1:
line = line.split()
SpecialData['TotalCharge'] = int(line[2])
SpecialData['Multiplicity'] = int(line[5])
break
StrangeElement = False
#if runtyp = 'opt':
# print 'Gaussian optimization job.'
while 1:
line = CoordFile.readline()
if line == '': break
if ('Input orientation:' in line) or ('Standard orientation:' in line):
coordtemp = []
for ii in range(4): line = CoordFile.readline()
## Locate coords for current config:
while 1:
line = CoordFile.readline()
if len(line)>9 and line[:10]==' ---------': break
line = line.split()
ndx = int(line[1])
if ndx > len(ELEMENT):
StrangeElement = True
ndx = str(ndx)
else: ndx = ELEMENT[ndx]
coordtemp.append([ndx,line[3],line[4],line[5]])
## Locate energy value for current config:
while 1:
line = CoordFile.readline()
if line=='':
break
if line.find('SCF Done:')>-1:
line = line.split('=')[1]
line = line.split()
SpecialData['Energy'] = float(line[0])
break
if StrangeElement:
print "\n###################################################################"
print "!!!Warning: There are special elements with no symbol assigned!!!"
print "###################################################################"
return coordtemp
def ReadNWChem(CoordFile):
sys.stderr.write('\n NWChem job, end coordinations read.\n')
CoordFile.seek(0)
runtyp = ''
while 1:
line = CoordFile.readline()
if line == '': break
elif line.strip() == 'NWChem Geometry Optimization':
runtyp = 'opt'
break
if runtyp == '':
print '\nNot an optimization job, exit.',lineno()
return 100
else:
IsOpted = False
CoordFile.seek(0)
coordtemp = []
coordtempbackup = []
while 1:
line = CoordFile.readline()
if line == '': break
templine = line.split()
if len(templine)==2 and templine[0]=='Step':
coordtempbackup = []
while 1:
line = CoordFile.readline()
line = line.strip()
if line.find('No.')==0: break
line = CoordFile.readline()
while 1:
line = CoordFile.readline()
if line.strip()=='': break
line = line.split()
line.pop(0)
line.pop(1)
coordtempbackup.append(line)
coordtemp = deepcopy(coordtempbackup)
if line.strip() == 'Optimization converged':
IsOpted = True
coordtemp = []
while 1:
line = CoordFile.readline()
if line.strip() == 'Geometry "geometry" -> "geometry"':
for ii in range(6): CoordFile.readline()
while 1:
line = CoordFile.readline()
if line.strip()=='': break
line = line.split()
line.pop(0)
line.pop(1)
coordtemp.append(line)
break
break
if IsOpted: sys.stderr.write(' Optimization converged.\n')
else: sys.stderr.write(' Optimization NOT converged, last configuration read.\n')
return coordtemp
def ReadREBO(CoordFile):
coordtemp = []
while 1:
line = CoordFile.readline()
if line == '': break
line = line.split()
if (len(line)>1) and (line[1].lower()=='atoms'):
Natoms = int(line[0])
if len(line)>0 and line[0].lower() == 'atoms':
CoordFile.readline()
for ii in xrange(Natoms):
line = CoordFile.readline()
line = line.split()
if line[1]=='1': elem = 'C'
else: elem = 'H'
coordtemp.append([elem, line[2], line[3], line[4]])
return coordtemp
#def ReadARC(CoordFile, PDBFile):
def ReadGRO(CoordFile):
return 6
################## Writing procedures ##########################
def WriteXYZ(file_h, coords):
file_h.write("%d\nAtoms\n" % len(coords))
for atom in coords:
file_h.write("%2s" % atom[0])
for ii in range(1,4):
file_h.write("%15s" % atom[ii])
file_h.write("\n")
file_h.write("\n")
return
def WriteGJF(file_h, coords):
prefix = os.path.splitext(SpecialData['OutputFileName'])[0]
file_h.write("%%chk=%s.chk\n%%mem=500MW\n%%nprocshared=8\n"%prefix)
file_h.write("# B3LYP/6-31g(d)\n\n")
file_h.write('From "%s"'%SpecialData['InputFileName'])
if SpecialData==0.0: pass
else:
file_h.write(' E: %12.8f'%SpecialData['Energy'])
file_h.write('\n\n')
file_h.write("%d %d\n"%\
(SpecialData['TotalCharge'], SpecialData['Multiplicity']))
for atom in coords:
file_h.write("%2s" % atom[0])
for ii in range(1,4):
file_h.write("%18s" % atom[ii])
file_h.write("\n")
file_h.write("\n")
return
def WriteMOPAC(file_h, coords):
file_h.write("pm7 xyz charge=0 opt thread=8\n")
file_h.write("Mopac 2012 input file generated by mol2mol -- zhao_lf@yeah.net\n")
file_h.write("Title Card Required\n")
for atom in coords:
file_h.write(" %2s" % atom[0])
for ii in range(1,4):
file_h.write("%18s" % atom[ii])
file_h.write(" +1 " % atom[ii])
file_h.write("\n")
file_h.write("\n")
print """
Note:
Default of Mopac 2012 input file:
1. charge=0;
2. multiplicity is 1;
3. optimization job;
4. pm7 method.
You can modify the settings according to http://openmopac.net/manual/index_troubleshooting.html.
"""
return
def WriteINP(file_h, coords):
file_h.write("! Gamess input file generated by mol2mol.\n")
file_h.write(GAMESS_Settings)
for atom in coords:
file_h.write("%2s" % atom[0])
if atom[0].upper() in ZCharge:
file_h.write("%8s" % ZCharge[atom[0].upper()])
else:
file_h.write("%8s" % "X") # if the element is unknown print 'X'.
print "\n###################################################################"
print "!!!Warning: There are special elements with no atom No. assigned!!!"
print "###################################################################"
for ii in range(1,4): file_h.write("%15s" % atom[ii])
file_h.write("\n")
file_h.write(" $END\n")
return
def WritePDB(file_h, coords, IsWrtTitle=True, NdxAtom=1, NameRes='LIG', NdxRes=1):
if IsWrtTitle:
file_h.write('TITLE THIS PDB FILE IS GENERATED BY "mol2mol" --lfzhao.\n')
for atom in coords:
file_h.write("ATOM %5d%3s%6s A%4d%12.3f%8.3f%8.3f 1.00 0.00\n" % (NdxAtom,atom[0], NameRes, NdxRes,float(atom[1]),float(atom[2]),float(atom[3])))
NdxAtom += 1
return
def WriteNWinp(file_h, coords):
file_h.write('Title "NWChem input file generated by mol2mol. --L. Zhao"\n\n')
file_h.write('echo\nstart\n\nmemory 2000 mb\n\n')
file_h.write('geometry units angstroms\n')
for atom in coords:
file_h.write('%2s' % atom[0])
for ii in range(1,4):
file_h.write('%18s' % atom[ii])
file_h.write('\n')
file_h.write('end\n\nbasis\n * library 6-31g*\nend\n\nscf direct; end\n\n')
file_h.write('dft\n xc b3lyp\n iterations 300\nend\n\ntask dft optimize')
return
def WriteAIREBO(file_h, coords):
file_h.write('# This file is for McRebo program. Generated by "mol2mol" - lfzhao\n\n')
Ntemp = len(coords)
file_h.write('%5d atoms\n\n' % Ntemp)
file_h.write('2 atom types\n\n')
file_h.write('0.0 30.0 xlo xhi\n')
file_h.write('0.0 30.0 ylo yhi\n')
file_h.write('0.0 30.0 zlo zhi\n\n')
file_h.write('Masses\n\n 1 12.01100 # C\n 2 1.00794 # H\n\n')
file_h.write('Atoms\n\n')
for ii in range(Ntemp):
if coords[ii][0]=='C': Ttemp = 1
elif coords[ii][0]=='H': Ttemp = 2
else:
raise Exception, ' Error: atom name is not "C" or "H"'
file_h.write('%6d %6d %8s %8s %8s\n' % \
(ii+1, Ttemp, coords[ii][1], coords[ii][2], coords[ii][3]))
sys.stderr.write("\n###################################################################\n")
sys.stderr.write("!!! CAUTION: Default box size used (30 Angstrom). \n")
sys.stderr.write("###################################################################\n")
return
def WriteGRO(file_h, coords):
return
def NW2GMS(file1,file2):
## Locate file head of frequency calculation:
while 1:
line = file1.readline()
if line == '':
print 'Error in reading file.',lineno()
sys.exit(1)
if line.strip()=='NWChem Nuclear Hessian and Frequency Analysis':
for ii in range(5): line = file1.readline()
if 'Analytic' in line:
print '\nAnalytic Hessian Calculation.'
elif 'Finite-difference' in line:
print '\nNumerical Hessian Calculation.'
else: print '\nUnknown Type Hessian Calculation :('
break
## Find Energy:
while 1:
line = file1.readline()
if line == '':
print '\nError in reading file. Line %d\n' % lineno()
sys.exit(1)
if 'Total DFT energy =' in line:
print '\nDFT calculations.'
line = line.split()
Energy = float(line[-1])
break
elif 'Total MP2 energy' in line:
print '\nMP2 calculations.'
line = line.split()
Energy = float(line[-1])
break
## Locate atomic coordinates:
while 1:
line = file1.readline()
if line == '':
print '\nError in reading file. Line %d\n' % lineno()
sys.exit(1)
if 'Atom information' in line: break
file1.readline()
file1.readline()
## Read atomic coordinates:
temp_coord = []
while 1:
line = file1.readline()
if line[1:11]=='----------': break
line = line.split()
for ii in range(2,5): line[ii] = float(line[ii].replace('D','E'))
temp_coord.append(line)
NumOfAtoms = len(temp_coord)
dim = 3*NumOfAtoms
freqs = []
dxyz = []
for ii in range(dim): dxyz.append([])
## Locate & read freqencies values:
OK = False
while 1:
line = file1.readline()
if 'Projected Frequencies expressed in cm-1' in line:
while 1:
for ii in range(3): file1.readline()
line = file1.readline()
line = line.split()
for ii in line[1:]: freqs.append(float(ii))
file1.readline()
for ii in range(dim):
line = file1.readline()
line = line.split()
for jj in line[1:]: dxyz[ii].append(float(jj))
if len(dxyz[0])>=dim:
OK = True
break
if OK: break
## Locate & read freqencies intensities:
intensities = []
while 1:
line = file1.readline()
if 'Projected Infra Red Intensities' in line:
file1.readline()
file1.readline()
for ii in range(dim):
line = file1.readline()
line = line.split()
intensities.append(float(line[4]))
break
# Write Gamess log file.
file2.write(""" ******************************************************
* GAMESS VERSION = 11 APR 2008 (R1) *
* FROM IOWA STATE UNIVERSITY *
* M.W.SCHMIDT, K.K.BALDRIDGE, J.A.BOATZ, S.T.ELBERT, *
* M.S.GORDON, J.H.JENSEN, S.KOSEKI, N.MATSUNAGA, *
* K.A.NGUYEN, S.J.SU, T.L.WINDUS, *
* TOGETHER WITH M.DUPUIS, J.A.MONTGOMERY *
* J.COMPUT.CHEM. 14, 1347-1363(1993) *
**************** 64 BIT INTEL VERSION ****************
THE POINT GROUP OF THE MOLECULE IS C1
THE ORDER OF THE PRINCIPAL AXIS IS 0
ATOM ATOMIC COORDINATES (BOHR)
CHARGE X Y Z
""")
for atom in temp_coord[:]:
file2.write('%2s%14s%17.10f%20.10f%20.10f\n' % (atom[0],ZCharge[atom[0]],atom[2],atom[3],atom[4]))
file2.write("""\n $CONTRL OPTIONS
---------------
SCFTYP=RHF RUNTYP=HESSIAN EXETYP=RUN
FINAL R-B3LYP1 ENERGY IS%20.10f AFTER 11 ITERATIONS
FREQUENCIES IN CM**-1, IR INTENSITIES IN DEBYE**2/AMU-ANGSTROM**2,
REDUCED MASSES IN AMU.
--------------------------------------------------------
NORMAL COORDINATE ANALYSIS IN THE HARMONIC APPROXIMATION
--------------------------------------------------------
""" % Energy)
ndx = 0
OK = False
while 1:
ndx_begin = ndx*5
ndx_end = (ndx+1)*5
if ndx_end >= dim:
ndx_end = dim
OK = True
file2.write('\n ')
for ii in range(ndx_begin,ndx_end): file2.write('%12d' % (ii+1))
file2.write('\n FREQUENCY: ')
for ii in range(ndx_begin,ndx_end): file2.write('%12.2f' % (freqs[ii]))
file2.write('\n IR INTENSITY: ')
for ii in range(ndx_begin,ndx_end): file2.write('%12.5f' % (intensities[ii]))
file2.write('\n')
for ii in range(dim):
temp_ndx0 = int(ii+1)/3
temp_ndx1 = (ii+1)%3
if temp_ndx1 == 1: file2.write('\n%3d%4s X' % (temp_ndx0+1,temp_coord[temp_ndx0-1][0]))
elif temp_ndx1 == 2: file2.write('\n Y')
elif temp_ndx1 == 0: file2.write('\n Z')
for jj in range(ndx_begin,ndx_end): file2.write('%12.8f' % dxyz[ii][jj])
file2.write('\n')
if OK: break
ndx = ndx + 1
return
def Translate(IFileName, OFileName, params={}):
file1type = os.path.splitext(IFileName)
file2type = os.path.splitext(OFileName)
file1type = file1type[1]
file2type = file2type[1]
Ifile = open(IFileName, 'r')
Ofile = open(OFileName, 'w')
if params['-n2g']:
NW2GMS(Ifile, Ofile)
Ifile.close()
Ofile.close()
sys.stderr.write('\n Done.\n\n')
sys.exit(0)
if params['-pdb']:
PDBFile = open(params['-pdb'],'r')
CoordAll = ReadARC()
PDBFile.close()
sys.exit()
CoordFile = Ifile
if file1type == '.xyz': Coordtemp = ReadXYZ(CoordFile)
elif (file1type == '.gjf') \
or (file1type == '.com'): Coordtemp = ReadGJF(CoordFile)
elif file1type == '.pdb': Coordtemp = ReadPDB(CoordFile)
elif file1type == '.inp': Coordtemp = ReadINP(CoordFile)
elif file1type == '.log': Coordtemp = ReadLOG(CoordFile)
elif file1type == '.nwo': Coordtemp = ReadLOG(CoordFile)
elif file1type == '.nw' : Coordtemp = ReadNWinp(CoordFile)
elif file1type == '.data': Coordtemp = ReadREBO(CoordFile)
else: Coordtemp = ReadGRO(CoordFile)
if isinstance(Coordtemp, int):
raise Exception, 'Input file format not known. Failed.'
coords = Coordtemp
if file2type == '.xyz': WriteXYZ(Ofile, coords)
elif (file2type == '.gjf') \
or (file2type == '.com'): WriteGJF(Ofile, coords)
elif file2type == '.pdb': WritePDB(Ofile, coords)
elif file2type == '.inp': WriteINP(Ofile, coords)
elif file2type == '.nw': WriteNWinp(Ofile, coords)
elif file2type == '.data': WriteAIREBO(Ofile, coords)
elif file2type == '.minp': WriteMOPAC(Ofile, coords)
else: WriteGRO(file2, coords)
Ifile.close()
Ofile.close()
return
def ReadArgs():
usage = """ Usage: -f string : Input file name;
-o string : Output file name;
-n2t (optional)boolean Only for Translation from nwchem FREQUENCIES to gamess format
-pdb (optional)string Only for Translation from Tinker arc/xyz to pdb format
File formats allowed currently:
GAUSSIAN: (input) .gjf, .com
GAMESS-US: (input) .inp
.log (read only)
TINKER: .xyz (read only)
PDB: .pdb
NWCHEM: .nw
.nwo (read only)
MOPAC: .minp (generate input file only)
Please report bugs to <zhao_lf@yeah.net>\n\n"""
argv_err = """ Arguments error! Try "-h".\n"""
options = {'-f':'','-o':'','-pdb':''}
optionsYN = {'-n2g':False}
sys.stderr.write(__doc__)
num_argvs = len(sys.argv)
## No other arguments:
if num_argvs==1:
sys.stderr.write(usage)
sys.exit(1)
## Only one argument:
elif num_argvs==2:
if sys.argv[1]=='-h' or sys.argv[1]=='--help':
sys.stdout.write(usage)
sys.exit(0)
else:
raise Exception, argv_err
## Simple input format:
elif num_argvs==3:
options['-f'] = sys.argv[1]
options['-o'] = sys.argv[2]
options['-n2g'] = False
options['-pdb'] = False
return options
## More than one:
else:
ndx = 1
while 1:
if sys.argv[ndx] in options:
#if ndx==num_argvs-1: break
#else:
options[sys.argv[ndx]] = sys.argv[ndx+1]
ndx += 2
elif sys.argv[ndx] in optionsYN:
if (ndx+1)>=num_argvs or sys.argv[ndx+1][0] == '-':
optionsYN[sys.argv[ndx]] = True
ndx += 1
elif sys.argv[ndx+1].upper() in ['Y','YES','T','TRUE']:
optionsYN[sys.argv[ndx]] = True
ndx += 2
else:
ndx += 2
else:
sys.stderr.write(argv_err)
sys.exit(1)
if ndx >= num_argvs: break
for ii in optionsYN.keys(): options[ii]=optionsYN[ii]
return options
if __name__ == '__main__':
options = ReadArgs()
file1name = options['-f']
file2name = options['-o']
SpecialData['InputFileName'] = file1name
SpecialData['OutputFileName'] = file2name
params = {}
params['-n2g'] = options['-n2g']
params['-pdb'] = options['-pdb']
## TRANSLATE:
Translate(file1name, file2name, params)
sys.stderr.write('\n Done.\n\n')
sys.exit(0)