Esempio n. 1
0
def test_goniometer():
    # Construct the object
    g1 = Goniometer(rotation_axis=(1, 2, 3),
                    fixed_rotation_matrix=(1, 2, 3, 4, 5, 6, 7, 8, 9))

    # Create a dictionary and get the object back
    d = g1.to_dict()
    g2 = Goniometer.from_dict(d)
    assert g2 == g1
Esempio n. 2
0
    def __call__(self):
        from dxtbx.model import Goniometer

        # Construct the object
        g1 = Goniometer(rotation_axis=(1, 2, 3),
                        fixed_rotation_matrix=(1, 2, 3, 4, 5, 6, 7, 8, 9))

        # Create a dictionary and get the object back
        d = g1.to_dict()
        g2 = Goniometer.from_dict(d)
        assert (g2 == g1)

        print 'OK'
Esempio n. 3
0
    def tst_equality(self):

        from dxtbx.model import Beam, Detector, Goniometer, Scan
        from dxtbx.model import Crystal

        # Create a load of models
        b1 = Beam()
        d1 = Detector()
        g1 = Goniometer()
        s1 = Scan()
        c1 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

        # Create a load of models that look the same but aren't
        b2 = Beam()
        d2 = Detector()
        g2 = Goniometer()
        s2 = Scan()
        c2 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

        # Create an experiment
        e1 = Experiment(beam=b1,
                        detector=d1,
                        goniometer=g1,
                        scan=s1,
                        crystal=c1,
                        imageset=None)

        # Create an experiment
        e2 = Experiment(beam=b1,
                        detector=d1,
                        goniometer=g1,
                        scan=s1,
                        crystal=c1,
                        imageset=None)

        # Create an experiment
        e3 = Experiment(beam=b2,
                        detector=d2,
                        goniometer=g2,
                        scan=s2,
                        crystal=c2,
                        imageset=None)

        # Check e1 equals e2 but not e3
        assert (e1 == e2)
        assert (e1 != e3)
        assert (e2 != e3)

        # Test passed
        print 'OK'
Esempio n. 4
0
  def __call__(self):
    from dxtbx.model import Goniometer

    # Construct the object
    g1 = Goniometer(
      rotation_axis=(1, 2, 3),
      fixed_rotation_matrix=(1, 2, 3, 4, 5, 6, 7, 8, 9))

    # Create a dictionary and get the object back
    d = g1.to_dict()
    g2 = Goniometer.from_dict(d)
    assert(g2 == g1)

    print 'OK'
Esempio n. 5
0
    def tst_goniometer(self):
        from dxtbx.model import Goniometer, GoniometerFactory
        g1 = Goniometer((1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1))
        d = g1.to_dict()
        g2 = GoniometerFactory.from_dict(d)
        assert (d['rotation_axis'] == (1, 0, 0))
        assert (d['fixed_rotation'] == (1, 0, 0, 0, 1, 0, 0, 0, 1))
        assert (g1 == g2)

        # Test with a template and partial dictionary
        d2 = {'rotation_axis': (0, 1, 0)}
        g3 = GoniometerFactory.from_dict(d2, d)
        assert (g3.get_rotation_axis() == (0, 1, 0))
        assert (g3.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1))
        assert (g2 != g3)
Esempio n. 6
0
def test_goniometer():
    g1 = Goniometer((1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1))
    d = g1.to_dict()
    g2 = GoniometerFactory.from_dict(d)
    assert d["rotation_axis"] == (1, 0, 0)
    assert d["fixed_rotation"] == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert g1 == g2
    assert "setting_rotation_at_scan_points" not in d

    # Test with a template and partial dictionary
    d2 = {"rotation_axis": (0, 1, 0)}
    g3 = GoniometerFactory.from_dict(d2, d)
    assert g3.get_rotation_axis() == (0, 1, 0)
    assert g3.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert g2 != g3
