def get_fmodel_from_pdb(pdb_file_name, algorithm="direct", d_min=2.0, target="ls_wunit_k1"): pdb_file = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/%s" % pdb_file_name, test=os.path.isfile) xray_structure = iotbx.pdb.input( file_name=pdb_file).xray_structure_simple() params = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params.extract( ) assert params.high_resolution is None assert params.scattering_table == 'n_gaussian' assert params.structure_factors_accuracy.algorithm == 'fft' params.high_resolution = d_min params.scattering_table = "wk1995" params.structure_factors_accuracy.algorithm = algorithm fmodel = mmtbx.utils.fmodel_from_xray_structure( xray_structure=xray_structure, params=params, target=target, r_free_flags_fraction=0.01).fmodel assert approx_equal( mmtbx.bulk_solvent.r_factor(fmodel.f_obs().data(), fmodel.f_model().data()), 0) sfg_params = mmtbx.f_model.sf_and_grads_accuracy_master_params.extract() sfg_params.algorithm = algorithm fmodel = mmtbx.f_model.manager(target_name=target, xray_structure=xray_structure, f_obs=abs(fmodel.f_model()), sf_and_grads_accuracy_params=sfg_params) assert approx_equal(fmodel.r_work(), 0) return fmodel
def get_fmodel_from_pdb(pdb_file_name, algorithm = "direct", d_min = 2.0, target = "ls_wunit_k1"): pdb_file = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/%s"%pdb_file_name,test=os.path.isfile) xray_structure = iotbx.pdb.input(file_name =pdb_file).xray_structure_simple() params = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params.extract() assert params.high_resolution is None assert params.scattering_table == 'n_gaussian' assert params.structure_factors_accuracy.algorithm == 'fft' params.high_resolution = d_min params.scattering_table = "wk1995" params.structure_factors_accuracy.algorithm = algorithm fmodel = mmtbx.utils.fmodel_from_xray_structure( xray_structure = xray_structure, params = params, target = target, r_free_flags_fraction = 0.01).fmodel assert approx_equal(mmtbx.bulk_solvent.r_factor(fmodel.f_obs().data(), fmodel.f_model().data()), 0) sfg_params = mmtbx.f_model.sf_and_grads_accuracy_master_params.extract() sfg_params.algorithm = algorithm fmodel = mmtbx.f_model.manager( target_name = target, xray_structure = xray_structure, f_obs = abs(fmodel.f_model()), sf_and_grads_accuracy_params = sfg_params) assert approx_equal(fmodel.r_work(), 0) return fmodel
def scaling_metrics(self,other): # Read reflections # some requirements. 1) Fobs scaled to Fcalc, not the other way around. # 2) ability to make a plot of the two scaled sets # 3) set the number of bins # 4) understand and print out the per-bin scaling factor # 5) print an overall stats line at the end of the table # 6) choose one or the other binnings """1) scaling and analysis are separate functions""" #f_obs, r_free_flags = f_obs.common_sets(r_free_flags) f_obs = other #r_free_flags = r_free_flags.array(data=r_free_flags.data()==1) # Read model # Get Fmodel fmodel = mmtbx.f_model.manager( f_obs = f_obs, #r_free_flags = r_free_flags, xray_structure = self.xray_structure) # Do anisotropic overall scaling, bulk-solvent modeling, outlier rejection #fmodel.update_all_scales() print "r_work, r_free: %6.4f, %6.4f"%(fmodel.r_work(), fmodel.r_free()) # Print statistics in resolution bins f_model = fmodel.f_model_scaled_with_k1() bin_selections = fmodel.f_obs().log_binning() dsd = fmodel.f_obs().d_spacings().data() print "Bin# Resolution Nref Cmpl Rw CC" fmt="%2d: %6.3f-%-6.3f %5d %5.3f %6.4f %6.4f" for i_bin, sel in enumerate(bin_selections): d = dsd.select(sel) d_min = flex.min(d) d_max = flex.max(d) fmodel_sel = fmodel.select(sel) n = d.size() f_obs_sel = fmodel.f_obs().select(sel) f_model_sel = abs(f_model.select(sel)).data() cmpl = f_obs_sel.completeness(d_max=d_max) r_work = fmodel_sel.r_work() cc = flex.linear_correlation(x=f_obs_sel.data(), y=f_model_sel).coefficient() print fmt%(i_bin, d_max, d_min, n, cmpl, r_work, cc) # Alternative binning print print "Bin# Resolution Nref Cmpl Rw CC" fmodel.f_obs().setup_binner(reflections_per_bin = 2500) f_model.use_binning_of(fmodel.f_obs()) for i_bin in fmodel.f_obs().binner().range_used(): sel = fmodel.f_obs().binner().selection(i_bin) d = dsd.select(sel) d_min = flex.min(d) d_max = flex.max(d) fmodel_sel = fmodel.select(sel) n = d.size() f_obs_sel = fmodel.f_obs().select(sel) f_model_sel = abs(f_model.select(sel)).data() cmpl = f_obs_sel.completeness(d_max=d_max) r_work = fmodel_sel.r_work() cc = flex.linear_correlation(x=f_obs_sel.data(), y=f_model_sel).coefficient() print fmt%(i_bin, d_max, d_min, n, cmpl, r_work, cc)
def scaling_metrics(self, other): # Read reflections # some requirements. 1) Fobs scaled to Fcalc, not the other way around. # 2) ability to make a plot of the two scaled sets # 3) set the number of bins # 4) understand and print out the per-bin scaling factor # 5) print an overall stats line at the end of the table # 6) choose one or the other binnings """1) scaling and analysis are separate functions""" #f_obs, r_free_flags = f_obs.common_sets(r_free_flags) f_obs = other #r_free_flags = r_free_flags.array(data=r_free_flags.data()==1) # Read model # Get Fmodel fmodel = mmtbx.f_model.manager( f_obs=f_obs, #r_free_flags = r_free_flags, xray_structure=self.xray_structure) # Do anisotropic overall scaling, bulk-solvent modeling, outlier rejection #fmodel.update_all_scales() print "r_work, r_free: %6.4f, %6.4f" % (fmodel.r_work(), fmodel.r_free()) # Print statistics in resolution bins f_model = fmodel.f_model_scaled_with_k1() bin_selections = fmodel.f_obs().log_binning() dsd = fmodel.f_obs().d_spacings().data() print "Bin# Resolution Nref Cmpl Rw CC" fmt = "%2d: %6.3f-%-6.3f %5d %5.3f %6.4f %6.4f" for i_bin, sel in enumerate(bin_selections): d = dsd.select(sel) d_min = flex.min(d) d_max = flex.max(d) fmodel_sel = fmodel.select(sel) n = d.size() f_obs_sel = fmodel.f_obs().select(sel) f_model_sel = abs(f_model.select(sel)).data() cmpl = f_obs_sel.completeness(d_max=d_max) r_work = fmodel_sel.r_work() cc = flex.linear_correlation(x=f_obs_sel.data(), y=f_model_sel).coefficient() print fmt % (i_bin, d_max, d_min, n, cmpl, r_work, cc) # Alternative binning print print "Bin# Resolution Nref Cmpl Rw CC" fmodel.f_obs().setup_binner(reflections_per_bin=2500) f_model.use_binning_of(fmodel.f_obs()) for i_bin in fmodel.f_obs().binner().range_used(): sel = fmodel.f_obs().binner().selection(i_bin) d = dsd.select(sel) d_min = flex.min(d) d_max = flex.max(d) fmodel_sel = fmodel.select(sel) n = d.size() f_obs_sel = fmodel.f_obs().select(sel) f_model_sel = abs(f_model.select(sel)).data() cmpl = f_obs_sel.completeness(d_max=d_max) r_work = fmodel_sel.r_work() cc = flex.linear_correlation(x=f_obs_sel.data(), y=f_model_sel).coefficient() print fmt % (i_bin, d_max, d_min, n, cmpl, r_work, cc)