def __init__(self, map_manager, model, box_cushion, wrapping=None, log=sys.stdout): self._map_manager = map_manager self._model = model self._force_wrapping = wrapping if wrapping is None: wrapping = self.map_manager().wrapping() self.basis_for_boxing_string = 'using_model, wrapping = %s' % ( wrapping) # safeguards assert isinstance(map_manager, iotbx.map_manager.map_manager) assert isinstance(model, mmtbx.model.manager) assert self._map_manager.map_data().accessor().origin() == (0, 0, 0) # Make sure working model and map_manager crystal_symmetry match assert map_manager.is_compatible_model(model) assert box_cushion >= 0 if self.map_manager().wrapping(): # map must be entire unit cell assert map_manager.unit_cell_grid == map_manager.map_data().all() # NOTE: We are going to use crystal_symmetry and sites_frac based on # the map_manager (the model could still have different crystal_symmetry) # get items needed to do the shift cs = map_manager.crystal_symmetry() uc = cs.unit_cell() sites_cart = model.get_sites_cart() sites_frac = uc.fractionalize(sites_cart) map_data = map_manager.map_data() # convert box_cushion into fractional vector cushion_frac = flex.double(uc.fractionalize((box_cushion, ) * 3)) # find fractional corners frac_min = sites_frac.min() frac_max = sites_frac.max() frac_max = list(flex.double(frac_max) + cushion_frac) frac_min = list(flex.double(frac_min) - cushion_frac) # find corner grid nodes all_orig = map_data.all() self.gridding_first = [ ifloor(f * n) for f, n in zip(frac_min, all_orig) ] self.gridding_last = [iceil(f * n) for f, n in zip(frac_max, all_orig)] # Ready with gridding...set up shifts and box crystal_symmetry self.set_shifts_and_crystal_symmetry() # Apply boxing to model, ncs, and map (if available) self.apply_to_model_ncs_and_map()
def __init__(self, map_manager, model, box_cushion, wrapping=None, model_can_be_outside_bounds=False, stay_inside_current_map=None, log=sys.stdout): self._map_manager = map_manager self._model = model self.model_can_be_outside_bounds = model_can_be_outside_bounds self._force_wrapping = wrapping if wrapping is None: wrapping = self.map_manager().wrapping() self.basis_for_boxing_string = 'using_model, wrapping = %s' % ( wrapping) # safeguards assert isinstance(map_manager, iotbx.map_manager.map_manager) assert isinstance(model, mmtbx.model.manager) assert self._map_manager.map_data().accessor().origin() == (0, 0, 0) # Make sure working model and map_manager crystal_symmetry match assert map_manager.is_compatible_model(model) assert box_cushion >= 0 if self.map_manager().wrapping(): # map must be entire unit cell assert map_manager.unit_cell_grid == map_manager.map_data().all() # NOTE: We are going to use crystal_symmetry and sites_frac based on # the map_manager (the model could still have different crystal_symmetry) info = get_bounds_around_model( map_manager=map_manager, model=model, box_cushion=box_cushion, stay_inside_current_map=stay_inside_current_map) self.gridding_first = info.lower_bounds self.gridding_last = info.upper_bounds # Ready with gridding...set up shifts and box crystal_symmetry self.set_shifts_and_crystal_symmetry() # Apply boxing to model, ncs, and map (if available) self.apply_to_model_ncs_and_map()
def __init__(self, map_manager, lower_bounds, upper_bounds, model = None, wrapping = None, model_can_be_outside_bounds = False, log = sys.stdout): self.lower_bounds = lower_bounds self.upper_bounds = upper_bounds self._map_manager = map_manager self._model = model self.model_can_be_outside_bounds = model_can_be_outside_bounds self._info = None # safeguards assert lower_bounds is not None assert upper_bounds is not None assert len(tuple(lower_bounds))==3 assert len(tuple(upper_bounds))==3 for i in range(3): assert list(upper_bounds)[i] > list(lower_bounds)[i] assert isinstance(map_manager, iotbx.map_manager.map_manager) assert self._map_manager.map_data().accessor().origin() == (0, 0, 0) if model is not None: assert isinstance(model, mmtbx.model.manager) assert map_manager.is_compatible_model(model) self._force_wrapping = wrapping if wrapping is None: wrapping = self.map_manager().wrapping() self.basis_for_boxing_string = 'supplied bounds, wrapping = %s' %( wrapping) # These are lower and upper bounds of map with origin at (0, 0, 0) # (not the original map) self.gridding_first = lower_bounds self.gridding_last = upper_bounds # Ready with gridding...set up shifts and box crystal_symmetry self.set_shifts_and_crystal_symmetry() # Apply boxing to model, ncs, and map (if available) self.apply_to_model_ncs_and_map()
def __init__( self, map_manager, model=None, target_ncs_au_model=None, regions_to_keep=None, solvent_content=None, resolution=None, sequence=None, molecular_mass=None, symmetry=None, chain_type='PROTEIN', keep_low_density=True, # default from map_box box_cushion=5, soft_mask=True, mask_expand_ratio=1, wrapping=None, log=None): self.model_can_be_outside_bounds = None # not used but required to be set self._map_manager = map_manager self._model = model self._mask_data = None self._force_wrapping = wrapping if wrapping is None: wrapping = self.map_manager().wrapping() self.basis_for_boxing_string = 'around_unique, wrapping = %s' % ( wrapping) if log is None: log = null_out() # Print only if a log is supplied assert isinstance(map_manager, iotbx.map_manager.map_manager) assert self._map_manager.map_data().accessor().origin() == (0, 0, 0) assert resolution is not None if model is not None: assert isinstance(model, mmtbx.model.manager) assert map_manager.is_compatible_model(model) if self.map_manager().wrapping(): # map must be entire unit cell assert map_manager.unit_cell_grid == map_manager.map_data().all() # Get crystal_symmetry self.crystal_symmetry = map_manager.crystal_symmetry() # Convert to map_data from cctbx.maptbx.segment_and_split_map import run as segment_and_split_map assert self._map_manager.map_data().origin() == (0, 0, 0) args = [] ncs_group_obj, remainder_ncs_group_obj, tracking_data = \ segment_and_split_map(args, map_data = self._map_manager.map_data(), crystal_symmetry = self.crystal_symmetry, ncs_obj = self._map_manager.ncs_object(), target_model = target_ncs_au_model, write_files = False, auto_sharpen = False, add_neighbors = False, density_select = False, save_box_map_ncs_au = True, resolution = resolution, solvent_content = solvent_content, chain_type = chain_type, sequence = sequence, molecular_mass = molecular_mass, symmetry = symmetry, keep_low_density = keep_low_density, regions_to_keep = regions_to_keep, box_buffer = box_cushion, soft_mask_extract_unique = soft_mask, mask_expand_ratio = mask_expand_ratio, out = log) from scitbx.matrix import col if not hasattr(tracking_data, 'box_mask_ncs_au_map_data'): raise Sorry(" Extraction of unique part of map failed...") ncs_au_mask_data = tracking_data.box_mask_ncs_au_map_data lower_bounds = ncs_au_mask_data.origin() upper_bounds = tuple(col(ncs_au_mask_data.focus()) - col((1, 1, 1))) print("\nBounds for unique part of map: %s to %s " % (str(lower_bounds), str(upper_bounds)), file=log) # shift the map so it is in the same position as the box map will be in ncs_au_mask_data.reshape(flex.grid(ncs_au_mask_data.all())) assert col(ncs_au_mask_data.all()) == \ col(upper_bounds)-col(lower_bounds)+col((1, 1, 1)) self.gridding_first = lower_bounds self.gridding_last = upper_bounds # Ready with gridding...set up shifts and box crystal_symmetry self.set_shifts_and_crystal_symmetry() # Apply boxing to model, ncs, and map (if available) self.apply_to_model_ncs_and_map() # Note that at this point, self._map_manager has been boxed assert ncs_au_mask_data.all() == self._map_manager.map_data().all() self._mask_data = ncs_au_mask_data # Now separately apply the mask to the boxed map self.apply_around_unique_mask(self._map_manager, resolution=resolution, soft_mask=soft_mask)
def __init__(self, map_manager, model, box_cushion, wrapping=None, force_cube=False, log=sys.stdout): self._map_manager = map_manager self._model = model self._force_wrapping = wrapping if wrapping is None: wrapping = self.map_manager().wrapping() self.basis_for_boxing_string = 'using_model, wrapping = %s' % ( wrapping) # safeguards assert isinstance(map_manager, iotbx.map_manager.map_manager) assert isinstance(model, mmtbx.model.manager) assert self._map_manager.map_data().accessor().origin() == (0, 0, 0) # Make sure working model and map_manager crystal_symmetry match assert map_manager.is_compatible_model(model) assert box_cushion >= 0 if self.map_manager().wrapping(): # map must be entire unit cell assert map_manager.unit_cell_grid == map_manager.map_data().all() # NOTE: We are going to use crystal_symmetry and sites_frac based on # the map_manager (the model could still have different crystal_symmetry) # get items needed to do the shift cs = map_manager.crystal_symmetry() uc = cs.unit_cell() sites_cart = model.get_sites_cart() sites_frac = uc.fractionalize(sites_cart) map_data = map_manager.map_data() # convert box_cushion into fractional vector cushion_frac = flex.double(uc.fractionalize((box_cushion, ) * 3)) # find fractional corners frac_min = sites_frac.min() frac_max = sites_frac.max() frac_max = list(flex.double(frac_max) + cushion_frac) frac_min = list(flex.double(frac_min) - cushion_frac) # find corner grid nodes all_orig = map_data.all() gridding_first = [ifloor(f * n) for f, n in zip(frac_min, all_orig)] gridding_last = [iceil(f * n) for f, n in zip(frac_max, all_orig)] # if forcing a cube, expand the box to be the size of the largest dimension if force_cube: # a simple adjustment of the gridding ranges to enforce a cube. # Note that this might fail if the molecule takes up a large fraction of a non-cube box # so that the smallest dimension cannot be enlarged enough to match the largest. # At the moment no checking occurs for this case # make data number arrays gr_first = np.array(gridding_first) gr_last = np.array(gridding_last) gr_range = gr_last - gr_first gr_diff = np.max( gr_range ) - gr_range # the difference between the three box dimensions and the largest dimension gr_padding = ( gr_diff / 2 ) # The space we would need to add to make all sides equal gr_first_pad = gr_first - gr_padding # The new target values for "gridding_first" gr_last_pad = gr_last + gr_padding # The new target values for "gridding_last" gr_range_pad = gr_last_pad - gr_first_pad # The new range, this should now all be equal and whole assert (np.all(gr_range_pad == gr_range_pad[0]) ) # assert the new box dims will all be the same gr_first_pad = np.floor(gr_first_pad).astype( int) # round the "gridding_first" values down to nearest int gr_last_pad = gr_first_pad + gr_range_pad.astype( int) # add the new grid range to the "gridding_first values self.gridding_first = list(gr_first_pad) self.gridding_last = list(gr_last_pad) else: self.gridding_first = gridding_first self.gridding_last = gridding_last # Ready with gridding...set up shifts and box crystal_symmetry self.set_shifts_and_crystal_symmetry() # Apply boxing to model, ncs, and map (if available) self.apply_to_model_ncs_and_map()