-
Notifications
You must be signed in to change notification settings - Fork 0
/
RUN_lamaGOET.sh
executable file
·1485 lines (1450 loc) · 72.2 KB
/
RUN_lamaGOET.sh
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
#!/bin/bash
export LC_NUMERIC="en_US.UTF-8"
source job_options.txt
GAMESS_ELMODB_OLD_PDB(){
I=$[ $I + 1 ]
PDB=$( echo $CIF | awk -F "/" '{print $NF}' )
echo "title" > $JOBNAME.gamess.inp
echo "prova $JOBNAME - $BASISSETG - closed shell SCF" >> $JOBNAME.gamess.inp
echo "charge $CHARGE " >> $JOBNAME.gamess.inp
if [ "$MULTIPLICITY" != "1" ]; then
echo "multiplicity $MULTIPLICITY" >> $JOBNAME.gamess.inp
fi
echo "adapt off" >> $JOBNAME.gamess.inp
echo "nosym" >> $JOBNAME.gamess.inp
echo "geometry angstrom" >> $JOBNAME.gamess.inp
if [ "$I" = "1" ]; then
awk '$1 ~ /ATOM/ {printf "%f\t %f\t %f\t %s\t %s\n", $6, $7, $8, "carga", $3}' $CIF > atoms
else
awk 'NR > 2 {printf "%f\t %f\t %f\t %s\t %s\n", $2, $3, $4, "carga", $1}' $JOBNAME.xyz > atoms
fi
awk '{print $5}' atoms | gawk 'BEGIN { FS = "" } {print $1}' | awk '{ if ($1 == "N") print "7.0"; else if ($1 == "H") print "1.0"; else if ($1 == "O") print "8.0"; else if ($1 == "C") print "6.0"; else if ($1 == "S") print "16.0"; }' > atoms_Z
awk '{print $5}' atoms | gawk 'BEGIN { FS = "" } {print $1}' > atoms_names
awk 'FNR==NR{a[NR]=$1;next}{$4=a[FNR]}1' atoms_Z atoms > full
cp full atoms
awk 'FNR==NR{a[NR]=$1;next}{$5=a[FNR]}1' atoms_names atoms > full
awk '{printf "%f\t %f\t %f\t %s\t %s\n", $1, $2, $3, $4, $5}' full >> $JOBNAME.gamess.inp
# awk '{printf "%8.3f\t %8.3f\t %8.3f\t %s\t %s\n", $1, $2, $3, $4, $5}' full >> $JOBNAME.gamess.inp
#awk '$1 ~ /ATOM/ {printf "%f\t %f\t %f\t %s\t %s\n", $6, $7, $8, "carga", $3} ' $CIF >> $JOBNAME.gamess.inp
rm atoms
rm atoms_Z
rm full
rm atoms_names
echo "end" >> $JOBNAME.gamess.inp
case "6-31g(d,p)" in
$BASISSETG ) echo "basis 6-31G**" >> $JOBNAME.gamess.inp;;
*) case "6-311g(d,p)" in
$BASISSETG ) echo "basis 6-311G**" >> $JOBNAME.gamess.inp;;
*) echo "basis $BASISSETG" >> $JOBNAME.gamess.inp;;
esac;;
esac
# if [ $BASISSET == "6-31g(d,p)" ]; then
# echo "basis 6-31G**" >> $JOBNAME.gamess.inp
# elif [ $BASISSET == "6-311g(d,p)" ]; then
# echo "basis 6-311G**" >> $JOBNAME.gamess.inp
# else
# echo "basis $BASISSET" >> $JOBNAME.gamess.inp
# fi
echo "runtype scf" >> $JOBNAME.gamess.inp
echo "scftype rhf" >> $JOBNAME.gamess.inp
echo "enter " >> $JOBNAME.gamess.inp
echo "Calculating overlap integrals with gamessus, cycle number $I"
$GAMESS < $JOBNAME.gamess.inp > $JOBNAME.gamess.out
echo "Gamess cycle number $I ended"
mkdir $I.$SCFCALCPROG.cycle.$JOBNAME
cp $JOBNAME.gamess.inp $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.gamess.inp
cp $JOBNAME.gamess.out $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.gamess.out
cp sao $I.$SCFCALCPROG.cycle.$JOBNAME/$I.sao
rm ed*
rm gamess_input*
if ! grep -q 'OVERLAP INTEGRALS WRITTEN ON FILE sao' "$JOBNAME.gamess.out"; then
echo "ERROR: Calculation of overlap integrals with gamessus finished with error, please check the $I.th gamess.out file for more details" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
else
echo "Calculation of overlap integrals with gamess done, writing elmodb input files"
# if [[ ! -e "LIBRARIES" ]]; then
# ln -s $ELMOLIB LIBRARIES
# fi
# if [[ ! -f "elmodb.exe" ]]; then
if [[ ! -f "$( echo $SCFCALC_BIN | awk -F "/" '{print $NF}' )" ]]; then
cp $SCFCALC_BIN .
fi
if [ "$I" = "1" ]; then
# PDB=$( echo $CIF | awk -F "/" '{print $NF}' )
BASISSETDIR=$( echo "$(dirname $BASISSETDIR)/" )
ELMOLIB=$( echo "$(dirname $ELMOLIB)/" )
echo " "'$INPUT_METHOD'" job_title='$JOBNAME' basis_set='$BASISSETG' iprint_level=1 ncpus=$NUMPROC alloc_mem=$MEM bset_path='$BASISSETDIR' lib_path='$ELMOLIB' nci=.true. comp_sao=.false. "'$END'" " > $JOBNAME.elmodb.inp
echo " "'$INPUT_STRUCTURE'" pdb_file='$PDB' ntail=$NTAIL nssbond=$NSSBOND "'$END'" " >> $JOBNAME.elmodb.inp
if [[ "$NTAIL" != "0" ]]; then
echo "$MANUALRESIDUE" >> $JOBNAME.elmodb.inp
fi
if [[ "$NSSBOND" != "0" ]]; then
echo "$SSBONDATOMS" >> $JOBNAME.elmodb.inp
fi
else
echo " "'$INPUT_METHOD'" job_title='$JOBNAME' basis_set='$BASISSETG' xyz=.true. iprint_level=1 ncpus=$NUMPROC alloc_mem=$MEM bset_path='$BASISSETDIR' lib_path='$ELMOLIB' nci=.true. comp_sao=.false. "'$END'" " > $JOBNAME.elmodb.inp
echo " "'$INPUT_STRUCTURE'" pdb_file='$PDB' xyz_file='$JOBNAME.xyz' ntail=$NTAIL nssbond=$NSSBOND "'$END'" " >> $JOBNAME.elmodb.inp
if [[ "$NTAIL" != "0" ]]; then
echo "$MANUALRESIDUE" >> $JOBNAME.elmodb.inp
fi
if [[ "$NSSBOND" != "0" ]]; then
echo "$SSBONDATOMS" >> $JOBNAME.elmodb.inp
fi
fi
echo "Running elmodb"
./$( echo $SCFCALC_BIN | awk -F "/" '{print $NF}' ) < $JOBNAME.elmodb.inp > $JOBNAME.elmodb.out
if ! grep -q 'CONGRATULATIONS: THE ELMO-TRANSFERs ENDED GRACEFULLY!!!' "$JOBNAME.elmodb.out"; then
echo "ERROR: elmodb finished with error, please check the $I.th elmodb.out file for more details" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
else
echo "elmodb job finish correctly."
cp $JOBNAME.elmodb.out $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.elmodb.out
cp $JOBNAME.elmodb.inp $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.elmodb.inp
cp $JOBNAME.fchk $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.elmodb.fchk
if [ "$I" != "1" ]; then
cp $JOBNAME.xyz $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.xyz
fi
fi
fi
#elmo part finished here, now we will run gaussian only once to obtain a formated fchk file that will be edited with the results from elmo
#if [ "$I" = "1" ]; then
# echo "Writing fchk file with Gaussian"
# echo "%chk=./$JOBNAME.chk" > $JOBNAME.com
# echo "%rwf=./$JOBNAME.rwf" >> $JOBNAME.com
# echo "%int=./$JOBNAME.int" >> $JOBNAME.com
# echo "%mem=$MEM" >> $JOBNAME.com
# echo "%nprocshared=$NUMPROC" >> $JOBNAME.com
#BEWARE only rhf for elmodb
# echo "# $METHOD/$BASISSET nosymm output=wfn 6D 10F" >> $JOBNAME.com
# echo "" >> $JOBNAME.com
# echo "$JOBNAME" >> $JOBNAME.com
# echo "" >> $JOBNAME.com
# echo "$CHARGE $MULTIPLICITY" >> $JOBNAME.com
# awk '$1 ~ /ATOM/ {printf "%s\t %8.3f\t %8.3f\t %8.3f\n", substr($3,1,1), $6, $7, $8}' $CIF >> $JOBNAME.com
# echo "" >> $JOBNAME.com
# echo "./$JOBNAME.wfn" >> $JOBNAME.com
# echo "" >> $JOBNAME.com
# echo "Runing Gaussian, cycle number $I"
# g09 $JOBNAME.com
# echo "Gaussian cycle number $I ended"
# if ! grep -q 'Normal termination of Gaussian' "$JOBNAME.log"; then
# echo "ERROR: Gaussian job finished with error, please check the $I.th log file for more details" | tee -a $JOBNAME.lst
# unset MAIN_DIALOG
# exit 0
# fi
# echo "Generation fcheck file for Gaussian cycle number $I"
# formchk $JOBNAME.chk $JOBNAME.fchk
#fi
#sed -i -ne '/Alpha MO coefficients/ {p; r MOs' -e ':a; n; /Total SCF Density/ {p; b}; ba}; p' $JOBNAME.fchk
#sed -i -ne '/Total SCF Density/ {p; r DMAT' -e ':a; n; /Mulliken Charges/ {p; b}; ba}; p' $JOBNAME.fchk
#cp $JOBNAME.fchk $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.elmodb.fchk
}
ELMODB(){
I=$[ $I + 1 ]
#if [[ ! -e "LIBRARIES" ]]; then
# ln -s $ELMOLIB LIBRARIES
#fi
# if [[ ! -f "elmodb.exe" ]]; then
if [[ ! -f "$( echo $SCFCALC_BIN | awk -F "/" '{print $NF}' )" ]]; then
cp $SCFCALC_BIN .
fi
if [ "$I" = "1" ]; then
# PDB=$( echo $CIF | awk -F "/" '{print $NF}' )
BASISSETDIR=$( echo "$(dirname $BASISSETDIR)/" )
ELMOLIB=$( echo "$(dirname $ELMOLIB)/" )
echo " "'$INPUT_METHOD'" job_title='$JOBNAME' basis_set='$BASISSETG' iprint_level=1 ncpus=$NUMPROC alloc_mem=$MEM bset_path='$BASISSETDIR' lib_path='$ELMOLIB' nci=.true. "'$END'" " > $JOBNAME.elmodb.inp
if [[ "$INITADP" == "true" ]];then
echo " "'$INPUT_STRUCTURE'" pdb_file='$PDB' cif_file='$INITADPFILE' ntail=$NTAIL max_atail=$ATAIL max_frtail=$FRTAIL nssbond=$NSSBOND "'$END'" " >> $JOBNAME.elmodb.inp
else
echo " "'$INPUT_STRUCTURE'" pdb_file='$PDB' ntail=$NTAIL max_atail=$ATAIL max_frtail=$FRTAIL nssbond=$NSSBOND "'$END'" " >> $JOBNAME.elmodb.inp
fi
if [[ "$NTAIL" != "0" ]]; then
echo "$MANUALRESIDUE" >> $JOBNAME.elmodb.inp
fi
if [[ "$NSSBOND" != "0" ]]; then
echo "$SSBONDATOMS" >> $JOBNAME.elmodb.inp
fi
else
echo " "'$INPUT_METHOD'" job_title='$JOBNAME' basis_set='$BASISSETG' xyz=.true. iprint_level=1 ncpus=$NUMPROC alloc_mem=$MEM bset_path='$BASISSETDIR' lib_path='$ELMOLIB' nci=.true. "'$END'" " > $JOBNAME.elmodb.inp
if [[ "$NTAIL" != "0" ]]; then
echo " "'$INPUT_STRUCTURE'" pdb_file='$PDB' xyz_file='$JOBNAME.xyz' ntail=$NTAIL max_atail=$ATAIL max_frtail=$FRTAIL nssbond=$NSSBOND "'$END'" " >> $JOBNAME.elmodb.inp
echo "$MANUALRESIDUE" >> $JOBNAME.elmodb.inp
else
echo " "'$INPUT_STRUCTURE'" pdb_file='$PDB' xyz_file='$JOBNAME.xyz' nssbond=$NSSBOND "'$END'" " >> $JOBNAME.elmodb.inp
fi
if [[ "$NSSBOND" != "0" ]]; then
echo "$SSBONDATOMS" >> $JOBNAME.elmodb.inp
fi
fi
./$( echo $SCFCALC_BIN | awk -F "/" '{print $NF}' ) < $JOBNAME.elmodb.inp > $JOBNAME.elmodb.out
if ! grep -q 'CONGRATULATIONS: THE ELMO-TRANSFERs ENDED GRACEFULLY!!!' "$JOBNAME.elmodb.out"; then
echo "ERROR: elmodb finished with error, please check the $I.th elmodb.out file for more details" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
else
mkdir $I.$SCFCALCPROG.cycle.$JOBNAME
cp $JOBNAME.elmodb.out $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.elmodb.out
cp $JOBNAME.elmodb.inp $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.elmodb.inp
cp $JOBNAME.fchk $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.elmodb.fchk
if [ "$I" != "1" ]; then
cp $JOBNAME.xyz $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.xyz
fi
fi
}
CHECK_ELMO(){
LINES=$(wc -l < $JOBNAME.elmodb.out | tr -d '\r')
PERCENT1=$[ LINES / 100 ]
}
TONTO_TO_ORCA(){
I=$[ $I + 1 ]
echo "Extrating XYZ for Orca cycle number $I"
if [ "$METHOD" = "rks" ]; then
echo "! blyp $BASISSETG" > $JOBNAME.inp
else
if [ "$METHOD" = "uks" ]; then
echo "! ublyp $BASISSETG" > $JOBNAME.inp
else
echo "! $METHOD $BASISSETG" > $JOBNAME.inp
fi
fi
echo "" >> $JOBNAME.inp
echo "%output" >> $JOBNAME.inp
echo " PrintLevel=Normal" >> $JOBNAME.inp
echo " Print[ P_Basis ] 2" >> $JOBNAME.inp
echo " Print[ P_GuessOrb ] 1" >> $JOBNAME.inp
echo " Print[ P_MOs ] 1" >> $JOBNAME.inp
echo " Print[ P_Density ] 1" >> $JOBNAME.inp
echo " Print[ P_SpinDensity ] 1" >> $JOBNAME.inp
echo "end" >> $JOBNAME.inp
echo "" >> $JOBNAME.inp
echo "* xyz $CHARGE $MULTIPLICITY" >> $JOBNAME.inp
awk 'NR>2' $JOBNAME.xyz >> $JOBNAME.inp
if [ "$SCCHARGES" = "true" ]; then
awk '{a[NR]=$0}{b=12}/^------------------------------------------------------------------------/{c=NR}END{for(d=b;d<=c-1;++d)print a[d]}' gaussian-point-charges | awk '{printf "%s\t %s\t %s\t %s\t \n", "Q\t" $2, $3, $4, $1 }' >> $JOBNAME.inp
fi
echo "*" >> $JOBNAME.inp
echo "Running Orca, cycle number $I"
$SCFCALC_BIN $JOBNAME.inp > $JOBNAME.log
echo "Orca cycle number $I ended"
if ! grep -q '****ORCA TERMINATED NORMALLY****' "$JOBNAME.out"; then
echo "ERROR: Orca job finished with error, please check the $I.th out file for more details" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
fi
echo "Generation molden file for Orca cycle number $I"
orca_2mkl $JOBNAME -molden
echo "Orca cycle number $I, final energy is: $ENERGIA, RMSD is: $RMSD "
mkdir $I.$SCFCALCPROG.cycle.$JOBNAME
cp $JOBNAME.inp $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.inp
cp $JOBNAME.molden.input $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.molden.input
cp $JOBNAME.log $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.log
}
SCF_TO_TONTO(){
# echo "Writing Tonto stdin"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" > stdin
echo "!!! !!!" >> stdin
echo "!!! This stdin was written with lamaGOET !!!" >> stdin
echo "!!! !!!" >> stdin
echo "!!! script written by Lorraine Andrade Malaspina !!!" >> stdin
echo "!!! contact: [email protected] !!!" >> stdin
echo "!!! !!!" >> stdin
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> stdin
echo "{ " >> stdin
echo "" >> stdin
echo " keyword_echo_on" >> stdin
echo "" >> stdin
if [ "$SCFCALCPROG" = "elmodb" ]; then
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
echo " read_g09_fchk_file $JOBNAME.fchk" >> stdin
fi
if [ "$SCFCALCPROG" = "Gaussian" ]; then
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
echo " read_g09_fchk_file $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.fchk" >> stdin
elif [ "$SCFCALCPROG" = "Orca" ]; then
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
echo " read_molden_file $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.molden.input" >> stdin
else
echo " name= $JOBNAME" >> stdin
fi
echo "" >> stdin
#echo " charge= $CHARGE" >> stdin
#echo " multiplicity= $MULTIPLICITY" >> stdin
#echo "" >> stdin
if [ "$SCFCALCPROG" != "elmodb" ]; then
# if [[ "$SCFCALCPROG" != "Gaussian" && "$SCFCALCPROG" != "Orca" && "$COMPLETESTRUCT" != "true" ]]; then
echo " ! Process the CIF" >> stdin
echo " CIF= {" >> stdin
if [ $J = 0 ]; then
if [[ "$COMPLETESTRUCT" == "true" && "$SCFCALCPROG" != "Tonto" ]]; then
echo " file_name= $J.fit_cycle.$JOBNAME/$J.$JOBNAME.cartesian.cif2" >> stdin
else
echo " file_name= $CIF" >> stdin
fi
if [ "$XHALONG" = "true" ]; then
if [[ ! -z "$BHBOND" ]]; then
echo " BH_bond_length= $BHBOND angstrom" >> stdin
fi
if [[ ! -z "$CHBOND" ]]; then
echo " CH_bond_length= $CHBOND angstrom" >> stdin
fi
if [[ ! -z "$NHBOND" ]]; then
echo " NH_bond_length= $NHBOND angstrom" >> stdin
fi
if [[ ! -z "$OHBOND" ]]; then
echo " OH_bond_length= $OHBOND angstrom" >> stdin
fi
fi
else
# cp $JOBNAME'_cartesian.cif2' $JOBNAME.cartesian.cif2
echo " file_name= $J.fit_cycle.$JOBNAME/$J.$JOBNAME.cartesian.cif2" >> stdin
fi
echo " }" >> stdin
echo "" >> stdin
echo " process_CIF" >> stdin
echo "" >> stdin
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
fi
if [[ $J -gt 0 && "$SCFCALCPROG" == "elmodb" ]]; then
echo " ! Process the CIF" >> stdin
echo " CIF= {" >> stdin
echo " file_name= $J.fit_cycle.$JOBNAME/$J.$JOBNAME.cartesian.cif2" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " process_CIF" >> stdin
echo "" >> stdin
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
#cp $JOBNAME'_cartesian.cif2' $JOBNAME.cartesian.cif2
#echo " file_name= $JOBNAME.cartesian.cif2" >> stdin
#else
#echo " file_name= $CIF" >> stdin
fi
if [[ $J -eq 0 && "$SCFCALCPROG" == "elmodb" && "$INITADP" == "true" ]]; then
echo " ! Process the CIF" >> stdin
echo " CIF= {" >> stdin
echo " file_name= $INITADPFILE" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " process_CIF" >> stdin
echo "" >> stdin
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
fi
if [ "$SCFCALCPROG" = "Tonto" ]; then
echo " basis_directory= $BASISSETDIR" >> stdin
echo " basis_name= $BASISSETT" >> stdin
echo "" >> stdin
fi
if [ "$DISP" = "yes" ]; then
echo " dispersion_coefficients= {" >> stdin
echo " $(cat DISP_inst.txt)" >> stdin
#commented but its the working one
# for ((L=0; i<${#XDISP[]*]}; L++));
# do
# echo " ${XDISP[L]}" >> stdin
# done
echo " }" >> stdin
echo "" >> stdin
fi
# if [ "$SCFCALCPROG" != "elmodb" ]; then
# if [[ $J == 0 && "$COMPLETESTRUCT" == "true" && "$SCFCALCPROG" != "Gaussian" && "$SCFCALCPROG" != "Orca" ]]; then
# echo " cluster= {" >> stdin
# echo " defragment= $COMPLETESTRUCT" >> stdin
# echo " make_info" >> stdin
# echo " }" >> stdin
# echo "" >> stdin
# echo " create_cluster" >> stdin
# echo "" >> stdin
# echo " name= $JOBNAME" >> stdin
# echo "" >> stdin
# fi
# fi
echo " charge= $CHARGE" >> stdin
echo " multiplicity= $MULTIPLICITY" >> stdin
if [[ $J == 0 && "$IAMTONTO" == "true" ]]; then
echo ""
echo " crystal= { " >> stdin
if [[ "$SCFCALCPROG" = "elmodb" && "$INITADP" == "false" ]]; then
echo " REDIRECT tonto.cell" >> stdin
fi
# if [ "$COMPLETESTRUCT" = "true" ]; then
# echo " defragment= $COMPLETESTRUCT" >> stdin
# echo " make_info" >> stdin
# echo " put_cluster_info" >> stdin
# fi
echo " xray_data= { " >> stdin
echo " optimise_extinction= false" >> stdin
echo " correct_dispersion= $DISP" >> stdin
echo " wavelength= $WAVE Angstrom" >> stdin
if [ "$REFANHARM" == "true" ]; then
if [[ "$THIRDORD" == "false" && "$FOURTHORD" == "true" ]]; then
echo " refine_4th_order_only= true " >> stdin
echo " refine_4th_order_for_atoms= { $ANHARMATOMS } " >> stdin
elif [[ "$THIRDORD" == "true" && "$FOURTHORD" == "true" ]]; then
echo " refine_4th_order_for_atoms= { $ANHARMATOMS } " >> stdin
elif [[ "$THIRDORD" == "true" && "$FOURTHORD" == "false" ]]; then
echo " refine_3rd_order_for_atoms= { $ANHARMATOMS } " >> stdin
else
echo "ERROR: Please select at least one of the anharmonic terms to refine" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
fi
fi
echo " REDIRECT $HKL" >> stdin
echo " f_sigma_cutoff= $FCUT" >> stdin
echo " tol_for_shift_on_esd= $CONVTOL" >> stdin
# echo " refine_H_U_iso= $HADP" >> stdin
echo " refine_H_U_iso= yes" >> stdin
echo "" >> stdin
echo " show_fit_output= true" >> stdin
echo " show_fit_results= true" >> stdin
echo "" >> stdin
echo " } " >> stdin
echo " } " >> stdin
echo "" >> stdin
echo " ! Geometry " >> stdin
echo " put" >> stdin
echo "" >> stdin
echo " IAM_refinement" >> stdin
echo "" >> stdin
fi
echo "" >> stdin
echo " crystal= { " >> stdin
if [[ "$SCFCALCPROG" == "elmodb" && $J == 0 && "$INITADP" == "false" ]]; then
echo " REDIRECT tonto.cell" >> stdin
fi
# if [[ "$SCFCALCPROG" != "elmodb" && "$SCFCALCPROG" != "Tonto" ]]; then
# if [ $COMPLETESTRUCT = "true" ]; then
# echo " REDIRECT tonto.cell" >> stdin
# fi
# fi
#if [[ $J = 0 && "$COMPLETESTRUCT" = "true" ]]; then
# echo " defragment= $COMPLETESTRUCT" >> stdin
# echo " make_info" >> stdin
# echo " put_cluster_info" >> stdin
#fi
echo " xray_data= { " >> stdin
echo " thermal_smearing_model= hirshfeld" >> stdin
echo " partition_model= mulliken" >> stdin
echo " optimise_extinction= false" >> stdin
echo " correct_dispersion= $DISP" >> stdin
echo " optimise_scale_factor= true" >> stdin
echo " wavelength= $WAVE Angstrom" >> stdin
if [ "$REFANHARM" == "true" ]; then
if [[ "$THIRDORD" == "false" && "$FOURTHORD" == "true" ]]; then
echo " refine_4th_order_only= true " >> stdin
echo " refine_4th_order_for_atoms= { $ANHARMATOMS } " >> stdin
elif [[ "$THIRDORD" == "true" && "$FOURTHORD" == "true" ]]; then
echo " refine_4th_order_for_atoms= { $ANHARMATOMS } " >> stdin
elif [[ "$THIRDORD" == "true" && "$FOURTHORD" == "false" ]]; then
echo " refine_3rd_order_for_atoms= { $ANHARMATOMS } " >> stdin
else
echo "ERROR: Please select at least one of the anharmonic terms to refine" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
fi
fi
echo " REDIRECT $HKL" >> stdin
echo " f_sigma_cutoff= $FCUT" >> stdin
echo " tol_for_shift_on_esd= $CONVTOL" >> stdin
echo " refine_H_U_iso= $HADP" >> stdin
if [[ "$SCFCALCPROG" = "Tonto" && "$IAMTONTO" = "true" ]]; then
echo "" >> stdin
echo " show_fit_output= false" >> stdin
echo " show_fit_results= false" >> stdin
fi
echo "" >> stdin
if [ "$SCFCALCPROG" != "Tonto" ]; then
echo " show_fit_output= TRUE" >> stdin
echo " show_fit_results= TRUE" >> stdin
echo "" >> stdin
fi
if [ "$POSONLY" = "true" ]; then
echo " refine_positions_only= $POSONLY" >> stdin
fi
if [ "$ADPSONLY" = "true" ]; then
echo " refine_ADPs_only= $ADPSONLY" >> stdin
fi
if [ "$REFHADP" = "false" ]; then
if [ "$ADPSONLY" != "true" ]; then
echo " refine_H_ADPs= $REFHADP" >> stdin
fi
fi
if [ "$REFHPOS" = "false" ]; then
if [ "$ADPSONLY" != "true" ]; then
echo " refine_H_positions= $REFHPOS" >> stdin
fi
fi
if [ "$REFNOTHING" = "true" ]; then
echo " refine_nothing_for_atoms= { $ATOMLIST }" >> stdin
fi
if [ "$REFUISO" = "true" ]; then
echo " refine_u_iso_for_atoms= { $ATOMUISOLIST }" >> stdin
fi
if [ "$MAXLSCICLE" ]; then
echo " max_iterations= $MAXLSCICLE" >> stdin
fi
echo " } " >> stdin
echo " } " >> stdin
echo "" >> stdin
if [ "$HADP" = "yes" ]; then
echo " set_isotropic_h_adps" >> stdin
echo "" >> stdin
fi
echo " ! Geometry " >> stdin
echo " put" >> stdin
echo "" >> stdin
if [ "$USEBECKE" = "true" ]; then
echo " !Tight grid" >> stdin
echo " becke_grid = {" >> stdin
echo " set_defaults" >> stdin
echo " accuracy= $ACCURACY" >> stdin
echo " pruning_scheme= $BECKEPRUNINGSCHEME" >> stdin
echo " }" >> stdin
echo "" >> stdin
fi
if [ "$SCFCALCPROG" != "Tonto" ]; then
if [[ "$SCCHARGES" == "true" && "$SCFCALCPROG" != "elmodb" ]]; then
echo " ! SC cluster charge SCF" >> stdin
echo " scfdata= {" >> stdin
echo " initial_MOs= existing" >> stdin
if [[ "$METHOD" != "rks" && "$METHOD" != "rhf" && "$METHOD" != "uhf" && "$METHOD" != "uks" ]]; then
echo " kind= rks " >> stdin
echo " dft_exchange_functional= b3lypgx" >> stdin
echo " dft_correlation_functional= b3lypgc" >> stdin
else
echo " kind= $METHOD" >> stdin
fi
echo " use_SC_cluster_charges= TRUE" >> stdin
echo " cluster_radius= $SCCRADIUS angstrom" >> stdin
echo " defragment= $DEFRAG" >> stdin
echo " save_cluster_charges= true" >> stdin
echo " convergence= 0.001" >> stdin
echo " diis= { convergence_tolerance= 0.0002 }" >> stdin
echo " output= YES" >> stdin
echo " output_results= YES" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " make_scf_density_matrix" >> stdin
echo " make_fock_matrix" >> stdin
echo "" >> stdin
echo " ! SC cluster charge SCF" >> stdin
echo " scfdata= {" >> stdin
echo " initial_density= promolecule" >> stdin
echo " initial_MOs= existing" >> stdin
if [[ "$METHOD" != "rks" && "$METHOD" != "rhf" && "$METHOD" != "uhf" && "$METHOD" != "uks" ]]; then
echo " kind= rks " >> stdin
echo " dft_exchange_functional= b3lypgx" >> stdin
echo " dft_correlation_functional= b3lypgc" >> stdin
else
echo " kind= $METHOD" >> stdin
fi
echo " use_SC_cluster_charges= TRUE" >> stdin
echo " cluster_radius= $SCCRADIUS angstrom" >> stdin
echo " defragment= $DEFRAG" >> stdin
echo " put_cluster" >> stdin
echo " put_cluster_charges" >> stdin
echo "" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " ! Make Hirshfeld structure factors" >> stdin
echo " fit_hirshfeld_atoms" >> stdin
echo "" >> stdin
echo " write_xyz_file" >> stdin
else
echo " ! Make Hirshfeld structure factors" >> stdin
echo " fit_hirshfeld_atoms" >> stdin
echo "" >> stdin
echo " write_xyz_file" >> stdin
fi
fi
if [ "$SCFCALCPROG" = "Tonto" ]; then
# if [ "$USEBECKE" = "true" ]; then
# echo " !Tight grid" >> stdin
# echo " becke_grid = {" >> stdin
# echo " set_defaults" >> stdin
# echo " accuracy= $ACCURACY" >> stdin
# echo " pruning_scheme= $BECKEPRUNINGSCHEME" >> stdin
# echo " }" >> stdin
# echo "" >> stdin
# fi
echo " ! Normal SCF" >> stdin
echo " scfdata= {" >> stdin
echo " initial_density= promolecule " >> stdin
echo " kind= rhf" >> stdin # this is the promolecule guess, should be always rhf
# if [ "$METHOD" = "b3lyp" ]; then
# echo " kind= rks " >> stdin
# echo " dft_exchange_functional= b3lypgx" >> stdin
# echo " dft_correlation_functional= b3lypgc" >> stdin
# else
# echo " kind= $METHOD" >> stdin
# fi
echo " use_SC_cluster_charges= FALSE" >> stdin
echo " convergence= 0.001" >> stdin
echo " diis= { convergence_tolerance= 0.0002 }" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " scf" >> stdin
echo "" >> stdin
echo " ! SC cluster charge SCF" >> stdin
echo " scfdata= {" >> stdin
echo " initial_MOs= restricted" >> stdin
if [ "$METHOD" = "b3lyp" ]; then
echo " kind= rks" >> stdin
echo " dft_exchange_functional= b3lypgx" >> stdin
echo " dft_correlation_functional= b3lypgc" >> stdin
else
echo " kind= $METHOD" >> stdin
fi
if [ "$SCCHARGES" = "true" ]; then
echo " use_SC_cluster_charges= TRUE" >> stdin
echo " cluster_radius= $SCCRADIUS angstrom" >> stdin
echo " defragment= $DEFRAG" >> stdin
else
echo " use_SC_cluster_charges= FALSE" >> stdin
fi
echo " convergence= 0.001" >> stdin
echo " diis= {" >> stdin
echo " convergence_tolerance= 0.0002" >> stdin
echo " }" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " ! Make Hirshfeld structure factors" >> stdin
echo " refine_hirshfeld_atoms" >> stdin
fi
echo "" >> stdin
echo "}" >> stdin
J=$[ $J + 1 ]
echo "Running Tonto, cycle number $J"
# if [[ "$NUMPROC" != "1" ]]; then
# mpirun_tonto -n $NUMPROC $TONTO
# else
$TONTO
# fi
INITIALCHI=$(awk '{a[NR]=$0}/^Begin rigid-atom fit/{b=NR}END {print a[b+10]}' stdout | awk '{print $2}')
MAXSHIFT=$(awk '{a[NR]=$0}/^Begin rigid-atom fit/{b=NR+10}/^Rigid-atom fit results/{c=NR-4}END {for(d=b;d<=c;++d)print a[d]}' stdout | awk -v max=0 '{if($5>max){shift=$5; atom=$6; param=$7; max=$5}}END{print shift}')
MAXSHIFTATOM=$(awk '{a[NR]=$0}/^Begin rigid-atom fit/{b=NR+10}/^Rigid-atom fit results/{c=NR-4}END {for(d=b;d<=c;++d)print a[d]}' stdout | awk -v max=0 '{if($5>max){shift=$5; atom=$6; param=$7; max=$5}}END{print atom}')
MAXSHIFTPARAM=$(awk '{a[NR]=$0}/^Begin rigid-atom fit/{b=NR+10}/^Rigid-atom fit results/{c=NR-4}END {for(d=b;d<=c;++d)print a[d]}' stdout | awk -v max=0 '{if($5>max){shift=$5; atom=$6; param=$7; max=$5}}END{print param}')
if [[ "$SCFCALCPROG" != "Tonto" && "$SCFCALCPROG" != "elmodb" ]]; then
sed -i 's/(//g' $JOBNAME.xyz
sed -i 's/)//g' $JOBNAME.xyz
fi
echo "Tonto cycle number $J ended"
if ! grep -q 'Wall-clock time taken' "stdout"; then
echo "ERROR: problems in fit cycle, please check the $J.th stdout file for more details" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
fi
if [ $J = 1 ]; then
#awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-5]}' stdout
echo "====================" >> $JOBNAME.lst
echo "Begin rigid-atom fit" >> $JOBNAME.lst
echo "====================" >> $JOBNAME.lst
echo "" >> $JOBNAME.lst
echo "__________________________________________________________________________________________________________________________________________________________________" >> $JOBNAME.lst
echo "" >> $JOBNAME.lst
echo "Cycle Fit initial final R R_w Max. Max. No. of No. of Energy RMSD Delta " >> $JOBNAME.lst
echo " Iter chi2 chi2 Shift Shift params eig's at final at final Energy " >> $JOBNAME.lst
echo " /esd param near 0 Geom. Geom. " >> $JOBNAME.lst
echo "" >> $JOBNAME.lst
echo "__________________________________________________________________________________________________________________________________________________________________" >> $JOBNAME.lst
echo "" >> $JOBNAME.lst
# echo " $J $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-5]}' stdout) $ENERGIA $RMSD $ENERGY " >> $JOBNAME.lst
fi
if [[ "$SCFCALCPROG" != "Gaussian" && "$SCFCALCPROG" != "Orca" ]]; then
echo -e " $J\t$(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $1}' )\t$INITIALCHI\t$(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $2"\t"$3"\t"$4"\t"}') $MAXSHIFT\t$MAXSHIFTATOM $MAXSHIFTPARAM $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print "\t"" "$8" \t"$9 }' ) " >> $JOBNAME.lst
fi
# echo " $J $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $1"\t"}' ) $INITIALCHI $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print "\t"$2"\t"$3"\t"$4}') $(awk '{a[NR]=$0}/^Begin rigid-atom fit/{b=NR}END {print a[b+10]}' stdout | awk '{print "\t"$5" "$6" "$7}') $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print "\t"$8"\t"$9 }' ) " >> $JOBNAME.lst
# echo " $J $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-5]}' stdout)" >> $JOBNAME.lst
#echo " $J $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-5]}' stdout) $ENERGIA2 $RMSD2 $DE" >> $JOBNAME.lst
if [ "$SCFCALCPROG" != "Tonto" ]; then
mkdir $J.fit_cycle.$JOBNAME
cp $JOBNAME.xyz $J.fit_cycle.$JOBNAME/$J.$JOBNAME.xyz
cp stdin $J.fit_cycle.$JOBNAME/$J.stdin
cp stdout $J.fit_cycle.$JOBNAME/$J.stdout
sed -i '/# NOTE: Cartesian 9Nx9N covariance matrix in BOHR units/,/# ===========/d' $JOBNAME.cartesian.cif2
cp $JOBNAME'.cartesian.cif2' $J.fit_cycle.$JOBNAME/$J.$JOBNAME.cartesian.cif2
cp $JOBNAME'.archive.cif' $J.fit_cycle.$JOBNAME/$J.$JOBNAME.archive.cif
cp $JOBNAME'.archive.fco' $J.fit_cycle.$JOBNAME/$J.$JOBNAME.archive.fco
cp $JOBNAME'.archive.fcf' $J.fit_cycle.$JOBNAME/$J.$JOBNAME.archive.fcf
if [[ "$SCFCALCPROG" != "elmodb" && "$SCCHARGES" == "true" ]]; then
cp gaussian-point-charges $J.fit_cycle.$JOBNAME/$J.gaussian-point-charges
fi
fi
}
#######################################################################
TONTO_TO_GAUSSIAN(){
I=$[ $I + 1 ]
echo "Extrating XYZ for Gaussian cycle number $I"
echo "%rwf=./$JOBNAME.rwf" >> $JOBNAME.com
echo "%int=./$JOBNAME.int" >> $JOBNAME.com
echo "%NoSave" >> $JOBNAME.com
echo "%chk=./$JOBNAME.chk" > $JOBNAME.com
echo "%mem=$MEM" >> $JOBNAME.com
echo "%nprocshared=$NUMPROC" >> $JOBNAME.com
#echo "# rb3lyp/$BASISSETG output=wfn" >> $JOBNAME.com
if [ "$METHOD" = "rks" ]; then
if [ "$SCCHARGES" = "true" ]; then
echo "# blyp/$BASISSETG Charge nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
else
echo "# blyp/$BASISSETG nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
fi
elif [ "$METHOD" = "uks" ]; then
if [ "$SCCHARGES" = "true" ]; then
echo "# ublyp/$BASISSETG Charge nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
else
echo "# ublyp/$BASISSETG nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
fi
elif [ "$METHOD" = "rhf" ]; then
if [ "$SCCHARGES" = "true" ]; then
echo "# rhf/$BASISSETG Charge nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
else
echo "# rhf/$BASISSETG nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
fi
else
if [ "$SCCHARGES" = "true" ]; then
echo "# $METHOD/$BASISSETG Charge nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
else
echo "# $METHOD/$BASISSETG nosymm output=wfn 6D 10F Fchk $INT" >> $JOBNAME.com
fi
fi
echo "" >> $JOBNAME.com
echo "$JOBNAME" >> $JOBNAME.com
echo "" >> $JOBNAME.com
echo "$CHARGE $MULTIPLICITY" >> $JOBNAME.com
### commented but working on new tonto, will use dylan's old write_xyz_file keyword because that one keeps the atom labels, florian's new one does not.
### awk '{a[NR]=$0}/^_atom_site_Cartn_disorder_group/{b=NR}/^# ==========================/{c=NR}END{for(d=b+4;d<=c-4;++d)print a[d]}' $JOBNAME.cartesian.cif2 | awk -v OFS='\t' 'NR%2==0 {print $1, $2, $3, $4}' | awk '{gsub("[(][^)]*[)]","")}1 {print }' >> $JOBNAME.com
awk 'NR>2' $J.fit_cycle.$JOBNAME/$J.$JOBNAME.xyz >> $JOBNAME.com
# sleep 15 #check if needed
# awk '{a[NR]=$0}/^_atom_site_Cartn_U_iso_or_equiv_esd/{b=NR}/^# ==========================/{c=NR}END{for(d=b+1;d<=c-4;++d)print a[d]}' $JOBNAME.cartn-fragment.cif | awk 'NR%2==1 {print $1, $2, $3, $4}' >> $JOBNAME.com
echo "" >> $JOBNAME.com
if [ "$SCCHARGES" = "true" ]; then
awk '{a[NR]=$0}{b=12}/^------------------------------------------------------------------------/{c=NR}END{for(d=b;d<=c-1;++d)print a[d]}' gaussian-point-charges | awk '{printf "%s\t %s\t %s\t %s\t \n", $2, $3, $4, $1 }' >> $JOBNAME.com
echo "" | tee -a $JOBNAME.com $JOBNAME.lst
fi
if [ "$GAUSGEN" = "true" ]; then
cat basis_gen.txt >> $JOBNAME.com
echo "" >> $JOBNAME.com
fi
echo "./$JOBNAME.wfn" >> $JOBNAME.com
echo "" >> $JOBNAME.com
echo "Running Gaussian, cycle number $I"
$SCFCALC_BIN $JOBNAME.com
echo "Gaussian cycle number $I ended"
if ! grep -q 'Normal termination of Gaussian' "$JOBNAME.log"; then
echo "ERROR: Gaussian job finished with error, please check the $I.th log file for more details" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
fi
echo "Generation fcheck file for Gaussian cycle number $I"
# formchk $JOBNAME.chk $JOBNAME.fchk
mkdir $I.$SCFCALCPROG.cycle.$JOBNAME
cp $JOBNAME.com $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.com
# cp $JOBNAME.fchk $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.fchk
cp Test.FChk $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.fchk
cp $JOBNAME.log $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.log
}
###################### Gaussian done ########################
###################### Begin check energy ########################
CHECK_ENERGY(){
if [ "$SCFCALCPROG" = "Gaussian" ]; then
# ENERGIA2=$(sed 's/^ //' $JOBNAME.log | sed 'N;s/\n//' | sed 'N;s/\n//' | sed -n '/HF=/{N;p;}' | sed 's/^.*HF=//' | sed 'N;s/\n//' | sed '2d' | sed 's/RMSD=//g' | awk -F '\' '{ print $1}' | tr -d '\r') # exchanging for another one where I join the lines 2x more.
ENERGIA2=$(sed 's/^ //' $JOBNAME.log | sed 'N;s/\n//' | sed 'N;s/\n//' | sed 'N;s/\n//' | sed 'N;s/\n//' | sed -n '/HF=/{N;p;}' | sed 's/^.*HF=//' | sed 'N;s/\n//' | sed '2d' | sed 's/RMSD=//g' | awk -F '\' '{ print $1}' | tr -d '\r')
#this one was not working whenever relativistics was used in gaussian, the bottom one works.
# RMSD2=$(sed 's/^ //' $JOBNAME.log | sed 'N;s/\n//' | sed 'N;s/\n//' | sed -n '/HF=/{N;p;}' | sed 's/^.*HF=//' | sed 'N;s/\n//' | sed '2d' | sed 's/RMSD=//g' | awk -F '\' '{ print $2}'| tr -d '\r')
RMSD2=$(sed 's/^ //' $JOBNAME.log | sed 'N;s/\n//' | sed 'N;s/\n//' | sed 'N;s/\n//'| sed -n '/RMSD=/{N;p;}' | sed 's/^.*RMSD=//' | sed 'N;s/\n//' | sed '2d' | sed 's/RMSD=//g' | awk -F '\' '{ print $1}'| tr -d '\r')
echo "Gaussian cycle number $I, final energy is: $ENERGIA2, RMSD is: $RMSD2 "
elif [ "$SCFCALCPROG" = "Orca" ]; then
ENERGIA2=$(sed -n '/Total Energy :/p' $JOBNAME.log | awk '{print $4}' | tr -d '\r')
RMSD2=$(sed -n '/Last RMS-Density change/p' $JOBNAME.log | awk '{print $5}' | tr -d '\r')
echo "Orca cycle number $I, final energy is: $ENERGIA2, RMSD is: $RMSD2 "
fi
# DE=$(($ENERGIA - $ENERGIA2))
### DE=$(echo "$ENERGIA2 - $ENERGIA" | bc)
DE=$(awk "BEGIN {print $ENERGIA2 - $ENERGIA}")
# DE=$(echo "$ENERGIA - $ENERGIA2" | bc)
# DRMSD=$(($RMSD - $RMSD2))
echo -e " $J\t$(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $1}' )\t$INITIALCHI\t$(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $2"\t"$3"\t"$4"\t"}') $MAXSHIFT\t$MAXSHIFTATOM $MAXSHIFTPARAM $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print " "$8" \t"$9 }' ) $ENERGIA2 $RMSD2 \t$DE" >> $JOBNAME.lst
# echo -e " $J\t$(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $1}' )\t$INITIALCHI\t$(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $2"\t"$3"\t"$4"\t"}') $MAXSHIFT\t$MAXSHIFTATOM $MAXSHIFTPARAM $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print "\t"" "$8" \t"$9 }' ) $ENERGIA2 $RMSD2 \t$DE" >> $JOBNAME.lst
# echo " $J $(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout) $ENERGIA2 $RMSD2 $DE" >> $JOBNAME.lst
ENERGIA=$ENERGIA2
RMSD=$RMSD2
echo "Delta E (cycle $I - $[ I - 1 ]): $DE "
### echo "Delta E (cycle $I - $[ I - 1 ]): $DE (convergency will reach when Delta E is smaller than 0.0001)"
# J=$[ $J + 1 ]
# echo "Running Tonto, cycle number $J"
# $TONTO
# echo "Tonto cycle number $I ended"
# cp stdout stdout.$J
}
CHECKCONV(){
#FINALPARAMESD=$(awk '{a[NR]=$0}/^Rigid-atom fit results/{b=NR}END {print a[b-4]}' stdout | awk '{print $5}') This is from the last line
FINALPARAMESD=$(awk '{a[NR]=$0}/^Begin rigid-atom fit/{b=NR}END {print a[b+10]}' stdout | awk '{print $5}')
}
###################### End check energy ########################
# function to get the residual density, only needed for scf program different than tonto, since we remove the residual calculation from inside the fits.
GET_RESIDUALS(){
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" > stdin
echo "!!! !!!" >> stdin
echo "!!! This stdin was written with lamaGOET !!!" >> stdin
echo "!!! !!!" >> stdin
echo "!!! This stdin is only to get the residual density after the HAR using an SCF program !!!" >> stdin
echo "!!! that is different than Tonto. A cube file containing the residual density will be !!!" >> stdin
echo "!!! written where the units are e/A^3. !!!" >> stdin
echo "!!! !!!" >> stdin
echo "!!! script written by Lorraine Andrade Malaspina !!!" >> stdin
echo "!!! contact: [email protected] !!!" >> stdin
echo "!!! !!!" >> stdin
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> stdin
echo "{ " >> stdin
echo "" >> stdin
echo " keyword_echo_on" >> stdin
echo "" >> stdin
if [ "$SCFCALCPROG" = "elmodb" ]; then
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
echo " read_g09_fchk_file $JOBNAME.fchk" >> stdin
fi
if [ "$SCFCALCPROG" = "Gaussian" ]; then
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
echo " read_g09_fchk_file $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.fchk" >> stdin
elif [ "$SCFCALCPROG" = "Orca" ]; then
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
echo " read_molden_file $I.$SCFCALCPROG.cycle.$JOBNAME/$I.$JOBNAME.molden.input" >> stdin
else
echo " name= $JOBNAME" >> stdin
fi
echo "" >> stdin
if [ "$SCFCALCPROG" != "elmodb" ]; then
echo " ! Process the CIF" >> stdin
echo " CIF= {" >> stdin
echo " file_name= $J.fit_cycle.$JOBNAME/$J.$JOBNAME.cartesian.cif2" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " process_CIF" >> stdin
echo "" >> stdin
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
fi
if [ "$SCFCALCPROG" == "elmodb" ]; then
echo " ! Process the CIF" >> stdin
echo " CIF= {" >> stdin
echo " file_name= $J.fit_cycle.$JOBNAME/$J.$JOBNAME.cartesian.cif2" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " process_CIF" >> stdin
echo "" >> stdin
echo " name= $JOBNAME" >> stdin
echo "" >> stdin
fi
if [ "$SCFCALCPROG" = "Tonto" ]; then
echo " basis_directory= $BASISSETDIR" >> stdin
echo " basis_name= $BASISSETT" >> stdin
echo "" >> stdin
fi
if [ "$DISP" = "yes" ]; then
echo " dispersion_coefficients= {" >> stdin
echo " $(cat DISP_inst.txt)" >> stdin
echo " }" >> stdin
echo "" >> stdin
fi
echo " charge= $CHARGE" >> stdin
echo " multiplicity= $MULTIPLICITY" >> stdin
echo "" >> stdin
echo " crystal= { " >> stdin
echo " xray_data= { " >> stdin
echo " thermal_smearing_model= hirshfeld" >> stdin
echo " partition_model= mulliken" >> stdin
echo " optimise_extinction= false" >> stdin
echo " correct_dispersion= $DISP" >> stdin
echo " optimise_scale_factor= true" >> stdin
echo " wavelength= $WAVE Angstrom" >> stdin
echo " REDIRECT $HKL" >> stdin
echo " f_sigma_cutoff= $FCUT" >> stdin
echo " tol_for_shift_on_esd= $CONVTOL" >> stdin
echo "" >> stdin
echo " } " >> stdin
echo " } " >> stdin
echo "" >> stdin
echo " ! Geometry " >> stdin
echo " put" >> stdin
echo "" >> stdin
echo " scfdata= {" >> stdin
echo " initial_MOs= existing" >> stdin
if [[ "$METHOD" != "rks" && "$METHOD" != "rhf" && "$METHOD" != "uhf" && "$METHOD" != "uks" ]]; then
echo " kind= rks " >> stdin
echo " dft_exchange_functional= b3lypgx" >> stdin
echo " dft_correlation_functional= b3lypgc" >> stdin
else
echo " kind= $METHOD" >> stdin
fi
echo " use_SC_cluster_charges= $SCCHARGES" >> stdin
if [ "$SCCHARGES" == "true" ]; then
echo " cluster_radius= $SCCRADIUS angstrom" >> stdin
echo " defragment= $DEFRAG" >> stdin
echo " save_cluster_charges= true" >> stdin
fi
echo " convergence= 0.001" >> stdin
echo " diis= { convergence_tolerance= 0.0002 }" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " make_scf_density_matrix" >> stdin
echo " make_structure_factors" >> stdin
echo "" >> stdin
echo " put_minmax_residual_density" >> stdin
echo "" >> stdin
echo " plot_grid= { " >> stdin
echo "" >> stdin
echo " kind= residual_density_map" >> stdin
echo " use_unit_cell_as_bbox" >> stdin
echo " desired_separation= 0.1 angstrom" >> stdin
echo " plot_format= cell.cube" >> stdin
echo " plot_units= angstrom^-3" >> stdin
echo "" >> stdin
echo " }" >> stdin
echo "" >> stdin
echo " plot" >> stdin
echo "" >> stdin
echo "}" >> stdin
echo "Calculating residual density at final geometry"
$TONTO
}
run_script(){
SECONDS=0
I=$"0" ###counter for gaussian jobs
J=$"0" ###counter for tonto fits
shopt -s nocasematch
#removing 0 0 0 line
if [[ ! -z $(awk '{if (($1) == "0" && ($2) == "0" && ($3) == "0" ) print}' $HKL) ]]; then
awk '{if (($1) != "0" && ($2) != "0" && ($3) != "0" ) print}' $HKL > $JOBNAME.tonto_edited.hkl
fi
#backing up hkl input file and copying the one without the 0 line to the $HKL variable
if [ -f "$JOBNAME.tonto_edited.hkl" ]; then
cp $HKL $JOBNAME.your_input.hkl
cp $JOBNAME.tonto_edited.hkl $HKL
rm $JOBNAME.tonto_edited.hkl
echo "WARNING: HKL has been formated, your original input is saved with the name $JOBNAME.your_input.hkl!"
fi
#checking if numbers are grown together and separating them. note that this will ignore the header lines if is exists.
if [[ ! -z "$(awk ' NF<5 && NF>2 {print $0}' $HKL)" ]]; then
gawk 'BEGIN { FS = "" } { for (i = 1; i <= NF; i = i + 1) h=$1$2$3$4; k=$5$6$7$8; l=$9$10$11$12; i_f=$13$14$15$16$17$18$19$20; sig=$21$22$23$24$25$26$27$28; print h, k, l, i_f, sig }' $HKL > $JOBNAME.tonto_edited.hkl
cp $HKL $JOBNAME.your_input.hkl
cp $JOBNAME.tonto_edited.hkl $HKL
rm $JOBNAME.tonto_edited.hkl
fi
# writing header on hkl
if [ "$WRITEHEADER" = "true" ]; then
#checking if the header was not there already
if [[ ! -z "$(grep "reflection_data= {" $HKL)" ]]; then
echo "header was already in the hkl file, nothing to do."
else
#putting the header in
sed -i '1 i\ data= {' $HKL
if [ "$ONF" = "true" ]; then
sed -i '1 i\ keys= { h= k= l= f_exp= f_sigma= }' $HKL
elif [ "$ONF2" = "true" ]; then
sed -i '1 i\ keys= { h= k= l= i_exp= i_sigma= }' $HKL
else
echo "ERROR: Please select the format of the hkl file for header (F or F^2)" | tee -a $JOBNAME.lst
unset MAIN_DIALOG
exit 0
fi
sed -i '1 i\ reflection_data= {' $HKL
sed -i '$ a\ }' $HKL
sed -i '$ a\ }' $HKL
sed -i '$ a\ REVERT' $HKL
fi
fi
if [[ -z "$(grep "reflection_data= {" $HKL)" ]]; then
echo "You are missing the tonto header in the hkl file."
fi
#writing the lst file
echo "###############################################################################################" > $JOBNAME.lst
echo " lamaGOT " >> $JOBNAME.lst
echo "###############################################################################################" >> $JOBNAME.lst
echo "Job started on:" >> $JOBNAME.lst
date >> $JOBNAME.lst
echo "User Inputs: " >> $JOBNAME.lst
echo "Tonto executable : $TONTO" >> $JOBNAME.lst
echo "$($TONTO -v)" >> $JOBNAME.lst
#awk 'NR==7 { print }' stdout >> $JOBNAME.lst #print the tonto version, but there is no stdout yet