Ejemplo n.º 1
0
 def format_old (self) :
   s_occ = format_value("%.2f", self.occupancy)
   s_score = format_value("%.1f", self.score)
   chis = list(self.chi_angles)
   return "%s:%s:%s:%s:%s:%s" % (self.id_str(), s_occ, s_score,
     self.format_chi_angles(pad=True, sep=":"),
     self.evaluation,self.rotamer_name)
Ejemplo n.º 2
0
 def rescore (self, params, log=None, prefix="") :
   # FIXME this needs to be rationalized and made consistent with the
   # rescoring against the original maps
   if (log is None) : log = null_out()
   reject = (self.rotamer == "OUTLIER")
   bad_mc_two_fofc_msg = None
   for i_seq, atom in enumerate(self.new_hierarchy.atoms()) :
     name = atom.name.strip()
     if (name in ["N","C","O","CA", "CB"]) :
       if (self.two_fofc_values[i_seq] < params.omit_two_fofc_min_mc) :
         bad_mc_two_fofc_msg = "poor backbone: 2Fo-Fc(%s)=%.2f" % (name,
               self.two_fofc_values[i_seq])
         reject = True
         break
   if (self.sc_fofc_mean is not None) :
     if (self.sc_fofc_mean < params.omit_fofc_min_sc_mean) :
       reject = True
     elif ((self.sc_two_fofc_mean < params.omit_two_fofc_min_sc_mean) and
           (self.sc_fofc_mean < params.omit_fofc_min_sc_mean + 1)) :
       reject = True
   flag = ""
   if (reject) :
     flag = " !!!"
   print >> log, prefix+\
     "occupancy=%.2f rotamer=%s 2Fo-Fc(sc)=%s  Fo-Fc(sc)=%s%s" % \
     (self.occupancy, self.rotamer,
      format_value("%5f", self.sc_two_fofc_mean),
      format_value("%5f", self.sc_fofc_mean),
      flag)
   if (bad_mc_two_fofc_msg is not None) :
     print >> log, prefix+"  %s" % bad_mc_two_fofc_msg
   return (not reject)
Ejemplo n.º 3
0
 def format_info_string(self):
   return "%7s %6s    %6s     %6s %9s"%(
     self.id_str,
     format_value("%6.3f",self.map_cc_all),
     format_value("%6.3f",self.map_cc_backbone),
     format_value("%6.3f",self.map_cc_sidechain),
     self.rotamer_status)
Ejemplo n.º 4
0
  def _show_impl (self, out) :
    label_suffix = ""
    if (self.info is not None) :
      label_suffix = " of %s" % str(self.info)
    out.show_sub_header("Maximum likelihood isotropic Wilson scaling")
    out.show(""" ML estimate of overall B value%s:""" % label_suffix)
    out.show_preformatted_text("   %s A**(-2)" %
      format_value("%5.2f", self.b_wilson))
    out.show(""" Estimated -log of scale factor%s:""" % label_suffix)
    out.show_preformatted_text("""   %s""" %
      format_value("%5.2f", self.p_scale))
    out.show("""\
 The overall B value ("Wilson B-factor", derived from the Wilson plot) gives
 an isotropic approximation for the falloff of intensity as a function of
 resolution.  Note that this approximation may be misleading for anisotropic
 data (where the crystal is poorly ordered along an axis).  The Wilson B is
 strongly correlated with refined atomic B-factors but these may differ by
 a significant amount, especially if anisotropy is present.""")
    if (self.b_wilson < 0) :
      out.warn("The Wilson B-factor is negative!  This indicates that "+
        "the data are either unusually pathological, or have been "+
        "artifically manipulated (for instance by applying anisotropic "+
        "scaling directly).  Please inspect the raw data and/or use "+
        "unmodified reflections for phasing and refinement, as any model "+
        "generated from the current dataset will be unrealistic.")
Ejemplo n.º 5
0
 def format_for_model_cc (self) :
   return "%6.2f  %6.2f  %6d  %6.2f  %6.2f  %5.3f  %5.3f   %s   %s  %s  %s"%(
     self.d_max, self.d_min, self.n_uniq,
     self.completeness*100, self.i_over_sigma_mean,
     self.cc_one_half, self.cc_star,
     format_value("%5.3f", self.cc_work), format_value("%5.3f", self.cc_free),
     format_value("%5.3f", self.r_work), format_value("%5.3f", self.r_free))
Ejemplo n.º 6
0
 def show_rfactors_targets_scales_overall(self, header = None, out=None):
   from cctbx import sgtbx
   if(out is None): out = sys.stdout
   out.flush()
   p = " "
   self._header_resolutions_nreflections(header=header, out=out)
   print >> out, "| "+"  "*38+"|"
   self._rfactors_and_bulk_solvent_and_scale_params(out=out)
   line7="| normalized target function (%s) (work): %s"% (
     self.target_name, n_as_s("%15.6f",self.target_work))
   np = 79 - (len(line7) + 1)
   line7 = line7 + " "*np + "|"
   print >> out, line7
   # no norm - work
   line71="| target function (%s) not normalized (work): %s"% (
     self.target_name, n_as_s("%15.6f",self.target_work_no_norm))
   np = 79 - (len(line71) + 1)
   line71 = line71 + " "*np + "|"
   print >> out, line71
   # no norm - free
   line71="| target function (%s) not normalized (free): %s"% (
     self.target_name, n_as_s("%15.6f",self.target_free_no_norm))
   np = 79 - (len(line71) + 1)
   line71 = line71 + " "*np + "|"
   print >> out, line71
   #
   if(self.twin_fraction is not None):
     line8="| twin fraction: "+format_value("%-4.2f",self.twin_fraction)+\
       "  twin operator: "+\
       format_value("%-s",sgtbx.change_of_basis_op(self.twin_law).as_hkl())
     np = 79 - (len(line8) + 1)
     line8 = line8 + " "*np + "|"
     print >> out, line8
   print >> out, "|"+"-"*77+"|"
   out.flush()
Ejemplo n.º 7
0
 def collect(self, iter = None, nfun = None):
   if(iter is not None): self.iter = format_value("%-4d", iter)
   if(nfun is not None): self.nfun = format_value("%-4d", nfun)
   self.fmodels.fmodel_xray().xray_structure == self.model.xray_structure
   fmodels_tg = self.fmodels.target_and_gradients(
     weights           = self.weights,
     compute_gradients = False)
   self.rxw.append(format_value("%6.4f", self.fmodels.fmodel_xray().r_work()))
   self.rxf.append(format_value("%6.4f", self.fmodels.fmodel_xray().r_free()))
   self.ex.append(format_value("%10.4f", fmodels_tg.target_work_xray))
   if(self.fmodels.fmodel_neutron() is not None):
     self.rnw.append(format_value("%6.4f", self.fmodels.fmodel_neutron().r_work()))
     self.rnf.append(format_value("%6.4f", self.fmodels.fmodel_neutron().r_free()))
     self.en.append(format_value("%10.4f", fmodels_tg.target_work_neutron))
   if(self.refine_xyz and self.weights.w > 0):
     er = self.model.restraints_manager_energies_sites(
       compute_gradients = False).target
   elif(self.refine_adp and self.weights.w > 0):
     use_hd = False
     if(self.fmodels.fmodel_n is not None): use_hd = True
     er = self.model.energies_adp(
       iso_restraints = self.iso_restraints,
       use_hd = use_hd,
       compute_gradients = False).target
   elif(self.refine_occ):
     er = 0
   else: er = 0
   self.er.append(format_value("%10.4f", er))
   self.et.append(format_value(
     "%10.4f", fmodels_tg.target()+er*self.weights.w))
Ejemplo n.º 8
0
 def fs (value) :
   if (isinstance(value, int)) :
     return format_value("%d", value, replace_none_with="---")
   elif (isinstance(value, float)) :
     return format_value("%.2f", value, replace_none_with="---")
   else :
     return "---"
Ejemplo n.º 9
0
 def show_helper(self, fmodel, log):
   r_work = format_value("%6.4f", fmodel.r_work())
   r_free = format_value("%6.4f", fmodel.r_free())
   target = format_value("%-13.3f", fmodel.target_w())
   target_name = format_value("%s", fmodel.target_name)
   p1 = "| r_work = %s r_free = %s" % (r_work, r_free)
   p2 = "target_work(%s) = %s |" % (target_name, target)
   print >> log, p1+" "*(79-len(p1+p2))+p2
Ejemplo n.º 10
0
 def xray_line(self, i_seq):
   line = "| %s = %s * %s * %s + %s * %s"%(
     self.et[i_seq].strip(),
     format_value("%6.2f",self.weights.wx).strip(),
     format_value("%6.2f",self.weights.wx_scale).strip(),
     self.ex[i_seq].strip(),
     format_value("%6.2f",self.weights.w).strip(),
     self.er[i_seq].strip())
   line = line + " "*(78 - len(line))+"|"
   return line
Ejemplo n.º 11
0
 def format_for_cc_star_gui (self) :
     return [ "%.2f - %.2f" % (self.d_max, self.d_min),
            str(self.n_uniq),
            "%.1f %%" % (self.completeness * 100),
            "%.1f" % self.i_over_sigma_mean,
            "%.3f" % self.cc_one_half,
            "%.3f" % self.cc_star,
             format_value("%5.3f", self.cc_work),
             format_value("%5.3f", self.cc_free),
             format_value("%5.3f", self.r_work),
             format_value("%5.3f", self.r_free) ]
Ejemplo n.º 12
0
 def update_reflection_info (self, hkl, d_min, value) :
   print hkl, value
   if (hkl is None) :
     self.hkl_info.SetValue("")
     self.d_min_info.SetValue("")
     self.value_info.SetValue("")
   else :
     self.hkl_info.SetValue("%d, %d, %d" % hkl)
     d_min_str = format_value("%.3g", d_min)
     self.d_min_info.SetValue(d_min_str)
     value_str = format_value("%.3g", value, replace_none_with="---")
     self.value_info.SetValue(value_str)
