Torben's Awk Scripts

Usage: script filename > output_file

coord2xyz.awk
This awk script transforms a Turbomole coordinate file (in Bohr) to an xyz file (in Å).

#!/bin/awk -f

BEGIN {i=0;j=0}
$4~/[a-z]/ {
    if(j==1) {
        x[i]=$1; y[i]=$2; z[i]=$3; atm[i]=$4; i++
        }
    }
$1~/^\$/ {j=0}
$1~/coord/ {j=1}
END {
    printf ("%s\n\n", i)
    for(k=0;k<i;k++) {
        printf ("%3s   %16.12f   %16.12f   %16.12f\n",
        atm[k],
        x[k]*0.529177249,
        y[k]*0.529177249,
        z[k]*0.529177249)
        }
    }


get_chg.awk
This awk script strips the eps charges from a G98 output file. The atomic charges are printed on individual lines with one preceding blank line. The intention is that this output should be pasted with a pdb file created with mimic or xyz2pdb.awk to produce a pdb file with charges.

#!/bin/awk -f

BEGIN {i=0}
/------------/ {i=0}
    {if(i==1){
        if(NF==1){print ""}
        if(NF==3){printf ("%7.4f\n", $3)}
        }
    }
/Charges from ESP fit/ {i=1}


xyz2pdb.awk
This awk script transforms an xyz file to a pdb file with one title line.

#!/bin/awk -f

BEGIN {i=0}
NR==1 {print "REMARK Created from xyz file with xyz2pdb.awk"}
NF==4 {
   i++
   printf ("ATOM   %4d %2s   ???     1     %7.3f %7.3f %7.3f\n",
   i,$1,$2,$3,$4)
   }
END {print "END"}


remwat.awk
I use this awk script to remove all but a selected few waters from a pdb file (with charges). The array watkeep must contain the residue numbers of the waters you want to keep!

#!/bin/awk -f

{
watkeep[1]=res_nr
watkeep[2]=res_nr
:
}

$0!~/WAT/ {print $0}
$0~/WAT/ {
   printstate="off"
   for( i in watkeep ) {
      if( $(NF-4) == watkeep[i] ) printstate="on"
      }
   if( printstate=="on" ) print $0
   }


remqm.awk
This awk script removes the atoms, specified in the qm array, from a pqr file.

#!/bin/awk -f

{
qm[1]=atm_nr
qm[2]=atm_nr
:
}

{
   printstate="on"
   for( i in qm ) {
      if( $2 == qm[i] ) printstate="off"
   }
   if( printstate=="on" ) print $0
}


prep_pqr.awk
This script assigns unique atom labels to all atoms in a pqr file.

#!/bin/awk -f

$1!~/ATOM/ {print $0}
$1~/ATOM/ {
    printf("%4s   %4s %-5s %3s   %3s     %7.3f %7.3f %7.3f %7.4f  %4.2f\n",
    $1, $2, $3$2"'", $4, $5, $6, $7, $8, $9, $10)
    }


get_sol.awk
This script extracts important info from solinprot output files.

#!/bin/awk -f

# Takes an output file from solinprot as input.
# Returns the specifications for the finest grid level
# and all the energies.

BEGIN {j=0}
/Finest level/ || /Only one level/ {
    if (j==0) {
        print $(NF-1), $NF
	print "Inter:   React:   Sol:"
    }
j++
}
NR==1 {
    print $NF
}
$1 ~ /SOLVATION/ {
    sol[j]=$6
}
$1 ~ /Interaction/ {
    inter[j]=$8
}
$1 ~ /Reaction/ {
    react[j]=$7
}
END {
    for(l=1;l<=j;l++) {
        print inter[l], react[l], sol[l]
    }
}