量子化学計算ソフトGaussianのエネルギーをエクセルに出力するプログラム


量子化学計算ソフトGaussian16のエネルギーをエクセルに出力するプログラム
ここではlogファイルに記載されているギブスの自由エネルギーをエクセルに出力させるプログラムを作ってみました。プログラミング初心者なためコードが雑になっていますがご了承を。

python3.6
import os
import glob
import openpyxl as px

os.chdir('C:\\')

#logファイル名の取得
a = glob.glob("*.log")

wb = px.Workbook()
ws = wb.active

#ファイル名をエクセルのA列に出力
j=1
for p in a:
    name = os.path.splitext(os.path.basename(p))[0]
    print(name)
    name2 = name.split() 
    for i in name2:
        ws.cell(row=j,column=1).value = name
        j += 1

wb.save('C:\samp.xlsx')

#logファイルに書かれているギブスエネルギーの値をエクセルのB列に出力
j = 1
for i in a:
    path = i
    with open(path) as f:
        lines = f.readlines()
        lines_strip = [line.strip() for line in lines]
        m = [line for line in lines_strip if 'Sum of electronic and thermal Free Energies' in line]
        s = ''.join(m)
        l = s.lstrip('Sum of electronic and thermal Free Energies=       ')
        print(l)
        ws.cell(row=j,column=2).value = l
        j += 1

wb.save('C:\samp.xlsx')