Exemple #1
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
    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)
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
Exemple #4
0
def imagesweep_from_dict(d, check_format=True, directory=None):
    """Construct and image sweep from the dictionary."""
    # Get the template (required)
    template = load_path(str(d["template"]), directory=directory)

    # If the scan isn't set, find all available files
    scan_dict = d.get("scan")
    if scan_dict is None:
        image_range = None
    else:
        image_range = scan_dict.get("image_range")

    # Set the models with the exisiting models as templates
    beam = BeamFactory.from_dict(d.get("beam"))
    goniometer = GoniometerFactory.from_dict(d.get("goniometer"))
    detector = DetectorFactory.from_dict(d.get("detector"))
    scan = ScanFactory.from_dict(d.get("scan"))

    # Construct the sweep
    try:
        sweep = ImageSetFactory.from_template(
            template,
            image_range,
            beam=beam,
            detector=detector,
            goniometer=goniometer,
            scan=scan,
            check_format=check_format,
        )[0]
    except Exception:
        indices = range(image_range[0], image_range[1] + 1)
        sweep = ImageSetFactory.make_sweep(
            template,
            indices,
            beam=beam,
            detector=detector,
            goniometer=goniometer,
            scan=scan,
            check_format=check_format,
        )

    # Set some external lookups
    if "mask" in d and d["mask"] is not None and d["mask"] is not "":
        path = load_path(d["mask"], directory=directory)
        with open(path) as infile:
            sweep.external_lookup.mask.filename = path
            sweep.external_lookup.mask.data = ImageBool(pickle.load(infile))
    if "gain" in d and d["gain"] is not None and d["gain"] is not "":
        path = load_path(d["gain"], directory=directory)
        with open(path) as infile:
            sweep.external_lookup.gain.filename = path
            sweep.external_lookup.gain.data = ImageDouble(pickle.load(infile))
    if "pedestal" in d and d["pedestal"] is not None and d["pedestal"] is not "":
        path = load_path(d["pedestal"], directory=directory)
        with open(path) as infile:
            sweep.external_lookup.pedestal.filename = path
            sweep.external_lookup.pedestal.data = ImageDouble(pickle.load(infile))

    # Return the sweep
    return sweep
Exemple #5
0
def imagesweep_from_dict(d, check_format=True):
    '''Construct and image sweep from the dictionary.'''
    from dxtbx.imageset import ImageSetFactory
    from dxtbx.model import BeamFactory, DetectorFactory, GoniometerFactory, ScanFactory
    from dxtbx.serialize.filename import load_path

    # Get the template (required)
    template = load_path(str(d['template']))

    # If the scan isn't set, find all available files
    scan_dict = d.get('scan')
    if scan_dict is None:
        image_range = None
    else:
        image_range = scan_dict.get('image_range')

    # Set the models with the exisiting models as templates
    beam = BeamFactory.from_dict(d.get('beam'))
    goniometer = GoniometerFactory.from_dict(d.get('goniometer'))
    detector = DetectorFactory.from_dict(d.get('detector'))
    scan = ScanFactory.from_dict(d.get('scan'))

    # Construct the sweep
    try:
        sweep = ImageSetFactory.from_template(template,
                                              image_range,
                                              beam=beam,
                                              detector=detector,
                                              goniometer=goniometer,
                                              scan=scan,
                                              check_format=check_format)[0]
    except Exception:
        indices = range(image_range[0], image_range[1] + 1)
        sweep = ImageSetFactory.make_sweep(template,
                                           indices,
                                           beam=beam,
                                           detector=detector,
                                           goniometer=goniometer,
                                           scan=scan,
                                           check_format=check_format)

    # Set some external lookups
    if 'mask' in d and d['mask'] is not None and d['mask'] is not "":
        with open(d['mask']) as infile:
            sweep.external_lookup.mask.filename = d['mask']
            sweep.external_lookup.mask.data = ImageBool(pickle.load(infile))
    if 'gain' in d and d['gain'] is not None and d['gain'] is not "":
        with open(d['gain']) as infile:
            sweep.external_lookup.gain.filename = d['gain']
            sweep.external_lookup.gain.data = ImageDouble(pickle.load(infile))
    if 'pedestal' in d and d['pedestal'] is not None and d[
            'pedestal'] is not "":
        with open(d['pedestal']) as infile:
            sweep.external_lookup.pedestal.filename = d['pedestal']
            sweep.external_lookup.pedestal.data = ImageDouble(
                pickle.load(infile))

    # Return the sweep
    return sweep
