Esempio n. 1
0
    def extract_file(self, event):
        output_file = self.choose_output_entry.textvariable.get()
        extract_path = self.choose_extract_folder_entry.textvariable.get()

        if Check.check_path(output_file) or Check.check_path(extract_path):
            messagebox.showerror("错误", "路径不能有空或者有空格")
            return

        if not output_file.endswith(".txt"):
            messagebox.showerror("错误", "输入必须为txt文件!")
            return

        if not extract_file(output_file, extract_path):
            messagebox.showerror("错误!", "输入文件内容无法识别!" "具体参见命令行。")
            return
        messagebox.showinfo("成功", "成功提取配体!")
Esempio n. 2
0
    def move_file(self, event):
        proteins_dir = self.choose_pdbqt_dir_entry.textvariable.get()

        if Check.check_path(proteins_dir):
            messagebox.showerror("路径不为空,不能包括空格!")
            return

        if not os.path.exists(proteins_dir):
            messagebox.showerror("错误", "选择文件夹不存在")
            return

        proteins2dir(proteins_dir)
        messagebox.showinfo("成功", "文件成功移动!")
Esempio n. 3
0
    def generate_configs(self, event):
        ligand = self.choose_ligand_entry.textvariable.get()
        proteins_dir = self.choose_receptor_entry.textvariable.get()

        if Check.check_path(ligand) or Check.check_path(proteins_dir):
            messagebox.showerror("错误", "路径不能空或者包含空格!")
            return

        if not ligand.endswith(".pdbqt"):
            messagebox.showerror("错误", "受体必须是pdbqt格式")
            return

        receptors_dir = []

        # 如果是一个受体文件夹
        if os.path.exists(proteins_dir + os.sep + "preped.pdbqt"):
            receptors_dir.append(proteins_dir + os.sep + "preped.pdbqt")
        else:
            for receptor in os.listdir(proteins_dir):
                pdbqt_file = proteins_dir + os.sep + receptor + os.sep + "preped.pdbqt"
                if os.path.exists(pdbqt_file):
                    receptors_dir.append(pdbqt_file)
                else:
                    print("%s中没有preped.pdbqt文件" % receptor)

        if len(receptors_dir) == 0:
            messagebox.showerror("错误", "没有检测到受体文件!")
            return

        for receptor_dir in receptors_dir:
            gen_config(receptor_dir, ligand)
            print(
                "------------------------------------------------------------")
            print("%s准备成功!" % receptor_dir)
            print(
                "------------------------------------------------------------")

        messagebox.showinfo("成功", "已经生成多个配置文件!")
Esempio n. 4
0
    def extract_score(self, event):
        score_file = self.choose_scores_entry.textvariable.get()

        if Check.check_path(score_file):
            messagebox.showerror("错误", "路径不能为空或者包含空格!")
            return

        # 如果是单个pdbqt文件,弹出窗口直接显示结果。
        if score_file.endswith(".pdbqt"):

            scores = read_scores(score_file)

            if len(scores) == 0:
                messagebox.showerror("错误", "选择的文件中没有检测到分数!")
                return

            file_name = os.path.split(score_file)[-1][0:-6]
            score_top = SMultiTopLevel(self.root, 600, 100, file_name).toplevel
            SLabel(score_top, text="当前文件:" + file_name, x=10, y=0)

            SLabel(score_top, text="number", x=10, y=30)
            SLabel(score_top, text="scores", x=10, y=60)
            i = 0
            while i < len(scores):
                SLabel(score_top, text=str(i + 1), x=80 + (50 * i), y=30)
                SLabel(score_top, text=scores[i], x=80 + (50 * i), y=60)
                i += 1

        # 如果是文件夹,在该文件夹中生成分数文件
        elif os.path.isdir(score_file):
            output_file = score_file + os.sep + "scores.txt"
            # 如果是子目录,没有受体,只输出分数最高的
            if os.listdir(score_file)[0].endswith(".pdbqt"):
                scores = read_folder_scores(score_file, mode=1)
                create_scores_file(output_file, scores, mode=1)
            else:
                scores = read_root_folder_scores(score_file, mode=1)
                create_scores_file(output_file, scores, mode=0)
            messagebox.showinfo("保存成功!", "保存分数文件到%s" % output_file)
        else:
            messagebox.showerror("输入错误", "请选择pdbqt文件或者选择文件夹!")
            return
