<commit_before>"""
Functions to help with reindexing against a reference dataset
"""
from libtbx.utils import Sorry
from cctbx import sgtbx
from mmtbx.scaling.twin_analyses import twin_laws

def determine_reindex_operator_against_reference(test_miller_set,
  reference_miller_set):
  """This function takes two miller arrays, a reference and a test array. The
  space group is checked to see if any reindexing may be required to give
  consistent indexing between both datasets. If possible twin operators exist,
  the different indexing options are tested against the reference set, using
  the correlation between datasets as the test.
  An sgtbx.change_of_basis_op is returned, which should be applied to the
  test dataset to give consistent indexing with the reference."""

  if reference_miller_set.space_group().type().number() != \
    test_miller_set.space_group().type().number():
    raise Sorry("""Space groups are not equal. Can only reindex against a
reference dataset if both dataset are in the same spacegroup.""")

  twin_ops = twin_laws(miller_array=test_miller_set.eliminate_sys_absent()).operators
  twin_ops = [sgtbx.change_of_basis_op(op.operator.as_xyz()) for op in twin_ops]

  if twin_ops:
    correlations = []
    print("Possible twin operators identified for space group %s:" \
      % test_miller_set.space_group().info())
    for op in twin_ops:
      print(op)
    # Loop through twin operators, calculating cc between two datasets
    cc = test_miller_set.correlation(reference_miller_set)
    correlations.append(cc.coefficient())
    for op in twin_ops:
      reindexed = test_miller_set.change_basis(op)<commit_msg>reference reindex bugfix - missed instance of correlation calculation<commit_after>"""
Functions to help with reindexing against a reference dataset
"""
from libtbx.utils import Sorry
from cctbx import sgtbx
from mmtbx.scaling.twin_analyses import twin_laws

def determine_reindex_operator_against_reference(test_miller_set,
  reference_miller_set):
  """This function takes two miller arrays, a reference and a test array. The
  space group is checked to see if any reindexing may be required to give
  consistent indexing between both datasets. If possible twin operators exist,
  the different indexing options are tested against the reference set, using
  the correlation between datasets as the test.
  An sgtbx.change_of_basis_op is returned, which should be applied to the
  test dataset to give consistent indexing with the reference."""

  if reference_miller_set.space_group().type().number() != \
    test_miller_set.space_group().type().number():
    raise Sorry("""Space groups are not equal. Can only reindex against a
reference dataset if both dataset are in the same spacegroup.""")

  twin_ops = twin_laws(miller_array=test_miller_set.eliminate_sys_absent()).operators
  twin_ops = [sgtbx.change_of_basis_op(op.operator.as_xyz()) for op in twin_ops]

  if twin_ops:
    correlations = []
    print("Possible twin operators identified for space group %s:" \
      % test_miller_set.space_group().info())
    for op in twin_ops:
      print(op)
    # Loop through twin operators, calculating cc between two datasets
    cc = test_miller_set.correlation(reference_miller_set,
      assert_is_similar_symmetry=False)
    correlations.append(cc.coefficient())
    for op in twin_ops:
      reindexed = test_miller_set.change_basis(op)
{'fraction_non_alphanumeric': 0.0709658421672556, 'fraction_numerical': 0.0, 'mean_word_length': 4.728499156829679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5314386', 'n_tokens_mistral': 1007, 'n_tokens_neox': 958, 'n_words': 339}