def _thing_vs_dose_shells_str(self, title, thing, value_bins, values): column_labels = ( ["Dose"] + [ "%.2f-%.2f(A)" % self.binner.bin_d_range(i + 1) for i in range(self.n_bins) ] + [thing] ) column_formats = ["%8.1f"] + ["%7.4f" for i in range(self.n_bins + 1)] graph_names = [thing, thing + ", in resolution shells"] graph_columns = [[0, self.n_bins + 1], list(range(self.n_bins + 1))] table = table_data( title=title, column_labels=column_labels, column_formats=column_formats, graph_names=graph_names, graph_columns=graph_columns, ) for i in range(self.n_steps): row = ( [i * self.range_width + self.range_min] + [value_bins[j, i] for j in range(self.binner.n_bins_used())] + [values[i]] ) table.add_row(row) return table.format_loggraph()
def exercise_logfile(): log_file = libtbx.env.find_in_repositories( relative_path="phenix_regression/tracking/scala.log", test=os.path.isfile) if log_file is not None: tables = data_plots.import_ccp4i_logfile(log_file) assert ([t.title for t in tables] == [ '>>> Scales v rotation range, Unspecified ', 'Analysis against Batch, Unspecified ', 'Analysis against resolution , Unspecified ', 'Analysis against intensity, Unspecified ', 'Completeness, multiplicity, Rmeas v. resolution, Unspecified ', 'Correlations within dataset, Unspecified ', 'Axial reflections, axis h, Unspecified ', 'Axial reflections, axis k, Unspecified ', 'Axial reflections, axis l, Unspecified ', 'Run 1, standard deviation v. Intensity, Unspecified ' ]) loggraph3 = """\ $TABLE: Matthews coefficients: $GRAPHS: Protein crystal computed at resolution of 2.450 :A:1,2,3,4 $$ Nmol/asym Matthews_Coeff sovlent_frac P(2.450) $$ $$ 1 3.13 0.61 0.99 2 1.56 0.21 0.01 $$ """ t3 = data_plots.table_data(None) t3.import_loggraph(loggraph3) g3 = t3.get_graph("Protein crystal computed at resolution of 2.450") p3 = g3.get_plots()
def exercise_logfile () : log_file = libtbx.env.find_in_repositories( relative_path="phenix_regression/tracking/scala.log", test=os.path.isfile) if log_file is not None : tables = data_plots.import_ccp4i_logfile(log_file) assert ([ t.title for t in tables ] == ['>>> Scales v rotation range, Unspecified ', 'Analysis against Batch, Unspecified ', 'Analysis against resolution , Unspecified ', 'Analysis against intensity, Unspecified ', 'Completeness, multiplicity, Rmeas v. resolution, Unspecified ', 'Correlations within dataset, Unspecified ', 'Axial reflections, axis h, Unspecified ', 'Axial reflections, axis k, Unspecified ', 'Axial reflections, axis l, Unspecified ', 'Run 1, standard deviation v. Intensity, Unspecified ']) loggraph3 = """\ $TABLE: Matthews coefficients: $GRAPHS: Protein crystal computed at resolution of 2.450 :A:1,2,3,4 $$ Nmol/asym Matthews_Coeff sovlent_frac P(2.450) $$ $$ 1 3.13 0.61 0.99 2 1.56 0.21 0.01 $$ """ t3 = data_plots.table_data(None) t3.import_loggraph(loggraph3) g3 = t3.get_graph("Protein crystal computed at resolution of 2.450") p3 = g3.get_plots()
def display_file_info(file_name, parent=None): from iotbx import reflection_file_editor from iotbx import file_reader from iotbx import data_plots hkl_in = file_reader.any_file(file_name, force_type="hkl") hkl_in.check_file_type("hkl") labels = [] tables = [] stats = [] arrays_and_flags = hkl_in.file_server.get_r_free_flags( file_name=hkl_in.file_name, label=None, test_flag_value=None, disable_suitability_test=False, parameter_scope=None, return_all_valid_arrays=True, ) for array, test_flag_value in arrays_and_flags: labels.append(array.info().label_string()) (n_bins, n_free, sse, accu) = reflection_file_editor.get_r_free_stats( miller_array=array, test_flag_value=test_flag_value ) table = data_plots.table_data( title="Distribution of R-free test set", column_labels=["Reflection #", "Fraction counted"], graph_names=["Fraction free vs. resolution"], graph_labels=[["Reflection #", "ntest/total"]], graph_columns=[[0, 1]], data=[accu.reflection_counts, accu.free_fractions], ) tables.append(table) stats.append( group_args( n_free=n_free, n_all=array.indices().size(), percent_free=n_free / array.indices().size(), completeness=array.completeness(), ) ) if len(labels) == 0: raise Sorry("No recognizable R-free flags found in this file.") frame = wx.Frame(parent, -1, "R-free flags info", style=wx.DEFAULT_FRAME_STYLE) szr = wx.BoxSizer(wx.VERTICAL) frame.SetSizer(szr) panel = RfreeInspector(frame, -1) panel.set_data( file_name=file_name, labels=labels, tables=tables, stats=stats, flags_and_values=[(a.data(), f) for (a, f) in arrays_and_flags], ) szr.Add(panel, 1, wx.ALL | wx.EXPAND) szr.Fit(panel) frame.Fit() frame.Show()
def completeness_vs_dose_str(self): anomalous = self.intensities.anomalous_flag() title = "Completeness vs. dose:" graph_names = ["Completeness", "Completeness in resolution shells"] if anomalous: column_labels = (["Dose"] + [ "%.2f-%.2f(A)" % self.binner.bin_d_range(i + 1) for i in range(self.n_bins) ] + ["I+", "I-", "I", "dI"]) column_formats = (["%8.1f"] + ["%5.3f" for i in range(self.n_bins)] + ["%5.3f", "%5.3f", "%5.3f", "%5.3f"]) # graph_columns = [[0,1,2,3,4]] graph_columns = [ [0] + list(range(self.n_bins + 1, self.n_bins + 5)), list(range(self.n_bins + 1)), ] else: column_labels = (["Dose"] + [ "%.2f-%.2f(A)" % self.binner.bin_d_range(i + 1) for i in range(self.n_bins) ] + ["I"]) column_formats = (["%8.1f"] + ["%5.3f" for i in range(self.n_bins)] + ["%5.3f"]) graph_columns = [[0, self.n_bins + 1], list(range(self.n_bins + 1))] table_completeness = table_data( title=title, column_labels=column_labels, column_formats=column_formats, graph_names=graph_names, graph_columns=graph_columns, ) for i in range(self.n_steps): if anomalous: row = ([i * self.range_width + self.range_min] + [ self.ieither_comp_bins[i_bin, i] for i_bin in range(self.n_bins) ] + [ self.iplus_comp_overall[i], self.iminus_comp_overall[i], self.ieither_comp_overall[i], self.iboth_comp_overall[i], ]) else: row = ([i * self.range_width + self.range_min] + [ self.ieither_comp_bins[i_bin, i] for i_bin in range(self.n_bins) ] + [self.ieither_comp_overall[i]]) table_completeness.add_row(row) return table_completeness.format_loggraph()
def exercise_column_formats(): t = data_plots.table_data( title="Resolution shell statistics", column_labels=["1/resol^2", "Nrefl", "R-free", "FOM"], column_formats=["%.2g", "%i", "%.2f", "%.2f"], data=[[0.02, 0.04, 0.06, 0.08, 0.10], [2004, 2084, None, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, float('NaN'), 0.75, None]]) assert t.format() == """\
def display_file_info(file_name, parent=None): from iotbx import reflection_file_editor from iotbx import file_reader from iotbx import data_plots hkl_in = file_reader.any_file(file_name, force_type="hkl") hkl_in.check_file_type("hkl") labels = [] tables = [] stats = [] arrays_and_flags = hkl_in.file_server.get_r_free_flags( file_name=hkl_in.file_name, label=None, test_flag_value=None, disable_suitability_test=False, parameter_scope=None, return_all_valid_arrays=True) for array, test_flag_value in arrays_and_flags: labels.append(array.info().label_string()) (n_bins, n_free, sse, accu) = reflection_file_editor.get_r_free_stats( miller_array=array, test_flag_value=test_flag_value) table = data_plots.table_data( title="Distribution of R-free test set", column_labels=["Reflection #", "Fraction counted"], graph_names=["Fraction free vs. resolution"], graph_labels=[["Reflection #", "ntest/total"]], graph_columns=[[0, 1]], data=[accu.reflection_counts, accu.free_fractions]) tables.append(table) stats.append( group_args(n_free=n_free, n_all=array.indices().size(), percent_free=n_free / array.indices().size(), completeness=array.completeness())) if (len(labels) == 0): raise Sorry("No recognizable R-free flags found in this file.") frame = wx.Frame(parent, -1, "R-free flags info", style=wx.DEFAULT_FRAME_STYLE) szr = wx.BoxSizer(wx.VERTICAL) frame.SetSizer(szr) panel = RfreeInspector(frame, -1) panel.set_data(file_name=file_name, labels=labels, tables=tables, stats=stats, flags_and_values=[(a.data(), f) for (a, f) in arrays_and_flags]) szr.Add(panel, 1, wx.ALL | wx.EXPAND) szr.Fit(panel) frame.Fit() frame.Show()
def __init__(self, all_curves, level=6.0, all_bad_z_scores=False): self.table = data_plots.table_data( title="Relative Wilson plot", column_labels=[ "Max. resolution", "log(I_exp/I_obs)", "Reference curve", "Z-score" ], graph_names=["Relative Wilson plot"], graph_labels=[("High resolution", "")], graph_columns=[list(range(4))], x_is_inverse_d_min=True, data=[list(array) for array in all_curves]) self.cutoff = level self.all_bad_z_scores = all_bad_z_scores
def __init__ (self, all_curves, level=6.0, all_bad_z_scores=False) : self.table = data_plots.table_data( title="Relative Wilson plot", column_labels=["Max. resolution", "log(I_exp/I_obs)", "Reference curve", "Z-score"], graph_names=["Relative Wilson plot"], graph_labels=[("High resolution", "")], graph_columns=[list(range(4))], x_is_inverse_d_min=True, data=[ list(array) for array in all_curves ]) self.cutoff = level self.all_bad_z_scores = all_bad_z_scores
def cc_anom_table (self) : column_labels = ["1/d**2", "CC(anom)"] graph_columns = [[0,1]] graph_names = ["CC(anom)"] table = data_plots.table_data( title="Half-dataset anomalous correlation", column_labels=["1/d**2", "CC(anom)"], column_formats=["%6.2f", "%5.3f"], graph_names=["CC(anom)"], graph_columns=[[0,1]], x_is_inverse_d_min=True, force_exact_x_labels=True) for bin in self.bins : data = bin.table_data() table.add_row([ (1/bin.d_min**2), bin.anom_half_corr ]) return table
def cc_anom_table(self): column_labels = ["d_min", "CC(anom)"] graph_columns = [[0, 1]] graph_names = ["CC(anom)"] table = data_plots.table_data( title="Half-dataset anomalous correlation", column_labels=column_labels, column_formats=["%6.2f", "%5.3f"], graph_names=graph_names, graph_columns=graph_columns, x_is_inverse_d_min=True, force_exact_x_labels=True) for bin in self.bins: data = bin.table_data() table.add_row([(1 / bin.d_min**2), bin.cc_anom]) return table
def quality_table (self) : column_labels = ["1/d**2", "R-merge", "R-meas", "R-pim", "CC1/2", "CC(anom)"] graph_columns = [[0,1,2,3],[0,4],[0,5]] graph_names = ["R-factors", "CC1/2", "CC(anom)"] table = data_plots.table_data( title="Statistics for dataset consistency", column_labels=column_labels, column_formats=["%6.2f","%5.3f", "%5.3f", "%5.3f", "%5.3f", "%5.3f"], graph_names=graph_names, graph_columns=graph_columns, x_is_inverse_d_min=True, force_exact_x_labels=True) for bin in self.bins : data = bin.table_data() table.add_row([ data[0] ] + data[7:12]) return table
def quality_table(self): column_labels = ["1/d**2", "R-merge", "R-meas", "R-pim", "CC1/2", "CC(anom)"] graph_columns = [[0,1,2,3],[0,4],[0,5]] graph_names = ["R-factors", "CC1/2", "CC(anom)"] table = data_plots.table_data( title="Statistics for dataset consistency", column_labels=column_labels, column_formats=["%6.2f","%5.3f", "%5.3f", "%5.3f", "%5.3f", "%5.3f"], graph_names=graph_names, graph_columns=graph_columns, x_is_inverse_d_min=True, force_exact_x_labels=True) for bin in self.bins : data = bin.table_data() table.add_row([ data[0] ] + data[7:11] + [ data[-1] ]) return table
def print_rd_vs_dose(self): title = "R vs. BATCH difference:" column_labels = ["BATCH", "Rd"] column_formats = ["%8.1f", "%5.3f"] graph_names = ["Rd"] graph_columns = [[0,1]] table_rd = table_data(title=title, column_labels=column_labels, column_formats=column_formats, graph_names=graph_names, graph_columns=graph_columns) for i in xrange(self.n_steps): row = [i * self.range_width + self.range_min, self.rd[i]] table_rd.add_row(row) print table_rd.format_loggraph()
def signal_table (self) : column_labels = ["1/d**2","N(obs)","N(unique)","Redundancy","Completeness", "Mean(I)", "Mean(I/sigma)", ] graph_names = ["Reflection counts", "Redundancy", "Completeness", "Mean(I)", "Mean(I/sigma)",] graph_columns = [[0,1,2],[0,3],[0,4],[0,5],[0,6],] table = data_plots.table_data( title="Statistics for redundancy, completeness, and signal", column_labels=column_labels, graph_names=graph_names, graph_columns=graph_columns, column_formats=["%6.2f","%6d","%6d","%5.2f","%6.2f","%8.1f","%6.1f"], x_is_inverse_d_min=True, force_exact_x_labels=True) for bin in self.bins : data = bin.table_data() table.add_row(data[0:7]) return table
def signal_table(self): column_labels = ["1/d**2","N(obs)","N(unique)","Redundancy","Completeness", "Mean(I)", "Mean(I/sigma)", ] graph_names = ["Reflection counts", "Redundancy", "Completeness", "Mean(I)", "Mean(I/sigma)",] graph_columns = [[0,1,2],[0,3],[0,4],[0,5],[0,6],] table = data_plots.table_data( title="Statistics for redundancy, completeness, and signal", column_labels=column_labels, graph_names=graph_names, graph_columns=graph_columns, column_formats=["%6.2f","%6d","%6d","%5.2f","%6.2f","%8.1f","%6.1f"], x_is_inverse_d_min=True, force_exact_x_labels=True) for bin in self.bins : data = bin.table_data() table.add_row(data[0:7]) return table
def __init__(self, crystal_symmetry, n_residues=None, n_bases=None, out=None): from iotbx import data_plots self.n_residues_in = n_residues self.n_bases_in = n_bases best_guess_is_n_residues = False if (n_residues is None) and (n_bases is None): n_residues = 1 n_bases = 0 best_guess_is_n_residues = True vm_estimator = p_vm_calculator(crystal_symmetry, n_residues, n_bases, out=out) if (best_guess_is_n_residues): self.n_copies = 1 self.n_residues = int(vm_estimator.best_guess) self.n_bases = 0 else: self.n_copies = int(vm_estimator.best_guess) self.n_residues = vm_estimator.n_residues self.n_bases = vm_estimator.n_bases self.solvent_content = vm_estimator.vm_prop[vm_estimator.best_guess - 1][1] self.table = data_plots.table_data( title="Solvent content analysis", column_labels=[ "Copies", "Solvent content", "Matthews coeff.", "P(solvent content)" ], column_formats=["%d", "%.3f", "%.2f", "%.3f"], graph_names=["Solvent content", "Matthews coeff."], graph_columns=[[0, 1], [0, 2]]) self.n_possible_contents = 0 for ii in range(len(vm_estimator.vm_prop)): self.n_possible_contents += 1 row = [] for jj in range(len(vm_estimator.vm_prop[ii])): if (jj == 0): row.append(int(vm_estimator.vm_prop[ii][jj])) else: row.append(vm_estimator.vm_prop[ii][jj]) self.table.add_row(row)
def print_completeness_vs_dose(self): anomalous = self.intensities.anomalous_flag() title = "Completeness vs. dose:" graph_names = ["Completeness", "Completeness in resolution shells"] if anomalous: column_labels = ["Dose"] + ["%.2f-%.2f(A)" %self.binner.bin_d_range(i+1) for i in range(self.n_bins)] + \ ['I+', 'I-', 'I', 'dI'] column_formats = ["%8.1f"] + [ "%5.3f" for i in range(self.n_bins) ] + ["%5.3f", "%5.3f", "%5.3f", "%5.3f"] #graph_columns = [[0,1,2,3,4]] graph_columns = [[0] + range(self.n_bins + 1, self.n_bins + 5), range(self.n_bins + 1)] else: column_labels = ["Dose"] + [ "%.2f-%.2f(A)" % self.binner.bin_d_range(i + 1) for i in range(self.n_bins) ] + ["I"] column_formats = ["%8.1f"] + ["%5.3f" for i in range(self.n_bins) ] + ["%5.3f"] graph_columns = [[0, self.n_bins + 1], range(self.n_bins + 1)] table_completeness = table_data(title=title, column_labels=column_labels, column_formats=column_formats, graph_names=graph_names, graph_columns=graph_columns) for i in xrange(self.n_steps): if anomalous: row = [i * self.range_width + self.range_min] \ + [self.ieither_comp_bins[i_bin, i] for i_bin in range(self.n_bins)] \ + [self.iplus_comp_overall[i], self.iminus_comp_overall[i], self.ieither_comp_overall[i], self.iboth_comp_overall[i]] else: row = [i * self.range_width + self.range_min] \ + [self.ieither_comp_bins[i_bin, i] for i_bin in range(self.n_bins)] \ + [self.ieither_comp_overall[i]] table_completeness.add_row(row) print(table_completeness.format_loggraph())
def print_scp_vs_dose(self): title = "Normalised radiation damage analysis:" column_labels = ["Dose"] + ["%.2f-%.2f(A)" %self.binner.bin_d_range(i+1) for i in range(self.n_bins)] + ["Rcp(d)"] column_formats = ["%8.1f"] + ["%7.4f" for i in range(self.n_bins+1)] graph_names = ["Scp(d)", "Scp(d), in resolution shells"] graph_columns = [[0, self.n_bins+1], range(self.n_bins+1)] table_scp = table_data(title=title, column_labels=column_labels, column_formats=column_formats, graph_names=graph_names, graph_columns=graph_columns) for i in xrange(self.n_steps): row = [i * self.range_width + self.range_min] \ + [self.scp_bins[j, i] for j in xrange(self.binner.n_bins_used())] + [self.scp[i]] table_scp.add_row(row) print table_scp.format_loggraph()
def export_bins_table_data(bins, title="Statistics by resolution bin"): from iotbx import data_plots table_stats = [ "r_work", "r_free", "completeness", "fom_work", "pher_free", "scale_k1_work" ] labels = [ "Resolution", "R-work", "R-free", "Completeness", "FOM", "Phase error", "Scale factor" ] graph_names = [ "R-work/R-free vs. resolution", "Completeness vs. resolution", "Figure of merit vs. resolution", "Phase error vs. resolution", "Scale factor vs. resolution" ] graph_columns = [[0, 1, 2], [0, 3], [0, 4], [0, 5], [0, 6]] if hasattr(bins[0], "cc_work") and (bins[0].cc_work is not None): table_stats.insert(2, "cc_work") table_stats.insert(3, "cc_free") labels.insert(3, "CC(work)") labels.insert(4, "CC(free)") graph_columns = [[0, 1, 2], [0, 3, 4], [0, 5], [0, 6], [0, 7], [0, 8]] graph_names.insert(1, "CC-work/CC-free vs. resolution") data_rows = [] for bin in bins: bin_stats = [] (min_res_str, max_res_str) = re.sub("\s*", "", bin.d_range).split("-") (min_res, max_res) = (string.atof(min_res_str), string.atof(max_res_str)) bin_stats.append(1 / (max_res**2)) for stat_attr_name in table_stats: bin_stats.append(getattr(bin, stat_attr_name)) data_rows.append(bin_stats) data = [[row[i] for row in data_rows] for i in range(len(data_rows[0]))] t = data_plots.table_data(title=title, column_labels=labels, graph_names=graph_names, graph_columns=graph_columns, data=data, x_is_inverse_d_min=True) return t
def print_completeness_vs_dose(self): anomalous = self.intensities.anomalous_flag() title = "Completeness vs. dose:" graph_names = ["Completeness", "Completeness in resolution shells"] if anomalous: column_labels = ["Dose"] + ["%.2f-%.2f(A)" %self.binner.bin_d_range(i+1) for i in range(self.n_bins)] + \ ['I+', 'I-', 'I', 'dI'] column_formats = ["%8.1f"] + ["%5.3f" for i in range(self.n_bins)] + ["%5.3f", "%5.3f", "%5.3f", "%5.3f"] #graph_columns = [[0,1,2,3,4]] graph_columns = [[0] + range(self.n_bins+1, self.n_bins+5), range(self.n_bins+1)] else: column_labels = ["Dose"] + ["%.2f-%.2f(A)" %self.binner.bin_d_range(i+1) for i in range(self.n_bins)] + ["I"] column_formats = ["%8.1f"] + ["%5.3f" for i in range(self.n_bins)] + [ "%5.3f"] graph_columns = [[0, self.n_bins+1], range(self.n_bins+1)] table_completeness = table_data(title=title, column_labels=column_labels, column_formats=column_formats, graph_names=graph_names, graph_columns=graph_columns) for i in xrange(self.n_steps): if anomalous: row = [i * self.range_width + self.range_min] \ + [self.ieither_comp_bins[i_bin, i] for i_bin in range(self.n_bins)] \ + [self.iplus_comp_overall[i], self.iminus_comp_overall[i], self.ieither_comp_overall[i], self.iboth_comp_overall[i]] else: row = [i * self.range_width + self.range_min] \ + [self.ieither_comp_bins[i_bin, i] for i_bin in range(self.n_bins)] \ + [self.ieither_comp_overall[i]] table_completeness.add_row(row) print table_completeness.format_loggraph()
def export_bins_table_data (bins, title="Statistics by resolution bin") : from iotbx import data_plots table_stats = ["r_work", "r_free", "completeness", "fom_work", "pher_free", "scale_k1_work"] labels = ["Resolution", "R-work", "R-free", "Completeness", "FOM", "Phase error", "Scale factor"] graph_names = ["R-work/R-free vs. resolution", "Completeness vs. resolution", "Figure of merit vs. resolution", "Phase error vs. resolution", "Scale factor vs. resolution"] graph_columns = [[0,1,2], [0,3], [0,4], [0,5], [0,6]] if hasattr(bins[0], "cc_work") and (bins[0].cc_work is not None) : table_stats.insert(2, "cc_work") table_stats.insert(3, "cc_free") labels.insert(3, "CC(work)") labels.insert(4, "CC(free)") graph_columns = [ [0,1,2], [0,3,4], [0,5], [0,6], [0,7], [0,8] ] graph_names.insert(1, "CC-work/CC-free vs. resolution") data_rows = [] for bin in bins : bin_stats = [] (min_res_str, max_res_str) = re.sub("\s*", "", bin.d_range).split("-") (min_res, max_res) = (string.atof(min_res_str), string.atof(max_res_str)) bin_stats.append(1 / (max_res ** 2)) for stat_attr_name in table_stats : bin_stats.append(getattr(bin, stat_attr_name)) data_rows.append(bin_stats) data = [[row[i] for row in data_rows] for i in xrange(len(data_rows[0]))] t = data_plots.table_data( title=title, column_labels=labels, graph_names=graph_names, graph_columns=graph_columns, data=data, x_is_inverse_d_min=True) return t
def __init__ (self, crystal_symmetry, n_residues=None, n_bases=None) : from iotbx import data_plots self.n_residues_in = n_residues self.n_bases_in = n_bases best_guess_is_n_residues = False if (n_residues is None) and (n_bases is None) : n_residues = 1 n_bases = 0 best_guess_is_n_residues = True vm_estimator = p_vm_calculator(crystal_symmetry, n_residues, n_bases) if (best_guess_is_n_residues) : self.n_copies = 1 self.n_residues = int(vm_estimator.best_guess) self.n_bases = 0 else : self.n_copies = int(vm_estimator.best_guess) self.n_residues = vm_estimator.n_residues self.n_bases = vm_estimator.n_bases self.solvent_content = vm_estimator.vm_prop[vm_estimator.best_guess-1][1] self.table = data_plots.table_data( title="Solvent content analysis", column_labels=["Copies", "Solvent content", "Matthews coeff.", "P(solvent content)"], column_formats=["%d","%.3f", "%.2f", "%.3f"], graph_names=["Solvent content", "Matthews coeff."], graph_columns=[[0,1], [0,2]]) self.n_possible_contents = 0 for ii in range( len(vm_estimator.vm_prop) ): self.n_possible_contents += 1 row = [] for jj in range(len(vm_estimator.vm_prop[ii])) : if (jj == 0) : row.append(int(vm_estimator.vm_prop[ii][jj])) else : row.append(vm_estimator.vm_prop[ii][jj]) self.table.add_row(row)
def rcp_vs_dose_str(self): title = "Cumulative radiation damage analysis:" column_labels = (["Dose"] + [ "%.2f-%.2f(A)" % self.binner.bin_d_range(i + 1) for i in range(self.n_bins) ] + ["Rcp(d)"]) column_formats = ["%8.1f"] + ["%7.4f" for i in range(self.n_bins + 1)] graph_names = ["Rcp(d)", "Rcp(d), in resolution shells"] graph_columns = [[0, self.n_bins + 1], list(range(self.n_bins + 1))] table_rcp = table_data( title=title, column_labels=column_labels, column_formats=column_formats, graph_names=graph_names, graph_columns=graph_columns, ) for i in range(self.n_steps): row = ([i * self.range_width + self.range_min] + [ self.rcp_bins[j, i] for j in range(self.binner.n_bins_used()) ] + [self.rcp[i]]) table_rcp.add_row(row) return table_rcp.format_loggraph()
def show_overall_observations(Fit_I,Fit_I_stddev,I_visited,ordered,sim, out = None,title = None,work_params = None): # at minimum we need the Miller set of merged intensities and sigmas # assert len(ordered.indices())==len(Fit_I) # have to assert this because the "ordered" indices may not in fact be ordered. # but can not assert this in the test1.py test suite. model_subset = ordered[0:len(Fit_I)] uc = ordered.unit_cell() model_subset.crystal_symmetry().show_summary() if work_params is not None: d_min = work_params.d_min d_max = work_params.d_max n_bins = work_params.output.n_bins else: d_min = flex.min(uc.d(model_subset.indices())) # extent of data d_max = None n_bins = min( len(Fit_I)//20, 15 ) #obs, redundancy, summed_wt_I, summed_weight, ISIGI, n_bins=15, out=None, title=None, work_params=None): if out is None: out = sys.stdout model_subset.setup_binner(d_max=(d_max or 100000), d_min=d_min, n_bins=n_bins) result = [] multiplicity = flex.int(len(Fit_I)) for iraw in xrange(len(sim.miller)): multiplicity[sim.miller[iraw]] += 1 cumulative_unique = 0 cumulative_meas = 0 cumulative_theor = 0 cumulative_In = 0 cumulative_I = 0.0 cumulative_Isigma = 0.0 frame_worker = n_frames_worker(obs_arrays=sim, unique_set=model_subset, d_max=(d_max or 100000),d_min=d_min,n_bins=n_bins) for i_bin in model_subset.binner().range_used(): sel_w = model_subset.binner().selection(i_bin) sel_fo_all = model_subset.select(sel_w) d_range = model_subset.binner().bin_legend( i_bin=i_bin, show_bin_number=False, show_counts=False) sel_multiplicity = multiplicity.select(sel_w) sel_absent = sel_multiplicity.count(0) n_present = sel_multiplicity.size() - sel_absent sel_complete_tag = "[%d/%d]" % (n_present, sel_multiplicity.size()) sel_measurements = flex.sum(sel_multiplicity) # Alternatively, redundancy (or multiplicity) is calculated as the # average number of observations for the observed # reflections--missing reflections do not affect the redundancy # adversely, and the reported value becomes # completeness-independent. val_multiplicity_obs = 0 if n_present > 0: val_multiplicity_obs = flex.sum(sel_multiplicity) / n_present sel_frames = frame_worker.per_bin_frames(i_bin) # Per-bin sum of I and I/sig(I). For any reflection, the weight # of the merged intensity must be positive for this to make sense. sel_o = (sel_w & (Fit_I_stddev > 0.)) selected_intensity = Fit_I.select(sel_o) selected_stddev = Fit_I_stddev.select(sel_o) I_sum = flex.sum(selected_intensity) assert selected_stddev.count(0.) == 0 I_sigI_sum = flex.sum(selected_intensity / selected_stddev) I_n = sel_o.count(True) assert sel_measurements == frame_worker.per_bin_meas(i_bin) if sel_measurements > 0: mean_I = mean_I_sigI = 0 if I_n > 0: mean_I = I_sum / I_n mean_I_sigI = I_sigI_sum / I_n bin = resolution_bin( i_bin=i_bin, d_range=d_range, d_min=model_subset.binner().bin_d_min(i_bin), redundancy_asu=flex.mean(sel_multiplicity.as_double()), redundancy_obs=val_multiplicity_obs, frames=sel_frames, complete_tag=sel_complete_tag, completeness=n_present / sel_multiplicity.size(), measurements=sel_measurements, negative=frame_worker.per_bin_neg(i_bin), percent_neg=100.*frame_worker.per_bin_neg(i_bin)/frame_worker.per_bin_meas(i_bin), mean_I=mean_I, mean_I_sigI=mean_I_sigI ) result.append(bin) cumulative_unique += n_present cumulative_meas += sel_measurements cumulative_theor += sel_multiplicity.size() cumulative_In += I_n cumulative_I += I_sum cumulative_Isigma += I_sigI_sum if (title is not None) : print >> out, title from libtbx import table_utils table_header = ["","","","<asu","<obs",""," #"," %","","",""] table_header2 = ["Bin","Resolution Range","Completeness","multi>","multi>","n_meas"," neg"," neg","n_xtal","<I>","<I/sig(I)>"] table_data = [] table_data.append(table_header) table_data.append(table_header2) for bin in result: table_row = [] table_row.append("%3d" % bin.i_bin) table_row.append("%-13s" % bin.d_range) table_row.append("%13s" % bin.complete_tag) table_row.append("%6.2f" % bin.redundancy_asu) table_row.append("%6.2f" % bin.redundancy_obs) table_row.append("%6d" % bin.measurements) table_row.append("%4d" % bin.negative) table_row.append("%5.2f"%bin.percent_neg) table_row.append("%6d" % bin.frames) table_row.append("%8.3f" % bin.mean_I) table_row.append("%8.3f" % bin.mean_I_sigI) table_data.append(table_row) table_data.append([""]*len(table_header)) table_data.append( [ format_value("%3s", "All"), format_value("%-13s", " "), format_value("%13s", "[%d/%d]"%(cumulative_unique,cumulative_theor)), format_value("%6.2f", cumulative_meas/cumulative_theor), format_value("%6.2f", cumulative_meas/cumulative_unique), format_value("%6d", cumulative_meas), format_value("%4d", frame_worker.all_neg()), format_value("%5.2f", 100.*frame_worker.all_neg()/frame_worker.all_meas()), format_value("%6d", frame_worker.all_frames()), format_value("%8.3f", cumulative_I/cumulative_In), format_value("%8.3f", cumulative_Isigma/cumulative_In), ]) print print >>out,table_utils.format(table_data,has_header=2,justify='center',delim=" ") # XXX generate table object for displaying plots if (title is None) : title = "Data statistics by resolution" table = data_plots.table_data( title=title, x_is_inverse_d_min=True, force_exact_x_labels=True) table.add_column( column=[1 / bin.d_min**2 for bin in result], column_name="d_min", column_label="Resolution") table.add_column( column=[bin.redundancy_asu for bin in result], column_name="redundancy", column_label="Redundancy") table.add_column( column=[bin.completeness for bin in result], column_name="completeness", column_label="Completeness") table.add_column( column=[bin.mean_I_sigI for bin in result], column_name="mean_i_over_sigI", column_label="<I/sig(I)>") table.add_graph( name="Redundancy vs. resolution", type="GRAPH", columns=[0,1]) table.add_graph( name="Completeness vs. resolution", type="GRAPH", columns=[0,2]) table.add_graph( name="<I/sig(I)> vs. resolution", type="GRAPH", columns=[0,3]) return table,n_bins,d_min
def __init__ (self, i_obs, crystal_symmetry=None, d_min=None, d_max=None, anomalous=False, n_bins=10, debug=False, file_name=None, model_arrays=None, sigma_filtering=Auto, use_internal_variance=True, eliminate_sys_absent=True, d_min_tolerance=1.e-6, extend_d_max_min=False, log=None) : self.file_name = file_name if (log is None) : log = null_out() assert (i_obs.sigmas() is not None) info = i_obs.info() sigma_filtering = get_filtering_convention(i_obs, sigma_filtering) if (crystal_symmetry is None) : assert (i_obs.space_group() is not None) crystal_symmetry = i_obs.crystal_symmetry() self.crystal_symmetry = crystal_symmetry i_obs = i_obs.customized_copy( crystal_symmetry=crystal_symmetry).set_info(info) if (i_obs.is_unique_set_under_symmetry()) : raise Sorry(("The data in %s are already merged. Only unmerged (but "+ "scaled) data may be used in this program.")% i_obs.info().label_string()) d_min_cutoff = d_min d_max_cutoff = d_max if (d_min is not None) : d_min_cutoff *= (1-d_min_tolerance) if (d_max is not None) : assert (d_max > d_min) if (d_max is not None) : d_max_cutoff *= 1+d_min_tolerance i_obs = i_obs.resolution_filter( d_min=d_min_cutoff, d_max=d_max_cutoff).set_info(info) if (i_obs.size() == 0) : raise Sorry("No reflections left after applying resolution cutoffs.") i_obs.show_summary(f=log) self.anom_extra = "" if (not anomalous) : i_obs = i_obs.customized_copy(anomalous_flag=False).set_info(info) self.anom_extra = " (non-anomalous)" overall_d_max_min = None # eliminate_sys_absent() before setting up binner to ensure consistency # between reported overall d_min/max and d_min/max for resolution bins" if eliminate_sys_absent: i_obs = i_obs.eliminate_sys_absent() if extend_d_max_min : i_obs.setup_binner( n_bins=n_bins, d_max=d_max_cutoff, d_min=d_min_cutoff) overall_d_max_min = d_max_cutoff, d_min_cutoff else : i_obs.setup_binner(n_bins=n_bins) self.overall = merging_stats(i_obs, d_max_min=overall_d_max_min, model_arrays=model_arrays, anomalous=anomalous, debug=debug, sigma_filtering=sigma_filtering, use_internal_variance=use_internal_variance) self.bins = [] title = "Intensity merging statistics" column_labels = ["1/d**2","N(obs)","N(unique)","Redundancy","Completeness", "Mean(I)", "Mean(I/sigma)", "R-merge", "R-meas", "R-pim", "CC1/2", "CC(anom)"] graph_names = ["Reflection counts", "Redundancy", "Completeness", "Mean(I)", "Mean(I/sigma)", "R-factors", "CC1/2", "CC(anom)"] graph_columns = [[0,1,2],[0,3],[0,4],[0,5],[0,6],[0,7,8,9],[0,10],[0,11]] #--- CC* mode if (model_arrays is not None) : title = "Model quality and intensity merging statistics" column_labels.extend(["CC*", "CC(work)", "CC(free)", "R-work", "R-free"]) graph_names.extend(["CC*", "Model R-factors"]) graph_columns.extend([[0,11,12,13],[0,14,15]]) #--- self.table = data_plots.table_data( title=title, column_labels=column_labels, graph_names=graph_names, graph_columns=graph_columns, x_is_inverse_d_min=True, force_exact_x_labels=True) last_bin = None for bin in i_obs.binner().range_used() : sele_unmerged = i_obs.binner().selection(bin) bin_stats = merging_stats(i_obs.select(sele_unmerged), d_max_min=i_obs.binner().bin_d_range(bin), model_arrays=model_arrays, anomalous=anomalous, debug=debug, sigma_filtering=sigma_filtering, use_internal_variance=use_internal_variance) self.bins.append(bin_stats) self.table.add_row(bin_stats.table_data())
def exercise_inline(): loggraph1 = """\ $TABLE: Resolution shell statistics $GRAPHS :R-free vs. resolution:A:1,3: :FOM vs. resolution:A:1,4: $$ 1/resol^2 Nrefl R-free FOM $$ $$ 0.02 2004 0.25 0.89 0.04 2084 0.23 0.88 0.06 * 0.27 nan 0.08 1949 0.28 0.75 0.1 1783 0.38 * $$ """ # Different newline arrangement, otherwise identical loggraph_input = """\ $TABLE: Resolution shell statistics: $GRAPHS :R-free vs. resolution:A:1,3: :FOM vs. resolution:A:1,4: $$ 1/resol^2 Nrefl """ + """ R-free FOM $$ $$ 0.02 2004 """ + """ 0.25 0.89 0.04 2084 0.23 0.88 0.06 nan 0.27 nan 0.08 1949 0.28 0.75 0.1 1783 0.38 * $$ """ t = data_plots.table_data(None) t.import_loggraph(loggraph_input) # print t.format_loggraph() # print "---" # print loggraph1 assert (len(t.data) == 4) assert (t.data[0] == [0.02, 0.04, 0.06, 0.08, 0.10]) assert (t.data[3][4] is None) assert (t.format_loggraph() == loggraph1), t.format_loggraph() assert (t.export_rows()[-1] == ['0.1', '1783', '0.38', '*']) json_t = t.export_json_table() json_d = json.loads(json_t) assert (json_d['rows'] == [["1/resol^2", "Nrefl", "R-free", "FOM"], ["0.02", "2004", "0.25", "0.89"], ["0.04", "2084", "0.23", "0.88"], ["0.06", "*", "0.27", "nan"], ["0.08", "1949", "0.28", "0.75"], ["0.1", "1783", "0.38", "*"]]), json_d['rows'] assert (json_d['title'] == "Resolution shell statistics"), json_d['title'] f = open("_tst_data_plots.log", "w") f.write("\nRandom non-loggraph text\n\n") f.write(loggraph1) f.write("\n\n") f.write(loggraph1) f.close() tables = data_plots.import_ccp4i_logfile("_tst_data_plots.log") assert len(tables) == 2 assert tables[0].format_loggraph() == loggraph1 assert tables[0].format_loggraph() == tables[1].format_loggraph() t2 = data_plots.table_data( title="Resolution shell statistics", column_labels=["1/resol^2", "Nrefl", "R-free", "FOM"], graph_names=["R-free vs. resolution", "FOM vs. resolution"], graph_columns=[[0, 2], [0, 3]], data=[[0.02, 0.04, 0.06, 0.08, 0.10], [2004, 2084, None, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, float('NaN'), 0.75, None]]) #print loggraph1 #print "---" #print t2.format_loggraph() assert t2.format_loggraph() == loggraph1 g1 = t2.get_graph("R-free vs. resolution") g2 = t2.get_graph("FOM vs. resolution") assert len(g1.data) == 2 and len(g2.data) == 2 p1 = g1.get_plots(fill_in_missing_y=None) p2 = g2.get_plots(fill_in_missing_y=None) assert len(p1) == 1 and len(p2) == 1 (plot_x, plot_y) = p1.pop() assert len(plot_x) == 5 (plot_x, plot_y) = p2.pop() assert len(plot_x) == 4 formatted_table = """\ ------------------------------------------------- | Resolution shell statistics | |-----------------------------------------------| | 1/resol^2 | Nrefl | R-free | FOM | |-----------------------------------------------| | 0.02 | 2004 | 0.25 | 0.89 | | 0.04 | 2084 | 0.23 | 0.88 | | 0.06 | * | 0.27 | nan | | 0.08 | 1949 | 0.28 | 0.75 | | 0.1 | 1783 | 0.38 | * | ------------------------------------------------- """ #print t2.format() assert t2.format(indent=2) == formatted_table simple_table = """\ Resolution shell statistics 1/resol^2 Nrefl R-free FOM 0.02 2004 0.25 0.89 0.04 2084 0.23 0.88 0.06 * 0.27 nan 0.08 1949 0.28 0.75 0.1 1783 0.38 * """ # as above, but without indentation simpler_table = """\ Resolution shell statistics 1/resol^2 Nrefl R-free FOM 0.02 2004 0.25 0.89 0.04 2084 0.23 0.88 0.06 * 0.27 nan 0.08 1949 0.28 0.75 0.1 1783 0.38 * """ formatted = t2.format_simple(indent=2) assert (formatted == simple_table), formatted assert str(t2) == simpler_table json_str = t2.export_json() json_dict = json.loads(json_str) expected_dict = { "graph_types": ["A", "A"], "graph_columns": [[0, 2], [0, 3]], "title": "Resolution shell statistics", "column_labels": ["1/resol^2", "Nrefl", "R-free", "FOM"], "data": [[0.02, 0.04, 0.06, 0.08, 0.1], [2004, 2084, None, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, float('nan'), 0.75, None]], "graph_names": ["R-free vs. resolution", "FOM vs. resolution"], "x_is_inverse_d_min": False } for key in expected_dict: if key != 'data': assert (key in json_dict), key assert (json_dict[key] == expected_dict[key]), \ (key, json_dict[key], expected_dict[key]) assert ( '"data": [[0.02, 0.04, 0.06, 0.08, 0.1], [2004, 2084, null, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, NaN, 0.75, null]]' in json_str), json_str
def __init__(self, i_obs, crystal_symmetry=None, d_min=None, d_max=None, anomalous=False, n_bins=10, binning_method='volume', debug=False, file_name=None, model_arrays=None, sigma_filtering=Auto, use_internal_variance=True, eliminate_sys_absent=True, d_min_tolerance=1.e-6, extend_d_max_min=False, cc_one_half_significance_level=None, cc_one_half_method='half_dataset', assert_is_not_unique_set_under_symmetry=True, log=None): self.file_name = file_name if (log is None): log = null_out() assert (i_obs.sigmas() is not None) info = i_obs.info() sigma_filtering = get_filtering_convention(i_obs, sigma_filtering) if (crystal_symmetry is None): assert (i_obs.space_group() is not None) crystal_symmetry = i_obs.crystal_symmetry() self.crystal_symmetry = crystal_symmetry i_obs = i_obs.customized_copy( crystal_symmetry=crystal_symmetry).set_info(info) if (assert_is_not_unique_set_under_symmetry and i_obs.is_unique_set_under_symmetry()): raise Sorry( ("The data in %s are already merged. Only unmerged (but " + "scaled) data may be used in this program.") % i_obs.info().label_string()) d_min_cutoff = d_min d_max_cutoff = d_max if (d_min is not None): d_min_cutoff *= (1 - d_min_tolerance) if (d_max is not None): assert (d_max > d_min) if (d_max is not None): d_max_cutoff *= 1 + d_min_tolerance i_obs = i_obs.resolution_filter(d_min=d_min_cutoff, d_max=d_max_cutoff).set_info(info) if (i_obs.size() == 0): raise Sorry( "No reflections left after applying resolution cutoffs.") i_obs.show_summary(f=log) self.anom_extra = "" if (not anomalous): i_obs = i_obs.customized_copy(anomalous_flag=False).set_info(info) self.anom_extra = " (non-anomalous)" overall_d_max_min = None # eliminate_sys_absent() before setting up binner to ensure consistency # between reported overall d_min/max and d_min/max for resolution bins" if eliminate_sys_absent: i_obs = i_obs.eliminate_sys_absent() if extend_d_max_min: i_obs.setup_binner(n_bins=n_bins, d_max=d_max_cutoff, d_min=d_min_cutoff) overall_d_max_min = d_max_cutoff, d_min_cutoff else: if binning_method == 'volume': i_obs.setup_binner(n_bins=n_bins) elif binning_method == 'counting_sorted': i_obs.setup_binner_counting_sorted(n_bins=n_bins) self.overall = merging_stats( i_obs, d_max_min=overall_d_max_min, model_arrays=model_arrays, anomalous=anomalous, debug=debug, sigma_filtering=sigma_filtering, use_internal_variance=use_internal_variance, cc_one_half_significance_level=cc_one_half_significance_level, cc_one_half_method=cc_one_half_method) self.bins = [] title = "Intensity merging statistics" column_labels = [ "1/d**2", "N(obs)", "N(unique)", "Redundancy", "Completeness", "Mean(I)", "Mean(I/sigma)", "R-merge", "R-meas", "R-pim", "CC1/2", "CC(anom)" ] graph_names = [ "Reflection counts", "Redundancy", "Completeness", "Mean(I)", "Mean(I/sigma)", "R-factors", "CC1/2", "CC(anom)" ] graph_columns = [[0, 1, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7, 8, 9], [0, 10], [0, 13]] if cc_one_half_significance_level is not None: column_labels.extend( ["CC1/2 significance", "CC1/2 critical value"]) graph_names.extend(["CC1/2 significance", "CC1/2 critical value"]) graph_columns[-2] = [0, 10, 12] #--- CC* mode if (model_arrays is not None): title = "Model quality and intensity merging statistics" column_labels.extend( ["CC*", "CC(work)", "CC(free)", "R-work", "R-free"]) graph_names.extend(["CC*", "Model R-factors"]) graph_columns.extend([[0, 11, 14, 15], [0, 16, 17]]) #--- self.table = data_plots.table_data(title=title, column_labels=column_labels, graph_names=graph_names, graph_columns=graph_columns, x_is_inverse_d_min=True, force_exact_x_labels=True) last_bin = None for bin in i_obs.binner().range_used(): sele_unmerged = i_obs.binner().selection(bin) bin_stats = merging_stats( i_obs.select(sele_unmerged), d_max_min=i_obs.binner().bin_d_range(bin), model_arrays=model_arrays, anomalous=anomalous, debug=debug, sigma_filtering=sigma_filtering, use_internal_variance=use_internal_variance, cc_one_half_significance_level=cc_one_half_significance_level, cc_one_half_method=cc_one_half_method) self.bins.append(bin_stats) self.table.add_row(bin_stats.table_data()) from scitbx.array_family import flex self.cc_one_half_overall = flex.mean_weighted( flex.double(b.cc_one_half for b in self.bins), flex.double(b.cc_one_half_n_refl for b in self.bins)) self.cc_one_half_sigma_tau_overall = flex.mean_weighted( flex.double(b.cc_one_half_sigma_tau for b in self.bins), flex.double(b.cc_one_half_sigma_tau_n_refl for b in self.bins))
def exercise_inline () : loggraph1 = """\ $TABLE: Resolution shell statistics $GRAPHS :R-free vs. resolution:A:1,3: :FOM vs. resolution:A:1,4: $$ 1/resol^2 Nrefl R-free FOM $$ $$ 0.02 2004 0.25 0.89 0.04 2084 0.23 0.88 0.06 2037 0.27 0.83 0.08 1949 0.28 0.75 0.1 1783 0.38 * $$ """ t = data_plots.table_data(None) t.import_loggraph(loggraph1) # print t.format_loggraph() # print "---" # print loggraph1 assert (len(t.data) == 4) assert (t.data[0] == [0.02, 0.04, 0.06, 0.08, 0.10]) assert (t.data[3][4] is None) assert (t.format_loggraph() == loggraph1), t.format_loggraph() assert (t.export_rows()[-1] == ['0.1', '1783', '0.38', '*']) assert (t.export_json_table() == """{"rows": [["1/resol^2", "Nrefl", "R-free", "FOM"], ["0.02", "2004", "0.25", "0.89"], ["0.04", "2084", "0.23", "0.88"], ["0.06", "2037", "0.27", "0.83"], ["0.08", "1949", "0.28", "0.75"], ["0.1", "1783", "0.38", "*"]], "title": "Resolution shell statistics"}""") f = open("_tst_data_plots.log", "w") f.write("\nRandom non-loggraph text\n\n") f.write(loggraph1) f.write("\n\n") f.write(loggraph1) f.close() tables = data_plots.import_ccp4i_logfile("_tst_data_plots.log") assert len(tables) == 2 assert tables[0].format_loggraph() == loggraph1 assert tables[0].format_loggraph() == tables[1].format_loggraph() t2 = data_plots.table_data( title = "Resolution shell statistics", column_labels = ["1/resol^2", "Nrefl", "R-free", "FOM"], graph_names = ["R-free vs. resolution", "FOM vs. resolution"], graph_columns = [[0,2], [0,3]], data = [[0.02, 0.04, 0.06, 0.08, 0.10], [2004, 2084, 2037, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, 0.83, 0.75, None]] ) #print loggraph1 #print "---" #print t2.format_loggraph() assert t2.format_loggraph() == loggraph1 g1 = t2.get_graph("R-free vs. resolution") g2 = t2.get_graph("FOM vs. resolution") assert len(g1.data) == 2 and len(g2.data) == 2 p1 = g1.get_plots(fill_in_missing_y=None) p2 = g2.get_plots(fill_in_missing_y=None) assert len(p1) == 1 and len(p2) == 1 (plot_x, plot_y) = p1.pop() assert len(plot_x) == 5 (plot_x, plot_y) = p2.pop() assert len(plot_x) == 4 formatted_table = """\ ------------------------------------------------- | Resolution shell statistics | |-----------------------------------------------| | 1/resol^2 | Nrefl | R-free | FOM | |-----------------------------------------------| | 0.02 | 2004 | 0.25 | 0.89 | | 0.04 | 2084 | 0.23 | 0.88 | | 0.06 | 2037 | 0.27 | 0.83 | | 0.08 | 1949 | 0.28 | 0.75 | | 0.1 | 1783 | 0.38 | * | ------------------------------------------------- """ #print t2.format() assert t2.format(indent=2) == formatted_table simple_table = """\ Resolution shell statistics 1/resol^2 Nrefl R-free FOM 0.02 2004 0.25 0.89 0.04 2084 0.23 0.88 0.06 2037 0.27 0.83 0.08 1949 0.28 0.75 0.1 1783 0.38 * """ # as above, but without indentation simpler_table = """\ Resolution shell statistics 1/resol^2 Nrefl R-free FOM 0.02 2004 0.25 0.89 0.04 2084 0.23 0.88 0.06 2037 0.27 0.83 0.08 1949 0.28 0.75 0.1 1783 0.38 * """ formatted = t2.format_simple(indent=2) assert (formatted == simple_table), formatted assert str(t2) == simpler_table json_str = t2.export_json() assert (json_str == '{"graph_types": ["A", "A"], "graph_columns": [[0, 2], [0, 3]], "title": "Resolution shell statistics", "column_labels": ["1/resol^2", "Nrefl", "R-free", "FOM"], "data": [[0.02, 0.04, 0.06, 0.08, 0.1], [2004, 2084, 2037, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, 0.83, 0.75, null]], "graph_names": ["R-free vs. resolution", "FOM vs. resolution"], "x_is_inverse_d_min": false}')
def OnViewGraphs(self, evt): """ Open a wxtbx.plots.loggraph_frame window with the table. """ assert hasattr(self._table, "get_graph") graph_frame = wxtbx.plots.loggraph(parent=self.GetParent(), title=self._table.title, tables=[self._table]) graph_frame.Show() # TESTING if (__name__ == "__main__"): from iotbx import data_plots table = data_plots.table_data( title="Resolution shell statistics", column_labels=["1/resol^2", "Nrefl", "R-free", "FOM"], graph_names=["R-free vs. resolution", "FOM vs. resolution"], graph_columns=[[0, 2], [0, 3]], data=[[0.02, 0.04, 0.06, 0.08, 0.10], [2004, 2084, 2037, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, 0.83, 0.75, None]]) app = wx.App(0) frame = wx.Frame(parent=None, title="Test frame", size=(600, 280)) panel = wx.Panel(parent=frame) ctrl = TableView(panel, pos=(10, 10), size=(580, 180)) ctrl.SetTable(table) btn = wx.Button(parent=panel, label="Show graphs", pos=(10, 210)) frame.Bind(wx.EVT_BUTTON, ctrl.OnViewGraphs, btn) frame.Show() app.MainLoop()
Open a wxtbx.plots.loggraph_frame window with the table. """ assert hasattr(self._table, "get_graph") graph_frame = wxtbx.plots.loggraph( parent=self.GetParent(), title=self._table.title, tables=[self._table]) graph_frame.Show() # TESTING if (__name__ == "__main__") : from iotbx import data_plots table = data_plots.table_data( title = "Resolution shell statistics", column_labels = ["1/resol^2", "Nrefl", "R-free", "FOM"], graph_names = ["R-free vs. resolution", "FOM vs. resolution"], graph_columns = [[0,2], [0,3]], data = [[0.02, 0.04, 0.06, 0.08, 0.10], [2004, 2084, 2037, 1949, 1783], [0.25, 0.23, 0.27, 0.28, 0.38], [0.89, 0.88, 0.83, 0.75, None]]) app = wx.App(0) frame = wx.Frame(parent=None, title="Test frame", size=(600,280)) panel = wx.Panel(parent=frame) ctrl = TableView(panel, pos=(10,10), size=(580,180)) ctrl.SetTable(table) btn = wx.Button(parent=panel, label="Show graphs", pos=(10,210)) frame.Bind(wx.EVT_BUTTON, ctrl.OnViewGraphs, btn) frame.Show() app.MainLoop()