Jump to content

Mod:Hunt Research Group:model freq script

From ChemWiki

data script

  • script to extract data and print in a format to paste into the template excel sheet used for the database
  • simply copy and paste this script into a file get_data.py
  • then run with "python getdata.py file_name.log"
#
# getdata.py
#
# python3 script to 
#    extract key data from gaussian log files for input into 
#    excell spreadsheets for our database
#
# to run the script type
#    python3 getdata.py file.log
#
import sys
filein=str(sys.argv[1])
f = open(filein,'r')

enstring = 'SCF Done'
gstring = 'Sum of electronic and thermal Free Energies='
hstring = 'Sum of electronic and thermal Enthalpies='
zpestring = 'Zero-point correction='
freqstring = 'Low frequencies ---'
freqlist = []

line=f.readline()
while line:
        if enstring in line:
                enval = line[(len(enstring)+16):(len(enstring)+31)]

        if gstring in line:
                gval = line[(len(gstring)+9):(len(gstring)+21)]

        if hstring in line:
                hval = line[(len(hstring)+12):(len(hstring)+24)]

        if zpestring in line:
                zpeval = line[(len(zpestring)+27):(len(zpestring)+36)]

        pos = line.find(freqstring)
        if pos != -1:
                freqval = line[(len(freqstring)+1):]
                freqs = freqval.split()
                freqlist = freqlist + freqs;

        line=f.readline()
#endwhile

newval=float(hval)-float(gval)
newval=str(round(newval,10))

f.close()

s='input file is '
print('\n {0:}{1:}'.format(s,filein))

se='SCF energy'
sg='Gibbs free energy'
sh='Enthalpy'
ss='Entropy'
sz='ZPE'
print(' {0:}={1:} \n {2:}={3:} \n {4:}={5:} \n {6:}={7:} \n {8:}={9:}'.format \
     (se,enval,sg,gval,sh,hval,ss,newval,sz,zpeval))

sf='low modes:'
print(' {0:} {1[0]:}, {1[1]:}, {1[2]:}, {1[3]:}, {1[4]:}, {1[5]:}'.format(sf,freqlist))

s='suitable for copying to excel:'
print('{0:} \n'.format(s))
print('{0:}, , ,{1:}, ,{2:}, ,{3:}, ,{4:}, ,{5:},{6[0]:},{6[1]:},{6[2]:},{6[3]:},{6[4]:},{6[5]:}'.format(filein,enval,gval,hval,newval,zpeval,freqlist))

# finish up
f.close()
sys.exit()