]> www.hackdaworld.org Git - physik/posic.git/blob - visualize
added $1 check - removed lots of files :(
[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 directory="doesnt_exist____for_sure"
27 width="640"
28 height="480"
29 radius="1.0"
30 x0=""; y0=""; z0="";
31 x1=""; y1=""; z1="";
32 cx=""; cy=""; cz="";
33 lx="0"; ly="-100"; lz="100";
34 ortographic=""
35 bx0=""; by0=""; bz0="";
36 bx1=""; by1=""; bz1="";
37 bcr="";
38
39 while [ "$1" ]; do
40         case "$1" in
41                 -d)             directory=$2;           shift 2;;
42                 -w)             width=$2;               shift 2;;
43                 -h)             height=$2;              shift 2;;
44                 -r)             radius=$2;              shift 2;;
45                 -nll)           x0=$2; y0=$3; z0=$4;    shift 4;;
46                 -fur)           x1=$2; y1=$3; z1=$4;    shift 4;;
47                 -c)             cx=$2; cy=$3; cz=$4;    shift 4;;
48                 -l)             lx=$2; ly=$3; lz=$4;    shift 4;;
49                 -o)             ortographic=1;          shift 1;;
50                 -b)             bx0=$2; by0=$3; bz0=$4;
51                                 bx1=$5; by1=$6; bz1=$7; shift 7;;
52                 -B)             bcr=$2;                 shift 2;;
53                 *)
54                                 echo "options:"
55                                 echo "########"
56                                 echo "directory to progress:"
57                                 echo "  -d <directory> (mandatory)"
58                                 echo "png dim:"
59                                 echo "  -w <width>"
60                                 echo "  -h <height>"
61                                 echo "atom size:"
62                                 echo "  -r <radius>"
63                                 echo "  -B <bond cylinder radius>"
64                                 echo "visualization volume:"
65                                 echo "  -nll <x> <y> <z> (near lower left)"
66                                 echo "  -fur <x> <y> <z> (far upper right)"
67                                 echo "  -o (ortographic)"
68                                 echo "bounding box:"
69                                 echo "  -b <x0> <y0> <z0> <x1> <y1> <z1>"
70                                 echo "povray:"
71                                 echo "  -c <x> <y> <z> (camera position)"
72                                 echo "  -l <x> <y> <z> (light source)"
73                                 exit 1;;
74         esac
75 done
76
77 if [ ! -d $directory ] ; then
78         echo "no valid directory"
79         exit 1
80 fi
81
82 POVRAY="povray -W${width} -H${height} -d" 
83
84 for file in $directory/atomic_conf_*.xyz; do
85
86         cat > temp.pov <<-EOF
87 #include "colors.inc"
88 #include "textures.inc"
89 #include "shapes.inc"
90 #include "glass.inc"
91 #include "metals.inc"
92 #include "woods.inc"
93 #include "stones.inc"
94 EOF
95
96         # meta info
97         count=`grep '# \[P\]' $file | awk '{ print $3 }'`
98         time=`grep '# \[P\]' $file | awk '{ print $4 }'`
99         camloc=`grep '# \[P\]' $file | awk '{ print $5 }'`
100         [ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
101
102         # atoms
103         if [ -n "$x0" ]; then
104                 export x0 y0 z0 x1 y1 z1 radius
105                 cat $file | grep -v '#' | awk '\
106                 BEGIN {
107                         x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
108                         x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
109                         radius=ENVIRON["radius"];
110                 }
111                 {
112                         if(($2>=x0)&&($3>=y0)&&($4>=z0)&&\
113                            ($2<=x1)&&($3<=y1)&&($4<=z1)) {
114                                 print "sphere { <"$2","$4","$3">, "radius" ";
115                                 print "texture { pigment { color "$5" } ";
116                                 print "finish { phong 1 metallic } } }";
117                         }
118                 }' >> temp.pov
119         else
120                 cat $file | grep -v '#' | while read name x y z color temp; do
121                         cat >> temp.pov <<-EOF
122 sphere {
123 <$x, $z, $y>, $radius
124 texture {
125 pigment { color $color }
126 finish {
127 phong 1
128 metallic
129 }
130 }
131 }
132 EOF
133                 done
134         fi
135
136         # boundaries
137         if [ -z "$bx0" ]; then
138
139         if [ -z "$x0" ]; then
140
141         cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
142                 draw_cyl $x1 $z1 $y1 $x2 $z2 $y2 0.05
143         done
144
145         else
146                 # manually drawing the 3x4 boundaries ...
147                 draw_cyl $x0 $y0 $z0 $x1 $y0 $z0
148                 draw_cyl $x0 $y0 $z0 $x0 $y1 $z0
149                 draw_cyl $x1 $y1 $z0 $x1 $y0 $z0
150                 draw_cyl $x0 $y1 $z0 $x1 $y1 $z0
151
152                 draw_cyl $x0 $y0 $z1 $x1 $y0 $z1
153                 draw_cyl $x0 $y0 $z1 $x0 $y1 $z1
154                 draw_cyl $x1 $y1 $z1 $x1 $y0 $z1
155                 draw_cyl $x0 $y1 $z1 $x1 $y1 $z1
156
157                 draw_cyl $x0 $y0 $z1 $x0 $y0 $z0
158                 draw_cyl $x0 $y1 $z1 $x0 $y1 $z0
159                 draw_cyl $x1 $y0 $z1 $x1 $y0 $z0
160                 draw_cyl $x1 $y1 $z1 $x1 $y1 $z0
161         fi
162
163         else
164
165                 # manually drawing the 3x4 boundaries specified by argv ...
166                 draw_cyl $bx0 $by0 $bz0 $bx1 $by0 $bz0
167                 draw_cyl $bx0 $by0 $bz0 $bx0 $by1 $bz0
168                 draw_cyl $bx1 $by1 $bz0 $bx1 $by0 $bz0
169                 draw_cyl $bx0 $by1 $bz0 $bx1 $by1 $bz0
170
171                 draw_cyl $bx0 $by0 $bz1 $bx1 $by0 $bz1
172                 draw_cyl $bx0 $by0 $bz1 $bx0 $by1 $bz1
173                 draw_cyl $bx1 $by1 $bz1 $bx1 $by0 $bz1
174                 draw_cyl $bx0 $by1 $bz1 $bx1 $by1 $bz1
175
176                 draw_cyl $bx0 $by0 $bz1 $bx0 $by0 $bz0
177                 draw_cyl $bx0 $by1 $bz1 $bx0 $by1 $bz0
178                 draw_cyl $bx1 $by0 $bz1 $bx1 $by0 $bz0
179                 draw_cyl $bx1 $by1 $bz1 $bx1 $by1 $bz0
180
181         fi      
182
183         # bonds
184         if [ -n "$bcr" ]; then
185
186                 if [ -z "$x0" ]; then
187
188         cat $file | grep '# \[B\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
189                 draw_bond $x1 $z1 $y1 $x2 $z2 $y2 $bcr
190         done
191
192                 else
193
194                 export x0 y0 z0 x1 y1 z1 bcr
195                 cat $file | grep '# \[B\]' | awk '\
196                 BEGIN {
197                         x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
198                         x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
199                         bcr=ENVIRON["bcr"];
200                 }
201                 {
202                         if(($3>=x0)&&($4>=y0)&&($5>=z0)&&\
203                            ($3<=x1)&&($4<=y1)&&($5<=z1)) {
204                                 print "cylinder {";
205                                 print "<"$3","$5","$4">,";
206                                 print "<"$6","$8","$7">, "bcr;
207                                 print "pigment { color Blue }";
208                                 print "}";
209                         }
210                 }' >> temp.pov
211
212                 fi
213         fi      
214
215         # add camera and light source
216         cat >> temp.pov <<-EOF
217 camera {
218 EOF
219         if [ -n "$ortographic" ]; then  cat >> temp.pov <<-EOF
220 orthographic
221 EOF
222         fi
223         cat >> temp.pov <<-EOF
224 location $camloc
225 look_at <0,0,0>
226 }
227 light_source { <0,100,-100> color White shadowless }
228 EOF
229
230         # mv png
231         $POVRAY temp.pov > /dev/null 2>&1
232         mv temp.png `echo $file | sed 's/\.xyz/\.png/'`
233
234 done
235
236 echo "done"