-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConfSearch-carts
1734 lines (1542 loc) · 61.5 KB
/
ConfSearch-carts
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/perl
$|++;
use Term::ANSIColor;
############################################################################
# ConfSearch #
# #
# This code is for performing a conformer search, implementing the EDTS #
# method. #
# #
# To execute the code, first make the script executable by running #
# >> "chmod +x ConfSearch" #
# from the containing directory. #
# #
# USAGE #
# ----- #
# ConfSearch $mol [$atom1 $atom2] [$gooddist] --> for transition state #
# optimisation, if r12 is fixed, this can be used to help determine the #
# optimised geometry is valid. #
# #
# REQUIRES #
# -------- #
# 1. Input file format "$mol.$dih.com" -> ensure the use of the #
# period (.) as opposed to underscores (_) or hyphens (-) #
# 2. $mol.list in the input directory. #
# 3. ~/bin/crinxyz
# #
# Several default values are listed below #
# $window ($EC1 and $EC2) #
# $Nmax #
# #
# While optimising Error (Address Error) -> Email to ask continue #
# While Runtime Terminate (killed) -> Email to ask continue #
# Not yet deal with Large system where the round2/3 maybe 1000 #
# All the job.list is printout in CF-* #
# CF-$mol.round1 (if 2nd lowest < 4kJ) -> CF-$mol.round2 -> CF-$mol.round3-$i.tosub
# (if 2nd lowest > 4kJ) -> CF-$mol.round3-$i.tosub
# A few other useful files:
# 1. CF-$mol.round$x.uh/lh (upper/lower half with the energy difference)
# 2. CF-$mol.*.window (those energies within 4kJ and the first Nmax with their energy difference)
# 3. CF-$mol.done (At every stage, the done file will tell you what has been done)
# 4. At the end of the program, you can look into CF-$mol.done.*, which tell you the all Energy difference.
# To adjust the sleep time:
# Current setting: Check full Queue = every $sleep_queue seconds;
# Check Job finished = every day.
#
############################################################################
# Modified by Naomi Haworth 17/3/2015
############################################################################
$ProjectCode[0] = ("$ENV{PROJECT}");
$ProjectCode[1] = ("$ENV{PROJECT2}");
if (!($ENV{PROJ1GRANT})) {
die "Please edit your .bashrc to include the following lines and source: \nexport PROJECT=f81\nexport PROJECT2=x69\nexport PROJ1GRANT=500\nexport PROJ2GRANT=800\n";
}
else {
$grant{$ProjectCode[0]} = $ENV{PROJ1GRANT};
$grant{$ProjectCode[1]} = $ENV{PROJ2GRANT};
}
$ruser = $ENV{REMOTE_USER};
#$rdir = $ENV{PROJECT};
#$rdir = "f81";
$email = "$ENV{email}";
$debug=0;
$machine="raijin";
$sub="rjsub";
############################################################################
$maxQ{x69} = 690; # Max is 400 but can be slow to update
$maxQ{f81} = 690; # Max is 400 but can be slow to update
$maxQ{user} = 650; # Limited to 350 to allow space for other group members
$maxCPU{x69} = 50000; # Default for vu normal queue
$maxCPU{f81} = 50000; # Default for vu normal queue
$maxCPU{user} = 50000; # Default for vu normal queue
$Nmax = 5; # Default
$EC1 = 3; # Default 3kJ/mol
$EC2 = 4; # Default 4kJ/mol
$sleep_job = 600;
$sleep_queue = 360;
$ncpus = 4;
$mol=$ARGV[0];
$mol=~s/.xyz//;
$atom1=$ARGV[1];
$atom2=$ARGV[2];
system(clear);
if ($ARGV[1]){
if (!$ARGV[3] ){
$gooddist=2.5;
$toldist=0.1;
print "No appropriate bond length specified, $gooddist A will be used.\n";
print "No appropriate bond length tolerance specified, $toldist A will be used.\n";
}
else{
$gooddist=$ARGV[3];
print "Bond length specified at $gooddist A.\n";
if (!$ARGV[4]){
print "No appropriate bond length tolerance specified, 0.00 A has been used.\n";
$toldist=0.00;
}
else{
$toldist=$ARGV[4];
print "Bond length tolerance specified at $toldist A.\n";
}
}
}
chomp($mol);
#$time1 = `quotasu -P x69 | grep 'Service Units remaining' |sed 's/.*\\*//' | sed 's/ //g'` ;
#$time2 = `quotasu -P f81 | grep 'Service Units remaining' |sed 's/.*\\*//' | sed 's/ //g'` ;
#chomp ($time1);
#chomp ($time2);
#$time = $time1 + $time2;
#Print Out Warnings!
print color 'green';
print "#########################################################################\n";
print "# Starting ConfSearch... #\n";
print "# Ensure you don't have a period (.) in the name of the molecule. #\n";
print "#########################################################################\n\n";
print color 'reset';
print "Checking queues... ";
$p = $ProjectCode[0];
@alloctime = split(/\s+/,`ssh $machine -l \$REMOTE_USER nci_account -P $p | grep 'Overall' `);
if ($alloctime[6]/1000 + 20 > $grant{$p}) {
$p1 = 1;
print "Not enough SU available on project $p use $ProjectCode[1].\n";
}
else {
$freetime = $grant{$p} - $alloctime[6]/1000;
printf "%4.0f kSU available on project %3s.\n", $freetime, $p;
$p1 = 0;
}
print "\nConformer search for $mol according to total energy...\n-------------------------------------------------------------------------\n\n";
#print " Remaining Project Hours $time hr?\n" ;
###################################################################################
$InputDir = ".";
###################################################################################
# Round1 #
###################################################################################
print color 'blue';
print "#########################################################################\n";
print "# Beginning round 1... #\n";
print "#########################################################################\n\n";
print color 'reset';
if (!-e "CF-$mol.round1"){
#system("rm CF-$mol.round1");
open fr,">CF-$mol.round1" or die $!;
open comlist, "$mol.list" or die $!;
while (<comlist>){
#@crap=split(/\./,$_);
$dih = $_;
if (length($dih) <4 || (length($dih)<6 && $dih=~/a1/) ){
print fr "$mol.$dih";
}
}
close comlist;
close fr;
}
open round1, "CF-$mol.round1" or die $!;
while ($r1 = <round1>){
foreach $item ($r1){
chomp($item);
if (! -e "$item.log" and ! -e "$item.job") {
while (!($queue = freeQ())){
print color 'red';
print "Queue on machine $machine is full.\n\n";
print color 'reset';
sleep $sleep_queue;
}
testThenSubmit($queue,$item);
}
}
}
close round1;
sub testThenSubmit {
my ($q,$j) = @_;
if (!isBadComFile($j)) {
system("echo $sub $j.com -rproj $q -cs");
if($debug==0){
system("$sub $j.com -rproj $q -cs");
system("touch $j.job");
}
}
else {
print color 'red';
print "$j is too crowded.\n";
print color 'reset';
}
}
###################################################################################
# Round2 #
###################################################################################
system("cat CF-$mol.round1 | sort | uniq > CF-$mol.done");
open done, "CF-$mol.done" or die $!;
while ($done = <done>){
chomp($done);
foreach $y ($done){
$ok = 0;
if (-e "$y.log" ) {
$ok = check("$y");
}
while (! -e "$y.log" ){
$fin = `ssh -l $ruser $machine "if \[ -e JOB/$y.batch \] ;then echo 1 ;fi "`;
if ($fin == 1){
@rdir = split(/\s+/, `ssh -l $ruser $machine grep Project JOB/$y.batch`);
if ($rdir[1] =~ /Project/) {
`scp $ruser\@$machine:/short/$rdir[2]/$ruser/RUN/$y/$y.log .`;
}
else {
@rdir = split(/\s+/, `ssh -l $ruser $machine grep saved JOB/$y.batch`);
$rdir2 = substr($rdir[1], 0, -1);
`scp $ruser\@$machine:$rdir2/$y.log .`;
}
if (-e "$y.log" ){
`ssh -l $ruser $machine mv JOB/$y.batch BATCH/$y.batch`;
$ok = check("$y");
}
else {
print "something has gone wrong with the transfer of $y.log.\n";
$fin = 0;
}
}
else{
print color 'yellow';
print "$y.log in round 1 does not exist. Waiting for log file from \n $machine ...\n\n";
print color 'reset';
sleep $sleep_job;
}
}
}
}
close done;
opteng("CF-$mol.round1",$EC1);
system("wc CF-$mol.round1.lh > CF-$mol.round1.ll" );
open alength, "CF-$mol.round1.ll" or die $!;
while ($asd = readline(alength)){
@crapl=split(/\s+/,$asd);
$l = $crapl[1];
}
close alength;
squeeze("CF-$mol.round1.uh");
if ($l ne "1"){
print color 'blue';
print "########################################################################\n";
print "# Beginning round 2... #\n";
print "########################################################################\n\n";
print color 'reset';
squeeze("CF-$mol.round1.lh");
group("CF-$mol.round1.lh.sq");
combine("CF-$mol.round1.lh.sq.gp");
system("sort CF-$mol.i | uniq | sed 's/\\.//g' | sed 's/\^/$mol./'> CF-$mol.round1.todo");
system("rm CF-$mol.i");
recomb("CF-$mol.round1.todo");
system("mv CF-$mol.round1.todo.uniq CF-$mol.round2");
open round2, "CF-$mol.round2" or die $!;
while ($r2 = <round2>){
foreach $j ($r2){
chomp($j);
if (! -e "$j.log" and ! -e "$j.job") {
while (!($queue = freeQ())){
print color 'red';
print "Queue on machine $machine is full.\n\n";
print color 'reset';
sleep $sleep_queue;
}
testThenSubmit($queue,$j);
}
}
}
close round2;
open round2, "CF-$mol.round2" or die $!;
while ($round2 = <round2>){
chomp($round2);
foreach $y ($round2){
$ok = 0;
if (-e "$y.log" ) {
$ok = check("$y");
}
while (! -e "$y.log" ){
$fin = `ssh -l $ruser $machine "if \[ -e JOB/$y.batch \] ;then echo 1 ;fi "`;
if ($fin == 1){
@rdir = split(/\s+/, `ssh -l $ruser $machine grep Project JOB/$y.batch`);
if ($rdir[1] =~ /Project/) {
`scp $ruser\@$machine:/short/$rdir[2]/$ruser/RUN/$y/$y.log .`;
}
else {
@rdir = split(/\s+/, `ssh -l $ruser $machine grep saved JOB/$y.batch`);
$rdir2 = substr($rdir[1], 0, -1);
`scp $ruser\@$machine:$rdir2/$y.log .`;
}
if (-e "$y.log" ){
`ssh -l $ruser $machine mv JOB/$y.batch BATCH/$y.batch`;
$ok = check("$y");
}
else {
print "something has gone wrong with the transfer of $y.log.\n";
$fin = 0;
}
}
else{
print color 'yellow';
print "$y.log in round 2 does not exist. Waiting for log file from \n $machine ...\n\n";
print color 'reset';
sleep $sleep_job;
}
}
}
}
close round2;
}
else {
print color 'blue';
print "########################################################################\n";
print "# Beginning round 3... #\n";
print "########################################################################\n\n";
print color 'reset';
}
###################################################################################
# Round3 #
###################################################################################
if (-e "CF-$mol.round3"){
system("/bin/rm CF-$mol.round3");
}
system("touch CF-$mol.round2 CF-$mol.round3");
open r1uh, "CF-$mol.round1.uh.sq" or die $!;
$uhi = 0;
while (<r1uh>){
foreach $x ($_){
open r1uhlist, ">CF-$mol.round1.uh.sq.$uhi" or die $!;
print r1uhlist $x;
close r1uhlist;
}
system("cat CF-$mol.round1 CF-$mol.round2 CF-$mol.round3 | sort | uniq > CF-$mol.done");
opteng("CF-$mol.done",$EC2);
window("CF-$mol.done.window","CF-$mol.round1.uh.sq.$uhi");
combine("CF-$mol.window");
system("cat CF-$mol.i | sed 's/\^/CF-$mol./' > CF-$mol.needreorder");
system("rm CF-$mol.i");
reorder("CF-$mol.needreorder");
#Before submit round3-1, check if there is anything in DONE!
recomb("CF-$mol.order");
system("sort CF-$mol.order.uniq | uniq > CF-$mol.round3-$uhi.tosub");
system("cat CF-$mol.round3-$uhi.tosub >> CF-$mol.round3");
open R3tosub, "CF-$mol.round3-$uhi.tosub" or die $!;
print color 'blue';
print "########################################################################\n";
print "# Beginning round 3-$uhi... #\n";
print "########################################################################\n\n";
print color 'reset';
while ($R3 = <R3tosub>){
chomp($R3);
foreach $y ($R3){
if (! -e "$y.log" and ! -e "$y.job") {
while (!($queue = freeQ())){
print color 'red';
print "Queue on machine $machine is full.\n\n";
print color 'reset';
sleep $sleep_queue;
}
testThenSubmit($queue,$y);
}
}
}
close R3tosub;
$fileexist= 1;
open R3tosub, "CF-$mol.round3-$uhi.tosub" or die $!;
while ($R3tosub = <R3tosub>){
chomp($R3tosub);
foreach $y ($R3tosub){
$ok = 0;
if (-e "$y.log" ) {
$ok = check("$y");
}
while (! -e "$y.log" ){
$fin = `ssh -l $ruser $machine "if \[ -e JOB/$y.batch \] ;then echo 1 ;fi "`;
if ($fin == 1){
@rdir = split(/\s+/, `ssh -l $ruser $machine grep Project JOB/$y.batch`);
if ($rdir[1] =~ /Project/) {
`scp $ruser\@$machine:/short/$rdir[2]/$ruser/RUN/$y/$y.log .`;
}
else {
@rdir = split(/\s+/, `ssh -l $ruser $machine grep saved JOB/$y.batch`);
$rdir2 = substr($rdir[1], 0, -1);
`scp $ruser\@$machine:$rdir2/$y.log .`;
}
if (-e "$y.log" ){
`ssh -l $ruser $machine mv JOB/$y.batch BATCH/$y.batch`;
$ok = check("$y");
}
else {
print "something has gone wrong with the transfer of $y.log.\n";
$fin = 0;
}
}
else{
print color 'yellow';
print "$y.log in round 3 does not exist. Waiting for log file from \n $machine ...\n\n";
print color 'reset';
sleep $sleep_job;
}
}
}
}
close R3tosub;
$uhi++;
}
close r1uh;
system("cat CF-$mol.round1 CF-$mol.round2 CF-$mol.round3 | sort | uniq > CF-$mol.done");
opteng("CF-$mol.done",$EC2);
system("rm CF-$mol.*order* CF-$mol.*sq* CF-$mol.*.ll");
print color 'green';
print "########################################################################\n";
print "# Conformer search complete. #\n";
print "########################################################################\n\n";
print color 'reset';
system("touch CF-$mol.complete");
############################################################################
# freeQ #
############################################################################
sub freeQ{
for ($i = $p1; $i <= $#ProjectCode; $i++) {
$p = $ProjectCode[$i];
# $p = "f81";
@totalQ = split(/\s+/,`ssh $machine -l \$REMOTE_USER /opt/pbs/default/bin/nqstat -P $p | grep ' $ruser ' | grep ' $p ' | wc `);
@Queuejob = `ssh $machine -l \$REMOTE_USER /opt/pbs/default/bin/nqstat -P $p | grep ' $p ' | sed 's/.*MB//' | sed 's/.*GB//'`;
print "\n";
print "Total queued jobs for project $p is $#Queuejob. ";
if($#Queuejob >= $maxQ{$p}){
print "This is greater than the limit of $maxQ{$p} per project.\n";
}
else{
print "This is less than the limit of $maxQ{$p} per project.\n";
print "Total queued jobs for $ruser on project $p = ", $totalQ[1],". ";
if ($totalQ[1] >= $maxQ{user}){
print "This is greater than the limit of $maxQ{user} per user.\n";
}
else{
print "This is less than the limit of $maxQ{user} per user.\n";
return $p;
}
}
}
return 0;
}
#sub freeQ{
# @totalQ = split(/\s+/,`ssh $machine -l \$REMOTE_USER /opt/pbs/default/bin/nqstat -P $rdir | grep ' $ruser ' | grep ' $rdir ' | wc `);
# @totalCpus = `ssh $machine -l \$REMOTE_USER /opt/pbs/default/bin/nqstat | grep ' \$REMOTE_USER ' | grep ' $rdir ' | sed 's/.*MB//' | sed 's/.*GB//' `;
# $Cpus = add(@totalCpus);
# print "\n";
# if ($totalQ[1] >= $maxQ{user}){
# print "Total queued jobs = ", $totalQ[1]," is greater than $maxQ{user} per user.\n";
# print "test\n";
# }
# elsif ($Cpus + $ncpus >= $maxCPU{user}){
# $Cpus1 = $Cpus + $ncpus;
# print "Total CPUs in use = ", $Cpus1 , " is greater than $maxCPU{user} per user.\n";
# }
# else{
# print "Total CPUSs in use = ", $Cpus , " is less than $maxCPU{user} per user.\n";
# print "Total queued jobs = ", $totalQ[1]," is less than $maxQ{user} per user.\n";
# foreach $p (@ProjectCode){
# for ($i = 0; $i <= 1; $i++) {
# if ($i == 0) {$p = "f81"} else {$p = "x69"}
# @Queuejob = `ssh $machine -l \$REMOTE_USER /opt/pbs/default/bin/nqstat -P $p | grep ' $p ' | sed 's/.*MB//' | sed 's/.*GB//'`;
# $currentCpus =add(@Queuejob);
# print "Total CPUs in use for project $p is $currentCpus.\n";
# print "Total queued jobs for project $p is $#Queuejob.\n\n";
# if ($currentCpus + $ncpus >= $maxCPU{$p}){ # this is for max 1000 per project.
# print "Total queued cpus = ", $currentCpus + $ncpus," is greater than $maxCPU{$p} per project.\n";
# }
# if($#Queuejob+1 >= $maxQ{$p}){
# print "Total queued jobs = ", $#Queuejob+1," is greater than $maxQ{$p} per project.\n";
# }
# else{
# return $p;
# }
# }
# }
# return 0;
#}
############################################################################
# add #
############################################################################
sub add{
$sum = 0;
while (@_) {
$Q = shift @_;
next unless($Q =~ m/[0-9]/);
$sum+=$Q;
}
return $sum;
}
############################################################################
# Check Output file is Valid (Good Distance) for TS Optimisation #
############################################################################
sub check {
my $file = shift(@_);
$jobdone =-2 ;
if (! $tols){
$test1 = `grep Done $file.log | tail -n 1`;
$test2 = `grep Normal $file.log | tail -n 1`;
$test3 = `grep "fake Gaussian" $file.log | tail -n 1`;
if ($test3 =~ /fake/) {
print color 'red';
print "$file is too crowded - not considerd.\n\n";
print color 'reset';
return 0;
}
elsif ($test1 !~ /Done/) {
print color 'red';
print "$file did not run correctly - submitting again.\n";
print color 'reset';
system("$sub $file.com -cs");
`mv $file.log $file.log.bak`;
`touch $file.job`;
return 1;
}
elsif (($test2 !~ /Normal/) && (-e "$file.log.bak")) {
print color 'red';
print "$file has failed twice - not resubmitting.\n\n";
print color 'reset';
return 0;
}
elsif ($test2 !~ /Normal/) {
print color 'red';
print "$file failed - rerunning.\n";
print color 'reset';
system("rerun $file.log");
`mv $file.log $file.log.bak`;
`touch $file.job`;
return 1;
}
else{
print color 'green';
printf "%s terminated normally.\n\n",$file;
print color 'reset';
return 0;
}
}
elsif ($tols){
open ifh, "$file.log" or die $!;
system("crinxyz $file.log ");
open xyzfile, "$file.xyz" or die $!;
readline(xyzfile);
readline(xyzfile);
$natom=1;
while ($atomline = readline(xyzfile)){
@atom = split(/\s+/,$atomline);
$atomx[$natom]= $atom[1];
$atomy[$natom]= $atom[2];
$atomz[$natom]= $atom[3];
$natom ++;
}
close xyzfile;
if ($atom[1] =~/Xx/){
$bondlength =0.0
}
else{
$bondlength =
sqrt(($atomx[$atom1] - $atomx[$atom2])**2 + ($atomy[$atom1] - $atomy[$atom2])**2 + ($atomz[$atom1] - $atomz[$atom2])**2);
}
while ($line = readline(ifh)) {
if ($line=~ /Normal/){
$jobdone=1;
}
elsif ($line=~ /Address/){
$jobdone=-1;
}
elsif ($line=~ /kill/){
$jobdone=-2;
}
}
close ifh;
if (($jobdone <=-2) ) {
if ( $bondlength<= $gooddist+$toldist and $bondlength >= $gooddist-$toldist){
printf "%s killed, no resubmit\t %5.2f\t(within %5.2f-%5.2f )\n",$file,$bondlength,$gooddist-$toldist,$gooddist+$toldist;
$resub = "N"; # maybe yes
system("mailx -s 'Resubmit $file (killed), bond length is $bondlength within $gooddist-$toldist and $gooddist+$toldist' $email < $file.xyz ") ;
}
else{
printf "%s killed, no resubmit\t %5.2f\t(shorter than %5.2f or longer than %5.2f)\n",$file,$bondlength,$gooddist-$toldist,$gooddist+$toldist;
$resub = "N";
system("mailx -s 'NO Resubmit $file (killed), bond length is $bondlength shorter than $gooddist-$toldist or longer than $gooddist+$toldist' $email < $file.xyz ") ;
}
}
if ($resub eq "Y"){
system("cat $file.log >> $file.log.2; /bin/rm $file.log");
return 0;
}
elsif (($jobdone ==-1) ) {
if ( $bondlength<= $gooddist+$toldist and $bondlength >= $gooddist-$toldist){
printf "%s Address Error, resubmit\t %5.2f\t(within %5.2f- %5.2f)\n",$file,$bondlength,$gooddist-$toldist,$gooddist+$toldist;
$resub = "N"; # maybe yes
system("mailx -s 'Resubmit $file (Address Error), bond length is $bondlength (within $gooddist-$toldist and $gooddist +$toldist), but we adivice you to check what causes this Address Error Termination' $email < $file.xyz ") ;
}
else{
printf "%s Address Error, no resubmit\t %5.2f\t(shorter than %5.2f or longer than %5.2f)\n",$file,$bondlength,$gooddist-$toldist,$gooddist+$toldist;
$resub = "N";
system("mailx -s 'NO Resubmit $file (Address Error), bond length is $bondlength (shorter than $gooddist -$toldist or longer than $gooddist+$toldist), ' $email < $file.xyz ") ;
}
}
if ($resub eq "Y"){
system("cat $file.log >> $file.log.2; /bin/rm $file.log");
return 0;
}
elsif ($jobdone ==1){
if ( $bondlength<= $gooddist+$toldist and $bondlength >= $gooddist-$toldist){
print color 'green';
printf "%s terminated normally\t %5.2f\t(within %5.2f- %5.2f)\n",$file,$bondlength,$gooddist-$toldist,$gooddist+$toldist;
print color 'reset';
}
else{
print color 'green';
printf "%s terminated normally.\t %5.2f\t(shorter than %5.2f or longer than %5.2f)\n",$file,$bondlength,$gooddist-$toldist,$gooddist+$toldist;
print color 'reset';
}
}
return 0;
}
}
############################################################################
# OptEng #
############################################################################
sub opteng{
$count = 0;
my ($roundlist,$window) = @_;
open roundlist, $roundlist or die $!;
while ($round = <roundlist>) {
foreach $i ($round){
chomp($i);
@roundlist=split(/\./,$i);
$dih[$count] = $roundlist[1];
@crap = split(/\s+/,`grep Done $i.log | tail -n 1 `);
$eng[$count]=$crap[5];
# open output, "$i.log" or die $!; # this might be taking too much time, to get energy for each of them. need reoptimize!! Leaf
# while (<output>) {
# if (/SCF D/) {
# @crap=split(/\s+/,$_);
# $eng[$count]=$crap[5];
# }
# }
# close output;
if ($tols){
system("crinxyz $i.log ");
open xyzfile, "$i.xyz" or die $!;
readline(xyzfile);
readline(xyzfile);
$natom=1;
while ($atomline = readline(xyzfile)){
@atom = split(/\s+/,$atomline);
$atomx[$natom]= $atom[1];
$atomy[$natom]= $atom[2];
$atomz[$natom]= $atom[3];
$natom ++;
}
close xyzfile;
$bonddist[$count] =
sqrt(($atomx[$atom1] - $atomx[$atom2])**2 + ($atomy[$atom1] - $atomy[$atom2])**2 + ($atomz[$atom1] - $atomz[$atom2])**2);
if ( $bonddist[$count] >= $gooddist+$toldist or $bonddist[$count] <= $gooddist-$toldist){
$eng[$count] = 0.0;
}
#print "$dih[$count] , $bonddist[$count]\n";
}
#print "$dih[$count] , $eng[$count]\n";
$count ++;
}
}
close roundlist;
sub numerically { $a <=> $b; }
@sorteng = sort numerically @eng;
$sortk=0;
while ($sortk <$count){
for ($k = 0; $k < $count ; $k++){
if ($sorteng[$sortk] == $eng[$k] ){
$sortdih[$sortk] = $dih[$k];
$sortk++;
}
}
}
open fla, ">$roundlist.all" or die $!;
open flh, ">$roundlist.lh" or die $!;
open flw, ">$roundlist.window" or die $!;
open fuh, ">$roundlist.uh" or die $!;
$Lowest = ($sorteng[1]-$sorteng[0]) *2625.5;
if ($Lowest < $window){
for ($sortk = 0; $sortk < $count ; $sortk++){
$Deng[$sortk]= ($sorteng[$sortk]-$sorteng[0]) *2625.5;
if (($Deng[$sortk] < $window && $Deng[$sortk]> -$window)&& $sortk < $Nmax ){
printf flw "Less than %.2fkJ/mol= %s \t%f\n", $window, $sortdih[$sortk], $Deng[$sortk];
}
if ($sortk < $count/2) {
printf flh "Lower Half = %s \t%f\n", $sortdih[$sortk], $Deng[$sortk];
printf fla "Lower Half = %s \t%f kJ/mol or %f Hartree\n", $sortdih[$sortk], $Deng[$sortk], $sorteng[$sortk];
}
else{
printf fuh "Upper Half = %s \t%f\n", $sortdih[$sortk], $Deng[$sortk];
printf fla "Upper Half = %s \t%f kJ/mol or %f Hartree\n", $sortdih[$sortk], $Deng[$sortk], $sorteng[$sortk];
}
}
print "\n-----------------------------------------------------------\n";
printf "Lowest energy conformer is %s \t%f Hartree\n", $sortdih[0], $sorteng[0];
printf "The next lowest is %s \t+%f kJ/mol\n", $sortdih[1] ,$Lowest ;
print "-----------------------------------------------------------\n";
}
else {
print "\n-----------------------------------------------------------\n";
printf "Lowest 1 = %s \t%f Hartree\n", $sortdih[0], $sorteng[0];
printf "No other conformer has energy less than %.2fkJ/mol\n", $window;
print "-----------------------------------------------------------\n";
printf flh "Lowest 1 = %s \t%f\n", $sortdih[0], $Deng[0];
printf fla "Lowest 1 = %s \t%f kJ/mol or %f Hartree\n", $sortdih[0], $Deng[0], $sorteng[0];
printf flw "Less than %.2fkJ/mol= %s \t%f\n", $window, $sortdih[0], $Deng[0];
for ($sortk = 1; $sortk < $count ; $sortk++){
$Deng[$sortk]= ($sorteng[$sortk]-$sorteng[0]) *2625.5;
printf fuh "Upper Rest = %s \t%f\n", $sortdih[$sortk], $Deng[$sortk];
printf fla "Upper Rest = %s \t%f kJ/mol or %f Hartree\n", $sortdih[$sortk], $Deng[$sortk], $sorteng[$sortk];
}
}
close fla;
close flh;
close flw;
close fuh;
}
############################################################################
# Squeeze #
############################################################################
sub squeeze{
my $tosq=shift(@_);
open filesq,">$tosq.sq" or die $!;
open tosq, $tosq or die $!;
$count=0;
while ($dihhh= readline(tosq)){
@crap=split(/\s/,$dihhh);
$dih = $crap[3];
if (length($dih) <4 ){
print filesq "$dih\n";
}
else {
@IndDih= split(/a1/,$dih);
print filesq "$IndDih[1]\n";
}
}
close tosq;
close filesq;
}
############################################################################
# Group #
############################################################################
sub group{
my $togp=shift(@_);
$count = 0;
$maxk = 0;
@list = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
open togp, "$togp" or die $!;
while ($dih[$count] = readline(togp)){
chomp($dih[$count]);
@diha = split(/\d+/,$dih[$count]);
$aaa[$count] = $diha[0];
chomp($aaa[$count]);
for ($k=0;$k<=length[$list];$k++){
#$group[$k][0]="";
if ("$aaa[$count]" eq "$list[$k]"){
$group[$k][$gp[$k][$dep]]= $dih[$count] ;
$gp[$k][$dep]++;
if ($k > $maxk){ $maxk = $k;}
}
}
$count++;
}
close togp;
open filegp, ">$togp.gp" or die $!;
for ($i=0;$i<=$maxk; $i++) {
if ( length($group[$i]) > 0 ){
for ($j=0;$j<=$gp[$i][$dep];$j++) {
print filegp "$group[$i][$j] " ;
}
print filegp "\n";
}
}
close filegp;
}
############################################################################
# Combine without. #
############################################################################
sub combine{
@data = ();
#use Data::Dumper;
my $tocomb = shift(@_);
open tocomb,"$tocomb" or die $!;
while ($nnn=readline(tocomb)){
push(@data,[split(/\s+/,$nnn)]);;
}
close tocomb;
open moli, ">CF-$mol.i" or die $!;
# start at 1 to skip the empty selection
for ($i = 3; $i < 2**@data; $i++) {
@bin = dec2bin($i);
my @tmp = ();
for ($j = 0; $j < @bin ;$j++) {
push(@tmp,$data[$j]) if ($bin[$j]);
}
perm("",@tmp);
}
sub dec2bin {
my $str = unpack("B32", pack("N", shift));
$str =~ s/^0+(?=\d)//;
return split(//,reverse($str));
}
sub perm {
my ($s,@a) = @_;
my $i;
if (@a) {
my @b = @{$a[0]};
shift (@a);
for (@b) {
#change this line later
perm($s."$_.",@a);
}
}else {
#print length($s),"\n";
#print "$s\n";
if (length($s)>3){
if ($s =~ /a/) {
print moli "$s\n";
}
else{
print moli "a1.$s\n";
}
}
}
return;
}
close moli;
}
############################################################################
# ReCombine #
############################################################################
sub recomb{
my $torc = shift(@_);
chomp($torc);
open torc, "$torc" or die $!;
open moldone,"CF-$mol.done" or die $!;
$count1=0;
$count2=0;
while ($crap1[$count1] = readline(torc)){
chomp($crap1[$count1]);
@crap2 = split(/\./,$crap1[$count1]);
$todo[$count1] = $crap2[1];
$count1++;
}
while ($crap2[$count2] = readline(moldone)){
chomp($crap2[$count2]);
@crap3 = split(/\./,$crap2[$count2]);
$done[$count2] = $crap3[1];
$count2++;
}
open todo, ">$torc.uniq" or die $!;
for ($kk=0;$kk< $count1 ; $kk++){
for ($jj=0;$jj<$count2;$jj++){
if ("$done[$jj]" eq "$todo[$kk]"){
$iii=1;
}
else{
$iii=0;
}
}
if ($iii ==0){
print todo "$mol.$todo[$kk]\n";
}
}
close moldone;
close todo;
close torc;
}
############################################################################
# Window #
# < CF-$mol.done.window CF-$mol.round1.uh.sq.$i > CF-$mol.window #
############################################################################
sub window {
my ($donewd,$uhi)=@_;
open wd,">CF-$mol.window" or die $!;
open uhi, "$uhi" or die $!;
while ($dihh= readline(uhi)){
@crap=split(/\s/,$dihh);
$dih = $crap[0];
print wd "$dih ";
}
print wd "\n";
close uhi;
open donewd, $donewd or die $!;
$count=0;
while ($dihh= readline(donewd)){
@crap=split(/\s/,$dihh);
$dih = $crap[3];
$dih =~ s/(\d)/$1\./g;
print wd "$dih ";
}
close wd;
close donewd;
}
############################################################################
# Window #
# < CF-$mol.done.window CF-$mol.round1.uh.sq.$i > CF-$mol.window #
############################################################################
sub reorder{
@list = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
my $order = shift(@_);
open molorder,">CF-$mol.order" or die $!;
open order, $order or die $!;
while ($dihhh= readline(order)){
@crap=split(/\./,$dihhh);
print molorder "CF-$mol.";
for ($count=@crap; $count >0 ; $count--){