<commit_before>#!/usr/bin/env python
#
# profile_model.py
#
#  Copyright (C) 2013 Diamond Light Source
#
#  Author: <NAME>
#
#  This code is distributed under the BSD license, a copy of which is
#  included in the root directory of this package.
#
# FIXME Mosaicity seems to be overestimated
# FIXME Don't know how XDS REFLECTING_RANGE is calculated
# FIXME Don't know what XDS REFLECTION_RANGE is used for
# FIXME Don't know what XDS BEAM_DIVERGENCE is used for
# FIXME Should maybe be scan varying
# FIXME Don't know how XDS calculated the n_sigma

from __future__ import division


class ComputeEsdBeamDivergence(object):
  '''Calculate the E.s.d of the beam divergence.'''

  def __init__(self, detector, reflections):
    ''' Calculate the E.s.d of the beam divergence.

    Params:
        detector The detector class
        reflections The reflections

    '''
    from scitbx.array_family import flex
    from math import sqrt

    # Calculate the beam direction variances
    variance = self._beam_direction_variance_list(detector, reflections)

    # Calculate and return the e.s.d of the beam divergence
    self._sigma = sqrt(flex.sum(variance) / len(variance))

  def sigma(self):
    ''' Return the E.S.D of the beam divergence. '''
    return self._sigma

  def _beam_direction_variance_list(self, detector, reflections):
    '''Calculate the variance in beam direction for each spot.

    Params:
        reflections The list of reflections

    Returns:
        The list of variances

    '''
    from scitbx.array_family import flex

    # Get the reflection columns
    shoebox = reflections['shoebox']
    bbox = reflections['bbox']
    xyz = reflections['xyzobs.px.value']

    # Loop through all the reflections
    variance = []
    for r in range(len(reflections)):

      # Get the coordinates and values of valid shoebox pixels
      # FIXME maybe I note in Kabsch (2010) §3.1 step (v) is
      # background subtraction, appears to be missing here.
      mask = shoebox[r].mask != 0
      coords = shoebox[r].coords(mask)
      values = shoebox[r].values(mask)
      s1 = shoebox[r].beam_vectors(detector, mask)

      # Calculate the beam vector at the centroid
      panel = shoebox[r].panel
      s1_centroid = detector[panel].get_pixel_lab_coord(xyz[r][0:2])
      angles = s1.angle(s1_centroid, deg=False)
      variance.append(flex.sum(values * (angles**2)) / (flex.sum(values) - 1))

    # Return a list of variances
    return flex.double(variance)


class FractionOfObservedIntensity(object):
  '''Calculate the fraction of observed intensity for different sigma_m.'''

  def __init__(self, crystal, beam, detector, goniometer, scan, reflections):
    '''Initialise the algorithm. Calculate the list of tau and zetas.

    Params:
        reflections The list of reflections
        experiment The experiment object

    '''
    from dials.array_family import flex
    from math import sqrt

    # Get the oscillation width<commit_msg>§ is not a letter<commit_after>#!/usr/bin/env python
#
# profile_model.py
#
#  Copyright (C) 2013 Diamond Light Source
#
#  Author: <NAME>
#
#  This code is distributed under the BSD license, a copy of which is
#  included in the root directory of this package.
#
# FIXME Mosaicity seems to be overestimated
# FIXME Don't know how XDS REFLECTING_RANGE is calculated
# FIXME Don't know what XDS REFLECTION_RANGE is used for
# FIXME Don't know what XDS BEAM_DIVERGENCE is used for
# FIXME Should maybe be scan varying
# FIXME Don't know how XDS calculated the n_sigma

from __future__ import division


class ComputeEsdBeamDivergence(object):
  '''Calculate the E.s.d of the beam divergence.'''

  def __init__(self, detector, reflections):
    ''' Calculate the E.s.d of the beam divergence.

    Params:
        detector The detector class
        reflections The reflections

    '''
    from scitbx.array_family import flex
    from math import sqrt

    # Calculate the beam direction variances
    variance = self._beam_direction_variance_list(detector, reflections)

    # Calculate and return the e.s.d of the beam divergence
    self._sigma = sqrt(flex.sum(variance) / len(variance))

  def sigma(self):
    ''' Return the E.S.D of the beam divergence. '''
    return self._sigma

  def _beam_direction_variance_list(self, detector, reflections):
    '''Calculate the variance in beam direction for each spot.

    Params:
        reflections The list of reflections

    Returns:
        The list of variances

    '''
    from scitbx.array_family import flex

    # Get the reflection columns
    shoebox = reflections['shoebox']
    bbox = reflections['bbox']
    xyz = reflections['xyzobs.px.value']

    # Loop through all the reflections
    variance = []
    for r in range(len(reflections)):

      # Get the coordinates and values of valid shoebox pixels
      # FIXME maybe I note in Kabsch (2010) s3.1 step (v) is
      # background subtraction, appears to be missing here.
      mask = shoebox[r].mask != 0
      coords = shoebox[r].coords(mask)
      values = shoebox[r].values(mask)
      s1 = shoebox[r].beam_vectors(detector, mask)

      # Calculate the beam vector at the centroid
      panel = shoebox[r].panel
      s1_centroid = detector[panel].get_pixel_lab_coord(xyz[r][0:2])
      angles = s1.angle(s1_centroid, deg=False)
      variance.append(flex.sum(values * (angles**2)) / (flex.sum(values) - 1))

    # Return a list of variances
    return flex.double(variance)


class FractionOfObservedIntensity(object):
  '''Calculate the fraction of observed intensity for different sigma_m.'''

  def __init__(self, crystal, beam, detector, goniometer, scan, reflections):
    '''Initialise the algorithm. Calculate the list of tau and zetas.

    Params:
        reflections The list of reflections
        experiment The experiment object

    '''
    from dials.array_family import flex
    from math import sqrt

    # Get the oscillation width
{'fraction_non_alphanumeric': 0.08341742347796838, 'fraction_numerical': 0.006390850992263707, 'mean_word_length': 3.300072306579899, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1079766', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1718, 'n_words': 623}