Wednesday, November 20, 2013

perl and bash scripts ---II

read-water.pl
#! /usr/bin/perl -w
my @line=0;
my $i=0;
open FILE1, "10waterch3och3noatom.xyz" or die $!;
@line=;
for ($i=0;$i<10 br="" i="">open FILE2, "> water-opart$i";
open FILE3, "> water-hpart$i";
print FILE2 $line[3*$i];
print FILE3 $line[3*$i+1];
print FILE3 $line[3*$i+2];
close FILE2;
close FILE3;
}
close FILE1;
------------------------------------------------------------------------------------------------------

std.pl

#! /usr/bin/perl -w -l

my @eksenergy=0;
my $tempnumber=0;
my $nobias_average_energy=0;
my $product_average_energy=0;
my $temptotal=0;
my $count=0;
my $energy_std=0;
my $selected_range_start=0;
my $selected_range_end=35000;

open ENERGYFILE, 'eks.dat' or die 'can not find the file!';
while (){
$eksenergy[$tempnumber]=$_;
$tempnumber++;
}

close ENERGYFILE;
print 'total numbers are ', $tempnumber;

for ($count=$selected_range_start;$count<$selected_range_end; $count++){
$temptotal=$eksenergy[$count]+$temptotal;
}

$nobias_average_energy=$temptotal/($selected_range_end-$selected_range_start);

$temptotal=0;

for ($count=$selected_range_start;$count<$selected_range_end;$count++){
$temptotal=($eksenergy[$count]-$nobias_average_energy)**2+$temptotal
}

$energy_std=($temptotal/($selected_range_end-$selected_range_start))**(1/2);

print 'the STD is ', $energy_std*627.509;

print 'the average is ', $nobias_average_energy*627.509;
-----------------------------------------------------------------------------------------------------------

decide-h3.pl

#! /usr/bin/perl -w
my @line=0;
my $i=0;
open FILE1, "COLVAR" or die $!;
@line=;
for ($i=0;$i<500 br="" i="">open FILE2, "> hpart$i";
print FILE2 $line[$i];
close FILE2;
}
close FILE1;
-----------------------------------------------------------------------------------------------------------

 find-1214161820.pl

#! /usr/bin/perl -w

my @fileContent=0; # array to store contents of a file

my @tempStore=0;  # temporary array to store data

my @requiredCoordinates=qw(120001 140001 160001 180001 200001); # get the required time-step coordinates in a TRAJECTORY file.

my $moleculeNumberOfAtoms=8; # the number of one system: methanol and oxygen

my $numberOfSeparation=2; # the separation lines between two coordinate file

my $tempNumber=0; # the temporary number used in program

my $tempNumberTwo=0; # the temporary number used in program

my $coordInterval=50; # every 50 time step we choose one trajectory

open INPUTFILE, "@ARGV" or die "can not open TRAJEC.xyz $!"; # open the trajectroy file. If no files, returen a warning.

@fileContent=; # open the TRAJEC.xyz file and store it into fileContent array

open OUTPUTFILE, ">>requiredTimestepsCordinates.xyz"; # open a new file to store the required coordinates.

for ($tempNumber=0;$tempNumber<5 array="" br="" elements="" five="" in="" nbsp="" read="" requiredcoordinates="" tempnumber="">
for ($tempNumberTwo=0;$tempNumberTwo<($moleculeNumberOfAtoms+$numberOfSeparation);$tempNumberTwo++) { # read 10 lines from coordinate file
     ## you can not skip the N.O. 0 element since all arrays have first elment with index 0.
print OUTPUTFILE $fileContent[($requiredCoordinates[$tempNumber]-1)/50*($moleculeNumberOfAtoms+$numberOfSeparation)+ $tempNumberTwo]; #

}

}

close INPUTFILE;

close OUTPUTFILE;



No comments:

Post a Comment