def test_output_grid(self): #g_0 = Grid.from_file(self.grid_paths[0]) g_0 = self.grid_list[0] print(g_0.count_grid()) print(self.max_grid.count_grid()) max_g, ref_g = Grid.common_grid([self.max_grid, g_0]) diff_grid = (max_g - ref_g) nx, ny, nz = diff_grid.nsteps for x in range(nx): for y in range(ny): for z in range(nz): if diff_grid.value(x, y, z) != 0: print(diff_grid.value(x, y, z)) self.assertEqual((max_g - ref_g).count_grid(), 0, msg="Testing the max_grid") means_grid = self.grid_ensemble.output_grid(mode="mean", save=False) mean_g, ref_g = Grid.common_grid([means_grid, g_0]) self.assertEqual((max_g - ref_g).count_grid(), 0, msg="Testing the means_grid") ranges_grid = self.grid_ensemble.output_grid(mode="ranges", save=False) self.assertEqual(ranges_grid.count_grid(), 0, msg="Testing the ranges grid") other_g = self.grid_ensemble.output_grid(mode="bla", save=False) self.assertIsNone(other_g)
def make_difference_maps(self): """ Brings the two results to the same size and subtracts them. TODO - think about cases of results with different numbers of probe grids (charged vs not) :return: ccdc grids """ diff_maps = {} for probe, gr in self.target.super_grids.items(): try: off_gr = self.off_target.super_grids[probe] # In case the off-target hotspot result doesn't have a map for that probe except KeyError: continue # if gr.check_same_size_and_coords(off_gr): # c_gr = gr # c_off = off_gr # else: # print("Input grids of different size. Converting to same coordinates.") c_gr, c_off = Grid.common_grid([gr, off_gr]) diff_maps[probe] = _GridEnsemble.array_from_grid(c_gr - c_off) self.common_grid_dimensions = np.array(c_gr.bounding_box) self.common_grid_nsteps = c_gr.nsteps return diff_maps
def common_hotspots(self, other): common_hotspot_grids = {} for probe, g in self.super_grids.items(): common_self_g, common_other_g = Grid.common_grid( g, other.super_grids[probe]) common_hotspot_grids[probe] = common_self_g * common_other_g return Results(super_grids=common_hotspot_grids, protein=self.protein, buriedness=self.buriedness)
def _get_weighted_maps(self): """ private method weight superstar output by burriedness :return: a list of :class:`WeightedResult` instances """ results = [] for s in self.superstar_grids: g, b = Grid.common_grid([s.grid, self.buriedness], padding=1) weighted_grid = g * b results.append(_WeightedResult(s.identifier, weighted_grid)) return results
def set_background(self, background_value=1.0): spacing = self.super_grids["apolar"]._spacing prot_g = Grid.from_molecule(self.protein, value=background_value, scaling_type='none', scaling=1, spacing=spacing) for probe, g in self.super_grids.items(): common_prot, common_g = Grid.common_grid([prot_g, g]) bg_mask = (common_prot < 0.1) & (common_g < 1) tmp_g = common_g + bg_mask new_g = tmp_g - (common_prot) origin, corner = g.bounding_box i, j, k = new_g.point_to_indices(origin) l, m, n = new_g.point_to_indices(corner) self.super_grids[probe] = new_g.sub_grid((i, j, k, l, m, n))
def _remove_protein_vol(self, g): """ :param g: :return: """ prot_g = Grid.from_molecule(self.hotspot_result.protein, value=1, scaling_type='none', scaling=1) common_prot, common_g = Grid.common_grid([prot_g, g]) new_g = common_g * (common_prot < 1) origin, corner = g.bounding_box i, j, k = new_g.point_to_indices(origin) l, m, n = new_g.point_to_indices(corner) return new_g.sub_grid((i, j, k, l, m, n))
def get_difference_map(self, other, tolerance): """ *Experimental feature.* Generates maps to highlight selectivity for a target over an off target cavity. Proteins should be aligned by the binding site of interest prior to calculation. High scoring regions of a map represent areas of favourable interaction in the target binding site, not present in off target binding site :param other: a :class:`hotspots.result.Results` instance :param int tolerance: how many grid points away to apply filter to :return: a :class:`hotspots.result.Results` instance """ selectivity_grids = {} for probe in self.super_grids.keys(): g1 = self.super_grids[probe] g2 = other.super_grids[probe] og1, og2 = Grid.common_grid([g1, g2]) sele = self._filter_map(og1, og2, tolerance) selectivity_grids[probe] = sele hr = Results(selectivity_grids, self.protein, None, None) return hr