Esempio n. 5
0
    def _gen_smi(self, event):

        if not Check.check_obabel():
            messagebox.showerror("错误!", "请检查obabel路径是否配置正确!")
            return

        smi = self.input_smi_entry.textvariable.get()
        output_path = self.output_path_entry.textvariable.get()

        if Check.check_path(output_path):
            messagebox.showerror("错误", "输出路径不能为空或者包含空格!")
            return

        # 如果只有一个元素则表示没有[R]标签
        if len(smi.split("[R]")) == 1:
            messagebox.showerror("错误", "%s没有[R]标签!" % smi)
            return

        gen_smi_der(smi, output_path)
        messagebox.showinfo("成功!", "成功生成衍生物!\n请检查后使用。")
Esempio n. 6
0
    def _docking(self, event):
        input_ligands_full = self.choose_ligand_entry.entry.get()
        receptor_dir = self.choose_proteins_entry.entry.get()
        output_dir = self.choose_output_entry.entry.get()
        docking_times = self.times_entry.entry.get()

        # 所有选择的路径和文件都不能为空和包含空格。
        if (Check.check_path(input_ligands_full)
                or Check.check_path(receptor_dir)
                or Check.check_path(output_dir)
                or Check.check_path(docking_times)):
            messagebox.showerror("输入错误", "所有参数不能为空或者包含空格")
            return

        try:
            times = int(docking_times)
        except ValueError:
            messagebox.showerror("错误!", "对接次数必须是数字!")
            return

        # 如果不存在输出文件夹就创建
        if not os.path.exists(output_dir):
            os.mkdir(output_dir)

        input_ligands = []

        # 输入的配体
        if input_ligands_full.endswith(";"):  # 如果是单个或者多个配体
            # 必须是pdbqt文件
            if input_ligands_full.split(".")[-1][0:-1] != "pdbqt":
                messagebox.showerror("错误!", "配体必须是pdbqt格式!")
                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("pdbqt"):
                    input_ligands.append(input_ligands_full + os.sep + file)
            if len(input_ligands) == 0:
                messagebox.showerror("错误!", "所选文件夹中不包含pdbqt格式的配体!")
                return
        else:
            messagebox.showerror("错误!", "请检查输入的配体!")
            return

        # 输入的受体
        receptors = []
        # 选择了一个受体
        if os.path.exists("%s" % receptor_dir + os.sep + "preped.pdbqt"):
            if not Check.check_config(receptor_dir):
                messagebox.showerror("错误!", "受体中没有config.txt文件!")
                return
            receptors.append("%s" % receptor_dir + os.sep + "preped.pdbqt")
        # 可能选择了多个受体
        else:
            if not os.path.exists(receptor_dir):
                messagebox.showerror("错误!", "所选受体目录不存在!")
                return
            child_receptor = os.listdir(receptor_dir)
            for receptor in child_receptor:
                if os.path.exists("%s" % receptor_dir + os.sep +
                                  "%s" % receptor + os.sep + "preped.pdbqt"):
                    if not Check.check_config("%s" % receptor_dir + os.sep +
                                              "%s" % receptor):
                        messagebox.showwarning(
                            "警告!", "受体%s中没有config.txt文件,将不进行对接!" % receptor)
                        continue
                    receptors.append("%s" % receptor_dir + os.sep +
                                     "%s" % receptor + os.sep + "preped.pdbqt")
        if len(receptors) == 0:
            messagebox.showerror("错误!", "没有受体,请检查选择的文件夹或者子文件夹中是否"
                                 "包含preped.pdbqt文件!")
            return

        self.progress["maximum"] = len(receptors) * len(input_ligands)
        for receptor in receptors:
            # 在输出目录创建受体的文件夹
            output_dir_r = "%s" % output_dir + os.sep + "%s" % receptor.split(
                os.sep)[-2]
            # 读取受体中的config文件
            config_files = get_config_files(os.path.split(receptor)[0])
            if not os.path.exists(output_dir_r):
                os.mkdir(output_dir_r)

            for ligand in input_ligands:
                # 初始化循环次数
                i = 0

                # 更新进度条和标签
                current_num = receptors.index(receptor) * len(
                    input_ligands) + input_ligands.index(ligand) + 1
                max_num = len(receptors) * len(input_ligands)
                label_text = "%s/%s" % (current_num, max_num)

                self.progress_label.label.configure(text=label_text)
                self.progress_label.label.update()

                self.progress["value"] = current_num
                self.progress.update()

                current_protein = "当前受体:%s" % receptor.split(os.sep)[-2]
                self.current_protein.label.configure(text=current_protein)
                self.current_protein.label.update()

                current_ligand = "当前配体:%s" % ligand.split(
                    os.sep)[-1].split(".")[0]
                self.current_ligand.label.configure(text=current_ligand)
                self.current_ligand.label.update()

                current_time = "当前次数:%i" % (i + 1)
                self.current_time.label.configure(text=current_time)
                self.current_time.label.update()

                # 开始对接
                while i < times:
                    dock_time = i + 1
                    for config in config_files:
                        ligand_basename = ligand.split(
                            os.sep)[-1].split(".")[0]
                        config_name = os.path.splitext(config)[0].split(
                            os.sep)[-1]
                        output = "%s" % output_dir_r + os.sep +\
                                 "%s_%s_out%s.pdbqt" % (ligand_basename, config_name, dock_time)
                        print(output)
                        vina_dock(ligand, receptor, config, output)
                    i += 1
        messagebox.showinfo("成功!", "对接完成!")
        self.progress_label.label.configure(text="没有任务")
        self.progress_label.label.update()

        self.progress["value"] = 0
        self.progress.update()

        self.current_protein.label.configure(text="")
        self.current_protein.label.update()

        self.current_ligand.label.configure(text="")
        self.current_ligand.label.update()

        self.current_time.label.configure(text="")
        self.current_time.label.update()
