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