#!/usr/bin/perl -I /home/manini/bin/perllib # the above include is the location for math_module.pl # couln't find a better way, e.g. using $HOME: does not work! use POSIX; use math_module; # get it from http://www.lwebzem.com/cgi-bin/res/view.cgi?name=math_module.pm # put math_module.pm in the folder named after -I in the first line above sub print_help{ print STDERR <){ s/^\s*//; # remove leading spaces @li = split('\s+'); chomp(); if($#li==0 && $count!=1){ $count=0; print $_,"\n"; } if($count==1){ # comment line print $_,"refolded by xyz_in_cell\n"; } if($count>1){ print $li[0]; for($i=0;$i<3;$i++){ $r[$i]=$li[$i+1]; } for($i=0;$i<3;$i++){ # matrix multiplication by @inv $p[$i]=0; for($j=0;$j<3;$j++){ $p[$i]+=$inv[$i][$j]*$r[$j]; } } for($i=0;$i<3;$i++){ # reduction to -0.5 to 0.5 interval $appo[$i]=$p[$i]-POSIX::floor($p[$i]+0.5); } @rk=(0.,0.,0.); $mindist=$HUGE; for($n1=-$ws;$n1<=$ws;$n1++){ # explore translations to nearest for($n2=-$ws;$n2<=$ws;$n2++){ # neighbors for the WS case for($n3=-$ws;$n3<=$ws;$n3++){ @nvec=($n1,$n2,$n3); for($i=0;$i<3;$i++){ # matrix multiplication by @mat: $rr[$i]=0; for($j=0;$j<3;$j++){ $rr[$i]+=$mat[$i][$j]*($appo[$j]+$nvec[$j]); } } $norm=$rr[0]*$rr[0]+$rr[1]*$rr[1]+$rr[2]*$rr[2]; if($norm<$mindist){ # select shortest $mindist=$norm; @rk=@rr; } } } } for($i=0;$i<3;$i++){ print "\t",$rk[$i]; } print "\n"; } $count++; } close(INPUT); }