Exemple #1
0
def divide_select(g1, g2):
    """
    Makes a selectivity map by dividing two grids
    :param g1: ccdc.utilities.Grid
    :param g2: ccdc.utilities.Grid
    :return: ccdc.utilities Grid
    """

    h = HotspotsHelper()
    g1, g2 = h._common_grid(g1, g2)
    com_bound_box = g1.bounding_box
    com_spacing = g1.spacing

    arr1 = grid_to_numpy(g1)
    arr1[arr1 < 1] = 1.0
    arr2 = grid_to_numpy(g2)
    arr2[arr2 < 1] = 1.0

    sel_arr = np.divide(arr1, arr2)
    sel_arr[sel_arr == 1.0] = 0.0

    sel_map = Grid(origin=com_bound_box[0],
                   far_corner=com_bound_box[1],
                   spacing=com_spacing)

    for x in range(sel_map.nsteps[0]):
        for y in range(sel_map.nsteps[1]):
            for z in range(sel_map.nsteps[2]):
                sel_map.set_value(x, y, z, sel_arr[x][y][z])

    return sel_map
Exemple #2
0
    def get_results_array(self):
        """
        constructs the numpy array containing the list of tuples.
        Adjusts the coordinates based on the origins of the grids
        self.results_array = numpy array
        :return:
        """
        print('Making results array')
        r_a_grid = Grid(origin=self.array_grid_origin, far_corner=self.array_grid_far_corner, spacing=self.spacing)

        nx, ny, nz = r_a_grid.nsteps
        results_array = np.zeros((nx, ny, nz), dtype=tuple)
        rec_spacing = 1 / self.spacing

        def set_value(x, y, z):
            r_x = x + int(d_coor[0])
            r_y = y + int(d_coor[1])
            r_z = z + int(d_coor[2])

            if isinstance(results_array[r_x][r_y][r_z], tuple):
                results_array[r_x][r_y][r_z] += (ar[x][y][z],)
            else:
                results_array[r_x][r_y][r_z] = (ar[x][y][z],)

        vset_value = np.vectorize(set_value, otypes=[tuple])

        for i in range(self.tup_max_length):
            g = Grid.from_file(self.grid_list[i])
            d_coor = [(g.bounding_box[0][b] - r_a_grid.bounding_box[0][b])*rec_spacing for b in range(3)]
            print('D_coor:',d_coor)
            ar = fxn.grid_to_numpy(g)
            ind_ar = np.where(ar > 0)
            vset_value(ind_ar[0], ind_ar[1], ind_ar[2])

        self.results_array = results_array
Exemple #3
0
def read_grids(stem, substring, charged_probes=False):
    """
    Creates a grid_dic from a given directory
    :param stem: str(path to directory)
    :param substring: str(protein name)
    :param charged_probes: whether o look for positive and negative grids
    :return: Python dictionary
    """
    grid_dic = {}
    if charged_probes == False:
        probe_list = ['apolar', 'acceptor', 'donor']
    else:
        probe_list = ['apolar', 'acceptor', 'donor', 'positive', 'negative']

    for root, subdirs, files in os.walk(stem):
        for filename in files:
            if substring in filename:
                name_path = os.path.join(root, filename)
                if '.ccp4' in filename:
                    prot_name = filename.replace('.ccp4', '')
                elif '.grd' in filename:
                    prot_name = filename.replace('.grd', '')
                else:
                    continue
                for probe in probe_list:
                    if probe in filename:
                        grid_dic[probe] = Grid.from_file(name_path)

    return grid_dic
Exemple #4
0
    def get_array_grid(self):
        """
        Gets the coordinates of a grid that can fit all other grids (to use as basis for self.results_array)
        :return: 
        """
        print('Making array grid')
        grid_list = []
        or_list = [0, 0, 0]
        far_list = [0, 0, 0]

        for root, subdirs, files in os.walk(self.stem):
            for filename in files:
                if self.probe in filename and self.prot_name in filename and 'ccp4' in filename:
                    if ('frequency' not in filename) and ('ranges' not in filename):
                        grid_list.append(join(self.stem, filename))
                        g = Grid.from_file(join(self.stem, filename))
                        _or_list = [g.bounding_box[0][j] for j in range(3)]
                        _far_list = [g.bounding_box[1][m] for m in range(3)]

                        for i in range(3):
                            or_list[i] = min(or_list[i], _or_list[i])
                            far_list[i] = max(far_list[i], _far_list[i])

        self.grid_list = grid_list
        self.spacing = g.spacing
        self.tup_max_length = len(grid_list)
        self.array_grid_origin = (or_list[0], or_list[1], or_list[2])
        self.array_grid_far_corner = (far_list[0], far_list[1], far_list[2])
