Difference between revisions of "Mod:Hunt Research Group:model freq script"

From wiki
Jump to navigation Jump to search
(Created page with "=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_dat...")
 
 
Line 1: Line 1:
 
=data script=
 
=data script=
 
*script to extract data and print in a format to paste into the template excel sheet used for the database
 
*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
+
*simply copy and paste this script into a file getdata.py
 
*then run with "python getdata.py file_name.log"  
 
*then run with "python getdata.py file_name.log"  
 
<pre>
 
<pre>
Line 15: Line 15:
 
#
 
#
 
import sys
 
import sys
filein=str(sys.argv[1])
+
import os
f = open(filein,'r')
+
#
 +
# 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')
  
enstring = 'SCF Done'
+
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='
 
gstring = 'Sum of electronic and thermal Free Energies='
hstring = 'Sum of electronic and thermal Enthalpies='
 
zpestring = 'Zero-point correction='
 
 
freqstring = 'Low frequencies ---'
 
freqstring = 'Low frequencies ---'
 
freqlist = []
 
freqlist = []
Line 27: Line 40:
 
line=f.readline()
 
line=f.readline()
 
while line:
 
while line:
         if enstring in line:
+
         if scfstring in line:
                enval = line[(len(enstring)+16):(len(enstring)+31)]
+
          tmp=line.rstrip().split()
 +
          enscf=float(tmp[4])
 +
#          print('{0:} \n'.format(tmp[4]))
  
         if gstring in line:
+
         if zpestring in line:
                gval = line[(len(gstring)+9):(len(gstring)+21)]
+
          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:
 
         if hstring in line:
                hval = line[(len(hstring)+12):(len(hstring)+24)]
+
          tmp=line.rstrip().split()
 +
          hval = float(tmp[6])  
 +
#          print('{0:} \n'.format(tmp[6]))
  
         if zpestring in line:
+
         if gstring in line:
                zpeval = line[(len(zpestring)+27):(len(zpestring)+36)]
+
          tmp=line.rstrip().split()
 +
          gval = float(tmp[7])  
 +
#          print('{0:} \n'.format(tmp[7]))
  
 
         pos = line.find(freqstring)
 
         pos = line.find(freqstring)
Line 48: Line 74:
 
#endwhile
 
#endwhile
  
newval=float(hval)-float(gval)
+
entval=hval-gval
newval=str(round(newval,10))
+
entval=round(entval,10)
 +
enscf2=enzpeval-zpeval
 +
enscf2=round(enscf2,10)
  
 
f.close()
 
f.close()
  
 
s='input file is '
 
s='input file is '
print('\n {0:}{1:}'.format(s,filein))
+
print('\n {0:}{1:}'.format(s,log_file))
  
 
se='SCF energy'
 
se='SCF energy'
 +
sze='SCF+ZPE energy'
 
sg='Gibbs free energy'
 
sg='Gibbs free energy'
 
sh='Enthalpy'
 
sh='Enthalpy'
 
ss='Entropy'
 
ss='Entropy'
 
sz='ZPE'
 
sz='ZPE'
print(' {0:}={1:} \n {2:}={3:} \n {4:}={5:} \n {6:}={7:} \n {8:}={9:}'.format \
+
#enscf = scf energy
     (se,enval,sg,gval,sh,hval,ss,newval,sz,zpeval))
+
#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:'
+
sf=' low modes:'
print(' {0:} {1[0]:}, {1[1]:}, {1[2]:}, {1[3]:}, {1[4]:}, {1[5]:}'.format(sf,freqlist))
+
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='suitable for copying to excel:'
+
s='\n suitable for copying to excel:'
print('{0:} \n'.format(s))
+
print('{0:}'.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))
+
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
 
# finish up

Latest revision as of 08:05, 18 December 2024

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()