Exemple #1
0
def test_stills_indexer_multi_lattice_bug_MosaicSauter2014(
        dials_regression, tmpdir):
    """Problem: In stills_indexer, before calling the refine function, the
    experiment list contains a list of dxtbx crystal models (that are not
    MosaicSauter2014 models). The conversion to MosaicSauter2014 is made
    during the refine step when functions from nave_parameters is called.
    If the experiment list contains more than 1 experiment, for eg.
    multiple lattices, only the first crystal gets assigned mosaicity. In
    actuality, all crystal models should be assigned mosaicity. This test
    only compares whether or not all crystal models have been assigned a
    MosaicSauter2014 model."""

    import dxtbx.model
    from dxtbx.model import Crystal
    from dxtbx.model.experiment_list import (
        Experiment,
        ExperimentList,
        ExperimentListFactory,
    )

    from dials.algorithms.indexing.stills_indexer import StillsIndexer
    from dials.array_family import flex
    from dials.command_line.stills_process import (
        phil_scope as stills_process_phil_scope, )

    experiment_data = os.path.join(
        dials_regression,
        "refinement_test_data",
        "cspad_refinement",
        "cspad_refined_experiments_step6_level2_300.json",
    )
    reflection_data = os.path.join(
        dials_regression,
        "refinement_test_data",
        "cspad_refinement",
        "cspad_reflections_step7_300.pickle",
    )

    refl = flex.reflection_table.from_file(reflection_data)
    explist = ExperimentListFactory.from_json_file(experiment_data,
                                                   check_format=False)[0:2]
    reflist = refl.select(
        refl["id"] < 2)  # Only use the first 2 for convenience
    # Construct crystal models that don't have mosaicity. These A,B,C values are the same
    # as read in from the dials_regression folder
    # Crystal-0
    cs0 = Crystal(explist[0].crystal)
    exp0 = Experiment(
        imageset=explist[0].imageset,
        beam=explist[0].beam,
        detector=explist[0].detector,
        goniometer=None,
        scan=None,
        crystal=cs0,
    )

    # Crystal-1
    cs1 = Crystal(explist[1].crystal)
    exp1 = Experiment(
        imageset=explist[1].imageset,
        beam=explist[1].beam,
        detector=explist[1].detector,
        goniometer=None,
        scan=None,
        crystal=cs1,
    )
    # Construct a new experiment_list that will be passed on for refinement
    unrefined_explist = ExperimentList([exp0, exp1])
    # Get default params from stills_process and construct StillsIndexer, then run refinement
    params = stills_process_phil_scope.extract()
    SI = StillsIndexer(reflist, unrefined_explist, params=params)
    refined_explist, new_reflist = SI.refine(unrefined_explist, reflist)
    # Now check whether the models have mosaicity after stills_indexer refinement
    # Also check that mosaicity values are within expected limits
    for ii, crys in enumerate(refined_explist.crystals()):
        assert isinstance(crys, dxtbx.model.MosaicCrystalSauter2014)
        if ii == 0:
            assert crys.get_domain_size_ang() == pytest.approx(2242.0, rel=0.1)
        if ii == 1:
            assert crys.get_domain_size_ang() == pytest.approx(2689.0, rel=0.1)
Exemple #2
0
def test_stills_indexer_multi_lattice_bug_MosaicSauter2014(
        dials_regression, tmpdir):
    """ Problem: In stills_indexer, before calling the refine function, the experiment list contains a list of 
        dxtbx crystal models (that are not MosaicSauter2014 models). The conversion to MosaicSauter2014 is made 
        during the refine step when functions from nave_parameters is called. If the experiment list contains
        more than 1 experiment, for eg. multiple lattices, only the first crystal gets assigned mosaicity. In 
        actuality, all crystal models should be assigned mosaicity. This test only compares whether or not all crystal models
        have been assigned a MosaicSauter2014 model.  """

    import libtbx
    from dxtbx.model.experiment_list import ExperimentListFactory
    from dxtbx.model.experiment_list import Experiment, ExperimentList
    from dials.array_family import flex
    from dxtbx.model import Crystal
    from scitbx.matrix import col
    from dials.algorithms.indexing.stills_indexer import StillsIndexer
    from dials.command_line.stills_process import (
        phil_scope as stills_process_phil_scope, )
    import dxtbx_model_ext  # needed for comparison of types

    xfel_regression = libtbx.env.find_in_repositories(
        relative_path="xfel_regression", test=os.path.isdir)
    if not xfel_regression:
        pytest.skip("test requires xfel_regression")

    experiment_data = os.path.join(xfel_regression, "cspad_cbf_metrology",
                                   "input_combined_experiments_300.json")
    reflection_data = os.path.join(xfel_regression, "cspad_cbf_metrology",
                                   "input_combined_reflections_300.pickle")

    refl = flex.reflection_table.from_file(reflection_data)
    explist = ExperimentListFactory.from_json_file(experiment_data,
                                                   check_format=False)[0:2]
    reflist = refl.select(
        refl["id"] < 2)  # Only use the first 2 for convenience
    # Construct crystal models that don't have mosaicity. These A,B,C values are the same
    # as read in from the xfel_regression folder
    # Crystal-0
    sg = "P6122"
    c = col((-6.273802315592485, 130.0982158871206, -5.79093135302508))
    b = col((12.889379382910931, -3.488465493571038, -92.33550227410447))
    a = col((73.48274403946694, 6.087949131831335, 57.16094537694445))
    cs0 = Crystal(a, b, c, sg)
    exp0 = Experiment(
        imageset=explist[0].imageset,
        beam=explist[0].beam,
        detector=explist[0].detector,
        goniometer=None,
        scan=None,
        crystal=cs0,
    )

    # Crystal-1
    a1 = col((-9.848734136977392, -91.47863873838793, 15.37304224517648))
    b1 = col((-61.88040624461757, 60.16978337475523, 35.38476831968059))
    c1 = col((-72.13672676543942, -10.447921098609202, -108.38564134527415))
    cs1 = Crystal(a1, b1, c1, sg)
    exp1 = Experiment(
        imageset=explist[1].imageset,
        beam=explist[1].beam,
        detector=explist[1].detector,
        goniometer=None,
        scan=None,
        crystal=cs1,
    )
    # Construct a new experiment_list that will be passed on for refinement
    unrefined_explist = ExperimentList([exp0, exp1])
    # Get default params from stills_process and construct StillsIndexer, then run refinement
    params = stills_process_phil_scope.extract()
    SI = StillsIndexer(reflist, unrefined_explist, params=params)
    refined_explist, new_reflist = SI.refine(unrefined_explist, reflist)
    # Now check whether the models have mosaicity after stills_indexer refinement
    for crys in refined_explist.crystals():
        assert isinstance(crys, dxtbx_model_ext.MosaicCrystalSauter2014)