Ejemplo n.º 13
0
 def _rfactors_and_bulk_solvent_and_scale_params(self, out):
   out.flush()
   r_work = format_value("%6.4f",self.r_work).strip()
   r_free = format_value("%6.4f",self.r_free).strip()
   scale  = format_value("%6.3f",self.overall_scale_k1).strip()
   err    = format_value("%-4.2f",self.ml_coordinate_error)
   errl   =" coordinate error (max.-lik. estimate): %s A"%err
   line = "| r_work= "+r_work+" r_free= "+r_free+errl
   np = 79 - (len(line) + 1)
   if(np < 0): np = 0
   print >> out, line + " "*np + "|"
   print >> out, "| "+"  "*38+"|"
   out.flush()
Ejemplo n.º 14
0
 def show_targets(self, out = None, text = ""):
   if(out is None): out = sys.stdout
   part1 = "|-"+text
   part2 = "-|"
   n = 79 - len(part1+part2)
   print >> out, part1 + "-"*n + part2
   part3 = "| target_work(%s) = %s  r_work = %s  r_free = %s" % (
     self.target_name,
     format_value(format="%.6g",  value = self.target_work),
     format_value(format="%6.4f", value = self.r_work),
     format_value(format="%6.4f", value = self.r_free))
   n = 78 - len(str(part3)+"|")
   print >> out, part3, " "*n +"|"
   print >> out, "|" +"-"*77+"|"
   out.flush()
Ejemplo n.º 15
0
 def format (self) :
   return "%6.2f %6.2f %6d %6d   %5.2f %6.2f  %8.1f  %6.1f  %s  %s  %s  %5.3f  %5.3f" % (
     self.d_max,
     self.d_min,
     self.n_obs,
     self.n_uniq,
     self.mean_redundancy,
     self.completeness*100,
     self.i_mean,
     self.i_over_sigma_mean,
     format_value("%5.3f", self.r_merge),
     format_value("%5.3f", self.r_meas),
     format_value("%5.3f", self.r_pim),
     self.cc_one_half,
     self.anom_half_corr)
Ejemplo n.º 16
0
 def show_summary (self, out=None) :
   if (out is None) : out = sys.stdout
   chi_angles = None
   if (self.chis is not None) :
     chi_angles = ",".join([ "%.1f" % x for x in self.chis ])
   density_str = ""
   if (self.mean_fofc is not None) :
     density_str = "%6.2f  %6.2f  " % (self.mean_2fofc, self.mean_fofc)
   translation_str = ""
   if (self.translation is not None) :
     translation_str = "%4.2f,%4.2f,%4.2f  " % tuple(self.translation)
   print >> out, """%12s  %6s  %6s  %6s  %6.3f  %s%s%s""" % (
     self.residue.id_str(), format_value("%6.1f", self.backrub),
     format_value("%6.1f", self.shear),
     self.rotamer, self.rmsd, translation_str, density_str, chi_angles)
Ejemplo n.º 17
0
 def _header_resolutions_nreflections(self, header, out):
   if(header is None): header = ""
   percent="%"
   frac_free = self.number_of_test_reflections/self.number_of_reflections*100
   line1 = "(resolution: "
   line2 = format_value("%6.2f",self.d_min).strip()
   line3 = format_value("%6.2f",self.d_max).strip()
   line4 = " - "
   line5 = " A, n_refl.="
   line6 = format_value("%d",self.number_of_reflections).strip()
   line7 = " (all), %-6.2f%s free"%(frac_free, percent)
   tl = header+"-"+line1+line2+line4+line3+line5+line6+line7+")"
   line_len = len("|-"+"|"+tl)
   fill_len = 80-line_len-1
   print >> out, "|-"+tl+"-"*(fill_len)+"|"
   out.flush()
Ejemplo n.º 18
0
 def as_string (self, prefix="", highlight_if_heavy=False) :
   flag = ""
   if highlight_if_heavy and self.is_heavy_atom() :
     flag = " ***"
   return "%-20s  %6.2f  %4.2f  %6.2f  %6.2f  %s  %5.3f%s" % (
     self.id_str(), self.b_iso, self.occupancy, self.two_fofc, self.fofc,
     format_value("%6.2f", self.anom, replace_none_with="---"), self.cc, flag)
Ejemplo n.º 19
0
 def format_chi_angles (self, pad=False, sep=",") :
   formatted = []
   for chi in self.chi_angles :
     if pad or (chi is not None) :
       formatted.append(format_value("%.1f", chi,
         replace_none_with="").strip())
   return sep.join(formatted)
Ejemplo n.º 20
0
  def format_molprobity_scores(self, prefix=""):
    clashscore_explanation = '"Clashscore and/or Probe failed to process model"'
    result="%s" % prefix
    if(self.ramachandran_outliers is not None):
      result = """%sMOLPROBITY STATISTICS.
%s ALL-ATOM CLASHSCORE : %s
%s RAMACHANDRAN PLOT:
%s   OUTLIERS : %-5.2f %s
%s   ALLOWED  : %-5.2f %s
%s   FAVORED  : %-5.2f %s
%s ROTAMER OUTLIERS : %s %s
%s CBETA DEVIATIONS : %-d
%s PEPTIDE PLANE:
%s   CIS-PROLINE     : %s
%s   CIS-GENERAL     : %s
%s   TWISTED PROLINE : %s
%s   TWISTED GENERAL : %s"""%(
        prefix,
        prefix, format_value("%-6.2f",
                             self.clashscore,
                             replace_none_with=clashscore_explanation).strip(),
        prefix,
        prefix, self.ramachandran_outliers, "%",
        prefix, self.ramachandran_allowed, "%",
        prefix, self.ramachandran_favored, "%",
        prefix, str("%6.2f"%(self.rotamer_outliers)).strip(),"%",
        prefix, self.c_beta_dev,
        prefix,
        prefix, str(self.n_cis_proline),
        prefix, str(self.n_cis_general),
        prefix, str(self.n_twisted_proline),
        prefix, str(self.n_twisted_general))
    if not prefix:
      result = self._capitalize(result)
    return result
Ejemplo n.º 21
0
 def show(self, fmodels, message, log):
   if(log is not None):
     print >> log, "|-"+message+"-"*(79-len("|-"+message+"|"))+"|"
     fm_x, fm_n = fmodels.fmodel_xray(), fmodels.fmodel_neutron()
     if(fm_n is not None):
       print >> log, "|"+" "*36+"X-ray"+" "*36+"|"
     self.show_helper(fmodel = fm_x, log = log)
     if(fm_n is not None):
       print >> log, "|"+" "*35+"neutron"+" "*35+"|"
       self.show_helper(fmodel = fm_n, log = log)
     occupancies = fm_x.xray_structure.scatterers().extract_occupancies()
     occ_max = format_value("%4.2f", flex.max(occupancies))
     occ_min = format_value("%4.2f", flex.min(occupancies))
     number_small = format_value("%8d", (occupancies < 0.1).count(True))
     print >> log, \
       "| occupancies: max = %s  min = %s   number of occupancies < 0.1: %s |"%(
       occ_max, occ_min, number_small)
     print >> log, "|"+"-"*77+"|"
Ejemplo n.º 22
0
 def show_rfactors_targets_in_bins(self, out = None):
   if(out is None): out = sys.stdout
   print >> out, "|"+"-"*77+"|"
   print >> out, "| Bin     Resolution   Compl.  No. Refl.    R-factors          Targets        |"
   print >> out, "|number     range              work test   work   test        work        test|"
   for bin in self.bins:
     print >> out, "|%3d: %-17s %4.2f %6d %4d %s %s %s %s|" % (
       bin.i_bin,
       bin.d_range,
       bin.completeness,
       bin.n_work,
       bin.n_free,
       format_value("%6.4f",  bin.r_work),
       format_value("%6.4f",  bin.r_free),
       format_value("%11.5g", bin.target_work),
       format_value("%11.5g", bin.target_free))
   print >> out, "|"+"-"*77+"|"
   out.flush()
Ejemplo n.º 23
0
 def GetItemText (self, item, col) :
   n_items = self.GetItemCount()
   solution = self.table[item]
   if (col == 0) :
     return solution['counter']
   elif (col == 1) :
     return "%s%s" % (str_utils.format_value("%.4f",
       solution['max_angular_difference']), chr(161))
   elif (col == 2) :
     return str_utils.format_value("%.4f", solution['residual'])
   elif (col == 3) :
     return str(solution['count_GOOD'])
   elif (col == 4) :
     return "%s %s" % (solution['system'], solution['bravais'])
   elif (col == 5) :
     unit_cell = solution['orient'].unit_cell()
     return "%g %g %g %g %g %g" % unit_cell.parameters()
   elif (col == 6) :
     unit_cell = solution['orient'].unit_cell()
     return str(int(unit_cell.volume()))
Ejemplo n.º 24
0
  def show(self, prefix="", log=None):
    self.assert_pdb_hierarchy_xray_structure_sync()
    if(log is None): log = sys.stdout
    fmt = """%s Map CC (whole unit cell):  %-6.3f
%s Map CC (around atoms):     %-6.3f
%s rmsd (bonds):              %-s
%s rmsd (angles):             %-s
%s Dist. moved from start:    %-6.3f
%s Dist. moved from previous: %-6.3f
%s All-atom clashscore        %-s
%s Ramachandran plot:
%s   outliers:                %-s %%
%s   allowed:                 %-s %%
%s   favored:                 %-s %%
%s Rotamer outliers:          %-s %%
%s C-beta deviations:         %-s
"""
    if(self.geometry_restraints_manager is not None):
      mso = model_statistics.geometry(
        pdb_hierarchy      = self.pdb_hierarchy,
        molprobity_scores  = libtbx.env.has_module("probe"),
        restraints_manager = self.geometry_restraints_manager)
      print >> log, fmt%(
        prefix, self.map_cc_whole_unit_cell,
        prefix, self.map_cc_around_atoms,
        prefix, format_value("%-6.2f", self.rmsd_b).strip(),
        prefix, format_value("%-6.2f", self.rmsd_a).strip(),
        prefix, self.dist_from_start,
        prefix, self.dist_from_previous,
        prefix, format_value("%-6.2f", mso.clashscore),
        prefix,
        prefix, format_value("%-5.2f", mso.ramachandran_outliers),
        prefix, format_value("%-5.2f", mso.ramachandran_allowed),
        prefix, format_value("%-5.2f", mso.ramachandran_favored),
        prefix, format_value("%6.2f", mso.rotamer_outliers).strip(),
        prefix, format_value("%-3d", mso.c_beta_dev))
    else:
      print >> log, fmt%(
        prefix, self.map_cc_whole_unit_cell,
        prefix, self.map_cc_around_atoms,
        prefix, "None",
        prefix, "None",
        prefix, self.dist_from_start,
        prefix, self.dist_from_previous,
        prefix, "None",
        prefix,
        prefix, "None",
        prefix, "None",
        prefix, "None",
        prefix, "None",
        prefix, "None")
 def formatted_string(self):
   result = "%s %s %s %s %s %s %s" % (
     format_value("%6s",self.file_name),
     format_value("%6s",str(self.r_work)),
     format_value("%6s",str(self.r_free)),
     format_value("%6s",str(self.sigma)),
     format_value("%6s",str(self.high)),
     format_value("%6s",str(self.low)),
     format_value("%6s",str(self.resolution)))
   return result
