--- /dev/null
+#!/bin/sh
+
+#
+# visualization script
+# author: frank.zirkelbach@physik.uni-augsburg.de
+#
+
+# help function
+draw_cyl() {
+ cat >> temp.pov <<-EOF
+cylinder {
+<$1, $3, $2>, <$4, $6, $5>, 0.05
+pigment { color White }
+}
+EOF
+}
+draw_bond() {
+ cat >> temp.pov <<-EOF
+cylinder {
+<$1, $3, $2>, <$4, $6, $5>, $7
+pigment {
+ color rgbf <0, 0, 1.0, 0.8>
+ finish { phong 1 metallic }
+}
+}
+EOF
+}
+
+# defaults
+
+lc=5.429
+directory="doesnt_exist____for_sure"
+width="640"
+height="480"
+radius="0.6"
+x0="-0.6"; y0="-0.6"; z0="-0.6";
+x1="0.6"; y1="0.6"; z1="0.6";
+cx=""; cy=""; cz="";
+lx="0"; ly="-100"; lz="100";
+ortographic=""
+bx0=""; by0=""; bz0="";
+bx1=""; by1=""; bz1="";
+bcr="0.1";
+clx="0"; cly="0"; clz="0";
+extra=0
+displace=""
+mirror=0
+mx1=0; mx2=0; mx3=0;
+my1=0; my2=0; my3=0;
+mz1=0; mz2=0; mz3=0;
+ab=0
+
+# parse argv
+
+while [ "$1" ]; do
+ case "$1" in
+ -d) directory=$2; shift 2;;
+ -w) width=$2; shift 2;;
+ -h) height=$2; shift 2;;
+ -r) radius=$2; shift 2;;
+ -nll) x0=$2; y0=$3; z0=$4; shift 4;;
+ -fur) x1=$2; y1=$3; z1=$4; shift 4;;
+ -c) cx=$2; cy=$3; cz=$4; shift 4;;
+ -L) clx=$2; cly=$3; clz=$4; shift 4;;
+ -l) lx=$2; ly=$3; lz=$4; shift 4;;
+ -o) ortographic=1; shift 1;;
+ -b) bx0=$2; by0=$3; bz0=$4;
+ bx1=$5; by1=$6; bz1=$7; shift 7;;
+ -B) bcr=$2; shift 2;;
+ -C) lc=$2; shift 2;;
+ -e) extra=1; shift 1;;
+ -D) displace=$2; shift 2;;
+ -m) mx1=$2; mx2=$3; mx3=$4;
+ my1=$5; my2=$6; my3=$7;
+ mz1=$8; mz2=$9; mz3=${10};
+ mirror=1; shift 10;;
+ -A) ab=$2; shift 2;
+ ((cnt=1))
+ while [ $cnt -le $ab ]; do
+ anr[$cnt]=$1; shift 1;
+ ((cnt+=1))
+ done
+ cutoff=$1; shift 1;;
+ *)
+ echo "options:"
+ echo "########"
+ echo "directory to progress:"
+ echo " -d <directory> (mandatory)"
+ echo "png dim:"
+ echo " -w <width>"
+ echo " -h <height>"
+ echo "atom size:"
+ echo " -r <radius>"
+ echo " -B <bond cylinder radius>"
+ echo "unit cell:"
+ echo " -C <lattice constant>"
+ echo " -m <dimX> <dimY> <dimZ> (mirror atoms)"
+ echo "visualization volume:"
+ echo " -nll <x> <y> <z> (near lower left)"
+ echo " -fur <x> <y> <z> (far upper right)"
+ echo " -o (ortographic)"
+ echo "bounding box:"
+ echo " -b <x0> <y0> <z0> <x1> <y1> <z1>"
+ echo "povray:"
+ echo " -c <x> <y> <z> (camera position)"
+ echo " -L <x> <y> <z> (camera look)"
+ echo " -l <x> <y> <z> (light source)"
+ echo "bonds:"
+ echo " -ab <atom number> <cutoff> (auto bonds)"
+ exit 1;;
+ esac
+done
+
+# calculation from lattic eunits to angstroms
+
+[ "$lc" = "sic" ] && lc=4.359
+[ "$lc" = "si" ] && lc=5.480
+[ "$lc" = "c" ] && lc=3.566
+
+#offset=`echo 0.125 \* $lc | bc`
+offset=0.0
+
+x0=`echo $x0 \* $lc + $offset | bc`
+y0=`echo $y0 \* $lc + $offset | bc`
+z0=`echo $z0 \* $lc + $offset | bc`
+x1=`echo $x1 \* $lc + $offset | bc`
+y1=`echo $y1 \* $lc + $offset | bc`
+z1=`echo $z1 \* $lc + $offset | bc`
+
+mx1=`echo $mx1 \* $lc + $offset | bc`
+my1=`echo $my1 \* $lc + $offset | bc`
+mz1=`echo $mz1 \* $lc + $offset | bc`
+mx2=`echo $mx2 \* $lc + $offset | bc`
+my2=`echo $my2 \* $lc + $offset | bc`
+mz2=`echo $mz2 \* $lc + $offset | bc`
+mx3=`echo $mx3 \* $lc + $offset | bc`
+my3=`echo $my3 \* $lc + $offset | bc`
+mz3=`echo $mz3 \* $lc + $offset | bc`
+
+clx=`echo $clx \* $lc + $offset | bc`
+cly=`echo $cly \* $lc + $offset | bc`
+clz=`echo $clz \* $lc + $offset | bc`
+
+if [ -n "$cx" -a -n "$cy" -a -n "$cz" ]; then
+ cx=`echo $cx \* $lc + $offset | bc`
+ cy=`echo $cy \* $lc + $offset | bc`
+ cz=`echo $cz \* $lc + $offset | bc`
+fi
+
+if [ -n "$bx0" ]; then
+ bx0=`echo $bx0 \* $lc + $offset | bc`
+ by0=`echo $by0 \* $lc + $offset | bc`
+ bz0=`echo $bz0 \* $lc + $offset | bc`
+ bx1=`echo $bx1 \* $lc + $offset | bc`
+ by1=`echo $by1 \* $lc + $offset | bc`
+ bz1=`echo $bz1 \* $lc + $offset | bc`
+fi
+
+# povray command
+POVRAY="povray -W${width} -H${height} -d"
+
+# camera location
+[ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
+
+# convert options
+COPTS="-font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
+COPTS="$COPTS -depth 8 -fill white -stroke blue -pointsize 24"
+
+# do it ...
+
+if [ -d $directory ]; then
+ filesource=$directory/CONTCAR*
+fi
+
+if [ -f $directory ]; then
+ filesource=$directory
+fi
+
+for file in $filesource; do
+
+ echo "working on $file ..."
+
+ cat > temp.pov <<-EOF
+#include "colors.inc"
+#include "textures.inc"
+#include "shapes.inc"
+#include "glass.inc"
+#include "metals.inc"
+#include "woods.inc"
+#include "stones.inc"
+EOF
+
+ # meta info
+ scale=`sed -n 2p $file | awk '{ print $1 }'`
+ line="`sed -n 3p $file`"
+ X1=`echo $line | awk '{ print $1 }'`
+ X2=`echo $line | awk '{ print $2 }'`
+ X3=`echo $line | awk '{ print $3 }'`
+ line="`sed -n 4p $file`"
+ Y1=`echo $line | awk '{ print $1 }'`
+ Y2=`echo $line | awk '{ print $2 }'`
+ Y3=`echo $line | awk '{ print $3 }'`
+ line="`sed -n 5p $file`"
+ Z1=`echo $line | awk '{ print $1 }'`
+ Z2=`echo $line | awk '{ print $2 }'`
+ Z3=`echo $line | awk '{ print $3 }'`
+ line="`sed -n 6p $file`"
+ nsi=`echo $line | awk '{ print $1 }'`
+ nc=`echo $line | awk '{ print $2 }'`
+ ((ntot=nsi+nc))
+
+ echo "Si : $nsi"
+ echo "C : $nc"
+ echo "tot: $ntot"
+ echo "cutoff: $cutoff"
+
+ export scale
+ export X1 X2 X3
+ export Y1 Y2 Y3
+ export Z1 Z2 Z3
+
+ export x0 y0 z0 x1 y1 z1 radius
+
+ # atoms
+ ((count=1))
+ ((offset=8))
+ while [ "1" ]; do
+
+ echo -en "$count "
+
+ if [ $count -le $nsi ]; then
+ color="Yellow"
+ else
+ color="Gray"
+ fi
+ export color
+
+ ((gl=offset+count))
+ line="`sed -n ${gl}p $file`"
+ x=`echo $line | awk '{ print $1 }'`
+ y=`echo $line | awk '{ print $2 }'`
+ z=`echo $line | awk '{ print $3 }'`
+
+ echo $x $y $z | awk '\
+ BEGIN {
+ x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
+ x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
+ X1=ENVIRON["X1"]; X2=ENVIRON["X2"]; X3=ENVIRON["X3"];
+ Y1=ENVIRON["Y1"]; Y2=ENVIRON["Y2"]; Y3=ENVIRON["Y3"];
+ Z1=ENVIRON["Z1"]; Z2=ENVIRON["Z2"]; Z3=ENVIRON["Z3"];
+ radius=ENVIRON["radius"]; scale=ENVIRON["scale"];
+ color=ENVIRON["color"]
+ x=0; y=0; z=0;
+ xt=0; yt=0; zt=0;
+ i=0; j=0; k=0;
+ }
+ {
+ for(i=-1;i<=1;i++) {
+ for(j=-1;j<=1;j++) {
+ for(k=-1;k<=1;k++) {
+
+ nx=$1+i; ny=$2+j; nz=$3+k;
+
+ xt=nx*X1+ny*Y1+nz*Z1;
+ yt=nx*X2+ny*Y2+nz*Z2;
+ zt=nx*X3+ny*Y3+nz*Z3;
+
+ xt*=scale;
+ yt*=scale;
+ zt*=scale;
+
+ if((xt>=x0)&&(yt>=y0)&&(zt>=z0)&&\
+ (xt<=x1)&&(yt<=y1)&&(zt<=z1)) {
+ print "sphere { <"xt","zt","yt">, "radius" ";
+ print "texture { pigment { color " color " } ";
+ print "finish { phong 1 metallic } } }";
+ }
+
+ }
+ }
+ }
+ }' >> temp.pov
+
+ # see, whether there are bonds to draw
+ if [ "$ab" = "0" ]; then
+ ((count+=1))
+ continue
+ fi
+ ((cnt=1))
+ dobond=no
+ while [ $cnt -le $ab ]; do
+ anr=${anr[$cnt]}
+ if [ $anr -eq $count ]; then
+ dobond=yes
+ break
+ fi
+ ((cnt+=1))
+ done
+ if [ "$ab" = "-1" ]; then
+ dobond=yes
+ fi
+ if [ "$dobond" = "no" ]; then
+ ((count+=1))
+ continue;
+ fi
+
+ # draw bonds
+ ((ic=1))
+ while [ "1" ]; do
+
+ [ $ic -gt $count ] && break
+
+ if [ $ic -eq $count ]; then
+ ((ic+=1))
+ continue
+ fi
+
+ ((il=ic+offset))
+ line="`sed -n ${il}p $file`"
+ xb=`echo $line | awk '{ print $1 }'`
+ yb=`echo $line | awk '{ print $2 }'`
+ zb=`echo $line | awk '{ print $3 }'`
+
+ echo $x $y $z $xb $yb $zb $cutoff | awk '\
+ BEGIN {
+ x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
+ x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
+ X1=ENVIRON["X1"]; X2=ENVIRON["X2"]; X3=ENVIRON["X3"];
+ Y1=ENVIRON["Y1"]; Y2=ENVIRON["Y2"]; Y3=ENVIRON["Y3"];
+ Z1=ENVIRON["Z1"]; Z2=ENVIRON["Z2"]; Z3=ENVIRON["Z3"];
+ bcr=ENVIRON["bcr"]; scale=ENVIRON["scale"];
+ }
+ {
+ for(i=-1;i<=1;i++) {
+ for(j=-1;j<=1;j++) {
+ for(k=-1;k<=1;k++) {
+
+ for(ii=-1;ii<=1;ii++) {
+ for(ij=-1;ij<=1;ij++) {
+ for(ik=-1;ik<=1;ik++) {
+
+ nx=$1+i; ny=$2+j; nz=$3+k;
+ xt=nx*X1+ny*Y1+nz*Z1;
+ yt=nx*X2+ny*Y2+nz*Z2;
+ zt=nx*X3+ny*Y3+nz*Z3;
+ xt*=scale;
+ yt*=scale;
+ zt*=scale;
+
+ inx=$4+ii; iny=$5+ij; inz=$6+ik;
+ ixt=inx*X1+iny*Y1+inz*Z1;
+ iyt=inx*X2+iny*Y2+inz*Z2;
+ izt=inx*X3+iny*Y3+inz*Z3;
+ ixt*=scale;
+ iyt*=scale;
+ izt*=scale;
+
+ dist=sqrt((xt-ixt)^2+(yt-iyt)^2+(zt-izt)^2);
+
+ if((xt>=x0)&&(yt>=y0)&&(zt>=z0)&&\
+ (xt<=x1)&&(yt<=y1)&&(zt<=z1)) {
+ if(dist<=$7) {
+ print "cylinder {";
+ print "<"xt","zt","yt">,";
+ print "<"ixt","izt","iyt">,0.1";
+ print "pigment { color Blue }";
+ print "}";
+ }
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }' >> temp.pov
+
+ ((ic+=1))
+ [ $ic -gt $ntot ] && break;
+
+ done
+
+ ((count+=1))
+ [ $count -gt $ntot ] && break;
+
+ done
+
+ echo
+
+ # manually drawing the 3x4 boundaries specified by argv ...
+ draw_cyl $bx0 $by0 $bz0 $bx1 $by0 $bz0
+ draw_cyl $bx0 $by0 $bz0 $bx0 $by1 $bz0
+ draw_cyl $bx1 $by1 $bz0 $bx1 $by0 $bz0
+ draw_cyl $bx0 $by1 $bz0 $bx1 $by1 $bz0
+
+ draw_cyl $bx0 $by0 $bz1 $bx1 $by0 $bz1
+ draw_cyl $bx0 $by0 $bz1 $bx0 $by1 $bz1
+ draw_cyl $bx1 $by1 $bz1 $bx1 $by0 $bz1
+ draw_cyl $bx0 $by1 $bz1 $bx1 $by1 $bz1
+
+ draw_cyl $bx0 $by0 $bz1 $bx0 $by0 $bz0
+ draw_cyl $bx0 $by1 $bz1 $bx0 $by1 $bz0
+ draw_cyl $bx1 $by0 $bz1 $bx1 $by0 $bz0
+ draw_cyl $bx1 $by1 $bz1 $bx1 $by1 $bz0
+
+ # add camera and light source
+ cat >> temp.pov <<-EOF
+camera {
+EOF
+ if [ -n "$ortographic" ]; then cat >> temp.pov <<-EOF
+orthographic
+EOF
+ fi
+ cat >> temp.pov <<-EOF
+location $camloc
+look_at <$clx,$clz,$clz>
+}
+light_source { <0,100,-100> color White shadowless }
+EOF
+
+ # mv png
+ $POVRAY temp.pov > /dev/null 2>&1
+ mv temp.png `dirname $file`/
+
+done
+
+echo "done"