added some helper tools for vasp usage
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 8 Jul 2009 13:46:35 +0000 (15:46 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 8 Jul 2009 13:46:35 +0000 (15:46 +0200)
vasp_tools/Makefile [new file with mode: 0644]
vasp_tools/create_lattice.c [new file with mode: 0644]
vasp_tools/e_coh [new file with mode: 0755]
vasp_tools/e_form [new file with mode: 0755]
vasp_tools/outcar2moldyn [new file with mode: 0755]
vasp_tools/ppm2avi [new file with mode: 0755]
vasp_tools/stdvis [new file with mode: 0755]
vasp_tools/visualize [new file with mode: 0755]

diff --git a/vasp_tools/Makefile b/vasp_tools/Makefile
new file mode 100644 (file)
index 0000000..177b5e9
--- /dev/null
@@ -0,0 +1,12 @@
+CC = gcc-4.3
+
+CFLAGS = -Wall -Winline
+CFLAGS += -O3 -march=native -msse2 -mfpmath=sse
+CFLAGS += -g
+
+LDFLAGS = -lm
+
+ALL = create_lattice
+
+all: $(ALL)
+
diff --git a/vasp_tools/create_lattice.c b/vasp_tools/create_lattice.c
new file mode 100644 (file)
index 0000000..5f6cb8d
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * create lattice (for usage in vasp POSCAR file)
+ *
+ * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "../math/math.h"
+
+#define FCC            0x01
+#define DIAMOND                0x02
+#define ZINCBLENDE     0x03
+
+int main(int argc,char **argv) {
+
+       int i,j,k,l,cnt;
+       t_3dvec basis[3];
+       t_3dvec offset;
+       t_3dvec r,n;
+       char type;
+       double zrot;
+
+       if(argc<5) {
+               printf("usage: %s type lx ly lz\n",argv[0]);
+               return -1;
+       }
+
+       type=argv[1][0];
+       type=DIAMOND;
+
+       zrot=0.0;
+       if(argc==6)
+               zrot=atof(argv[5]);
+
+       offset.x=0.25;
+       offset.y=0.25;
+       offset.z=0.25;
+
+       memset(basis,0,3*sizeof(t_3dvec));
+       basis[0].x=0.5;
+       basis[0].y=0.5;
+       basis[1].x=0.5;
+       basis[1].z=0.5;
+       basis[2].y=0.5;
+       basis[2].z=0.5;
+
+       cnt=0;
+       r.x=0.0;
+       for(i=0;i<atoi(argv[2]);i++) {
+               r.y=0.0;
+               for(j=0;j<atoi(argv[3]);j++) {
+                       r.z=0.0;
+                       for(k=0;k<atoi(argv[4]);k++) {
+
+       // first atom
+       printf(" %.2f %.2f %.2f T T T\n",r.x,r.y,r.z);
+       cnt+=1;
+       // face centered atoms
+       for(l=0;l<3;l++) {
+               v3_add(&n,&r,&(basis[l]));
+               printf(" %.2f %.2f %.2f T T T\n",n.x,n.y,n.z);
+               cnt+=1;
+       }
+
+                               r.z+=1.0;
+                       }
+                       r.y+=1.0;
+               }
+               r.x+=1.0;
+       }
+
+       // second fcc lattice
+       if(type==DIAMOND) {
+
+       r.x=0.0;
+       for(i=0;i<atoi(argv[2]);i++) {
+               r.y=0.0;
+               for(j=0;j<atoi(argv[3]);j++) {
+                       r.z=0.0;
+                       for(k=0;k<atoi(argv[4]);k++) {
+
+       // first atom
+       printf(" %.2f %.2f %.2f T T T\n",r.x+0.25,r.y+0.25,r.z+0.25);
+       cnt+=1;
+       // face centered atoms
+       for(l=0;l<3;l++) {
+               v3_add(&n,&r,&(basis[l]));
+               printf(" %.2f %.2f %.2f T T T\n",n.x+0.25,n.y+0.25,n.z+0.25);
+               cnt+=1;
+       }
+
+                               r.z+=1.0;
+                       }
+                       r.y+=1.0;
+               }
+               r.x+=1.0;
+       }
+
+       }
+
+
+       printf("\ntotal: %d ions\n\n",cnt);
+
+       return 0;
+
+}
+               
diff --git a/vasp_tools/e_coh b/vasp_tools/e_coh
new file mode 100755 (executable)
index 0000000..ddd866b
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+sicnt=`grep 'ions per' $1/OUTCAR | awk '{ print $5 }'`
+ccnt=`grep 'ions per' $1/OUTCAR | awk '{ print $6 }'`
+
+((total=sicnt+ccnt))
+
+echo "parsing OUTCAR file ..."
+echo "  Si: $sicnt, C: $ccnt, total: $total"
+
+cnt=0
+tcnt=0
+
+energy=`grep energy\ without $1/OUTCAR | tail -1 | awk '{ print $8 }'`
+
+echo "  total energy: $energy eV"
+echo "$energy $total" | \
+       awk '{ print "  cohesive energy: "$1/$2 " eV" }'
+
+echo
+
diff --git a/vasp_tools/e_form b/vasp_tools/e_form
new file mode 100755 (executable)
index 0000000..5786621
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+echo "## `basename $2` - `basename $1` ##"
+
+e1=`./e_coh $1 | grep cohesive | awk '{ print $5 }'`
+e2=`./e_coh $2 | grep cohesive | awk '{ print $5 }'`
+count=`./e_coh $2 | grep total\: | awk '{ print $6 }'`
+
+echo "$e1 $e2 $count" | \
+       awk '{ print "formation energy: "($2-$1)*$3 " eV" }'
+
+echo
+
diff --git a/vasp_tools/outcar2moldyn b/vasp_tools/outcar2moldyn
new file mode 100755 (executable)
index 0000000..780dd93
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+rm -rf video
+mkdir -p video
+
+sicnt=`grep 'ions per' OUTCAR | awk '{ print $5 }'`
+ccnt=`grep 'ions per' OUTCAR | awk '{ print $6 }'`
+
+((total=sicnt+ccnt))
+
+echo "parsing OUTCAR file ..."
+echo "  Si: $sicnt, C: $ccnt, total: $total"
+
+cnt=0
+tcnt=0
+
+cx=1.0
+cy=1.0
+cz=0.8
+
+sed -n -e '/POSITION/,/total/p' OUTCAR | \
+       grep -v POS | grep -v total | grep -v -- ^\ - | \
+       while read x y z fx fy fz; do
+
+       time=`printf "%05d" $tcnt`
+       echo -en "$tcnt/$cnt "
+       [ "$cnt" = "0" ] && \
+               echo "# P $total $time <$cx,$cy,$cz>" > \
+                       video/atomic_conf_$time.xyz
+
+       type="Si"
+       color="Yellow"
+       force=`echo "sqrt($fx*$fx+$fy*$fy+$fz*$fz)" | bc`
+       if [ $cnt -ge $sicnt ]; then
+               type="C"
+               color="Gray"
+       fi
+       echo "$type $x $y $z $color $force" >> \
+               video/atomic_conf_$time.xyz
+       
+       ((cnt+=1))
+       if [ $cnt -eq $total ]; then
+               cnt=0
+               ((tcnt+=1))
+               echo
+       fi
+done
+
+echo
+
diff --git a/vasp_tools/ppm2avi b/vasp_tools/ppm2avi
new file mode 100755 (executable)
index 0000000..74c8370
--- /dev/null
@@ -0,0 +1,13 @@
+#for i in $1/*.ppm; do
+#      convert $i $1/$(basename $i ppm)png
+#done
+
+MFOPTS="-mf fps=13:type=png"
+#MFOPTS="-mf fps=25:type=png"
+
+OUTFILE=md.avi
+[ -n "$2" ] && OUTFILE=$2
+
+#mencoder mf://$1/*.png -ovc copy -o $1/$OUTFILE >/dev/null 2>&1
+mencoder $MFOPTS mf://$1/*.png -ovc xvid -xvidencopts bitrate=1000 \
+         -o $1/$OUTFILE >/dev/null 2>&1
diff --git a/vasp_tools/stdvis b/vasp_tools/stdvis
new file mode 100755 (executable)
index 0000000..12c7cd6
--- /dev/null
@@ -0,0 +1,14 @@
+if [ -z "$1" ]; then
+       exit
+fi
+
+./visualize -w 640 -h 480 -d $1/video \
+       -nll -1.06 -1.06 -1.06 -fur 2.06 2.06 2.06 \
+       -b 0.0 0.0 0.0 1.0 1.0 1.0 \
+       -c 0.3 -2.5 1.1 -L 0.5 0.5 0.4 \
+       -r 0.6
+
+./ppm2avi $1/video
+
+mplayer $1/video/md.avi
+
diff --git a/vasp_tools/visualize b/vasp_tools/visualize
new file mode 100755 (executable)
index 0000000..7cc4496
--- /dev/null
@@ -0,0 +1,313 @@
+#!/bin/sh
+
+#
+# visualization script
+# author: frank.zirkelbach@physik.uni-augsburg.de
+#
+
+# help function
+draw_cyl() {
+       cat >> temp.pov <<-EOF
+cylinder {
+<$1, $3, $2>, <$4, $6, $5>, 0.05
+pigment { color White }
+}
+EOF
+}
+draw_bond() {
+       cat >> temp.pov <<-EOF
+cylinder {
+<$1, $3, $2>, <$4, $6, $5>, $7
+pigment { color Blue }
+}
+EOF
+}
+
+# defaults
+
+lc=5.429
+directory="doesnt_exist____for_sure"
+width="640"
+height="480"
+radius="0.6"
+x0="-0.6"; y0="-0.6"; z0="-0.6";
+x1="0.6"; y1="0.6"; z1="0.6";
+cx=""; cy=""; cz="";
+lx="0"; ly="-100"; lz="100";
+ortographic=""
+bx0=""; by0=""; bz0="";
+bx1=""; by1=""; bz1="";
+bcr="";
+clx="0"; cly="0"; clz="0";
+extra=0
+
+# parse argv
+
+while [ "$1" ]; do
+       case "$1" in
+               -d)             directory=$2;           shift 2;;
+               -w)             width=$2;               shift 2;;
+               -h)             height=$2;              shift 2;;
+               -r)             radius=$2;              shift 2;;
+               -nll)           x0=$2; y0=$3; z0=$4;    shift 4;;
+               -fur)           x1=$2; y1=$3; z1=$4;    shift 4;;
+               -c)             cx=$2; cy=$3; cz=$4;    shift 4;;
+               -L)             clx=$2; cly=$3; clz=$4; shift 4;;
+               -l)             lx=$2; ly=$3; lz=$4;    shift 4;;
+               -o)             ortographic=1;          shift 1;;
+               -b)             bx0=$2; by0=$3; bz0=$4;
+                               bx1=$5; by1=$6; bz1=$7; shift 7;;
+               -B)             bcr=$2;                 shift 2;;
+               -C)             lc=$2;                  shift 2;;
+               -e)             extra=1;                shift 1;;
+               *)
+                               echo "options:"
+                               echo "########"
+                               echo "directory to progress:"
+                               echo "  -d <directory> (mandatory)"
+                               echo "png dim:"
+                               echo "  -w <width>"
+                               echo "  -h <height>"
+                               echo "atom size:"
+                               echo "  -r <radius>"
+                               echo "  -B <bond cylinder radius>"
+                               echo "unit cell:"
+                               echo "  -C <lattice constant>"
+                               echo "visualization volume:"
+                               echo "  -nll <x> <y> <z> (near lower left)"
+                               echo "  -fur <x> <y> <z> (far upper right)"
+                               echo "  -o (ortographic)"
+                               echo "bounding box:"
+                               echo "  -b <x0> <y0> <z0> <x1> <y1> <z1>"
+                               echo "povray:"
+                               echo "  -c <x> <y> <z> (camera position)"
+                               echo "  -L <x> <y> <z> (camera look)"
+                               echo "  -l <x> <y> <z> (light source)"
+                               exit 1;;
+       esac
+done
+
+# calculation from lattic eunits to angstroms
+
+[ "$lc" = "sic" ] && lc=4.359
+[ "$lc" = "si" ] && lc=5.429
+[ "$lc" = "c" ] && lc=3.566
+
+#offset=`echo 0.125 \* $lc | bc`
+offset=0.0
+
+x0=`echo $x0 \* $lc + $offset | bc`
+y0=`echo $y0 \* $lc + $offset | bc`
+z0=`echo $z0 \* $lc + $offset | bc`
+x1=`echo $x1 \* $lc + $offset | bc`
+y1=`echo $y1 \* $lc + $offset | bc`
+z1=`echo $z1 \* $lc + $offset | bc`
+
+clx=`echo $clx \* $lc + $offset | bc`
+cly=`echo $cly \* $lc + $offset | bc`
+clz=`echo $clz \* $lc + $offset | bc`
+
+if [ -n "$cx" -a -n "$cy" -a -n "$cz" ]; then
+       cx=`echo $cx \* $lc + $offset | bc`
+       cy=`echo $cy \* $lc + $offset | bc`
+       cz=`echo $cz \* $lc + $offset | bc`
+fi
+
+if [ -n "$bx0" ]; then
+       bx0=`echo $bx0 \* $lc + $offset | bc`
+       by0=`echo $by0 \* $lc + $offset | bc`
+       bz0=`echo $bz0 \* $lc + $offset | bc`
+       bx1=`echo $bx1 \* $lc + $offset | bc`
+       by1=`echo $by1 \* $lc + $offset | bc`
+       bz1=`echo $bz1 \* $lc + $offset | bc`
+fi
+
+# povray command
+
+POVRAY="povray -W${width} -H${height} -d" 
+
+# convert options
+
+COPTS="-font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
+COPTS="$COPTS -depth 8 -fill white -stroke blue -pointsize 24"
+
+# do it ...
+
+if [ -d $directory ]; then
+       filesource=$directory/atomic_conf_*.xyz
+fi
+
+if [ -f $directory ]; then
+       filesource=$directory
+fi
+
+for file in $filesource; do
+
+       cat > temp.pov <<-EOF
+#include "colors.inc"
+#include "textures.inc"
+#include "shapes.inc"
+#include "glass.inc"
+#include "metals.inc"
+#include "woods.inc"
+#include "stones.inc"
+EOF
+
+       # meta info
+       count=`grep '# \[P\]' $file | awk '{ print $3 }'`
+       time=`grep '# \[P\]' $file | awk '{ print $4 }'`
+       camloc=`grep '# \[P\]' $file | awk '{ print $5 }'`
+       [ -n "$cx" -a -n "$cy" -a -n "$cz" ] && camloc="<$cx,$cz,$cy>"
+
+       # atoms
+#echo "-----> $x0 $y0 $z0 $x1 $y1 $z1 <-----"
+       if [ -n "$x0" ]; then
+               export x0 y0 z0 x1 y1 z1 radius extra
+               cat $file | grep -v '#' | awk '\
+               BEGIN {
+                       x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
+                       x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
+                       radius=ENVIRON["radius"]; extra=ENVIRON["extra"];
+               }
+               {
+#                      print "----> " x0 " " y0 " " z0 " " $2 " " $3 " " $4
+#                      print "----> " x1 " " y1 " " z1 " " $2 " " $3 " " $4
+#if(($2>=x0)) print $2 " groesser " x0
+#if(($3>=y0)) print $3 " groesser " y0
+#if(($4>=z0)) print $4 " groesser " z0
+#if(($2<=x1)) print $2 " kleiner " x1
+#if(($3<=y1)) print $3 " kleiner " y1
+#if(($4<=z1)) print $4 " kleiner " z1
+                       if(($2>=x0)&&($3>=y0)&&($4>=z0)&&\
+                          ($2<=x1)&&($3<=y1)&&($4<=z1)) {
+#                      if(($2<=x0)&&($3<=y0)&&($4<=z0)&&\
+#                         ($2>=x1)&&($3>=y1)&&($4>=z1)) {
+                               print "sphere { <"$2","$4","$3">, "radius" ";
+                               if(extra)
+               print "texture { pigment { color rgb<"$6/4.4",0,"1-$6/4.4"> } ";
+                               else
+               print "texture { pigment { color "$5" } ";
+                               print "finish { phong 1 metallic } } }";
+                       }
+               }' >> temp.pov
+       else
+               cat $file | grep -v '#' | while read name x y z color temp; do
+                       cat >> temp.pov <<-EOF
+sphere {
+<$x, $z, $y>, $radius
+texture {
+pigment { color $color }
+finish {
+phong 1
+metallic
+}
+}
+}
+EOF
+               done
+       fi
+
+       # boundaries
+       if [ -z "$bx0" ]; then
+
+       #if [ -z "$x0" ]; then
+
+       cat $file | grep '# \[D\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
+               draw_cyl $x1 $y1 $z1 $x2 $y2 $z2 0.05
+       done
+
+       #else
+
+               # manually drawing the 3x4 boundaries ...
+#              draw_cyl $x0 $y0 $z0 $x1 $y0 $z0
+#              draw_cyl $x0 $y0 $z0 $x0 $y1 $z0
+#              draw_cyl $x1 $y1 $z0 $x1 $y0 $z0
+#              draw_cyl $x0 $y1 $z0 $x1 $y1 $z0
+
+#              draw_cyl $x0 $y0 $z1 $x1 $y0 $z1
+#              draw_cyl $x0 $y0 $z1 $x0 $y1 $z1
+#              draw_cyl $x1 $y1 $z1 $x1 $y0 $z1
+#              draw_cyl $x0 $y1 $z1 $x1 $y1 $z1
+
+#              draw_cyl $x0 $y0 $z1 $x0 $y0 $z0
+#              draw_cyl $x0 $y1 $z1 $x0 $y1 $z0
+#              draw_cyl $x1 $y0 $z1 $x1 $y0 $z0
+#              draw_cyl $x1 $y1 $z1 $x1 $y1 $z0
+#      fi
+
+       else
+
+               # manually drawing the 3x4 boundaries specified by argv ...
+               draw_cyl $bx0 $by0 $bz0 $bx1 $by0 $bz0
+               draw_cyl $bx0 $by0 $bz0 $bx0 $by1 $bz0
+               draw_cyl $bx1 $by1 $bz0 $bx1 $by0 $bz0
+               draw_cyl $bx0 $by1 $bz0 $bx1 $by1 $bz0
+
+               draw_cyl $bx0 $by0 $bz1 $bx1 $by0 $bz1
+               draw_cyl $bx0 $by0 $bz1 $bx0 $by1 $bz1
+               draw_cyl $bx1 $by1 $bz1 $bx1 $by0 $bz1
+               draw_cyl $bx0 $by1 $bz1 $bx1 $by1 $bz1
+
+               draw_cyl $bx0 $by0 $bz1 $bx0 $by0 $bz0
+               draw_cyl $bx0 $by1 $bz1 $bx0 $by1 $bz0
+               draw_cyl $bx1 $by0 $bz1 $bx1 $by0 $bz0
+               draw_cyl $bx1 $by1 $bz1 $bx1 $by1 $bz0
+
+       fi      
+
+       # bonds
+       if [ -n "$bcr" ]; then
+
+               if [ -z "$x0" ]; then
+
+       cat $file | grep '# \[B\]' | while read foo bar x1 y1 z1 x2 y2 z2 ; do
+               draw_bond $x1 $z1 $y1 $x2 $z2 $y2 $bcr
+       done
+
+               else
+
+               export x0 y0 z0 x1 y1 z1 bcr
+               cat $file | grep '# \[B\]' | awk '\
+               BEGIN {
+                       x0=ENVIRON["x0"]; y0=ENVIRON["y0"]; z0=ENVIRON["z0"];
+                       x1=ENVIRON["x1"]; y1=ENVIRON["y1"]; z1=ENVIRON["z1"];
+                       bcr=ENVIRON["bcr"];
+               }
+               {
+                       if(($3>=x0)&&($4>=y0)&&($5>=z0)&&\
+                          ($3<=x1)&&($4<=y1)&&($5<=z1)) {
+                               print "cylinder {";
+                               print "<"$3","$5","$4">,";
+                               print "<"$6","$8","$7">, "bcr;
+                               print "pigment { color Blue }";
+                               print "}";
+                       }
+               }' >> temp.pov
+
+               fi
+       fi      
+
+       # add camera and light source
+       cat >> temp.pov <<-EOF
+camera {
+EOF
+       if [ -n "$ortographic" ]; then  cat >> temp.pov <<-EOF
+orthographic
+EOF
+       fi
+       cat >> temp.pov <<-EOF
+location $camloc
+look_at <$clx,$clz,$clz>
+}
+light_source { <0,100,-100> color White shadowless }
+EOF
+
+       # mv png
+       $POVRAY temp.pov > /dev/null 2>&1
+       time=`basename $file | awk -F. '{ print $1 }' | awk -F_ '{ print $3 }'`
+       convert $COPTS -draw "text 5,20 't = $time fs'" temp.png temp.png
+       mv temp.png `echo $file | sed 's/\.xyz/\.png/'`
+
+done
+
+echo "done"