Ejemplo n.º 26
0
 def show_rwork_rfree_number_completeness(self, prefix="", title=None, out = None):
   if(out is None): out = sys.stdout
   if(title is not None):
     print >> out, prefix+title
   print >> out,\
     prefix+" BIN  RESOLUTION RANGE  COMPL.    NWORK NFREE   RWORK  RFREE  CCWORK CCFREE"
   fmt = " %s %s    %s %s %s  %s %s   %s  %s"
   for bin in self.bins:
     print >> out,prefix+fmt%(
       format_value("%3d", bin.i_bin),
       format_value("%-17s", bin.d_range),
       format_value("%4.2f", bin.completeness),
       format_value("%8d", bin.n_work),
       format_value("%5d", bin.n_free),
       format_value("%6.4f", bin.r_work),
       format_value("%6.4f", bin.r_free),
       format_value("%5.3f", bin.cc_work),
       format_value("%5.3f", bin.cc_free))
Ejemplo n.º 27
0
def show_observations(obs,out=None, n_bins=12):
  if out==None:
    import sys
    out = sys.stdout
  from libtbx.str_utils import format_value

  obs.setup_binner(n_bins = n_bins)
  result = []
  counts_given = obs.binner().counts_given()
  counts_complete = obs.binner().counts_complete()
  for i_bin in obs.binner().range_used():
    sel_w = obs.binner().selection(i_bin)
    sel_fo_all = obs.select(sel_w)
    d_max_,d_min_ = sel_fo_all.d_max_min()
    d_range = obs.binner().bin_legend(
      i_bin=i_bin, show_bin_number=False, show_counts=True)
    sel_data = obs.select(sel_w).data()
    sel_sig = obs.select(sel_w).sigmas()

    if(sel_data.size() > 0):
      bin = resolution_bin(
        i_bin        = i_bin,
        d_range      = d_range,
        mean_I       = flex.mean(sel_data),
        n_work       = sel_data.size(),
        mean_I_sigI  = flex.mean(sel_data/sel_sig),
        d_max_min    = (d_max_, d_min_),
        completeness = (counts_given[i_bin], counts_complete[i_bin]))
      result.append(bin)
  print >>out, "\n Bin  Resolution Range  Compl.         <I>     <I/sig(I)>"
  for bin in result:
    fmt = " %s %s    %s  %s"
    print >>out,fmt%(
      format_value("%3d",   bin.i_bin),
      format_value("%-17s", bin.d_range),
      format_value("%8.1f", bin.mean_I),
      format_value("%8.1f", bin.mean_I_sigI),
      )
  return result
Ejemplo n.º 28
0
 def show_current_r_factors_summary (self, out, prefix="") :
   if (len(self.steps) == 0) :
     return
   last_step = self.steps[-1].replace(":", "")
   fields = last_step.split("_")
   action_label = None
   if (len(fields) >= 2) :
     cycle = fields[0]
     action = "_".join(fields[1:])
     action_label = show_actions.get(action, None)
     if (action_label is None) :
       return
     action_label = cycle + "_" + action_label
   if (action_label is None) :
     if (len(self.steps) == 1) :
       action_label = "start"
     else :
       action_label = "end"
   print >> out, "%s%-6s  r_work=%s  r_free=%s" % (prefix,
     action_label,
     format_value("%.4f", self.r_works[-1]),
     format_value("%.4f", self.r_frees[-1]))
Ejemplo n.º 29
0
def finish_job (result) :
  stats = []
  if (result is not None) :
    stats = [
      ("High resolution", format_value("%.3g", result.overall.d_min)),
      ("Redundancy", format_value("%.1f", result.overall.mean_redundancy)),
      ("R-meas", format_value("%.3g", result.overall.r_meas)),
      ("R-meas (high-res)", format_value("%.3g", result.bins[-1].r_meas)),
      ("<I/sigma>", format_value("%.2g", result.overall.i_over_sigma_mean)),
      ("<I/sigma> (high-res)", format_value("%.2g",
        result.bins[-1].i_over_sigma_mean)),
      ("Completeness", format_value("%.1f%%", result.overall.completeness*100)),
      ("Completeness (high-res)", format_value("%.1f%%",
        result.bins[-1].completeness*100)),
    ]
  return ([], stats)
Ejemplo n.º 30
0
 def get_statistics_for_phenix_gui (self) :
   mp = self
   stats = [
     ("R-work", format_value("%.4f", mp.r_work())),
     ("R-free", format_value("%.4f", mp.r_free())),
     ("RMS(bonds)", format_value("%.3f", mp.rms_bonds())),
     ("RMS(angles)", format_value("%.4f", mp.rms_angles())),
     ("Clashscore", format_value("%.2f", mp.clashscore())),
     ("MolProbity score", format_value("%.3f", mp.molprobity_score())),
   ]
   if (self.neutron_stats is not None) :
     stats.extend([
       ("R-work (neutron)", format_value("%.4f", self.neutron_stats.r_work)),
       ("R-free (neutron)", format_value("%.4f", self.neutron_stats.r_free)),
     ])
   return stats
Ejemplo n.º 31
0
def run(args, log=sys.stdout):
    """phenix.map_model_cc or phenix.model_map_cc:
  Given PDB file and a map file calculate model-map coorelation.

How to run:
  phenix.map_model_cc model.pdb map.ccp4 resolution=3
  phenix.model_map_cc model.pdb map.ccp4 resolution=3

Feedback:
  [email protected]
  [email protected]
  """
    assert len(locals().keys()) == 2  # intentional
    print >> log, "-" * 79
    print >> log, run.__doc__
    print >> log, "-" * 79
    # Get inputs
    inputs = get_inputs(args=args, log=log, master_params=master_params())
    # Model
    broadcast(m="Input PDB:", log=log)
    print >> log, inputs.pdb_file_name  # ideally this should not be available here
    inputs.pdb_hierarchy.show(level_id="chain")
    # Crystal symmetry
    broadcast(m="Box (unit cell) info:", log=log)
    inputs.crystal_symmetry.show_summary(f=log)
    # Map
    broadcast(m="Input map:", log=log)
    inputs.ccp4_map_object.show_summary(prefix="  ")
    # Run task in 4 separate steps
    task_obj = mmtbx.maps.map_model_cc.map_model_cc(
        map_data=inputs.ccp4_map_object.data.as_double(),
        pdb_hierarchy=inputs.pdb_hierarchy,
        crystal_symmetry=inputs.crystal_symmetry,
        params=inputs.params.map_model_cc)
    task_obj.validate()
    task_obj.run()
    results = task_obj.get_results()
    if inputs.params.pkl_file_name is not None:
        easy_pickle.dump(
            file_name=inputs.params.pkl_file_name,
            obj=group_args(
                cc_mask=results.cc_mask,
                cc_volume=results.cc_volume,
                cc_peaks=results.cc_peaks,
                cc_per_chain=results.cc_per_chain,
                # cc_per_residue = results.cc_per_residue, # not pickleable because of residue in it and big size
                fsc=results.fsc,
            ))
    #
    broadcast(m="Map resolution:", log=log)
    print >> log, "  Resolution:", inputs.params.map_model_cc.resolution
    broadcast(m="Map-model CC (overall):", log=log)
    print >> log, "  CC_mask  : %s" % format_value("%6.4f", results.cc_mask)
    print >> log, "  CC_volume: %s" % format_value("%6.4f", results.cc_volume)
    print >> log, "  CC_peaks : %s" % format_value("%6.4f", results.cc_peaks)
    if results.fsc is not None:
        broadcast(m="Model-map FSC:", log=log)
        if (inputs.params.output_file_name_prefix is None):
            out = log
        else:
            fsc_fn = "%s_fsc.log" % inputs.params.output_file_name_prefix
            out = open(fsc_fn, "w")
            print >> log, "  saved to:", fsc_fn
        print >> out, "    1/resolution    CC"
        for a, b in zip(results.fsc.d_inv, results.fsc.fsc):
            print >> out, "%15.9f %15.9f" % (a, b)
        if (inputs.params.output_file_name_prefix is not None):
            out.close()
    if len(results.cc_per_chain) + len(results.cc_per_residue) > 0:
        broadcast(m="Map-model CC (local):", log=log)
    # Per chain
    if len(results.cc_per_chain) > 0:
        print >> log, "Per chain:"
        print >> log, "chain ID  CC       <B>    <occ>   N atoms"
        fmt = "%s        %7.4f %8.3f %4.2f    %d"
        for r in results.cc_per_chain:
            print fmt % (r.chain_id, r.cc, r.b_iso_mean, r.occ_mean, r.n_atoms)
    # Per residue
    if len(results.cc_per_residue) > 0:
        print >> log, "Per residue:"
        fmt = "%s %s %s %7.4f %8.3f %4.2f"
        for r in results.cc_per_residue:
            print fmt % (r.chain_id, r.resname, r.resseq, r.cc, r.b_iso_mean,
                         r.occ_mean)
    return None
Ejemplo n.º 32
0
 def format_score(self, replace_none_with="None"):
     return format_value(self.score_format,
                         self.score,
                         replace_none_with=replace_none_with)
Ejemplo n.º 33
0
 def fv (fs, val) :
   return format_value(fs, val, replace_none_with="----")
Ejemplo n.º 34
0
    def show(self, log=None):
        if (log is None): log = sys.stdout
        # crystal
        print >> log, "  Unit cell:       ", self.crystal.uc
        print >> log, "  Space group:     ", self.crystal.sg, \
                      "number of symmetry operations:", self.crystal.n_sym_op
        # models
        print >> log, "  Number of models:", len(self.models)
        for i_seq, i_model in enumerate(self.models):
            print >> log, "  Model #%s:" % str("%d" % (i_seq + 1)).strip()
            print >> log, "    Number of residues in alternative conformations:", \
              i_model.n_residues_in_altlocs
            print >> log, "    Residue content:"
            len_max = 0
            for k in i_model.resname_classes:
                k = k.split()
                if (len(k[0]) > len_max): len_max = len(k[0])
            fmt = "      %-" + str(len_max) + "s : %s"
            for rc in i_model.resname_classes:
                k, v = rc.split()
                print >> log, fmt % (k, v)
            x = i_model.xray_structure_stat
            print >> log, "    Atoms:"
            print >> log, "      content: %s" % x.all.n_atoms
            max_field_for_element_count = 1
            for element_occupancy_sum in x.all.atom_counts_str.split():
                individual_element_count_len = len(
                    element_occupancy_sum.split(":")[1])
                if (individual_element_count_len >
                        max_field_for_element_count):
                    max_field_for_element_count = individual_element_count_len
            for element_occupancy_sum in x.all.atom_counts_str.split():
                iecl = "%" + str(max_field_for_element_count) + "s"
                fmt = "        %s " + "count: %s " % iecl + "occupancy sum: %s"
                print >> log, fmt % tuple(element_occupancy_sum.split(":"))
            print >> log, "      ADP (min,max,mean):"
            print >> log, "        all           (%s atoms): %s %s %s" % (
                x.all.n_atoms, x.all.b_min, x.all.b_max, x.all.b_mean)

            if (x.sidechain is not None):
                print >> log, "        side chains   (%s atoms): %s %s %s" % (
                    x.sidechain.n_atoms, x.sidechain.b_min, x.sidechain.b_max,
                    x.sidechain.b_mean)
            if (x.backbone is not None):
                print >> log, "        main chains   (%s atoms): %s %s %s" % (
                    x.backbone.n_atoms, x.backbone.b_min, x.backbone.b_max,
                    x.backbone.b_mean)
            if (x.macromolecule is not None):
                print >> log, "        macromolecule (%s atoms): %s %s %s" % (
                    x.macromolecule.n_atoms, x.macromolecule.b_min,
                    x.macromolecule.b_max, x.macromolecule.b_mean)
            if (x.ligand is not None):
                print >> log, "        ligands       (%s atoms): %s %s %s" % (
                    x.ligand.n_atoms, x.ligand.b_min, x.ligand.b_max,
                    x.ligand.b_mean)
            if (x.solvent is not None):
                print >> log, "        solvent       (%s atoms): %s %s %s" % (
                    x.solvent.n_atoms, x.solvent.b_min, x.solvent.b_max,
                    x.solvent.b_mean)
            if (i_model.rms_b_iso_or_b_equiv_bonded is not None):
                print >> log, "      mean bonded (Bi-Bj) : %s" % format_value(
                    "%8.2f", i_model.rms_b_iso_or_b_equiv_bonded).strip()
            print >> log, "      occupancies (min,max,mean)       : %s %s %s" % (
                x.all.o_min, x.all.o_max, x.all.o_mean)
            print >> log, "      number_of_anisotropic            : " + format_value(
                "%-7s", x.all.n_aniso)
            print >> log, "      number_of_non_positive_definite  : %s" % x.all.n_npd
            g = i_model.geometry_all
            if (g is not None):
                print >> log, "    Stereochemistry statistics (mean, max, count) - overall:"
                print >> log, "      bonds            : %8.4f %8.4f %d" % (
                    g.b[2], g.b[1], g.b_number)
                print >> log, "      angles           : %8.4f %8.4f %d" % (
                    g.a[2], g.a[1], g.a_number)
                print >> log, "      dihedrals        : %8.4f %8.4f %d" % (
                    g.d[2], g.d[1], g.d_number)
                print >> log, "      chirality        : %8.4f %8.4f %d" % (
                    g.c[2], g.c[1], g.c_number)
                print >> log, "      planarity        : %8.4f %8.4f %d" % (
                    g.p[2], g.p[1], g.p_number)
                print >> log, "      non-bonded (min) : %8.4f" % (g.n[0])
            if ([i_model.geometry_solvent,
                 i_model.geometry_ligand].count(None) == 0):
                g = i_model.geometry_macromolecule
                if (g is not None):
                    print >> log, "    Stereochemistry statistics (mean, max, count) - macromolecule:"
                    print >> log, "      bonds            : %8.4f %8.4f %d" % (
                        g.b[2], g.b[1], g.b_number)
                    print >> log, "      angles           : %8.4f %8.4f %d" % (
                        g.a[2], g.a[1], g.a_number)
                    print >> log, "      dihedrals        : %8.4f %8.4f %d" % (
                        g.d[2], g.d[1], g.d_number)
                    print >> log, "      chirality        : %8.4f %8.4f %d" % (
                        g.c[2], g.c[1], g.c_number)
                    print >> log, "      planarity        : %8.4f %8.4f %d" % (
                        g.p[2], g.p[1], g.p_number)
                    print >> log, "      non-bonded (min) : %8.4f" % (g.n[0])
                g = i_model.geometry_ligand
                if (g is not None):
                    print >> log, "    Stereochemistry statistics (mean, max, count) - ligands:"
                    print >> log, "      bonds            : %8.4f %8.4f %d" % (
                        g.b[2], g.b[1], g.b_number)
                    print >> log, "      angles           : %8.4f %8.4f %d" % (
                        g.a[2], g.a[1], g.a_number)
                    print >> log, "      dihedrals        : %8.4f %8.4f %d" % (
                        g.d[2], g.d[1], g.d_number)
                    print >> log, "      chirality        : %8.4f %8.4f %d" % (
                        g.c[2], g.c[1], g.c_number)
                    print >> log, "      planarity        : %8.4f %8.4f %d" % (
                        g.p[2], g.p[1], g.p_number)
                    print >> log, "      non-bonded (min) : %8.4f" % (g.n[0])
                g = i_model.geometry_solvent
                if (g is not None):
                    print >> log, "    Stereochemistry statistics - solvent:"
                    print >> log, "      non-bonded (min) : %8.4f" % (g.n[0])
            if (i_model.molprobity is not None):
                outl = i_model.molprobity.ramalyze_outliers
                allo = i_model.molprobity.ramalyze_allowed
                favo = i_model.molprobity.ramalyze_favored
                print >> log, "    Molprobity statistics:"
                print >> log, "      Ramachandran plot, number of:"
                print >> log, "        outliers : %-5d (%-5.2f %s)" % (
                    outl[0], outl[1] * 100., "%")
                print >> log, "        allowed  : %-5d (%-5.2f %s)" % (
                    allo[0], allo[1] * 100., "%")
                print >> log, "        favored  : %-5d (%-5.2f %s)" % (
                    favo[0], favo[1] * 100., "%")
                print >> log, "      Rotamer outliers        : %d (%s %s)" % (
                    i_model.molprobity.rotalyze[0],
                    str("%6.2f" %
                        (i_model.molprobity.rotalyze[1] * 100.)).strip(), "%")
                print >> log, "      Cbeta deviations >0.25A : %d" % i_model.molprobity.cbetadev
                print >> log, "      All-atom clashscore     : %.2f (steric overlaps >0.4A per 1000 atoms)"% \
                  i_model.molprobity.clashscore
                print >> log, "      Overall score           : %.2f" % \
                  i_model.molprobity.mpscore
        #
        print >> log, "  Data:"
        result = " \n    ".join([
            "data_label                           : %s" % self.data.data_label,
            "high_resolution                      : " +
            format_value("%-5.2f", self.data.high_resolution),
            "low_resolution                       : " +
            format_value("%-6.2f", self.data.low_resolution),
            "completeness_in_range                : " +
            format_value("%-6.2f", self.data.completeness_in_range),
            "completeness(d_min-inf)              : " +
            format_value("%-6.2f", self.data.completeness_d_min_inf),
            "completeness(6A-inf)                 : " +
            format_value("%-6.2f", self.data.completeness_6A_inf),
            "wilson_b                             : " +
            format_value("%-6.1f", self.data.wilson_b),
            "number_of_reflections                : " +
            format_value("%-8d", self.data.number_of_reflections),
            "number_of_reflections(non-anomalous) : " +
            format_value("%-8d", self.data.number_of_reflections_merged),
            "test_set_size                        : " +
            format_value("%-8.4f", self.data.test_set_size),
            "test_flag_value                      : " +
            format_value("%-s", self.data.test_flag_value),
            "number_of_Fobs_outliers              : " +
            format_value("%-8d", self.data.number_of_Fobs_outliers),
            "twinned                              : " +
            format_value("%-s", self.data.twinned),
            "anomalous_flag                       : " +
            format_value("%-6s", self.data.anomalous_flag)
        ])
        print >> log, "   ", result
        #
        print >> log, "  Model_vs_Data:"
        result = [
            "r_work(re-computed)                : %s" %
            format_value("%-6.4f", self.model_vs_data.r_work).strip(),
            "r_free(re-computed)                : %s" %
            format_value("%-6.4f", self.model_vs_data.r_free).strip(),
            "mean phase error estimate (deg)    : %s" % format_value(
                "%-7.2f", self.model_vs_data.mean_phase_error).strip(),
        ]
        ml_err = self.model_vs_data.ml_coordinate_error
        if (ml_err is not None):
            result.append("ml coordinate error estimate (A)   : %s" %
                          format_value("%-6.2f", ml_err).strip())
        sc = self.model_vs_data.solvent_content_via_mask
        if (sc is not None): sc *= 100
        result.append("solvent_content_estimated_via_mask : %-s %%" %
                      format_value("%.1f", sc))
        result = " \n    ".join(result)
        print >> log, "   ", result
        #
        if (self.pdb_header is not None):
            print >> log, "  Information extracted from PDB file header:"
            print >> log, "    program_name    : %-s" % format_value(
                "%s", self.pdb_header.program_name)
            print >> log, "    year            : %-s" % format_value(
                "%s", self.pdb_header.year)
            print >> log, "    r_work          : %-s" % format_value(
                "%s", self.pdb_header.r_work)
            print >> log, "    r_free          : %-s" % format_value(
                "%s", self.pdb_header.r_free)
            print >> log, "    high_resolution : %-s" % format_value(
                "%s", self.pdb_header.high_resolution)
            print >> log, "    low_resolution  : %-s" % format_value(
                "%s", self.pdb_header.low_resolution)
            print >> log, "    sigma_cutoff    : %-s" % format_value(
                "%s", self.pdb_header.sigma_cutoff)
            print >> log, "    matthews_coeff  : %-s" % format_value(
                "%s", self.pdb_header.matthews_coeff)
            if (self.pdb_header.solvent_cont is not None):
                print >> log, "    solvent_cont    : %-s %%" % format_value(
                    "%s", self.pdb_header.solvent_cont)
            else:
                print >> log, "    solvent_cont    : %-s" % format_value(
                    "%s", self.pdb_header.solvent_cont)
            if (self.pdb_header.tls is not None):
                print >> log, "    TLS             : %-s" % format_value(
                    "%s", " ".join([
                        str(self.pdb_header.tls.pdb_inp_tls.tls_present),
                        "(number of groups: %s)" %
                        str(len(self.pdb_header.tls.tls_selections))
                    ]))
            else:
                print >> log, "    TLS             : None"
            if (self.pdb_header.exptl_method is not None):
                print >> log, "    exptl_method    : %-s" % format_value(
                    "%s", self.pdb_header.exptl_method)
        #
        print >> log, "  After applying resolution and sigma cutoffs:"
        print >> log, "    n_refl_cutoff : %-s" % format_value(
            "%d", self.misc.n_refl_cutoff).strip()
        print >> log, "    r_work_cutoff : %-s" % format_value(
            "%6.4f", self.misc.r_work_cutoff).strip()
        print >> log, "    r_free_cutoff : %-s" % format_value(
            "%6.4f", self.misc.r_free_cutoff).strip()
