sualization mods + adabtions
[physik/posic.git] / visualize
1 #!/bin/sh
2
3 #
4 # visualization script
5 # author: frank.zirkelbach@physik.uni-augsburg.de
6 #
7
8 directory="doesnt_exist____for_sure"
9 width="1024"
10 height="768"
11 radius="1.0"
12 x0=""; y0=""; z0="";
13 x1=""; y1=""; z1="";
14 cx=""; cy=""; cz="";
15 lx="0"; ly="-100"; lz="100";
16
17 while [ "$1" ]; do
18         case "$1" in
19                 -d)             directory=$2;           shift 2;;
20                 -w)             width=$2;               shift 2;;
21                 -h)             height=$2;              shift 2;;
22                 -r)             radius=$2;              shift 2;;
23                 -nll)           x0=$2; y0=$3; z0=$4;    shift 4;;
24                 -fur)           x1=$2; y1=$3; z1=$4;    shift 4;;
25                 -c)             cx=$2; cy=$3; cz=$4;    shift 4;;
26                 -l)             lx=$2; ly=$3; lz=$4;    shift 4;;
27                 -o)             ortographic=1;          shift 1;;
28                 *)
29                                 echo "options:"
30                                 echo "########"
31                                 echo "directory to progress:"
32                                 echo "  -d <directory> (mandatory)"
33                                 echo "png dim:"
34                                 echo "  -w <width>"
35                                 echo "  -h <height>"
36                                 echo "atom size:"
37                                 echo "  -r <radius>"
38                                 echo "visualization volume:"
39                                 echo "  -nll <x> <y> <z> (near lower left)"
40                                 echo "  -fur <x> <y> <z> (far upper right)"
41                                 echo "  -o (ortographic)"
42                                 echo "povray:"
43                                 echo "  -c <x> <y> <z> (camera position)"
44                                 echo "  -l <x> <y> <z> (light source)"
45                                 exit 1;;
46         esac
47 done
48                 
49 if [ ! -d $directory ] ; then
50         echo "no valid directory"
51         exit 1
52 fi
53
54 POVRAY="povray -W${width} -H${height} -d" 
55
56 for file in $directory/atomic_conf_*.xyz; do
57
58         cat > temp.pov <<-EOF
59 #include "colors.inc"
60 #include "textures.inc"
61 #include "shapes.inc"
62 #include "glass.inc"
63 #include "metals.inc"
64 #include "woods.inc"
65 #include "stones.inc"
66 EOF
67
68         # meta info
69         count=`grep '# \[P\]' $file | awk '{ print $3 }'`
70         time=`grep '# \[P\]' $file | awk '{ print $4 }'`
71         camloc=`grep '# \[P\]' $file | awk '{ print $5 }'`
72         [ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
73
74         # atoms
75         if [ -n "$x0" ]; then
76                 export x0 y0 z0 x1 y1 z1 radius
77                 cat $file | grep -v '#' | awk '\
78                 BEGIN {
79                         x0=ENVIRON["x0"]; y0==ENVIRON["y0"]; z0==ENVIRON["z0"];
80                         x1=ENVIRON["x1"]; y0==ENVIRON["y1"]; z0==ENVIRON["z1"];
81                         radius=ENVIRON["radius"];
82                 }
83                 {
84                         if(($2>=x0)&&($3>=y0)&&($4>=z0)&&\
85                            ($2<=x1)&&($3<=y1)&&($4<=z1)) {
86                                 print "sphere { <"$2","$4","$3">, "radius" ";
87                                 print "texture { pigment { color "$5" } ";
88                                 print "finish { phong 1, metallic } } }";
89                         }
90                 }' >> temp.pov
91         else
92                 cat $file | grep -v '#' | while read name x y z color temp; do
93                         cat >> temp.pov <<-EOF
94 sphere {
95 <$x, $z, $y>, $radius
96 texture {
97 pigment { color $color }
98 finish {
99 phong 1
100 metallic
101 }
102 }
103 }
104 EOF
105                 done
106         fi
107
108         # boundaries
109         if [ -z "$x0" ]; then
110         cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
111                 cat >> temp.pov <<-EOF
112 cylinder {
113 <$x1, $z1, $y1>, <$x2, $z2, $y2>, 0.05
114 pigment { color White }
115 }
116 EOF
117         done
118         fi
119
120         # add camera and light source
121         cat >> temp.pov <<-EOF
122 camera {
123 EOF
124         if [ -n "$ortographic" ]; then  cat >> temp.pov <<-EOF
125 orthographic
126 EOF
127         fi
128         cat >> temp.pov <<-EOF
129 location $camloc
130 look_at <0,0,0>
131 }
132 light_source { <0,100,-100> color White shadowless }
133 EOF
134
135         # mv png
136         $POVRAY temp.pov > /dev/null 2>&1
137         mv temp.png `echo $file | sed 's/\.xyz/\.png/'`
138
139 done
140
141 echo "done"