前回から引き続き屈折率自動算出アプリの紹介です。
前回もコメントさせていただきましたが、基本的なコードは以前に紹介した分子軌道情報(HOMO/LUMO)の自動算出アプリと同じです。
今回はCustumTkinterのパートの紹介です。
CustumTkinterですが、tkinterと比べてある程度デザイン性に優れた画面を作成することが可能で、設定情報などは以前の分子軌道情報(HOMO/LUMO)の自動算出アプリで紹介させていただきました。
画面の構成ですが、smiles情報を有するファイルの選択、量子化学計算の条件設定
(構造最適化)、分極率の計算方法の設定からなっています。分極率は、cc2法とっccsd法を選択できるようになっています。
一般的には分極率の計算は量子化学計算において分散関数を使用することが推奨されますが、計算コストの関係から必ずしも対応できない場合もあるので、その辺は量子化学計算の計算手法を適宜選択できるように設定しています。
# Custon Tkinter main ctk.set_appearance_mode('dark') # global root root = ctk.CTk() root.title("Reflactive Index List Calculator") root.geometry('700x450') # Select main molecule file Label1=ctk.CTkLabel(master=root, fg_color='blue',corner_radius=10, text='Smiles File Select',font=("Arial",16,"bold","italic")) Label1.place(x=20, y=20) filename_sv = tk.StringVar() filenameEntry = ctk.CTkEntry(master=root, width=500, textvariable=filename_sv) filenameEntry.place(x=20, y= 50) Button1 = ctk.CTkButton(master=root, text='Select',width=30,font=("Times",14,"bold")) Button1.bind("<Button-1>", data_import) Button1.place(x=600, y=50) # Calculation Run Button2_3=ctk.CTkButton(master=root, text='Quantum Calculation Start',width=50, font=("Times",14,"bold")) Button2_3.bind("<Button-1>", start_calc_button) Button2_3.place(x=70, y=330) # Select calculation methods Label3=ctk.CTkLabel(master=root, fg_color='blue',corner_radius=10, text='Quantum Calculation Method', font=("Arial",16,"bold","italic")) Label3.place(x=20, y=100) Label3_1=ctk.CTkLabel(master=root, text='Method',font=("Times",12)) Label3_1.place(x=70, y=140) method_sv = tk.StringVar() methods=('HF','DFT', 'MP2') comboBox3_1=ctk.CTkComboBox(master=root, height=5, width=80, border_color='blue',state='readonly', values=methods, variable=method_sv) comboBox3_1.place(x=70, y=160) Label3_2=ctk.CTkLabel(master=root, text='Function',font=("Times",12)) Label3_2.place(x=170, y=140) function_sv = tk.StringVar() functions=('','b3lyp','cam-b3lyp', 'edf2','m06', 'pbe','wb97x-d') comboBox3_2=ctk.CTkComboBox(master=root, height=5, width=80, border_color='blue',state='readonly', values=functions, variable=function_sv) comboBox3_2.place(x=170, y=160) Label3_3=ctk.CTkLabel(master=root, text='Basis set',font=("Times",12)) Label3_3.place(x=270, y=140) baseset_sv = tk.StringVar() # sto-3g で計算すると何故か異常に遅くなる(PCがほぼハングアップ状態)ため、削除した base_sets=('3-21g','6-31g', '6-31g(d)','6-311g', 'aug-cc-pvtz') comboBox3_3=ctk.CTkComboBox(master=root, height=5, width=80,border_color='blue', state='readonly', values=base_sets, variable=baseset_sv) comboBox3_3.place(x=270, y=160) # Select options Label4=ctk.CTkLabel(master=root, text='Options', font=("Times",14,"bold")) Label4.place(x=70, y=180) Label4_1=ctk.CTkLabel(master=root, text='Tread',font=("Times",12)) Label4_1.place(x=80, y=200) threads=tk.IntVar(value=2) textBox1_1=ctk.CTkEntry(master=root, width=50, textvariable=threads) textBox1_1.place(x=80, y=220) Label4_2=ctk.CTkLabel(master=root, text='Memory/MB',font=("Times",12)) Label4_2.place(x=180, y=200) memory=tk.IntVar(value=500) textBox1_2=ctk.CTkEntry(master=root, width=50, textvariable=memory) textBox1_2.place(x=180, y=220) Label4_3=ctk.CTkLabel(master=root, text='Charge',font=("Times",12)) Label4_3.place(x=80, y=250) charge=tk.IntVar(value=0) textBox2_1=ctk.CTkEntry(master=root, width=50, textvariable=charge) textBox2_1.place(x=80, y=270) Label4_4=ctk.CTkLabel(master=root, text='Multiplicity',font=("Times",12)) Label4_4.place(x=180, y=250) multi=tk.IntVar(value=1) textBox2_2=ctk.CTkEntry(master=root, width=50, textvariable=multi) textBox2_2.place(x=180, y=270) # select Polar calc method Label5=ctk.CTkLabel(master=root, fg_color='blue',corner_radius=10, text='Polarizability Calc Set', font=("Arial",12,"bold","italic")) Label5.place(x=400, y=100) Label5_1=ctk.CTkLabel(master=root, text='Calculation method',font=("Times",12)) Label5_1.place(x=420, y=130) method_sv_pol = tk.StringVar() methods=('cc2','ccsd') comboBox5_1=ctk.CTkComboBox(master=root, height=5, width=80, border_color='blue',state='readonly', values=methods, variable=method_sv_pol) comboBox5_1.place(x=420, y=160) # Finish program Label6=ctk.CTkLabel(master=root, text='Finish the program') Label6.place(x=550, y=370) Button3 = ctk.CTkButton(master=root, text='Quit',width=30, command=scry_finish,font=("Times",14,"bold")) Button3.place(x=550, y=390) root.mainloop()
コードは上記の通りで、CustumTkinter特有の設定を少し意識すればそれほど難しいものではありません。アプリの使い方等は次回に紹介したいと思います。