def find(temp_dir, jobname):
        """
        searches the calculation working directory and constructs a
        `hotspots.atomic_hotspots_calculation.AtomHotspotResult` instance
        :param str temp_dir: path to the temporary calculation directory
        :param str jobname: name of the atomic probe used in the calculation
        :return: a `hotspots.atomic_hotspots_calculation.AtomHotspotResult` instance
        """
        grid_path = join(temp_dir, jobname + ".acnt")
        grid = Grid.from_file(grid_path)
        buriedness_path = join(temp_dir, jobname + ".ligsite.acnt")

        if exists(buriedness_path):
            b_grid = Grid.from_file(buriedness_path)
            print('ligsite extrema', b_grid.extrema)
            # b.write('buriedness_broken.grd')
            buriedness = _AtomicHotspotResult._correct_ligsite(grid, b_grid)

        else:
            print(buriedness_path)
            raise AttributeError(
                '{} ligsite grid could not be found'.format(jobname))

        return _AtomicHotspotResult(identifier=jobname,
                                    grid=grid,
                                    buriedness=buriedness,
                                    ins=join(temp_dir,
                                             "{}.ins".format(jobname)))
    def _merge_cavities(results):
        """
        private method

        atomic hotspot results for the same atomic probe but different cavities are combined onto a single grid
        :param a `hotspots.atomic_hotspot_calculation._AtomicHotspotResult` instance results: a result object
        :return: list, of merged _AtomicHotspotResults
        """
        result_dict = {}
        for result in results:
            if result.identifier in result_dict:
                result_dict[result.identifier].append(result)
            else:
                result_dict.update({result.identifier: [result]})

        merged_results = []
        for identifier, atomic_results in result_dict.items():
            g_dict = {"grid_{}".format(i): g.grid for i, g in enumerate(atomic_results)}
            g = Grid.get_single_grid(g_dict, mask=False)

            b_dict = {"buriedness_{}".format(i): g.buriedness for i, g in enumerate(atomic_results)}
            b = Grid.get_single_grid(b_dict, mask=False)

            merged_results.append(_AtomicHotspotResult(identifier=identifier,
                                                      grid=g,
                                                      buriedness=b,
                                                      )
                                  )

        return merged_results
Example #3
0
    def _get_grids(self, sub_dir=None):
        """
        create a grid dictorionary
        :return:
        """
        if sub_dir:
            base = join(self._base, sub_dir)
            self._files = listdir(base)
            self._extensions = set(
                [splitext(f)[1] for f in self._files if f != '' or f != '.py'])
        else:
            base = self._base

        if ".dat" in self._extensions:
            grid_dic = {
                splitext(fname)[0]: Grid.from_array(join(base, fname))
                for fname in [
                    f for f in self._files if splitext(f)[1] == ".grd"
                    and splitext(f)[0] in self._supported_interactions
                ]
            }
            try:
                buriedness = Grid.from_array(join(self.base, "buriedness.dat"))
            except RuntimeError:
                buriedness = None

        else:
            ext = list(
                set(self._extensions).intersection(self._supported_grids))
            if len(ext) == 1:
                grid_dic = {
                    splitext(fname)[0]: Grid.from_file(join(base, fname))
                    for fname in [
                        f for f in self._files if splitext(f)[1] == ext[0]
                        and splitext(f)[0] in self._supported_interactions
                    ]
                }
                try:
                    buriedness = Grid.from_file("buriedness{}".format(ext[0]))
                except RuntimeError:
                    buriedness = None
            else:
                raise RuntimeError("Opps, something went wrong.")

        return grid_dic, buriedness
Example #4
0
    def write(self, hr):
        """
        writes the Fragment Hotspot Maps result to the output directory and create the pymol visualisation file

        :param `hotspots.result.Result` hr: a Fragment Hotspot Maps result or list of results

        >>> from hotspots.calculation import Runner
        >>> from hotspots.hs_io import HotspotWriter

        >>> r = Runner
        >>> result = r.from_pdb("1hcl")
        >>> out_dir = <path_to_out>
        >>> with HotspotWriter(out_dir) as w:
        >>>     w.write(result)


        """
        if isinstance(hr, list):
            self.settings.grids = hr[0].super_grids.keys()
            self.container = "hotspot_boundaries"
            self.number_of_hotspots = len(hr)

            self.out_dir = Helper.get_out_dir(join(self.path, self.container))

            self._write_protein(hr[0].protein)
            if hr[0].pharmacophore:
                self.settings.pharmacophore = True
            # hts = [h.hotspot_result for h in hr]
            self._write_pymol(hr, self.zipped)

            for i, hotspot in enumerate(hr):
                self.out_dir = Helper.get_out_dir(
                    join(self.path, self.container, str(i)))
                self.settings.isosurface_threshold = [
                    round(hotspot.threshold, 1)
                ]

                bi = (Grid.super_grid(
                    2, hotspot.best_island).max_value_of_neighbours() >
                      hotspot.threshold)

                self._write_grids(hotspot.super_grids,
                                  buriedness=None,
                                  mesh=bi)
                self._write_protein(hotspot.protein)

                if hotspot.pharmacophore:
                    self._write_pharmacophore(hotspot.pharmacophore)

                self._write_pymol(hotspot, False)

            self.out_dir = dirname(self.out_dir)
            if self.zipped:
                self.compress(join(dirname(self.out_dir), self.container))

        else:
            self.settings.grids = hr.super_grids.keys()
            self.container = "out"
            self.number_of_hotspots = 1

            self.out_dir = Helper.get_out_dir(join(self.path, self.container))
            self._write_grids(hr.super_grids, buriedness=hr.buriedness)
            self._write_protein(hr.protein)

            if hr.pharmacophore:
                self.settings.pharmacophore = True
                self._write_pharmacophore(hr.pharmacophore)
            self._write_pymol(hr, self.zipped)

            if self.zipped:
                self.compress(join(dirname(self.out_dir), self.container))