コード例 #1
0
    def extract(self, event):
        input_format = self.input_format.textvariable.get()
        input_ligands_full = self.choose_ligands_entry.entry.get()
        output_dir = self.extract_output_entry.entry.get()
        choose_num = self.complex_ligand_num_entry.entry.get()

        # 所有选择的路径和文件都不能为空。
        if input_ligands_full == "" or output_dir == "":
            messagebox.showerror("错误!", "输入不能为空!")
            return

        # 不能包括空格
        if Check.has_space(input_ligands_full):
            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)

        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

        for ligand in input_ligands:
            extract_pdbqt(ligand, output_dir, num)
        messagebox.showinfo("成功", "成功导入文件!")
コード例 #2
0
    def _start_convert(self, event):
        if not Check.check_obabel():
            return

        if not Check.check_python():
            return

        input_files = self.choose_ligands_entry.textvariable.get()

        # 判断输入内容不能包含空格
        if Check.has_space(input_files):
            messagebox.showerror("输入错误!", "输入路径不能包含空格!")
            return

        input_format = self.input_format.textvariable.get()
        input_ligands = []

        # 判断输入的内容
        if input_files.endswith(";"):
            if input_files.split(".")[-1][0:-1] != input_format:
                messagebox.showerror("错误!", "选择的配体和输入的配体不符合!")
                return
            input_ligands.extend(input_files.split(";")[0:-1])
        elif os.path.isdir(input_files):
            list_file = os.listdir(input_files)
            for file in list_file:
                if file.endswith(input_format):
                    input_ligands.append(input_files + os.sep + file)
            if len(input_ligands) == 0:
                messagebox.showerror("错误!", "所选文件夹中不包含选择格式的配体!")
                return
        else:
            messagebox.showerror("错误!", "请检查输入的配体!")
            return

        ph = self.ph.textvariable.get()
        # ph不能为空
        if ph == "":
            messagebox.showerror("错误!", "请输入pH!")
            return

        gen3d = self.gen3d.variable.get()
        is_minimize = self.is_minimize.variable.get()
        minimize = self.minimize.textvariable.get()
        output_format = self.output_format.textvariable.get()
        output_path = self.choose_output_dir_entry.textvariable.get()

        # 输出目录不能为空
        if output_path == "" or output_path.count(" ") > 0:
            messagebox.showerror("输入错误!", "输出路径不能包含空格!")
            return
        if not os.path.exists(output_path):
            messagebox.showerror("输入错误!", "输出路径不存在!")
            return

        if input_format == output_format:
            messagebox.showerror("错误!", "输入和输出格式不应相等!")
            return

        output_ligands = []

        for ligand in input_ligands:
            ligand_name = ligand.split(
                os.sep)[-1].split(".")[0] + "." + output_format
            output_ligands.append(output_path + os.sep + ligand_name)

        self.progress["maximum"] = len(input_ligands)

        # 进行格式转换
        if input_format == "pdbqt":  # pdbqt->other
            # pdbqt->pdb
            if output_format == "pdb":
                i = 0
                while i < len(input_ligands):
                    # 更改标签文字
                    label_text = "%i/%i" % (i + 1, len(input_ligands))
                    self.progress_label.label.configure(text=label_text)
                    self.progress_label.label.update()

                    # 更新进度条
                    self.progress["value"] = i + 1
                    self.progress.update()

                    pdbqt_2_pdb(input_ligands[i], output_ligands[i])
                    i += 1
                messagebox.showinfo("转换完成!", "成功将pdbqt转换成pdb!")
                self.progress["value"] = 0
                self.progress_label.label.configure(text="没有任务")
                return
            # pdbqt->other
            else:
                # obabel转换成输出格式,先转成pdb
                pdb_ligands = []
                for ligand in input_ligands:
                    ligand_name = ligand.split(
                        os.sep)[-1].split(".")[0] + ".pdb"
                    pdb_ligands.append(output_path + os.sep + "tmp" + os.sep +
                                       ligand_name)

                self.progress["maximum"] = len(input_ligands) * 2

                mk_output_dir(output_path + os.sep + "tmp")  # 创建临时文件夹

                i = 0
                while i < len(input_ligands):
                    label_text = "%i/%i" % (i + 1, len(input_ligands))
                    self.progress_label.label.configure(text=label_text)
                    self.progress_label.label.update()

                    self.progress["value"] = i + 1
                    self.progress.update()

                    pdbqt_2_pdb(input_ligands[i], pdb_ligands[i])
                    i += 1

                i = 0
                while i < len(input_ligands):
                    # 更改标签文字
                    label_text = "%i/%i" % (i + 1, len(input_ligands))
                    self.progress_label.label.configure(text=label_text)
                    self.progress_label.label.update()

                    # 更新进度条
                    self.progress["value"] = i + 1 + len(input_ligands)
                    self.progress.update()

                    pdb_2_other(pdb_ligands[i], output_ligands[i])
                    i += 1

                # 删除临时pdb文件
                shutil.rmtree(output_path + os.sep + "tmp")
                messagebox.showinfo("转换完成!", "成功将pdbqt转换%s!" % output_format)
                self.progress["value"] = 0
                self.progress_label.label.configure(text="没有任务")
                return

        # pdb/mol2->pdbqt
        elif (input_format == "pdb"
              or input_format == "mol2") and output_format == "pdbqt":
            i = 0
            while i < len(input_ligands):
                # 更改标签文字
                label_text = "%i/%i" % (i + 1, len(input_ligands))
                self.progress_label.label.configure(text=label_text)
                self.progress_label.label.update()

                # 更新进度条
                self.progress["value"] = i + 1 + len(input_ligands)
                self.progress.update()

                pdb_mol2_2_pdbqt(input_ligands[i], output_ligands[i])
                i += 1
            messagebox.showinfo("转换完成!", "成功将%s转换pdbqt!" % input_format)
            self.progress["value"] = 0
            self.progress_label.label.configure(text="没有任务")
            return

        else:
            # mol/smi->pdbqt
            if input_format == "mol" or input_format == "smi" and output_format == "pdbqt":
                pdb_ligands = []
                for ligand in input_ligands:
                    ligand_name = ligand.split(
                        os.sep)[-1].split(".")[0] + ".pdb"
                    pdb_ligands.append(output_path + os.sep + "tmp" + os.sep +
                                       ligand_name)

                self.progress["maximum"] = len(input_ligands) * 2

                mk_output_dir(output_path + os.sep + "tmp")  # 创建临时文件夹

                i = 0
                while i < len(input_ligands):
                    label_text = "%i/%i" % (i + 1, len(input_ligands))
                    self.progress_label.label.configure(text=label_text)
                    self.progress_label.label.update()

                    self.progress["value"] = i + 1
                    self.progress.update()

                    two_d_2_pdb(input_ligands[i], pdb_ligands[i], ph, minimize)
                    i += 1

                i = 0
                while i < len(input_ligands):
                    # 更改标签文字
                    label_text = "%i/%i" % (i + 1, len(input_ligands))
                    self.progress_label.label.configure(text=label_text)
                    self.progress_label.label.update()

                    # 更新进度条
                    self.progress["value"] = i + 1 + len(input_ligands)
                    self.progress.update()

                    pdb_mol2_2_pdbqt(pdb_ligands[i], output_ligands[i])
                    i += 1
                # 删除临时pdb文件
                shutil.rmtree(output_path + os.sep + "tmp")
                messagebox.showinfo("转换完成!", "成功将%s转换pdbqt!" % input_format)
                self.progress["value"] = 0
                self.progress_label.label.configure(text="没有任务")
                return
            # sdf->pdbqt
            elif (input_format == "sdf"
                  or input_format == "xyz") and output_format == "pdbqt":
                # 先转pdb
                pdb_ligands = []
                for ligand in input_ligands:
                    ligand_name = ligand.split(
                        os.sep)[-1].split(".")[0] + ".pdb"
                    pdb_ligands.append(output_path + os.sep + "tmp" + os.sep +
                                       ligand_name)

                self.progress["maximum"] = len(input_ligands) * 2

                mk_output_dir(output_path + os.sep + "tmp")  # 创建临时文件夹

                i = 0
                while i < len(input_ligands):
                    label_text = "%i/%i" % (i + 1, len(input_ligands))
                    self.progress_label.label.configure(text=label_text)
                    self.progress_label.label.update()

                    self.progress["value"] = i + 1
                    self.progress.update()

                    three_d_2_pdb(input_ligands[i], pdb_ligands[i],
                                  is_minimize, minimize)
                    i += 1

                i = 0
                while i < len(input_ligands):
                    # 更改标签文字
                    label_text = "%i/%i" % (i + 1, len(input_ligands))
                    self.progress_label.label.configure(text=label_text)
                    self.progress_label.label.update()

                    # 更新进度条
                    self.progress["value"] = i + 1 + len(input_ligands)
                    self.progress.update()

                    pdb_mol2_2_pdbqt(pdb_ligands[i], output_ligands[i])
                    i += 1
                # 删除临时pdb文件
                shutil.rmtree(output_path + os.sep + "tmp")
                messagebox.showinfo("转换完成!", "成功将%s转换pdbqt!" % input_format)
                self.progress["value"] = 0
                self.progress_label.label.configure(text="没有任务")
                return
            # mol/smi/sdf/mol2/pdb/xyz->pdb/sdf/mol2/xyz
            else:
                if gen3d == "1":
                    # 3D并最小化
                    if is_minimize == "1":
                        i = 0
                        while i < len(input_ligands):
                            label_text = "%s/%s" % (i + 1, len(input_ligands))
                            self.progress_label.label.configure(
                                text=label_text)
                            self.progress_label.label.update()

                            self.progress["value"] = i + 1
                            self.progress.update()

                            ob_3d_min(input_ligands[i], output_ligands[i], ph,
                                      minimize)
                            i += 1
                        messagebox.showinfo(
                            "成功!",
                            "成功将%s转换成%s!" % (input_format, output_format))
                        self.progress["value"] = 0
                        self.progress_label.label.configure(text="没有任务")
                    # 3D不最小化
                    else:
                        i = 0
                        while i < len(input_ligands):
                            label_text = "%s/%s" % (i + 1, len(input_ligands))
                            self.progress_label.label.configure(
                                text=label_text)
                            self.progress_label.label.update()

                            self.progress["value"] = i + 1
                            self.progress.update()

                            ob_3d(input_ligands[i], output_ligands[i], ph)
                            i += 1
                        messagebox.showinfo(
                            "成功!",
                            "成功将%s转换成%s!" % (input_format, output_format))
                        self.progress["value"] = 0
                        self.progress_label.label.configure(text="没有任务")
                else:
                    # 不3D并最小化
                    if is_minimize == "1":
                        i = 0
                        while i < len(input_ligands):
                            label_text = "%s/%s" % (i + 1, len(input_ligands))
                            self.progress_label.label.configure(
                                text=label_text)
                            self.progress_label.label.update()

                            self.progress["value"] = i + 1
                            self.progress.update()

                            ob_min(input_ligands[i], output_ligands[i], ph,
                                   minimize)
                            i += 1
                        messagebox.showinfo(
                            "成功!",
                            "成功将%s转换成%s!" % (input_format, output_format))
                        self.progress["value"] = 0
                        self.progress_label.label.configure(text="没有任务")
                    # 不3D也不最小化
                    else:
                        i = 0
                        while i < len(input_ligands):
                            label_text = "%s/%s" % (i + 1, len(input_ligands))
                            self.progress_label.label.configure(
                                text=label_text)
                            self.progress_label.label.update()

                            self.progress["value"] = i + 1
                            self.progress.update()

                            ob(input_ligands[i], output_ligands[i])
                            i += 1
                        messagebox.showinfo(
                            "成功!",
                            "成功将%s转换成%s!" % (input_format, output_format))
                        self.progress["value"] = 0
                        self.progress_label.label.configure(text="没有任务")
コード例 #3
0
    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()