Wednesday, November 20, 2013

some of my perl code and bash script------I

clean.sh
rm log.file HILLS* TRAJEC* COLVAR* RESTART.1 GEO_OPT.xyz HESSIAN *.out  LATEST ENERGIES GEOMETRY* input.out name*
--------------------------------------------------------------------------------------------------------------
average.pl

#! /usr/bin/perl -w
use warnings;
use strict;

my $m=0;
my $n =35000;
my $pn = 68000;
my @eks=0;
my $ksind=0;
my $reactave=0;
my $prodave=0;
my $temp=0;

open KSFILE, 'eks.dat';

while (){
$eks[$ksind]=$_+55.9;
$ksind +=1;
}

print "$eks[34999] \n";

print "the average of reactant";

for ($m=0;$m<$n;$m++){
$temp=$eks[$m]+$temp;
}
$reactave=$temp/$n*2625.5/4.18;

print "$reactave \n";
print "the average of product";

$temp=0;
$m=0;
for ($m=$pn;$m<$pn+4000;$m++){
$temp=$eks[$m]+$temp;
}
$prodave=$temp/4000*2625.5/4.18;
my $diff;
$diff= $prodave - $ reactave;

print "$prodave \n";

print "the energy difference betwen produc and reactant is ";
print "$diff \n";


--------------------------------------------------------------------------------------------
combine.sh
awk '{print $4}' ENERGIES > eks.dat
cp ~/to-gscratch/ch3oh/ch3oh-o2/01172013/nonpbc-10o2/ch3oh-oxy1/backup/ENERGIES nonpbc-energy
awk '{print $4}' nonpbc-energy > nonpbc-eks.dat
cat nonpbc-eks.dat eks.dat > eks-total.dat
---------------------------------------------------------------------------------------------
generate-zpe.pl
#! /usr/bin/perl
#!/usr/local/bin/perl
#
# change all occurances of a string in a file to another string
#
## first open a file to read all the lines

use strict;
use warnings;

my @all=0;
my @freq;
my $zpe=0;
my $m=0;
my $n=0;
my @temp;
my $newfile= "raw-freq";
my $targetfile = "freq.out";

open(MYFILE, $targetfile) or die("can not open the file freq.out");
open (OUTFILE,">", $newfile);

while () {
   next unless /PURIFICATION OF DYNAMICAL MATRIX/;
   $all[$m]= $_;
   while ()
    {
        $m +=1;
        $all[$m]= $_;
        last if /BIG MEMORY ALLOCATIONS/;
    }
  
}
##print @all;
##print $m;
##print $all[5];
##print $all[$m-3];

while ($n<$m-7){
@temp=split (' ', $all[$n+5]);
##print @temp;
$n +=1;
##print $n, @temp;
push (@freq,@temp);
}

foreach (@freq) {
if ($_ < 0) {
next;
}

else {
print OUTFILE "$_ \n";
$zpe=0.5*$_*4.556E-6 + $zpe;
##print "$zpe \n";
}

}

print "$zpe \n";
print OUTFILE "the ZPE is \n";
print OUTFILE $zpe;

close(MYFILE);
close (OUTFILE);




No comments:

Post a Comment