Ejemplo n.º 35
0
 def format_info_string(self):
     return "%7s %6s    %6s     %6s %9s" % (
         self.id_str, format_value("%6.3f", self.map_cc_all),
         format_value("%6.3f", self.map_cc_backbone),
         format_value("%6.3f", self.map_cc_sidechain), self.rotamer_status)
Ejemplo n.º 36
0
 def show_remark_3(self, out = None):
   from cctbx import sgtbx
   if(out is None): out = sys.stdout
   pr = "REMARK   3  "
   print(pr+"REFINEMENT TARGET : %s"%self.target_name.upper(), file=out)
   print(pr, file=out)
   print(pr+"DATA USED IN REFINEMENT.", file=out)
   print(pr+" RESOLUTION RANGE HIGH (ANGSTROMS) : %s"%format_value("%-8.2f", self.d_min), file=out)
   print(pr+" RESOLUTION RANGE LOW  (ANGSTROMS) : %s"%format_value("%-8.2f", self.d_max), file=out)
   print(pr+" MIN(FOBS/SIGMA_FOBS)              : %s"%format_value("%-6.2f", self.min_f_obs_over_sigma), file=out)
   print(pr+" COMPLETENESS FOR RANGE        (%s) : %-6.2f"%\
     ("%", self.completeness_in_range*100.0), file=out)
   print(pr+" NUMBER OF REFLECTIONS             : %-10d"%self.number_of_reflections, file=out)
   print(pr+" NUMBER OF REFLECTIONS (NON-ANOMALOUS) : %-10d"%self.number_of_reflections_merged, file=out)
   print(pr, file=out)
   print(pr+"FIT TO DATA USED IN REFINEMENT.", file=out)
   print(pr+" R VALUE     (WORKING + TEST SET) : %s"%format_value("%-6.4f",self.r_all), file=out)
   print(pr+" R VALUE            (WORKING SET) : %s"%format_value("%-6.4f", self.r_work), file=out)
   print(pr+" FREE R VALUE                     : %s"%format_value("%-6.4f", self.r_free), file=out)
   print(pr+" FREE R VALUE TEST SET SIZE   (%s) : %-6.2f"%("%",
     float(self.number_of_test_reflections)/self.number_of_reflections*100.), file=out)
   print(pr+" FREE R VALUE TEST SET COUNT      : %-10d"%self.number_of_test_reflections, file=out)
   print(pr, file=out)
   self.show_rwork_rfree_number_completeness(prefix = pr,
     title = "FIT TO DATA USED IN REFINEMENT (IN BINS).", out = out)
   print(pr, file=out)
   print(pr+"BULK SOLVENT MODELLING.", file=out)
   print(pr+" METHOD USED        : FLAT BULK SOLVENT MODEL", file=out)
   print(pr+" SOLVENT RADIUS     : %s"%format_value("%-8.2f", self.mask_solvent_radius), file=out)
   print(pr+" SHRINKAGE RADIUS   : %s"%format_value("%-8.2f", self.mask_shrink_radius), file=out)
   print(pr+" GRID STEP FACTOR   : %s"%format_value("%-8.2f", self.mask_grid_step_factor), file=out)
   print(pr, file=out)
   if(self.twin_fraction is not None):
     print(pr+"TWINNING INFORMATION.", file=out)
     print(pr+" FRACTION: %s"%format_value("%-8.3f", self.twin_fraction), file=out)
     print(pr+" OPERATOR: %s"%\
       format_value("%-s", sgtbx.change_of_basis_op(self.twin_law).as_hkl()), file=out)
   print(pr+"ERROR ESTIMATES.", file=out)
   print(pr+" COORDINATE ERROR (MAXIMUM-LIKELIHOOD BASED)     : %s"%\
     format_value("%-8.2f", self.ml_coordinate_error), file=out)
   print(pr+" PHASE ERROR (DEGREES, MAXIMUM-LIKELIHOOD BASED) : %s"%\
     format_value("%-8.2f", self.ml_phase_error), file=out)
   print(pr, file=out)
   print(pr+"STRUCTURE FACTORS CALCULATION ALGORITHM : %-s"%\
     self.sf_algorithm.upper(), file=out)
   print(pr+"B VALUES.", file=out)
   print(pr+" FROM WILSON PLOT           (A**2) : %s" %\
     format_value("%-8.2f", self.wilson_b), file=out)
   out.flush()
Ejemplo n.º 37
0
 def as_remark_200(self, wavelength=None):
     from libtbx.test_utils import approx_equal
     synchrotron = wl = "NULL"
     if (wavelength is not None):
         out = StringIO()
         # XXX somewhat risky...
         if (not approx_equal(wavelength, 1.5418, eps=0.01, out=out) and
                 not approx_equal(wavelength, 0.7107, eps=0.01, out=out)):
             synchrotron = "Y"
         else:
             synchrotron = "N"
         wl = "%.4f" % wavelength
     lines = []
     lines.append("")
     lines.append("EXPERIMENTAL DETAILS")
     lines.append(" EXPERIMENT TYPE                : X-RAY DIFFRACTION")
     lines.append(" DATE OF DATA COLLECTION        : NULL")
     lines.append(" TEMPERATURE           (KELVIN) : NULL")
     lines.append(" PH                             : NULL")
     lines.append(" NUMBER OF CRYSTALS USED        : NULL")
     lines.append("")
     lines.append(" SYNCHROTRON              (Y/N) : NULL")
     lines.append(" RADIATION SOURCE               : NULL")
     lines.append(" BEAMLINE                       : NULL")
     lines.append(" X-RAY GENERATOR MODEL          : NULL")
     lines.append(" MONOCHROMATIC OR LAUE    (M/L) : M")
     lines.append(" WAVELENGTH OR RANGE        (A) : %s" % wl)
     lines.append(" MONOCHROMATOR                  : NULL")
     lines.append(" OPTICS                         : NULL")
     lines.append("")
     lines.append(" DETECTOR TYPE                  : NULL")
     lines.append(" DETECTOR MANUFACTURER          : NULL")
     lines.append(" INTENSITY-INTEGRATION SOFTWARE : NULL")
     lines.append(" DATA SCALING SOFTWARE          : NULL")
     lines.append("")
     lines.append("OVERALL.")
     comp_overall = format_value("%.1f", self.overall.completeness * 100)
     mult_overall = format_value("%.1f", self.overall.mean_redundancy)
     rmerg_overall = format_value("%.5f", self.overall.r_merge)
     s2n_overall = format_value("%.4f", self.overall.i_over_sigma_mean)
     lines.append(" COMPLETENESS FOR RANGE     (%%) : %s" % comp_overall)
     lines.append(" DATA REDUNDANCY                : %s" % mult_overall)
     lines.append(" R MERGE                    (I) : %s" % rmerg_overall)
     lines.append(" R SYM                      (I) : NULL")
     lines.append(" <I/SIGMA(I)> FOR THE DATA SET  : %s" % s2n_overall)
     lines.append("")
     lines.append("IN THE HIGHEST RESOLUTION SHELL.")
     bin_stats = self.bins[-1]
     d_max = format_value("%.2f", bin_stats.d_max)
     d_min = format_value("%.2f", bin_stats.d_min)
     comp_lastbin = format_value("%.1f", bin_stats.completeness * 100)
     mult_lastbin = format_value("%.1f", bin_stats.mean_redundancy)
     rmerg_lastbin = format_value("%.5f", bin_stats.r_merge)
     s2n_lastbin = format_value("%.4f", bin_stats.i_over_sigma_mean)
     lines.append(" HIGHEST RESOLUTION SHELL, RANGE HIGH (A) : %s" % d_min)
     lines.append(" HIGHEST RESOLUTION SHELL, RANGE LOW  (A) : %s" % d_max)
     lines.append(" COMPLETENESS FOR SHELL     (%%) : %s" % comp_lastbin)
     lines.append(" DATA REDUNDANCY IN SHELL       : %s" % mult_lastbin)
     lines.append(" R MERGE FOR SHELL          (I) : %s" % rmerg_lastbin)
     lines.append(" R SYM FOR SHELL            (I) : NULL")
     lines.append(" <I/SIGMA(I)> FOR SHELL         : %s" % s2n_lastbin)
     lines.append("")
     remark_lines = ["REMARK 200 %s" % line for line in lines]
     return "\n".join(remark_lines)