Esempio n. 7
0
    def tst_from_sweep(self):
        from dxtbx.model import Beam, Detector, Goniometer, Scan
        from dxtbx.model import Crystal
        from dxtbx.format.Format import Format

        filenames = ["filename_%01d.cbf" % (i + 1) for i in range(0, 2)]

        imageset = Format.get_imageset(filenames,
                                       beam=Beam(),
                                       detector=Detector(),
                                       goniometer=Goniometer(),
                                       scan=Scan((1, 2), (0, 1)),
                                       as_sweep=True)

        crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1),
                          space_group_symbol="P1")

        experiments = ExperimentListFactory.from_imageset_and_crystal(
            imageset, crystal)

        assert (len(experiments) == 1)
        assert (experiments[0].imageset is not None)
        assert (experiments[0].beam is not None)
        assert (experiments[0].detector is not None)
        assert (experiments[0].goniometer is not None)
        assert (experiments[0].scan is not None)
        assert (experiments[0].crystal is not None)

        print 'OK'
Esempio n. 8
0
def random_gonio():
    # make a random rotation axis with a random setting matrix
    axis = matrix.col(flex.random_double_point_on_sphere())
    fixed_rotation = matrix.sqr((1, 0, 0, 0, 1, 0, 0, 0, 1))
    setting_rotation = matrix.sqr(flex.random_double_r3_rotation_matrix())
    goniometer = Goniometer(axis, fixed_rotation, setting_rotation)
    return goniometer
Esempio n. 9
0
    def tst_from_null_sweep(self):
        from dxtbx.datablock import DataBlockFactory
        from dxtbx.imageset import NullReader, ImageSweep, SweepFileList
        from dxtbx.model import Beam, Detector, Goniometer, Scan

        sweep = ImageSweep(
            NullReader(SweepFileList("template_%2d.cbf", (0, 10))))
        sweep.set_beam(Beam((0, 0, 1)))
        sweep.set_detector(Detector())
        sweep.set_goniometer(Goniometer((1, 0, 0)))
        sweep.set_scan(Scan((1, 10), (0, 0.1)))

        # Create the datablock
        datablock = DataBlockFactory.from_imageset(sweep)
        assert (len(datablock) == 1)
        datablock = datablock[0]

        sweeps = datablock.extract_sweeps()
        assert (len(sweeps) == 1)
        assert (sweeps[0].get_beam() == sweep.get_beam())
        assert (sweeps[0].get_detector() == sweep.get_detector())
        assert (sweeps[0].get_goniometer() == sweep.get_goniometer())
        assert (sweeps[0].get_scan() == sweep.get_scan())

        print 'OK'
Esempio n. 10
0
def generate_test_input():
    (reflections,
     ms) = load_data("test_dataset_mu0p2_smalldetector_P4_rot0.pickle")

    # json.dump(datablock, open(datablock_json, 'w'))

    experiments = ExperimentList()
    exp_dict = {
        "__id__": "crystal",
        "real_space_a": [20.0, 0.0, 0.0],
        "real_space_b": [0.0, 20.0, 0.0],
        "real_space_c": [0.0, 0.0, 15.0],
        "space_group_hall_symbol": " P 4",
    }
    experiments.crystal = Crystal.from_dict(exp_dict)
    experiments.scan = Scan(image_range=[0, 360], oscillation=[0.0, 1.0])
    experiments.beam = Beam(s0=(0.0, 0.0, 1.01))
    experiments.goniometer = Goniometer((1.0, 0.0, 0.0))

    phil_scope = phil.parse(
        """
      include scope dials_scratch.jbe.scaling_code.scaling_options.phil_scope
  """,
        process_includes=True,
    )

    optionparser = OptionParser(phil=phil_scope, check_format=False)
    parameters, _ = optionparser.parse_args(args=None,
                                            quick_parse=True,
                                            show_diff_phil=False)
    parameters.__inject__("scaling_method", "aimless")
    parameters.scaling_options.__inject__("multi_mode", False)
    return (reflections, experiments, parameters)
 def _goniometer_from_dict(obj):
   ''' Get the goniometer from a dictionary. '''
   if 'axes' in obj and 'angles' in obj and 'scan_axis' in obj:
     from dxtbx.model import MultiAxisGoniometer
     return MultiAxisGoniometer.from_dict(obj)
   from dxtbx.model import Goniometer
   return Goniometer.from_dict(obj)
