Пример #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")
Пример #2
0
        def visualise(g, gname, peaks):
            # visualise
            gobj_name = f"{gname}_grid"
            surface_objname = f"surface_{gobj_name}"
            vis = f"testdata/grid_extension/{gname}.py"
            gpath = f"testdata/grid_extension/{gname}.grd"

            g.write(gpath)

            f = PyMOLFile()
            f.commands += PyMOLCommands.load(fname=f"{gname}.grd",
                                             objname=gobj_name)
            f.commands += PyMOLCommands.isosurface(
                grd_name=gobj_name,
                isosurface_name=surface_objname,
                level=5,
                color="yellow")

            for i, p in enumerate(peaks):
                f.commands += PyMOLCommands.sphere(objname=f"peak_obj_{i}",
                                                   rgba=[1, 1, 1, 1],
                                                   coords=p,
                                                   radius=0.5)
                f.commands += PyMOLCommands.load_cgo(obj=f"peak_obj_{i}",
                                                     objname=f"peak_{i}")

            f.write(vis)
Пример #3
0
    def _write_pymol_isosurfaces(self, dict, relpath, identifier, dict_type):
        """
        Loads grids and generates isosurfaces

        :param dict: interaction grid dictionary
        :param relpath: result containing directory
        :param identifier: hotspot identifier
        :param dict_type: superstar, fhm or weighted_superstar

        :type dict: dict
        :type relpath: str
        :type identifier: str
        :type dict_type: str

        :return: pymol commands
        :rtype: str
        """
        cmd = ""
        default_level = 5
        # load grids and create isosurfaces
        group_members = []
        for p in dict.keys():
            if dict_type == 'fhm':
                objname = f'{p}_{identifier}'
                fname = f'{relpath}/{p}{self.settings.grid_extension}'
            else:
                objname = f'{dict_type}_{p}_{identifier}'
                fname = f'{relpath}/{dict_type}_{p}{self.settings.grid_extension}'
            cmd += PyMOLCommands.load(fname=fname, objname=objname)

            # surface_10_apolar_hotspotid
            surface_objname = f'surface_{objname}'
            cmd += PyMOLCommands.isosurface(grd_name=objname,
                                            isosurface_name=surface_objname,
                                            level=default_level,
                                            color=self.settings.colour_dict[p])

            cmd += PyMOLCommands.pymol_set(setting_name='transparency',
                                           value=self.settings.transparency,
                                           selection=surface_objname)

            group_members.extend([objname, f"surface_{objname}"])

        cmd += PyMOLCommands.group(group_name=identifier,
                                   members=group_members)
        return cmd
Пример #4
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))
Пример #5
0
    def _write_pymol_objects(self, relpath, hr, load_prot=True):
        """
        generates pymol commands associated with an indivdual hotspot

        :param relpath: path to the directory holding associated files
        :param hr: hotspot result

        :type relpath: str
        :type hr: `hotspots.results.Results`

        """
        self.pymol_out.commands += self._write_pymol_isosurfaces(
            hr.super_grids, relpath, hr.identifier, "fhm")

        if self.settings.output_superstar and hr.superstar:
            self.pymol_out.commands += self._write_pymol_isosurfaces(
                hr.superstar, relpath, hr.identifier, "superstar")

        if self.settings.output_weighted and hr.weighted_superstar:
            self.pymol_out.commands += self._write_pymol_isosurfaces(
                hr.weighted_superstar, relpath, hr.identifier, "weighted")

        if self.settings.output_buriedness and hr.buriedness:
            default_level = 3
            objname = f'buriedness_{hr.identifier}'
            fname = f'{relpath}/buriedness{self.settings.grid_extension}'

            self.pymol_out.commands += PyMOLCommands.load(fname=fname,
                                                          objname=objname)

            # surface_10_apolar_hotspotid
            surface_objname = f'surface_{objname}'
            self.pymol_out.commands += PyMOLCommands.isosurface(
                grd_name=objname,
                isosurface_name=surface_objname,
                level=default_level,
                color=self.settings.colour_dict["buriedness"])

            self.pymol_out.commands += PyMOLCommands.pymol_set(
                setting_name='transparency',
                value=self.settings.transparency,
                selection=surface_objname)

        group_members = [
            f'buriedness_{hr.identifier}',
            f'surface_buriedness_{hr.identifier}'
        ]

        self.pymol_out.commands += PyMOLCommands.group(
            group_name=hr.identifier, members=group_members)

        # generate grid labels
        labels = hr.grid_labels()

        for p, dic in labels.items():
            i = 0
            group_me = []
            for coord, value in dic.items():
                objname = f"PS_{p}_{hr.identifier}_{i}"
                group_me.append(objname)
                self.pymol_out.commands += PyMOLCommands.pseudoatom(
                    objname=objname, coords=coord, label=f'{round(value, 1)}')
                group_me.append(objname)
                i += 1
            self.pymol_out.commands += PyMOLCommands.group(
                f'label_{p}_{hr.identifier}', group_me)

        self.pymol_out.commands += PyMOLCommands.group(
            f"labels_{hr.identifier}",
            [f'label_{p}_{hr.identifier}' for p in hr.super_grids.keys()])

        # load up the protein
        if load_prot:
            self.pymol_out.commands += PyMOLCommands.load(
                f'{relpath}/protein.pdb', f'protein_{hr.identifier}')
            if len(self.settings.protein_color_dic) > 0:
                self.pymol_out += PyMOLCommands.color(
                    "slate", f'protein_{hr.identifier}')
            self.pymol_out.commands += PyMOLCommands.show(
                "cartoon", f'protein_{hr.identifier}')
            self.pymol_out.commands += PyMOLCommands.hide(
                "line", f'protein_{hr.identifier}')
            self.pymol_out.commands += PyMOLCommands.show("sticks", "organic")