Xyz poscar.pl
- !/usr/bin/perl -w
- Edit this###############
$title = "Single points"; $ncell = 25.832;
- Parameters inicialization
$i = $j = $k = $l = $J = $m = 0; $k = 1;
- Enter the XYZ file
chomp($arq_log = <STDIN>);
- open file
open(ARQ, "<$arq_log") or die "Check the file $arq_log: $!\n"; $arq_xyz = "$arq_log";
- replacing suffix: xyz=>vasp
$arq_xyz =~ s/xyz/vasp/g;
- 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++; } }
- sorting the lines
@sorted_lines = sort @line;
- 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++; } }
- Generation of the VASP file ###
- open new file.vasp
open(XYZ, ">$arq_xyz" ) or die "Check the file $arq_xyz : $!\n";
- Print preambulo####
- 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;
- 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";
- 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";
- 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";
- Close the XYZ and VASP files
close(ARQ); close(XYZ);