コード例 #1
0
def get_best_co(map_data, min_cutoff=0.5):
    max_value = map_data.as_1d().min_max_mean().max

    # Find max number of clusters in range of 0.5 to 1.0 * max
    n = 100
    max_clusters = None
    cutoff = None
    for t in range(int(min_cutoff * n), n + 1):
        threshold = t * max_value / n
        co, sorted_by_volume, min_b, max_b = get_co(map_data,
                                                    threshold=threshold,
                                                    wrapping=False)
        if ((not max_clusters) or (len(sorted_by_volume) > max_clusters)) and (
                len(sorted_by_volume) > 1):
            max_clusters = len(sorted_by_volume)
            cutoff = threshold
    if max_clusters is None:
        return None
    print("Clusters: %s   Threshold: %.2f " % (max_clusters, cutoff))
    co, sorted_by_volume, min_b, max_b = get_co(map_data,
                                                threshold=cutoff,
                                                wrapping=False)
    return group_args(group_args_type='co info',
                      co=co,
                      sorted_by_volume=sorted_by_volume)
コード例 #2
0
    def __init__(self, map_manager, wrapping, log=sys.stdout):
        adopt_init_args(self, locals())

        # safeguards
        assert isinstance(wrapping, bool)
        assert isinstance(map_manager, iotbx.map_manager.map_manager)
        assert self.map_manager.map_data().accessor().origin() == (0, 0, 0)
        if wrapping:
            assert map_manager.unit_cell_grid == map_manager.map_data().all()

        self.basis_for_boxing_string = 'around_mask bounds, wrapping=%s' % (
            wrapping)

        # Get a connectivity object that marks all the connected regions in map

        from cctbx.maptbx.segment_and_split_map import get_co
        co, sorted_by_volume, min_b, max_b = get_co(
            map_data=map_manager.map_data(), threshold=0.5, wrapping=False)

        if len(sorted_by_volume) < 2:  # didn't work
            raise Sorry("No mask obtained...")

        # Get the biggest connected region in the map

        original_id_from_id = {}
        for i in range(1, len(sorted_by_volume)):
            v, id = sorted_by_volume[i]
            original_id_from_id[i] = id
        id = 1
        orig_id = original_id_from_id[id]

        # Get lower and upper bounds of this region in grid units

        self.gridding_first = min_b[orig_id]
        self.gridding_last = max_b[orig_id]

        # Ready with gridding...set up shifts and box crystal_symmetry
        self.set_shifts_and_crystal_symmetry()

        # Apply to map_manager so that self.map_manager is boxed version

        self.map_manager = self.apply_to_map(self.map_manager)