def test_experiments_multiaxisgonio():
    """Create a mock experiments object."""
    # beam along +z
    gonio_1 = GoniometerFactory.from_dict(
        {
            "axes": [
                [
                    1.0 / sqrt(2.0),
                    0.0,
                    -1.0 / sqrt(2.0),
                ],
                [1.0, 0.0, 0.0],
            ],
            "angles": [0.0, 0.0],
            "names": ["GON_PHI", "GON_OMEGA"],
            "scan_axis": 1,
        }
    )
    gonio_2 = GoniometerFactory.from_dict(
        {
            "axes": [
                [
                    1.0 / sqrt(2.0),
                    0.0,
                    -1.0 / sqrt(2.0),
                ],
                [1.0, 0.0, 0.0],
            ],
            "angles": [0.0, 0.0],
            "names": ["GON_PHI", "GON_OMEGA"],
            "scan_axis": 0,
        }
    )

    experiments = ExperimentList()
    for g in [gonio_1, gonio_2]:
        experiments.append(
            Experiment(
                beam=Beam(s0=(0.0, 0.0, 2.0)),
                goniometer=g,
                scan=Scan(image_range=[1, 90], oscillation=[0.0, 1.0]),
            )
        )

    return experiments
Exemple #7
0
def test_multi_axis_goniometer():
    g1 = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )),
                                      flex.double((0, )),
                                      flex.std_string(("PHI", )), 0)
    d = g1.to_dict()
    g2 = GoniometerFactory.from_dict(d)
    assert d["axes"] == [(1, 0, 0)]
    assert d["angles"] == [0.0]
    assert d["names"] == ["PHI"]
    assert d["scan_axis"] == 0
    assert g1 == g2
    assert "setting_rotation_at_scan_points" not in d

    # Test with a template and partial dictionary
    d2 = {"axes": [(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 test_multi_axis_goniometer():
    from dxtbx.model import GoniometerFactory
    from scitbx.array_family import flex
    g1 = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )),
                                      flex.double((0, )),
                                      flex.std_string(('PHI', )), 0)
    d = g1.to_dict()
    g2 = GoniometerFactory.from_dict(d)
    assert d['axes'] == [(1, 0, 0)]
    assert d['angles'] == [0.0]
    assert d['names'] == ['PHI']
    assert d['scan_axis'] == 0
    assert g1 == g2
    assert 'setting_rotation_at_scan_points' not in d

    # Test with a template and partial dictionary
    d2 = {'axes': [(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
Exemple #9
0
def import_geometry(xds_inp=None, dials_json=None):
    assert (xds_inp, dials_json).count(None) == 1

    geom_kwds = set([
        "DIRECTION_OF_DETECTOR_X-AXIS",
        "DIRECTION_OF_DETECTOR_Y-AXIS",
        "DETECTOR_DISTANCE",
        "ORGX",
        "ORGY",
        "ROTATION_AXIS",  # "X-RAY_WAVELENGTH",
        "INCIDENT_BEAM_DIRECTION",
        "SEGMENT",
        "DIRECTION_OF_SEGMENT_X-AXIS",
        "DIRECTION_OF_SEGMENT_Y-AXIS",
        "SEGMENT_DISTANCE",
        "SEGMENT_ORGX",
        "SEGMENT_ORGY"
    ])

    # FIXME in case of multi-segment detector..

    if xds_inp:
        inp = get_xdsinp_keyword(xds_inp)
        inp = filter(lambda x: x[0] in geom_kwds, inp)
        return map(lambda x: "%s= %s" % x, inp)
    elif dials_json:
        import dxtbx.imageset
        from dxtbx.serialize.load import _decode_dict
        from dxtbx.model import BeamFactory
        from dxtbx.model import DetectorFactory
        from dxtbx.model import GoniometerFactory
        from dxtbx.model import ScanFactory
        from dxtbx.serialize.xds import to_xds
        j = json.loads(open(dials_json).read(), object_hook=_decode_dict)
        # dummy
        sweep = dxtbx.imageset.ImageSetFactory.from_template(
            "####", image_range=[1, 1], check_format=False)[0]
        sweep.set_detector(DetectorFactory.from_dict(j["detector"][0]))
        sweep.set_beam(BeamFactory.from_dict(j["beam"][0]))
        sweep.set_goniometer(GoniometerFactory.from_dict(j["goniometer"][0]))
        sweep.set_scan(
            ScanFactory.make_scan(image_range=[1, 1],
                                  exposure_times=[1],
                                  oscillation=[1, 2],
                                  epochs=[0]))  # dummy
        sio = cStringIO.StringIO()
        to_xds(sweep).XDS_INP(sio)
        inp = get_xdsinp_keyword(inp_str=sio.getvalue())
        inp = filter(lambda x: x[0] in geom_kwds, inp)
        return map(lambda x: "%s= %s" % x, inp)

    return []
def test_experiment_singleaxisgonio():
    gonio = GoniometerFactory.from_dict({
        "axes": [
            [1.0, 0.0, 0.0],
        ],
        "angles": [0.0],
        "names": ["GON_PHI"],
        "scan_axis": 0,
    })
    return Experiment(
        beam=Beam(s0=(0.0, 0.0, 2.0)),
        goniometer=gonio,
        scan=Scan(image_range=[1, 90], oscillation=[0.0, 1.0]),
    )
Exemple #11
0
 def load_models(obj):
   try:
     beam = BeamFactory.from_dict(blist[obj['beam']])
   except Exception:
     beam = None
   try:
     dobj = dlist[obj['detector']]
     detector = DetectorFactory.from_dict(dobj)
   except Exception:
     detector = None
   try:
     gonio = GoniometerFactory.from_dict(glist[obj['goniometer']])
   except Exception:
     gonio = None
   try:
     scan = ScanFactory.from_dict(slist[obj['scan']])
   except Exception:
     scan = None
   return beam, detector, gonio, scan
Exemple #12
0
def test_goniometer_with_scan_points():
    simple_g = Goniometer((1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1))
    multi_ax_g = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )),
                                              flex.double((0, )),
                                              flex.std_string(("PHI", )), 0)

    for g1 in [simple_g, multi_ax_g]:

        S_static = matrix.sqr(g1.get_setting_rotation())
        g1.set_setting_rotation_at_scan_points([S_static] * 5)
        d = g1.to_dict()
        g2 = GoniometerFactory.from_dict(d)

        for Scomp in d["setting_rotation_at_scan_points"]:
            assert matrix.sqr(Scomp) == S_static

        for Scomp in g2.get_setting_rotation_at_scan_points():
            assert matrix.sqr(Scomp) == S_static

        assert g1 == g2
