示例#1
0
    def apply_to_map(self, map_manager):
        assert map_manager is not None
        # Apply to a map_manager that is similar to the one used to generate
        #   this around_model object
        assert map_manager.crystal_symmetry().is_similar_symmetry(
            self.original_crystal_symmetry)

        ma1 = map_manager.map_data().accessor()
        ma2 = self.original_accessor
        assert ma1.all() == ma2.all()
        assert ma1.origin() == ma2.origin()
        assert ma1.focus() == ma2.focus()
        map_data = map_manager.map_data()
        # Check if map is all valid
        bounds_info = get_bounds_of_valid_region(
            map_data=map_data,
            gridding_first=self.gridding_first,
            gridding_last=self.gridding_last)
        if self.wrapping or bounds_info.inside_allowed_bounds:
            # Just copy everything
            map_box = maptbx.copy(map_data, self.gridding_first,
                                  self.gridding_last)
            # Note: map_box gridding is self.gridding_first to self.gridding_last
        else:  # Need to copy and then zero outside of defined region
            map_box = copy_and_zero_map_outside_bounds(map_data=map_data,
                                                       bounds_info=bounds_info)
        #  Now reshape map_box to put origin at (0,0,0)
        map_box.reshape(flex.grid(self.box_all))

        # Create new map_manager object:
        #   Use original values for:
        #     unit_cell_grid    (gridding of original full unit cell)
        #     unit_cell_crystal_symmetry  (symmetry of original full unit cell)
        #     input_file_name
        #   Use new (boxed) values for:
        #     map_data
        #     crystal_symmetry   (symmetry of the part of the map that is present)
        #   Update:
        #     origin_shift_grid_units  (position in the original map of the
        #                                 (0,0,0) grid point in map_box)
        #     labels  (add label specifying boxing operation)
        #
        # New origin_shift_grid_units:
        origin_shift_grid_units = [
            self.gridding_first[i] + map_manager.origin_shift_grid_units[i]
            for i in range(3)
        ]
        # New labels:
        new_label = "Boxed %s to %s %s" % (str(tuple(
            self.gridding_first)), str(tuple(
                self.gridding_last)), self.basis_for_boxing_string)
        #  Set up new map_manager.
        #  NOTE: origin_shift_grid_units is required as bounds have changed
        new_map_manager = map_manager.customized_copy(
            map_data=map_box, origin_shift_grid_units=origin_shift_grid_units)
        # Add the label
        new_map_manager.add_label(new_label)
        return new_map_manager
示例#2
0
    def apply_to_map(self, map_manager):
        '''
     Apply boxing to a map_manager that is similar to the one used to generate
       this around_model object

     Also apply to its ncs_object, if any

    '''
        assert isinstance(map_manager, iotbx.map_manager.map_manager)

        # This one should just have similar unit_cell_crystal_symmetry
        # crystal_symmetry should match self.map_crystal_symmetry_at_initialization

        assert map_manager.unit_cell_crystal_symmetry().is_similar_symmetry(
            self._map_manager.unit_cell_crystal_symmetry())
        assert map_manager.crystal_symmetry().is_similar_symmetry(
            self.map_crystal_symmetry_at_initialization)

        ma1 = map_manager.map_data().accessor()
        ma2 = self.accessor_at_initialization
        assert ma1.all() == ma2.all()
        assert ma1.origin() == ma2.origin()
        assert ma1.focus() == ma2.focus()
        map_data = map_manager.map_data()
        # Check if map is all valid
        bounds_info = get_bounds_of_valid_region(map_data, self.gridding_first,
                                                 self.gridding_last)

        # Allow override of wrapping
        if isinstance(self._force_wrapping, bool):
            wrapping = self._force_wrapping
        else:
            # Get wrapping from map_manager. If it is not defined and
            #  bounds are outside allowed, try to get the wrapping
            wrapping = map_manager.wrapping()

        if wrapping or bounds_info.inside_allowed_bounds:
            # Just copy everything
            map_box = maptbx.copy(map_data, self.gridding_first,
                                  self.gridding_last)
            # Note: map_box gridding is self.gridding_first to self.gridding_last
        elif not bounds_info.some_valid_points:
            # No valid points, Just copy everything and zero
            map_box = maptbx.copy(map_data, self.gridding_first,
                                  self.gridding_last)
            map_box = map_box * 0.
            self._warning_message += "\nWARNING: boxed map is entirely outside map"+\
               " and wrapping=%s\n...setting all values to zero" %(wrapping)

        else:  # Need to copy and then zero outside of defined region
            map_box = copy_and_zero_map_outside_bounds(map_data, bounds_info)
            self._warning_message += \
                  "\nWARNING: boxed map goes outside original map"+\
               " and wrapping=%s\n...setting unknown values to zero" %(wrapping)
        #  Now reshape map_box to put origin at (0, 0, 0)
        map_box.reshape(flex.grid(self.box_all))

        # Create new map_manager object:
        #   Use original values for:
        #     unit_cell_grid    (gridding of original full unit cell)
        #     unit_cell_crystal_symmetry  (symmetry of original full unit cell)
        #     input_file_name
        #   Use new (boxed) values for:
        #     map_data
        #     crystal_symmetry   (symmetry of the part of the map that is present)
        #   Update:
        #     origin_shift_grid_units  (position in the original map of the
        #                                 (0, 0, 0) grid point in map_box)
        #     labels  (add label specifying boxing operation)
        #
        # New origin_shift_grid_units:
        origin_shift_grid_units = [
            self.gridding_first[i] + map_manager.origin_shift_grid_units[i]
            for i in range(3)
        ]
        # New labels:
        new_label = "Boxed %s to %s %s" % (str(tuple(
            self.gridding_first)), str(tuple(
                self.gridding_last)), self.basis_for_boxing_string)
        #  Set up new map_manager. This will contain new data and not overwrite
        #   original
        #  NOTE: origin_shift_grid_units is required as bounds have changed
        new_map_manager = map_manager.customized_copy(
            map_data=map_box, origin_shift_grid_units=origin_shift_grid_units)
        if self._force_wrapping:
            # Set the wrapping of the new map if it is possible
            if (self._force_wrapping and (new_map_manager.is_full_size())) or \
             ( (not self._force_wrapping) and (not new_map_manager.is_full_size())):
                new_map_manager.set_wrapping(self._force_wrapping)

        # Add the label
        new_map_manager.add_label(new_label)
        return new_map_manager