Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $i ; my $j ; my $buf ; my $line ; my $aa=8.4216417639317700 ;
- my @empline ; my @ener; my @xdatcar ; my $xdhead=7 ;
- open (XDAT, '<', 'XDATCAR') or die "'XDATCAR' $!";
- open (ENER, '<', 'energy.dat') or die "'energy.dat' $!";
- @ener=<ENER> ; chomp for @ener ; ## reading energy.dat
- my $Ndata = scalar @ener ; ## getting total lines number in energy.dat
- foreach $buf (@ener) { $buf=sprintf("%.10f",$buf); } ##convert string to float
- close (ENER) ;
- @xdatcar=<XDAT>; chomp for @xdatcar; ## reading XDATCAR
- close (XDAT) ;
- my @nspe = split(' ',$xdatcar[$xdhead-1]) ; ##getting number of species array from XDATCAR
- my $Nat=0 ; foreach $buf (@nspe) { $Nat+=$buf } ## sumup nspe array
- $i = 0 ;
- $j = 0 ;
- foreach $line (@xdatcar) { ## searching for empty line or Direct line, to be replaced with energy values
- $i++ ;
- if ( $line ~~ /^\s*$/ or $line ~~ /Direct/i ) { ##matching empty lines with any kind of whitespaces, or lines containing 'Direct' word
- $empline[$j]= $i ; ## saving pointer to those lines, empline
- $line = " $aa $ener[$j] $Nat 1" ; ## replacing those empty lines with energies and data
- $j++ ;
- }
- }
- my $off=$xdhead+1 ;
- for($i = 0; $i < $Ndata-1; $i++) {
- my @block = @xdatcar[$empline[$i]..$empline[$i]+$Nat-1] ; ## extracting blocks between empty lines
- my @revblock = reverse(@block) ; ## inverting block
- my @sub_block = @revblock[$Nat-5..$Nat-1] ; ## inverting molecule sub_block
- my @revsub_block = reverse(@sub_block) ;
- splice(@revblock,$Nat-5,5,@revsub_block) ;
- splice(@xdatcar, $off+$i*($Nat+1), $Nat, @revblock) ; ## replacing with correct block
- }
- splice(@xdatcar, 0, $xdhead) ; ## removing header
- open(OUT,'>','tofit.in');
- foreach $line (@xdatcar) { print OUT "$line \n" ; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement