def calculate_map(map_coeffs=None,crystal_symmetry=None,n_real=None): if crystal_symmetry is None: crystal_symmetry=map_coeffs.crystal_symmetry() from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs map_data=get_map_from_map_coeffs( map_coeffs=map_coeffs,crystal_symmetry=crystal_symmetry, n_real=n_real) return map_data
def get_map(params=None, out=sys.stdout): if params.input_files.map_file: from cctbx.maptbx.segment_and_split_map import get_map_object map_data, space_group, unit_cell, crystal_symmetry, origin_frac = get_map_object( file_name=params.input_files.map_file, out=out) map_data = map_data.as_double() elif params.input_files.map_coeffs_file: map_coeffs = get_map_coeffs_from_file( map_coeffs_file=params.input_files.map_coeffs_file, map_coeffs_labels=params.input_files.map_coeffs_labels) if not map_coeffs: raise Sorry("Could not get map coeffs from %s with labels %s" % (params.input_files.map_coeffs_file, params.input_files.map_coeffs_labels)) print >> out, "Map coefficients read from %s with labels %s" % ( params.input_files.map_coeffs_file, str(params.input_files.map_coeffs_labels)) crystal_symmetry = map_coeffs.crystal_symmetry() from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs map_data = get_map_from_map_coeffs(map_coeffs=map_coeffs, crystal_symmetry=crystal_symmetry) if not params.crystal_info.resolution: params.crystal_info.resolution = map_coeffs.d_min() print >> out, "Resolution from map_coeffs is %7.2f A" % ( params.crystal_info.resolution) else: raise Sorry("Need ccp4 map or map_coeffs") if params.crystal_info.resolution is None: raise Sorry("Need resolution if map is supplied") return map_data, crystal_symmetry
def get_map(params=None,out=sys.stdout): if params.input_files.map_file: from cctbx.maptbx.segment_and_split_map import get_map_object map_data,space_group,unit_cell,crystal_symmetry,origin_frac=get_map_object( file_name=params.input_files.map_file,out=out) map_data=map_data.as_double() elif params.input_files.map_coeffs_file: map_coeffs=get_map_coeffs_from_file( map_coeffs_file=params.input_files.map_coeffs_file, map_coeffs_labels=params.input_files.map_coeffs_labels) if not map_coeffs: raise Sorry("Could not get map coeffs from %s with labels %s" %( params.input_files.map_coeffs_file,params.input_files.map_coeffs_labels)) print >>out,"Map coefficients read from %s with labels %s" %( params.input_files.map_coeffs_file, str(params.input_files.map_coeffs_labels)) crystal_symmetry=map_coeffs.crystal_symmetry() from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs map_data=get_map_from_map_coeffs( map_coeffs=map_coeffs,crystal_symmetry=crystal_symmetry) if not params.crystal_info.resolution: params.crystal_info.resolution=map_coeffs.d_min() print >>out,"Resolution from map_coeffs is %7.2f A" %( params.crystal_info.resolution) else: raise Sorry("Need ccp4 map or map_coeffs") if params.crystal_info.resolution is None: raise Sorry("Need resolution if map is supplied") return map_data,crystal_symmetry
def get_map_and_model(params=None, map_data=None, crystal_symmetry=None, pdb_inp=None, ncs_obj=None, half_map_data_list=None, map_coords_inside_cell=True, get_map_labels=None, out=sys.stdout): acc=None # accessor used to shift map back to original location if desired origin_frac=(0,0,0) map_labels=None if map_data and crystal_symmetry: original_crystal_symmetry=crystal_symmetry original_unit_cell_grid=None acc=map_data.accessor() shift_needed = not \ (map_data.focus_size_1d() > 0 and map_data.nd() == 3 and map_data.is_0_based()) if(shift_needed): origin_shift=( map_data.origin()[0]/map_data.all()[0], map_data.origin()[1]/map_data.all()[1], map_data.origin()[2]/map_data.all()[2]) origin_frac=origin_shift # NOTE: fraction of NEW cell map_data = map_data.shift_origin() else: origin_frac=(0.,0.,0.) elif params.input_files.map_file: print >>out,"\nReading map from %s\n" %( params.input_files.map_file) from cctbx.maptbx.segment_and_split_map import get_map_object map_data,space_group,unit_cell,crystal_symmetry,origin_frac,acc,\ original_crystal_symmetry,original_unit_cell_grid,map_labels=\ get_map_object(file_name=params.input_files.map_file, must_allow_sharpening=(not params.control.ignore_map_limitations), get_map_labels=True,out=out) map_data=map_data.as_double() if origin_frac != (0,0,0) and acc is None: print >>out,"\nWARNING: Unable to place output map at position of "+\ "input map though input map has non-zero origin at %s\n" %( str(origin_frac)) elif params.input_files.map_coeffs_file: map_coeffs=get_map_coeffs_from_file( map_coeffs_file=params.input_files.map_coeffs_file, map_coeffs_labels=params.input_files.map_coeffs_labels) if not map_coeffs: raise Sorry("Could not get map coeffs from %s with labels %s" %( params.input_files.map_coeffs_file,params.input_files.map_coeffs_labels)) print >>out,"Map coefficients read from %s with labels %s" %( params.input_files.map_coeffs_file, str(params.input_files.map_coeffs_labels)) crystal_symmetry=map_coeffs.crystal_symmetry() from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs map_data=get_map_from_map_coeffs( map_coeffs=map_coeffs,crystal_symmetry=crystal_symmetry) acc=map_data.accessor() original_crystal_symmetry=crystal_symmetry original_unit_cell_grid=None if not params.crystal_info.resolution: params.crystal_info.resolution=map_coeffs.d_min() print >>out,"Resolution from map_coeffs is %7.2f A" %( params.crystal_info.resolution) else: raise Sorry("Need ccp4 map or map_coeffs") if params.input_files.half_map_file: if len(params.input_files.half_map_file) != 2: raise Sorry("Please supply zero or two half_map files") half_map_data_list=[] from cctbx.maptbx.segment_and_split_map import get_map_object for file_name in params.input_files.half_map_file: print >>out,"\nReading half-map from %s\n" %(file_name) half_map_data,half_map_space_group,half_map_unit_cell,\ half_map_crystal_symmetry,half_map_origin_frac,half_map_acc,\ half_map_original_crystal_symmetry,half_map_original_unit_cell_grid=\ get_map_object(file_name=file_name,out=out) half_map_data=half_map_data.as_double() assert half_map_crystal_symmetry.is_similar_symmetry(crystal_symmetry) half_map_data_list.append(half_map_data) if params.crystal_info.resolution is None: raise Sorry("Need resolution if map is supplied") if params.crystal_info.resolution >= 10: print >>out,"\n** WARNING: auto_sharpen is designed for maps at a "+\ "resolution of about 4.5 A\nor better. Sharpening may be"+\ "poor at %7.0f A" %(params.crystal_info.resolution) if params.input_files.pdb_file and not pdb_inp: # get model model_file=params.input_files.pdb_file if not os.path.isfile(model_file): raise Sorry("Missing the model file: %s" %(model_file)) pdb_inp=iotbx.pdb.input(file_name=model_file) if pdb_inp: # XXX added 2019-05-05 if origin_frac != (0,0,0): print >>out,"Shifting model by %s" %(str(origin_frac)) from cctbx.maptbx.segment_and_split_map import \ apply_shift_to_pdb_hierarchy origin_shift=crystal_symmetry.unit_cell().orthogonalize( (-origin_frac[0],-origin_frac[1],-origin_frac[2])) pdb_inp=apply_shift_to_pdb_hierarchy( origin_shift=origin_shift, crystal_symmetry=crystal_symmetry, pdb_hierarchy=pdb_inp.construct_hierarchy(), out=out).as_pdb_input() if map_coords_inside_cell: # put inside (0,1) pdb_inp=map_inside_cell(pdb_inp,crystal_symmetry=crystal_symmetry) if params.input_files.ncs_file and not ncs_obj: # NCS from cctbx.maptbx.segment_and_split_map import get_ncs ncs_obj,dummy_tracking_data=get_ncs(params,out=out) if origin_frac != (0,0,0): origin_shift=crystal_symmetry.unit_cell().orthogonalize( (-origin_frac[0],-origin_frac[1],-origin_frac[2])) print >>out,"Shifting NCS by (%7.2f,%7.2f,%7.2f) " %((origin_shift)) from scitbx.math import matrix ncs_obj=ncs_obj.coordinate_offset( coordinate_offset=matrix.col(origin_shift)) if get_map_labels: return pdb_inp,map_data,half_map_data_list,ncs_obj,crystal_symmetry,acc,\ original_crystal_symmetry,original_unit_cell_grid,map_labels else: return pdb_inp,map_data,half_map_data_list,ncs_obj,crystal_symmetry,acc,\ original_crystal_symmetry,original_unit_cell_grid
def calculate_map(map_coeffs=None,crystal_symmetry=None,n_real=None): if crystal_symmetry is None: crystal_symmetry=map_coeffs.crystal_symmetry() from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs return get_map_from_map_coeffs(map_coeffs=map_coeffs,crystal_symmetry=crystal_symmetry, n_real=n_real)
def generate_map( output_map_file_name=None, map_coeffs=None, # Required high_resolution=3, gridding=None, origin_shift_grid_units=None, low_resolution_fourier_noise_fraction=0, high_resolution_fourier_noise_fraction=0, low_resolution_real_space_noise_fraction=0, high_resolution_real_space_noise_fraction=0, low_resolution_noise_cutoff=None, log=sys.stdout): ''' Generate map from map_coefficients and add noise in Fourier or real space This function typically accessed and tested through map_model_manager Summary: -------- Calculate a map and optionally add noise to it. Supply map coefficients (miller_array object) and types of noise to add, along with optional gridding (nx,ny,nz), and origin_shift_grid_units. Optionally create map coefficients from a model and optionally generate a model. Unique aspect of this noise generation is that it can be specified whether the noise is local in real space (every point in a map gets a random value before Fourier filtering), or local in Fourier space (every Fourier coefficient gets a complex random offset). Also the relative contribution of each type of noise vs resolution can be controlled. Parameters: ----------- output_map_file_name (string, None): Output map file (MRC/CCP4 format) map_coeffs (miller.array object, None) : map coefficients high_resolution (float, 3): high_resolution limit (A) gridding (tuple (nx,ny,nz), None): Gridding of map (optional) origin_shift_grid_units (tuple (ix,iy,iz), None): Move location of origin of resulting map to (ix,iy,iz) before writing out low_resolution_fourier_noise_fraction (float, 0): Low-res Fourier noise high_resolution_fourier_noise_fraction (float, 0): High-res Fourier noise low_resolution_real_space_noise_fraction(float, 0): Low-res real-space noise high_resolution_real_space_noise_fraction (float, 0): High-res real-space noise low_resolution_noise_cutoff (float, None): Low resolution where noise starts to be added ''' if gridding: if type(gridding) == type([1, 2, 3]) and type(gridding[0]) == type(1): pass # already fine else: gridding = [] for x in str(gridding).replace(",", "").split(): gridding.append(int(x)) low_resolution_fourier_noise_fraction = float( low_resolution_fourier_noise_fraction) high_resolution_fourier_noise_fraction = float( high_resolution_fourier_noise_fraction) low_resolution_real_space_noise_fraction = float( low_resolution_real_space_noise_fraction) high_resolution_real_space_noise_fraction = float( high_resolution_real_space_noise_fraction) if low_resolution_noise_cutoff: low_resolution_noise_cutoff = float(low_resolution_noise_cutoff) if high_resolution: high_resolution = float(high_resolution) map_coeffs = map_coeffs.resolution_filter(d_min=high_resolution) # Calculate a map from Fourier coefficients: from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs map_data = get_map_from_map_coeffs( map_coeffs=map_coeffs, crystal_symmetry=map_coeffs.crystal_symmetry(), n_real=gridding, apply_sigma_scaling=False) # Optionally add noise to this map as an additive noise map # Noise can be added in Fourier space (leads to correlated errors # in real space) or in real space (leads to correlated errors # in Fourier space). # Noise is Fourier-weighted as function of resolution. # RMS noise to add at low-resolution (Fourier based noise) as fraction of RMS # value in map at low-resolution is: low_resolution_fourier_noise_fraction # RMS Fourier high-res noise:is high_resolution_fourier_noise_fraction # RMS real-space low-res noise:is low_resolution_real_space_noise_fraction # RMS real-space high-res noise:is high_resolution_real_space_noise_fraction # Low-resolution where noise begins to be added is low_resolution_noise_cutoff if (low_resolution_fourier_noise_fraction or high_resolution_fourier_noise_fraction): fourier_noise_map = get_fourier_noise_map( n_real=map_data.all(), map_coeffs=map_coeffs, low_resolution_fourier_noise_fraction= low_resolution_fourier_noise_fraction, high_resolution_fourier_noise_fraction= high_resolution_fourier_noise_fraction, high_resolution=high_resolution, low_resolution_noise_cutoff=low_resolution_noise_cutoff, log=log) else: fourier_noise_map = None if (low_resolution_real_space_noise_fraction or high_resolution_real_space_noise_fraction): real_space_noise_map = get_real_space_noise_map( map_data=map_data, map_coeffs=map_coeffs, low_resolution_real_space_noise_fraction= low_resolution_real_space_noise_fraction, high_resolution_real_space_noise_fraction= high_resolution_real_space_noise_fraction, high_resolution=high_resolution, low_resolution_noise_cutoff=low_resolution_noise_cutoff, log=log) else: real_space_noise_map = None if fourier_noise_map: map_data += fourier_noise_map if real_space_noise_map: map_data += real_space_noise_map # Create a map_manager object directly (unusual use of map_manager) from iotbx.map_manager import map_manager mm = map_manager(map_data=map_data, unit_cell_grid=map_data.all(), unit_cell_crystal_symmetry=map_coeffs.crystal_symmetry(), origin_shift_grid_units=origin_shift_grid_units) if output_map_file_name: mm.write_map(output_map_file_name) else: print("Generated map with origin at %s and size of %s" % (mm.map_data().origin(), mm.map_data().all()), file=log) return mm
def get_map_and_model(params=None, map_data=None, crystal_symmetry=None, pdb_inp=None, ncs_obj=None, half_map_data_list=None, out=sys.stdout): acc = None # accessor used to shift map back to original location if desired origin_frac = (0, 0, 0) acc = None if map_data and crystal_symmetry: pass # we are set elif params.input_files.map_file: print >> out, "\nReading map from %s\n" % (params.input_files.map_file) from cctbx.maptbx.segment_and_split_map import get_map_object map_data,space_group,unit_cell,crystal_symmetry,origin_frac,acc=\ get_map_object(file_name=params.input_files.map_file,out=out) map_data = map_data.as_double() if origin_frac != (0, 0, 0) and acc is None: print >>out,"\nWARNING: Unable to place output map at position of "+\ "input map though input map has non-zero origin at %s\n" %( str(origin_frac)) elif params.input_files.map_coeffs_file: map_coeffs = get_map_coeffs_from_file( map_coeffs_file=params.input_files.map_coeffs_file, map_coeffs_labels=params.input_files.map_coeffs_labels) if not map_coeffs: raise Sorry("Could not get map coeffs from %s with labels %s" % (params.input_files.map_coeffs_file, params.input_files.map_coeffs_labels)) print >> out, "Map coefficients read from %s with labels %s" % ( params.input_files.map_coeffs_file, str(params.input_files.map_coeffs_labels)) crystal_symmetry = map_coeffs.crystal_symmetry() from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs map_data = get_map_from_map_coeffs(map_coeffs=map_coeffs, crystal_symmetry=crystal_symmetry) acc = map_data.accessor() if not params.crystal_info.resolution: params.crystal_info.resolution = map_coeffs.d_min() print >> out, "Resolution from map_coeffs is %7.2f A" % ( params.crystal_info.resolution) else: raise Sorry("Need ccp4 map or map_coeffs") if params.input_files.half_map_file: if len(params.input_files.half_map_file) != 2: raise Sorry("Please supply zero or two half_map files") half_map_data_list = [] from cctbx.maptbx.segment_and_split_map import get_map_object for file_name in params.input_files.half_map_file: print >> out, "\nReading half-map from %s\n" % (file_name) half_map_data,half_map_space_group,half_map_unit_cell,\ half_map_crystal_symmetry,half_map_origin_frac,half_map_acc=\ get_map_object(file_name=file_name,out=out) half_map_data = half_map_data.as_double() assert half_map_crystal_symmetry.is_similar_symmetry( crystal_symmetry) half_map_data_list.append(half_map_data) if params.crystal_info.resolution is None: raise Sorry("Need resolution if map is supplied") if params.input_files.pdb_file and not pdb_inp: # get model model_file = params.input_files.pdb_file if not os.path.isfile(model_file): raise Sorry("Missing the model file: %s" % (model_file)) pdb_inp = iotbx.pdb.input(file_name=model_file) if origin_frac != (0, 0, 0): print >> out, "Shifting model by %s" % (str(origin_frac)) from cctbx.maptbx.segment_and_split_map import \ apply_shift_to_pdb_hierarchy origin_shift = crystal_symmetry.unit_cell().orthogonalize( (-origin_frac[0], -origin_frac[1], -origin_frac[2])) pdb_inp = apply_shift_to_pdb_hierarchy( origin_shift=origin_shift, crystal_symmetry=crystal_symmetry, pdb_hierarchy=pdb_inp.construct_hierarchy(), out=out).as_pdb_input() if params.input_files.ncs_file and not ncs_obj: # NCS from cctbx.maptbx.segment_and_split_map import get_ncs ncs_obj, dummy_tracking_data = get_ncs(params, out=out) if origin_frac != (0, 0, 0): origin_shift = crystal_symmetry.unit_cell().orthogonalize( (-origin_frac[0], -origin_frac[1], -origin_frac[2])) print >> out, "Shifting NCS by (%7.2f,%7.2f,%7.2f) " % ( (origin_shift)) from scitbx.math import matrix ncs_obj = ncs_obj.coordinate_offset( coordinate_offset=matrix.col(origin_shift)) return pdb_inp, map_data, half_map_data_list, ncs_obj, crystal_symmetry, acc
def generate_map(map_coeffs=None, high_resolution=3, gridding=None, origin_shift_grid_units=None, low_resolution_fourier_noise_fraction=0, high_resolution_fourier_noise_fraction=0, low_resolution_real_space_noise_fraction=0, high_resolution_real_space_noise_fraction=0, output_map_file_name=None, log=sys.stdout, **pass_through_kw ): # pass_through_kw picks up all the keywords that are to be # passed to other routines ''' generate_map Convenience method to calculate a map and optionally add noise to it. Supply map coefficients (miller_array object) and types of noise to add, along with optional gridding (nx,ny,nz), and origin_shift_grid_units. Not implemented: Unique aspect of this noise generation is that it can be specified whether the noise is local in real space (every point in a map gets a random value before Fourier filtering), or local in Fourier space (every Fourier coefficient gets a complex random offset). Also the relative contribution of each type of noise vs resolution can be controlled. Full list of keywords that can be supplied. These affect generate_model, generate_map_coefficients and generate_map: model_file_name=None # file to read model from n_residues=10, # how many residues to include b_iso=30, # what b_iso to set all the atoms to box_buffer=5, # buffer around atoms start_res=None, # residue to start with space_group_number=1, # space group number for model and map output_model_file_name=None, # file name for model (if any) random_seed=None, # random seed for shake shake=None, # rms offset for each atom if any scattering_table='electron', # scattering table, electron n_gaussian gridding=None, # optional gridding for map origin_shift_grid_units=None, # optional origin for map low_resolution_fourier_noise_fraction=0, # fourier noise lowres high_resolution_fourier_noise_fraction=0, # hires low_resolution_real_space_noise_fraction=0, # real-space noise lowres high_resolution_real_space_noise_fraction=0, # real-space noise hires output_map_file_name=None, # optional output map file namd ''' if gridding: if type(gridding) == type([1, 2, 3]) and type(gridding[0]) == type(1): pass # already fine else: gridding = [] for x in str(gridding).replace(",", "").split(): gridding.append(int(x)) if not map_coeffs: # get map coefficients map_coeffs = generate_map_coefficients(high_resolution=high_resolution, log=log, **pass_through_kw) if high_resolution: map_coeffs = map_coeffs.resolution_filter(d_min=high_resolution) # Calculate a map from Fourier coefficients: from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs map_data = get_map_from_map_coeffs( map_coeffs=map_coeffs, crystal_symmetry=map_coeffs.crystal_symmetry(), n_real=gridding, apply_sigma_scaling=False) from iotbx.map_manager import map_manager mm = map_manager(map_data=map_data, unit_cell_grid=map_data.all(), unit_cell_parameters=map_coeffs.crystal_symmetry( ).unit_cell().parameters(), space_group_number=map_coeffs.crystal_symmetry(). space_group().info().symbol_and_number().split('(')[0], origin_shift_grid_units=origin_shift_grid_units) if output_map_file_name: mm.write_map(output_map_file_name) else: print("Generated map with origin at %s and size of %s" % (mm.map_data().origin(), mm.map_data().all()), file=log) return mm