def _choose_ligand_frame(self): choose_ligand_labelframe = LabelFrame(self.root, text="选择/提取配体") choose_ligand_labelframe.place(x=10, y=10, width=570, height=120) # 选择输入配体的格式 SLabel(root=choose_ligand_labelframe, text="输入格式:", x=10, y=0) input_format_text = ("pdbqt", "sdf", "pdb") self.input_format = SCombbox(root=choose_ligand_labelframe, textvariable=StringVar(), values=input_format_text, default_value=Configer.get_para("complex_ligand_format"), x=80, y=0, width=60) create_tooltip(self.input_format.combobox, "导入配体的格式") # 选择第几个配体 SLabel(root=choose_ligand_labelframe, text="选择第", x=160, y=0) self.complex_ligand_num_entry = SEntry(choose_ligand_labelframe, textvariable=StringVar(), text=Configer.get_para("complex_ligand_num"), x=205, y=2, width=20) create_tooltip(self.complex_ligand_num_entry.entry, "只针对多构象pdbqt文件。输入" "要进行复合或者提取的构象。" "如果为0则全部提取/复合") SLabel(root=choose_ligand_labelframe, text="个构象", x=230, y=0) # 选择配体 choose_ligands_button = SButton(choose_ligand_labelframe, text="选择单/多个配体", x=10, y=30) create_tooltip(choose_ligands_button.button, "选择一个或者多个所选格式的配体") choose_ligand_dir_button = SButton(choose_ligand_labelframe, text="选择文件夹", x=110, y=30) create_tooltip(choose_ligand_dir_button.button, "选择包含配体的文件夹,匹配其中所选格式的文件") self.choose_ligands_entry = SEntry(root=choose_ligand_labelframe, textvariable=StringVar(), text=Configer.get_para("choose_complex_ligands"), x=200, y=34, width=360) create_tooltip(self.choose_ligands_entry.entry, "所选的配体或者包含配体的目录") choose_ligands_button.bind_open_files(entry_text=self.choose_ligands_entry.textvariable, title="选择单/多个配体", file_type=self.input_format.textvariable) choose_ligand_dir_button.bind_open_dir(entry_text=self.choose_ligands_entry.textvariable, title="选择包含配体文件的文件夹") # 选择单独输出配体文件夹 choose_output_button = SButton(choose_ligand_labelframe, text="提取配体输出路径", x=10, y=65) create_tooltip(choose_output_button.button, "单独提取配体,选择要输出的文件夹。") self.extract_output_entry = SEntry(choose_ligand_labelframe, textvariable=StringVar(), text=Configer.get_para("extract_pdbqt_dir"), x=120, y=65 + 3, width=340) create_tooltip(self.extract_output_entry.entry, "输出的文件夹") choose_output_button.bind_open_dir(entry_text=self.extract_output_entry.textvariable, title="选择提取配体输出的文件夹") extract_button = SButton(choose_ligand_labelframe, text="提取选定的配体", x=470, y=65) extract_button.button.bind("<Button-1>", self.extract) create_tooltip(extract_button.button, "提取配体")
def vina_validate(self, event): self.windows = STopLevel(self.root, win_x=570, win_y=50, title="计算RMSD").toplevel # 选择目录 input_button = SButton(self.windows, text="选择验证目录", x=10, y=10) create_tooltip(input_button.button, "选择要验证的目录。该目录必须包含配体和受体!") self.input_path_entry = SEntry( self.windows, textvariable=StringVar(), text=Configer.get_para("validate_folder") if self.validate_folder == "" else self.validate_folder, x=100, y=13, width=360) create_tooltip(self.input_path_entry.entry, "选择的要验证的目录") input_button.bind_open_dir( entry_text=self.input_path_entry.textvariable, title="选择要验证的目录", parent=self.windows) validate_button = SButton(self.windows, "开始验证", x=465, y=10) create_tooltip(validate_button.button, "开始验证Vina方案") validate_button.button.bind("<Button-1>", self._vina_validate) # 关闭窗口保存参数 self.windows.protocol( "WM_DELETE_WINDOW", lambda: self.save_validate( self.windows, self.input_path_entry.textvariable.get()))
def create_move_pdbqt(self): move_pdbqt_labelframe = Labelframe(self.root, text="移动受体文件") move_pdbqt_labelframe.place(x=10, y=100, width=570, height=50) choose_pdbqt_dir = SButton(move_pdbqt_labelframe, text="选择文件", x=10, y=0) create_tooltip(choose_pdbqt_dir.button, "选择包含pdbqt受体的文件夹") self.choose_pdbqt_dir_entry = SEntry( move_pdbqt_labelframe, textvariable=StringVar(), text=Configer.get_para("pdbqt_dir"), x=100, y=3, width=350) create_tooltip(self.choose_pdbqt_dir_entry.entry, "选择包含pdbqt受体的文件夹") choose_pdbqt_dir.bind_open_dir( self.choose_pdbqt_dir_entry.textvariable, title="选择有pdbqt受体的文件夹") move_button = SButton(move_pdbqt_labelframe, text="生成文件", x=460, y=0, width=90) create_tooltip(move_button.button, "开始移动pdbqt文件并重命名为preped.pdbqt") move_button.button.bind("<Button-1>", self.move_file)
def _choose_ligand_frame(self): choose_ligand_labelframe = LabelFrame(self.root, text="选择配体") choose_ligand_labelframe.place(x=10, y=10, width=570, height=50) choose_ligands = SButton(root=choose_ligand_labelframe, text="选择单/多个配体", x=10, y=0) create_tooltip(choose_ligands.button, "选择单/多个配体,配体格式必须是pdbqt!") choose_ligand_dir = SButton(root=choose_ligand_labelframe, text="选择文件夹", x=110, y=0) create_tooltip(choose_ligand_dir.button, "选择包含pdbqt格式配体的文件夹。") self.choose_ligand_entry = SEntry( root=choose_ligand_labelframe, textvariable=StringVar(), text=Configer.get_para("choose_docking_ligands"), x=200, y=4, width=360) create_tooltip(self.choose_ligand_entry.entry, "选择的配体或者包含配体的文件夹") choose_ligands.bind_open_files( entry_text=self.choose_ligand_entry.textvariable, title="选择单/多个配体", file_type="pdbqt") choose_ligand_dir.bind_open_dir( entry_text=self.choose_ligand_entry.textvariable, title="选择包含pdbqt配体的文件夹")
def create_extract_scores(self): extract_scores_labelframe = Labelframe(self.root, text="提取分数") extract_scores_labelframe.place(x=10, y=155, width=570, height=50) choose_score = SButton(root=extract_scores_labelframe, text="选择单个文件", x=10, y=0) create_tooltip(choose_score.button, "选择单个打分结果pdbqt文件") choose_scores_dir = SButton(root=extract_scores_labelframe, text="选择文件夹", x=100, y=0) create_tooltip(choose_scores_dir.button, "选择多个打分结果所在的文件夹") self.choose_scores_entry = SEntry( root=extract_scores_labelframe, textvariable=StringVar(), text=Configer.get_para("choose_score_file"), x=190, y=4, width=260) create_tooltip(self.choose_scores_entry.entry, "选择的文件/文件夹") choose_score.bind_open_file(self.choose_scores_entry.textvariable, title="选择对接结果pdbqt文件", file_type="pdbqt") choose_scores_dir.bind_open_dir(self.choose_scores_entry.textvariable, title="选择含有对接结果的文件夹") extract_button = SButton(extract_scores_labelframe, text="提取分数", x=460, y=0, width=90) create_tooltip(extract_button.button, "提取分数结果。如果是单个文件直接显示窗口。" "如果选择文件夹,则输出txt文件到选择的文件夹") extract_button.button.bind("<Button-1>", self.extract_score)
def extract_from_file(self): extract_from_file_labelframe = Labelframe(self.root, text="从文件提取配体") extract_from_file_labelframe.place(x=10, y=210, width=570, height=85) choose_file_button = SButton(extract_from_file_labelframe, text="选择输入文件", x=10, y=0) create_tooltip(choose_file_button.button, "选择输入的txt文件") self.choose_output_entry = SEntry(extract_from_file_labelframe, textvariable=StringVar(), text=Configer.get_para("output_txt"), x=100, y=3, width=450) create_tooltip(self.choose_output_entry.entry, "选择的txt文件") choose_file_button.bind_open_file( entry_text=self.choose_output_entry.textvariable, title="选择输入的txt文件", file_type="txt") choose_output_button = SButton(extract_from_file_labelframe, text="选择提取目录", x=10, y=33) create_tooltip(choose_output_button.button, "选择提取输出的目录") self.choose_extract_folder_entry = SEntry( extract_from_file_labelframe, textvariable=StringVar(), text=Configer.get_para("extract_folder"), x=100, y=33, width=350) create_tooltip(self.choose_extract_folder_entry.entry, "选择提取输出的目录") choose_output_button.bind_open_dir( entry_text=self.choose_extract_folder_entry.textvariable, title="选择输出目录") extract_button = SButton(extract_from_file_labelframe, text="提取配体", x=460, y=30, width=90) create_tooltip(extract_button.button, "根据输入的文件提取配体") extract_button.button.bind("<Button-1>", self.extract_file)
def gen_smi(self, event): self.windows = STopLevel(self.root, win_x=570, win_y=100, title="分子生成器").toplevel # 输入smi SLabel(self.windows, text="输入smi", x=10, y=10) self.input_smi_entry = SEntry(self.windows, textvariable=StringVar(), text=Configer.get_para("input_smi") if self.input_smi == "" else self.input_smi, x=80, y=13, width=470) create_tooltip(self.input_smi_entry.entry, "输入含有[R]的smi文本") # 输出目录 output_button = SButton(self.windows, text="选择输出目录", x=10, y=50) create_tooltip(output_button.button, "选择衍生物输出的目录") self.output_path_entry = SEntry( self.windows, textvariable=StringVar(), text=Configer.get_para("mol_output_path") if self.output_path == "" else self.output_path, x=100, y=53, width=360) create_tooltip(self.output_path_entry.entry, "选择衍生物mol的输出目录") output_button.bind_open_dir( entry_text=self.output_path_entry.textvariable, title="选择衍生物输出目录", parent=self.windows) gen_button = SButton(self.windows, "生成衍生物", x=465, y=50) create_tooltip(gen_button.button, "开始生成衍生物") gen_button.button.bind("<Button-1>", self._gen_smi) # 关闭窗口保存参数 self.windows.protocol( "WM_DELETE_WINDOW", lambda: self.save_smi( self.windows, self.input_smi_entry.textvariable.get(), self.output_path_entry.textvariable.get()))
def _create_option_frame(self): option_label_frame = LabelFrame(self.root, text="可选") option_label_frame.place(x=340, y=10, width=240, height=120) # exhaustiveness SLabel(option_label_frame, text="exhaustiveness = ", x=10, y=5) self.exhaustiveness = SEntry(option_label_frame, textvariable=StringVar(), text=Configer.get_para("exhaustiveness"), x=140, y=5, width=20) create_tooltip(self.exhaustiveness.entry, "搜索度,越大耗时越长,建议保持默认") # num_modes SLabel(option_label_frame, text="num_modes = ", x=10, y=35) self.num_modes = SEntry(option_label_frame, textvariable=StringVar(), text=Configer.get_para("num_modes"), x=140, y=35, width=20) create_tooltip(self.num_modes.entry, "最多生成多少种结合模式") # energy_range SLabel(option_label_frame, text="energy_range = ", x=10, y=65) self.energy_range = SEntry(option_label_frame, textvariable=StringVar(), text=Configer.get_para("energy_range"), x=140, y=65, width=20) create_tooltip(self.energy_range.entry, "最大最小结合模式能量差") # 恢复默认值 default_button = SButton(option_label_frame, text="默认", x=170, y=62, width=60) default_button.button.bind("<Button-1>", self._change_default) create_tooltip(default_button.button, "恢复默认值")
def _create_tools_frame(self): tools_frame = LabelFrame(self.root, text="工具") tools_frame.place(x=10, y=140, width=570, height=100) # 读取配置文件 read_config_button = SButton(tools_frame, "读取配置文件", 10, 10) create_tooltip(read_config_button.button, "必须选择config.txt文件!") self.read_config_entry = SEntry(root=tools_frame, textvariable=StringVar(), text=Configer.get_para("read_config"), x=100, y=14, width=360) create_tooltip(self.read_config_entry.entry, "你选择的config.txt文件位置") read_config_button.bind_open_file( entry_text=self.read_config_entry.textvariable, title="请选择config.txt文件", file_type="txt") read_button = SButton(tools_frame, "读取到参数", 470, 10) create_tooltip(read_button.button, "读取到上方") read_button.button.bind("<Button-1>", self.read_config) # 自动生成盒子 choose_raw_ligand_button = SButton(tools_frame, "读取共晶配体", 10, 40) create_tooltip(choose_raw_ligand_button.button, "必须选择共晶配体pdbqt文件!") self.choose_raw_ligand_entry = SEntry( root=tools_frame, textvariable=StringVar(), text=Configer.get_para("choose_raw_ligand"), x=100, y=44, width=360) choose_raw_ligand_button.bind_open_file( entry_text=self.choose_raw_ligand_entry.textvariable, title="请选择“共晶配体”PDBQT文件!", file_type="pdbqt") create_tooltip(self.choose_raw_ligand_entry.entry, "你选择的共晶配体pdbqt文件位置") gen_box_button = SButton(tools_frame, "计算对接位点", 470, 40) create_tooltip(gen_box_button.button, "自动计算对接位点,该对接位点为共晶配体的" "最小外切正方体,结果仅供参考。") gen_box_button.button.bind("<Button-1>", self.gen_box)
def create_all_config(self): all_config_labelframe = LabelFrame(self.root, text="受体全局对接") all_config_labelframe.place(x=10, y=10, width=570, height=85) choose_ligand = SButton(all_config_labelframe, text="选择配体", x=10, y=0) create_tooltip(choose_ligand.button, "选择参考配体pdbqt文件") self.choose_ligand_entry = SEntry( all_config_labelframe, textvariable=StringVar(), text=Configer.get_para("refer_ligand"), x=100, y=3, width=450) create_tooltip(self.choose_ligand_entry.entry, "选择的参考配体") choose_ligand.bind_open_file(self.choose_ligand_entry.textvariable, title="选择配体pdbqt文件", file_type="pdbqt") choose_receptor = SButton(all_config_labelframe, text="选择受体", x=10, y=30) create_tooltip(choose_receptor.button, "选择需要全局搜索的单/多个受体文件夹,具体请看帮助或者教程") self.choose_receptor_entry = SEntry( all_config_labelframe, textvariable=StringVar(), text=Configer.get_para("refer_receptor"), x=100, y=33, width=350) create_tooltip(self.choose_receptor_entry.entry, "选择的参考") choose_receptor.bind_open_dir( entry_text=self.choose_receptor_entry.textvariable, title="选择单/多个受体所在文件夹") generate_button = SButton(all_config_labelframe, text="生成文件", x=460, y=30, width=90) create_tooltip(generate_button.button, "生成全局对接的多个config文件") generate_button.button.bind("<Button-1>", self.generate_configs)
def save_para(self): if messagebox.askokcancel("退出", "保存参数并退出软件?"): self.config.para_dict["python_path"] = Configer.get_para( "python_path") self.config.para_dict["obabel_path"] = Configer.get_para( "obabel_path") # 保存各个标签的参数 self.tab1_configer.save_para() self.tab2_configer.save_para() self.tab3_configer.save_para() self.tab4_configer.save_para() self.tab5_configer.save_para() self.tab6_configer.save_para() self.tab8_configer.save_para() # 进行文件保存 self.config.save_para() # 关闭窗口 self.main_window.destroy()
def _choose_output_frame(self): choose_output_labelframe = LabelFrame(self.root, text="复合物输出") choose_output_labelframe.place(x=10, y=190, width=570, height=50) choose_output = SButton(root=choose_output_labelframe, text="选择输出文件夹", x=10, y=0) create_tooltip(choose_output.button, "选择复合物输出目录") self.choose_output_entry = SEntry(root=choose_output_labelframe, textvariable=StringVar(), text=Configer.get_para("choose_complex_output"), x=110, y=4, width=450) create_tooltip(self.choose_output_entry.entry, "所选的复合物输出目录") choose_output.bind_open_dir(entry_text=self.choose_output_entry.textvariable, title="选择复合物输出的文件夹")
def _choose_protein_frame(self): choose_protein_labelframe = LabelFrame(self.root, text="选择受体") choose_protein_labelframe.place(x=10, y=135, width=570, height=50) choose_proteins = SButton(root=choose_protein_labelframe, text="选择受体", x=10, y=0) create_tooltip(choose_proteins.button, "选择pdbqt格式的受体") self.choose_proteins_entry = SEntry(root=choose_protein_labelframe, textvariable=StringVar(), text=Configer.get_para("choose_complex_proteins"), x=110, y=4, width=450) create_tooltip(self.choose_proteins_entry.entry, "受体文件") choose_proteins.bind_open_file(entry_text=self.choose_proteins_entry.textvariable, title="选择蛋白受体", file_type="pdbqt")
def gen_config_file(output_name, x, y, z, size): """ 根据x,y,z,size生成config文件 :param output_name: 输出路径文件名 :param x: x坐标 :param y: y坐标 :param z: z坐标 :param size: 盒子大小 """ exhaustiveness = Configer.get_para( "exhaustiveness") if Configer.get_para("exhaustiveness") != "" else 8 num_modes = Configer.get_para( "num_modes") if Configer.get_para("num_modes") != "" else 9 energy_range = Configer.get_para( "energy_range") if Configer.get_para("energy_range") != "" else 3 with open(output_name, "w") as f: f.writelines("center_x = " + str(x) + "\n") f.writelines("center_y = " + str(y) + "\n") f.writelines("center_z = " + str(z) + "\n") f.writelines("size_x = " + str(size) + "\n") f.writelines("size_y = " + str(size) + "\n") f.writelines("size_z = " + str(size) + "\n") f.writelines("exhaustiveness = " + exhaustiveness + "\n") f.writelines("num_modes = " + num_modes + "\n") f.writelines("energy_range = " + energy_range + "\n")
def choose_obabel(self): y = 50 # python路径 choose_obabel_path = SButton(self.top, text="选择obabel.exe的路径", x=10, y=y) create_tooltip(choose_obabel_path.button, "选择obabel.exe文件") self.choose_obabel_path_entry = SEntry(root=self.top, textvariable=StringVar(), text=Configer.get_para("obabel_path"), x=150, y=y + 4, width=230) create_tooltip(self.choose_obabel_path_entry.entry, "obabel.exe位置") choose_obabel_path.bind_open_file(entry_text=self.choose_obabel_path_entry.textvariable, title="选择obabel.exe", file_type="exe", parent=self.top)
def choose_python(self): y = 10 # python路径 choose_python_path = SButton(self.top, text="选择ADT的python路径", x=10, y=y) create_tooltip(choose_python_path.button, "必须选择mgltools目录里面的python.exe文件!\n" "比如:\nC:/mgltools/python.exe") self.choose_python_path_entry = SEntry(root=self.top, textvariable=StringVar(), text=Configer.get_para("python_path"), x=150, y=y + 4, width=230) create_tooltip(self.choose_python_path_entry.entry, "ADT的python路径") choose_python_path.bind_open_file(entry_text=self.choose_python_path_entry.textvariable, title="选择ADT中的python.exe", file_type="exe", parent=self.top)
def _choose_docking_config(self): choose_config_labelframe = LabelFrame(self.root, text="对接配置") choose_config_labelframe.place(x=10, y=190, width=570, height=50) self.docking_time_label = SLabel(root=choose_config_labelframe, text="对接次数:", x=10, y=0) self.times_entry = SEntry(root=choose_config_labelframe, textvariable=StringVar(), text=Configer.get_para("docking_times"), x=80, y=0, width=20) create_tooltip(self.times_entry.entry, "每个配体需要对接的次数")
def check_obabel(obabel_path=""): """ 检查obabel是否配置正确 :return: 正确返回True,不正确返回False """ if Configer.get_para("obabel_path") != "": return True if obabel_path.count(" ") > 0 or not obabel_path.endswith( "obabel.exe"): messagebox.showerror("输入错误!", "obabel.exe选择不正确!请确保路径不包含空格并且是obabel.exe文件!") return False obabel_cmd = os.popen(obabel_path).read() # print(obabel_cmd) if "Usage:\nobabel" not in obabel_cmd: messagebox.showerror("错误!", "obabel.exe不正确,请在“脚本配置”中选择!") return False messagebox.showinfo("obabel配置成功!", "obabel配置成功!") return True
def check_python(choose_python_path=""): """ 检查adt的python路径是否配置正确 :return: 正确返回True """ # 如果有内容,直接判断通过 if Configer.get_para("python_path") != "": return True if choose_python_path.count( " ") > 0 or not choose_python_path.endswith("python.exe"): messagebox.showerror( "输入错误!", "adt的python.exe选择不正确,请确保路径不包含空格并且是python.exe文件!") return False check_cmd = "%s %s" % (choose_python_path, pdbqt_to_pdb_path) state = os.system(check_cmd) if state == 1: messagebox.showerror("python路径错误!", "请确定选择的是安装adt软件的python.exe!") return False messagebox.showinfo("python配置成功!", "python配置成功!") return True
def _create_output_frame(self): output_frame = LabelFrame(self.root, text="输出配置文件") output_frame.place(x=10, y=250, width=570, height=50) # 输出配置文件 output_config_button = SButton(output_frame, "选择输出目录", 10, 0) create_tooltip(output_config_button.button, "选择config.txt输出的目录") self.output_config_entry = SEntry( root=output_frame, textvariable=StringVar(), text=Configer.get_para("output_config"), x=100, y=4, width=360) create_tooltip(self.output_config_entry.entry, "输出config.txt文件的位置") output_config_button.bind_open_dir( self.output_config_entry.textvariable, title="选择输出目录") gen_config_button = SButton(output_frame, "输出", 470, 0) create_tooltip(gen_config_button.button, "开始输出") gen_config_button.button.bind("<Button-1>", self.output_config)
def _start_join(self): y = 250 join_button = SButton(root=self.root, text="结合", x=10, y=y) create_tooltip(join_button.button, "将配体和受体结合成一个文件") join_button.button.bind("<Button-1>", self._join) self.progress = Progressbar(self.root, mode="determinate") self.progress.place(x=100, y=y + 2, width=400) create_tooltip(self.progress, "结合进度") self.progress_label = SLabel(self.root, text="没有任务", x=510, y=y) text_y = 286 current_ligand_frame = Frame(self.root, width=400, height=40) current_ligand_frame.place(x=10, y=text_y) self.current_ligand = SLabel(root=current_ligand_frame, text="", x=0, y=0) # 是否保留提取配体 self.remain_ligand = SCheckbutton(self.root , text="保留提取构象", variable=StringVar(), value=Configer.get_para("remain_ligand"), x=10, y=text_y + 20) create_tooltip(self.remain_ligand.checkbutton, "保留提取或者转换的构象。")
def _choose_protein_frame(self): choose_protein_labelframe = LabelFrame(self.root, text="选择受体") choose_protein_labelframe.place(x=10, y=70, width=570, height=50) choose_proteins = SButton(root=choose_protein_labelframe, text="选择受体文件夹", x=10, y=0) create_tooltip( choose_proteins.button, "选择受体文件夹。受体必须命名为preped.pdbqt\n" "单个受体请选择包含这个受体的文件夹\n" "多个受体请选择包含多个受体文件夹的文件夹\n" "详情见帮助及教程") self.choose_proteins_entry = SEntry( root=choose_protein_labelframe, textvariable=StringVar(), text=Configer.get_para("choose_docking_proteins"), x=110, y=4, width=450) create_tooltip(self.choose_proteins_entry.entry, "包含受体的文件夹") choose_proteins.bind_open_dir( entry_text=self.choose_proteins_entry.textvariable, title="选择包含pdbqt受体的文件夹")
from tools.configer import Configer from tools.file_path import * obabel_path = Configer.get_para("obabel_path") python_path = Configer.get_para("python_path") def pdb_2_other(input_file, output_file): """ 使用obabel将pdb文件转换为其他文件 :param input_file: 输入的pdb文件 :param output_file: 输出的其他格式文件 :return 执行结果 """ cmd = "%s %s -O %s" % (obabel_path, input_file, output_file) convert_result(cmd, output_file) def pdbqt_2_pdb(input_file, output_file): """ 使用adt将pdbqt文件转pdb文件 :param input_file: 输入的pdbqt文件 :param output_file: 输出的pdb文件 """ cmd = "%s %s -f %s -o %s" % (python_path, pdbqt_to_pdb_path, input_file, output_file) convert_result(cmd, output_file) def pdb_mol2_2_pdbqt(input_file, output_file): """
def prepare_receptor(receptor: str, output_file: str, fix_method: str, preserve_charges: int, nphs: int, lps: int, waters: int, nonstdres: int): """ 使用ADT的prepareReceptor4准备受体。 :param receptor: 受体路径。比如D:/test/a.pdb :param output_file: 输出路径。比如D:/test :param fix_method: 修复方法。"bonds_hydrogens", "bonds", "hydrogens", "checkhydrogens", "None" :param preserve_charges: 保留电荷。1或者0 :param nphs:合并非极性氢。1或者0 :param lps:合并电荷。1或者0 :param waters:去水。1或者0 :param nonstdres:去除非标准氨基酸。1或者0 :return 准备成功返回真,失败返回假 """ u_para_list = [] if nphs: u_para_list.append("nphs") if lps: u_para_list.append("lps") if waters: u_para_list.append("waters") if nonstdres: u_para_list.append("nonstdres") u_paras = "" for u_para in u_para_list: if u_para == u_para_list[-1]: u_paras += u_para break u_paras += u_para + "_" # print(u_paras) if preserve_charges: # 保留电荷,做处理 if u_paras != "": cmd = "%s %s -r %s -o %s -A %s -C -U %s -e" % ( Configer.get_para("python_path"), prepare_receptor4_path, receptor, output_file, fix_method, u_paras) # 保留电荷,不做处理 else: cmd = "%s %s -r %s -o %s -A %s -C -e" % ( Configer.get_para("python_path"), prepare_receptor4_path, receptor, output_file, fix_method) else: # 不保留电荷,做处理 if u_paras != "": cmd = "%s %s -r %s -o %s -A %s -U %s -e" % ( Configer.get_para("python_path"), prepare_receptor4_path, receptor, output_file, fix_method, u_paras) # 不保留电荷,不处理 else: cmd = "%s %s -r %s -o %s -A %s -e" % ( Configer.get_para("python_path"), prepare_receptor4_path, receptor, output_file, fix_method) exit_code = os.system(cmd) if exit_code == 0: print("------------------------------------------------------------") print("%s准备成功" % receptor) print("------------------------------------------------------------") return True else: print("------------------------------------------------------------") print("%s准备失败,请尝试使用biopython进行修复。" % receptor) print("------------------------------------------------------------") return False
def _join(self, event): input_format = self.input_format.textvariable.get() input_ligands_full = self.choose_ligands_entry.entry.get() input_receptor = self.choose_proteins_entry.entry.get() output_dir = self.choose_output_entry.entry.get() choose_num = self.complex_ligand_num_entry.entry.get() remain = self.remain_ligand.variable.get() # 所有选择的路径和文件都不能为空。 if input_ligands_full == "" or input_receptor == "" or output_dir == "": messagebox.showerror("错误!", "输入不能为空!") return # 不能包括空格 if Check.has_space(input_ligands_full): messagebox.showerror("错误!", "配体路径不能包含空格!") return if Check.has_space(input_receptor): messagebox.showerror("错误!", "受体路径不能包含空格!") return if Check.has_space(output_dir): messagebox.showerror("错误!", "输出路径不能包含空格!") return # 选择构象要是数字 try: num = int(choose_num) except ValueError: messagebox.showerror("错误!", "提取的构象必须是数字!") return if num < 0: messagebox.showerror("错误!", "提取构象至少大于0!") return # 输出路径不存在则创建 if not os.path.exists(output_dir): os.mkdir(output_dir) # 受体格式必须是pdbqt if not input_receptor.endswith(".pdbqt"): messagebox.showerror("错误!", "输入的受体必须是pdbqt格式。") return input_ligands = [] # 输入的配体 if input_ligands_full.endswith(";"): # 如果是单个或者多个配体 if input_ligands_full.split(".")[-1][0:-1] != input_format: # 格式不匹配 messagebox.showerror("错误!", "配体格式不是所选格式!") return input_ligands.extend(input_ligands_full.split(";")[0:-1]) elif os.path.isdir(input_ligands_full): # 如果选择的是目录 list_file = os.listdir(input_ligands_full) for file in list_file: if file.endswith(input_format): input_ligands.append(input_ligands_full + os.sep + file) if len(input_ligands) == 0: messagebox.showerror("错误!", "所选文件夹中不包含%s格式的配体!" % input_format) return else: messagebox.showerror("错误!", "请检查输入的配体!") return # 检查路径是否正确 if not Check.check_python(): return obabel_path = Configer.get_para("obabel_path") if not Check.check_obabel(): return self.progress_label.label.configure(text="准备受体") self.progress_label.label.update() # 将受体pdbqt转成pdb input_pdb = output_dir + os.sep + input_receptor.split(".")[0].split(os.sep)[-1] + ".pdb" pdbqt_2_pdb(input_receptor, input_pdb) ligands = [] self.progress_label.label.configure(text="准备配体") self.progress_label.label.update() if input_format == "pdbqt": for ligand in input_ligands: # 是否是单个配体: with open(ligand, "r") as f: line = f.readline() if "MODEL" not in line: # 只有一个,直接转换成pdb pdb_ligand = output_dir + os.sep + ligand.split(".")[0].split(os.sep)[-1] + ".pdb" pdbqt_2_pdb(ligand, pdb_ligand) ligands.append(pdb_ligand) else: output_pdbqts = extract_pdbqt(ligand, output_dir, num) for output_pdbqt in output_pdbqts: output_pdb = output_pdbqt[:-2] pdbqt_2_pdb(output_pdbqt, output_pdb) os.remove(output_pdbqt) ligands.append(output_pdb) else: pdb_ligands = [] # 全部转换成pdb格式 for ligand in input_ligands: output_ligand = output_dir + os.sep + ligand.split(".")[0].split(os.sep)[-1] + ".pdb" ob(ligand, output_ligand) pdb_ligands.append(output_ligand) ligands = pdb_ligands # 进行复合 self.progress["maximum"] = len(ligands) for ligand in ligands: # 更新进度条 label_text = str(ligands.index(ligand) + 1) + os.sep + str(len(ligands)) self.progress_label.label.configure(text=label_text) self.progress_label.label.update() self.progress["value"] = ligands.index(ligand) + 1 self.progress.update() current_ligand = "当前配体:%s" % ligand.split(os.sep)[-1].split(".")[0] self.current_ligand.label.configure(text=current_ligand) self.current_ligand.label.update() output_name = ligand.split(os.sep)[-1].split(".")[0] + "_" + input_receptor.split(os.sep)[-1].split(".")[ 0] + ".pdb" output = output_dir + os.sep + output_name ob_join(ligand, input_pdb, output) # 如果不保留提取配体,删除提取配体 if input_format == "pdbqt" and remain == "0": for ligand in ligands: os.remove(ligand) # 删除受体 os.remove(input_pdb) messagebox.showinfo("成功!", "生成复合物成功!") self.progress_label.label.configure(text="没有任务") self.progress_label.label.update() self.progress["value"] = 0 self.progress.update() self.current_ligand.label.configure(text="") self.current_ligand.label.update()
def _create_main_frame(self): main_label_frame = LabelFrame(self.root, text="主要参数") main_label_frame.place(x=10, y=10, width=320, height=120) # center_x SLabel(main_label_frame, text="center_x = ", x=10, y=5) self.center_x = SEntry(main_label_frame, textvariable=StringVar(), text=Configer.get_para("center_x"), x=95, y=5, width=60) create_tooltip(self.center_x.entry, "对接位点的x坐标") # center_y SLabel(main_label_frame, text="center_y = ", x=10, y=35) self.center_y = SEntry(main_label_frame, textvariable=StringVar(), text=Configer.get_para("center_y"), x=95, y=35, width=60) create_tooltip(self.center_y.entry, "对接位点的y坐标") # center_z SLabel(main_label_frame, text="center_z = ", x=10, y=65) self.center_z = SEntry(main_label_frame, textvariable=StringVar(), text=Configer.get_para("center_z"), x=95, y=65, width=60) create_tooltip(self.center_z.entry, "对接位点的z坐标") # size_x SLabel(main_label_frame, text="size_x = ", x=175, y=5) self.size_x = SEntry(main_label_frame, textvariable=StringVar(), text=Configer.get_para("size_x"), x=245, y=5, width=60) create_tooltip(self.size_x.entry, "对接位点的x方向大小") # size_y SLabel(main_label_frame, text="size_y = ", x=175, y=35) self.size_y = SEntry(main_label_frame, textvariable=StringVar(), text=Configer.get_para("size_y"), x=245, y=35, width=60) create_tooltip(self.size_y.entry, "对接位点的y方向大小") # size_z SLabel(main_label_frame, text="size_z = ", x=175, y=65) self.size_z = SEntry(main_label_frame, textvariable=StringVar(), text=Configer.get_para("size_z"), x=245, y=65, width=60) create_tooltip(self.size_z.entry, "对接位点的z方向大小")
def cal_rmsd(self, event): self.windows = STopLevel(self.root, win_x=570, win_y=130, title="计算RMSD").toplevel # 参考配体 single_ligand_button = SButton(self.windows, text="选择参考配体", x=10, y=10) create_tooltip(single_ligand_button.button, "选择一个参考配体,只支持xyz格式") self.single_ligand_entry = SEntry( self.windows, textvariable=StringVar(), text=Configer.get_para("single_ligand") if self.single_ligand == "" else self.single_ligand, x=100, y=13, width=450) create_tooltip(self.single_ligand_entry.entry, "选择的参考配体") single_ligand_button.bind_open_file( entry_text=self.single_ligand_entry.textvariable, title="选择参考配体", file_type="xyz", parent=self.windows) # 比较配体 sec_ligand_button = SButton(self.windows, text="选择第二个配体", x=10, y=50) create_tooltip(sec_ligand_button.button, "选择需要比较的单个配体") sec_ligands_button = SButton(self.windows, text="选择文件夹", x=110, y=50) create_tooltip(sec_ligands_button.button, "选择第二个配体所在的文件夹") self.sec_ligands_entry = SEntry( self.windows, textvariable=StringVar(), text=Configer.get_para("sec_ligands") if self.sec_ligands == "" else self.sec_ligands, x=200, y=53, width=350) create_tooltip(self.sec_ligands_entry.entry, "选择需要比较的配体") sec_ligand_button.bind_open_file( entry_text=self.sec_ligands_entry.textvariable, title="选择需要比较的配体", file_type="xyz", parent=self.windows) sec_ligands_button.bind_open_dir( entry_text=self.sec_ligands_entry.textvariable, title="选择需要比较的配体所在的文件夹", parent=self.windows) SLabel(root=self.windows, text="旋转方法", x=10, y=90) rotate_method_text = ("none", "kabsch", "quaternion") self.rotate_method_box = SCombbox( root=self.windows, textvariable=StringVar(), values=rotate_method_text, default_value=Configer.get_para("rotate_method") if self.rotate_method == "" else self.rotate_method, x=70, y=90, width=85) create_tooltip(self.rotate_method_box.combobox, "是否旋转原子和旋转方法") SLabel(root=self.windows, text="原子对齐方法", x=170, y=90) reorder_method_text = ("hungarian", "distance") self.reorder_method_box = SCombbox( root=self.windows, textvariable=StringVar(), values=reorder_method_text, default_value=Configer.get_para("reorder_method") if self.reorder_method == "" else self.reorder_method, x=260, y=90, width=85) create_tooltip(self.rotate_method_box.combobox, "是否旋转原子和旋转方法") rmsd_button = SButton(self.windows, "计算RMSD", x=465, y=90) create_tooltip(rmsd_button.button, "计算RMSD") rmsd_button.button.bind("<Button-1>", self._cal_rmsd) # 关闭窗口保存参数 self.windows.protocol( "WM_DELETE_WINDOW", lambda: self.save_rmsd( self.windows, self.single_ligand_entry.textvariable.get(), self.sec_ligands_entry.textvariable.get(), self.rotate_method_box.textvariable.get(), self.reorder_method_box.textvariable.get()))