def __init__(self, data_arrays, xray_structure, log=None, silent=False, output_file=None, peak_search=False, map_cutoff=None, peak_search_params=None, r_free_arrays=None, write_map=True, multiscale=False, anomalous=False): if (log is None): log = sys.stdout adopt_init_args(self, locals()) fmodels = [] for i_seq, d in enumerate(data_arrays): if (not silent): print("Data set: %d" % i_seq, file=log) if (d.anomalous_flag()) and (not anomalous): d = d.average_bijvoet_mates() elif (anomalous): assert d.anomalous_flag() if (r_free_arrays is not None) and (i_seq < len(r_free_arrays)): r_free_flags = r_free_arrays[i_seq] else: r_free_flags = d.array(data=flex.bool(d.data().size(), False)) fmodel = mmtbx.f_model.manager(xray_structure=xray_structure, r_free_flags=r_free_flags, target_name="ls_wunit_k1", f_obs=d) fmodel.update_all_scales(log=None) if (not silent): fmodel.info().show_rfactors_targets_scales_overall(out=log) print(file=log) fmodels.append(fmodel) self.fmodel = fmodels[0] # prepare Fobs for map calculation (apply scaling): f_obss = [] for fmodel in fmodels: obs = fmodel.f_obs() f_obs_scale = 1.0 / fmodel.k_anisotropic() / fmodel.k_isotropic() obs = miller.array(miller_set=fmodel.f_model(), data=obs.data() * f_obs_scale) f_obss.append(obs) # given two Fobs sets, make them one-to-one matching, get phases and map coefficients # Note: f_calc below is just f_calc from atoms (no bulk solvent etc applied) fobs_1, f_model = f_obss[0].common_sets(other=fmodels[1].f_model()) fobs_1, fobs_2 = fobs_1.common_sets(other=f_obss[1]) fobs_1, f_model = fobs_1.common_sets(other=f_model) self.f_model = f_model assert fobs_2.indices().all_eq(fobs_1.indices()) assert f_model.indices().all_eq(fobs_1.indices()) # scale again scale_k1 = 1 den = flex.sum(flex.abs(fobs_2.data()) * flex.abs(fobs_2.data())) if (den != 0): scale_k1 = flex.sum( flex.abs(fobs_1.data()) * flex.abs(fobs_2.data())) / den # fobs_2 = fobs_2.array(data=fobs_2.data() * scale_k1) if multiscale: fobs_1 = fobs_2.multiscale(other=fobs_1, reflections_per_bin=250) if (not silent): print("", file=log) print("Fobs1_vs_Fobs2 statistics:", file=log) print("Bin# Resolution range Compl. No.of refl. CC R-factor", file=log) fobs_1.setup_binner( reflections_per_bin=min(500, fobs_1.data().size())) fobs_2.use_binning_of(fobs_1) for i_bin in fobs_1.binner().range_used(): sel = fobs_1.binner().selection(i_bin) f1 = fobs_1.select(sel) f2 = fobs_2.select(sel) d_max, d_min = fobs_1.d_max_min() compl = fobs_1.completeness(d_max=d_max) n_ref = sel.count(True) num = flex.sum(flex.abs(f1.data() - f2.data())) den = flex.sum(flex.abs(f1.data() + f2.data()) / 2) r = None if (den != 0): r = num / den cc = flex.linear_correlation(x=f1.data(), y=f2.data()).coefficient() d_range = fobs_1.binner().bin_legend(i_bin=i_bin, show_bin_number=False, show_counts=False) fmt = "%3d: %-17s %4.2f %6d %5.3f %6s" print(fmt % (i_bin, d_range, compl, n_ref, cc, format_value("%6.4f", r)), file=log) # overall statistics self.cc = flex.linear_correlation(x=fobs_1.data(), y=fobs_2.data()).coefficient() num = flex.sum(flex.abs(fobs_1.data() - fobs_2.data())) den = flex.sum(flex.abs(fobs_2.data() + fobs_2.data()) / 2) self.r_factor = None if (den != 0): self.r_factor = num / den # map coefficients def phase_transfer(miller_array, phase_source): tmp = miller.array( miller_set=miller_array, data=flex.double(miller_array.indices().size(), 1)).phase_transfer(phase_source=phase_source) return miller.array(miller_set=miller_array, data=miller_array.data() * tmp.data()) if (not anomalous): diff = miller.array(miller_set=f_model, data=fobs_1.data() - fobs_2.data()) self.map_coeff = phase_transfer(miller_array=diff, phase_source=f_model) else: dano_1 = fobs_1.anomalous_differences() dano_2 = fobs_2.anomalous_differences() assert dano_1.indices().all_eq(dano_2.indices()) diff = miller.array(miller_set=dano_1, data=dano_1.data() - dano_2.data()) f_model_phases = f_model.average_bijvoet_mates().common_set(diff) map_coeffs = phase_transfer(miller_array=diff, phase_source=f_model_phases) self.map_coeff = map_coeffs.customized_copy( data=map_coeffs.data() / (2j)) if (self.map_coeff.anomalous_flag()): self.map_coeff = map_coeff.average_bijvoet_mates() self.file_names = [] if (write_map): self.file_names = self.write_map_file()
def __init__ (self, data_arrays, xray_structure, log=None, silent=False, output_file=None, peak_search=False, map_cutoff=None, peak_search_params=None, r_free_arrays=None, write_map=True, multiscale=False, anomalous=False) : if (log is None) : log = sys.stdout adopt_init_args(self, locals()) fmodels = [] for i_seq, d in enumerate(data_arrays): if(not silent): print >> log, "Data set: %d"%i_seq if(d.anomalous_flag()) and (not anomalous) : d = d.average_bijvoet_mates() elif (anomalous) : assert d.anomalous_flag() if (r_free_arrays is not None) and (i_seq < len(r_free_arrays)) : r_free_flags = r_free_arrays[i_seq] else : r_free_flags = d.array(data = flex.bool(d.data().size(), False)) fmodel = mmtbx.f_model.manager( xray_structure = xray_structure, r_free_flags = r_free_flags, target_name = "ls_wunit_k1", f_obs = d) fmodel.update_all_scales(log=None) if(not silent): fmodel.info().show_rfactors_targets_scales_overall(out=log) print >> log fmodels.append(fmodel) self.fmodel = fmodels[0] # prepare Fobs for map calculation (apply scaling): f_obss = [] for fmodel in fmodels: obs = fmodel.f_obs() f_obs_scale = 1.0 / fmodel.k_anisotropic() / fmodel.k_isotropic() obs = miller.array(miller_set = fmodel.f_model(), data = obs.data()*f_obs_scale) f_obss.append(obs) # given two Fobs sets, make them one-to-one matching, get phases and map coefficients # Note: f_calc below is just f_calc from atoms (no bulk solvent etc applied) fobs_1, f_model = f_obss[0].common_sets(other = fmodels[1].f_model()) fobs_1, fobs_2 = fobs_1.common_sets(other = f_obss[1]) fobs_1, f_model = fobs_1.common_sets(other = f_model) self.f_model = f_model assert fobs_2.indices().all_eq(fobs_1.indices()) assert f_model.indices().all_eq(fobs_1.indices()) # scale again scale_k1 = 1 den = flex.sum(flex.abs(fobs_2.data())*flex.abs(fobs_2.data())) if(den != 0): scale_k1 = flex.sum(flex.abs(fobs_1.data())*flex.abs(fobs_2.data())) / den # fobs_2 = fobs_2.array(data = fobs_2.data()*scale_k1) if multiscale: fobs_1 = fobs_2.multiscale(other = fobs_1, reflections_per_bin=250) if(not silent): print >> log, "" print >> log, "Fobs1_vs_Fobs2 statistics:" print >> log, "Bin# Resolution range Compl. No.of refl. CC R-factor" fobs_1.setup_binner(reflections_per_bin = min(500, fobs_1.data().size())) fobs_2.use_binning_of(fobs_1) for i_bin in fobs_1.binner().range_used(): sel = fobs_1.binner().selection(i_bin) f1 = fobs_1.select(sel) f2 = fobs_2.select(sel) d_max, d_min = fobs_1.d_max_min() compl = fobs_1.completeness(d_max = d_max) n_ref = sel.count(True) num = flex.sum(flex.abs(f1.data()-f2.data())) den = flex.sum(flex.abs(f1.data()+f2.data())/2) r = None if(den!=0): r = num/den cc = flex.linear_correlation(x=f1.data(), y=f2.data()).coefficient() d_range = fobs_1.binner().bin_legend( i_bin = i_bin, show_bin_number = False, show_counts = False) fmt = "%3d: %-17s %4.2f %6d %5.3f %6s" print >> log, fmt % (i_bin, d_range, compl, n_ref, cc, format_value("%6.4f", r)) # overall statistics self.cc = flex.linear_correlation( x=fobs_1.data(), y=fobs_2.data()).coefficient() num = flex.sum(flex.abs(fobs_1.data()-fobs_2.data())) den = flex.sum(flex.abs(fobs_2.data()+fobs_2.data())/2) self.r_factor = None if (den != 0) : self.r_factor = num / den # map coefficients def phase_transfer(miller_array, phase_source): tmp = miller.array(miller_set = miller_array, data = flex.double(miller_array.indices().size(), 1) ).phase_transfer(phase_source = phase_source) return miller.array(miller_set = miller_array, data = miller_array.data() * tmp.data() ) if (not anomalous) : diff = miller.array( miller_set = f_model, data = fobs_1.data()-fobs_2.data()) self.map_coeff = phase_transfer( miller_array = diff, phase_source = f_model) else : dano_1 = fobs_1.anomalous_differences() dano_2 = fobs_2.anomalous_differences() assert dano_1.indices().all_eq(dano_2.indices()) diff = miller.array( miller_set = dano_1, data = dano_1.data() - dano_2.data()) f_model_phases = f_model.average_bijvoet_mates().common_set(diff) map_coeffs = phase_transfer( miller_array = diff, phase_source = f_model_phases) self.map_coeff = map_coeffs.customized_copy(data=map_coeffs.data()/(2j)) if(self.map_coeff.anomalous_flag()): self.map_coeff = map_coeff.average_bijvoet_mates() self.file_names = [] if (write_map) : self.file_names = self.write_map_file()