Example #1
0
    def test_isosurface(self):
        self.pymol_file.commands += PyMOLCommands.set_color(
            "pomegranate", self.pomegranate)
        self.pymol_file.commands += PyMOLCommands.isosurface(
            "test_grid.grd", "mygrid", "mysurface", 4, "pomegranate")

        self.pymol_file.write("testdata/wrapper_pymol/test_isosurface.py")
Example #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))