コード例 #3
0
    def __init__(self,
                 map_manager,
                 mask_as_map_manager,
                 model=None,
                 box_cushion=3,
                 wrapping=None,
                 model_can_be_outside_bounds=False,
                 log=sys.stdout):

        self._map_manager = map_manager
        self._model = model
        self.model_can_be_outside_bounds = model_can_be_outside_bounds
        assert map_manager.shift_cart() == mask_as_map_manager.shift_cart()

        # safeguards
        assert isinstance(map_manager, iotbx.map_manager.map_manager)
        assert isinstance(mask_as_map_manager, iotbx.map_manager.map_manager)
        assert self._map_manager.map_data().accessor().origin() == (0, 0, 0)
        assert map_manager.is_similar(mask_as_map_manager)
        if self.map_manager().wrapping():
            assert map_manager.unit_cell_grid == map_manager.map_data().all()

        self._force_wrapping = wrapping
        if wrapping is None:
            wrapping = self.map_manager().wrapping()
        self.basis_for_boxing_string = 'around_mask bounds, wrapping = %s' % (
            wrapping)

        # Make sure the map goes from 0 to 1
        map_data = mask_as_map_manager.map_data()
        mmm = map_data.as_1d().min_max_mean()
        minimum = mmm.min
        range_of_values = mmm.max - mmm.min
        map_data = (map_data - minimum) / max(1.e-10, range_of_values)

        # Get a connectivity object that marks all the connected regions in map

        from cctbx.maptbx.segment_and_split_map import get_co
        co, sorted_by_volume, min_b, max_b = get_co(map_data=map_data,
                                                    threshold=0.5,
                                                    wrapping=False)

        if len(sorted_by_volume) < 2:  # didn't work
            raise Sorry("No mask obtained...")

        # Get the biggest connected region in the map

        original_id_from_id = {}
        for i in range(1, len(sorted_by_volume)):
            v, id = sorted_by_volume[i]
            original_id_from_id[i] = id
        id = 1
        orig_id = original_id_from_id[id]

        # Get lower and upper bounds of this region in grid units

        self.gridding_first = min_b[orig_id]
        self.gridding_last = max_b[orig_id]

        # Increase range of bounds by box_cushion
        cs = map_manager.crystal_symmetry()
        cushion = flex.double(cs.unit_cell().fractionalize(
            (box_cushion, ) * 3))
        all_orig = map_manager.map_data().all()
        self.gridding_first = [
            max(0, ifloor(gf - c * n))
            for c, gf, n in zip(cushion, self.gridding_first, all_orig)
        ]
        self.gridding_last = [
            min(n - 1, iceil(gl + c * n))
            for c, gl, n in zip(cushion, self.gridding_last, all_orig)
        ]

        # Ready with gridding...set up shifts and box crystal_symmetry
        self.set_shifts_and_crystal_symmetry()

        self.apply_to_model_ncs_and_map()

        # Also apply to mask_as_map_manager so that mask_as_map_manager is boxed
        mask_as_map_manager = self.apply_to_map(mask_as_map_manager)
        self.mask_as_map_manager = mask_as_map_manager  # save it
コード例 #4
0
    def __init__(self,
                 map_manager=None,
                 resolution=None,
                 buffer_radius=5,
                 minimum_fraction_of_max=0.01):
        '''
     Create a mask (map object) with values of 1 expanded by buffer_radius

     Parameters are:
       map_manager: source of previous mask.
       resolution : optional resolution of map
       buffer_radius:  radius to expand in A
       minimum_fraction_of_max: smallest-sized region to expand
         as ratio to biggest
    '''

        assert (map_manager is not None)

        if not resolution:
            from cctbx.maptbx import d_min_from_map
            resolution = d_min_from_map(
                map_data=map_manager.map_data(),
                unit_cell=map_manager.crystal_symmetry().unit_cell())

        self._crystal_symmetry = map_manager.crystal_symmetry()

        from cctbx.maptbx.segment_and_split_map import estimate_expand_size, get_co

        expand_size = estimate_expand_size(
            crystal_symmetry=map_manager.crystal_symmetry(),
            map_data=map_manager.map_data(),
            expand_target=buffer_radius,
            minimum_expand_size=0,
            out=null_out())

        if expand_size < 1:
            return  # do nothing
        co, sorted_by_volume, min_b, max_b = get_co(
            map_data=map_manager.map_data(), threshold=0.5, wrapping=False)
        if len(sorted_by_volume) < 2:
            return  # do nothing

        minimum_size = sorted_by_volume[1][0] * minimum_fraction_of_max
        s = None
        for v1, i1 in sorted_by_volume[1:]:
            if v1 < minimum_size: break
            bool_region_mask = co.expand_mask(id_to_expand=i1,
                                              expand_size=expand_size)
            if s is None:
                s = (bool_region_mask == True)
            else:
                s |= (bool_region_mask == True)
        self._mask = map_manager.deep_copy().map_data()
        self._mask.set_selected(s, 1)
        self._mask.set_selected(~s, 0)

        self._solvent_content = s.count(False) / s.size()

        # Set up map_manager with this mask
        self._map_manager = map_manager.customized_copy(map_data=self._mask)
        self._map_manager.set_is_mask(True)

        # Initialize soft mask
        self._is_soft_mask = False
        self._is_soft_mask_around_edges = False