<commit_before>from __future__ import division, print_function

def table1_tex(crystal_params, merging_stats):
  # based on table1 from
  #
  # http://journals.iucr.org/d/issues/2018/02/00/di5011/index.html

  assert len(crystal_params) == len(merging_stats)

  # first iterate through and work out how many columns we will be needing
  columns = [len(ms) for ms in merging_stats]

  if max(columns) > 1:
    raise RuntimeError(':TODO: make this work for multiwavelength data sets')

  ncols = sum(columns)

  print('\\begin{tabular}{%s}' % ('l' * (ncols + 1)))

  name_str = ['']
  for cp in crystal_params:
    name_str.append(cp['name'].replace('_', '\_'))

  print(' & '.join(name_str) + ' \\\\')
  print('Crystal parameters' + ' & ' * ncols + '\\\\')
  print('Space group & ' +
          ' & '.join([cp['space_group'] for cp in crystal_params]) + ' \\\\')

  # witchcraft to work out how to write out the unit cell
  from cctbx import sgtbx
  cell_str = ['Unit-cell parameters (\\AA)']
  for cp in crystal_params:
    sgi = sgtbx.space_group_info(str(cp['space_group']))
    sg = sgi.group()
    constraints = sgtbx.tensor_rank_2_constraints(space_group=sg,
                                                  reciprocal_space=False)
    cell_tmp = '$'
    cell = cp['cell']
    if 0 in constraints.independent_indices:
      cell_tmp += 'a=%.5f, ' % cell[0]
    else:
      cell_tmp += 'a='
    if 1 in constraints.independent_indices:
      cell_tmp += 'b=%.5f, ' % cell[1]
    else:
      cell_tmp += 'b='
    cell_tmp += 'c=%.5f' % cell[2]
    if 3 in constraints.independent_indices:
      cell_tmp += ', \\alpha=%.5f' % cell[3]
    if 4 in constraints.independent_indices:
      cell_tmp += ', \\beta=%.5f' % cell[4]
    if 5 in constraints.independent_indices:
      cell_tmp += ', \\gamma=%.5f' % cell[5]
    cell_str.append(cell_tmp)
  print(' & '.join(cell_str) + ' \\\\')
  print('Data statistics' + ' & ' * ncols + '\\\\')

  # resolution ranges, shells

  resolution_str = ['Resolution range (\\AA)']

  for ms in merging_stats:
    for name in ms:
      low = ms[name]['Low resolution limit']
      high = ms[name]['High resolution limit']
      resolution_str.append('%.2f-%.2f (%.2f-%.2f)' %
                              (low[0], high[0], low[2], high[2]))

  print(' & '.join(resolution_str) + ' \\\\')

  # loopy boiler plate stuff - https://xkcd.com/1421/ - sorry - and why do
  # grown ups sometimes need things in %ages? x_x

  magic_words_and_places_and_multipliers = [
    ('No. of unique reflections', 'Total unique', 1, '%d'),
    ('Multiplicity', 'Multiplicity', 1, '%.1f'),
    ('$R_{\\rm{merge}}$', 'Rmerge(I)', 1, '%.3f'),
    ('$R_{\\rm{meas}}$', 'Rmeas(I)', 1, '%.3f'),
    ('$R_{\\rm{pim}}$', 'Rpim(I)', 1, '%.3f'),
    ('Completeness (\\%)', 'Completeness', 1, '%.1f'),<commit_msg>Dang, annoying<commit_after>from __future__ import division, print_function

def table1_tex(crystal_params, merging_stats):
  # based on table1 from
  #
  # http://journals.iucr.org/d/issues/2018/02/00/di5011/index.html

  assert len(crystal_params) == len(merging_stats)

  # first iterate through and work out how many columns we will be needing
  columns = [len(ms) for ms in merging_stats]

  if max(columns) > 1:
    raise RuntimeError(':TODO: make this work for multiwavelength data sets')

  ncols = sum(columns)

  print('\\begin{tabular}{%s}' % ('l' * (ncols + 1)))

  name_str = ['']
  for cp in crystal_params:
    name_str.append(cp['name'].replace('_', '\_'))

  print(' & '.join(name_str) + ' \\\\')
  print('Crystal parameters' + ' & ' * ncols + '\\\\')
  print('Space group & ' +
          ' & '.join([cp['space_group'] for cp in crystal_params]) + ' \\\\')

  # witchcraft to work out how to write out the unit cell
  from cctbx import sgtbx
  cell_str = ['Unit-cell parameters (\\AA)']
  for cp in crystal_params:
    sgi = sgtbx.space_group_info(str(cp['space_group']))
    sg = sgi.group()
    constraints = sgtbx.tensor_rank_2_constraints(space_group=sg,
                                                  reciprocal_space=False)
    cell_tmp = '$'
    cell = cp['cell']
    if 0 in constraints.independent_indices:
      cell_tmp += 'a=%.5f, ' % cell[0]
    else:
      cell_tmp += 'a='
    if 1 in constraints.independent_indices:
      cell_tmp += 'b=%.5f, ' % cell[1]
    else:
      cell_tmp += 'b='
    cell_tmp += 'c=%.5f' % cell[2]
    if 3 in constraints.independent_indices:
      cell_tmp += ', \\alpha=%.5f' % cell[3]
    if 4 in constraints.independent_indices:
      cell_tmp += ', \\beta=%.5f' % cell[4]
    if 5 in constraints.independent_indices:
      cell_tmp += ', \\gamma=%.5f' % cell[5]
    cell_tmp += '$'
    cell_str.append(cell_tmp)
  print(' & '.join(cell_str) + ' \\\\')
  print('Data statistics' + ' & ' * ncols + '\\\\')

  # resolution ranges, shells

  resolution_str = ['Resolution range (\\AA)']

  for ms in merging_stats:
    for name in ms:
      low = ms[name]['Low resolution limit']
      high = ms[name]['High resolution limit']
      resolution_str.append('%.2f-%.2f (%.2f-%.2f)' %
                              (low[0], high[0], low[2], high[2]))

  print(' & '.join(resolution_str) + ' \\\\')

  # loopy boiler plate stuff - https://xkcd.com/1421/ - sorry - and why do
  # grown ups sometimes need things in %ages? x_x

  magic_words_and_places_and_multipliers = [
    ('No. of unique reflections', 'Total unique', 1, '%d'),
    ('Multiplicity', 'Multiplicity', 1, '%.1f'),
    ('$R_{\\rm{merge}}$', 'Rmerge(I)', 1, '%.3f'),
    ('$R_{\\rm{meas}}$', 'Rmeas(I)', 1, '%.3f'),
    ('$R_{\\rm{pim}}$', 'Rpim(I)', 1, '%.3f'),
    ('Completeness (\\%)', 'Completeness', 1, '%.1f'),
{'fraction_non_alphanumeric': 0.18596429202757644, 'fraction_numerical': 0.020152024041011136, 'mean_word_length': 2.8568507157464214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '199071', 'n_tokens_mistral': 2112, 'n_tokens_neox': 1977, 'n_words': 463}