Exemple #5
0
def find_grid(stem, prot_name, probe=None):
    """
    Loops through a directory to find a specific grid. Doesn't discriminate probes
    :param prot_name: 
    :return: ccdc.utilities.Grid object
    """
    for root, subdirs, files in os.walk(stem):
        for filename in files:
            if prot_name in filename and '.ccp4' in filename:
                name_path = os.path.join(root, filename)
                if probe != None:
                    if probe in filename:
                        grid = Grid.from_file(name_path)
                        return grid
                else:
                    grid = Grid.from_file(name_path)
                    return grid
Exemple #6
0
    def __init__(self, settings):
        self.settings = settings
        self.identifier = settings.jobname.split(".")[0]
        print self.identifier

        gridpath = os.path.join(self.settings.working_directory,
                                self.identifier + ".ins.acnt")
        if os.path.exists(gridpath):
            self.grid = Grid.from_file(gridpath)
        else:
            raise AttributeError('{} superstar grid could not be found'.format(
                self.identifier))

        ligsitepath = os.path.join(self.settings.working_directory,
                                   self.identifier + ".ins.ligsite.acnt")
        if os.path.exists(ligsitepath):
            self.ligsite = Grid.from_file(ligsitepath)
        else:
            raise AttributeError('{} ligsite grid could not be found'.format(
                self.identifier))
Exemple #7
0
    def make_frequency_grid(self):
        '''
        Makes a grid that stores how many times each point has been sampled
        :return: ccdc.utilities Grid object
        '''
        r_a_grid = Grid(origin=self.array_grid_origin, far_corner=self.array_grid_far_corner, spacing=self.spacing)

        for x in range(self.results_array.shape[0]):
            for y in range(self.results_array.shape[1]):
                for z in range(self.results_array.shape[2]):
                    if isinstance(self.results_array[x][y][z], tuple):
                        r_a_grid.set_value(x, y, z, len(self.results_array[x][y][z]))

        r_a_grid.write(join(self.out_dir, '{}_Ghecom_frequency_{}.ccp4'.format(self.prot_name, self.probe)))
        return r_a_grid
def main():
    out_dir = "Z://fragment-hotspot-results//patel_set//2//out"
    grd = Grid.from_file(join(out_dir, "apolar.grd"))
    nx, ny, nz = grd.nsteps
    fname = join(out_dir, "inferno_gradient.py")
    header(fname)
    string_list = ""

    for a in range(nx):
        for b in range(ny):
            for c in range(nz):
                if grd.value(a,b,c) > 5:
                    pnt = GridPoint(a,b,c, grd, inferno_data)
                    string_list += pnt.point_to_string()
                else:
                    continue

    with open(fname, "a") as pymol_file:
        pymol_file.write(string_list)

    footer(fname)
Exemple #9
0
    def make_mean_grid(self):
        '''
        Makes a grid that stores the mean of the sampled values at each point
        :return: ccdc.utilities Grid object
        '''
        r_a_grid = Grid(origin=self.array_grid_origin, far_corner=self.array_grid_far_corner, spacing=self.spacing)

        for x in range(self.results_array.shape[0]):
            for y in range(self.results_array.shape[1]):
                for z in range(self.results_array.shape[2]):
                    if isinstance(self.results_array[x][y][z], tuple):
                        t_a = np.array(self.results_array[x][y][z])
                        r_a_grid.set_value(x, y, z, np.mean(t_a))

        r_a_grid.write(join(self.out_dir, '{}_Ghecom_mean_{}.ccp4'.format(self.prot_name, self.probe)))
        return r_a_grid
