#!/usr/bin/perl # the above is the standard linux/unix path for perl: change if your computer is nonstandard sub print_help{ print STDERR <0 or die "Invalid index $index\n"; next; } if($p eq "-c"){ # color atom and print them all $color=1; next; } if($p eq "-h"){ # help print_help; die "\n"; } print_help; die "invalid option $p\n"; } $count=-1; $actualframes=0; open(INPUT,"$filename") || die "Cannot open $filename\n"; while(){ s/^\s*//; @li = split('\s+'); if($#li==0 && $li[0]+0==$li[0]){ $count++; $natms = $li[0]; $index <= $natms or die "index $index is not compatible with this xyz file, with $natms atoms only\n"; $_=; $comment=$_; s/^\s*//; @li = split('\s+'); $time=$li[1]+0.; if($time<=0){ $time=$count; } if($color){ print $natms."\n"; print $comment; for($i=1;$i<=$natms;$i++){ $_=; if($i == $index){ s/^\s*//; @li = split('\s+'); print "O","\t",$li[1],"\t",$li[2],"\t",$li[3],"\n", } else{ print; } } } else{ for($i=1;$i<=$natms;$i++){ $_=; if($i == $index){ s/^\s*//; @li = split('\s+'); print $time,"\t",$li[1],"\t",$li[2],"\t",$li[3],"\t",$li[0],"\n", } } } } } close(INPUT);