Mod:Hunt Research Group:model freq script

From wiki
Jump to navigation Jump to search

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 getdata.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
import os
#
# check to see if the user has used the .log extenion or not
# find returns -1 if the sub-string is not found, or the index of where the sub-string starts
# we cut out the .log part if .log is found
infile=str(sys.argv[1])
i_infile=infile.find('.log')
if (i_infile == -1):
  base=infile
else:
  base=infile[:i_infile]
#endif
log_file=base+'.log'
f = open(log_file,'r')

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

line=f.readline()
while line:
        if scfstring in line:
           tmp=line.rstrip().split()
           enscf=float(tmp[4])
#           print('{0:} \n'.format(tmp[4]))

        if zpestring in line:
           tmp=line.rstrip().split()
           zpeval = float(tmp[2]) 
#           print('{0:} \n'.format(tmp[2]))

        if enzpestring in line:
           tmp=line.rstrip().split()
           enzpeval = float(tmp[6]) 
#           print('{0:} \n'.format(tmp[6]))

        if hstring in line:
           tmp=line.rstrip().split()
           hval = float(tmp[6]) 
#           print('{0:} \n'.format(tmp[6]))

        if gstring in line:
           tmp=line.rstrip().split()
           gval = float(tmp[7]) 
#           print('{0:} \n'.format(tmp[7]))

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

        line=f.readline()
#endwhile

entval=hval-gval
entval=round(entval,10)
enscf2=enzpeval-zpeval
enscf2=round(enscf2,10)

f.close()

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

se='SCF energy'
sze='SCF+ZPE energy'
sg='Gibbs free energy'
sh='Enthalpy'
ss='Entropy'
sz='ZPE'
#enscf = scf energy
#zpeval = ZPE correction
#enzpeval = scf+ZPE
#hval = H
#gval = G
#entval = TS = G-H
#enscf2 = scf = SCF-(SCF+ZPE)

print(' {0:}={1:}, \n {2:}={3:} \n {4:}={5:} \n {6:}={7:} \n {8:}={9:} \n {10:}={11:}'.format \
     (se,enscf2,sg,gval,sh,hval,ss,entval,sz,zpeval,sze,enzpeval))

sf=' low modes:'
sf1=' no modes!'
sf2=' linear molecule modes:'
num_modes=len(freqlist)
if len(freqlist) < 4:
 print('{0:}'.format(sf1))
 for i in range (3,6):
   freqlist.append(0.00)
elif len(freqlist) < 6:
 print('{0:}'.format(sf2))
 freqlist.append(0.00)
else:
 print(' {0:} {1[0]:}, {1[1]:}, {1[2]:}, {1[3]:}, {1[4]:}, {1[5]:}'.format(sf,freqlist))

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

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