Exemple #10
0
    def make_max_grid(self):
        '''
        Makes a grid that stores the maximum of values of each point
        :return: ccdc.utilities Grid object
        '''
        r_a_grid = Grid(origin=self.array_grid_origin, far_corner=self.array_grid_far_corner, spacing=self.spacing)

        for x in range(self.results_array.shape[0]):
            for y in range(self.results_array.shape[1]):
                for z in range(self.results_array.shape[2]):
                    if isinstance(self.results_array[x][y][z], tuple):
                        hist_arr = np.array(self.results_array[x][y][z])
                        r_a_grid.set_value(x, y, z, (max(hist_arr)))

        r_a_grid.write(join(self.out_dir, '{}_max_{}.ccp4'.format(self.prot_name, self.probe)))
        return r_a_grid
Exemple #11
0
def compress_grid(grid):
    """
    Compresses a grid.
    :param grid: ccdc.utilities Grid
    :return: ccdc.utilities Grid
    """

    arr = grid_to_numpy(grid)
    ind_arr = np.where(arr > 0)
    or_diff = [min(ind_arr[i]) for i in range(3)]
    print(or_diff)
    far_diff = [grid.nsteps[i] - max(ind_arr[i]) for i in range(3)]
    print(far_diff)
    if int(min(or_diff)) < 3 or int(min(far_diff)) < 3:
        p = 0
    else:
        p = 2
    region = (min(ind_arr[0]) - p, min(ind_arr[1]) - p, min(ind_arr[2]) - p,
              max(ind_arr[0]) + p, max(ind_arr[1]) + p, max(ind_arr[2]) + p)
    compr_grid = Grid.sub_grid(grid, region)

    return compr_grid
Exemple #12
0
def filter_map(g1, g2):
    """
    Sets 2 grids to the same size and coordinate frames. Points that are zero in one grid but sampled in the other are
    set to the mean of their nonzero neighbours.
    :param g1: ccdc.utilities.Grid
    :param g2: ccdc.utilities.Grid
    :return: ccdc.utilities.Grid
    """
    def filter_point(x, y, z):
        loc_arr = np.array([
            g[x + i][y + j][z + k] for i in range(-1, 2) for j in range(-1, 2)
            for k in range(-1, 2)
        ])
        if loc_arr[loc_arr > 0].size != 0:
            print(np.mean(loc_arr[loc_arr > 0]))
            new_grid[x][y][z] = np.mean(loc_arr[loc_arr > 0])

    vfilter_point = np.vectorize(filter_point)
    h = HotspotsHelper()
    g1 = compress_grid(g1)
    g2 = compress_grid(g2)
    g1, g2 = h._common_grid(g1, g2, padding=1)
    com_bound_box = g1.bounding_box
    com_spacing = g1.spacing

    arr1 = grid_to_numpy(g1)
    arr2 = grid_to_numpy(g2)

    b_arr1 = np.copy(arr1)
    b_arr2 = np.copy(arr2)

    b_arr1[b_arr1 > 0] = 1.0
    b_arr2[b_arr2 > 0] = -1.0

    diff_arr = b_arr1 + b_arr2

    unmatch1 = np.where(diff_arr == 1)
    unmatch2 = np.where(diff_arr == -1)

    g = arr1
    new_grid = np.copy(arr1)
    vfilter_point(unmatch2[0], unmatch2[1], unmatch2[2])
    f_arr1 = np.copy(new_grid)
    f_arr1[f_arr1 < 1] = 1

    g = arr2
    new_grid = np.copy(arr2)
    vfilter_point(unmatch1[0], unmatch1[1], unmatch1[2])
    f_arr2 = np.copy(new_grid)
    f_arr2[f_arr2 < 1] = 1

    sel_arr = np.divide(f_arr1, f_arr2)
    sel_arr[sel_arr == 1] = 0

    sel_map = Grid(origin=com_bound_box[0],
                   far_corner=com_bound_box[1],
                   spacing=com_spacing)

    for x in range(sel_map.nsteps[0]):
        for y in range(sel_map.nsteps[1]):
            for z in range(sel_map.nsteps[2]):
                sel_map.set_value(x, y, z, sel_arr[x][y][z])
    return sel_map