Skip to content

Instantly share code, notes, and snippets.

@rwest
Created October 15, 2009 22:25
Show Gist options
  • Save rwest/211348 to your computer and use it in GitHub Desktop.
Save rwest/211348 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
"""Extract cartesian geometries from gaussian log files using openbabel.
Reads all files that end '.log' in the current working directory.
Puts corresponding .mol files in the 'Geometries' subdirectory.
Created by Richard West on 2009-10-15.
Copyright (c) 2009 MIT. All rights reserved.
"""
import sys
import os
import pybel
import re
if __name__ == '__main__':
outfolder='Geometries'
(os.path.exists(outfolder) and os.path.isdir(outfolder)) or os.mkdir(outfolder)
finder = re.compile('.*\.log')
for possible in os.listdir('.'):
if finder.match(possible):
filename=possible
try:
reader = pybel.readfile('g03',filename)
try:
molecule = reader.next()
finally:
reader.close()
outname = os.path.join(outfolder,filename+'.mol')
molecule.write(format='mol',filename=outname)
except:
print "failed to read",possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment