コード例 #1
0
def tst_set_mosflm_beam_centre(detector):
    from scitbx import matrix
    from dxtbx.model import Beam
    wavelength = 1
    panel = detector[0]
    detector_normal = matrix.col(panel.get_normal())
    origin = matrix.col(panel.get_origin())
    fast_axis = matrix.col(panel.get_fast_axis())
    slow_axis = matrix.col(panel.get_slow_axis())
    image_size = panel.get_image_size_mm()

    s0 = (1.0 / wavelength) * detector_normal
    beam = Beam(-s0.normalize(), wavelength)

    beam_centre = matrix.col(panel.get_beam_centre(beam.get_s0()))
    origin_shift = matrix.col((1, 0.5))
    new_beam_centre = beam_centre + origin_shift

    new_mosflm_beam_centre = tuple(reversed(new_beam_centre))

    from dxtbx.model.detector_helpers import set_mosflm_beam_centre
    set_mosflm_beam_centre(detector, beam, new_mosflm_beam_centre)

    assert (matrix.col(panel.get_beam_centre(beam.get_s0())) - matrix.col(
        tuple(reversed(new_mosflm_beam_centre)))).length() < 1e-6

    print 'OK'
コード例 #2
0
ファイル: tst_detector.py プロジェクト: keitaroyam/cctbx_fork
def tst_set_mosflm_beam_centre(detector):
  from scitbx import matrix
  from dxtbx.model import Beam
  wavelength = 1
  panel = detector[0]
  detector_normal = matrix.col(panel.get_normal())
  origin = matrix.col(panel.get_origin())
  fast_axis = matrix.col(panel.get_fast_axis())
  slow_axis = matrix.col(panel.get_slow_axis())
  image_size = panel.get_image_size_mm()

  s0 = (1.0/wavelength) * detector_normal
  beam = Beam(-s0.normalize(), wavelength)

  beam_centre = matrix.col(panel.get_beam_centre(beam.get_s0()))
  origin_shift = matrix.col((1, 0.5))
  new_beam_centre = beam_centre + origin_shift

  new_mosflm_beam_centre = tuple(reversed(new_beam_centre))

  from dxtbx.model.detector_helpers import set_mosflm_beam_centre
  set_mosflm_beam_centre(detector, beam, new_mosflm_beam_centre)

  assert (matrix.col(panel.get_beam_centre(beam.get_s0())) -
          matrix.col(tuple(reversed(new_mosflm_beam_centre)))).length() < 1e-6

  print 'OK'
コード例 #3
0
def test_experimentlist_with_identifiers():
    from dxtbx.model import Beam, Detector, Goniometer, Scan

    # Initialise a list of experiments
    experiments = ExperimentList()

    experiments.append(
        Experiment(beam=Beam(s0=(0, 0, -1)),
                   detector=Detector(),
                   identifier="bacon"))

    experiments.append(
        Experiment(beam=Beam(s0=(0, 0, -1)),
                   detector=Detector(),
                   identifier="sausage"))

    with pytest.raises(Exception):
        experiments.append(
            Experiment(beam=Beam(), detector=Detector(), identifier="bacon"))

    d = experiments.to_dict()
    e2 = ExperimentListDict(d).decode()

    assert experiments[0].identifier == e2[0].identifier
    assert experiments[1].identifier == e2[1].identifier

    assert tuple(experiments.identifiers()) == ("bacon", "sausage")
    experiments[0].identifier = "spam"
    assert tuple(experiments.identifiers()) == ("spam", "sausage")
コード例 #4
0
ファイル: tst_beam.py プロジェクト: cctbx/cctbx-playground
def tst_set_direction_wavelength():
  """Test setting direction and wavelength"""
  from scitbx import matrix
  direction = matrix.col((0.013142, 0.002200, 1.450476))
  unit_direction = direction.normalize()
  wavelength = 0.689400

  # Create the beam
  b = Beam(direction, wavelength)

  eps = 1e-7

  # Check direction is a unit vector
  assert(abs(matrix.col(b.get_direction()).length() - 1) <= eps)
  assert(abs(matrix.col(b.get_direction()) - unit_direction) <= eps)

  # Check wavelength is correct
  assert(abs(b.get_wavelength() - wavelength) <= eps)

  # Check s0 is in direction and has length 1/wavelength
  assert(abs(matrix.col(b.get_s0()).length() - 1.0 / wavelength) <= eps)
  assert(abs(-matrix.col(b.get_s0()).normalize() - unit_direction) <= eps)

  # Test passed
  print "OK"
コード例 #5
0
ファイル: test_detector.py プロジェクト: hbrunie/dxtbx
def tst_resolution(detector):
    from dxtbx.model import Beam

    beam = Beam(direction=(0, 0, 1), wavelength=1.0)
    d_min1 = detector.get_max_resolution(beam.get_s0())
    d_min2 = detector.get_max_inscribed_resolution(beam.get_s0())
    assert d_min1 < d_min2
コード例 #6
0
def test_experimentlist_with_identifiers():
    # Initialise a list of experiments
    experiments = ExperimentList()

    experiments.append(
        Experiment(beam=Beam(s0=(0, 0, -1)),
                   detector=Detector(),
                   identifier="bacon"))

    experiments.append(
        Experiment(beam=Beam(s0=(0, 0, -1)),
                   detector=Detector(),
                   identifier="sausage"))

    with pytest.raises(Exception):
        experiments.append(
            Experiment(beam=Beam(), detector=Detector(), identifier="bacon"))

    d = experiments.to_dict()
    e2 = ExperimentListDict(d).decode()

    assert experiments[0].identifier == e2[0].identifier
    assert experiments[1].identifier == e2[1].identifier

    assert tuple(experiments.identifiers()) == ("bacon", "sausage")
    experiments[0].identifier = "spam"
    assert tuple(experiments.identifiers()) == ("spam", "sausage")

    experiments.append(Experiment(identifier="bacon"))
    experiments.select_on_experiment_identifiers(["spam", "bacon"])
    assert list(experiments.identifiers()) == ["spam", "bacon"]
    experiments.append(Experiment(identifier="ham"))
    experiments.append(Experiment(identifier="jam"))
    experiments.remove_on_experiment_identifiers(["spam", "jam"])
    assert list(experiments.identifiers()) == ["bacon", "ham"]
コード例 #7
0
def tst_resolution(detector):

  from dxtbx.model import Beam
  beam = Beam(direction=(0,0,1), wavelength=1.0)
  d_min1 = detector.get_max_resolution(beam.get_s0())
  d_min2 = detector.get_max_inscribed_resolution(beam.get_s0())
  assert d_min1 < d_min2
  print 'OK'
コード例 #8
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'
コード例 #9
0
def test_set_mosflm_beam_centre(detector):
    wavelength = 1.0
    panel = detector[0]
    detector_normal = matrix.col(panel.get_normal())
    _ = matrix.col(panel.get_origin())
    _ = matrix.col(panel.get_fast_axis())
    _ = matrix.col(panel.get_slow_axis())
    _ = panel.get_image_size_mm()

    s0 = (1.0 / wavelength) * detector_normal
    beam = Beam(-s0.normalize(), wavelength)

    beam_centre = matrix.col(panel.get_beam_centre(beam.get_s0()))
    origin_shift = matrix.col((1, 0.5))
    new_beam_centre = beam_centre + origin_shift

    new_mosflm_beam_centre = tuple(reversed(new_beam_centre))

    set_mosflm_beam_centre(detector, beam, new_mosflm_beam_centre)

    assert (
        matrix.col(panel.get_beam_centre(beam.get_s0()))
        - matrix.col(tuple(reversed(new_mosflm_beam_centre)))
    ).length() < 1e-6

    # test resolution methods
    beam = Beam(direction=(0, 0, 1), wavelength=1.0)
    d_min1 = detector.get_max_resolution(beam.get_s0())
    d_min2 = detector.get_max_inscribed_resolution(beam.get_s0())
    assert d_min1 < d_min2
コード例 #10
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'
コード例 #11
0
ファイル: tst_datablock.py プロジェクト: hainm/cctbx_project
    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'