Ejemplo n.º 38
0
 def fs(format, value):
     return str_utils.format_value(format,
                                   value,
                                   replace_none_with=("(none)"))
Ejemplo n.º 39
0
 def format(self):
     return "resolution = %s  intensity = %.2f  slow=%d  fast=%d" % (
         format_value("%.2f A",
                      self.d_min), self.intensity, self.slow, self.fast)
Ejemplo n.º 40
0
 def f(v):
     return format_value(format=format, value=v)
Ejemplo n.º 41
0
    def __init__(self, obs, unobstructed, params, out=None, n_bins=12):
        if out == None:
            import sys
            out = sys.stdout
        from libtbx.str_utils import format_value
        self.params = params
        self.out = out
        self.obs = obs

        obs.setup_binner(n_bins=n_bins)
        attenuated = obs.select(~unobstructed)
        unattenuated = obs.select(unobstructed)

        attenuated.use_binning_of(obs)
        unattenuated.use_binning_of(obs)

        self.result = []
        counts_given = obs.binner().counts_given()
        counts_complete = obs.binner().counts_complete()

        counts_given_attenuated = attenuated.binner().counts_given()
        counts_given_unattenuated = unattenuated.binner().counts_given()

        for i_bin in obs.binner().range_used():
            sel_w = obs.binner().selection(i_bin)
            sel_fo_all = obs.select(sel_w)
            d_max_, d_min_ = sel_fo_all.d_max_min()
            d_range = obs.binner().bin_legend(i_bin=i_bin,
                                              show_bin_number=False,
                                              show_counts=True)
            sel_data = obs.select(sel_w).data()
            sel_sig = obs.select(sel_w).sigmas()

            sel_unatten_w = unattenuated.binner().selection(i_bin)
            sel_unatten_data = unattenuated.select(sel_unatten_w).data()
            sel_unatten_sig = unattenuated.select(sel_unatten_w).sigmas()

            sel_atten_w = attenuated.binner().selection(i_bin)
            sel_atten_data = attenuated.select(sel_atten_w).data()
            sel_atten_sig = attenuated.select(sel_atten_w).sigmas()

            if len(sel_unatten_data) > 0:
                unatten_mean_I = flex.mean(sel_unatten_data)
                unatten_mean_I_sigI = flex.mean(sel_unatten_data /
                                                sel_unatten_sig)
            else:
                unatten_mean_I = 0
                unatten_mean_I_sigI = 0

            if len(sel_atten_data) > 0:
                atten_mean_I = flex.mean(sel_atten_data)
                atten_mean_I_sigI = flex.mean(sel_atten_data / sel_atten_sig)
            else:
                atten_mean_I = 0
                atten_mean_I_sigI = 0

            if (sel_data.size() > 0):
                bin = resolution_bin(
                    i_bin=i_bin,
                    d_range=d_range,
                    mean_I=flex.mean(sel_data),
                    n_work=sel_data.size(),
                    mean_I_sigI=flex.mean(sel_data / sel_sig),
                    d_max_min=(d_max_, d_min_),
                    completeness=(counts_given[i_bin], counts_complete[i_bin]),
                    given_unatten=counts_given_unattenuated[i_bin],
                    unatten_mean_I=unatten_mean_I,
                    unatten_mean_I_sigI=unatten_mean_I_sigI,
                    given_atten=counts_given_attenuated[i_bin],
                    atten_mean_I=atten_mean_I,
                    atten_mean_I_sigI=atten_mean_I_sigI,
                )
                self.result.append(bin)
        self.set_limits(unobstructed)
        print >> out, "\n Bin  Resolution Range  Compl.         <I>     <I/sig(I)> Unobstructed <I>     <I/sig(I)> Obstructed <I>     <I/sig(I)>"
        for bin in self.result:
            fmt = " %s %s    %s  %s%s   %s   %s  %s%s   %s  %s   %s%s"
            print >> out, fmt % (
                format_value("%3d", bin.i_bin),
                format_value("%-17s", bin.d_range),
                format_value("%8.1f", bin.mean_I),
                format_value("%8.2f", bin.mean_I_sigI),
                format_value("%1s", getattr(bin, "limit", " ")),
                format_value("%6d", bin.given_unatten),
                format_value("%8.1f", bin.unatten_mean_I),
                format_value("%8.2f", bin.unatten_mean_I_sigI),
                format_value("%1s", getattr(bin, "unatten_limit", " ")),
                format_value("%6d", bin.given_atten),
                format_value("%8.1f", bin.atten_mean_I),
                format_value("%8.2f", bin.atten_mean_I_sigI),
                format_value("%1s", getattr(bin, "atten_limit", " ")),
            )
Ejemplo n.º 42
0
 def show_fom_pher_alpha_beta_in_bins(self, out = None):
   if(out is None): out = sys.stdout
   print("|"+"-"*77+"|", file=out)
   print("|R-free likelihood based estimates for figures of merit, absolute phase error,|", file=out)
   print("|and distribution parameters alpha and beta (Acta Cryst. (1995). A51, 880-887)|", file=out)
   print("|"+" "*77+"|", file=out)
   print("| Bin     Resolution      No. Refl.   FOM  Phase Scale    Alpha        Beta   |", file=out)
   print("|  #        range        work  test        error factor                       |", file=out)
   for bin in self.bins:
     print("|%3d: %-17s%6d%6d%s%s%s%s%s|" % (
       bin.i_bin,
       bin.d_range,
       bin.n_work,
       bin.n_free,
       format_value("%6.2f",  bin.fom_work),
       format_value("%7.2f",  bin.pher_work),
       format_value("%7.2f",  bin.scale_k1_work),
       format_value("%9.2f",  bin.alpha_work),
       format_value("%14.2f", bin.beta_work)), file=out)
   print("|alpha:            min =%s max =%s mean =%s|"%(
     format_value("%12.2f", self.alpha_work_min),
     format_value("%16.2f", self.alpha_work_max),
     format_value("%13.2f", self.alpha_work_mean)), file=out)
   print("|beta:             min =%s max =%s mean =%s|"%(
     format_value("%12.2f", self.beta_work_min),
     format_value("%16.2f", self.beta_work_max),
     format_value("%13.2f", self.beta_work_mean)), file=out)
   print("|figures of merit: min =%s max =%s mean =%s|"%(
     format_value("%12.2f", self.fom_work_min),
     format_value("%16.2f", self.fom_work_max),
     format_value("%13.2f", self.fom_work_mean)), file=out)
   print("|phase err.(work): min =%s max =%s mean =%s|"%(
     format_value("%12.2f", self.pher_work_min),
     format_value("%16.2f", self.pher_work_max),
     format_value("%13.2f", self.pher_work_mean)), file=out)
   print("|phase err.(test): min =%s max =%s mean =%s|"%(
     format_value("%12.2f", self.pher_free_min),
     format_value("%16.2f", self.pher_free_max),
     format_value("%13.2f", self.pher_free_mean)), file=out)
   print("|"+"-"*77+"|", file=out)
   out.flush()
Ejemplo n.º 43
0
def n_as_s(format, value):
  if (value is None):
    return format_value(format=format, value=value)
  if (isinstance(value, (int, float))):
    return (format % value).strip()
  return [(format % v).strip() for v in value]
