Difference between revisions of "Mod:Hunt Research Group:model freq script"
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 | + | *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 | ||
| − | + | import os | |
| − | f = open( | + | # |
| + | # 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=' | gstring = 'Sum of electronic and thermal Free Energies=' | ||
| − | |||
| − | |||
freqstring = 'Low frequencies ---' | freqstring = 'Low frequencies ---' | ||
freqlist = [] | freqlist = [] | ||
| Line 27: | Line 40: | ||
line=f.readline() | line=f.readline() | ||
while line: | while line: | ||
| − | if | + | if scfstring in line: |
| − | + | tmp=line.rstrip().split() | |
| + | enscf=float(tmp[4]) | ||
| + | # print('{0:} \n'.format(tmp[4])) | ||
| − | if | + | 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: | if hstring in line: | ||
| − | + | tmp=line.rstrip().split() | |
| + | hval = float(tmp[6]) | ||
| + | # print('{0:} \n'.format(tmp[6])) | ||
| − | if | + | if gstring in line: |
| − | + | 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 | ||
| − | + | entval=hval-gval | |
| − | + | 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, | + | 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, | + | #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:} | + | print('{0:}'.format(s)) |
| − | print('{0:} | + | 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()