def output_map(f_obs, r_free_flags, xray_structure, mask_data, filename, params, log): f_calc = f_obs.structure_factors_from_scatterers( xray_structure=xray_structure).f_calc() mask = f_obs.structure_factors_from_map(map=mask_data, use_scale=True, anomalous_flag=False, use_sg=False) # is it really use_sg = false? fmodel = mmtbx.f_model.manager(f_obs=f_obs, r_free_flags=r_free_flags, f_calc=f_calc, f_mask=mask) fmodel.update_all_scales() print >> log, "r_work=%6.4f r_free=%6.4f" % (fmodel.r_work(), fmodel.r_free()) print >> log, "*" * 79 mc_diff = map_tools.electron_density_map(fmodel=fmodel).map_coefficients( map_type="mFo-DFc", isotropize=True, fill_missing=False) if (params.mask_output and filename != 'bias_omit'): ccp4_map.write_ccp4_map(file_name="mask_" + filename + ".ccp4", unit_cell=f_obs.unit_cell(), space_group=f_obs.space_group(), map_data=mask_data, labels=flex.std_string([""])) return mc_diff
def output_map(f_obs, r_free_flags, xray_structure, mask_data, filename, params, log): f_calc = f_obs.structure_factors_from_scatterers( xray_structure = xray_structure).f_calc() mask = f_obs.structure_factors_from_map( map = mask_data, use_scale = True, anomalous_flag = False, use_sg = False) # is it really use_sg = false? fmodel = mmtbx.f_model.manager( f_obs = f_obs, r_free_flags = r_free_flags, f_calc = f_calc, f_mask = mask) fmodel.update_all_scales() print >> log, "r_work=%6.4f r_free=%6.4f" % (fmodel.r_work(), fmodel.r_free()) print >> log, "*"*79 mc_diff = map_tools.electron_density_map( fmodel = fmodel).map_coefficients( map_type = "mFo-DFc", isotropize = True, fill_missing = False) if (params.mask_output and filename != 'bias_omit'): ccp4_map.write_ccp4_map( file_name = "mask_"+filename+".ccp4", unit_cell = f_obs.unit_cell(), space_group = f_obs.space_group(), map_data = mask_data, labels = flex.std_string([""])) return mc_diff
def compute_map(fmodel, crystal_gridding, map_type): map_coefficients = map_tools.electron_density_map( fmodel=fmodel).map_coefficients(map_type=map_type, isotropize=True, fill_missing=False) fft_map = cctbx.miller.fft_map(crystal_gridding=crystal_gridding, fourier_coefficients=map_coefficients) fft_map.apply_sigma_scaling() return fft_map.real_map_unpadded()
def compute_map(fmodel, crystal_gridding, map_type): map_coefficients = map_tools.electron_density_map( fmodel = fmodel).map_coefficients( map_type = map_type, isotropize = True, fill_missing = False) fft_map = cctbx.miller.fft_map( crystal_gridding = crystal_gridding, fourier_coefficients = map_coefficients) fft_map.apply_sigma_scaling() return fft_map.real_map_unpadded()
def get_map(fmodel): map_coeffs = map_tools.electron_density_map(fmodel = fmodel).map_coefficients( map_type = "2mFo-DFc", isotropize = True, fill_missing = False) crystal_gridding = fmodel.f_obs().crystal_gridding( d_min = fmodel.f_obs().d_min(), symmetry_flags = maptbx.use_space_group_symmetry, resolution_factor = 1./4) fft_map = miller.fft_map( crystal_gridding = crystal_gridding, fourier_coefficients = map_coeffs) fft_map.apply_sigma_scaling() return fft_map.real_map_unpadded()
def get_poler_diff_map(f_obs): fmodel = mmtbx.f_model.manager(f_obs=f_obs, r_free_flags=r_free_flags, f_calc=f_calc, f_mask=f_mask) fmodel.update_all_scales(remove_outliers=False) mc_diff = map_tools.electron_density_map( fmodel=fmodel).map_coefficients(map_type="mFo-DFc", isotropize=True, fill_missing=False) fft_map = miller.fft_map(crystal_gridding=cpm_obj.crystal_gridding, fourier_coefficients=mc_diff) fft_map.apply_sigma_scaling() map_data = fft_map.real_map_unpadded() return mmtbx.utils.extract_box_around_model_and_map( xray_structure=xrs_selected, map_data=map_data, box_cushion=2.1)
def get_fmodel_and_map_coefficients(self, xray_structure, mask_data): f_calc = self.f_obs.structure_factors_from_scatterers( xray_structure=xray_structure).f_calc() mask = self.f_obs.structure_factors_from_map(map=mask_data, use_scale=True, anomalous_flag=False, use_sg=False) # To check: is it really use_sg = false? fmodel = mmtbx.f_model.manager(f_obs=self.f_obs, r_free_flags=self.r_free_flags, f_calc=f_calc, f_mask=mask) fmodel.update_all_scales() mc_fofc = map_tools.electron_density_map( fmodel=fmodel).map_coefficients(map_type="mFo-DFc", isotropize=True, fill_missing=False) return fmodel, mc_fofc
def get_poler_diff_map(f_obs): fmodel = mmtbx.f_model.manager( f_obs = f_obs, r_free_flags = r_free_flags, f_calc = f_calc, f_mask = f_mask) fmodel.update_all_scales(remove_outliers=False) mc_diff = map_tools.electron_density_map( fmodel = fmodel).map_coefficients( map_type = "mFo-DFc", isotropize = True, fill_missing = False) fft_map = miller.fft_map( crystal_gridding = cpm_obj.crystal_gridding, fourier_coefficients = mc_diff) fft_map.apply_sigma_scaling() map_data = fft_map.real_map_unpadded() return mmtbx.utils.extract_box_around_model_and_map( xray_structure = xrs_selected, map_data = map_data, box_cushion = 2.1)
def get_polder_diff_map(self, f_obs, r_free_flags, f_calc, f_mask, model_selected, box_cushion): fmodel = mmtbx.f_model.manager(f_obs=f_obs, r_free_flags=r_free_flags, f_calc=f_calc, f_mask=f_mask) fmodel.update_all_scales(remove_outliers=False) mc_diff = map_tools.electron_density_map( fmodel=fmodel).map_coefficients(map_type="mFo-DFc", isotropize=True, fill_missing=False) fft_map = miller.fft_map(crystal_gridding=self.crystal_gridding, fourier_coefficients=mc_diff) fft_map.apply_sigma_scaling() mm = fft_map.as_map_manager() import iotbx.map_and_model inputs = iotbx.map_and_model.input(model=model_selected.deep_copy(), map_manager=mm, box=True) return inputs.shift_manager()
def __init__(self, f_obs, r_free_flags, xray_structure, use_resolve, use_omit, use_max_map, sharp, use_unsharp_masking, resolution_factor, n_inner_loop=10, n_outer_loop=10, log=None): adopt_init_args(self, locals()) if (self.log is None): self.log = sys.stdout print("Start FEM...", file=self.log) self.prepare_f_obs_and_flags() self.mc_orig = self.compute_original_map() self.b_overall = None print("Create un-sharpened fmodel...", file=self.log) self.fmodel_nosharp = self.create_fmodel(show=True).deep_copy() if (self.sharp): self.remove_common_isotropic_adp() print("Create fmodel...", file=self.log) self.fmodel = self.create_fmodel(show=True) self.crystal_gridding = self.f_obs.crystal_gridding( d_min=self.fmodel.f_obs().d_min(), symmetry_flags=maptbx.use_space_group_symmetry, resolution_factor=self.resolution_factor) # initial maps print("Compute initial maps...", file=self.log) self.mc = map_tools.electron_density_map( fmodel=self.fmodel).map_coefficients(map_type="2mFo-DFc", isotropize=True, fill_missing=False) self.mc_fill = map_tools.electron_density_map( fmodel=self.fmodel).map_coefficients(map_type="2mFo-DFc", isotropize=True, fill_missing=True) print("Finding typical atom volumes...", file=self.log) self.selection = good_atoms_selection( crystal_gridding=self.crystal_gridding, map_coeffs=self.mc_fill, xray_structure=self.fmodel.xray_structure) # main FEM loop m = self.outer_loop() m = low_volume_density_elimination(m=m, fmodel=self.fmodel, selection=self.selection) self.zero_below_threshold(m=m) # HE m = maptbx.volume_scale(map=m, n_bins=10000).map_data() # create Fourier ripples filter sel = m < 0.5 msk = m.set_selected(sel, 0) sel = msk >= 0.5 msk = msk.set_selected(sel, 1) #XXX maptbx.sharpen(map_data=m, index_span=2, n_averages=1, #XXX allow_negatives=False) # Use Resolve filter m_resolve = self.resolve_filter_map() if (m_resolve is not None): m = m * m_resolve # Use OMIT if (self.use_omit): comit = mmtbx.maps.composite_omit_map.run( fmodel=self.fmodel_nosharp, crystal_gridding=self.crystal_gridding, box_size_as_fraction=0.2, max_boxes=2000, neutral_volume_box_cushion_width=2, full_resolution_map=True, log=self.log) omit_map = comit.as_p1_map() #ccp4_map(cg=self.crystal_gridding, file_name="omit1.ccp4", map_data=omit_map) omit_map = low_volume_density_elimination(m=omit_map, fmodel=self.fmodel, selection=self.selection, end=16) #ccp4_map(cg=self.crystal_gridding, file_name="omit2.ccp4", map_data=omit_map) sel = omit_map < 1.5 omit_map = omit_map.set_selected(sel, 0) sel = omit_map >= 1.5 omit_map = omit_map.set_selected(sel, 1) m = m * omit_map # # Extra filter: seems to ne redundant, TBD. # #omit_mc = comit.result_as_sf() #omit_map = get_map(mc=omit_mc, cg=self.crystal_gridding) #omit_map = low_volume_density_elimination(m=omit_map, fmodel=self.fmodel, selection=self.selection) #ccp4_map(cg=self.crystal_gridding, file_name="omit2.ccp4", map_data=omit_map) #sel = omit_map<0.5 #omit_map = omit_map.set_selected(sel, 0) #sel = omit_map>=0.5 #omit_map = omit_map.set_selected(sel, 1) #m = m * omit_map # self.mc_result = self.mc_fill.structure_factors_from_map( map=m, use_scale=True, anomalous_flag=False, use_sg=False) if (self.sharp): self.mc_result = mmtbx.maps.b_factor_sharpening_by_map_kurtosis_maximization( map_coeffs=self.mc_result, show=True, b_only=False) self.map_result = get_map(mc=self.mc_result, cg=self.crystal_gridding) * msk
def compute_original_map(self): return map_tools.electron_density_map(fmodel=self.create_fmodel( update_f_part1=False)).map_coefficients(map_type="2mFo-DFc", isotropize=False, fill_missing=False)
def __init__( self, fmodel, map_type = "2mFo-DFc", mask_data = None, crystal_gridding = None, number_of_kicks = 100, macro_cycles = 10, kick_completeness = 0.95, omit = True): fmodel = self.convert_to_non_anomalous(fmodel=fmodel) from mmtbx import map_tools self.mc_orig = map_tools.electron_density_map( fmodel=fmodel).map_coefficients( map_type = "2mFo-DFc", isotropize = True, fill_missing = False) md_orig = get_map(map_coeffs=self.mc_orig, crystal_gridding=crystal_gridding) # model missing self.complete_set = map_tools.resolve_dm_map( fmodel = fmodel, map_coeffs = self.mc_orig, pdb_inp = None, use_model_hl = True, fill = True) md_complete_set = get_map(map_coeffs=self.complete_set, crystal_gridding=crystal_gridding) self.missing = self.complete_set.lone_set(self.mc_orig) # Kick map coefficients md_kick = kick_map_coeffs( map_coeffs = self.mc_orig, crystal_gridding = crystal_gridding, number_of_kicks = number_of_kicks, macro_cycles = macro_cycles, missing = self.missing, kick_completeness = kick_completeness) self.mc_kick = self.map_coeffs_from_map(map_data=md_kick) # Kick fmodel md_fm = kick_fmodel( fmodel = fmodel, map_type = map_type, crystal_gridding = crystal_gridding, number_of_kicks = number_of_kicks, macro_cycles = macro_cycles, missing = self.missing, kick_completeness = kick_completeness) self.mc_fm = self.map_coeffs_from_map(map_data=md_fm) if(omit): # Kick OMIT map com1 = mmtbx.maps.composite_omit_map.run( crystal_gridding = crystal_gridding, fmodel = fmodel.deep_copy(), # XXX full_resolution_map = True, box_size_as_fraction = 0.03) md_com1 = kick_map_coeffs( map_coeffs = com1.map_coefficients(), crystal_gridding = crystal_gridding, number_of_kicks = number_of_kicks, macro_cycles = macro_cycles, phases_only = True, missing = self.missing, kick_completeness = kick_completeness) self.mc_com1 = self.map_coeffs_from_map(map_data=md_com1) # Kick OMIT map 2 com2 = mmtbx.maps.composite_omit_map.run( crystal_gridding = crystal_gridding, fmodel = fmodel.deep_copy(), # XXX full_resolution_map = True, box_size_as_fraction = 0.03) md_com2 = kick_map_coeffs( map_coeffs = com2.map_coefficients(), crystal_gridding = crystal_gridding, number_of_kicks = number_of_kicks, macro_cycles = macro_cycles, phases_only = True, missing = self.missing, kick_completeness = kick_completeness) self.mc_com2 = self.map_coeffs_from_map(map_data=md_com2) # combine maps def intersect(m1,m2, use_average): maptbx.intersection( map_data_1 = m1, map_data_2 = m2, thresholds = flex.double([0,0.1,0.2,0.3,0.4,0.5]), average = False) if(use_average): return (m1+m2)/2 else: return m1 m = (md_kick + md_fm)/2 m = intersect(m, md_kick, use_average=True) m = intersect(m, md_fm, use_average=True) if(omit): m = intersect(m, md_com1, use_average=False) m = intersect(m, md_com2, use_average=False) m = intersect(m, md_orig, use_average=False) m = intersect(m, md_complete_set, use_average=False) self.map_data_result = m self.mc_result = self.map_coeffs_from_map(map_data=self.map_data_result)
def __init__( self, f_obs, r_free_flags, xray_structure, use_resolve, use_omit, use_max_map, sharp, use_unsharp_masking, resolution_factor, n_inner_loop = 10, n_outer_loop = 10, log = None): adopt_init_args(self, locals()) if(self.log is None): self.log = sys.stdout print >> self.log, "Start FEM..." self.prepare_f_obs_and_flags() self.mc_orig = self.compute_original_map() self.b_overall = None print >> self.log, "Create un-sharpened fmodel..." self.fmodel_nosharp = self.create_fmodel(show=True).deep_copy() if(self.sharp): self.remove_common_isotropic_adp() print >> self.log, "Create fmodel..." self.fmodel = self.create_fmodel(show=True) self.crystal_gridding = self.f_obs.crystal_gridding( d_min = self.fmodel.f_obs().d_min(), symmetry_flags = maptbx.use_space_group_symmetry, resolution_factor = self.resolution_factor) # initial maps print >> self.log, "Compute initial maps..." self.mc = map_tools.electron_density_map( fmodel=self.fmodel).map_coefficients( map_type = "2mFo-DFc", isotropize = True, fill_missing = False) self.mc_fill = map_tools.electron_density_map( fmodel=self.fmodel).map_coefficients( map_type = "2mFo-DFc", isotropize = True, fill_missing = True) print >> self.log, "Finding typical atom volumes..." self.selection = good_atoms_selection( crystal_gridding = self.crystal_gridding, map_coeffs = self.mc_fill, xray_structure = self.fmodel.xray_structure) # main FEM loop m = self.outer_loop() m = low_volume_density_elimination(m=m, fmodel=self.fmodel, selection=self.selection) self.zero_below_threshold(m = m) # HE m = maptbx.volume_scale(map = m, n_bins = 10000).map_data() # create Fourier ripples filter sel = m<0.5 msk = m.set_selected(sel, 0) sel = msk>=0.5 msk = msk.set_selected(sel, 1) #XXX maptbx.sharpen(map_data=m, index_span=2, n_averages=1, #XXX allow_negatives=False) # Use Resolve filter m_resolve = self.resolve_filter_map() if(m_resolve is not None): m = m * m_resolve # Use OMIT if(self.use_omit): comit = mmtbx.maps.composite_omit_map.run( fmodel = self.fmodel_nosharp, crystal_gridding = self.crystal_gridding, box_size_as_fraction = 0.2, max_boxes = 2000, neutral_volume_box_cushion_width = 2, full_resolution_map = True, log = self.log) omit_map = comit.as_p1_map() #ccp4_map(cg=self.crystal_gridding, file_name="omit1.ccp4", map_data=omit_map) omit_map = low_volume_density_elimination(m=omit_map, fmodel=self.fmodel, selection=self.selection,end=16) #ccp4_map(cg=self.crystal_gridding, file_name="omit2.ccp4", map_data=omit_map) sel = omit_map<1.5 omit_map = omit_map.set_selected(sel, 0) sel = omit_map>=1.5 omit_map = omit_map.set_selected(sel, 1) m = m * omit_map # # Extra filter: seems to ne redundant, TBD. # #omit_mc = comit.result_as_sf() #omit_map = get_map(mc=omit_mc, cg=self.crystal_gridding) #omit_map = low_volume_density_elimination(m=omit_map, fmodel=self.fmodel, selection=self.selection) #ccp4_map(cg=self.crystal_gridding, file_name="omit2.ccp4", map_data=omit_map) #sel = omit_map<0.5 #omit_map = omit_map.set_selected(sel, 0) #sel = omit_map>=0.5 #omit_map = omit_map.set_selected(sel, 1) #m = m * omit_map # self.mc_result = self.mc_fill.structure_factors_from_map( map = m, use_scale = True, anomalous_flag = False, use_sg = False) if(self.sharp): self.mc_result=mmtbx.maps.b_factor_sharpening_by_map_kurtosis_maximization( map_coeffs=self.mc_result, show=True, b_only=False) self.map_result = get_map(mc=self.mc_result, cg=self.crystal_gridding)*msk
def compute_original_map(self): return map_tools.electron_density_map( fmodel = self.create_fmodel(update_f_part1=False)).map_coefficients( map_type = "2mFo-DFc", isotropize = False, fill_missing = False)
def __init__(self, fmodel, map_type="2mFo-DFc", mask_data=None, crystal_gridding=None, number_of_kicks=100, macro_cycles=10, kick_completeness=0.95, omit=True): fmodel = self.convert_to_non_anomalous(fmodel=fmodel) from mmtbx import map_tools self.mc_orig = map_tools.electron_density_map( fmodel=fmodel).map_coefficients(map_type="2mFo-DFc", isotropize=True, fill_missing=False) md_orig = get_map(map_coeffs=self.mc_orig, crystal_gridding=crystal_gridding) # model missing self.complete_set = map_tools.resolve_dm_map(fmodel=fmodel, map_coeffs=self.mc_orig, pdb_inp=None, use_model_hl=True, fill=True) md_complete_set = get_map(map_coeffs=self.complete_set, crystal_gridding=crystal_gridding) self.missing = self.complete_set.lone_set(self.mc_orig) # Kick map coefficients md_kick = kick_map_coeffs(map_coeffs=self.mc_orig, crystal_gridding=crystal_gridding, number_of_kicks=number_of_kicks, macro_cycles=macro_cycles, missing=self.missing, kick_completeness=kick_completeness) self.mc_kick = self.map_coeffs_from_map(map_data=md_kick) # Kick fmodel md_fm = kick_fmodel(fmodel=fmodel, map_type=map_type, crystal_gridding=crystal_gridding, number_of_kicks=number_of_kicks, macro_cycles=macro_cycles, missing=self.missing, kick_completeness=kick_completeness) self.mc_fm = self.map_coeffs_from_map(map_data=md_fm) if (omit): # Kick OMIT map com1 = mmtbx.maps.composite_omit_map.run( crystal_gridding=crystal_gridding, fmodel=fmodel.deep_copy(), # XXX full_resolution_map=True, box_size_as_fraction=0.03) md_com1 = kick_map_coeffs(map_coeffs=com1.map_coefficients(), crystal_gridding=crystal_gridding, number_of_kicks=number_of_kicks, macro_cycles=macro_cycles, phases_only=True, missing=self.missing, kick_completeness=kick_completeness) self.mc_com1 = self.map_coeffs_from_map(map_data=md_com1) # Kick OMIT map 2 com2 = mmtbx.maps.composite_omit_map.run( crystal_gridding=crystal_gridding, fmodel=fmodel.deep_copy(), # XXX full_resolution_map=True, box_size_as_fraction=0.03) md_com2 = kick_map_coeffs(map_coeffs=com2.map_coefficients(), crystal_gridding=crystal_gridding, number_of_kicks=number_of_kicks, macro_cycles=macro_cycles, phases_only=True, missing=self.missing, kick_completeness=kick_completeness) self.mc_com2 = self.map_coeffs_from_map(map_data=md_com2) # combine maps def intersect(m1, m2, use_average): maptbx.intersection(map_data_1=m1, map_data_2=m2, thresholds=flex.double( [0, 0.1, 0.2, 0.3, 0.4, 0.5]), average=False) if (use_average): return (m1 + m2) / 2 else: return m1 m = (md_kick + md_fm) / 2 m = intersect(m, md_kick, use_average=True) m = intersect(m, md_fm, use_average=True) if (omit): m = intersect(m, md_com1, use_average=False) m = intersect(m, md_com2, use_average=False) m = intersect(m, md_orig, use_average=False) m = intersect(m, md_complete_set, use_average=False) self.map_data_result = m self.mc_result = self.map_coeffs_from_map( map_data=self.map_data_result)