Ejemplo n.º 44
0
    def print_table(self):
        from libtbx import table_utils
        from libtbx.str_utils import format_value

        table_header = [
            "Tile", "Dist", "Nobs", "aRmsd", "Rmsd", "delx", "dely", "disp",
            "rotdeg", "Rsigma", "Tsigma"
        ]
        table_data = []
        table_data.append(table_header)
        sort_radii = flex.sort_permutation(flex.double(self.radii))
        tile_rmsds = flex.double()
        radial_sigmas = flex.double(len(self.tiles) // 4)
        tangen_sigmas = flex.double(len(self.tiles) // 4)
        for idx in range(len(self.tiles) // 4):
            x = sort_radii[idx]
            if self.tilecounts[x] < 3:
                wtaveg = 0.0
                radial = (0, 0)
                tangential = (0, 0)
                rmean, tmean, rsigma, tsigma = (0, 0, 1, 1)
            else:
                wtaveg = self.weighted_average_angle_deg_from_tile(x)
                radial, tangential, rmean, tmean, rsigma, tsigma = get_radial_tangential_vectors(
                    self, x)

            radial_sigmas[x] = rsigma
            tangen_sigmas[x] = tsigma
            table_data.append([
                format_value("%3d", x),
                format_value("%7.2f", self.radii[x]),
                format_value("%6d", self.tilecounts[x]),
                format_value("%5.2f", self.asymmetric_tile_rmsd[x]),
                format_value("%5.2f", self.tile_rmsd[x]),
                format_value("%5.2f", self.mean_cv[x][0]),
                format_value("%5.2f", self.mean_cv[x][1]),
                format_value("%5.2f",
                             matrix.col(self.mean_cv[x]).length()),
                format_value("%6.2f", wtaveg),
                format_value("%6.2f", rsigma),
                format_value("%6.2f", tsigma),
            ])
        table_data.append([""] * len(table_header))
        rstats = flex.mean_and_variance(radial_sigmas,
                                        self.tilecounts.as_double())
        tstats = flex.mean_and_variance(tangen_sigmas,
                                        self.tilecounts.as_double())
        table_data.append([
            format_value("%3s", "ALL"),
            format_value("%s", ""),
            format_value("%6d", self.overall_N),
            format_value("%5.2f", math.sqrt(flex.mean(self.delrsq))),
            format_value("%5.2f", self.overall_rmsd),
            format_value("%5.2f", self.overall_cv[0]),
            format_value("%5.2f", self.overall_cv[1]),
            format_value(
                "%5.2f",
                flex.mean(
                    flex.double(
                        [matrix.col(cv).length() for cv in self.mean_cv]))),
            format_value("%s", ""),
            format_value("%6.2f", rstats.mean()),
            format_value("%6.2f", tstats.mean()),
        ])

        print()
        print(
            table_utils.format(table_data,
                               has_header=1,
                               justify='center',
                               delim=" "))
Ejemplo n.º 45
0
def _format_mean(values, format):
    return format_value(format=format,
                        value=mean_default(values=values, default=None))
Ejemplo n.º 46
0
  def show(self, log=None, prefix="", lowercase=False):
    if(log is None): log = sys.stdout
    def fmt(f1,f2,d1):
      fmt_str= "%6.3f %7.3f %6d"
      if f1 is None  : return '   -       -       -  '
      return fmt_str%(f1,f2,d1)
    def fmt2(f1):
      if f1 is None: return '  -   '
      return "%-6.3f"%(f1)
    res = self.result()
    a,b,c,d,p,n = res.angle, res.bond, res.chirality, res.dihedral, \
      res.planarity, res.nonbonded
    result = "%s" % prefix
    result += """
%sGEOMETRY RESTRAINTS LIBRARY: %s
%sDEVIATIONS FROM IDEAL VALUES.
%s  BOND      : %s
%s  ANGLE     : %s
%s  CHIRALITY : %s
%s  PLANARITY : %s
%s  DIHEDRAL  : %s
%s  MIN NONBONDED DISTANCE : %s
%s"""%(prefix,
       self.restraints_source,
       prefix,
       prefix, fmt(b.mean, b.max, b.n),
       prefix, fmt(a.mean, a.max, a.n),
       prefix, fmt(c.mean, c.max, c.n),
       prefix, fmt(p.mean, p.max, p.n),
       prefix, fmt(d.mean, d.max, d.n),
       prefix, fmt2(n.min),
       prefix)
    result += "%s" % prefix
    result += """
%sMOLPROBITY STATISTICS.
%s  ALL-ATOM CLASHSCORE : %s
%s  RAMACHANDRAN PLOT:
%s    OUTLIERS : %-5.2f %s
%s    ALLOWED  : %-5.2f %s
%s    FAVORED  : %-5.2f %s
%s  ROTAMER OUTLIERS : %s %s
%s  CBETA DEVIATIONS : %-d
%s  PEPTIDE PLANE:
%s    CIS-PROLINE     : %s
%s    CIS-GENERAL     : %s
%s    TWISTED PROLINE : %s
%s    TWISTED GENERAL : %s"""%(
        prefix,
        prefix, format_value("%-6.2f", res.clash.score).strip(),
        prefix,
        prefix, res.ramachandran.outliers, "%",
        prefix, res.ramachandran.allowed, "%",
        prefix, res.ramachandran.favored, "%",
        prefix, str("%6.2f"%(res.rotamer.outliers)).strip(),"%",
        prefix, res.c_beta.outliers,
        prefix,
        prefix, str(res.omega.cis_proline),
        prefix, str(res.omega.cis_general),
        prefix, str(res.omega.twisted_proline),
        prefix, str(res.omega.twisted_general))
    if(lowercase):
      result = result.swapcase()
    print >> log, result
Ejemplo n.º 47
0
    def show(self, prefix="", log=None):
        self.assert_pdb_hierarchy_xray_structure_sync()
        if (log is None): log = sys.stdout
        fmt = """%s CC_mask:                   %-6.3f
%s CC_volume:                 %-6.3f
%s CC_peaks:                  %-6.3f
%s rmsd (bonds):              %-s
%s rmsd (angles):             %-s
%s Dist. moved from start:    %-6.3f
%s Dist. moved from previous: %-6.3f
%s All-atom clashscore        %-s
%s Ramachandran plot:
%s   outliers:                %-s %%
%s   allowed:                 %-s %%
%s   favored:                 %-s %%
%s Omega angle:
%s   cis-proline:             %-s %%
%s   twisted proline:         %-s %%
%s   cis-general:             %-s %%
%s   twisted-general:         %-s %%
%s CaBLAM analysis:
%s   outliers:                %-s %%
%s   disfavored:              %-s %%
%s   ca outliers:             %-s %%
%s Rotamer outliers:          %-s %%
%s C-beta deviations:         %-s %%
"""
        mso = None
        try:
            if self.geometry_restraints_manager is not None and False:
                # XXX False at the end is intentional, because currently I want to
                # disable this 'if' branch. Reason is - nothing from extended
                # model_statistics (with GRM) is being used, so no reason to spend
                # time calculating statistics over various restraints.
                mso = mmtbx.model.statistics.geometry(
                    pdb_hierarchy=self.pdb_hierarchy,
                    molprobity_scores=libtbx.env.has_module("probe"),
                    restraints_manager=self.geometry_restraints_manager)
            else:
                mso = mmtbx.model.statistics.geometry_no_grm(
                    pdb_hierarchy=self.pdb_hierarchy,
                    molprobity_scores=libtbx.env.has_module("probe"))
        except Exception:
            # some part of validation failed
            pass
        self.stats_evaluations.append(
            group_args(cc=group_args(cc_mask=self.five_cc.result.cc_mask,
                                     cc_volume=self.five_cc.result.cc_volume,
                                     cc_peaks=self.five_cc.result.cc_peaks),
                       geometry=mso,
                       rmsd_a=self.rmsd_a,
                       rmsd_b=self.rmsd_b))
        if mso is not None and self.five_cc is not None:
            print >> log, fmt % (
                # prefix, self.map_cc_whole_unit_cell,
                # prefix, self.map_cc_around_atoms,
                prefix,
                self.five_cc.cc_mask,
                prefix,
                self.five_cc.cc_volume,
                prefix,
                self.five_cc.cc_peaks,
                prefix,
                format_value("%-6.2f", self.rmsd_b).strip(),
                prefix,
                format_value("%-6.2f", self.rmsd_a).strip(),
                prefix,
                self.dist_from_start,
                prefix,
                self.dist_from_previous,
                prefix,
                format_value("%-6.2f", mso.clashscore),
                prefix,
                prefix,
                format_value("%-5.2f", mso.ramachandran_outliers),
                prefix,
                format_value("%-5.2f", mso.ramachandran_allowed),
                prefix,
                format_value("%-5.2f", mso.ramachandran_favored),
                prefix,
                prefix,
                format_value("%-5.2f", mso.cis_proline),
                prefix,
                format_value("%-5.2f", mso.twisted_proline),
                prefix,
                format_value("%-5.2f", mso.cis_general),
                prefix,
                format_value("%-5.2f", mso.twisted_general),
                prefix,
                prefix,
                format_value("%-5.2f", mso.cablam_outliers),
                prefix,
                format_value("%-5.2f", mso.cablam_disfavored),
                prefix,
                format_value("%-5.2f", mso.cablam_ca_outliers),
                prefix,
                format_value("%6.2f", mso.rotamer_outliers).strip(),
                prefix,
                format_value("%-5.2f", mso.c_beta_dev_percent))
Ejemplo n.º 48
0
def fv(fs, val):
    return str_utils.format_value(fs, val, replace_none_with="---")
Ejemplo n.º 49
0
def run(args, left_offset=0.1, right_offset=0.1, n_bins=10):
    need_help_msg = False
    if (len(args) == 0): need_help_msg = True
    else:
        for arg in args:
            if (str(arg).lower() in ["help", "-h", "--help", "--h", "h"]):
                need_help_msg = True
                break
    if (need_help_msg):
        print(help_message)
    #
    def get_value(x):
        result = None
        try:
            result = float(x[x.index("=") + 1:])
        except IndexError:
            pass
        except ValueError:
            pass
        return result

    d_min = None
    for arg in args:
        arg = str(arg).lower()
        try:
            d_min = float(arg)
        except ValueError:
            pass
        if (arg.count("left_offset")):
            x = get_value(arg)
            if (x is not None): left_offset = x
        if (arg.count("right_offset")):
            x = get_value(arg)
            if (x is not None): right_offset = x
        if (arg.count("n_bins")):
            x = int(get_value(arg))
            if (x is not None): n_bins = x
    dl, dr = [0, 1.e+6]
    if (d_min is not None):
        cmd = "phenix.r_factor_statistics %s left_offset=%s right_offset=%s n_bins=%s" % (
            format_value("%6.3f", d_min).strip(),
            format_value("%6.3f", left_offset).strip(),
            format_value("%6.3f", right_offset).strip(),
            format_value("%d", n_bins).strip())
        print("Command used:\n\n%s\n\n" % cmd)
        dl = d_min - left_offset
        dr = d_min + right_offset
    file = libtbx.env.find_in_repositories(
        relative_path="chem_data/polygon_data/all_mvd.pickle",
        test=os.path.isfile)
    database_dict = easy_pickle.load(file)
    r_work_pdb = database_dict["pdb_header_r_work"]
    r_free_pdb = database_dict["pdb_header_r_free"]
    d_min = database_dict["high_resolution"]
    sel = r_work_pdb != "none"
    sel &= r_free_pdb != "none"
    sel &= d_min != "none"
    #
    r_work_pdb = r_work_pdb.select(sel)
    r_free_pdb = r_free_pdb.select(sel)
    d_min = d_min.select(sel)

    #
    def str_to_float(x):
        tmp = flex.double()
        for x_ in x:
            tmp.append(float(x_))
        return tmp

    #
    d_min = str_to_float(d_min)
    r_work_pdb = str_to_float(r_work_pdb)
    r_free_pdb = str_to_float(r_free_pdb)
    diff = r_free_pdb - r_work_pdb
    #
    sel = d_min > dl
    sel &= d_min < dr
    sel &= diff > 0.
    sel &= diff < 0.1
    #
    r_work_pdb = r_work_pdb.select(sel)
    r_free_pdb = r_free_pdb.select(sel)
    d_min = d_min.select(sel)
    diff = diff.select(sel)
    #
    print("Histogram of Rwork for models in PDB at resolution %4.2f-%4.2f A:" %
          (dl, dr))
    show_histogram(data=r_work_pdb, n_slots=n_bins)
    print("Histogram of Rfree for models in PDB at resolution %4.2f-%4.2f A:" %
          (dl, dr))
    show_histogram(data=r_free_pdb, n_slots=n_bins)
    print(
        "Histogram of Rfree-Rwork for all model in PDB at resolution %4.2f-%4.2f A:"
        % (dl, dr))
    show_histogram(data=diff, n_slots=n_bins)
    print("Number of structures considered:", diff.size())
Ejemplo n.º 50
0
    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()
Ejemplo n.º 51
0
def run_cc(params, reindexing_op, output):
    uniform, selected_uniform, have_iso_ref = load_cc_data(
        params, reindexing_op, output)
    NBIN = params.output.n_bins

    if have_iso_ref:
        slope, offset, corr_iso, N_iso = correlation(selected_uniform[1],
                                                     selected_uniform[0],
                                                     params.include_negatives)
        print("C.C. iso is %.1f%% on %d indices" % (100 * corr_iso, N_iso),
              file=output)

    slope, offset, corr_int, N_int = correlation(selected_uniform[2],
                                                 selected_uniform[3],
                                                 params.include_negatives)
    print("C.C. int is %.1f%% on %d indices" % (100. * corr_int, N_int),
          file=output)

    if have_iso_ref:
        binned_cc_ref, binned_cc_ref_N = binned_correlation(
            selected_uniform[1], selected_uniform[0], params.include_negatives)
        #binned_cc_ref.show(f=output)

        ref_scale = scale_factor(selected_uniform[1],
                                 selected_uniform[0],
                                 weights=flex.pow(selected_uniform[1].sigmas(),
                                                  -2),
                                 use_binning=True)
        #ref_scale.show(f=output)

        ref_riso = r1_factor(selected_uniform[1],
                             selected_uniform[0],
                             scale_factor=ref_scale,
                             use_binning=True)
        #ref_riso.show(f=output)

        ref_scale_all = scale_factor(selected_uniform[1],
                                     selected_uniform[0],
                                     weights=flex.pow(
                                         selected_uniform[1].sigmas(), -2))

        ref_riso_all = r1_factor(selected_uniform[1],
                                 selected_uniform[0],
                                 scale_factor=ref_scale_all)

    binned_cc_int, binned_cc_int_N = binned_correlation(
        selected_uniform[2], selected_uniform[3], params.include_negatives)
    #binned_cc_int.show(f=output)

    oe_scale = scale_factor(
        selected_uniform[2],
        selected_uniform[3],
        weights=flex.pow(selected_uniform[2].sigmas(), -2) +
        flex.pow(selected_uniform[3].sigmas(), -2),
        use_binning=True)
    #oe_scale.show(f=output)

    oe_rint = r1_factor(selected_uniform[2],
                        selected_uniform[3],
                        scale_factor=oe_scale,
                        use_binning=True)
    #oe_rint.show(f=output)

    oe_rsplit = r_split(selected_uniform[2],
                        selected_uniform[3],
                        use_binning=True)

    oe_scale_all = scale_factor(
        selected_uniform[2],
        selected_uniform[3],
        weights=flex.pow(selected_uniform[2].sigmas(), -2) +
        flex.pow(selected_uniform[3].sigmas(), -2),
    )

    oe_rint_all = r1_factor(selected_uniform[2],
                            selected_uniform[3],
                            scale_factor=oe_scale_all)
    oe_rsplit_all = r_split(selected_uniform[2], selected_uniform[3])
    if have_iso_ref:
        print("R factors Riso = %.1f%%, Rint = %.1f%%" %
              (100. * ref_riso_all, 100. * oe_rint_all),
              file=output)
    else:
        print("R factor Rint = %.1f%%" % (100. * oe_rint_all), file=output)

    split_sigma_data = split_sigma_test(selected_uniform[2],
                                        selected_uniform[3],
                                        scale=oe_scale,
                                        use_binning=True,
                                        show_plot=False)
    split_sigma_data_all = split_sigma_test(selected_uniform[2],
                                            selected_uniform[3],
                                            scale=oe_scale_all,
                                            use_binning=False,
                                            show_plot=False)

    print(file=output)
    if reindexing_op == "h,k,l":
        print("Table of Scaling Results:", file=output)
    else:
        print("Table of Scaling Results Reindexing as %s:" % reindexing_op,
              file=output)

    from libtbx import table_utils
    table_header = [
        "", "", "", "CC", " N", "CC", " N", "R", "R", "R", "Scale", "Scale",
        "SpSig"
    ]
    table_header2 = [
        "Bin", "Resolution Range", "Completeness", "int", "int", "iso", "iso",
        "int", "split", "iso", "int", "iso", "Test"
    ]
    table_data = []
    table_data.append(table_header)
    table_data.append(table_header2)

    items = binned_cc_int.binner.range_used()

    # XXX Make it clear what the completeness here actually is!
    cumulative_counts_given = 0
    cumulative_counts_complete = 0
    for bin in items:
        table_row = []
        table_row.append("%3d" % bin)
        table_row.append("%-13s" %
                         binned_cc_int.binner.bin_legend(i_bin=bin,
                                                         show_bin_number=False,
                                                         show_bin_range=False,
                                                         show_d_range=True,
                                                         show_counts=False))
        table_row.append("%13s" %
                         binned_cc_int.binner.bin_legend(i_bin=bin,
                                                         show_bin_number=False,
                                                         show_bin_range=False,
                                                         show_d_range=False,
                                                         show_counts=True))
        cumulative_counts_given += binned_cc_int.binner._counts_given[bin]
        cumulative_counts_complete += binned_cc_int.binner._counts_complete[
            bin]
        table_row.append("%.1f%%" % (100. * binned_cc_int.data[bin]))
        table_row.append("%7d" % (binned_cc_int_N.data[bin]))

        if have_iso_ref and binned_cc_ref.data[bin] is not None:
            table_row.append("%.1f%%" % (100 * binned_cc_ref.data[bin]))
        else:
            table_row.append("--")

        if have_iso_ref and binned_cc_ref_N.data[bin] is not None:
            table_row.append("%6d" % (binned_cc_ref_N.data[bin]))
        else:
            table_row.append("--")

        if oe_rint.data[bin] is not None:
            table_row.append("%.1f%%" % (100. * oe_rint.data[bin]))
        else:
            table_row.append("--")

        if oe_rsplit.data[bin] is not None:
            table_row.append("%.1f%%" % (100 * oe_rsplit.data[bin]))
        else:
            table_row.append("--")

        if have_iso_ref and ref_riso.data[bin] is not None:
            table_row.append("%.1f%%" % (100 * ref_riso.data[bin]))
        else:
            table_row.append("--")

        if oe_scale.data[bin] is not None:
            table_row.append("%.3f" % oe_scale.data[bin])
        else:
            table_row.append("--")

        if have_iso_ref and ref_scale.data[bin] is not None:
            table_row.append("%.3f" % ref_scale.data[bin])
        else:
            table_row.append("--")

        if split_sigma_data.data[bin] is not None:
            table_row.append("%.4f" % split_sigma_data.data[bin])
        else:
            table_row.append("--")

        table_data.append(table_row)
    table_data.append([""] * len(table_header))

    table_row = [
        format_value("%3s", "All"),
        format_value("%-13s", "                 "),
        format_value(
            "%13s",
            "[%d/%d]" % (cumulative_counts_given, cumulative_counts_complete)),
        format_value("%.1f%%", 100 * corr_int),
        format_value("%7d", N_int)
    ]

    if have_iso_ref:
        table_row.extend(
            (format_value("%.1f%%",
                          100 * corr_iso), format_value("%6d", N_iso)))
    else:
        table_row.extend(("--", "--"))

    table_row.extend((format_value("%.1f%%", 100 * oe_rint_all),
                      format_value("%.1f%%", 100 * oe_rsplit_all)))
    if have_iso_ref:
        table_row.append(format_value("%.1f%%", 100 * ref_riso_all))
    else:
        table_row.append("--")

    table_row.append(format_value("%.3f", oe_scale_all))
    if have_iso_ref:
        table_row.append(format_value("%.3f", ref_scale_all))
    else:
        table_row.append("--")

    if split_sigma_data_all is not None:
        table_row.append("%.1f" % split_sigma_data_all)
    else:
        table_row.append("--")

    table_data.append(table_row)

    print(file=output)
    print(table_utils.format(table_data,
                             has_header=2,
                             justify='center',
                             delim=" "),
          file=output)
    print(
        """CCint is the CC-1/2 defined by Diederichs; correlation between odd/even images.
  Similarly, Scale int and R int are the scaling factor and scaling R factor between odd/even images.
  "iso" columns compare the whole XFEL dataset to the isomorphous reference.""",
        file=output)

    print("""Niso: result vs. reference common set""", end=' ', file=output)
    if params.include_negatives:
        print(
            """including negative merged intensities (set by phil parameter).""",
            file=output)
    elif params.scaling.log_cutoff is None:
        print(file=output)
    else:
        print("""with intensites < %7.2g filtered out (controlled by
    scaling.log_cutoff phil parameter set to %5.1f)""" %
              (math.exp(params.scaling.log_cutoff), params.scaling.log_cutoff),
              file=output)

    if have_iso_ref:
        assert N_iso == flex.sum(
            flex.double([x for x in binned_cc_ref_N.data if x is not None]))
    assert N_int == flex.sum(
        flex.double([x for x in binned_cc_int_N.data if x is not None]))

    if params.scaling.show_plots:
        from matplotlib import pyplot as plt
        plt.plot(flex.log(selected_uniform[-2].data()),
                 flex.log(selected_uniform[-1].data()), 'r.')
        plt.show()
        if have_iso_ref:
            plt.plot(flex.log(selected_uniform[0].data()),
                     flex.log(selected_uniform[1].data()), 'r.')
            plt.show()
    print(file=output)