#!/bin/bash d0=0.0002 #definition of a step multiplicator nmax=11 # number of steps rm curve.a.c2h2 # delete file curve.a.c2h2 if it exists for n in $(eval echo "{1..$nmax}") # loop, where n changes from 1 to 11 (nmax) do delta=`echo \( $n \- 6 \) \* $d0 | bc -l ` # This command performs delta=n-6*d0 # Where "bc" is a linux calculator. # symbol "\" says to bash that next symbol is a text symbol not a command awk -v delta=$delta '{if (($1 == "H" || $1 == "C" )) { if (ind<=1) {printf "%s %10.8f %10.8f %10.8f \n", $1,$2-delta,$3,$4; ind=ind+1} else {printf "%s %10.8f %10.8f %10.8f \n", $1,$2+delta,$3,$4; ind=ind+1} } else {print $0} }' < c2h2.amber.inp > c2h2.$n.inp # awk reads file c2h2.amber.inp line by line and prints output in the file cp2k.1.inp (if n equals 1) # If the firs word of a line is H or C, then x coordinate is decreased (for the first and the second atom) or increased # (for the third and the fourth atom) by the value of "delta" cp2k.popt -i c2h2.$n.inp > c2h2.$n.out # running cp2k dist=`grep -A 4 '&COORD' c2h2.$n.inp | grep ^C | awk '{x[NR]=$2;y[NR]=$3;z[NR]=$4} END {dx=x[1]-x[2]; dy=y[1]-y[2]; dz=z[1]-z[2];print sqrt(dx*dx+dy*dy+dz*dz)}' ` # ^ # reading the cp2k ouput file # and printing line which # contains the world # "&COORD" + 4 lines below # ^ # printing only # the lines # which begins # from C # ^ # NR is the number of current line (in our case it can be only 1 or 2, because there are only two carbon atoms in C2H2) # When awk finished reading the input file it performs directives, which are written in END { ... } # in our case it's simply calculation the distance between two carbon atoms # ^ finally the variable dist is equal to the distance between two carbon atoms grep 'ENERGY|' c2h2.$n.out | grep -v Run | awk -v dist=$dist '{print dist,$9}' >> curve.a.c2h2 # ^ # print lines from the file c2h2.1.inp (if n equals 1) , which contains the word "ENERGY|" # ^ # don't print lines, which contains the word "Run" # ^ # print distance between two atoms and 9th word from the line which correspond to the value of energy in the file curve.a.c2h2 done # finishing the loop mkdir Logs # creating directory Logs mv c2h2.?.inp c2h2.??.inp c2h2.*.out Logs rm RUN* *restart* # removing all the files, which has name starting from "RUN.." or contains word "restart"