Пример #1
0
    def _write_pymol_isoslider(self, hr):
        """
        generates the commands for an isoslider

        :param hr: a hotspot result
        :type hr: `hotspots.results.Results`
        """
        # Isosurface obj's take the name: "surface_{probe ID}_{hotpsot ID}"
        # e.g. "surface_apolar_hotspotA"
        if not isinstance(hr, list):
            hr = [hr]

        # the hotspot grids are always output
        surface_dic = {h.identifier: {'fhm': [f"surface_{g}_{h.identifier}" for g in h.super_grids.keys()]}
                       for h in hr}

        surface_value_dic = {h.identifier: {"fhm": max([round(g.extrema[1], 1) for g in h.super_grids.values()])}
                             for h in hr}

        for h in hr:
            if self.settings.output_superstar and h.superstar:
                surface_dic[h.identifier].update({'superstar': [f"surface_superstar_{g}_{h.identifier}"
                                                                for g in h.superstar.keys()]})

                surface_value_dic[h.identifier].update({'superstar': max([round(g.extrema[1], 1)
                                                                          for g in h.superstar.values()])})

            if self.settings.output_weighted and h.weighted_superstar:
                surface_dic[h.identifier].update({'weighted': [f"surface_weighted_superstar_{g}_{h.identifier}"
                                                                for g in h.weighted_superstar.keys()]})

                surface_value_dic[h.identifier].update({'weighted': max([round(g.extrema[1], 1)
                                                                          for g in h.weighted_superstar.values()])})

            if self.settings.output_buriedness and h.buriedness:
                surface_dic[h.identifier].update({'buriedness': [f"surface_buriedness_{h.identifier}"]})

                surface_value_dic[h.identifier].update({'buriedness': 8})

        min_value = 0
        print(surface_dic)
        print(surface_value_dic)

        self.pymol_out.commands += PyMOLCommands.isoslider(surface_dic, surface_value_dic)
Пример #2
0
    def pymol_visulisation(self, outdir=None, fname="pymol_file.py"):
        if not outdir:
            outdir = os.getcwd()

        if not os.path.exists(outdir):
            os.mkdir(outdir)

        if self.ligands:
            with MoleculeWriter(os.path.join(outdir, "ligands.mol2")) as w:
                for ligand in self.ligands:
                    try:
                        w.write(ligand.molecule)
                    except AttributeError:
                        w.write(ligand)

        if self.protein:
            with MoleculeWriter(os.path.join(outdir, "protein.mol2")) as w:
                w.write(self.protein.molecule)

        self.pymol_out = PyMOLFile()

        if self.ligands:
            self.pymol_out.commands += PyMOLCommands.load(
                "ligands.mol2", "ligands")

        if self.protein:
            self.pymol_out.commands += PyMOLCommands.load(
                "protein.mol2", "protein")

        # write out point spheres and projection sphere and lines if applicable
        self.pymol_out.commands += self.features_to_pymol_strings(
            self.detected_features)

        if self.feature_point_grids:
            for identifier, g in self.feature_point_grids.items():
                g.write(os.path.join(outdir, f"{identifier}.grd"))

                point_colour = rgb_to_decimal(
                    self.feature_definitions[identifier].colour)
                self.pymol_out.commands += PyMOLCommands.set_color(
                    f"{identifier}_color", point_colour)
                self.pymol_out.commands += PyMOLCommands.load(
                    f"{identifier}.grd", f"{identifier}_grid")
                self.pymol_out.commands += PyMOLCommands.isosurface(
                    f"{identifier}_grid",
                    f"surface_{identifier}",
                    level=1,
                    color=f"{identifier}_color")

            self.pymol_out.commands += PyMOLCommands.group(
                "feature_grids", self.feature_point_grids.keys())
            self.pymol_out.commands += PyMOLCommands.group(
                "feature_grids",
                [f"surface_{a}" for a in self.feature_point_grids])

            min_value = 0
            surface_dic = {
                self.identifier: {
                    'feature_grids':
                    [f"surface_{g}" for g in self.feature_point_grids.keys()]
                }
            }

            surface_value_dic = {
                self.identifier: {
                    "feature_grids":
                    max([
                        round(g.extrema[1], 1)
                        for g in self.feature_point_grids.values()
                    ])
                }
            }

            self.pymol_out.commands += PyMOLCommands.isoslider(
                surface_dic, surface_value_dic)

        self.pymol_out.write(os.path.join(outdir, fname))