Beispiel #1
0
def generate_spots(crystal_model, detector, beam, goniometer=None, scan=None,
                   sel_fraction=1.0):
  import math

  experiment = Experiment(beam=beam,
                          detector=detector,
                          goniometer=goniometer,
                          scan=scan,
                          crystal=crystal_model)

  # if we don't set the imageset then from_predictions uses the StillsReflectionPredictor :-(
  from dxtbx.imageset import NullReader, ImageSweep
  imageset = ImageSweep(NullReader, indices=range(len(scan.get_epochs())), beam=beam, goniometer=goniometer,
                        detector=detector, scan=scan)
  experiment.imageset = imageset

  predicted = flex.reflection_table.from_predictions(experiment)

  sel = flex.random_selection(len(predicted),
                              int(math.floor(sel_fraction*len(predicted))))
  predicted = predicted.select(sel)
  predicted['imageset_id'] = flex.size_t(len(predicted), 0)
  predicted['xyzobs.px.value'] = predicted['xyzcal.px']
  predicted['xyzobs.px.variance'] = flex.vec3_double(
    len(predicted), (0.5,0.5,0.5))
  return predicted
Beispiel #2
0
def generate_spots(crystal_model,
                   detector,
                   beam,
                   goniometer=None,
                   scan=None,
                   sel_fraction=1.0):
    import math

    experiment = Experiment(beam=beam,
                            detector=detector,
                            goniometer=goniometer,
                            scan=scan,
                            crystal=crystal_model)

    # if we don't set the imageset then from_predictions uses the StillsReflectionPredictor :-(
    from dxtbx.imageset import NullReader, ImageSweep
    imageset = ImageSweep(NullReader,
                          indices=range(len(scan.get_epochs())),
                          beam=beam,
                          goniometer=goniometer,
                          detector=detector,
                          scan=scan)
    experiment.imageset = imageset

    predicted = flex.reflection_table.from_predictions(experiment)

    sel = flex.random_selection(len(predicted),
                                int(math.floor(sel_fraction * len(predicted))))
    predicted = predicted.select(sel)
    predicted['imageset_id'] = flex.size_t(len(predicted), 0)
    predicted['xyzobs.px.value'] = predicted['xyzcal.px']
    predicted['xyzobs.px.variance'] = flex.vec3_double(len(predicted),
                                                       (0.5, 0.5, 0.5))
    return predicted
Beispiel #3
0
    def split_for_scan_range(self, experiments, reference, scan_range):
        """ Update experiments when scan range is set. """
        from dxtbx.model.experiment.experiment_list import ExperimentList
        from dxtbx.model.experiment.experiment_list import Experiment
        from logging import info
        from dials.array_family import flex

        # Only do anything is the scan range is set
        if scan_range is not None and len(scan_range) > 0:

            # Ensure that all experiments have the same imageset and scan
            iset = [e.imageset for e in experiments]
            scan = [e.scan for e in experiments]
            assert all(x == iset[0] for x in iset)
            assert all(x == scan[0] for x in scan)

            # Get the imageset and scan
            iset = experiments[0].imageset
            scan = experiments[0].scan

            # Get the array range
            if scan is not None:
                frame10, frame11 = scan.get_array_range()
                assert scan.get_num_images() == len(iset)
            else:
                frame10, frame11 = (0, len(iset))

            # Create the new lists
            new_experiments = ExperimentList()
            new_reference_all = reference.split_by_experiment_id()
            new_reference = flex.reflection_table()
            for i in range(len(new_reference_all) - len(experiments)):
                new_reference_all.append(flex.reflection_table())
            assert len(new_reference_all) == len(experiments)

            # Loop through all the scan ranges and create a new experiment list with
            # the requested scan ranges.
            for frame00, frame01 in scan_range:
                assert frame01 > frame00
                assert frame00 >= frame10
                assert frame01 <= frame11
                index0 = frame00 - frame10
                index1 = index0 + (frame01 - frame00)
                assert index0 < index1
                assert index0 >= 0
                assert index1 <= len(iset)
                new_iset = iset[index0:index1]
                if scan is None:
                    new_scan = None
                else:
                    new_scan = scan[index0:index1]
                for i, e1 in enumerate(experiments):
                    e2 = Experiment()
                    e2.beam = e1.beam
                    e2.detector = e1.detector
                    e2.goniometer = e1.goniometer
                    e2.crystal = e1.crystal
                    e2.imageset = new_iset
                    e2.scan = new_scan
                    new_reference_all[i]["id"] = flex.int(len(new_reference_all[i]), len(new_experiments))
                    new_reference.extend(new_reference_all[i])
                    new_experiments.append(e2)
            experiments = new_experiments
            reference = new_reference

            # Print some information
            info("Modified experiment list to integrate over requested scan range")
            for frame00, frame01 in scan_range:
                info(" scan_range = %d -> %d" % (frame00, frame01))
            info("")

        # Return the experiments
        return experiments, reference
Beispiel #4
0
    def split_for_scan_range(self, experiments, reference, scan_range):
        ''' Update experiments when scan range is set. '''
        from dxtbx.model.experiment.experiment_list import ExperimentList
        from dxtbx.model.experiment.experiment_list import Experiment
        from dials.array_family import flex

        # Only do anything is the scan range is set
        if scan_range is not None and len(scan_range) > 0:

            # Ensure that all experiments have the same imageset and scan
            iset = [e.imageset for e in experiments]
            scan = [e.scan for e in experiments]
            assert (all(x == iset[0] for x in iset))
            assert (all(x == scan[0] for x in scan))

            # Get the imageset and scan
            iset = experiments[0].imageset
            scan = experiments[0].scan

            # Get the array range
            if scan is not None:
                frame10, frame11 = scan.get_array_range()
                assert (scan.get_num_images() == len(iset))
            else:
                frame10, frame11 = (0, len(iset))

            # Create the new lists
            new_experiments = ExperimentList()
            new_reference_all = reference.split_by_experiment_id()
            new_reference = flex.reflection_table()
            for i in range(len(new_reference_all) - len(experiments)):
                new_reference_all.append(flex.reflection_table())
            assert (len(new_reference_all) == len(experiments))

            # Loop through all the scan ranges and create a new experiment list with
            # the requested scan ranges.
            for frame00, frame01 in scan_range:
                assert (frame01 > frame00)
                assert (frame00 >= frame10)
                assert (frame01 <= frame11)
                index0 = frame00 - frame10
                index1 = index0 + (frame01 - frame00)
                assert (index0 < index1)
                assert (index0 >= 0)
                assert (index1 <= len(iset))
                new_iset = iset[index0:index1]
                if scan is None:
                    new_scan = None
                else:
                    new_scan = scan[index0:index1]
                for i, e1 in enumerate(experiments):
                    e2 = Experiment()
                    e2.beam = e1.beam
                    e2.detector = e1.detector
                    e2.goniometer = e1.goniometer
                    e2.crystal = e1.crystal
                    e2.imageset = new_iset
                    e2.scan = new_scan
                    new_reference_all[i]['id'] = flex.int(
                        len(new_reference_all[i]), len(new_experiments))
                    new_reference.extend(new_reference_all[i])
                    new_experiments.append(e2)
            experiments = new_experiments
            reference = new_reference

            # Print some information
            logger.info(
                'Modified experiment list to integrate over requested scan range'
            )
            for frame00, frame01 in scan_range:
                logger.info(' scan_range = %d -> %d' % (frame00, frame01))
            logger.info('')

        # Return the experiments
        return experiments, reference