Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
  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)
Пример #4
0
    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)