Esempio n. 7
0
    def _cal_rmsd(self, event):
        single_ligand = self.single_ligand_entry.textvariable.get()
        sec_ligands = self.sec_ligands_entry.textvariable.get()
        rotate_method = self.rotate_method_box.textvariable.get()
        reorder_method = self.reorder_method_box.textvariable.get()

        if Check.check_path(single_ligand) or Check.check_path(sec_ligands):
            messagebox.showerror("错误", "选择的文件或者路径不能为空或者包括空格!")
            return

        if not Check.check_obabel():
            messagebox.showerror("错误!", "Obabel配置不正确!")
            return

        sec_ligands_path = []
        # 如果选择的是一个文件
        if os.path.isfile(sec_ligands):
            sec_ligands_path.append(sec_ligands)
        # 如果选的是多个文件
        elif os.path.isdir(sec_ligands):
            list_file = os.listdir(sec_ligands)
            for file in list_file:
                if file.endswith("xyz"):
                    sec_ligands_path.append(sec_ligands + os.sep + file)
            if len(sec_ligands_path) == 0:
                messagebox.showerror("错误!", "所选文件夹中不包含xyz的配体!")
                return
        else:
            messagebox.showerror("错误!请检查输入的配体!")
            return

        rmsds = {}

        for sec_ligand_path in sec_ligands_path:
            rmsd = charnley_cal_rmsd(single_ligand, sec_ligand_path,
                                     rotate_method, reorder_method)
            if rmsd:
                rmsds[os.path.split(sec_ligand_path)[-1][:-4]] = rmsd
            else:
                print("%s无法计算RMSD!" % sec_ligand_path)
                continue

        if len(rmsds) == 1:
            top = SMultiTopLevel(self.windows,
                                 win_x=400,
                                 win_y=100,
                                 title="RMSD结果").toplevel
            for ligand in rmsds:
                text = "%s    vs    %s" % (os.path.split(single_ligand)[-1]
                                           [:-4], os.path.split(ligand)[-1])
                SLabel(top, text=text, x=10, y=10)
                text = rmsds[ligand]
                SLabel(top, text=text, x=10, y=50)
        elif len(rmsds) == 0:
            messagebox.showerror("错误!", "没有得到RMSD值!")
            return
        else:
            # 多个输出文件到目录中
            output_filename = os.path.join(sec_ligands, "rmsd.txt")
            with open(output_filename, "w") as f:
                f.writelines("second_ligand\trmsd\n")
                for ligand in rmsds:
                    f.write("%s\t%s\n" % (ligand, rmsds[ligand]))
            messagebox.showinfo("成功!", "成功导出rmsd结果到%s" % output_filename)