<commit_before>#!/usr/bin/env python
#
# dials.create_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.

from __future__ import division
from libtbx.phil import parse

help_message = '''

This program computes the profile model from the input reflections. It then
saves a modified experiments.json file with the additional profile model
information. Usually this is performed during integration; however, on some
occasions it may be desirable to compute the profile model independantly.

Examples::

  dials.create_profile_model experiments.json reflections.pickle

'''

phil_scope = parse('''
  subtract_background = False
    .type = bool
    .help = "Subtract background from pixel data before computing profile"
    .expert_level = 2
  output = experiments_with_profile_model.json
    .type = str
    .help = "The filename for the experiments"

  include scope dials.algorithms.profile_model.factory.phil_scope
  include scope dials.algorithms.spot_prediction.reflection_predictor.phil_scope
''', process_includes=True)

class Script(object):
  ''' Encapsulate the script in a class. '''

  def __init__(self):
    ''' Initialise the script. '''
    from dials.util.options import OptionParser
    import libtbx.load_env

    # The script usage
    usage  = "usage: %s [options] experiments.json spots.pickle" \
      % libtbx.env.dispatcher_name
    self.parser = OptionParser(
      usage=usage,
      epilog=help_message,
      phil=phil_scope,
      read_reflections=True,
      read_experiments=True,
      check_format=False)

  def run(self):
    ''' Run the script. '''
    from dials.algorithms.profile_model.factory import ProfileModelFactory
    from dials.util.command_line import Command
    from dials.array_family import flex
    from dials.util.options import flatten_reflections, flatten_experiments
    from dxtbx.model.experiment.experiment_list import ExperimentListDumper
    from libtbx.utils import Sorry
    from logging import info
    from dials.util import log

    log.config()

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=True)
    reflections = flatten_reflections(params.input.reflections)
    experiments = flatten_experiments(params.input.experiments)
    if len(reflections) == 0 and len(experiments) == 0:
      self.parser.print_help()
      return
    if len(reflections) != 1:
      raise Sorry('exactly 1 reflection table must be specified')
    if len(experiments) == 0:
      raise Sorry('no experiments were specified')
    if (not 'background.mean' in reference) and params.subtract_background:
      raise Sorry('for subtract_background need background.mean in reflections')

    reflections, _ = self.process_reference(reflections[0], params)

    # Predict the reflections
    info("")
    info("=" * 80)
    info("")
    info("Predicting reflections")
    info("")
    predicted = flex.reflection_table.from_predictions_multi(
      experiments,<commit_msg>Typo; sorry<commit_after>#!/usr/bin/env python
#
# dials.create_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.

from __future__ import division
from libtbx.phil import parse

help_message = '''

This program computes the profile model from the input reflections. It then
saves a modified experiments.json file with the additional profile model
information. Usually this is performed during integration; however, on some
occasions it may be desirable to compute the profile model independantly.

Examples::

  dials.create_profile_model experiments.json reflections.pickle

'''

phil_scope = parse('''
  subtract_background = False
    .type = bool
    .help = "Subtract background from pixel data before computing profile"
    .expert_level = 2
  output = experiments_with_profile_model.json
    .type = str
    .help = "The filename for the experiments"

  include scope dials.algorithms.profile_model.factory.phil_scope
  include scope dials.algorithms.spot_prediction.reflection_predictor.phil_scope
''', process_includes=True)

class Script(object):
  ''' Encapsulate the script in a class. '''

  def __init__(self):
    ''' Initialise the script. '''
    from dials.util.options import OptionParser
    import libtbx.load_env

    # The script usage
    usage  = "usage: %s [options] experiments.json spots.pickle" \
      % libtbx.env.dispatcher_name
    self.parser = OptionParser(
      usage=usage,
      epilog=help_message,
      phil=phil_scope,
      read_reflections=True,
      read_experiments=True,
      check_format=False)

  def run(self):
    ''' Run the script. '''
    from dials.algorithms.profile_model.factory import ProfileModelFactory
    from dials.util.command_line import Command
    from dials.array_family import flex
    from dials.util.options import flatten_reflections, flatten_experiments
    from dxtbx.model.experiment.experiment_list import ExperimentListDumper
    from libtbx.utils import Sorry
    from logging import info
    from dials.util import log

    log.config()

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=True)
    reflections = flatten_reflections(params.input.reflections)
    experiments = flatten_experiments(params.input.experiments)
    if len(reflections) == 0 and len(experiments) == 0:
      self.parser.print_help()
      return
    if len(reflections) != 1:
      raise Sorry('exactly 1 reflection table must be specified')
    if len(experiments) == 0:
      raise Sorry('no experiments were specified')
    if (not 'background.mean' in reflections[0]) and params.subtract_background:
      raise Sorry('for subtract_background need background.mean in reflections')

    reflections, _ = self.process_reference(reflections[0], params)

    # Predict the reflections
    info("")
    info("=" * 80)
    info("")
    info("Predicting reflections")
    info("")
    predicted = flex.reflection_table.from_predictions_multi(
      experiments,
{'fraction_non_alphanumeric': 0.0831323363884869, 'fraction_numerical': 0.004341534008683068, 'mean_word_length': 3.844236760124611, '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': '2253817', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1765, 'n_words': 532}