コード例 #12
0
    def tst_set_models(imageset):
        # Create some other models
        beam = Beam((1, 0, 0), 0.5)
        detector = Detector(
            Panel(
                "UNKNOWN",
                "Panel",
                (1, 0, 0),
                (0, 1, 0),
                (0, 0, 1),
                (0.1, 0.1),
                (1000, 1000),
                (0, 1),
            ))

        # Override sequence models
        imageset.set_beam(beam)
        imageset.set_detector(detector)

        # Ensure this doens't interfere with reading
        for i in imageset:
            pass

        # Get the models back and check they're ok
        beam2 = imageset.get_beam()
        detector2 = imageset.get_detector()
        assert beam2 == beam
        assert detector2 == detector

        # Get the models from an index back and check they're not the same
        beam2 = imageset.get_beam(0)
        detector2 = imageset.get_detector(0)
        assert beam2 != beam
        assert detector2 != detector
コード例 #13
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)
コード例 #14
0
ファイル: tst_beam.py プロジェクト: fsimkovic/cctbx_project
def tst_from_phil():

  from libtbx.phil import parse
  from dxtbx.model.beam import beam_phil_scope, BeamFactory
  from scitbx import matrix
  direction = matrix.col((0.013142, 0.002200, 1.450476))
  unit_direction = direction.normalize()
  wavelength = 0.689400

  reference = Beam(direction, wavelength)

  params1 = beam_phil_scope.fetch(parse("""
    beam {
      wavelength = 1.0
      direction = (0, 0, 1)
    }
  """)).extract()

  params2 = beam_phil_scope.fetch(parse("""
    beam {
      wavelength = 1.0
    }
  """)).extract()

  # Create the beam
  b1 = BeamFactory.from_phil(params1)
  b2 = BeamFactory.from_phil(params2, reference)
  try:
    b3 = BeamFactory.from_phil(params2)
    passed = True
  except Exception:
    passed = False
  assert passed == False

  print 'OK'
コード例 #15
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
コード例 #16
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
コード例 #17
0
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)
コード例 #18
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'
コード例 #19
0
ファイル: test_scale.py プロジェクト: jmp1985/dials
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
コード例 #20
0
def generated_exp(n=1, space_group="P 2", assign_ids=False, id_=None):
    """Generate an experiment list with two experiments."""
    experiments = ExperimentList()
    exp_dict = {
        "__id__": "crystal",
        "real_space_a": [15.0, 0.0, 0.0],
        "real_space_b": [0.0, 10.0, 0.0],
        "real_space_c": [0.0, 0.0, 20.0],
        "space_group_hall_symbol": space_group,
    }
    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))
    if assign_ids:
        experiments.append(
            Experiment(identifier="0", beam=beam, scan=scan, crystal=crystal)
        )
    elif id_:
        experiments.append(
            Experiment(identifier=str(id_), beam=beam, scan=scan, crystal=crystal)
        )
    else:
        experiments.append(Experiment(beam=beam, scan=scan, crystal=crystal))
    if n > 1:
        for i in range(1, n):
            if assign_ids:
                experiments.append(
                    Experiment(identifier=str(i), beam=beam, scan=scan, crystal=crystal)
                )
            else:
                experiments.append(Experiment(beam=beam, scan=scan, crystal=crystal))
    return experiments
コード例 #21
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'
コード例 #22
0
    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))
コード例 #23
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'
コード例 #24
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'
コード例 #25
0
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
コード例 #26
0
ファイル: test_beam.py プロジェクト: zhuligs/cctbx_project
def test_from_phil():
    from libtbx.phil import parse
    from dxtbx.model.beam import beam_phil_scope, BeamFactory
    from scitbx import matrix
    direction = matrix.col((0.013142, 0.002200, 1.450476))
    unit_direction = direction.normalize()
    wavelength = 0.689400

    reference = Beam(direction, wavelength)

    params1 = beam_phil_scope.fetch(
        parse("""
    beam {
      wavelength = 1.0
      direction = (0, 0, 1)
    }
  """)).extract()

    params2 = beam_phil_scope.fetch(
        parse("""
    beam {
      wavelength = 1.0
    }
  """)).extract()

    # Create the beam
    b1 = BeamFactory.from_phil(params1)
    b2 = BeamFactory.from_phil(params2, reference)
    with pytest.raises(RuntimeError):
        b3 = BeamFactory.from_phil(params2)
コード例 #27
0
    def __call__(self):
        from dxtbx.model import Beam

        # Construct the object
        b1 = Beam(direction=(1, 2, 3),
                  wavelength=1.1,
                  divergence=0.01,
                  sigma_divergence=0.01,
                  polarization_normal=(4, 5, 6),
                  polarization_fraction=0.9)

        # Create a dictionary and get the beam back
        d = b1.to_dict()
        b2 = Beam.from_dict(d)
        assert (b2 == b1)

        print 'OK'
