def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_experiments
  from libtbx.utils import Sorry
  import libtbx.load_env

  usage = "%s [options] experiments.json" %libtbx.env.dispatcher_name

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_experiments=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)
  experiments = flatten_experiments(params.input.experiments)
  if len(experiments) <= 1:
    parser.print_help()
    return

  hkl = flex.miller_index(params.hkl)

  from dials.algorithms.indexing.compare_orientation_matrices import \
       show_rotation_matrix_differences
  show_rotation_matrix_differences(experiments.crystals(),
                                   miller_indices=hkl)
示例#2
0
文件: sematura.py 项目: mewall/lunus
    def read_experiment_file(self, experiment_file):

        ### open DIALS json file
        phil_scope_str='''
            experiments = 'example_refined_experiments.json'
              '''
        phil_scope = parse(phil_scope_str, process_includes=True)
        parser = OptionParser(
            phil=phil_scope,
            check_format=False,
            read_experiments=True)
        params, options = parser.parse_args(args=[experiment_file], show_diff_phil=True)
        experiments = flatten_experiments(params.input.experiments)
        exp_xtal = experiments.crystals()[0]

        ### define useful attributes
        self.crystal = exp_xtal
        uc = self.crystal.get_unit_cell()
        uc_nospace = str(uc).replace(" ", "")
        uc_nospace_noparen = uc_nospace[1:-1]
        self.unit_cell = uc_nospace_noparen
        self.space_group = self.crystal.get_space_group()
        self.laue_group = self.space_group.laue_group_type()
        # self.a_matrix = crystal.get_A()
        self.experiments = experiments
示例#3
0
def run(args):
  from dials.util.options import OptionParser
  from dials.util.options import flatten_experiments
  from dials.util.options import flatten_reflections
  import libtbx.load_env

  usage = "%s [options] integrated.pickle experiments.json" % (
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_experiments=True,
    read_reflections=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=False)
  experiments = flatten_experiments(params.input.experiments)
  reflections = flatten_reflections(params.input.reflections)

  if len(experiments) != 1 or len(reflections) != 1:
    parser.print_help()
    exit()

  if not 'shoebox' in reflections[0]:
    print 'Please add shoeboxes to reflection pickle'
    exit()

  results = main(reflections[0], experiments[0], params)

  if results:
    print 'mean result: %.3f' % (sum(results) / len(results))
示例#4
0
  def run(self):
    ''' Parse the options. '''
    from dials.util.options import flatten_experiments, flatten_reflections
    # Parse the command line arguments
    params, options = self.parser.parse_args(show_diff_phil=True)
    self.params = params
    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    assert len(reflections) == len(experiments) == 1
    reflections = reflections[0]
    exp = experiments[0]

    from dials.algorithms.indexing import index_reflections
    from dials.algorithms.indexing.indexer import indexer_base

    reflections['id'] = flex.int(len(reflections), -1)
    reflections['imageset_id'] = flex.int(len(reflections), 0)
    reflections = indexer_base.map_spots_pixel_to_mm_rad(reflections, exp.detector, exp.scan)

    indexer_base.map_centroids_to_reciprocal_space(
      reflections, exp.detector, exp.beam, exp.goniometer,)

    index_reflections(reflections,
                      experiments, params.d_min,
                      tolerance=0.3)
    indexed_reflections = reflections.select(reflections['miller_index'] != (0,0,0))
    print "Indexed %d reflections out of %d"%(len(indexed_reflections), len(reflections))
    easy_pickle.dump("indexedstrong.pickle", indexed_reflections)
def run(args):
    import libtbx.load_env

    usage = "%s [options] experiment.json indexed.pickle" % libtbx.env.dispatcher_name

    parser = OptionParser(
        usage=usage,
        phil=phil_scope,
        read_reflections=True,
        read_experiments=True,
        check_format=False,
        epilog=help_message,
    )

    params, options = parser.parse_args(show_diff_phil=True)

    reflections = flatten_reflections(params.input.reflections)
    experiments = flatten_experiments(params.input.experiments)
    if len(reflections) == 0 or len(experiments) == 0:
        parser.print_help()
        return
    assert len(reflections) == 1
    assert len(experiments) == 1
    experiment = experiments[0]
    reflections = reflections[0]

    test_P1_crystal_indexing(reflections, experiment, params)
    test_crystal_pointgroup_symmetry(reflections, experiment, params)
示例#6
0
  def run(self):
    '''Execute the script.'''

    from dials.util.options import flatten_reflections, flatten_experiments

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=False)
    reflections = flatten_reflections(params.input.reflections)
    experiments = flatten_experiments(params.input.experiments)

    # Try to load the models and data
    nexp = len(experiments)
    if nexp == 0:
      print "No Experiments found in the input"
      self.parser.print_help()
      return
    if len(reflections) == 0:
      print "No reflection data found in the input"
      self.parser.print_help()
      return
    if len(reflections) > 1:
      raise Sorry("Only one reflections list can be imported at present")
    reflections = reflections[0] # first reflection list
    reflections = reflections.select(reflections['id'] == 0) # first experiment
    if len(reflections) == 0:
      print "No reflection data for the first experiment found in the input"
      self.parser.print_help()
      return
    if len(experiments) > 1:
      raise Sorry("Only one experiment can be imported at present")
    experiment = experiments[0]

    om = ObservationManager(reflections, experiment)

    gp_idx = om.group_index
示例#7
0
def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  import libtbx.load_env

  usage = "%s [options] datablock.json" %(
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_datablocks=True,
    read_experiments=True,
    check_format=True,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)
  datablocks = flatten_datablocks(params.input.datablock)
  experiments = flatten_experiments(params.input.experiments)

  if (len(datablocks) == 0 and len(experiments) == 0):
    parser.print_help()
    exit(0)

  if len(datablocks) == 0 and len(experiments) > 0:
    imagesets = experiments.imagesets()
  else:
    imagesets = []
    for datablock in datablocks:
      imagesets.extend(datablock.extract_imagesets())

  assert len(imagesets) == 1
  imageset = imagesets[0]
  gonio = imageset.get_goniometer()
  if not params.detector_distance:
    detector = imageset.get_detector()
    if len(detector) > 1:
      params.detector_distance = detector.hierarchy().get_directed_distance()
    else:
      params.detector_distance = detector[0].get_directed_distance()
  if params.angle:
    assert len(params.angle) == len(gonio.get_angles())
  else:
    for angle in gonio.get_angles():
      params.angle.append(angle)

  import wxtbx.app
  a = wxtbx.app.CCTBXApp(0)
  a.settings = params
  f = ExperimentViewer(
    None, -1, "Experiment viewer", size=(1024,768))
  f.load_imageset(imageset)
  f.Show()
  a.SetTopWindow(f)
  #a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f)
  a.MainLoop()
示例#8
0
文件: calc_rmsds.py 项目: dials/dials
def run(args):
  from dials.util import log
  import libtbx.load_env
  usage = "%s experiments.json indexed.pickle [options]" %libtbx.env.dispatcher_name


  from dials.util.options import OptionParser
  from dials.util.options import flatten_reflections
  from dials.util.options import flatten_experiments
  from dials.array_family import flex

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_experiments=True,
    read_reflections=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=False)

  # Configure the logging
  #log.config(info=params.output.log, debug=params.output.debug_log)

  from dials.util.version import dials_version
  logger.info(dials_version())

  # Log the diff phil
  diff_phil = parser.diff_phil.as_str()
  if diff_phil is not '':
    logger.info('The following parameters have been modified:\n')
    logger.info(diff_phil)

  experiments = flatten_experiments(params.input.experiments)
  reflections = flatten_reflections(params.input.reflections)
  assert(len(reflections) == 1)
  reflections = reflections[0]

  if len(experiments) == 0:
    parser.print_help()
    return

  #from dials.command_line import refine
  #params = refine.phil_scope.extract()
  indexed_reflections = reflections.select(reflections['id'] > -1)
  from dials.algorithms.refinement import RefinerFactory
  refiner = RefinerFactory.from_parameters_data_experiments(
    params, indexed_reflections, experiments)
  #refiner.run()
  rmsds = refiner.rmsds()
  import math
  xy_rmsds = math.sqrt(rmsds[0]**2 + rmsds[1]**2)

  print rmsds



  return
def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  from dials.util.options import flatten_reflections

  parser = OptionParser(
    phil=master_phil,
    read_datablocks=True,
    read_experiments=True,
    read_reflections=True,
    check_format=False)

  params, options = parser.parse_args(show_diff_phil=True)
  datablocks = flatten_datablocks(params.input.datablock)
  experiments = flatten_experiments(params.input.experiments)
  reflections = flatten_reflections(params.input.reflections)[0]
  if len(params.input.reflections) == 2:
    reflections2 = flatten_reflections(params.input.reflections)[1]
  else:
    reflections2 = None

  # find the reflections in the second set that DO NOT match those in the
  # first set
  mask, _ = reflections2.match_with_reference(reflections)
  reflections2 = reflections2.select(~mask)
  print "{0} reflections from the second set do not match the first". \
    format(len(reflections2))
  #reflections2 = reflections2.select(reflections2["miller_index"] == (-7,2,-25))

  if len(datablocks) == 0:
    if len(experiments) > 0:
      imagesets = experiments.imagesets()
    else:
      parser.print_help()
      return
  elif len(datablocks) > 1:
    raise Sorry("Only one DataBlock can be processed at a time")
  else:
    imagesets = datablocks[0].extract_imagesets()

  if len(imagesets) > 1:
    raise Sorry("Only one ImageSet can be processed at a time")
  imageset = imagesets[0]

  import wxtbx.app
  a = wxtbx.app.CCTBXApp(0)
  a.settings = params
  f = PredRelpViewer(
    None, -1, "Prediction reciprocal lattice viewer", size=(1024,768))
  f.load_reflections2(reflections2)
  f.load_models(imageset, reflections)
  f.Show()
  a.SetTopWindow(f)
  #a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f)
  a.MainLoop()
示例#10
0
def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  from dials.util.options import flatten_reflections
  import libtbx.load_env

  usage = "%s [options] datablock.json reflections.pickle" %(
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_datablocks=True,
    read_experiments=True,
    read_reflections=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)
  datablocks = flatten_datablocks(params.input.datablock)
  experiments = flatten_experiments(params.input.experiments)
  reflections = flatten_reflections(params.input.reflections)

  if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0:
    parser.print_help()
    exit(0)

  if len(datablocks) == 0 and len(experiments) > 0:
    imagesets = experiments.imagesets()
  else:
    imagesets = []
    for datablock in datablocks:
      imagesets.extend(datablock.extract_imagesets())

  if len(reflections) > 1:
    assert len(reflections) == len(imagesets)
    from scitbx.array_family import flex
    for i in range(len(reflections)):
      reflections[i]['imageset_id'] = flex.int(len(reflections[i]), i)
      if i > 0:
        reflections[0].extend(reflections[i])

  reflections = reflections[0]

  import wxtbx.app
  a = wxtbx.app.CCTBXApp(0)
  a.settings = params
  f = ReciprocalLatticeViewer(
    None, -1, "Reflection data viewer", size=(1024,768))
  f.load_models(imagesets, reflections)
  f.Show()
  a.SetTopWindow(f)
  #a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f)
  a.MainLoop()
  def run(self):
    params, options = self.parser.parse_args(show_diff_phil=True)
    experiments = flatten_experiments(params.input.experiments)

    detector = experiments[0].detector

    metro = map_detector_to_basis_dict(detector)
    write_cspad_cbf(None, metro, 'cbf', None, params.output_def_file, None, detector.hierarchy().get_distance(), header_only=True)

    print "Done"
示例#12
0
    def __call__(self):
        """
        Import the experiments
        """

        # Get the experiments
        experiments = flatten_experiments(self.params.input.experiments)

        # Check we have some filenames
        if len(experiments) == 0:

            # FIXME Should probably make this smarter since it requires editing here
            # and in dials.import phil scope
            try:
                format_kwargs = {
                    "dynamic_shadowing": self.params.format.dynamic_shadowing,
                    "multi_panel": self.params.format.multi_panel,
                }
            except AttributeError:
                format_kwargs = None

            # Check if a template has been set and print help if not, otherwise try to
            # import the images based on the template input
            if len(self.params.input.template) > 0:
                importer = ExperimentListTemplateImporter(
                    self.params.input.template,
                    image_range=self.params.geometry.scan.image_range,
                    format_kwargs=format_kwargs,
                )
                experiments = importer.experiments
                if len(experiments) == 0:
                    raise Sorry(
                        "No experiments found matching template %s"
                        % self.params.input.experiments
                    )
            elif len(self.params.input.directory) > 0:
                experiments = ExperimentListFactory.from_filenames(
                    self.params.input.directory, format_kwargs=format_kwargs
                )
                if len(experiments) == 0:
                    raise Sorry(
                        "No experiments found in directories %s"
                        % self.params.input.directory
                    )
            else:
                raise Sorry("No experiments found")

        if self.params.identifier_type:
            generate_experiment_identifiers(experiments, self.params.identifier_type)

        # Get a list of all imagesets
        imageset_list = experiments.imagesets()

        # Return the experiments
        return imageset_list
示例#13
0
    def run(self):
        ''' Parse the options. '''
        from dials.util.options import flatten_experiments, flatten_reflections
        # Parse the command line arguments
        params, options = self.parser.parse_args(show_diff_phil=True)
        experiments = flatten_experiments(params.input.experiments)
        reflections = flatten_reflections(params.input.reflections)
        assert len(reflections) == 1
        reflections = reflections[0]

        domain_size = flex.double()
        mosaic_angle = flex.double()
        filtered_reflections = flex.reflection_table()

        for i in range(len(experiments)):
            refls = reflections.select(reflections['id'] == i)
            try:
                nv = NaveParameters(params=None,
                                    experiments=experiments[i:i + 1],
                                    reflections=refls,
                                    refinery=None,
                                    graph_verbose=False)
                crystal_model_nv = nv()
            except Exception as e:
                continue
            domain_size.append(experiments[i].crystal.get_domain_size_ang() -
                               crystal_model_nv.get_domain_size_ang())
            mosaic_angle.append(
                experiments[i].crystal.get_half_mosaicity_deg() -
                crystal_model_nv.get_half_mosaicity_deg())
            experiments[i].crystal = crystal_model_nv

            refls = refls.select(nv.nv_acceptance_flags)
            filtered_reflections.extend(refls)

        print("Saving new experiments as %s" % params.output.experiments)
        dump = ExperimentListDumper(experiments)
        dump.as_json(params.output.experiments)

        print("Removed %d out of %d reflections as outliers" %
              (len(reflections) - len(filtered_reflections), len(reflections)))
        print("Saving filtered reflections as %s" % params.output.experiments)
        filtered_reflections.as_pickle(params.output.reflections)

        if params.plot_changes:
            from matplotlib import pyplot as plt
            domain_size = domain_size.select((domain_size >= -10)
                                             & (domain_size <= 10))
            mosaic_angle = mosaic_angle.select((mosaic_angle >= -0.1)
                                               & (mosaic_angle <= 0.1))

            for d in [domain_size, mosaic_angle]:
                f = plt.figure()
                plt.hist(d, bins=30)
            plt.show()
示例#14
0
    def run(self):
        """Execute the script."""
        # Parse the command line
        params, options = self.parser.parse_args(show_diff_phil=True)

        # Check the number of experiments
        experiments = flatten_experiments(params.input.experiments)
        if len(experiments) == 0:
            self.parser.print_help()
            return

        predicted_all = flex.reflection_table()

        for i_expt, expt in enumerate(experiments):
            if params.buffer_size > 0:
                # Hack to make the predicter predict reflections outside of the range
                # of the scan
                scan = expt.scan
                image_range = scan.get_image_range()
                oscillation = scan.get_oscillation()
                scan.set_image_range((
                    image_range[0] - params.buffer_size,
                    image_range[1] + params.buffer_size,
                ))
                scan.set_oscillation((
                    oscillation[0] - params.buffer_size * oscillation[1],
                    oscillation[1],
                ))

            # Populate the reflection table with predictions
            predicted = flex.reflection_table.from_predictions(
                expt, force_static=params.force_static, dmin=params.d_min)
            predicted["id"] = flex.int(len(predicted), i_expt)
            predicted_all.extend(predicted)

        # if we are not ignoring shadows, look for reflections in the masked
        # region, see https://github.com/dials/dials/issues/349

        if not params.ignore_shadows:
            shadowed = filter_shadowed_reflections(experiments,
                                                   predicted_all,
                                                   experiment_goniometer=True)
            predicted_all = predicted_all.select(~shadowed)

        try:
            predicted_all.compute_bbox(experiments)
        except Exception:
            pass

        # Save the reflections to file
        Command.start("Saving {0} reflections to {1}".format(
            len(predicted_all), params.output))
        predicted_all.as_file(params.output)
        Command.end("Saved {0} reflections to {1}".format(
            len(predicted_all), params.output))
示例#15
0
  def run(self):
    ''' Perform the integration. '''
    from dials.util.command_line import heading
    from dials.util.options import flatten_experiments
    from dials.util import log
    from time import time
    from libtbx.utils import Sorry
    from dials.array_family import flex

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=False)
    experiments = flatten_experiments(params.input.experiments)
    if len(experiments) == 0:
      self.parser.print_help()
      return

    assert len(experiments) == 1
    imageset = experiments[0].imageset
    beam = experiments[0].beam
    detector = experiments[0].detector
    goniometer = experiments[0].goniometer
    assert len(detector) == 1

    # Configure logging
    log.config()

    from dials.algorithms.background.gmodel import PolarTransform
    import cPickle as pickle
    model = pickle.load(open(params.model))
    image = model.data(0)
    mask = flex.bool(image.accessor(), True)

    # Do the transformation
    transform = PolarTransform(beam, detector[0], goniometer)
    result = transform.to_polar(image, mask)
    data = result.data()
    mask = result.mask()

    pickle.dump((data, mask), open(params.output.data, "w"))

    from matplotlib import pylab
    vmax = sorted(list(data))[int(0.99 * len(data))]
    figure = pylab.figure(figsize=(6,4))
    pylab.imshow(
      data.as_numpy_array(),
      interpolation = 'none',
      vmin          = 0,
      vmax          = vmax)
    ax1 = pylab.gca()
    ax1.get_xaxis().set_visible(False)
    ax1.get_yaxis().set_visible(False)
    cb = pylab.colorbar()
    cb.ax.tick_params(labelsize=8)
    logger.info("Saving polar model %s" % (params.output.image))
    pylab.savefig("%s" % (params.output.image), dpi=600, bbox_inches='tight')
示例#16
0
def run(args):
  import libtbx.load_env
  usage = "%s experiments.json [options]" %libtbx.env.dispatcher_name

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_experiments=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)
  experiments = flatten_experiments(params.input.experiments)
  if len(experiments) == 0:
    parser.print_help()
    return
  elif len(experiments) > 1:
    raise Sorry("More than one experiment present")

  assert len(params.miller_index), "Must specify at least one miller_index to predict."

  experiment = experiments[0]

  reflections = flex.reflection_table()
  miller_indices = flex.miller_index()
  entering_flags = flex.bool()
  for mi in params.miller_index:
    miller_indices.append(mi)
    miller_indices.append(mi)
    entering_flags.append(True)
    entering_flags.append(False)
  reflections['miller_index'] = miller_indices
  reflections['entering'] = entering_flags
  reflections['id'] = flex.size_t(len(reflections), 0)

  if params.expand_to_p1:
    from cctbx.miller import expand_to_p1_iselection
    proxy = expand_to_p1_iselection(
      experiment.crystal.get_space_group(),
      anomalous_flag=True,
      indices=miller_indices,
      build_iselection=True)
    reflections = reflections.select(proxy.iselection)
    reflections['miller_index'] = proxy.indices

  from dials.algorithms.refinement.prediction.managed_predictors import ExperimentsPredictor
  predictor = ExperimentsPredictor([experiment])
  predicted = predictor.predict(reflections)

  zmin, zmax = experiment.scan.get_array_range()
  z = predicted['xyzcal.px'].parts()[2]
  predicted = predicted.select((z >= zmin) & (z <= zmax))

  show_predictions(predicted)
示例#17
0
  def __init__(self, pickle_name, json_name):
    # load the integration.pickle file (reflection table) into memory and
    # load the experiments.json file (json) into memory, piecewise.
    # check_format=False because we don't wont to load any imagesets in the
    # experiement list
    importer = Importer([pickle_name, json_name], read_experiments=True, read_reflections=True, check_format=False)
    if importer.unhandled:
      print "unable to process:", importer.unhandled

    ConstructFrame.__init__(self, flatten_reflections(importer.reflections)[0],
                                  flatten_experiments(importer.experiments)[0])
示例#18
0
    def run(self):
        """
        Perform the integration.

        """
        from time import time

        # Check the number of arguments is correct
        start_time = time()

        # Parse the command line
        params, options = self.parser.parse_args(show_diff_phil=False)
        reflections = flatten_reflections(params.input.reflections)
        experiments = flatten_experiments(params.input.experiments)
        if len(reflections) == 0 or len(experiments) == 0:
            self.parser.print_help()
            return
        elif len(reflections) != 1:
            raise Sorry("more than 1 reflection file was given")
        elif len(experiments) == 0:
            raise Sorry("no experiment list was specified")
        reflections = reflections[0]

        # Configure logging
        if __name__ == "__main__":
            # Configure the logging
            log.config(verbosity=options.verbose, logfile="dials.potato.log")

        # Log the diff phil
        diff_phil = self.parser.diff_phil.as_str()
        if diff_phil is not "":
            logger.info("The following parameters have been modified:\n")
            logger.info(diff_phil)

        # Contruct the integrator
        integrator = Integrator(experiments, reflections, params)

        # Do cycles of indexing and refinement
        for i in range(params.refinement.n_macro_cycles):
            integrator.reindex_strong_spots()
            integrator.integrate_strong_spots()
            integrator.refine()

        # Do the integration
        integrator.predict()
        integrator.integrate()

        # Get the reflections
        reflections = integrator.reflections
        experiments = integrator.experiments

        # Save the reflections
        reflections.as_pickle(params.output.reflections)
        experiments.as_file(params.output.experiments)
示例#19
0
def run(args):
    from dials.util import log
    import libtbx.load_env
    usage = "%s experiments.json indexed.pickle [options]" % libtbx.env.dispatcher_name

    from dials.util.options import OptionParser
    from dials.util.options import flatten_reflections
    from dials.util.options import flatten_experiments

    parser = OptionParser(usage=usage,
                          phil=phil_scope,
                          read_experiments=True,
                          read_reflections=True,
                          check_format=False,
                          epilog=help_message)

    params, options = parser.parse_args(show_diff_phil=False)

    # Configure the logging
    #log.config(info=params.output.log, debug=params.output.debug_log)

    from dials.util.version import dials_version
    logger.info(dials_version())

    # Log the diff phil
    diff_phil = parser.diff_phil.as_str()
    if diff_phil is not '':
        logger.info('The following parameters have been modified:\n')
        logger.info(diff_phil)

    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)
    assert (len(reflections) == 1)
    reflections = reflections[0]

    if len(experiments) == 0:
        parser.print_help()
        return

    #from dials.command_line import refine
    #params = refine.phil_scope.extract()
    indexed_reflections = reflections.select(reflections['id'] > -1)
    from dials.algorithms.refinement import RefinerFactory
    refiner = RefinerFactory.from_parameters_data_experiments(
        params, indexed_reflections, experiments)
    #refiner.run()
    rmsds = refiner.rmsds()
    import math
    xy_rmsds = math.sqrt(rmsds[0]**2 + rmsds[1]**2)

    print rmsds

    return
示例#20
0
def run(args=None):
    """Run the script from the command-line."""
    usage = """Usage: dials.systematic_absences scaled.refl scaled.expt [options]"""

    parser = OptionParser(
        usage=usage,
        read_experiments=True,
        read_reflections=True,
        phil=phil_scope,
        check_format=False,
        epilog=help_message,
    )
    params, _ = parser.parse_args(args=args, show_diff_phil=False)

    if not params.input.experiments or not params.input.reflections:
        parser.print_help()
        sys.exit()

    reflections = flatten_reflections(params.input.reflections)
    experiments = flatten_experiments(params.input.experiments)

    log.config(verbosity=1, info=params.output.log)
    logger.info(dials_version())

    diff_phil = parser.diff_phil.as_str()
    if diff_phil != "":
        logger.info("The following parameters have been modified:\n")
        logger.info(diff_phil)

    ### Assert that all data have been scaled with dials - should only be
    # able to input one reflection table and experimentlist that are
    # matching and scaled together.
    if not len(reflections) == 1:
        raise Sorry("Only one reflection table can be given as input.")

    if (not "intensity.scale.value" in reflections[0]) and (
            not "intensity.prf.value" in reflections[0]):
        raise Sorry(
            "Unable to find integrated or scaled reflections in the reflection table."
        )

    try:
        run_sys_abs_checks(experiments, reflections, params.d_min)
    except ValueError as e:
        raise Sorry(e)

    if params.output.html:
        ScrewAxisObserver().generate_html_report(params.output.html)

    if params.output.experiments:
        dump = ExperimentListDumper(experiments)
        with open(params.output.experiments, "w") as outfile:
            outfile.write(dump.as_json(split=True))
示例#21
0
def run(args):
    from dials.util import Sorry
    from dials.util import log
    import six.moves.cPickle as pickle

    usage = "dials.find_hot_pixels [options] models.expt strong.refl"

    # Create the option parser
    parser = OptionParser(
        usage=usage,
        phil=phil_scope,
        read_reflections=True,
        read_experiments=True,
        check_format=False,
        epilog=help_message,
    )

    # Get the parameters
    params, options = parser.parse_args(show_diff_phil=False)

    # Configure the log
    log.config(verbosity=options.verbose, logfile="dials.find_hot_pixels.log")

    # Log the diff phil
    diff_phil = parser.diff_phil.as_str()
    if diff_phil != "":
        logger.info("The following parameters have been modified:\n")
        logger.info(diff_phil)

    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    if len(experiments) == 0 and len(reflections) == 0:
        parser.print_help()
        exit(0)

    if len(experiments) > 1:
        raise Sorry("Only one experiment can be processed at a time")
    else:
        imagesets = experiments.imagesets()
    if len(reflections) == 0:
        raise Sorry("No reflection lists found in input")
    if len(reflections) > 1:
        raise Sorry("Multiple reflections lists provided in input")

    assert len(reflections) == 1
    reflections = reflections[0]

    mask = hot_pixel_mask(imagesets[0], reflections)
    with open(params.output.mask, "wb") as fh:
        pickle.dump(mask, fh, pickle.HIGHEST_PROTOCOL)

    print("Wrote hot pixel mask to %s" % params.output.mask)
示例#22
0
文件: symmetry.py 项目: hattne/dials
def run(args):
    usage = "dials.symmetry [options] models.expt observations.refl"

    parser = OptionParser(
        usage=usage,
        phil=phil_scope,
        read_reflections=True,
        read_experiments=True,
        check_format=False,
        epilog=help_message,
    )

    params, _, args = parser.parse_args(args=args,
                                        show_diff_phil=False,
                                        return_unhandled=True)

    # Configure the logging
    log.config(params.verbosity,
               info=params.output.log,
               debug=params.output.debug_log)

    from dials.util.version import dials_version

    logger.info(dials_version())

    # Log the diff phil
    diff_phil = parser.diff_phil.as_str()
    if diff_phil != "":
        logger.info("The following parameters have been modified:\n")
        logger.info(diff_phil)

    if params.seed is not None:
        flex.set_random_seed(params.seed)
        random.seed(params.seed)

    if not params.input.experiments or not params.input.reflections:
        parser.print_help()
        sys.exit()

    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    reflections = parse_multiple_datasets(reflections)
    if len(experiments) != len(reflections):
        raise Sorry(
            "Mismatched number of experiments and reflection tables found: %s & %s."
            % (len(experiments), len(reflections)))
    try:
        experiments, reflections = assign_unique_identifiers(
            experiments, reflections)
        symmetry(experiments, reflections, params=params)
    except ValueError as e:
        raise Sorry(e)
示例#23
0
def run(args=None, phil=phil_scope):  # type: (List[str], libtbx.phil.scope) -> None
    """
    Check command-line input and call other functions to do the legwork.

    Run the script, parsing arguments found in 'args' and using the PHIL scope
    defined in 'phil'.

    Try to keep this function minimal, defining only what is necessary to run
    the program from the command line.

    Args:
        args: The arguments supplied by the user (default: sys.argv[1:])
        phil: The PHIL scope definition (default: phil_scope, the master PHIL scope
        for this program).
    """
    usage = "dials.command_name [options] imported.expt strong.refl"

    parser = OptionParser(
        usage=usage,
        phil=phil,
        read_reflections=True,
        read_experiments=True,
        check_format=False,
        epilog=__doc__,
    )

    params, options = parser.parse_args(args=args, show_diff_phil=False)

    # Configure the logging.
    dials.util.log.config(options.verbose, logfile=params.output.log)

    # Log the difference between the PHIL scope definition and the active PHIL scope,
    # which will include the parsed user inputs.
    diff_phil = parser.diff_phil.as_str()
    if diff_phil:
        logger.info("The following parameters have been modified:\n%s", diff_phil)

    # These functions are commonly used to collate the input.
    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    # You might well wish to check here that the command-line input is appropriate.
    if len(reflections) != 1:
        sys.exit("Exactly one reflection file needed.")
    if len(experiments) != 1:
        sys.exit("Exactly one experiment list required.")

    # Do whatever this program is supposed to do.
    experiments, reflections = do_boilerplate(experiments, reflections[0], params)

    # Do the file output here.
    logger.info("Writing the reflection table to %s", params.output.reflections)
    reflections.as_file(params.output.reflections)
示例#24
0
    def run(self):
        ''' Parse the options. '''
        from dials.util.options import flatten_experiments, flatten_reflections
        # Parse the command line arguments
        params, options = self.parser.parse_args(show_diff_phil=True)
        experiments = flatten_experiments(params.input.experiments)
        reflections = flatten_reflections(params.input.reflections)[0]

        filtered_experiments, filtered_reflections = run_with_preparsed(
            experiments, reflections, params)
        filtered_experiments.as_file(params.output.filtered_experiments)
        filtered_reflections.as_pickle(params.output.filtered_reflections)
示例#25
0
def run(args):

    from dials.util.options import OptionParser
    from dials.util.options import flatten_datablocks
    from dials.util.options import flatten_experiments
    from dials.util.options import flatten_reflections
    from dials.util import log

    usage = "%s [options] datablock.json reflections.pickle" % (
        libtbx.env.dispatcher_name
    )

    parser = OptionParser(
        usage=usage,
        phil=phil_scope,
        read_datablocks=True,
        read_experiments=True,
        read_reflections=True,
        check_format=False,
        epilog=help_message,
    )

    params, options = parser.parse_args()
    datablocks = flatten_datablocks(params.input.datablock)
    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0:
        parser.print_help()
        exit(0)

    ## Configure the logging
    # log.config(info='dials.rl_png.log')

    # Log the diff phil
    diff_phil = parser.diff_phil.as_str()
    if diff_phil is not "":
        logger.info("The following parameters have been modified:\n")
        logger.info(diff_phil)

    reflections = reflections[0]

    if len(datablocks) == 0 and len(experiments) > 0:
        imagesets = experiments.imagesets()
    else:
        imagesets = []
        for datablock in datablocks:
            imagesets.extend(datablock.extract_imagesets())

    f = ReciprocalLatticeJson(settings=params)
    f.load_models(imagesets, reflections)
    f.as_json(filename=params.output.json, compact=params.output.compact)
    print()
def run(args):

    from dials.util.options import OptionParser
    from dials.util.options import flatten_experiments
    import libtbx.load_env

    usage = "%s [options] experiments.json" % libtbx.env.dispatcher_name

    parser = OptionParser(usage=usage,
                          phil=phil_scope,
                          read_experiments=True,
                          check_format=False,
                          epilog=help_message)

    params, options = parser.parse_args(show_diff_phil=True)
    experiments = flatten_experiments(params.input.experiments)
    if len(experiments) <= 1:
        parser.print_help()
        return

    from dials.algorithms.indexing.compare_orientation_matrices import \
         difference_rotation_matrix_axis_angle
    crystals = []
    for experiment in experiments:
        crystal = experiment.crystal
        if params.space_group is not None:
            crystal.set_space_group(params.space_group.group())
        crystals.append(crystal)

    angles = flex.double()

    import math
    padding = int(math.ceil(math.log10(len(experiments))))
    output_template = '%s%%0%ii.json' % (params.output.prefix, padding)

    prev_expt = experiments[0]
    for i in range(1, len(experiments)):
        R_ij, axis, angle, cb_op = difference_rotation_matrix_axis_angle(
            prev_expt.crystal, experiments[i].crystal)
        angles.append(angle)
        #print i, angle
        if abs(angle) > params.max_deviation:
            continue
        experiments[i].crystal = experiments[i].crystal.change_basis(cb_op)
        prev_expt = experiments[i]

        from dxtbx.serialize import dump
        dump.experiment_list(experiments[i:i + 1], output_template % i)

    from matplotlib import pyplot
    n, bins, patches = pyplot.hist(angles.as_numpy_array(), 100)
    pyplot.show()
示例#27
0
    def run(self):
        '''Execute the script.'''

        from dials.util.options import flatten_reflections, flatten_experiments
        from libtbx.utils import Sorry
        from dials.array_family import flex

        # Parse the command line
        params, options = self.parser.parse_args(show_diff_phil=True)

        # Try to load the models and data
        if not params.input.experiments:
            print "No Experiments found in the input"
            self.parser.print_help()
            return
        if params.input.reflections:
            if len(params.input.reflections) != len(params.input.experiments):
                raise Sorry(
                    "The number of input reflections files does not match the "
                    "number of input experiments")

        experiments = flatten_experiments(params.input.experiments)
        if params.input.reflections:
            reflections = flatten_reflections(params.input.reflections)[0]
        else:
            reflections = None

        import math
        experiments_template = "%s_%%0%sd.json" % (
            params.output.experiments_prefix,
            int(math.floor(math.log10(len(experiments))) + 1))
        reflections_template = "%s_%%0%sd.pickle" % (
            params.output.reflections_prefix,
            int(math.floor(math.log10(len(experiments))) + 1))

        for i, experiment in enumerate(experiments):
            from dxtbx.model.experiment_list import ExperimentList
            from dxtbx.serialize import dump
            experiment_filename = experiments_template % i
            print 'Saving experiment %d to %s' % (i, experiment_filename)
            dump.experiment_list(ExperimentList([experiment]),
                                 experiment_filename)

            if reflections is not None:
                reflections_filename = reflections_template % i
                print 'Saving reflections for experiment %d to %s' % (
                    i, reflections_filename)
                ref_sel = reflections.select(reflections['id'] == i)
                ref_sel['id'] = flex.int(len(ref_sel), 0)
                ref_sel.as_pickle(reflections_filename)

        return
示例#28
0
def run(args):
    import dials.util.banner  # noqa: F401 - Importing means that it prints
    from dials.util.options import OptionParser
    from dials.util.options import flatten_experiments
    from dials.util.options import flatten_reflections

    usage = "dials.show [options] models.expt | image_*.cbf"

    parser = OptionParser(
        usage=usage,
        phil=phil_scope,
        read_experiments=True,
        read_experiments_from_images=True,
        read_reflections=True,
        check_format=False,
        epilog=help_message,
    )

    params, options = parser.parse_args(show_diff_phil=True)
    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    if len(experiments) == 0 and len(reflections) == 0:
        parser.print_help()
        exit()

    if len(experiments):
        if not all(e.detector for e in experiments):
            sys.exit("Error: experiment has no detector")
        if not all(e.beam for e in experiments):
            sys.exit("Error: experiment has no beam")
        print(
            show_experiments(
                experiments,
                show_scan_varying=params.show_scan_varying,
                show_image_statistics=params.show_image_statistics,
            )
        )

    if len(reflections):
        print(
            show_reflections(
                reflections,
                show_intensities=params.show_intensities,
                show_profile_fit=params.show_profile_fit,
                show_centroids=params.show_centroids,
                show_all_reflection_data=params.show_all_reflection_data,
                show_flags=params.show_flags,
                max_reflections=params.max_reflections,
                show_identifiers=params.show_identifiers,
            )
        )
示例#29
0
def main():
    parser = OptionParser(read_experiments=True, read_reflections=True)

    params, options = parser.parse_args(show_diff_phil=True)

    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    data = reflections[0]
    expt = experiments[0]
    data = data.select(data.get_flags(data.flags.integrated))

    # data = data.select(data['d'] > 2.0)

    z = data["xyzcal.px"].parts()[2]

    shoebox = data["shoebox"]

    # make a new reflection table, this one empty - then add columns for
    # every event in this set (with some shuffle) - flags = 32 apparently,
    # id == id above, intensity.sum.value=1 variance=1 n_signal=1 panel=panel
    # xyzobs.px.value = pixel + random.random() - 0.5 variance = 1/12 in each
    # direction - then map to reciprocal space

    events = flex.vec3_double()

    for s in shoebox:
        d = s.data
        k0, j0, i0 = s.bbox[0], s.bbox[2], s.bbox[4]
        k1, j1, i1 = d.focus()
        for k in range(k1):
            for j in range(j1):
                for i in range(i1):
                    for n in range(int(d[k, j, i])):
                        if random.random() > 0.1:
                            continue
                        z = k + k0 + random.random()
                        y = j + j0 + random.random()
                        x = i + i0 + random.random()
                        events.append((z, y, x))

    rt = flex.reflection_table()
    rt["xyzobs.px.value"] = events
    variance = flex.double(events.size(), 1.0 / 12.0)
    rt["xyzobs.px.variance"] = flex.vec3_double(variance, variance, variance)
    rt["flags"] = flex.size_t(events.size(), 32)
    rt["id"] = flex.int(events.size(), 0)
    rt["panel"] = flex.size_t(events.size(), 0)
    rt["intensity.sum.value"] = flex.double(events.size(), 1)
    rt["intensity.sum.variance"] = flex.double(events.size(), 1)
    rt.as_file("events.refl")
示例#30
0
def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  import libtbx.load_env

  usage = "%s [options] datablock.json | experiments.json" %(
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_datablocks=True,
    read_experiments=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)
  experiments = flatten_experiments(params.input.experiments)
  datablocks = flatten_datablocks(params.input.datablock)

  if len(experiments) == 0 and len(datablocks) == 0:
    parser.print_help()
    exit(0)

  from dials.command_line.dials_import import ManualGeometryUpdater
  update_geometry = ManualGeometryUpdater(params)


  if len(experiments):
    imagesets = experiments.imagesets()

  elif len(datablocks):

    assert len(datablocks) == 1
    imagesets = datablocks[0].extract_imageset()

  for imageset in imagesets:
    imageset_new = update_geometry(imageset)
    imageset.set_detector(imageset_new.get_detector())
    imageset.set_beam(imageset_new.get_beam())
    imageset.set_goniometer(imageset_new.get_goniometer())
    imageset.set_scan(imageset_new.get_scan())

  from dxtbx.serialize import dump
  if len(experiments):
    print "Saving modified experiments to %s" %params.output.experiments
    dump.experiment_list(experiments, params.output.experiments)
  elif len(datablocks):
    raise NotImplemented
示例#31
0
def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  from dials.util.options import flatten_reflections
  from dials.util import log

  usage = "%s [options] datablock.json reflections.pickle" %(
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_datablocks=True,
    read_experiments=True,
    read_reflections=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args()
  datablocks = flatten_datablocks(params.input.datablock)
  experiments = flatten_experiments(params.input.experiments)
  reflections = flatten_reflections(params.input.reflections)

  if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0:
    parser.print_help()
    exit(0)

  ## Configure the logging
  #log.config(info='dials.rl_png.log')

  # Log the diff phil
  diff_phil = parser.diff_phil.as_str()
  if diff_phil is not '':
    logger.info('The following parameters have been modified:\n')
    logger.info(diff_phil)

  reflections = reflections[0]

  if len(datablocks) == 0 and len(experiments) > 0:
    imagesets = experiments.imagesets()
  else:
    imagesets = []
    for datablock in datablocks:
      imagesets.extend(datablock.extract_imagesets())

  f = ReciprocalLatticeJson(settings=params)
  f.load_models(imagesets, reflections)
  f.as_json(filename=params.output.json, compact=params.output.compact)
  print
示例#32
0
def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  import libtbx.load_env

  usage = "%s [options] datablock.json | experiments.json" %(
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_datablocks=True,
    read_experiments=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)
  experiments = flatten_experiments(params.input.experiments)
  datablocks = flatten_datablocks(params.input.datablock)

  if len(experiments) == 0 and len(datablocks) == 0:
    parser.print_help()
    exit(0)

  from dials.command_line.dials_import import ManualGeometryUpdater
  update_geometry = ManualGeometryUpdater(params)

  if len(experiments):
    imagesets = experiments.imagesets()

  elif len(datablocks):

    assert len(datablocks) == 1
    imagesets = datablocks[0].extract_imagesets()

  for imageset in imagesets:
    imageset_new = update_geometry(imageset)
    imageset.set_detector(imageset_new.get_detector())
    imageset.set_beam(imageset_new.get_beam())
    imageset.set_goniometer(imageset_new.get_goniometer())
    imageset.set_scan(imageset_new.get_scan())

  from dxtbx.serialize import dump
  if len(experiments):
    print "Saving modified experiments to %s" %params.output.experiments
    dump.experiment_list(experiments, params.output.experiments)
  elif len(datablocks):
    print "Saving modified datablock to %s" %params.output.datablock
    dump.datablock(datablocks, params.output.datablock)
示例#33
0
文件: show.py 项目: kek-pf-mx/dials
def run(args):
    import dials.util.banner
    from dials.util.options import OptionParser
    from dials.util.options import flatten_experiments
    from dials.util.options import flatten_datablocks
    from dials.util.options import flatten_reflections
    import libtbx.load_env

    usage = "%s [options] datablock.json | experiments.json | image_*.cbf" % (
        libtbx.env.dispatcher_name)

    parser = OptionParser(usage=usage,
                          phil=phil_scope,
                          read_experiments=True,
                          read_datablocks=True,
                          read_datablocks_from_images=True,
                          read_reflections=True,
                          check_format=False,
                          epilog=help_message)

    params, options = parser.parse_args(show_diff_phil=True)
    experiments = flatten_experiments(params.input.experiments)
    datablocks = flatten_datablocks(params.input.datablock)
    reflections = flatten_reflections(params.input.reflections)

    if len(datablocks) == 0 and len(experiments) == 0 and len(
            reflections) == 0:
        parser.print_help()
        exit()

    if len(experiments):
        print(
            show_experiments(experiments,
                             show_panel_distance=params.show_panel_distance,
                             show_scan_varying=params.show_scan_varying))

    if len(datablocks):
        print(
            show_datablocks(datablocks,
                            show_panel_distance=params.show_panel_distance))

    if len(reflections):
        print(
            show_reflections(
                reflections,
                show_intensities=params.show_intensities,
                show_profile_fit=params.show_profile_fit,
                show_centroids=params.show_centroids,
                show_all_reflection_data=params.show_all_reflection_data,
                show_flags=params.show_flags,
                max_reflections=params.max_reflections))
def run(args):
  import libtbx.load_env
  from dials.array_family import flex
  from dials.util import log
  from dials.util.version import dials_version

  usage = "%s [options] experiment.json indexed.pickle" % \
    libtbx.env.dispatcher_name

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_reflections=True,
    read_experiments=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)

  # Configure the logging
  log.config(info=params.output.log, debug=params.output.debug_log)
  logger.info(dials_version())

  reflections = flatten_reflections(params.input.reflections)
  experiments = flatten_experiments(params.input.experiments)
  if len(reflections) == 0 or len(experiments) == 0:
    parser.print_help()
    return
  assert(len(reflections) == 1)
  assert(len(experiments) == 1)
  experiment = experiments[0]
  reflections = reflections[0]

  # remove reflections with 0, 0, 0 index
  zero = (reflections['miller_index'] == (0, 0, 0))
  logger.info('Removing %d unindexed reflections' % zero.count(True))
  reflections = reflections.select(~zero)

  h, k, l = reflections['miller_index'].as_vec3_double().parts()

  h = h.iround()
  k = k.iround()
  l = l.iround()

  logger.info('Range on h: %d to %d' % (flex.min(h), flex.max(h)))
  logger.info('Range on k: %d to %d' % (flex.min(k), flex.max(k)))
  logger.info('Range on l: %d to %d' % (flex.min(l), flex.max(l)))

  test_P1_crystal_indexing(reflections, experiment, params)
  test_crystal_pointgroup_symmetry(reflections, experiment, params)
def run(args):

    from dials.util.options import OptionParser
    from dials.util.options import flatten_datablocks
    from dials.util.options import flatten_experiments
    from dials.util.options import flatten_reflections
    import libtbx.load_env

    usage = "%s [options] datablock.json reflections.pickle" % (
        libtbx.env.dispatcher_name)

    parser = OptionParser(usage=usage,
                          phil=phil_scope,
                          read_datablocks=True,
                          read_experiments=True,
                          read_reflections=True,
                          check_format=False,
                          epilog=help_message)

    params, options = parser.parse_args(show_diff_phil=True)
    datablocks = flatten_datablocks(params.input.datablock)
    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    if (len(datablocks) == 0
            and len(experiments) == 0) or len(reflections) == 0:
        parser.print_help()
        exit(0)

    reflections = reflections[0]

    if len(datablocks) == 0 and len(experiments) > 0:
        imagesets = experiments.imagesets()
    else:
        imagesets = []
        for datablock in datablocks:
            imagesets.extend(datablock.extract_imagesets())

    import wxtbx.app
    a = wxtbx.app.CCTBXApp(0)
    a.settings = params
    f = DiffractionGeometryViewer(None,
                                  -1,
                                  "Diffraction Geometry viewer",
                                  size=(1024, 768))
    f.load_models(imagesets, reflections)
    f.Show()
    a.SetTopWindow(f)
    #a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f)
    a.MainLoop()
示例#36
0
def run(args):
  import libtbx.load_env
  from dials.array_family import flex
  from dials.util import log
  from dials.util.version import dials_version

  usage = "%s [options] experiment.json indexed.pickle" % \
    libtbx.env.dispatcher_name

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_reflections=True,
    read_experiments=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)

  # Configure the logging
  log.config(info=params.output.log, debug=params.output.debug_log)
  logger.info(dials_version())

  reflections = flatten_reflections(params.input.reflections)
  experiments = flatten_experiments(params.input.experiments)
  if len(reflections) == 0 or len(experiments) == 0:
    parser.print_help()
    return
  assert(len(reflections) == 1)
  assert(len(experiments) == 1)
  experiment = experiments[0]
  reflections = reflections[0]

  # remove reflections with 0, 0, 0 index
  zero = (reflections['miller_index'] == (0, 0, 0))
  logger.info('Removing %d unindexed reflections' % zero.count(True))
  reflections = reflections.select(~zero)

  h, k, l = reflections['miller_index'].as_vec3_double().parts()

  h = h.iround()
  k = k.iround()
  l = l.iround()

  logger.info('Range on h: %d to %d' % (flex.min(h), flex.max(h)))
  logger.info('Range on k: %d to %d' % (flex.min(k), flex.max(k)))
  logger.info('Range on l: %d to %d' % (flex.min(l), flex.max(l)))

  test_P1_crystal_indexing(reflections, experiment, params)
  test_crystal_pointgroup_symmetry(reflections, experiment, params)
 def __init__(self, refl_name, json_name, outname=None):
   # load the integration.pickle file (reflection table) into memory and
   # load the experiments.json file (json) into memory, piecewise.
   # check_format=False because we don't wont to load any imagesets in the
   # experiement list
   importer = Importer([refl_name, json_name], read_experiments=True, read_reflections=True, check_format=False)
   if importer.unhandled:
     print "unable to process:", importer.unhandled
   reflections_l = flatten_reflections(importer.reflections)
   experiments_l = flatten_experiments(importer.experiments)
   assert len(experiments_l) == 1, "cannot construct a single frame from multiple experiments"
   frame = ConstructFrame.__init__(self, reflections_l[0], experiments_l[0])
   if frame is not None:
     self.frame.make_frame()
示例#38
0
  def run(self):
    '''Execute the script.'''

    from dials.util.options import flatten_reflections, flatten_experiments
    from libtbx.utils import Sorry
    from dials.array_family import flex

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=True)

    # Try to load the models and data
    if not params.input.experiments:
      print "No Experiments found in the input"
      self.parser.print_help()
      return
    if params.input.reflections:
      if len(params.input.reflections) != len(params.input.experiments):
        raise Sorry("The number of input reflections files does not match the "
          "number of input experiments")

    experiments = flatten_experiments(params.input.experiments)
    if params.input.reflections:
      reflections = flatten_reflections(params.input.reflections)[0]
    else:
      reflections = None

    import math
    experiments_template = "%s_%%0%sd.json" %(
      params.output.experiments_prefix,
      int(math.floor(math.log10(len(experiments))) + 1))
    reflections_template = "%s_%%0%sd.pickle" %(
      params.output.reflections_prefix,
      int(math.floor(math.log10(len(experiments))) + 1))

    for i, experiment in enumerate(experiments):
      from dxtbx.model.experiment.experiment_list import ExperimentList
      from dxtbx.serialize import dump
      experiment_filename = experiments_template %i
      print 'Saving experiment %d to %s' %(i, experiment_filename)
      dump.experiment_list(ExperimentList([experiment]), experiment_filename)

      if reflections is not None:
        reflections_filename = reflections_template %i
        print 'Saving reflections for experiment %d to %s' %(i, reflections_filename)
        ref_sel = reflections.select(reflections['id'] == i)
        ref_sel['id'] = flex.int(len(ref_sel), 0)
        ref_sel.as_pickle(reflections_filename)

    return
示例#39
0
def run(phil=working_phil, args=None):
    usage = "dials.index [options] models.expt strong.refl"

    parser = OptionParser(
        usage=usage,
        phil=phil,
        read_reflections=True,
        read_experiments=True,
        check_format=False,
        epilog=help_message,
    )

    params, options = parser.parse_args(args=args, show_diff_phil=False)

    # Configure the logging
    log.config(verbosity=options.verbose, logfile=params.output.log)
    logger.info(dials_version())

    # Log the diff phil
    diff_phil = parser.diff_phil.as_str()
    if diff_phil != "":
        logger.info("The following parameters have been modified:\n")
        logger.info(diff_phil)

    experiments = flatten_experiments(params.input.experiments)
    reflections = flatten_reflections(params.input.reflections)

    if len(experiments) == 0:
        parser.print_help()
        return

    try:
        indexed_experiments, indexed_reflections = index(
            experiments, reflections, params)
    except (DialsIndexError, ValueError) as e:
        sys.exit(str(e))

    # Save experiments
    if params.output.split_experiments:
        logger.info("Splitting experiments before output")
        indexed_experiments = ExperimentList(
            [copy.deepcopy(re) for re in indexed_experiments])
    logger.info("Saving refined experiments to %s" % params.output.experiments)
    assert indexed_experiments.is_consistent()
    indexed_experiments.as_file(params.output.experiments)

    # Save reflections
    logger.info("Saving refined reflections to %s" % params.output.reflections)
    indexed_reflections.as_msgpack_file(filename=params.output.reflections)
示例#40
0
def run(args=None):
    import wx  # It is unclear why, but it is crucial that wx

    # is imported before the parser is run.
    # Otherwise viewer will crash when run with
    # .cbf image as parameter on linux with wxPython>=3
    # The problem can be traced to
    # dxtbx/format/FormatCBFFull.py:49
    #  ''' from iotbx.detectors.cbf import CBFImage '''
    # and the wx import must happen before that import.
    WX3 = wx.VERSION[0] == 3
    if not WX3:
        # HACK: Monkeypatch this renamed function so we can trick wxtbx's IntCtrl
        #       without having to alter the package
        wx.SystemSettings_GetColour = wx.SystemSettings.GetColour

    dials.util.log.print_banner()
    usage_message = "dials.image_viewer models.expt [observations.refl]"
    parser = OptionParser(
        usage=usage_message,
        phil=phil_scope,
        read_experiments=True,
        read_reflections=True,
        read_experiments_from_images=True,
        epilog=help_message,
    )
    params, options = parser.parse_args(args, show_diff_phil=True)
    experiments = [x.data for x in params.input.experiments]
    reflections = flatten_reflections(params.input.reflections)

    if len(experiments) == 0:
        parser.print_help()
        exit(0)

    flat_expts = flatten_experiments(params.input.experiments)
    if params.load_models:
        if any(e.detector is None for e in flat_expts):
            sys.exit("Error: experiment has no detector")
        if any(e.beam is None for e in flat_expts):
            sys.exit("Error: experiment has no beam")

    # If given a mask, replace the path with the loaded data
    if params.mask is not None:
        with open(params.mask, "rb") as f:
            params.mask = pickle.load(f)

    show_image_viewer(params=params,
                      reflections=reflections,
                      experiments=experiments)
示例#41
0
    def run(self, args=None):
        # Parse the command line
        params, options = self.parser.parse_args(args, show_diff_phil=True)

        if not params.rs_mapper.map_file:
            raise RuntimeError("Please specify output map file (map_file=)")
        else:
            self.map_file = params.rs_mapper.map_file

        # Ensure we have either a data block or an experiment list
        self.experiments = flatten_experiments(params.input.experiments)
        if len(self.experiments) != 1:
            self.parser.print_help()
            print("Please pass either an experiment list\n")
            return

        self.reverse_phi = params.rs_mapper.reverse_phi
        self.grid_size = params.rs_mapper.grid_size
        self.max_resolution = params.rs_mapper.max_resolution
        self.ignore_mask = params.rs_mapper.ignore_mask

        self.grid = flex.double(
            flex.grid(self.grid_size, self.grid_size, self.grid_size), 0
        )
        self.counts = flex.int(
            flex.grid(self.grid_size, self.grid_size, self.grid_size), 0
        )

        for experiment in self.experiments:
            self.process_imageset(experiment.imageset)

        recviewer.normalize_voxels(self.grid, self.counts)

        # Let's use 1/(100A) as the unit so that the absolute numbers in the
        # "cell dimensions" field of the ccp4 map are typical for normal
        # MX maps. The values in 1/A would give the "cell dimensions" around
        # or below 1 and some MX programs would not handle it well.
        box_size = 100 * 2.0 / self.max_resolution
        uc = uctbx.unit_cell((box_size, box_size, box_size, 90, 90, 90))
        ccp4_map.write_ccp4_map(
            self.map_file,
            uc,
            sgtbx.space_group("P1"),
            (0, 0, 0),
            self.grid.all(),
            self.grid,
            flex.std_string(["cctbx.miller.fft_map"]),
        )
示例#42
0
def data_from_pickle_and_json():
    from dials.util.options import (
        OptionParser,
        flatten_reflections,
        flatten_experiments,
    )

    help_message = """

  Generates a dials.array_family.flex.reflection_table and a
  dxtbx.model.experiment_list.ExperimentList from a observations.refl and a
  models.expt.

  Examples:

    dials.util.intensity_explorer indexed.refl indexed.expt

    dials.util.intensity_explorer integrated.refl integrated.expt

    """

    # Create the parser
    usage = (
        "usage: dials.util.intensity_explorer [options] "
        "observations.refl models.expt"
    )
    parser = OptionParser(
        usage=usage,
        read_reflections=True,
        read_experiments=True,
        check_format=True,
        epilog=help_message,
    )

    # Parse the command line arguments
    params, options = parser.parse_args(show_diff_phil=True)

    # Show the help
    if len(params.input.reflections) != 1 or len(params.input.experiments) != 1:
        parser.print_help()
        exit(0)

    rtable = flatten_reflections(params.input.reflections)
    elist = flatten_experiments(params.input.experiments)

    rtable.del_selected(rtable["intensity.sum.variance"] <= 0)

    return rtable, elist
示例#43
0
  def run(self):
    '''Execute the script.'''
    from dials.util.command_line import Command
    from dials.array_family import flex
    from dials.util.options import flatten_experiments

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=True)

    # Check the number of experiments
    experiments = flatten_experiments(params.input.experiments)
    if len(experiments) == 0:
      self.parser.print_help()
      return

    predicted_all = flex.reflection_table()

    for i_expt, expt in enumerate(experiments):
      if params.buffer_size > 0:
        # Hack to make the predicter predict reflections outside of the range
        # of the scan
        scan = expt.scan
        image_range = scan.get_image_range()
        oscillation = scan.get_oscillation()
        scan.set_image_range((image_range[0]-params.buffer_size,
                              image_range[1]+params.buffer_size))
        scan.set_oscillation((oscillation[0]-params.buffer_size*oscillation[1],
                              oscillation[1]))

      # Populate the reflection table with predictions
      predicted = flex.reflection_table.from_predictions(
        expt,
        force_static=params.force_static,
        dmin=params.d_min)
      predicted['id'] = flex.int(len(predicted), i_expt)
      predicted_all.extend(predicted)

    try:
      predicted_all.compute_bbox(experiments)
    except Exception:
      pass

    # Save the reflections to file
    Command.start('Saving {0} reflections to {1}'.format(
        len(predicted_all), params.output))
    predicted_all.as_pickle(params.output)
    Command.end('Saved {0} reflections to {1}'.format(
        len(predicted_all), params.output))
示例#44
0
    def run(self):
        params, options = self.parser.parse_args(show_diff_phil=True)
        datablocks = flatten_datablocks(params.input.datablock)
        experiments = flatten_experiments(params.input.experiments)
        reflections = flatten_reflections(params.input.reflections)
        if len(reflections) > 0:
            reflections = reflections[0]
        else:
            reflections = None

        all_detectors = []
        for db in datablocks:
            all_detectors.extend(db.unique_detectors())

        all_detectors.extend(experiments.detectors())
        display_detectors(all_detectors[: min(len(all_detectors), 10)], reflections=reflections)
    def run(self):
        """Execute the script."""

        from dials.util.options import flatten_experiments
        from dials.util import Sorry
        from dials.array_family import flex

        # Parse the command line
        params, options = self.parser.parse_args(show_diff_phil=True)

        # Try to load the experiments
        if not params.input.experiments:
            print("No Experiments found in the input")
            self.parser.print_help()
            return

        experiments = flatten_experiments(params.input.experiments)
        print("{0} experiments loaded".format(len(experiments)))

        us0_vecs = self.extract_us0_vecs(experiments)
        e_vecs = self.extract_rotation_axes(experiments)

        angles = [us0.angle(e, deg=True) for us0, e in zip(us0_vecs, e_vecs)]

        fmt = "{:." + str(params.print_precision) + "f}"
        header = ["Exp\nid", "Beam direction", "Rotation axis", "Angle (deg)"]
        rows = []
        for iexp, (us0, e, ang) in enumerate(zip(us0_vecs, e_vecs, angles)):
            beam_str = " ".join([fmt] * 3).format(*us0.elems)
            e_str = " ".join([fmt] * 3).format(*e.elems)
            rows.append([str(iexp), beam_str, e_str, fmt.format(ang)])
        if len(rows) > 0:
            st = simple_table(rows, header)
            print(st.format())

        # mean and sd
        if len(rows) > 1:
            angles = flex.double(angles)
            mv = flex.mean_and_variance(angles)

            print("Mean and standard deviation of the angle")
            print(
                fmt.format(mv.mean()) + " +/- " +
                fmt.format(mv.unweighted_sample_standard_deviation()))
            print()

        return
示例#46
0
    def run(self):
        '''Execute the script.'''
        from dials.util.command_line import Command
        from dials.array_family import flex
        from dials.util.options import flatten_experiments

        # Parse the command line
        params, options = self.parser.parse_args(show_diff_phil=True)

        # Check the number of experiments
        experiments = flatten_experiments(params.input.experiments)
        if len(experiments) == 0:
            self.parser.print_help()
            return

        predicted_all = flex.reflection_table()

        for i_expt, expt in enumerate(experiments):
            if params.buffer_size > 0:
                # Hack to make the predicter predict reflections outside of the range
                # of the scan
                scan = expt.scan
                image_range = scan.get_image_range()
                oscillation = scan.get_oscillation()
                scan.set_image_range((image_range[0] - params.buffer_size,
                                      image_range[1] + params.buffer_size))
                scan.set_oscillation(
                    (oscillation[0] - params.buffer_size * oscillation[1],
                     oscillation[1]))

            # Populate the reflection table with predictions
            predicted = flex.reflection_table.from_predictions(
                expt, force_static=params.force_static, dmin=params.d_min)
            predicted['id'] = flex.int(len(predicted), i_expt)
            predicted_all.extend(predicted)

        try:
            predicted_all.compute_bbox(experiments)
        except Exception:
            pass

        # Save the reflections to file
        Command.start('Saving {0} reflections to {1}'.format(
            len(predicted_all), params.output))
        predicted_all.as_pickle(params.output)
        Command.end('Saved {0} reflections to {1}'.format(
            len(predicted_all), params.output))
示例#47
0
    def run(self):
        params, options = self.parser.parse_args(show_diff_phil=True)
        datablocks = flatten_datablocks(params.input.datablock)
        experiments = flatten_experiments(params.input.experiments)
        reflections = flatten_reflections(params.input.reflections)
        if len(reflections) > 0:
            reflections = reflections[0]
        else:
            reflections = None

        all_detectors = []
        for db in datablocks:
            all_detectors.extend(db.unique_detectors())

        all_detectors.extend(experiments.detectors())
        display_detectors(all_detectors[:min(len(all_detectors), 10)],
                          reflections=reflections)
示例#48
0
  def run(self):
    '''Execute the script.'''

    from dials.util.options import flatten_experiments
    from libtbx.utils import Sorry
    from dials.array_family import flex

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=True)

    # Try to load the experiments
    if not params.input.experiments:
      print "No Experiments found in the input"
      self.parser.print_help()
      return

    experiments = flatten_experiments(params.input.experiments)
    print "{0} experiments loaded".format(len(experiments))

    us0_vecs = self.extract_us0_vecs(experiments)
    e_vecs = self.extract_rotation_axes(experiments)

    angles = [us0.angle(e, deg=True) for us0, e in zip(us0_vecs, e_vecs)]

    fmt = "{:." + str(params.print_precision) + "f}"
    header = ['Exp\nid','Beam direction', 'Rotation axis', 'Angle (deg)']
    rows = []
    for iexp, (us0, e, ang) in enumerate(zip(us0_vecs, e_vecs, angles)):
      beam_str = " ".join([fmt] * 3).format(*us0.elems)
      e_str = " ".join([fmt] * 3).format(*e.elems)
      rows.append([str(iexp), beam_str, e_str, fmt.format(ang)])
    if len(rows) > 0:
      st = simple_table(rows, header)
      print st.format()

    # mean and sd
    if len(rows) > 1:
      angles = flex.double(angles)
      mv = flex.mean_and_variance(angles)

      print "Mean and standard deviation of the angle"
      print (fmt.format(mv.mean()) + " +/- " + fmt.format(
        mv.unweighted_sample_standard_deviation()))
      print

    return