def test_goniometer_with_scan_points():
    from dxtbx.model import Goniometer, GoniometerFactory
    from scitbx.array_family import flex
    simple_g = Goniometer((1, 0, 0), (1, 0, 0, 0, 1, 0, 0, 0, 1))
    multi_ax_g = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )),
                                              flex.double((0, )),
                                              flex.std_string(('PHI', )), 0)

    from scitbx import matrix
    for g1 in [simple_g, multi_ax_g]:

        S_static = matrix.sqr(g1.get_setting_rotation())
        g1.set_setting_rotation_at_scan_points([S_static] * 5)
        d = g1.to_dict()
        g2 = GoniometerFactory.from_dict(d)

        for Scomp in d['setting_rotation_at_scan_points']:
            assert matrix.sqr(Scomp) == S_static

        for Scomp in g2.get_setting_rotation_at_scan_points():
            assert matrix.sqr(Scomp) == S_static

        assert g1 == g2
 def _goniometer_from_dict(obj):
     ''' Get the goniometer from a dictionary. '''
     from dxtbx.model import GoniometerFactory
     return GoniometerFactory.from_dict(obj)
Exemple #15
0
def imagesweep_from_dict(d, check_format=True):
    '''Construct and image sweep from the dictionary.'''
    from dxtbx.imageset import ImageSetFactory
    from dxtbx.model import BeamFactory, DetectorFactory, GoniometerFactory, ScanFactory
    from dxtbx.serialize.filename import load_path

    # Get the template (required)
    template = load_path(str(d['template']))

    # If the scan isn't set, find all available files
    scan_dict = d.get('scan')
    if scan_dict is None:
        image_range = None
    else:
        image_range = scan_dict.get('image_range')

    # Construct the sweep
    try:
        sweep = ImageSetFactory.from_template(template,
                                              image_range,
                                              check_format=check_format)[0]

        # Get the existing models as dictionaries
        beam_dict = sweep.get_beam().to_dict()
        gonio_dict = sweep.get_goniometer().to_dict()
        detector_dict = sweep.get_detector().to_dict()
        scan_dict = sweep.get_scan().to_dict()
    except Exception:
        indices = range(image_range[0], image_range[1] + 1)
        sweep = ImageSetFactory.make_sweep(template,
                                           indices,
                                           check_format=False)
        beam_dict = None
        gonio_dict = None
        detector_dict = None
        scan_dict = None

    # Set some external lookups
    if 'mask' in d and d['mask'] is not None:
        with open(d['mask']) as infile:
            sweep.external_lookup.mask.filename = d['mask']
            sweep.external_lookup.mask.data = pickle.load(infile)
    if 'gain' in d and d['gain'] is not None:
        with open(d['gain']) as infile:
            sweep.external_lookup.gain.filename = d['gain']
            sweep.external_lookup.gain.data = pickle.load(infile)
    if 'pedestal' in d and d['pedestal'] is not None:
        with open(d['pedestal']) as infile:
            sweep.external_lookup.pedestal.filename = d['pedestal']
            sweep.external_lookup.pedestal.data = pickle.load(infile)

    # Set the models with the exisiting models as templates
    sweep.set_beam(BeamFactory.from_dict(d.get('beam'), beam_dict))
    sweep.set_goniometer(
        GoniometerFactory.from_dict(d.get('goniometer'), gonio_dict))
    sweep.set_detector(
        DetectorFactory.from_dict(d.get('detector'), detector_dict))
    sweep.set_scan(ScanFactory.from_dict(d.get('scan'), scan_dict))

    # Return the sweep
    return sweep
Exemple #16
0
 def _goniometer_from_dict(obj):
     """ Get the goniometer from a dictionary. """
     return GoniometerFactory.from_dict(obj)