Xyz poscar.pl: Difference between revisions
No edit summary |
No edit summary |
||
| (5 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
go back to [[Main Page]], [[Computational Resources]], [[Scripts]], [[Scripts for VASP]] | |||
#!/usr/bin/perl -w | #!/usr/bin/perl -w | ||
###############Edit this############### | ###############Edit this############### | ||
$title = "Single points"; | $title = "Single points"; | ||
$ncell = 25.832; | $ncell = 25.832; | ||
####################################### | ####################################### | ||
###Parameters inicialization | ###Parameters inicialization | ||
$i = $j = $k = $l = $J = $m = 0; | $i = $j = $k = $l = $J = $m = 0; | ||
$k = 1; | $k = 1; | ||
###### | ###### | ||
###Enter the XYZ file | ###Enter the XYZ file | ||
chomp($arq_log = <STDIN>); | chomp($arq_log = <STDIN>); | ||
#open file | #open file | ||
open(ARQ, "<$arq_log") or die "Check the file $arq_log: $!\n"; | open(ARQ, "<$arq_log") or die "Check the file $arq_log: $!\n"; | ||
$arq_xyz = "$arq_log"; | $arq_xyz = "$arq_log"; | ||
#replacing suffix: xyz=>vasp | #replacing suffix: xyz=>vasp | ||
$arq_xyz =~ s/xyz/vasp/g; | $arq_xyz =~ s/xyz/vasp/g; | ||
#regular expression, operations | #regular expression, operations | ||
while (<ARQ>){ | while (<ARQ>){ | ||
if (/^\s(\w+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)/){ | if (/^\s(\w+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)\s+(\-?\d+\.\d+)/){ | ||
$atom[$i] = $1; | $atom[$i] = $1; | ||
| Line 35: | Line 36: | ||
$i++; | $i++; | ||
} | } | ||
} | } | ||
#sorting the lines | #sorting the lines | ||
@sorted_lines = sort @line; | @sorted_lines = sort @line; | ||
#split sorted lines | #split sorted lines | ||
foreach (@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"; | #print "$j $Atom[$j] $X[$j], $Y[$j], $Z[$j]\n"; | ||
if ($j == 0){ | if ($j == 0){ | ||
| Line 53: | Line 54: | ||
#print "$l $k $Atom[$j] $natoms[$l]\n"; | #print "$l $k $Atom[$j] $natoms[$l]\n"; | ||
$k++; | $k++; | ||
} | } | ||
else { | else { | ||
| Line 71: | Line 71: | ||
$j++; | $j++; | ||
} | } | ||
} | } | ||
################################## | ################################## | ||
###Generation of the VASP file ### | ###Generation of the VASP file ### | ||
################################## | ################################## | ||
#open new file.vasp | #open new file.vasp | ||
open(XYZ, ">$arq_xyz" ) or die "Check the file $arq_xyz : $!\n"; | open(XYZ, ">$arq_xyz" ) or die "Check the file $arq_xyz : $!\n"; | ||
####################### | ####################### | ||
####Print preambulo#### | ####Print preambulo#### | ||
####################### | ####################### | ||
#Cell's data | #Cell's data | ||
print XYZ " $title \n"; | print XYZ " $title \n"; | ||
printf XYZ " % 2.16f \n",$ncell; | 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",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, 1.0, 0.0; | ||
printf XYZ " % 2.16f % 2.16f % 2.16f \n",0.0, 0.0, 1.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 .... | #Number of each atom's type N1 N2 N3 .... | ||
for($m = 1; $m <= $l; $m++){ | for($m = 1; $m <= $l; $m++){ | ||
print XYZ " $natoms[$m]"; | print XYZ " $natoms[$m]"; | ||
} | } | ||
print XYZ "\n"; | print XYZ "\n"; | ||
print XYZ "Selective dynamics\n"; | print XYZ "Selective dynamics\n"; | ||
print XYZ "Direct\n"; | print XYZ "Direct\n"; | ||
####################### | ####################### | ||
#print the cartesian to the new file.vasp | #print the cartesian to the new file.vasp | ||
for($J = 0; $J < $i; $J++){ | for($J = 0; $J < $i; $J++){ | ||
printf XYZ " % 2.16f % 2.16f % 2.16f F F F \n",$X[$J], $Y[$J], $Z[$J]; | printf XYZ " % 2.16f % 2.16f % 2.16f F F F \n",$X[$J], $Y[$J], $Z[$J]; | ||
} | } | ||
$J = 0; | $J = 0; | ||
print XYZ "\n"; | print XYZ "\n"; | ||
#Print the parameters to dinamics. (by now, only zeros) | #Print the parameters to dinamics. (by now, only zeros) | ||
for($J = 0; $J < $i; $J++){ | for($J = 0; $J < $i; $J++){ | ||
printf XYZ " % 2.16f % 2.16f % 2.16f \n",0.0, 0.0, 0.0; | 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); | |||
close(ARQ); | |||
close(XYZ); | |||
Latest revision as of 13:14, 13 September 2011
go back to Main Page, Computational Resources, Scripts, Scripts for VASP
#!/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);