前回から引き続きアッベ数自動算出アプリの紹介です。
前回もコメントさせていただきましたが、基本的なコードは以前に紹介した屈折率自動算出アプリと同じです。
今回はCustumTkinterのパートの紹介です。
CustumTkinterですが、tkinterと比べてある程度デザイン性に優れた画面を作成することが可能で、設定情報などは以前のブログで紹介させていただきました。
画面の構成ですが、smiles情報を有するファイルの選択、量子化学計算の条件設定
(構造最適化)、分極率の計算方法の設定からなっています。分極率は、cc2法とっccsd法を選択できるようになっています。
一般的には分極率の計算は量子化学計算において分散関数を使用することが推奨されますが、計算コストの関係から必ずしも対応できない場合もあるので、その辺は量子化学計算の計算手法を適宜選択できるように設定しています。
また今回はローレンツローレンツ式を用いて屈折率の算出する際に利用する「分子体積」の値も選択できるようにしています。密度や他の量子化学計算の数値を利用することにより、実測値に近い値が得られる可能性が高まるかと思います。ただ、密度及び量子化学計算の値を用いる場合は複数分子の連続計算には対応しておらず、1分子のみの計算となるためご注意ください。
# Custon Tkinter main ctk.set_appearance_mode('dark') ctk.set_default_color_theme("dark-blue") # global root root = ctk.CTk() root.title("Abbe's number/Reflactive Index List Calculator") root.geometry('780x450') # Select main molecule file Label1=ctk.CTkLabel(master=root, fg_color='blue',corner_radius=2, text='Smiles File Select',font=("Times",16,"bold")) Label1.place(x=20, y=20) filename_sv = tk.StringVar() filenameEntry = ctk.CTkEntry(master=root, width=500, corner_radius=2, textvariable=filename_sv) filenameEntry.place(x=20, y= 50) Button1 = ctk.CTkButton(master=root, text='Select',width=30,corner_radius=2,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, corner_radius=2, font=("Times",14,"bold")) Button2_3.bind("<Button-1>", start_calc_button) Button2_3.place(x=250, y=410) # Select calculation methods Label3=ctk.CTkLabel(master=root, fg_color='blue',corner_radius=2, text='Quantum Calculation Method', font=("Arial",16,"bold","italic")) Label3.place(x=20, y=100) Label3_1=ctk.CTkLabel(master=root, text='Method',corner_radius=2, 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,corner_radius=2, 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',corner_radius=2, 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, corner_radius=2, 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',corner_radius=2, font=("Times",12)) Label3_3.place(x=270, y=140) baseset_sv = tk.StringVar() # sto-3g で計算すると何故か異常に遅くなる(PCがほぼハングアップ状態)ため、削除した。またaug-cc-pvtzの場合はスクラッチファイルが膨大数百GB以上になるため要注意 base_sets=('3-21g','6-31g', '6-31g(d)','6-31+g(d)','6-311g','6-311g(d)','6-311+g(d)', 'aug-cc-pvtz') comboBox3_3=ctk.CTkComboBox(master=root, height=5, width=80,corner_radius=2, 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',corner_radius=2, font=("Times",14,"bold")) Label4.place(x=70, y=180) Label4_1=ctk.CTkLabel(master=root, text='Tread',corner_radius=2, font=("Times",12)) Label4_1.place(x=80, y=200) threads=tk.IntVar(value=2) textBox1_1=ctk.CTkEntry(master=root, width=50,corner_radius=2, textvariable=threads) textBox1_1.place(x=80, y=220) Label4_2=ctk.CTkLabel(master=root, text='Memory/MB',corner_radius=2, font=("Times",12)) Label4_2.place(x=180, y=200) memory=tk.IntVar(value=500) textBox1_2=ctk.CTkEntry(master=root, width=50, corner_radius=2, textvariable=memory) textBox1_2.place(x=180, y=220) Label4_3=ctk.CTkLabel(master=root, text='Charge',corner_radius=2, font=("Times",12)) Label4_3.place(x=80, y=250) charge=tk.IntVar(value=0) textBox2_1=ctk.CTkEntry(master=root, width=50, corner_radius=2, textvariable=charge) textBox2_1.place(x=80, y=270) Label4_4=ctk.CTkLabel(master=root, text='Multiplicity',corner_radius=2, font=("Times",12)) Label4_4.place(x=180, y=250) multi=tk.IntVar(value=1) textBox2_2=ctk.CTkEntry(master=root, width=50, corner_radius=2, textvariable=multi) textBox2_2.place(x=180, y=270) # select Polar calc method Label5=ctk.CTkLabel(master=root, fg_color='blue',corner_radius=2, text='Polarizability Calc Set', font=("Arial",12,"bold","italic")) Label5.place(x=400, y=100) Label5_1=ctk.CTkLabel(master=root, text='Calc method',corner_radius=2,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, corner_radius=2, border_color='blue',state='readonly', values=methods, variable=method_sv_pol) comboBox5_1.place(x=420, y=160) Label5_2=ctk.CTkLabel(master=root,corner_radius=2, text='Basis set(pol)',font=("Times",12)) Label5_2.place(x=530, y=130) baseset_sv_pol = tk.StringVar() # sto-3g で計算すると何故か異常に遅くなる(PCがほぼハングアップ状態)ため、削除した。またaug-cc-pvtzの場合はスクラッチファイルが膨大数百GB以上になるため要注意 base_sets_pol=('3-21g','6-31g', '6-31g(d)','6-31+g(d)','6-311g','6-311g(d)','6-311+g(d)', 'aug-cc-pvtz') comboBox5_2=ctk.CTkComboBox(master=root, height=5, width=80,corner_radius=2, border_color='blue', state='readonly', values=base_sets_pol, variable=baseset_sv_pol) comboBox5_2.place(x=530, y=160) Label6_0=ctk.CTkLabel(master=root, corner_radius=2, text='Molecular Volume for RI Calc',font=("Times",12)) Label6_0.place(x=420, y=190) Calc_Vol_Lists=['Estimate from VDW data\n(calc in this program) : Default', 'From density/ g/cm3 (single molecule only)', 'From Similation data/ Angstrom3 (single molecule only)'] chk_st6_1=tk.BooleanVar() chk_bu6_1=ttk.Checkbutton(master=root, variable=chk_st6_1,text=Calc_Vol_Lists[0]) chk_bu6_1.place(x=420, y=210) chk_st6_1.set(True) Label6_1=ctk.CTkLabel(master=root, text='Scale_Factor',font=("Times",12)) Label6_1.place(x=440, y=240) scale_f=tk.DoubleVar(value=1.5) textBox6_1=ctk.CTkEntry(master=root, corner_radius=2, width=50, textvariable=scale_f) textBox6_1.place(x=570, y=240) chk_st6_2=tk.BooleanVar() chk_bu6_2=ttk.Checkbutton(master=root, variable=chk_st6_2, text=Calc_Vol_Lists[1]) chk_bu6_2.place(x=420, y=270) Label6_2_1=ctk.CTkLabel(master=root, corner_radius=2, text='Density',font=("Times",12)) Label6_2_1.place(x=440, y=290) density=tk.DoubleVar() textBox6_2_1=ctk.CTkEntry(master=root, corner_radius=2, width=50, textvariable=density) textBox6_2_1.place(x=500, y=290) Label6_2_2=ctk.CTkLabel(master=root, corner_radius=2, text='MW/mol',font=("Times",12)) Label6_2_2.place(x=560, y=290) molecular_weight=tk.IntVar() textBox6_2_2=ctk.CTkEntry(master=root, corner_radius=2, width=50, textvariable=molecular_weight) textBox6_2_2.place(x=610, y=290) chk_st6_3=tk.BooleanVar() chk_bu6_3=ttk.Checkbutton(master=root, variable=chk_st6_3, text=Calc_Vol_Lists[2]) chk_bu6_3.place(x=420, y=320) Label6_3=ctk.CTkLabel(master=root, text='Simulation Volume',font=("Times",12)) Label6_3.place(x=440, y=340) simvol=tk.DoubleVar() textBox6_3=ctk.CTkEntry(master=root, corner_radius=2, width=50, textvariable=simvol) textBox6_3.place(x=570, y=340) # Finish program Label6=ctk.CTkLabel(master=root, corner_radius=2, text='Finish the program') Label6.place(x=570, y=390) Button3 = ctk.CTkButton(master=root, corner_radius=2, text='Quit',width=30, command=scry_finish,font=("Times",14,"bold")) Button3.place(x=570, y=410) root.mainloop()
コードは上記の通りで、CustumTkinter特有の設定を少し意識すればそれほど難しいものではありません。アプリの使い方等は次回に紹介したいと思います。