def test_experimentlist_dumper_dump_empty_sweep(tmpdir):
  tmpdir.chdir()
  from dxtbx.model import Beam, Detector, Goniometer, Scan
  from dxtbx.model import Crystal
  from dxtbx.format.Format import Format

  filenames = ["filename_%01d.cbf" % (i+1) for i in range(0, 2)]

  imageset = Format.get_imageset(
    filenames,
    beam = Beam((1, 0, 0)),
    detector = Detector(),
    goniometer = Goniometer(),
    scan = Scan((1,2), (0.0, 1.0)),
    as_sweep=True)

  crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

  experiments = ExperimentListFactory.from_imageset_and_crystal(
    imageset, crystal)

  dump = ExperimentListDumper(experiments)
  filename = 'temp.json'
  dump.as_json(filename)
  experiments2 = ExperimentListFactory.from_json_file(filename,
                                                      check_format=False)
  check(experiments, experiments2)
Esempio n. 13
0
def generated_single_exp():
    """Generate an experiment object."""
    experiments = ExperimentList()
    exp_dict = {
        "__id__": "crystal",
        "real_space_a": [1.0, 0.0, 0.0],
        "real_space_b": [0.0, 1.0, 0.0],
        "real_space_c": [0.0, 0.0, 2.0],
        "space_group_hall_symbol": " C 2y",
    }
    crystal = Crystal.from_dict(exp_dict)
    scan = Scan(image_range=[0, 60], oscillation=[0.0, 1.0])
    beam = Beam(s0=(0.0, 0.0, 1.01))
    goniometer = Goniometer((1.0, 0.0, 0.0))
    detector = Detector()
    experiments.append(
        Experiment(
            beam=beam,
            scan=scan,
            goniometer=goniometer,
            detector=detector,
            crystal=crystal,
        ))
    experiments[0].identifier = "0"
    return experiments
Esempio n. 14
0
  def tst_contains(self):

    from dxtbx.model import Beam, Detector, Goniometer, Scan

    # Check all the models are found
    for e in self.el:
      assert(e.beam in self.el)
      assert(e.detector in self.el)
      assert(e.goniometer in self.el)
      assert(e.scan in self.el)

    # Create some more models
    b = Beam()
    d = Detector()
    g = Goniometer()
    s = Scan()

    # Check that models not in are not found
    assert(b not in self.el)
    assert(d not in self.el)
    assert(g not in self.el)
    assert(s not in self.el)

    # Test passed
    print 'OK'
def test_experimentlist_factory_from_datablock():
  from dxtbx.model import Beam, Detector, Goniometer, Scan
  from dxtbx.datablock import DataBlockFactory
  from dxtbx.model import Crystal
  from dxtbx.format.Format import Format

  filenames = ["filename_%01d.cbf" % (i+1) for i in range(0, 2)]

  imageset = Format.get_imageset(
    filenames,
    beam = Beam(),
    detector = Detector(),
    goniometer = Goniometer(),
    scan = Scan((1,2), (0,1)),
    as_sweep=True)

  crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

  datablock = DataBlockFactory.from_imageset(imageset)

  experiments = ExperimentListFactory.from_datablock_and_crystal(
    datablock, crystal)

  assert len(experiments) == 1
  assert experiments[0].imageset is not None
  assert experiments[0].beam is not None
  assert experiments[0].detector is not None
  assert experiments[0].goniometer is not None
  assert experiments[0].scan is not None
  assert experiments[0].crystal is not None
