in reply to XYZ Manipulation
I'm sorry code works this is my first HTML post, this line is printing an extra + but I have to go home from work now
#!/usr/bin/perl @coords_i=();@coords_j=(); open (IN,"CONTCAR"); open (OUT,">OUTPUT"); $k=$go=$i=0; while($line=<IN>){ $lines[$i]=$line; $i++; } for ($j=0;$j<$i;$j++){ $go++ if $lines[$j]=~/Direct/; $go=0 if $lines[$j]=~/0.00000000E/; if ($go>0){ if(($x,$y,$z)=$lines[$j]=~/^\s*([-+]?\d+\.\d+)\s+([-+]?\d+\.\d+)\s+([- ++]?\d+\.\d+)/){ $coords_i[$k]=sprintf("%.5f:%.5f:%.5f",$x,$y,$z); $coords_j[$k]=sprintf("%.5f:%.5f:%.5f",$x,$y,$z); $k++; } } } $n=1; foreach $atom (@coords_i){ print OUT "ATOM$n: $atom\n"; foreach $atom1 (@coords_j){ unless($atom eq $atom1){ ($x,$y,$z) = split(/:/,$atom); ($x1,$y1,$z1) = split(/:/,$atom1); &distance; } } $n++; } sub distance { $a1=($x1-$x);$b1=($y1-$y);$c1=($z1-$z); $r1=sqrt(($a1*$a1)+($b1*$b1)+($c1*$c1)); $distance=sprintf("%.5f",$r1); print OUT "$atom to $atom1\nDistance $distance\n"; } close (OUT); print STDERR "Done.\n";
|
|---|