Xyz poscar.pl

From Wiki
Revision as of 16:25, 13 July 2009 by 10.0.7.24 (talk) (New page: #!/usr/bin/perl -w ###############Edit this############### $title = "Single points"; $ncell = 25.832; ####################################### ###Parameters inicialization $i = $j = $k...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  1. !/usr/bin/perl -w
                              1. Edit this###############

$title = "Single points"; $ncell = 25.832;

      1. Parameters inicialization

$i = $j = $k = $l = $J = $m = 0; $k = 1;


      1. Enter the XYZ file

chomp($arq_log = <STDIN>);

  1. open file

open(ARQ, "<$arq_log") or die "Check the file $arq_log: $!\n"; $arq_xyz = "$arq_log";

  1. replacing suffix: xyz=>vasp

$arq_xyz =~ s/xyz/vasp/g;

  1. regular expression, operations

while (<ARQ>){ if (/^\s(\w+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)/){ $atom[$i] = $1; $x[$i] = sprintf("%2.16f", $2/$ncell); $y[$i] = sprintf("%2.16f", $3/$ncell); $z[$i] = sprintf("%2.16f", $4/$ncell);

               $line[$i] = "$atom[$i] $x[$i] $y[$i] $z[$i]";
         	#print "$line[$i]\n";

$i++; } }

  1. sorting the lines

@sorted_lines = sort @line;

  1. split sorted lines

foreach (@sorted_lines){

                     if (/^(\w+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)/){

$Atom[$j] = $1; $X[$j] = $2; $Y[$j] = $3; $Z[$j] = $4;

                         #print "$j $Atom[$j] $X[$j], $Y[$j], $Z[$j]\n";

if ($j == 0){ $l++; $natoms[$l] = $k; #print "$l $k $Atom[$j] $natoms[$l]\n"; $k++;

} else { if ($Atom[$j -1] eq $Atom[$j] ){ $natoms[$l] = $k; #print "$l $k $Atom[$j] $natoms[$l]\n"; $k++; } else { $k=1; $l++; $natoms[$l] = $k; #print "$l $k $Atom[$j] $natoms[$l]\n"; $k++ } } $j++; } }


      1. Generation of the VASP file ###
  1. open new file.vasp

open(XYZ, ">$arq_xyz" ) or die "Check the file $arq_xyz : $!\n";

        1. Print preambulo####
  1. Cell's data

print XYZ " $title \n"; printf XYZ "  % 2.16f \n",$ncell; printf XYZ "  % 2.16f % 2.16f % 2.16f \n",1.0, 0.0, 0.0; printf XYZ "  % 2.16f % 2.16f % 2.16f \n",0.0, 1.0, 0.0; printf XYZ "  % 2.16f % 2.16f % 2.16f \n",0.0, 0.0, 1.0;


  1. Number of each atom's type N1 N2 N3 ....

for($m = 1; $m <= $l; $m++){

   print XYZ "  $natoms[$m]";

} print XYZ "\n"; print XYZ "Selective dynamics\n"; print XYZ "Direct\n";


  1. print the cartesian to the new file.vasp

for($J = 0; $J < $i; $J++){

printf XYZ " % 2.16f % 2.16f % 2.16f F   F   F \n",$X[$J], $Y[$J], $Z[$J];

} $J = 0;

print XYZ "\n";

  1. Print the parameters to dinamics. (by now, only zeros)

for($J = 0; $J < $i; $J++){

printf XYZ " % 2.16f % 2.16f % 2.16f \n",0.0, 0.0, 0.0;

}

print XYZ "\n";

        1. Close the XYZ and VASP files

close(ARQ); close(XYZ);