コード例 #28
0
def test_beam():
    # Construct the object
    b1 = Beam(
        direction=(1, 2, 3),
        wavelength=1.1,
        divergence=0.01,
        sigma_divergence=0.01,
        polarization_normal=(4, 5, 6),
        polarization_fraction=0.9,
        flux=1.0,
        transmission=1.0,
    )

    # Create a dictionary and get the beam back
    d = b1.to_dict()
    b2 = Beam.from_dict(d)
    assert b2 == b1
コード例 #29
0
def tst_set_s0():
    """Test setting s0"""
    from scitbx import matrix
    direction = matrix.col((0.013142, 0.002200, 1.450476))
    unit_direction = direction.normalize()
    wavelength = 0.689400
    s0 = -unit_direction * 1.0 / wavelength

    # Create the beam
    b = Beam(s0)

    eps = 1e-7

    # Check direction is a unit vector
    assert (abs(matrix.col(b.get_direction()).length() - 1) <= eps)
    assert (abs(matrix.col(b.get_direction()) - unit_direction) <= eps)

    # Check wavelength is correct
    assert (abs(b.get_wavelength() - wavelength) <= eps)

    # Check s0 is in direction and has length 1/wavelength
    assert (abs(matrix.col(b.get_s0()).length() - 1.0 / wavelength) <= eps)
    assert (abs(-matrix.col(b.get_s0()).normalize() - unit_direction) <= eps)
    assert (abs(matrix.col(b.get_s0()) - s0) <= eps)

    # Test passed
    print "OK"
コード例 #30
0
  def __call__(self):
    from dxtbx.model import Beam

    # Construct the object
    b1 = Beam(
      direction=(1, 2, 3),
      wavelength=1.1,
      divergence=0.01,
      sigma_divergence=0.01,
      polarization_normal=(4, 5, 6),
      polarization_fraction=0.9)

    # Create a dictionary and get the beam back
    d = b1.to_dict()
    b2 = Beam.from_dict(d)
    assert(b2 == b1)

    print 'OK'
コード例 #31
0
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
コード例 #32
0
ファイル: test_serialize.py プロジェクト: cctbx/dxtbx
def test_beam():
    b1 = Beam((1, 0, 0), 2, 0.1, 0.1)
    d = b1.to_dict()
    b2 = BeamFactory.from_dict(d)
    assert d["direction"] == (1, 0, 0)
    assert d["wavelength"] == 2
    assert d["divergence"] == pytest.approx(0.1)
    assert d["sigma_divergence"] == pytest.approx(0.1)
    assert b1 == b2
    assert "s0_at_scan_points" not in d

    # Test with a template and partial dictionary
    d2 = {"direction": (0, 1, 0), "divergence": 0.2}
    b3 = BeamFactory.from_dict(d2, d)
    assert b3.get_sample_to_source_direction() == (0, 1, 0)
    assert b3.get_wavelength() == 2
    assert b3.get_divergence() == pytest.approx(0.2)
    assert b3.get_sigma_divergence() == pytest.approx(0.1)
    assert b2 != b3
コード例 #33
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
コード例 #34
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'
コード例 #35
0
ファイル: datablock.py プロジェクト: cctbx/cctbx-playground
 def load_models(obj):
   try:
     beam = Beam.from_dict(blist[obj['beam']])
   except Exception:
     beam = None
   try:
     dobj = dlist[obj['detector']]
     detector = Detector.from_dict(dobj)
   except Exception:
     detector = None
   try:
     from dxtbx.serialize import goniometer
     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
コード例 #36
0
ファイル: beam.py プロジェクト: cctbx/cctbx-playground
def from_dict(d, t=None):
  ''' Convert the dictionary to a beam model

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

  Returns:
      The beam model

  '''
  from dxtbx.model import Beam

  # 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 Beam.from_dict(d)
コード例 #37
0
ファイル: datablock.py プロジェクト: keitaroyam/cctbx_fork
 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
コード例 #38
0
 def _beam_from_dict(obj):
   ''' Get a beam from a dictionary. '''
   from dxtbx.model import Beam
   return Beam.from_dict(obj)