Esempio n. 16
0
def generated_exp(n=1):
    """Generate an experiment list with two experiments."""
    experiments = ExperimentList()
    exp_dict = {
        "__id__": "crystal",
        "real_space_a": [1.0, 0.0, 0.0],
        "real_space_b": [0.0, 1.0, 0.0],
        "real_space_c": [0.0, 0.0, 2.0],
        "space_group_hall_symbol": " C 2y",
    }
    crystal = Crystal.from_dict(exp_dict)
    scan = Scan(image_range=[0, 90], oscillation=[0.0, 1.0])
    beam = Beam(s0=(0.0, 0.0, 1.01))
    goniometer = Goniometer((1.0, 0.0, 0.0))
    detector = Detector()
    experiments.append(
        Experiment(
            beam=beam,
            scan=scan,
            goniometer=goniometer,
            detector=detector,
            crystal=crystal,
        ))
    if n > 1:
        for _ in range(n - 1):
            experiments.append(
                Experiment(
                    beam=beam,
                    scan=scan,
                    goniometer=goniometer,
                    detector=detector,
                    crystal=crystal,
                ))
    return experiments
Esempio n. 17
0
def test_experimentlist_factory_from_datablock():
    filenames = ["filename_%01d.cbf" % (i + 1) for i in range(0, 2)]

    imageset = Format.get_imageset(
        filenames,
        beam=Beam(),
        detector=Detector(),
        goniometer=Goniometer(),
        scan=Scan((1, 2), (0, 1)),
        as_sequence=True,
    )

    crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

    datablock = DataBlockFactory.from_imageset(imageset)
    assert datablock[0].format_class()

    experiments = ExperimentListFactory.from_datablock_and_crystal(
        datablock, crystal)

    assert len(experiments) == 1
    assert experiments[0].imageset
    assert experiments[0].beam
    assert experiments[0].detector is not None
    assert experiments[0].goniometer
    assert experiments[0].scan
    assert experiments[0].crystal
