Advertisement
chiara_cara

Untitled

May 16th, 2017
1,438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 1.96 KB | None | 0 0
  1. #
  2. # interpolate two POSCAR files
  3. # POSCAR files must be concated before passing them to
  4. # this awk script
  5. # first line of the first POSCAR file should be
  6. # rep number_of_replicase
  7. # if there is any line containing the term center
  8. # differences in the center of mass will be removed
  9. #
  10. file=$1
  11. if [ ! -x $file ]
  12. then
  13.   usage: interpolatePOS POSCAR1_POSCAR2
  14. fi
  15.  
  16. awk <$file '
  17. BEGIN { rep=8; center=0 }
  18. /center/ { center=1}
  19. /rep/ { rep=$2 }
  20.  { line=line+1
  21.    if ( second != 1 ) {
  22.        if ( line == 6 )  {
  23.           lines = $1 + $2 + $3 + 7
  24.           print "found ",lines," ions"
  25.           head[line] = $0
  26.        } else if ( line < 8 )
  27.           head[line] = $0
  28.        else
  29.           {
  30.              x[line-7] = $1 ; y[line-7] = $2 ; z[line-7] = $3
  31.              if (line==lines) {
  32.                    line=0; second=1;
  33.                    print "first set read"
  34.              }
  35.           }
  36.     } else {
  37.        if ( line >= 8 )
  38.           {
  39.               x2[line-7] = $1; y2[line-7] = $2 ; z2[line-7] = $3  }
  40.              if (line==lines) {
  41.                    print "second set read"
  42.              }
  43.     }
  44. }
  45. END  {
  46.    lines=lines-7
  47.    for ( line=1; line<=lines ; line ++ )  {
  48.     cx1=cx1+ x[line] ; cy1=cy1+ y[line] ; cz1=cz1+ z[line]
  49.     cx2=cx2+ x2[line]; cy2=cy2+ y2[line]; cz2=cz2+ z2[line]
  50.    }
  51.    if (center) {
  52.      cx=(cx2-cx1)/lines
  53.      cy=(cy2-cy1)/lines
  54.      cz=(cz2-cz1)/lines
  55.      print "center of mass for second cell will be shifted by",cx,cy,cz
  56.    }
  57.  
  58.    for ( i=0; i<rep ; i++ ) {
  59.        file="0" i "/POSCAR"
  60.        print "writing to " file
  61.        for (line=1; line<=7 ; line++ )
  62.           print head[line]  >file
  63.        for ( line=1; line<=lines ; line ++ )  {
  64.           b=i/(rep-1)
  65.           a=(rep-1-i)/(rep-1)
  66.           dx=a*x[line] + b*(x2[line]-cx)
  67.           dy=a*y[line] + b*(y2[line]-cy)
  68.           dz=a*z[line] + b*(z2[line]-cz)
  69.  
  70.           printf " %10.6f  %10.6f %10.6f\n",dx,dy,dz >file
  71.        }
  72.    }
  73. }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement