Difference between revisions of "Mod:Hunt Research Group:model freq script2"
Jump to navigation
Jump to search
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| − | =data | + | =Extract thermodynamic data and low frequencies from all the log files in a folder to a csv file for the database= |
| − | *script to extract data and directly produce a csv file that can be opened in MS Excel. It runs and uses all the log files (*.log) in the current directory. | + | *Here is a script to extract data from all the log files in a folder and directly produce a csv file that can be opened in MS Excel. It runs and uses all the log files (*.log) in the current directory. |
| − | *simply copy and paste this script into a file get_frequencies_data.py | + | *To use, simply copy and paste this script into a file get_frequencies_data.py |
| − | * | + | *Then run the file in any folder with the command "python3 get_frequencies_data.py" |
| + | *Alternatively, you can add the script to your PATH to call it anywhere. | ||
<pre> | <pre> | ||
| − | import glob | + | import glob, os, sys, csv |
| − | |||
| − | |||
| − | |||
print("#=====================================================================================#") | print("#=====================================================================================#") | ||
print("#-------------------------------------------------------------------------------------#") | print("#-------------------------------------------------------------------------------------#") | ||
| − | print("# A Script to Extract | + | print("# A Script to Extract SCF E, ΔG, ΔH, TΔS, and ZPE from Gaussian Output Files #") |
print("#-------------------------------------------------------------------------------------#") | print("#-------------------------------------------------------------------------------------#") | ||
print("#=====================================================================================#") | print("#=====================================================================================#") | ||
| Line 26: | Line 24: | ||
Zero_point_energy = "--NOT FOUND--" | Zero_point_energy = "--NOT FOUND--" | ||
TDS = "--NOT FOUND--" | TDS = "--NOT FOUND--" | ||
| + | delta_E = ' ' | ||
SCF_E_kJ = "--NOT FOUND--" | SCF_E_kJ = "--NOT FOUND--" | ||
Gibbs_E_kJ = "--NOT FOUND--" | Gibbs_E_kJ = "--NOT FOUND--" | ||
| Line 64: | Line 63: | ||
LF06 = complete_line[8] | LF06 = complete_line[8] | ||
found_low_frequencies = True | found_low_frequencies = True | ||
| − | return [filename, SCF_Energy, SCF_E_kJ, Gibbs_Energy, Gibbs_E_kJ, Rxn_Enthalpy_H, Enthalpy_of_Rxn_kJ, round(float(Rxn_Enthalpy_H) - float(Gibbs_Energy),10), round((float(Rxn_Enthalpy_H) - float(Gibbs_Energy))*2625.50,10), Zero_point_energy, float(SCF_Energy)+float(Zero_point_energy), (float(SCF_Energy)+float(Zero_point_energy))*2625.50, LF01, LF02, LF03, LF04, LF05, LF06] | + | return [filename, SCF_Energy, SCF_E_kJ, delta_E, Gibbs_Energy, Gibbs_E_kJ, Rxn_Enthalpy_H, Enthalpy_of_Rxn_kJ, round(float(Rxn_Enthalpy_H) - float(Gibbs_Energy),10), round((float(Rxn_Enthalpy_H) - float(Gibbs_Energy))*2625.50,10), Zero_point_energy, float(SCF_Energy)+float(Zero_point_energy), (float(SCF_Energy)+float(Zero_point_energy))*2625.50, LF01, LF02, LF03, LF04, LF05, LF06] |
#---------- End of Function ----------# | #---------- End of Function ----------# | ||
| Line 70: | Line 69: | ||
#input_files = input('Enter the names of input files or a range (e.g. *.log): ') | #input_files = input('Enter the names of input files or a range (e.g. *.log): ') | ||
input_files = '*.log' | input_files = '*.log' | ||
| − | Final_Energies_List = [['File Name', 'SCF Energy (a.u.)', u'Δ'+'E ( | + | Final_Energies_List = [['File Name', 'SCF Energy (a.u.)', 'SCF Energy (KJ/mol)', u'Δ'+'E (kJ/mol)' , 'G (a.u.)', 'G (KJ/mol)', 'H (a.u)', 'H (KJ/mol)', 'T'+u'Δ'+'S (a.u)', 'T'+u'Δ'+'S (kJ/mol)', 'ZPE (a.u.)', 'E+ZPE (a.u.)', 'E+ZPE (kJ/mol)', 'Low Frequencies', ' ', ' ', ' ', ' ', ' ']] # A list which will contain all the data from all log files |
#-------------------------------------------------------------------------------------------------------------------------# | #-------------------------------------------------------------------------------------------------------------------------# | ||
| Line 85: | Line 84: | ||
Final_Energies_List.append(SCF_and_Gibbs_Energy(files))''' | Final_Energies_List.append(SCF_and_Gibbs_Energy(files))''' | ||
| − | print("Here are the | + | print("Here are the SCF E, ΔG, ΔH, TΔS, and ZPE of all the Files\n") |
for i in Final_Energies_List: | for i in Final_Energies_List: | ||
print( | print( | ||
| − | " {:<20} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<10} {:<10} {:<10} {:<10} {:<10}".format(i[0], i[1], i[2], i[3], | + | " {:<20} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<10} {:<10} {:<10} {:<10} {:<10} {:<10}".format(i[0], i[1], i[2], i[3], |
| − | i[4], i[5], i[6], i[7], i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15], i[16], i[17])) | + | i[4], i[5], i[6], i[7], i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15], i[16], i[17], i[18])) |
print("\nAll Done Boss :)") | print("\nAll Done Boss :)") | ||
| Line 104: | Line 103: | ||
print("\n") | print("\n") | ||
print("#-------------------------------------------------------#") | print("#-------------------------------------------------------#") | ||
| − | print("# A Script by Dr. Muhammad Ali Hashmi ( | + | print("# A Script by Dr. Muhammad Ali Hashmi (01-August-2024) #") |
print("#-------------------------------------------------------#") | print("#-------------------------------------------------------#") | ||
| + | |||
</pre> | </pre> | ||
Latest revision as of 04:36, 1 August 2024
Extract thermodynamic data and low frequencies from all the log files in a folder to a csv file for the database
- Here is a script to extract data from all the log files in a folder and directly produce a csv file that can be opened in MS Excel. It runs and uses all the log files (*.log) in the current directory.
- To use, simply copy and paste this script into a file get_frequencies_data.py
- Then run the file in any folder with the command "python3 get_frequencies_data.py"
- Alternatively, you can add the script to your PATH to call it anywhere.
import glob, os, sys, csv
print("#=====================================================================================#")
print("#-------------------------------------------------------------------------------------#")
print("# A Script to Extract SCF E, ΔG, ΔH, TΔS, and ZPE from Gaussian Output Files #")
print("#-------------------------------------------------------------------------------------#")
print("#=====================================================================================#")
print("\n")
#---------------------------------------------------------------------------------------------------------------------------------------#
# A function to take out SCF & Gibb's Free Energy Values from a Gaussian log file and save the Filename., SCF E, & Gibb's E to a list #
#---------------------------------------------------------------------------------------------------------------------------------------#
#---------- Start of Function ----------#
def Extract_Energies(input_file):
SCF_Energy = "--NOT FOUND--"
Gibbs_Energy = "--NOT FOUND--"
Rxn_Enthalpy_H = "--NOT FOUND--"
Zero_point_energy = "--NOT FOUND--"
TDS = "--NOT FOUND--"
delta_E = ' '
SCF_E_kJ = "--NOT FOUND--"
Gibbs_E_kJ = "--NOT FOUND--"
Enthalpy_of_Rxn_kJ = "--NOT FOUND--"
ZPE_kJ = "--NOT FOUND--"
found_low_frequencies = False
f = open(input_file, 'r')
input = f.readlines()
filename=os.path.splitext(os.path.basename(input_file))[0]
for line in input:
if "SCF Done:" in line:
complete_line = line.split()
SCF_Energy = complete_line[4] # ΔE
SCF_E_kJ = float(SCF_Energy)*2625.50
if "Sum of electronic and thermal Free Energies" in line:
gibbs_line = line.split()
Gibbs_Energy = gibbs_line[7] # ΔG
Gibbs_E_kJ = float(Gibbs_Energy) * 2625.50
if "Sum of electronic and thermal Enthalpies" in line:
enthalpies_line = line.split()
Rxn_Enthalpy_H = enthalpies_line[6] # ΔH
Enthalpy_of_Rxn_kJ = float(Rxn_Enthalpy_H) * 2625.50
#TDS_au = float(Rxn_Enthalpy_H) - float(Gibbs_Energy)
#print('Here is the TDS value', TDS_au)
if "Zero-point correction=" in line:
complete_line = line.split()
Zero_point_energy = complete_line[2] # ZPE
ZPE_kJ = float(Zero_point_energy)*2625.50
if "Low frequencies ---" in line:
if found_low_frequencies:
continue # Skip processing if already found
complete_line = line.split()
LF01 = complete_line[3]
LF02 = complete_line[4]
LF03 = complete_line[5]
LF04 = complete_line[6]
LF05 = complete_line[7]
LF06 = complete_line[8]
found_low_frequencies = True
return [filename, SCF_Energy, SCF_E_kJ, delta_E, Gibbs_Energy, Gibbs_E_kJ, Rxn_Enthalpy_H, Enthalpy_of_Rxn_kJ, round(float(Rxn_Enthalpy_H) - float(Gibbs_Energy),10), round((float(Rxn_Enthalpy_H) - float(Gibbs_Energy))*2625.50,10), Zero_point_energy, float(SCF_Energy)+float(Zero_point_energy), (float(SCF_Energy)+float(Zero_point_energy))*2625.50, LF01, LF02, LF03, LF04, LF05, LF06]
#---------- End of Function ----------#
#Define the user input for input files (log files)
#input_files = input('Enter the names of input files or a range (e.g. *.log): ')
input_files = '*.log'
Final_Energies_List = [['File Name', 'SCF Energy (a.u.)', 'SCF Energy (KJ/mol)', u'Δ'+'E (kJ/mol)' , 'G (a.u.)', 'G (KJ/mol)', 'H (a.u)', 'H (KJ/mol)', 'T'+u'Δ'+'S (a.u)', 'T'+u'Δ'+'S (kJ/mol)', 'ZPE (a.u.)', 'E+ZPE (a.u.)', 'E+ZPE (kJ/mol)', 'Low Frequencies', ' ', ' ', ' ', ' ', ' ']] # A list which will contain all the data from all log files
#-------------------------------------------------------------------------------------------------------------------------#
# A for loop to go through all the .log files in the current directory and use the function defined above on all of them #
#-------------------------------------------------------------------------------------------------------------------------#
#Uncomment below if your log files are located in the same directory or use the loop below if log files are in multiple subdirectories.
for files in glob.glob(input_files):
Final_Energies_List.append(Extract_Energies(files))
#-----------------------------------------------------------------------------------------------------------------------------------#
# A for loop to go through all the subdirectories in the current directory and use the function defined above on all the log files #
#-----------------------------------------------------------------------------------------------------------------------------------#
'''for files in glob.iglob(os.path.join('*', '*.log')):
Final_Energies_List.append(SCF_and_Gibbs_Energy(files))'''
print("Here are the SCF E, ΔG, ΔH, TΔS, and ZPE of all the Files\n")
for i in Final_Energies_List:
print(
" {:<20} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<16} {:<10} {:<10} {:<10} {:<10} {:<10} {:<10}".format(i[0], i[1], i[2], i[3],
i[4], i[5], i[6], i[7], i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15], i[16], i[17], i[18]))
print("\nAll Done Boss :)")
# ------------------------------------------#
# A loop to write the output to a csv file #
# ------------------------------------------#
with open('frequencies_database.csv', 'w', newline='', encoding='utf-8-sig') as csvfile:
writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) # Defining general csv writing template
for i in Final_Energies_List:
writer.writerow(i)
print("\n")
print("#-------------------------------------------------------#")
print("# A Script by Dr. Muhammad Ali Hashmi (01-August-2024) #")
print("#-------------------------------------------------------#")