示例#49
0
    def run(self):
        params, options = self.parser.parse_args(show_diff_phil=True)
        experiments = flatten_experiments(params.input.experiments)

        detector = experiments[0].detector

        metro = map_detector_to_basis_dict(detector)
        write_cspad_cbf(None,
                        metro,
                        'cbf',
                        None,
                        params.output_def_file,
                        None,
                        detector.hierarchy().get_distance(),
                        header_only=True)

        print("Done")
示例#50
0
  def run(self):
    """lurrr"""
    from dials.util.options import flatten_experiments

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=True, args=None)
    experiments = flatten_experiments(params.input.experiments)
    if len(experiments) == 0:
      print "No experiments given"
      return
    elif len(experiments.imagesets()) > 1 or len(experiments.detectors()) > 1:
      raise RuntimeError('experiment list contains > 1 imageset or detector')

    params.prediction.dmin = 0.67
    params.prediction.dmax = 23
    if (params.prediction.dmin is None) or (params.prediction.dmax is None):
      integrated = pickle.load(open('/home/wra62962/local/testsets/Ni_dppe_NO2_2.dials.sweep3/integrated.pickle', 'rb'))
      #integrated = pickle.load(open('/home/wra62962/local/testsets/TestsetMX.300.dials/integrated.pickle', 'rb'))
      if params.prediction.dmin is None:
        params.prediction.dmin = min(integrated["d"])
      if params.prediction.dmax is None:
        params.prediction.dmax = max(integrated["d"])

    print "Considering reflections with resolution %.2f - %.2f Ang" % (params.prediction.dmin, params.prediction.dmax)

    evaluator = self.StrategyEvaluator(experiments,
                                       self.SimpleGeometricEvaluationFunctionFactory,
                                       #self.SimpleEvaluationFunctionFactory,
                                       params.prediction.dmin,
                                       params.prediction.dmax)

    strategylist = self.getFixedStrategylist()
    results = []

    for strategy in strategylist:
      print
      print "%s strategy: " % strategy['name']
      quality = evaluator(strategy['strategy'])
      quality['name'] = strategy['name']
      results.append(quality)

    print "%30s   Comp   Mul  Score  Sweep  Sc/deg" % "Strategy"
    for r in sorted(results, key=(lambda x: x['score']), reverse=True):
      print "%30s: %5.1f  %4.1f  %5d  %4d%s  %5.1f" %\
            (r['name'], r['completeness'], r['multiplicity'], r['score'], r['degrees'], " deg",
             r['score'] / r['degrees'])
示例#51
0
def run(args):
  import libtbx.load_env
  usage = """\
%s datablock.json reflections.pickle [options]""" %libtbx.env.dispatcher_name
  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  from dials.util.options import flatten_reflections
  from scitbx.array_family import flex
  from scitbx import matrix
  from libtbx.phil import command_line
  from libtbx.utils import Sorry
  parser = OptionParser(
    usage=usage,
    phil=master_phil_scope,
    read_datablocks=True,
    read_experiments=True,
    read_reflections=True,
    check_format=False)

  params, options = parser.parse_args(show_diff_phil=True)
  datablocks = flatten_datablocks(params.input.datablock)
  reflections = flatten_reflections(params.input.reflections)
  experiments = flatten_experiments(params.input.experiments)
  if len(datablocks) == 1:
    imageset = datablocks[0].extract_imagesets()[0]
  elif len(datablocks) > 1:
    raise Sorry("Only one DataBlock can be processed at a time")
  elif len(experiments.imagesets()) > 0:
    imageset = experiments.imagesets()[0]
    imageset.set_detector(experiments[0].detector)
    imageset.set_beam(experiments[0].beam)
    imageset.set_goniometer(experiments[0].goniometer)
  else:
    parser.print_help()
    return

  detector = imageset.get_detector()
  scan = imageset.get_scan()

  panel_origin_shifts = {0: (0,0,0)}
  try:
    hierarchy = detector.hierarchy()
  except AttributeError, e:
    hierarchy = None
示例#52
0
def matrixForFilename(filename, output):
	rootname_stem = rootnameStem(filename)
	
	arguments = []
	arguments.append(filename)

	from dials.util.options import OptionParser
	from dials.util.options import flatten_experiments
	from libtbx.utils import Abort

	parser = OptionParser(
	read_experiments=True,
	check_format=False)

	params, options = parser.parse_args(args=arguments, show_diff_phil=True)
	experiments = flatten_experiments(params.input.experiments)

	printExperiments(experiments, filename, output)
示例#53
0
文件: gen.py 项目: cppxfel/cppxfel
def matrixForFilename(filename, output):
	arguments = []
	arguments.append(filename)

	from dials.util.options import OptionParser
	from dials.util.options import flatten_experiments
	from libtbx.utils import Abort

	parser = OptionParser(
	read_experiments=True,
	check_format=False)

	params, options = parser.parse_args(args=arguments, show_diff_phil=True)
	experiments = flatten_experiments(params.input.experiments)

	path = experiments[0].imageset.get_path(0)
	print "Image", path, "has", len(experiments), "experiments."
	printExperiments(experiments, filename, output)
 def __init__(self, path, json=None, pickle_ext=None, json_ext=None):
   if json is None:
     json = find_json(path, pickle_ext, json_ext)
   if json is None:
     importer = Importer([path], read_experiments=False, read_reflections=True, check_format=False)
     print "unable to find experiment list"
     self.experiments = None
   else:
     importer = Importer([path, json], read_experiments=True, read_reflections=True, check_format=False)
     try:
       self.experiments = flatten_experiments(importer.experiments)[0]
     except IndexError:
       print "unable to read experiment list"
       self.experiments = None
   try:
     self.reflections = flatten_reflections(importer.reflections)[0]
   except IndexError:
     print "unable to read reflection table"
     self.reflections = None
示例#55
0
  def run(self):
    '''Execute the script.'''
    from dials.util.command_line import Command
    from dials.array_family import flex
    from dials.util.options import flatten_experiments

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=True)

    # Check the number of experiments is at least 2
    experiments = flatten_experiments(params.input.experiments)
    if len(experiments) < 2:
      self.parser.print_help()
      return

    detectors = [experiment.detector[0] for experiment in experiments]

    from itertools import combinations

    for pair in combinations(detectors, 2):
      determine_axis(pair, params)
示例#56
0
  def run(self):
    ''' Analyse the background '''
    from dials.util.command_line import heading
    from dials.util.options import flatten_experiments
    from dials.util import log
    from logging import info, debug
    from time import time
    from libtbx.utils import Sorry

    # Parse the command line
    params, options = self.parser.parse_args(show_diff_phil=False)
    experiments = flatten_experiments(params.input.experiments)
    if len(experiments) == 0:
      self.parser.print_help()
      return

    assert len(experiments) == 1

    # Get the imageset
    imageset = experiments[0].imageset

    total_image = None
    total_mask = None
    for i in range(len(imageset)):
      print i
      image = imageset.get_raw_data(i)
      mask = imageset.get_mask(i)
      if total_image is None:
        total_image = image[0]
        total_mask = mask[0]
      else:
        total_image += image[0]
    total_image /= len(imageset)
    print min(total_image)
    print max(total_image)
    print sum(total_image) / len(total_image)

    from matplotlib import pylab
    pylab.imshow(total_image.as_numpy_array(), vmin=0,vmax=2)
    pylab.show()
示例#57
0
def run(args):

  from dials.util.options import OptionParser
  from dials.util.options import flatten_datablocks
  from dials.util.options import flatten_experiments
  from dials.util.options import flatten_reflections
  import libtbx.load_env

  usage = "%s [options] datablock.json reflections.pickle" %(
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    read_datablocks=True,
    read_experiments=True,
    read_reflections=True,
    check_format=False,
    epilog=help_message)

  params, options = parser.parse_args(show_diff_phil=True)
  datablocks = flatten_datablocks(params.input.datablock)
  experiments = flatten_experiments(params.input.experiments)
  reflections = flatten_reflections(params.input.reflections)

  if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0:
    parser.print_help()
    exit(0)

  reflections = reflections[0]

  if len(datablocks) == 0 and len(experiments) > 0:
    imagesets = experiments.imagesets()
  else:
    imagesets = []
    for datablock in datablocks:
      imagesets.extend(datablock.extract_imagesets())

  spot_resolution_shells(imagesets, reflections, params)
示例#58
0
  def run(self):
    # load at least two detectors from the command line
    params, options = self.parser.parse_args(show_diff_phil=True)
    datablocks  = flatten_datablocks(params.input.datablock)
    experiments = flatten_experiments(params.input.experiments)

    # collect all detectors found
    all_detectors = []
    for db in datablocks:
      all_detectors.extend(db.unique_detectors())

    all_detectors.extend(experiments.detectors())

    assert len(all_detectors) >= 2

    a = all_detectors[0]
    b = all_detectors[1]

    level = 0
    pga = a.hierarchy()
    pgb = b.hierarchy()

    while True:
      # starting at the top of the hierarchy, show diffs in local origins at each level
      print "Level", level
      oa = col(pga.get_local_origin())
      ob = col(pgb.get_local_origin())

      print "  Detector a", oa.elems
      print "  Detector b", ob.elems
      print "  Diffs", (ob-oa).elems

      if hasattr(pga, 'children'):
        pga = pga[0]
        pgb = pgb[0]
        level += 1
      else:
        break