]> hackdaworld.org Git - physik/posic.git/blob - vasp_tools/visualize
pc script
[physik/posic.git] / vasp_tools / visualize
1 #!/bin/sh
2
3 #
4 # visualization script
5 # author: frank.zirkelbach@physik.uni-augsburg.de
6 #
7
8 # help function
9 draw_cyl() {
10         cat >> temp.pov <<-EOF
11 cylinder {
12 <$1, $3, $2>, <$4, $6, $5>, 0.05
13 pigment { color White }
14 }
15 EOF
16 }
17 draw_bond() {
18         cat >> temp.pov <<-EOF
19 cylinder {
20 <$1, $3, $2>, <$4, $6, $5>, $7
21 pigment { color Blue }
22 }
23 EOF
24 }
25
26 # defaults
27
28 lc=5.429
29 directory="doesnt_exist____for_sure"
30 width="640"
31 height="480"
32 radius="0.6"
33 x0="-0.6"; y0="-0.6"; z0="-0.6";
34 x1="0.6"; y1="0.6"; z1="0.6";
35 cx=""; cy=""; cz="";
36 lx="0"; ly="-100"; lz="100";
37 ortographic=""
38 bx0=""; by0=""; bz0="";
39 bx1=""; by1=""; bz1="";
40 bcr="";
41 clx="0"; cly="0"; clz="0";
42 extra=0
43 displace=""
44
45 # parse argv
46
47 while [ "$1" ]; do
48         case "$1" in
49                 -d)             directory=$2;           shift 2;;
50                 -w)             width=$2;               shift 2;;
51                 -h)             height=$2;              shift 2;;
52                 -r)             radius=$2;              shift 2;;
53                 -nll)           x0=$2; y0=$3; z0=$4;    shift 4;;
54                 -fur)           x1=$2; y1=$3; z1=$4;    shift 4;;
55                 -c)             cx=$2; cy=$3; cz=$4;    shift 4;;
56                 -L)             clx=$2; cly=$3; clz=$4; shift 4;;
57                 -l)             lx=$2; ly=$3; lz=$4;    shift 4;;
58                 -o)             ortographic=1;          shift 1;;
59                 -b)             bx0=$2; by0=$3; bz0=$4;
60                                 bx1=$5; by1=$6; bz1=$7; shift 7;;
61                 -B)             bcr=$2;                 shift 2;;
62                 -C)             lc=$2;                  shift 2;;
63                 -e)             extra=1;                shift 1;;
64                 -D)             displace=$2;            shift 2;;
65                 *)
66                                 echo "options:"
67                                 echo "########"
68                                 echo "directory to progress:"
69                                 echo "  -d <directory> (mandatory)"
70                                 echo "png dim:"
71                                 echo "  -w <width>"
72                                 echo "  -h <height>"
73                                 echo "atom size:"
74                                 echo "  -r <radius>"
75                                 echo "  -B <bond cylinder radius>"
76                                 echo "unit cell:"
77                                 echo "  -C <lattice constant>"
78                                 echo "visualization volume:"
79                                 echo "  -nll <x> <y> <z> (near lower left)"
80                                 echo "  -fur <x> <y> <z> (far upper right)"
81                                 echo "  -o (ortographic)"
82                                 echo "bounding box:"
83                                 echo "  -b <x0> <y0> <z0> <x1> <y1> <z1>"
84                                 echo "povray:"
85                                 echo "  -c <x> <y> <z> (camera position)"
86                                 echo "  -L <x> <y> <z> (camera look)"
87                                 echo "  -l <x> <y> <z> (light source)"
88                                 exit 1;;
89         esac
90 done
91
92 # calculation from lattic eunits to angstroms
93
94 [ "$lc" = "sic" ] && lc=4.359
95 [ "$lc" = "si" ] && lc=5.429
96 [ "$lc" = "c" ] && lc=3.566
97
98 #offset=`echo 0.125 \* $lc | bc`
99 offset=0.0
100
101 x0=`echo $x0 \* $lc + $offset | bc`
102 y0=`echo $y0 \* $lc + $offset | bc`
103 z0=`echo $z0 \* $lc + $offset | bc`
104 x1=`echo $x1 \* $lc + $offset | bc`
105 y1=`echo $y1 \* $lc + $offset | bc`
106 z1=`echo $z1 \* $lc + $offset | bc`
107
108 clx=`echo $clx \* $lc + $offset | bc`
109 cly=`echo $cly \* $lc + $offset | bc`
110 clz=`echo $clz \* $lc + $offset | bc`
111
112 if [ -n "$cx" -a -n "$cy" -a -n "$cz" ]; then
113         cx=`echo $cx \* $lc + $offset | bc`
114         cy=`echo $cy \* $lc + $offset | bc`
115         cz=`echo $cz \* $lc + $offset | bc`
116 fi
117
118 if [ -n "$bx0" ]; then
119         bx0=`echo $bx0 \* $lc + $offset | bc`
120         by0=`echo $by0 \* $lc + $offset | bc`
121         bz0=`echo $bz0 \* $lc + $offset | bc`
122         bx1=`echo $bx1 \* $lc + $offset | bc`
123         by1=`echo $by1 \* $lc + $offset | bc`
124         bz1=`echo $bz1 \* $lc + $offset | bc`
125 fi
126
127 # povray command
128
129 POVRAY="povray -W${width} -H${height} -d" 
130
131 # convert options
132
133 COPTS="-font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
134 COPTS="$COPTS -depth 8 -fill white -stroke blue -pointsize 24"
135
136 # do it ...
137
138 if [ -d $directory ]; then
139         filesource=$directory/atomic_conf_*.xyz
140 fi
141
142 if [ -f $directory ]; then
143         filesource=$directory
144 fi
145
146 for file in $filesource; do
147
148         cat > temp.pov <<-EOF
149 #include "colors.inc"
150 #include "textures.inc"
151 #include "shapes.inc"
152 #include "glass.inc"
153 #include "metals.inc"
154 #include "woods.inc"
155 #include "stones.inc"
156 EOF
157
158         # meta info
159         count=`grep '# \[P\]' $file | awk '{ print $3 }'`
160         time=`grep '# \[P\]' $file | awk '{ print $4 }'`
161         camloc=`grep '# \[P\]' $file | awk '{ print $5 }'`
162         [ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
163
164         # atoms
165 #echo "-----> $x0 $y0 $z0 $x1 $y1 $z1 <-----"
166         if [ -n "$x0" ]; then
167                 export x0 y0 z0 x1 y1 z1 radius extra
168                 cat $file | grep -v '#' | awk '\
169                 BEGIN {
170                         x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
171                         x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
172                         radius=ENVIRON["radius"]; extra=ENVIRON["extra"];
173                 }
174                 {
175 #                       print "----> " x0 " " y0 " " z0 " " $2 " " $3 " " $4
176 #                       print "----> " x1 " " y1 " " z1 " " $2 " " $3 " " $4
177 #if(($2>=x0)) print $2 " groesser " x0
178 #if(($3>=y0)) print $3 " groesser " y0
179 #if(($4>=z0)) print $4 " groesser " z0
180 #if(($2<=x1)) print $2 " kleiner " x1
181 #if(($3<=y1)) print $3 " kleiner " y1
182 #if(($4<=z1)) print $4 " kleiner " z1
183                         if(($2>=x0)&&($3>=y0)&&($4>=z0)&&\
184                            ($2<=x1)&&($3<=y1)&&($4<=z1)) {
185 #                       if(($2<=x0)&&($3<=y0)&&($4<=z0)&&\
186 #                          ($2>=x1)&&($3>=y1)&&($4>=z1)) {
187                                 print "sphere { <"$2","$4","$3">, "radius" ";
188                                 if(extra)
189                 print "texture { pigment { color rgb<"$6/4.4",0,"1-$6/4.4"> } ";
190                                 else
191                 print "texture { pigment { color "$5" } ";
192                                 print "finish { phong 1 metallic } } }";
193                         }
194                 }' >> temp.pov
195         else
196                 cat $file | grep -v '#' | while read name x y z color temp; do
197                         cat >> temp.pov <<-EOF
198 sphere {
199 <$x, $z, $y>, $radius
200 texture {
201 pigment { color $color }
202 finish {
203 phong 1
204 metallic
205 }
206 }
207 }
208 EOF
209                 done
210         fi
211
212         # boundaries
213         if [ -z "$bx0" ]; then
214
215         #if [ -z "$x0" ]; then
216
217         cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
218                 draw_cyl $x1 $y1 $z1 $x2 $y2 $z2 0.05
219         done
220
221         #else
222
223                 # manually drawing the 3x4 boundaries ...
224 #               draw_cyl $x0 $y0 $z0 $x1 $y0 $z0
225 #               draw_cyl $x0 $y0 $z0 $x0 $y1 $z0
226 #               draw_cyl $x1 $y1 $z0 $x1 $y0 $z0
227 #               draw_cyl $x0 $y1 $z0 $x1 $y1 $z0
228
229 #               draw_cyl $x0 $y0 $z1 $x1 $y0 $z1
230 #               draw_cyl $x0 $y0 $z1 $x0 $y1 $z1
231 #               draw_cyl $x1 $y1 $z1 $x1 $y0 $z1
232 #               draw_cyl $x0 $y1 $z1 $x1 $y1 $z1
233
234 #               draw_cyl $x0 $y0 $z1 $x0 $y0 $z0
235 #               draw_cyl $x0 $y1 $z1 $x0 $y1 $z0
236 #               draw_cyl $x1 $y0 $z1 $x1 $y0 $z0
237 #               draw_cyl $x1 $y1 $z1 $x1 $y1 $z0
238 #       fi
239
240         else
241
242                 # manually drawing the 3x4 boundaries specified by argv ...
243                 draw_cyl $bx0 $by0 $bz0 $bx1 $by0 $bz0
244                 draw_cyl $bx0 $by0 $bz0 $bx0 $by1 $bz0
245                 draw_cyl $bx1 $by1 $bz0 $bx1 $by0 $bz0
246                 draw_cyl $bx0 $by1 $bz0 $bx1 $by1 $bz0
247
248                 draw_cyl $bx0 $by0 $bz1 $bx1 $by0 $bz1
249                 draw_cyl $bx0 $by0 $bz1 $bx0 $by1 $bz1
250                 draw_cyl $bx1 $by1 $bz1 $bx1 $by0 $bz1
251                 draw_cyl $bx0 $by1 $bz1 $bx1 $by1 $bz1
252
253                 draw_cyl $bx0 $by0 $bz1 $bx0 $by0 $bz0
254                 draw_cyl $bx0 $by1 $bz1 $bx0 $by1 $bz0
255                 draw_cyl $bx1 $by0 $bz1 $bx1 $by0 $bz0
256                 draw_cyl $bx1 $by1 $bz1 $bx1 $by1 $bz0
257
258         fi      
259
260         # bonds
261         if [ -n "$bcr" ]; then
262
263                 if [ -z "$x0" ]; then
264
265         cat $file | grep '# \[B\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
266                 draw_bond $x1 $z1 $y1 $x2 $z2 $y2 $bcr
267         done
268
269                 else
270
271                 export x0 y0 z0 x1 y1 z1 bcr
272                 cat $file | grep '# \[B\]' | awk '\
273                 BEGIN {
274                         x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
275                         x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
276                         bcr=ENVIRON["bcr"];
277                 }
278                 {
279                         if(($3>=x0)&&($4>=y0)&&($5>=z0)&&\
280                            ($3<=x1)&&($4<=y1)&&($5<=z1)) {
281                                 print "cylinder {";
282                                 print "<"$3","$5","$4">,";
283                                 print "<"$6","$8","$7">, "bcr;
284                                 print "pigment { color Blue }";
285                                 print "}";
286                         }
287                 }' >> temp.pov
288
289                 fi
290         fi      
291
292         # add camera and light source
293         cat >> temp.pov <<-EOF
294 camera {
295 EOF
296         if [ -n "$ortographic" ]; then  cat >> temp.pov <<-EOF
297 orthographic
298 EOF
299         fi
300         cat >> temp.pov <<-EOF
301 location $camloc
302 look_at <$clx,$clz,$clz>
303 }
304 light_source { <0,100,-100> color White shadowless }
305 EOF
306
307         # mv png
308         $POVRAY temp.pov > /dev/null 2>&1
309         time=`basename $file | awk -F. '{ print $1 }' | awk -F_ '{ print $3 }'`
310         if [ ! -z $displace ]; then
311         convert $COPTS -draw "text 5,20 'd = $displace %'" temp.png temp.png
312         else
313         convert $COPTS -draw "text 5,20 't = $time fs'" temp.png temp.png
314         fi
315         mv temp.png `echo $file | sed 's/\.xyz/\.png/'`
316
317 done
318
319 echo "done"