Skip to content

Instantly share code, notes, and snippets.

@SeanMcGrath
Created April 6, 2015 20:41
Show Gist options
  • Save SeanMcGrath/d08179fad237faa65fae to your computer and use it in GitHub Desktop.
Save SeanMcGrath/d08179fad237faa65fae to your computer and use it in GitHub Desktop.
Create a .csv file containing the distance matrix of an optimized molecule from a Gaussian output file.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment