Пример #1
0
def run_indexing(datablock, strong_spots, crystal_model, rmsds):

  cwd = os.path.abspath(os.curdir)
  tmp_dir = os.path.abspath(open_tmp_directory(suffix="test_dials_index"))
  os.chdir(tmp_dir)

  sweep_path = os.path.join(tmp_dir, "datablock.json")
  pickle_path = os.path.join(tmp_dir, "strong.pickle")

  dump.datablock(datablock, sweep_path)
  easy_pickle.dump(pickle_path, strong_spots)

  from dials.test.algorithms.indexing.tst_index import run_one_indexing

  space_group_info = crystal_model.get_space_group()
  symmetry = crystal.symmetry(unit_cell=crystal_model.get_unit_cell(),
                              space_group=crystal_model.get_space_group())

  expected_rmsds = [1.1*r for r in rmsds]

  imageset = datablock[0].extract_imagesets()[0]
  pixel_size = imageset.get_detector()[0].get_pixel_size()
  phi_width = imageset.get_scan().get_oscillation()[1] * math.pi/180

  expected_rmsds = [1.1 * rmsds[0] * pixel_size[0],
                    1.1 * rmsds[1] * pixel_size[1],
                    1.1 * rmsds[2] * phi_width]

  run_one_indexing(pickle_path=pickle_path, sweep_path=sweep_path,
                   extra_args=[],
                   expected_unit_cell=symmetry.minimum_cell().unit_cell(),
                   expected_rmsds=expected_rmsds,
                   #expected_hall_symbol=crystal_model.get_space_group().type().hall_symbol(),
                   expected_hall_symbol=' P 1',
                   )
Пример #2
0
def run_indexing(datablock, strong_spots, crystal_model, rmsds):

    cwd = os.path.abspath(os.curdir)
    tmp_dir = os.path.abspath(open_tmp_directory(suffix="test_dials_index"))
    os.chdir(tmp_dir)

    sweep_path = os.path.join(tmp_dir, "datablock.json")
    pickle_path = os.path.join(tmp_dir, "strong.pickle")

    dump.datablock(datablock, sweep_path)
    easy_pickle.dump(pickle_path, strong_spots)

    from dials.test.algorithms.indexing.tst_index import run_one_indexing

    space_group_info = crystal_model.get_space_group()
    symmetry = crystal.symmetry(unit_cell=crystal_model.get_unit_cell(),
                                space_group=crystal_model.get_space_group())

    expected_rmsds = [1.1 * r for r in rmsds]

    imageset = datablock[0].extract_imagesets()[0]
    pixel_size = imageset.get_detector()[0].get_pixel_size()
    phi_width = imageset.get_scan().get_oscillation()[1] * math.pi / 180

    expected_rmsds = [
        1.1 * rmsds[0] * pixel_size[0], 1.1 * rmsds[1] * pixel_size[1],
        1.1 * rmsds[2] * phi_width
    ]

    run_one_indexing(
        pickle_path=pickle_path,
        sweep_path=sweep_path,
        extra_args=[],
        expected_unit_cell=symmetry.minimum_cell().unit_cell(),
        expected_rmsds=expected_rmsds,
        #expected_hall_symbol=crystal_model.get_space_group().type().hall_symbol(),
        expected_hall_symbol=' P 1',
    )
Пример #3
0
def exercise_2():

    from dials.test.algorithms.indexing.tst_index import run_one_indexing
    if not have_xia2_regression:
        print "Skipping exercise_2(): xia2_regression not available."
        return

    curdir = os.path.abspath(os.curdir)
    print curdir

    data_dir = os.path.join(xia2_regression, "test_data", "i04_bag_training")

    import glob
    g = glob.glob(os.path.join(data_dir, "*.cbf*"))
    if len(g) == 0:
        print "Skipping exercise_2(): xia2_regression files not downloaded."
        print "Run xia2_regression.fetch_test_data first."
        return

    # beam centre from image headers: 205.28,210.76 mm
    args = ["dials.import", "mosflm_beam_centre=207,212"] + g
    command = " ".join(args)
    #print command
    result = easy_run.fully_buffered(command=command).raise_if_errors()
    assert os.path.exists('datablock.json')

    # spot-finding, just need a subset of the data
    args = [
        "dials.find_spots", "datablock.json", "scan_range=1,10",
        "scan_range=531,540"
    ]
    command = " ".join(args)
    print command
    result = easy_run.fully_buffered(command=command).raise_if_errors()
    assert os.path.exists('strong.pickle')

    # actually run the beam centre search
    args = [
        "dials.discover_better_experimental_model", "datablock.json",
        "strong.pickle"
    ]
    command = " ".join(args)
    print command
    result = easy_run.fully_buffered(command=command).raise_if_errors()
    result.show_stdout()
    assert os.path.exists('optimized_datablock.json')

    # look at the results
    from dxtbx.serialize import load
    datablocks = load.datablock("datablock.json", check_format=False)
    original_imageset = datablocks[0].extract_imagesets()[0]
    optimized_datablock = load.datablock('optimized_datablock.json',
                                         check_format=False)
    detector_1 = original_imageset.get_detector()
    detector_2 = optimized_datablock[0].unique_detectors()[0]
    shift = (matrix.col(detector_1[0].get_origin()) -
             matrix.col(detector_2[0].get_origin()))
    print shift

    # check we can actually index the resulting optimized datablock
    from cctbx import uctbx
    expected_unit_cell = uctbx.unit_cell(
        (57.780, 57.800, 150.017, 89.991, 89.990, 90.007))
    expected_rmsds = (0.06, 0.05, 0.001)
    expected_hall_symbol = ' P 1'
    result = run_one_indexing(os.path.join(curdir, 'strong.pickle'),
                              os.path.join(curdir, 'optimized_datablock.json'),
                              [], expected_unit_cell, expected_rmsds,
                              expected_hall_symbol)
def exercise_2():

    from dials.test.algorithms.indexing.tst_index import run_one_indexing

    if not have_xia2_regression:
        print "Skipping exercise_2(): xia2_regression not available."
        return

    curdir = os.path.abspath(os.curdir)
    print curdir

    data_dir = os.path.join(xia2_regression, "test_data", "i04_bag_training")

    import glob

    g = glob.glob(os.path.join(data_dir, "*.cbf"))
    if len(g) == 0:
        print "Skipping exercise_2(): xia2_regression files not downloaded."
        print "Run xia2_regression.fetch_test_data first."
        return

    # beam centre from image headers: 205.28,210.76 mm
    args = ["dials.import", "mosflm_beam_centre=207,212"] + g
    command = " ".join(args)
    # print command
    result = easy_run.fully_buffered(command=command).raise_if_errors()
    assert os.path.exists("datablock.json")

    # spot-finding, just need a subset of the data
    args = ["dials.find_spots", "datablock.json", "scan_range=1,10", "scan_range=531,540"]
    command = " ".join(args)
    print command
    result = easy_run.fully_buffered(command=command).raise_if_errors()
    assert os.path.exists("strong.pickle")

    # actually run the beam centre search
    args = ["dials.discover_better_experimental_model", "datablock.json", "strong.pickle"]
    command = " ".join(args)
    print command
    result = easy_run.fully_buffered(command=command).raise_if_errors()
    result.show_stdout()
    assert os.path.exists("optimized_datablock.json")

    # look at the results
    from dxtbx.serialize import load

    datablocks = load.datablock("datablock.json", check_format=False)
    original_imageset = datablocks[0].extract_imagesets()[0]
    optimized_datablock = load.datablock("optimized_datablock.json", check_format=False)
    detector_1 = original_imageset.get_detector()
    detector_2 = optimized_datablock[0].unique_detectors()[0]
    shift = matrix.col(detector_1[0].get_origin()) - matrix.col(detector_2[0].get_origin())
    print shift

    # check we can actually index the resulting optimized datablock
    from cctbx import uctbx

    expected_unit_cell = uctbx.unit_cell((57.780, 57.800, 150.017, 89.991, 89.990, 90.007))
    expected_rmsds = (0.06, 0.05, 0.001)
    expected_hall_symbol = " P 1"
    result = run_one_indexing(
        os.path.join(curdir, "strong.pickle"),
        os.path.join(curdir, "optimized_datablock.json"),
        [],
        expected_unit_cell,
        expected_rmsds,
        expected_hall_symbol,
    )
Пример #5
0
def run():
    have_dials_regression = libtbx.env.has_module("dials_regression")
    if not have_dials_regression:
        print "Skipped: dials_regression not available"
        return
    dials_regression = libtbx.env.find_in_repositories(
        relative_path="dials_regression", test=os.path.isdir)

    from dials.test.algorithms.indexing.tst_index import run_one_indexing

    expected_unit_cell = uctbx.unit_cell(
        (11.624, 13.550, 30.103, 89.964, 93.721, 90.132))
    expected_rmsds = (0.039, 0.035, 0.002)

    datablock_old = os.path.join(
        dials_regression, "indexing_test_data/phi_scan/datablock_old.json")
    datablock_new = os.path.join(dials_regression,
                                 "indexing_test_data/phi_scan/datablock.json")
    strong_pickle = os.path.join(dials_regression,
                                 "indexing_test_data/phi_scan/strong.pickle")

    from dxtbx.serialize import load
    imageset_old = load.datablock(datablock_old,
                                  check_format=False)[0].extract_imagesets()[0]
    imageset_new = load.datablock(datablock_new,
                                  check_format=False)[0].extract_imagesets()[0]

    gonio_old = imageset_old.get_goniometer()
    gonio_new = imageset_new.get_goniometer()

    assert approx_equal(
        gonio_old.get_rotation_axis(),
        (0.7497646259807715, -0.5517923303436749, 0.36520984351713554))
    assert approx_equal(gonio_old.get_setting_rotation(),
                        (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))
    assert approx_equal(
        gonio_old.get_fixed_rotation(),
        (0.7497646259807748, -0.20997265900532208, -0.6275065641872948,
         -0.5517923303436731, 0.3250014637526764, -0.7680490041218182,
         0.3652098435171313, 0.9221092836691605, 0.12781329809272568))

    assert approx_equal(gonio_new.get_rotation_axis(),
                        gonio_old.get_rotation_axis())
    assert approx_equal(gonio_new.get_rotation_axis_datum(), (1, 0, 0))
    assert approx_equal(
        gonio_new.get_setting_rotation(),
        (0.7497646259807705, -0.20997265900532142, -0.6275065641873,
         -0.5517923303436786, 0.3250014637526763, -0.768049004121814,
         0.3652098435171315, 0.9221092836691607, 0.12781329809272335))
    assert approx_equal(gonio_new.get_fixed_rotation(),
                        (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))

    result_old = run_one_indexing(
        pickle_path=strong_pickle,
        sweep_path=datablock_old,
        extra_args=[],
        expected_unit_cell=expected_unit_cell,
        expected_rmsds=expected_rmsds,
        expected_hall_symbol=' P 1',
    )

    result_new = run_one_indexing(
        pickle_path=strong_pickle,
        sweep_path=datablock_new,
        extra_args=[],
        expected_unit_cell=expected_unit_cell,
        expected_rmsds=expected_rmsds,
        expected_hall_symbol=' P 1',
    )

    assert approx_equal(result_old.rmsds, result_new.rmsds)
    assert approx_equal(result_old.crystal_model.get_unit_cell().parameters(),
                        result_new.crystal_model.get_unit_cell().parameters())

    # Now test refinement gradients are correct
    from dxtbx.model.experiment_list import ExperimentList, Experiment
    old_exps = ExperimentList([
        Experiment(beam=imageset_old.get_beam(),
                   detector=imageset_old.get_detector(),
                   goniometer=gonio_old,
                   scan=imageset_old.get_scan(),
                   crystal=result_old.crystal_model,
                   imageset=None)
    ])
    new_exps = ExperimentList([
        Experiment(beam=imageset_new.get_beam(),
                   detector=imageset_new.get_detector(),
                   goniometer=gonio_new,
                   scan=imageset_new.get_scan(),
                   crystal=result_new.crystal_model,
                   imageset=None)
    ])

    from libtbx.phil import parse
    from dials.algorithms.refinement.refiner import phil_scope
    params = phil_scope.fetch(source=parse('')).extract()
    from dials.algorithms.refinement.refiner import RefinerFactory
    refiner_old = RefinerFactory.from_parameters_data_experiments(
        params, result_old.indexed_reflections, old_exps, verbosity=0)
    refiner_new = RefinerFactory.from_parameters_data_experiments(
        params, result_new.indexed_reflections, new_exps, verbosity=0)

    # Analytical gradients should be approximately the same in either case
    an_grads_old = refiner_old._pred_param.get_gradients(
        refiner_old.get_matches())
    an_grads_new = refiner_new._pred_param.get_gradients(
        refiner_new.get_matches())
    for g1, g2 in zip(an_grads_old, an_grads_new):
        assert approx_equal(g1["dX_dp"], g2["dX_dp"], eps=1.e-6)
        assert approx_equal(g1["dY_dp"], g2["dY_dp"], eps=1.e-6)
        assert approx_equal(g1["dphi_dp"], g2["dphi_dp"], eps=1.e-6)

    # Analytical gradients should be approximately equal to finite difference
    # gradients in either case
    fd_grads_old = calc_fd_grads(refiner_old)
    for g1, g2 in zip(fd_grads_old, an_grads_old):
        assert approx_equal(g1["dX_dp"], g2["dX_dp"], eps=5.e-6)
        assert approx_equal(g1["dY_dp"], g2["dY_dp"], eps=5.e-6)
        assert approx_equal(g1["dphi_dp"], g2["dphi_dp"], eps=5.e-6)
    fd_grads_new = calc_fd_grads(refiner_new)
    for g1, g2 in zip(fd_grads_new, an_grads_new):
        assert approx_equal(g1["dX_dp"], g2["dX_dp"], eps=5.e-6)
        assert approx_equal(g1["dY_dp"], g2["dY_dp"], eps=5.e-6)
        assert approx_equal(g1["dphi_dp"], g2["dphi_dp"], eps=5.e-6)
Пример #6
0
def run():
    have_dials_regression = libtbx.env.has_module("dials_regression")
    if not have_dials_regression:
        print "Skipped: dials_regression not available"
        return
    dials_regression = libtbx.env.find_in_repositories(
        relative_path="dials_regression", test=os.path.isdir)

    from dials.test.algorithms.indexing.tst_index import run_one_indexing

    expected_unit_cell = uctbx.unit_cell(
        (11.624, 13.550, 30.103, 89.964, 93.721, 90.132))
    expected_rmsds = (0.028, 0.031, 0.094)

    datablock_old = os.path.join(
        dials_regression, "indexing_test_data/phi_scan/datablock_old.json")
    datablock_new = os.path.join(dials_regression,
                                 "indexing_test_data/phi_scan/datablock.json")
    strong_pickle = os.path.join(dials_regression,
                                 "indexing_test_data/phi_scan/strong.pickle")

    from dxtbx.serialize import load
    imageset_old = load.datablock(datablock_old,
                                  check_format=False)[0].extract_imagesets()[0]
    imageset_new = load.datablock(datablock_new,
                                  check_format=False)[0].extract_imagesets()[0]

    gonio_old = imageset_old.get_goniometer()
    gonio_new = imageset_new.get_goniometer()

    assert approx_equal(
        gonio_old.get_rotation_axis(),
        (0.7497646259807715, -0.5517923303436749, 0.36520984351713554))
    assert approx_equal(gonio_old.get_setting_rotation(),
                        (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))
    assert approx_equal(
        gonio_old.get_fixed_rotation(),
        (0.7497646259807748, -0.20997265900532208, -0.6275065641872948,
         -0.5517923303436731, 0.3250014637526764, -0.7680490041218182,
         0.3652098435171313, 0.9221092836691605, 0.12781329809272568))

    assert approx_equal(gonio_new.get_rotation_axis(),
                        gonio_old.get_rotation_axis())
    assert approx_equal(gonio_new.get_rotation_axis_datum(), (1, 0, 0))
    assert approx_equal(
        gonio_new.get_setting_rotation(),
        (0.7497646259807705, -0.20997265900532142, -0.6275065641873,
         -0.5517923303436786, 0.3250014637526763, -0.768049004121814,
         0.3652098435171315, 0.9221092836691607, 0.12781329809272335))
    assert approx_equal(gonio_new.get_fixed_rotation(),
                        (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))

    result_old = run_one_indexing(
        pickle_path=strong_pickle,
        sweep_path=datablock_old,
        extra_args=[],
        expected_unit_cell=expected_unit_cell,
        expected_rmsds=expected_rmsds,
        expected_hall_symbol=' P 1',
    )

    result_new = run_one_indexing(
        pickle_path=strong_pickle,
        sweep_path=datablock_new,
        extra_args=[],
        expected_unit_cell=expected_unit_cell,
        expected_rmsds=expected_rmsds,
        expected_hall_symbol=' P 1',
    )

    assert approx_equal(result_old.rmsds, result_new.rmsds)
    assert approx_equal(result_old.crystal_model.get_unit_cell().parameters(),
                        result_new.crystal_model.get_unit_cell().parameters())
