new runmd script for the rx200
[physik/posic.git] / visualize
index f4736ea..7dc964e 100755 (executable)
--- a/visualize
+++ b/visualize
@@ -14,17 +14,33 @@ pigment { color White }
 }
 EOF
 }
+draw_bond() {
+       cat >> temp.pov <<-EOF
+cylinder {
+<$1, $3, $2>, <$4, $6, $5>, $7
+pigment { color Blue }
+}
+EOF
+}
+
+# defaults
 
+lc=5.429
 directory="doesnt_exist____for_sure"
-width="1024"
-height="768"
-radius="1.0"
-x0=""; y0=""; z0="";
-x1=""; y1=""; z1="";
+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="";
+clx="0"; cly="0"; clz="0";
+
+# parse argv
 
 while [ "$1" ]; do
        case "$1" in
@@ -35,10 +51,13 @@ while [ "$1" ]; do
                -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;;
                *)
                                echo "options:"
                                echo "########"
@@ -49,6 +68,9 @@ while [ "$1" ]; do
                                echo "  -h <height>"
                                echo "atom size:"
                                echo "  -r <radius>"
+                               echo "  -B <bond cylinder radius>"
+                               echo "unit cell:"
+                               echo "  -C <lattice constant>"
                                echo "visualization volume:"
                                echo "  -nll <x> <y> <z> (near lower left)"
                                echo "  -fur <x> <y> <z> (far upper right)"
@@ -57,19 +79,61 @@ while [ "$1" ]; do
                                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)"
                                exit 1;;
        esac
 done
 
-if [ ! -d $directory ] ; then
-       echo "no valid directory"
-       exit 1
+# calculation from lattic eunits to angstroms
+
+[ "$lc" = "sic" ] && lc=4.359
+[ "$lc" = "si" ] && lc=5.429
+[ "$lc" = "c" ] && lc=3.566
+
+offset=`echo 0.125 \* $lc | bc`
+
+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`
+
+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" 
 
-for file in $directory/atomic_conf_*.xyz; do
+# do it ...
+
+if [ -d $directory ]; then
+       filesource=$directory/atomic_conf_*.xyz
+fi
+
+if [ -f $directory ]; then
+       filesource=$directory
+fi
+
+for file in $filesource; do
 
        cat > temp.pov <<-EOF
 #include "colors.inc"
@@ -125,14 +189,11 @@ EOF
        if [ -z "$bx0" ]; then
 
        if [ -z "$x0" ]; then
+
        cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
-               cat >> temp.pov <<-EOF
-cylinder {
-<$x1, $z1, $y1>, <$x2, $z2, $y2>, 0.05
-pigment { color White }
-}
-EOF
+               draw_cyl $x1 $z1 $y1 $x2 $z2 $y2 0.05
        done
+
        else
                # manually drawing the 3x4 boundaries ...
                draw_cyl $x0 $y0 $z0 $x1 $y0 $z0
@@ -171,6 +232,38 @@ EOF
 
        fi      
 
+       # bonds
+       if [ -n "$bcr" ]; then
+
+               if [ -z "$x0" ]; then
+
+       cat $file | grep '# \[B\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
+               draw_bond $x1 $z1 $y1 $x2 $z2 $y2 $bcr
+       done
+
+               else
+
+               export x0 y0 z0 x1 y1 z1 bcr
+               cat $file | grep '# \[B\]' | awk '\
+               BEGIN {
+                       x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
+                       x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
+                       bcr=ENVIRON["bcr"];
+               }
+               {
+                       if(($3>=x0)&&($4>=y0)&&($5>=z0)&&\
+                          ($3<=x1)&&($4<=y1)&&($5<=z1)) {
+                               print "cylinder {";
+                               print "<"$3","$5","$4">,";
+                               print "<"$6","$8","$7">, "bcr;
+                               print "pigment { color Blue }";
+                               print "}";
+                       }
+               }' >> temp.pov
+
+               fi
+       fi      
+
        # add camera and light source
        cat >> temp.pov <<-EOF
 camera {
@@ -181,7 +274,7 @@ EOF
        fi
        cat >> temp.pov <<-EOF
 location $camloc
-look_at <0,0,0>
+look_at <$clx,$clz,$clz>
 }
 light_source { <0,100,-100> color White shadowless }
 EOF