Ejemplo n.º 1
0
    def test_neighbourhood(self):
        # check the catchment critera
        neighbours = Grid.neighbourhood(i=0,
                                        j=0,
                                        k=0,
                                        high=self.buriedness.nsteps,
                                        catchment=1)
        self.assertEqual(3, len(neighbours))

        neighbours1 = Grid.neighbourhood(i=5,
                                         j=5,
                                         k=5,
                                         high=self.buriedness.nsteps,
                                         catchment=1)
        self.assertEqual(6, len(neighbours1))

        f = PyMOLFile()
        for i, n in enumerate(neighbours + neighbours1):
            f.commands += PyMOLCommands.sphere(f"sphere_{i}", (0, 0, 1, 1), n,
                                               0.1)
            f.commands += PyMOLCommands.load_cgo(f"sphere_{i}",
                                                 f"sphere_{i}_obj")
        f.commands += PyMOLCommands.sphere("centre", (1, 0, 0, 1), (5, 5, 5),
                                           0.1)
        f.commands += PyMOLCommands.load_cgo("centre", "centre_obj")
        f.commands += PyMOLCommands.sphere("centre1", (1, 0, 0, 1), (0, 0, 0),
                                           0.1)
        f.commands += PyMOLCommands.load_cgo("centre1", "centre1_obj")

        f.write("testdata/grid_extension/neighbourhood.py")
Ejemplo n.º 2
0
    def test_cylinder(self):
        self.pymol_file.commands += PyMOLCommands.cylinder(
            "_mycylinder", (0, 0, 0), (1, 1, 1), 2, (1, 0, 0, 0.5))
        self.pymol_file.commands += PyMOLCommands.load_cgo(
            "_mycylinder", "mycylinder")

        self.pymol_file.commands += PyMOLCommands.cylinder(
            "_mycylinder2", (0, 0, 0), (10, 10, 10), 0.2, (1, 0, 0, 1),
            (0.5, 0.5, 0))
        self.pymol_file.commands += PyMOLCommands.load_cgo(
            "_mycylinder2", "mycylinder2")

        self.pymol_file.write("testdata/wrapper_pymol/test_cylinder.py")
Ejemplo n.º 3
0
    def test_arrow(self):
        self.pymol_file.commands += PyMOLCommands.arrow(
            "_myarrow", (1, 1, 0), (4, 5, 0), (1, 0, 0), (0, 0, 1))
        self.pymol_file.commands += PyMOLCommands.load_cgo(
            "_myarrow", "myarrow")

        self.pymol_file.write("testdata/wrapper_pymol/test_arrow.py")
Ejemplo n.º 4
0
    def test_cone(self):
        self.pymol_file.commands += PyMOLCommands.cone("_mycone", (0, 0, 0),
                                                       (10, 10, 10), 5,
                                                       (1, 0, 0))
        self.pymol_file.commands += PyMOLCommands.load_cgo("_mycone", "mycone")

        self.pymol_file.write("testdata/wrapper_pymol/test_cone.py")
Ejemplo n.º 5
0
    def test_sphere(self):
        self.pymol_file.commands += PyMOLCommands.sphere("_mysphere",
                                                         self.pomegranate,
                                                         (0, 0, 0),
                                                         radius=2)
        self.pymol_file.commands += PyMOLCommands.load_cgo(
            "_mysphere", "mysphere")

        self.pymol_file.commands += PyMOLCommands.sphere("_mysphere1",
                                                         self.pomegranate,
                                                         (1, 1, 1),
                                                         radius=1)
        self.pymol_file.commands += PyMOLCommands.load_cgo(
            "_mysphere1", "mysphere1")

        self.pymol_file.write("testdata/wrapper_pymol/test_sphere.py")
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def test_edge_detection(self):
        self.selected = Grid.from_file("testdata/result/molA.grd")
        edge = self.selected.edge_detection()

        self.assertLess(len(edge), self.selected.count_grid())
        f = PyMOLFile()
        for i, n in enumerate(edge):
            f.commands += PyMOLCommands.sphere(f"sphere_{i}", (0, 0, 1, 1), n,
                                               0.1)
            f.commands += PyMOLCommands.load_cgo(f"sphere_{i}",
                                                 f"sphere_{i}_obj")

        f.write("testdata/grid_extension/edge_detection.py")
Ejemplo n.º 8
0
    def to_pymol_str(self):
        pymol_out = ""
        pymol_out += PyMOLCommands.sphere("peak_obj", (1, 1, 1, 1),
                                          coords=self.point,
                                          radius=1)
        pymol_out += PyMOLCommands.load_cgo("peak_obj", "peak")

        ligand_peak_features = []
        for i, feat in enumerate(self.features):
            pymol_out += feat.to_pymol_str(i=i)
            ligand_peak_features.append(f"{feat.identifier}_{i}")

        pymol_out += PyMOLCommands.group("ligand_peak_features",
                                         ligand_peak_features)

        return pymol_out
Ejemplo n.º 9
0
    def to_pymol_str(self, i=0, label=True, transparency=0.6):
        pymol_out = ""
        point_colour = rgb_to_decimal(self.colour)
        point_colour = utilities.Colour(point_colour[0], point_colour[1],
                                        point_colour[2], transparency)
        feat_ID = f"{self.identifier}_{i}"
        group = []

        coords = (self.point[0].centre[0], self.point[0].centre[1],
                  self.point[0].centre[2])

        radius = self.point[0].radius

        point_objname = f"{self.identifier}_point_{i}"
        pymol_out += PyMOLCommands.sphere(point_objname,
                                          point_colour,
                                          coords,
                                          radius=radius)
        pymol_out += PyMOLCommands.load_cgo(point_objname,
                                            f"{point_objname}_obj")
        group.append(f"{point_objname}_obj")

        if self.score != 0 and label:
            score_name = f"{point_objname}_score"
            pymol_out += PyMOLCommands.pseudoatom(
                objname=score_name,
                coords=coords,
                label=f'{round(self.score, 1)}')
            group.append(score_name)

            rank_name = f"{self.identifier}_rank_{i}"
            pymol_out += PyMOLCommands.pseudoatom(objname=rank_name,
                                                  coords=coords,
                                                  label=str(i + 1))
            group.append(rank_name)

        if self.projected:
            proj_coords = (self.projected[0].centre[0],
                           self.projected[0].centre[1],
                           self.projected[0].centre[2])

            projection_objname = f"{self.identifier}_projection_{i}"
            line_objname = f"{self.identifier}_line_{i}"

            group.extend([projection_objname, line_objname])
            if self.projected_value != 0 and label:
                proj_score_name = f"{point_objname}_proj_score"
                pymol_out += PyMOLCommands.pseudoatom(
                    objname=proj_score_name,
                    coords=proj_coords,
                    label=f'{round(self.projected_value, 1)}')
                group.append(proj_score_name)
            projected_colour = adjust_lightness(self.colour, percentage=30)
            projected_colour = utilities.Colour(projected_colour[0],
                                                projected_colour[1],
                                                projected_colour[2],
                                                transparency)
            projected_radius = self.projected[0].radius

            pymol_out += PyMOLCommands.sphere(projection_objname,
                                              projected_colour,
                                              proj_coords,
                                              radius=projected_radius)
            pymol_out += PyMOLCommands.load_cgo(projection_objname,
                                                f"{projection_objname}_obj")
            pymol_out += PyMOLCommands.line(line_objname,
                                            coords,
                                            proj_coords,
                                            rgb=projected_colour)

        pymol_out += PyMOLCommands.group(feat_ID, group)
        return pymol_out