Пример #7
0
def run():
  have_dials_regression = libtbx.env.has_module("dials_regression")
  if not have_dials_regression:
    print "Skipped: dials_regression not available"
    return
  dials_regression = libtbx.env.find_in_repositories(
    relative_path="dials_regression",
    test=os.path.isdir)

  from dials.test.algorithms.indexing.tst_index import run_one_indexing

  expected_unit_cell = uctbx.unit_cell(
    (11.624, 13.550, 30.103, 89.964, 93.721, 90.132))
  expected_rmsds = (0.039, 0.035, 0.002)

  datablock_old = os.path.join(
    dials_regression, "indexing_test_data/phi_scan/datablock_old.json")
  datablock_new = os.path.join(
    dials_regression, "indexing_test_data/phi_scan/datablock.json")
  strong_pickle = os.path.join(
    dials_regression, "indexing_test_data/phi_scan/strong.pickle")

  from dxtbx.serialize import load
  imageset_old = load.datablock(
    datablock_old, check_format=False)[0].extract_imagesets()[0]
  imageset_new = load.datablock(
    datablock_new, check_format=False)[0].extract_imagesets()[0]

  gonio_old = imageset_old.get_goniometer()
  gonio_new = imageset_new.get_goniometer()

  assert approx_equal(
    gonio_old.get_rotation_axis(),
    (0.7497646259807715, -0.5517923303436749, 0.36520984351713554))
  assert approx_equal(
    gonio_old.get_setting_rotation(),
    (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))
  assert approx_equal(
    gonio_old.get_fixed_rotation(),
    (0.7497646259807748, -0.20997265900532208, -0.6275065641872948,
     -0.5517923303436731, 0.3250014637526764, -0.7680490041218182,
     0.3652098435171313, 0.9221092836691605, 0.12781329809272568))

  assert approx_equal(
    gonio_new.get_rotation_axis(), gonio_old.get_rotation_axis())
  assert approx_equal(gonio_new.get_rotation_axis_datum(), (1,0,0))
  assert approx_equal(
    gonio_new.get_setting_rotation(),
    (0.7497646259807705, -0.20997265900532142, -0.6275065641873,
     -0.5517923303436786, 0.3250014637526763, -0.768049004121814,
     0.3652098435171315, 0.9221092836691607, 0.12781329809272335))
  assert approx_equal(
    gonio_new.get_fixed_rotation(),
    (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))

  result_old = run_one_indexing(
    pickle_path=strong_pickle, sweep_path=datablock_old,
    extra_args=[],
    expected_unit_cell=expected_unit_cell,
    expected_rmsds=expected_rmsds,
    expected_hall_symbol=' P 1',
    )

  result_new = run_one_indexing(
    pickle_path=strong_pickle, sweep_path=datablock_new,
    extra_args=[],
    expected_unit_cell=expected_unit_cell,
    expected_rmsds=expected_rmsds,
    expected_hall_symbol=' P 1',
    )

  assert approx_equal(result_old.rmsds, result_new.rmsds)
  assert approx_equal(result_old.crystal_model.get_unit_cell().parameters(),
                      result_new.crystal_model.get_unit_cell().parameters())