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