This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
type "python read.py" to use | |
This program finds the last heat of formation in all GAMESS log files | |
for semiempirical geometry optimizations | |
""" | |
import string | |
from glob import glob | |
for filename in glob("/home/user/*.log"): | |
f = open(filename,'r') | |
while 1: | |
line = f.readline() # read a line from he file | |
if not line: break # if end-of-file: quit | |
words = string.split(line) # split line into words | |
if len(words) < 1: | |
continue | |
if words[0] == 'HEAT': | |
heat = words[-2] | |
print filename, heat |
Jimmy ran many PM6-D3H+ geometry optimizations using different starting geometries. Typing "grep EQUILIBRIUM *.log" showed that they had all converged, but how to extract the heat of formation on the optimized geometry? This python program does the trick. It finds the last heat of formation in each file or, more precisely, it finds the second to last "word" in the last line where the first word is HEAT.
Update 2015.10.03.
1. Apologies to +Jimmy Charnley Kromann for the poor formulation. Jimmy ran the calculations, I wrote the script. After the post came online he was immediately teased mercilessly by his so-called friends for writing such crappy code. That's on me.
2. As +Anders Steen Christensen pointed out in the comments this can be done in one line using Bash: "for f in *.log; do tac $f | grep -m1 HEAT; done"
3. If you want to do it in Fortran +Lars Bratholm suggested the following code

This work is licensed under a Creative Commons Attribution 4.0
Update 2015.10.03.
1. Apologies to +Jimmy Charnley Kromann for the poor formulation. Jimmy ran the calculations, I wrote the script. After the post came online he was immediately teased mercilessly by his so-called friends for writing such crappy code. That's on me.
2. As +Anders Steen Christensen pointed out in the comments this can be done in one line using Bash: "for f in *.log; do tac $f | grep -m1 HEAT; done"
3. If you want to do it in Fortran +Lars Bratholm suggested the following code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
type "python readv2.py *.log" to use | |
This program finds the last heat of formation in all GAMESS log files | |
for semiempirical geometry optimizations | |
""" | |
import sys | |
for filename in sys.argv[1:]: | |
for line in reversed(open(filename,'r').readlines()): | |
words = line.split() # split line into words | |
if len(words) < 1: | |
continue | |
if words[0] == 'HEAT': | |
heat = words[-2] | |
print filename, heat | |
break |
This work is licensed under a Creative Commons Attribution 4.0
No comments:
Post a Comment