def test_2(fmodel, convention, phi=0.0, psi=0.0, the=0.0, trans=[0.0, 0.0, 0.0]): rot_obj = scitbx.rigid_body.euler(phi=phi, psi=psi, the=the, convention=convention) size = fmodel.xray_structure.scatterers().size() fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj.rot_mat(), trans=trans) fmodel.update_xray_structure(update_f_calc=True) assert approx_equal(fmodel.r_work(), 0.0) params = mmtbx.refinement.rigid_body.master_params.extract() params.refine_rotation = True params.refine_translation = True params.target = "ls_wunit_k1" rb = mmtbx.refinement.rigid_body.manager( fmodel=fmodel, selections=[flex.bool(size, True).iselection()], params=params) assert approx_equal(rb.translation()[0], [0.0, 0.0, 0.0]) assert approx_equal(rb.rotation()[0], [0.0, 0.0, 0.0]) assert approx_equal(fmodel.r_work(), 0.0)
def test_3(fmodel, convention, phi=1, psi=2, the=3, trans=[0, 0, 0]): rot_obj = scitbx.rigid_body.euler(phi=phi, psi=psi, the=the, convention=convention) size = fmodel.xray_structure.scatterers().size() fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj.rot_mat(), trans=trans) fmodel.update_xray_structure(update_f_calc=True) assert fmodel.r_work() > 0.15 params = mmtbx.refinement.rigid_body.master_params.extract() params.refine_rotation = True params.refine_translation = False params.high_resolution = 1.0 params.max_iterations = 50 params.lbfgs_line_search_max_function_evaluations = 50 params.target = "ls_wunit_k1" rb = mmtbx.refinement.rigid_body.manager( fmodel=fmodel, selections=[flex.bool(size, True).iselection()], params=params) if (convention == "xyz"): assert approx_equal(rb.rotation()[0], [-1.0, -2.0, -3.0], 0.2) # XXX assert approx_equal(rb.translation()[0], [0.0, 0.0, 0.0]) assert approx_equal(fmodel.r_work(), 0.0)
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 test_5(fmodel, convention): size = fmodel.xray_structure.scatterers().size() sel1 = flex.bool() sel2 = flex.bool() for i in xrange(size): if (i < 500): sel1.append(True) sel2.append(False) else: sel1.append(False) sel2.append(True) selections = [sel1.iselection(), sel2.iselection()] rot_obj_1 = scitbx.rigid_body.euler(phi=1, psi=2, the=3, convention=convention) rot_obj_2 = scitbx.rigid_body.euler(phi=3, psi=2, the=1, convention=convention) fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj_1.rot_mat(), trans=[0.5, 1.0, 1.5], selection=sel1.iselection()) fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj_2.rot_mat(), trans=[1.5, 0.5, 1.0], selection=sel2.iselection()) fmodel.update_xray_structure(update_f_calc=True) assert fmodel.r_work() > 0.35 params = mmtbx.refinement.rigid_body.master_params.extract() params.refine_rotation = True params.refine_translation = True params.high_resolution = 1.0 params.target = "ls_wunit_k1" rb = mmtbx.refinement.rigid_body.manager(fmodel=fmodel, selections=selections, params=params) if (convention == "xyz"): assert approx_equal(rb.rotation()[0], [-1, -2, -3], 0.2) assert approx_equal(rb.rotation()[1], [-3, -2, -1], 0.2) assert approx_equal(rb.translation()[0], [-0.5, -1.0, -1.5], 1.e-4) assert approx_equal(rb.translation()[1], [-1.5, -0.5, -1.0], 1.e-4) assert approx_equal(fmodel.r_work(), 0.0, 0.0005) assert approx_equal(fmodel.r_free(), 0.0, 0.0005)
def test_5(fmodel, convention): size = fmodel.xray_structure.scatterers().size() sel1 = flex.bool() sel2 = flex.bool() for i in xrange(size): if(i<500): sel1.append(True) sel2.append(False) else: sel1.append(False) sel2.append(True) selections = [sel1.iselection(), sel2.iselection()] rot_obj_1 = scitbx.rigid_body.euler( phi = 1, psi = 2, the = 3, convention = convention) rot_obj_2 = scitbx.rigid_body.euler( phi = 3, psi = 2, the = 1, convention = convention) fmodel.xray_structure.apply_rigid_body_shift( rot = rot_obj_1.rot_mat(), trans = [0.5,1.0,1.5], selection = sel1.iselection()) fmodel.xray_structure.apply_rigid_body_shift( rot = rot_obj_2.rot_mat(), trans = [1.5,0.5,1.0], selection = sel2.iselection()) fmodel.update_xray_structure(update_f_calc = True) assert fmodel.r_work() > 0.35 params = mmtbx.refinement.rigid_body.master_params.extract() params.refine_rotation = True params.refine_translation = True params.high_resolution = 1.0 params.target="ls_wunit_k1" rb = mmtbx.refinement.rigid_body.manager(fmodel = fmodel, selections = selections, params = params) if(convention == "xyz"): assert approx_equal(rb.rotation()[0], [-1,-2,-3], 0.2) assert approx_equal(rb.rotation()[1], [-3,-2,-1], 0.2) assert approx_equal(rb.translation()[0], [-0.5,-1.0,-1.5], 1.e-4) assert approx_equal(rb.translation()[1], [-1.5,-0.5,-1.0], 1.e-4) assert approx_equal(fmodel.r_work(), 0.0, 0.0005) assert approx_equal(fmodel.r_free(), 0.0, 0.0005)
def test_2(fmodel, convention, phi = 0.0, psi = 0.0, the = 0.0, trans = [0.0,0.0,0.0]): rot_obj = scitbx.rigid_body.euler( phi = phi, psi = psi, the = the, convention = convention) size = fmodel.xray_structure.scatterers().size() fmodel.xray_structure.apply_rigid_body_shift( rot = rot_obj.rot_mat(), trans = trans) fmodel.update_xray_structure(update_f_calc = True) assert approx_equal(fmodel.r_work(), 0.0) params = mmtbx.refinement.rigid_body.master_params.extract() params.refine_rotation = True params.refine_translation = True params.target="ls_wunit_k1" rb = mmtbx.refinement.rigid_body.manager( fmodel = fmodel, selections = [flex.bool(size,True).iselection()], params = params) assert approx_equal(rb.translation()[0], [0.0,0.0,0.0]) assert approx_equal(rb.rotation()[0], [0.0,0.0,0.0]) assert approx_equal(fmodel.r_work(), 0.0)
def test_4(fmodel, convention, phi =1, psi =2, the =3, trans =[0.5,1.0,1.5]): rot_obj = scitbx.rigid_body.euler( phi = phi, psi = psi, the = the, convention = convention) size = fmodel.xray_structure.scatterers().size() fmodel.xray_structure.apply_rigid_body_shift( rot = rot_obj.rot_mat(), trans = trans) fmodel.update_xray_structure(update_f_calc = True) assert fmodel.r_work() > 0.15 params = mmtbx.refinement.rigid_body.master_params.extract() params.refine_rotation = True params.refine_translation = True params.high_resolution = 1.0 params.target="ls_wunit_k1" rb = mmtbx.refinement.rigid_body.manager( fmodel = fmodel, selections = [flex.bool(size,True).iselection()], params = params) if(convention == "xyz"): assert approx_equal(rb.rotation()[0], [-1.0,-2.0,-3.0], 0.2) # XXX assert approx_equal(rb.translation()[0], [-0.5,-1.0,-1.5], 1.e-3) assert approx_equal(fmodel.r_work(), 0.0, 1.e-3)
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)