Skip to content

Instantly share code, notes, and snippets.

@SeanMcGrath
Created April 6, 2015 20:41
Show Gist options
  • Select an option

  • Save SeanMcGrath/d08179fad237faa65fae to your computer and use it in GitHub Desktop.

Select an option

Save SeanMcGrath/d08179fad237faa65fae to your computer and use it in GitHub Desktop.

Revisions

  1. Sean McGrath renamed this gist Apr 6, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Sean McGrath created this gist Apr 6, 2015.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/usr/bin/env bash
    # Generates a standardized table of bond lengths and bond angles
    # from a gaussian .log file.

    if [[ $# > 0 ]]
    then
    # Find distance Matrix
    awk '/^ *1 *2 *3 *4 *5 *$/ {p=1}; p; /Stoich/ {p=0}' $1 |
    # Extract lines with distance data
    egrep '^[ \t]*[0-9]+[ \t]*[A-Z][ \t]*([-+]?[0-9]*\.?[0-9]+[ \t]*)' |
    # Build 2D distance array with awk
    awk '
    BEGIN {
    old = 0
    offset = 0
    }
    {
    col = 0
    current = $1
    if (current < old){
    offset = offset + 5
    }
    if (current == 1){
    offset = 0
    }
    while (col++ < NF-2) {
    distances[current][col+offset] = $(col+2)
    }
    old = current
    }
    END{ for(i in distances){
    for(j=1; j <= length(distances[i]); j++){
    {printf "%f,", distances[i][j]}
    }
    print ""
    }
    }
    ' | awk '{ print length, $0 }' | sort -n | awk '{$1=""; print $0}' #Sort by line length
    else
    echo 'Enter a Gaussian .log file to parse'
    fi