Esempio n. 18
0
  def tst_dump_empty_sweep(self):
    from dxtbx.imageset import ImageSweep, NullReader, SweepFileList
    from dxtbx.model import Beam, Detector, Goniometer, Scan
    from dxtbx.model.crystal import crystal_model
    from uuid import uuid4

    imageset = ImageSweep(NullReader(SweepFileList("filename%01d.cbf", (0, 3))))
    imageset.set_beam(Beam((1, 0, 0)))
    imageset.set_detector(Detector())
    imageset.set_goniometer(Goniometer())
    imageset.set_scan(Scan((1, 3), (0.0, 1.0)))

    crystal = crystal_model((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol=1)

    experiments = ExperimentListFactory.from_imageset_and_crystal(
      imageset, crystal)

    dump = ExperimentListDumper(experiments)
    filename = 'temp%s.json' % uuid4().hex
    dump.as_json(filename)
    experiments2 = ExperimentListFactory.from_json_file(filename,
                                                        check_format=False)
    self.check(experiments, experiments2)

    print 'OK'
Esempio n. 19
0
  def tst_from_datablock(self):
    from dxtbx.imageset import ImageSweep, NullReader, SweepFileList
    from dxtbx.model import Beam, Detector, Goniometer, Scan
    from dxtbx.datablock import DataBlockFactory
    from dxtbx.model.crystal import crystal_model

    imageset = ImageSweep(NullReader(SweepFileList("filename%01d.cbf", (0, 2))))
    imageset.set_beam(Beam())
    imageset.set_detector(Detector())
    imageset.set_goniometer(Goniometer())
    imageset.set_scan(Scan((1, 2), (0, 1)))

    crystal = crystal_model((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol=0)

    datablock = DataBlockFactory.from_imageset(imageset)

    experiments = ExperimentListFactory.from_datablock_and_crystal(
      datablock, crystal)

    assert(len(experiments) == 1)
    assert(experiments[0].imageset is not None)
    assert(experiments[0].beam is not None)
    assert(experiments[0].detector is not None)
    assert(experiments[0].goniometer is not None)
    assert(experiments[0].scan is not None)
    assert(experiments[0].crystal is not None)

    print 'OK'
    def __init__(self):
        # Let's say we have a scan of 100 images
        self.image_range = (1, 100)

        # Make a random P1 crystal
        a = random.uniform(10,50) * \
            self.random_direction_close_to(matrix.col((1, 0, 0)))
        b = random.uniform(10,50) * \
            self.random_direction_close_to(matrix.col((0, 1, 0)))
        c = random.uniform(10,50) * \
            self.random_direction_close_to(matrix.col((0, 0, 1)))
        self.xl = Crystal(a, b, c, space_group_symbol="P 1")

        # Make a beam with wavelength in the range 0.8--1.2 and s0 direction close
        # to 0,0,1
        s0 = random.uniform(0.8, 1.2) * \
            self.random_direction_close_to(matrix.col((0, 0, 1)))
        self.beam = Beam(s0)

        # Make a standard goniometer model along X
        self.goniometer = Goniometer((1, 0, 0))

        # Make a simple single panel detector
        d1 = matrix.col((1, 0, 0))
        d2 = matrix.col((0, -1, 0))
        npx_fast = 1475
        npx_slow = 1679
        pix_size_f = pix_size_s = 0.172
        from dxtbx.model import DetectorFactory
        self.detector = DetectorFactory.make_detector("PAD", d1, d2,
                                                      matrix.col((0, 0, -110)),
                                                      (pix_size_f, pix_size_s),
                                                      (npx_fast, npx_slow),
                                                      (0, 2e20))
Esempio n. 21
0
  def tst_from_null_sweep(self):
    from dxtbx.format.Format import Format
    from dxtbx.imageset import ImageSweep
    from dxtbx.model import Beam, Detector, Goniometer, Scan

    filenames = ["template_%2d.cbf" % (i+1) for i in range(0, 10)]
    sweep = Format.get_imageset(
      filenames,
      beam = Beam((0, 0, 1)),
      detector = Detector(),
      goniometer = Goniometer((1, 0, 0)),
      scan = Scan((1, 10), (0, 0.1)))

    # Create the datablock
    datablock = DataBlockFactory.from_imageset(sweep)
    assert(len(datablock) == 1)
    datablock = datablock[0]

    sweeps = datablock.extract_sweeps()
    assert(len(sweeps) == 1)
    assert(sweeps[0].get_beam() == sweep.get_beam())
    assert(sweeps[0].get_detector() == sweep.get_detector())
    assert(sweeps[0].get_goniometer() == sweep.get_goniometer())
    assert(sweeps[0].get_scan() == sweep.get_scan())

    print 'OK'
Esempio n. 22
0
def test_goniometer():
    from dxtbx.model import Goniometer, GoniometerFactory
    g1 = Goniometer((1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1))
    d = g1.to_dict()
    g2 = GoniometerFactory.from_dict(d)
    assert d['rotation_axis'] == (1, 0, 0)
    assert d['fixed_rotation'] == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert g1 == g2
    assert 'setting_rotation_at_scan_points' not in d

    # Test with a template and partial dictionary
    d2 = {'rotation_axis': (0, 1, 0)}
    g3 = GoniometerFactory.from_dict(d2, d)
    assert g3.get_rotation_axis() == (0, 1, 0)
    assert g3.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert g2 != g3
def experiment_list():
  from dxtbx.model import Beam, Detector, Goniometer, Scan

  # Initialise a list of experiments
  experiments = ExperimentList()

  # Create a few beams
  b1 = Beam()
  b2 = Beam()
  b3 = Beam()

  # Create a few detectors
  d1 = Detector()
  d2 = Detector()
  d3 = Detector()

  # Create a few goniometers
  g1 = Goniometer()
  g2 = Goniometer()
  g3 = Goniometer()

  # Create a few scans
  s1 = Scan()
  s2 = Scan()
  s3 = Scan()

  # Create a list of models
  b = [b1, b2, b3, b2, b1]
  d = [d1, d2, d3, d2, d1]
  g = [g1, g2, g3, g2, g1]
  s = [s1, s2, s3, s2, s1]
  ident = ["sausage", "eggs", "bacon", "toast", "beans"]

  # Populate with various experiments
  for i in range(5):
    experiments.append(Experiment(
      beam=b[i],
      detector=d[i],
      goniometer=g[i],
      scan=s[i],
      identifier=ident[i]))

  # Return the list of experiments
  return experiments
Esempio n. 24
0
def test_experiment_equality():
    # Create a load of models
    b1 = Beam()
    d1 = Detector()
    g1 = Goniometer()
    s1 = Scan()
    c1 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

    # Create a load of models that look the same but aren't
    b2 = Beam()
    d2 = Detector()
    g2 = Goniometer()
    s2 = Scan()
    c2 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

    # Create an experiment
    e1 = Experiment(beam=b1,
                    detector=d1,
                    goniometer=g1,
                    scan=s1,
                    crystal=c1,
                    imageset=None)

    # Create an experiment
    e2 = Experiment(beam=b1,
                    detector=d1,
                    goniometer=g1,
                    scan=s1,
                    crystal=c1,
                    imageset=None)

    # Create an experiment
    e3 = Experiment(beam=b2,
                    detector=d2,
                    goniometer=g2,
                    scan=s2,
                    crystal=c2,
                    imageset=None)

    # Check e1 equals e2 but not e3
    assert e1 == e2
    assert e1 != e3
    assert e2 != e3
Esempio n. 25
0
    def __init__(self, obj):
        from dxtbx.model import Goniometer

        # Get the rotation axis
        rotation_axis = construct_vector(
            obj.handle.file,
            obj.handle.file[obj.handle['depends_on'][()]].name)

        # Construct the model
        self.model = Goniometer(tuple(rotation_axis))
Esempio n. 26
0
    def tst_contains(self):
        from dxtbx.model import Beam, Detector, Goniometer, Scan
        from dxtbx.model import Crystal

        # Create a load of models
        b1 = Beam()
        d1 = Detector()
        g1 = Goniometer()
        s1 = Scan()
        c1 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

        # Create an experiment
        e = Experiment(beam=b1,
                       detector=d1,
                       goniometer=g1,
                       scan=s1,
                       crystal=c1,
                       imageset=None)

        # Check experiment contains model
        assert (b1 in e)
        assert (d1 in e)
        assert (g1 in e)
        assert (s1 in e)
        assert (c1 in e)

        # Create a load of models that look the same but aren't
        b2 = Beam()
        d2 = Detector()
        g2 = Goniometer()
        s2 = Scan()
        c2 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

        # Check experiment doesn't contain model
        assert (b2 not in e)
        assert (d2 not in e)
        assert (g2 not in e)
        assert (s2 not in e)
        assert (c2 not in e)

        # Test passed
        print 'OK'
def generated_exp(n=1, scan=True, image_range=[0, 10]):
    """Generate an experiment list with two experiments."""
    experiments = ExperimentList()
    exp_dict = {
        "__id__": "crystal",
        "real_space_a": [1.0, 0.0, 0.0],
        "real_space_b": [0.0, 1.0, 0.0],
        "real_space_c": [0.0, 0.0, 2.0],
        "space_group_hall_symbol": " C 2y",
    }
    crystal = Crystal.from_dict(exp_dict)
    if scan:
        scan = Scan(image_range=image_range, oscillation=[0.0, 1.0])
    else:
        scan = None
    beam = Beam(s0=(0.0, 0.0, 1.01))
    goniometer = Goniometer((1.0, 0.0, 0.0))
    goniometer_2 = Goniometer((1.0, 1.0, 0.0))
    detector = Detector()
    experiments.append(
        Experiment(
            beam=beam,
            scan=scan,
            goniometer=goniometer,
            detector=detector,
            crystal=crystal,
        )
    )
    experiments[0].identifier = "0"
    if n > 1:
        for i in range(0, n - 1):
            experiments.append(
                Experiment(
                    beam=beam,
                    scan=scan,
                    goniometer=goniometer_2,
                    detector=detector,
                    crystal=crystal,
                )
            )
            experiments[i + 1].identifier = str(i + 1)
    return experiments
Esempio n. 28
0
def test_experiment_is_still():
    experiment = Experiment()
    assert experiment.is_still()
    experiment.goniometer = Goniometer()
    assert experiment.is_still()
    experiment.scan = Scan()
    assert experiment.is_still()
    experiment.scan = Scan((1, 1000), (0, 0.05))
    assert not experiment.is_still()
    # Specifically test the bug from dxtbx#4 triggered by ending on 0°
    experiment.scan = Scan((1, 1800), (-90, 0.05))
    assert not experiment.is_still()
Esempio n. 29
0
def test_experimentlist_imagesequence_decode(mocker):
    # These models are shared between experiments
    beam = Beam(s0=(0, 0, -1))
    detector = Detector()
    gonio = Goniometer()

    # Construct the experiment list
    experiments = ExperimentList()
    for i in range(3):
        experiments.append(
            Experiment(
                beam=beam,
                detector=detector,
                scan=ScanFactory.make_scan(
                    image_range=(i + 1, i + 1),
                    exposure_times=[1],
                    oscillation=(0, 0),
                    epochs=[0],
                ),
                goniometer=gonio,
            ))

    # Convert experiment list to dict and manually insert a shared imageset
    d = experiments.to_dict()
    d["imageset"].append({
        "__id__": "ImageSequence",
        "template": "Puck3_10_1_####.cbf.gz"
    })
    for e in d["experiment"]:
        e["imageset"] = 0

    # Monkeypatch this function as we don't actually have an imageset
    make_sequence = mocker.patch.object(ExperimentListDict, "_make_sequence")
    # Ensure that if make_sequence is called more than once it returns a different
    # value each time
    make_sequence.side_effect = lambda *args, **kwargs: mocker.MagicMock()

    # Decode the dict to get a new experiment list
    experiments2 = ExperimentListDict(d).decode()

    # This function should only be called once per imageset
    make_sequence.assert_called_once()

    # Verify that this experiment is as we expect
    assert len(experiments2) == 3
    assert len(experiments2.imagesets()) == 1
    assert len(experiments2.goniometers()) == 1
    assert len(experiments2.detectors()) == 1
    assert len(experiments2.beams()) == 1
    assert len(experiments2.scans()) == 3
    for expt in experiments2:
        assert expt.imageset is experiments2.imagesets()[0]
Esempio n. 30
0
def test_experiment_contains():
    # Create a load of models
    b1 = Beam()
    d1 = Detector()
    g1 = Goniometer()
    s1 = Scan()
    c1 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

    # Create an experiment
    e = Experiment(beam=b1,
                   detector=d1,
                   goniometer=g1,
                   scan=s1,
                   crystal=c1,
                   imageset=None)

    # Check experiment contains model
    assert b1 in e
    assert d1 in e
    assert g1 in e
    assert s1 in e
    assert c1 in e

    # Create a load of models that look the same but aren't
    b2 = Beam()
    d2 = Detector()
    g2 = Goniometer()
    s2 = Scan()
    c2 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1")

    # Check experiment doesn't contain model
    assert b2 not in e
    assert d2 not in e
    assert g2 not in e
    assert s2 not in e
    assert c2 not in e
Esempio n. 31
0
  def tst_null_reader_sweep(self):
    from dxtbx.imageset import NullReader, ImageSweep, SweepFileList
    from dxtbx.model import Beam, Detector, Goniometer, Scan

    template = 'hello_world_%d.cbf'
    paths = [template % 1]

    # Create the null reader
    reader = NullReader(SweepFileList(template, (0, 1)))

    # Create the imageset
    imageset = ImageSweep(reader)

    # Try to get an item
    try:
      imageset[0]
      assert(False)
    except Exception:
      print 'OK'

    # Try to slice the imageset
    imageset2 = imageset[0:1]
    print 'OK'

    # Try some functions which should work
    assert(len(imageset) == 1)
    assert(imageset == imageset)
    assert(imageset.indices() == [0])
    assert(imageset.is_valid())
    assert(imageset.get_template() == template)
    print 'OK'

    # Get the image paths
    assert(imageset.paths() == paths)
    assert(imageset.get_path(0) == paths[0])
    print 'OK'

    imageset.set_beam(Beam())
    imageset.set_detector(Detector())
    imageset.set_goniometer(Goniometer())
    imageset.set_scan(Scan((1,1), (0, 1)))
    assert(isinstance(imageset.get_beam(), Beam))
    assert(isinstance(imageset.get_detector(), Detector))
    assert(isinstance(imageset.get_goniometer(), Goniometer))
    assert(isinstance(imageset.get_scan(), Scan))
    print 'OK'
Esempio n. 32
0
  def tst_indices(self):
    from dxtbx.model import Beam, Detector, Goniometer, Scan

    # Get the models
    b = [e.beam for e in self.el]
    d = [e.detector for e in self.el]
    g = [e.goniometer for e in self.el]
    s = [e.scan for e in self.el]

    # Check indices of beams
    assert(self.el.indices(b[0]) == [0, 4])
    assert(self.el.indices(b[1]) == [1, 3])
    assert(self.el.indices(b[2]) == [2])
    assert(self.el.indices(b[3]) == [1, 3])
    assert(self.el.indices(b[4]) == [0, 4])

    # Check indices of detectors
    assert(self.el.indices(d[0]) == [0, 4])
    assert(self.el.indices(d[1]) == [1, 3])
    assert(self.el.indices(d[2]) == [2])
    assert(self.el.indices(d[3]) == [1, 3])
    assert(self.el.indices(d[4]) == [0, 4])

    # Check indices of goniometer
    assert(self.el.indices(g[0]) == [0, 4])
    assert(self.el.indices(g[1]) == [1, 3])
    assert(self.el.indices(g[2]) == [2])
    assert(self.el.indices(g[3]) == [1, 3])
    assert(self.el.indices(g[4]) == [0, 4])

    # Check indices of scans
    assert(self.el.indices(s[0]) == [0, 4])
    assert(self.el.indices(s[1]) == [1, 3])
    assert(self.el.indices(s[2]) == [2])
    assert(self.el.indices(s[3]) == [1, 3])
    assert(self.el.indices(s[4]) == [0, 4])

    # Check some models not in the list
    assert(len(self.el.indices(Beam())) == 0)
    assert(len(self.el.indices(Detector())) == 0)
    assert(len(self.el.indices(Goniometer())) == 0)
    assert(len(self.el.indices(Scan())) == 0)

    # Test passed
    print 'OK'
Esempio n. 33
0
def from_dict(d, t=None):
  ''' Convert the dictionary to a goniometer model

  Params:
      d The dictionary of parameters
      t The template dictionary to use

  Returns:
      The goniometer model

  '''
  from dxtbx.model import Goniometer

  # If None, return None
  if d == None:
    if t == None: return None
    else: return from_dict(t, None)
  elif t != None:
    d = dict(t.items() + d.items())

  # Create the model from the dictionary
  return Goniometer.from_dict(d)
Esempio n. 34
0
 def load_models(obj):
   try:
     beam = Beam.from_dict(blist[obj['beam']])
   except Exception:
     beam = None
   try:
     dobj = dlist[obj['detector']]
     if 'hierarchy' in dobj:
       detector = HierarchicalDetector.from_dict(dobj)
     else:
       detector = Detector.from_dict(dobj)
   except Exception:
     detector = None
   try:
     gonio = Goniometer.from_dict(glist[obj['goniometer']])
   except Exception:
     gonio = None
   try:
     scan = Scan.from_dict(slist[obj['scan']])
   except Exception:
     scan = None
   return beam, detector, gonio, scan
Esempio n. 35
0
 def _goniometer_from_dict(obj):
   ''' Get the goniometer from a dictionary. '''
   from dxtbx.model import Goniometer
   return Goniometer.from_dict(obj)