Exemple #1
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
Exemple #2
0
  def from_dict(d, t=None):
    ''' Convert the dictionary to a crystal model

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

    Returns:
        The crystal model

    '''
    # 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
    if 'ML_half_mosaicity_deg' in d:
      assert 'ML_domain_size_ang' in d
      if d['ML_half_mosaicity_deg'] is None or d['ML_domain_size_ang'] is None:
        assert d['ML_half_mosaicity_deg'] is None and d['ML_domain_size_ang'] is None
      else:
        if 'mosaicity' in d and d['mosaicity'] > 0:
          print "Warning, two kinds of mosaicity found. Using Sauter2014 model"
        from dxtbx.model import MosaicCrystalSauter2014
        return MosaicCrystalSauter2014.from_dict(d)
    if 'mosaicity' in d:
      from dxtbx.model import MosaicCrystalKabsch2010
      return MosaicCrystalKabsch2010.from_dict(d)
    else:
      from dxtbx.model import Crystal
      return Crystal.from_dict(d)
Exemple #3
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
Exemple #4
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)
Exemple #5
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
Exemple #6
0
def mock_exp(mock_scaling_component, idval=0):
    """Mock experiments object for initialising a scaler."""
    def side_effect_config_table(*args):
        """Side effect to mock configure reflection table
        call during initialisation."""
        return args[0]

    exp = MagicMock()
    exp.identifier = str(idval)
    exp.scaling_model.components = {"scale": mock_scaling_component}
    exp.scaling_model.consecutive_refinement_order = ["scale"]
    exp.scaling_model.is_scaled = False
    exp.scaling_model.configdict = {}
    exp.scaling_model.configure_reflection_table.side_effect = side_effect_config_table
    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",
    }
    exp.crystal = Crystal.from_dict(exp_dict)
    exp.scan.get_oscillation.return_value = (0, 1.0)
    exp.beam.get_sample_to_source_direction.return_value = (0.0, 0.0, -1.0)
    exp.goniometer.get_rotation_axis.return_value = (0.0, 0.0, 1.0)
    return exp
Exemple #7
0
def example_crystal():
    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, 1.0],
        "space_group_hall_symbol": "-P 2yb",
    }
    crystal = Crystal.from_dict(exp_dict)
    return crystal
def test_ModelEvaluation(dials_regression, tmpdir):
    # thaumatin
    data_dir = os.path.join(dials_regression, "indexing_test_data",
                            "i04_weak_data")
    pickle_path = os.path.join(data_dir, "full.pickle")
    sweep_path = os.path.join(data_dir, "experiments_import.json")

    input_reflections = flex.reflection_table.from_file(pickle_path)
    input_experiments = load.experiment_list(sweep_path, check_format=False)

    input_reflections = input_reflections.select(
        input_reflections["xyzobs.px.value"].parts()[2] < 100)
    input_reflections.centroid_px_to_mm(input_experiments[0].detector,
                                        scan=input_experiments[0].scan)
    input_reflections.map_centroids_to_reciprocal_space(
        input_experiments[0].detector,
        input_experiments[0].beam,
        goniometer=input_experiments[0].goniometer,
    )
    input_reflections["imageset_id"] = flex.size_t(input_reflections.size(), 0)
    input_reflections["id"] = flex.int(input_reflections.size(), -1)

    refine_params = refine_phil.fetch().extract()
    evaluator = model_evaluation.ModelEvaluation(
        refinement_params=refine_params)

    experiments = copy.deepcopy(input_experiments)
    reflections = copy.deepcopy(input_reflections)
    experiments[0].crystal = Crystal.from_dict(
        dict([
            ("__id__", "crystal"),
            (
                "real_space_a",
                (20.007058080503633, 49.721143642677994, 16.636052132572846),
            ),
            (
                "real_space_b",
                (-15.182202482876685, 24.93846318493148, -50.7116866438356),
            ),
            (
                "real_space_c",
                (-135.23051191036296, 41.14539066294313, 55.41374425160883),
            ),
            ("space_group_hall_symbol", " P 1"),
        ]))

    assign_indices = AssignIndicesGlobal()
    assign_indices(reflections, experiments)
    result = evaluator.evaluate(experiments, reflections)
    assert result is not None
    assert result.n_indexed == 7313
    assert result.fraction_indexed == pytest.approx(0.341155066244)
    assert result.rmsds == pytest.approx(
        (0.10215787570953785, 0.12954412140128563, 0.0010980583382102509))
Exemple #9
0
def aligned_lyso_crystal():
    from dxtbx.model import Crystal
    cryst_descr = {
        '__id__': 'crystal',
        'real_space_a': (79, 0, 0),
        'real_space_b': (0, 79, 0),
        'real_space_c': (0, 0, 38),
        'space_group_hall_symbol': '-P 4 2'
    }
    C = Crystal.from_dict(cryst_descr)
    return C
Exemple #10
0
def single_exp():
    """Generate an experiment object."""
    crystal = Crystal.from_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",
    })
    scan = Scan(image_range=[0, 60], oscillation=[0.0, 1.0])
    return Experiment(scan=scan, crystal=crystal)
def test_exp_P1():
    """Create a mock experiments object."""
    exp = Experiment()
    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, 1.0],
        "space_group_hall_symbol": " P 1",
    }
    crystal = Crystal.from_dict(exp_dict)
    exp.crystal = crystal
    return exp
Exemple #12
0
def test_exp(idval=0):
    """Test experiments 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)
    experiments.append(Experiment(crystal=crystal))
    experiments[0].identifier = str(idval)
    return experiments
Exemple #13
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",
    }
    for i in range(n):
        experiments.append(
            Experiment(
                scan=Scan(image_range=[1, 25], oscillation=[0.0, 1.0]),
                crystal=Crystal.from_dict(exp_dict),
                identifier=str(i),
            ))
    return experiments
Exemple #14
0
def example_array(reflections):
    """Generate a miller array for a test."""
    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, 1.0],
        "space_group_hall_symbol": "-P 2yb",
    }
    crystal = Crystal.from_dict(exp_dict)
    ms = miller.set(
        crystal_symmetry=crystal.get_crystal_symmetry(),
        indices=reflections["miller_index"],
        anomalous_flag=False,
    )
    ma = miller.array(ms, data=reflections["intensity"])
    ma.set_sigmas(reflections["variance"]**0.5)
    return ma
def generate_test_experiments(n=2):
    """Make a test experiment list"""
    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",
    }
    for i in range(n):
        experiments.append(
            Experiment(
                crystal=Crystal.from_dict(exp_dict),
                scan=Scan(image_range=[1, 10], oscillation=[0.0, 1.0]),
                scaling_model=get_scaling_model(),
                identifier=str(i),
            ))
    return experiments
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
    def from_dict(d, t=None):
        """Convert the dictionary to a crystal model

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

        Returns:
            The crystal model

        """
        if d is None and t is None:
            return None
        joint = t.copy() if t else {}
        joint.update(d)

        # Create the model from the dictionary
        if "ML_half_mosaicity_deg" in joint:
            assert "ML_domain_size_ang" in joint
            if (joint["ML_half_mosaicity_deg"] is None
                    or joint["ML_domain_size_ang"] is None):
                assert (joint["ML_half_mosaicity_deg"] is None
                        and joint["ML_domain_size_ang"] is None)
            else:
                if joint.get("mosaicity", 0) > 0:
                    print(
                        "Warning, two kinds of mosaicity found. Using Sauter2014 model"
                    )
                from dxtbx.model import MosaicCrystalSauter2014

                return MosaicCrystalSauter2014.from_dict(joint)
        if "mosaicity" in joint:
            from dxtbx.model import MosaicCrystalKabsch2010

            return MosaicCrystalKabsch2010.from_dict(joint)
        else:
            from dxtbx.model import Crystal

            return Crystal.from_dict(joint)
Exemple #18
0
  def from_dict(d, t=None):
    ''' Convert the dictionary to a crystal model

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

    Returns:
        The crystal model

    '''
    from dxtbx.model import Crystal

    # 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 Crystal.from_dict(d)
Exemple #19
0
def test_Result():

    rmsds = (0.0269546226916153, 0.03159452239902618, 0.004208711548775884)
    fraction_indexed = 0.9683976336148051
    model_likelihood = 0.95846970346759
    n_indexed = 19152
    crystal = Crystal.from_dict(
        dict([
            ("__id__", "crystal"),
            (
                "real_space_a",
                (-45.031874961773504, -14.833784919966813,
                 -48.766092343826806),
            ),
            (
                "real_space_b",
                (-32.15263553253188, 3.8725711269478085, 59.82290857456796),
            ),
            (
                "real_space_c",
                (29.6683003477066, 59.732569113301565, -13.880892871529552),
            ),
            ("space_group_hall_symbol", " P 1"),
        ]))

    result = model_evaluation.Result(
        rmsds=rmsds,
        fraction_indexed=fraction_indexed,
        model_likelihood=model_likelihood,
        n_indexed=n_indexed,
        crystal=crystal,
    )

    assert result.rmsds == rmsds
    assert result.fraction_indexed == fraction_indexed
    assert result.model_likelihood == model_likelihood
    assert result.n_indexed == n_indexed
    assert result.crystal == crystal
def generate_test_experiments(n=2):
    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=[1, 10], oscillation=[0.0, 1.0])
    experiments.append(
        Experiment(crystal=crystal, scan=scan, scaling_model=get_scaling_model())
    )
    experiments[0].identifier = "0"
    if n > 1:
        for i in range(n - 1):
            experiments.append(
                Experiment(
                    crystal=crystal, scan=scan, scaling_model=get_scaling_model()
                )
            )
            experiments[i + 1].identifier = str(i + 1)
    return experiments
Exemple #21
0
def test_filtered_arrays_from_experiments_reflections():
    """Test the creating of a miller array from crystal and reflection table."""
    refl = generate_integrated_test_reflections()
    refl["miller_index"] = flex.miller_index([(1, 0, 0), (2, 0, 0), (3, 0, 0),
                                              (4, 0, 0), (5, 0, 0), (6, 0, 0)])
    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)
    experiments.append(Experiment(crystal=crystal))

    miller_set = filtered_arrays_from_experiments_reflections(
        experiments, [refl])[0]
    assert isinstance(miller_set, miller.set)
    assert list(miller_set.data()) == [4.6, 2.4, 2.5]  # same as calling filter
    # for export on scale intensity reducer.
    # now try for prf
    del refl["intensity.scale.value"]
    miller_set = filtered_arrays_from_experiments_reflections(
        experiments, [refl])[0]
    assert isinstance(miller_set, miller.set)
    assert list(miller_set.data()) == [1.0, 2.0, 3.0]  # same as calling filter
    # for export on prf + sum intensity reducer.
    # now just for sum
    del refl["intensity.prf.value"]
    miller_set = filtered_arrays_from_experiments_reflections(
        experiments, [refl])[0]
    assert isinstance(miller_set, miller.set)
    assert list(miller_set.data()) == [11.0, 12.0, 13.0,
                                       14.0]  # same as calling
    # filter for export on prf intensity reducer.

    # Now try with a bad dataset - should be filtered.
    refl = generate_integrated_test_reflections()
    refl["miller_index"] = flex.miller_index([(1, 0, 0), (2, 0, 0), (3, 0, 0),
                                              (4, 0, 0), (5, 0, 0), (6, 0, 0)])
    # Trigger filtering on prf/sum, but when prf is bad - should proceed with sum
    refl.unset_flags(flex.bool(6, True), refl.flags.integrated_prf)
    del refl["intensity.scale.value"]
    refl2 = generate_integrated_test_reflections()
    refl2["partiality"] = flex.double(6, 0.0)
    experiments = ExperimentList()
    experiments.append(Experiment(crystal=crystal))
    experiments.append(Experiment(crystal=crystal))
    miller_sets = filtered_arrays_from_experiments_reflections(
        experiments, [refl, refl2], outlier_rejection_after_filter=True)
    assert len(miller_sets) == 1

    with pytest.raises(AssertionError):
        miller_sets = filtered_arrays_from_experiments_reflections(
            experiments, [refl, refl2], return_batches=True)

    experiments = ExperimentList()
    experiments.append(Experiment(crystal=crystal))
    experiments.append(Experiment(crystal=crystal))
    refl2 = generate_integrated_test_reflections()
    refl2["partiality"] = flex.double(6, 0.0)
    with pytest.raises(ValueError):
        refl["partiality"] = flex.double(6, 0.0)
        _ = filtered_arrays_from_experiments_reflections(
            experiments, [refl, refl2])
Exemple #22
0
def test_ModelRank():
    results = [
        model_evaluation.Result(
            rmsds=(0.0269546226916153, 0.03159452239902618, 0.004208711548775884),
            fraction_indexed=0.9683976336148051,
            model_likelihood=0.95846970346759,
            n_indexed=19152,
            crystal=Crystal.from_dict(
                dict(
                    [
                        ("__id__", "crystal"),
                        (
                            "real_space_a",
                            (
                                -45.031874961773504,
                                -14.833784919966813,
                                -48.766092343826806,
                            ),
                        ),
                        (
                            "real_space_b",
                            (-32.15263553253188, 3.8725711269478085, 59.82290857456796),
                        ),
                        (
                            "real_space_c",
                            (29.6683003477066, 59.732569113301565, -13.880892871529552),
                        ),
                        ("space_group_hall_symbol", " P 1"),
                    ]
                )
            ),
            hkl_offset=None,
        ),
        model_evaluation.Result(
            rmsds=(0.0341397658828684, 0.027401396596305812, 0.00427723439147068),
            fraction_indexed=0.9849825554937554,
            model_likelihood=0.9562237490188447,
            n_indexed=19480,
            crystal=Crystal.from_dict(
                dict(
                    [
                        ("__id__", "crystal"),
                        (
                            "real_space_a",
                            (29.66830034770662, 59.73256911330157, -13.880892871529573),
                        ),
                        (
                            "real_space_b",
                            (47.516210146598816, -48.77135532028254, 2.824076640788394),
                        ),
                        (
                            "real_space_c",
                            (
                                -45.036407933560845,
                                -14.950807536025826,
                                -49.06808637024198,
                            ),
                        ),
                        ("space_group_hall_symbol", " P 1"),
                    ]
                )
            ),
            hkl_offset=None,
        ),
        model_evaluation.Result(
            rmsds=(0.30456791867888355, 0.15679214175133024, 0.009635577811258947),
            fraction_indexed=0.33629974212469027,
            model_likelihood=0.6574428619874397,
            n_indexed=6651,
            crystal=Crystal.from_dict(
                dict(
                    [
                        ("__id__", "crystal"),
                        (
                            "real_space_a",
                            (
                                -11.907050303571122,
                                34.85499418820148,
                                30.689745759790572,
                            ),
                        ),
                        (
                            "real_space_b",
                            (-56.943458237132, 19.90418665217566, -18.37834061045143),
                        ),
                        (
                            "real_space_c",
                            (-41.63267941211685, -24.82747139443437, 44.5508337593274),
                        ),
                        ("space_group_hall_symbol", " P 1"),
                    ]
                )
            ),
            hkl_offset=None,
        ),
    ]

    ranker = model_evaluation.ModelRankWeighted()
    ranker.extend(results)
    assert list(ranker.score_by_fraction_indexed()) == pytest.approx(
        [0.02449862002620243, 0.0, 1.550350501381241]
    )
    assert list(ranker.score_by_rmsd_xy()) == pytest.approx(
        [0.0, 0.07598423386955666, 3.044108569529155]
    )
    assert list(ranker.score_by_volume()) == pytest.approx(
        [0.44207271296753703, 0.45026641813391066, 0.0]
    )
    assert list(ranker.combined_scores()) == pytest.approx(
        [0.19602846593366663, 0.20851345109588518, 11.670183660213905]
    )
    assert (
        str(ranker)
        == """\
+-------------------------------------+----------+----------------+------------+-------------+-------------------+-----------+-----------------+-----------------+
| unit_cell                           |   volume |   volume score |   #indexed |   % indexed |   % indexed score |   rmsd_xy |   rmsd_xy score |   overall score |
|-------------------------------------+----------+----------------+------------+-------------+-------------------+-----------+-----------------+-----------------|
| 68.02 68.03 68.12 109.6 109.5 109.3 |   242890 |           0.44 |      19152 |          97 |              0.02 |      0.04 |            0    |            0.2  |
| 68.12 68.15 68.26 109.5 109.4 109.4 |   244274 |           0.45 |      19480 |          98 |              0    |      0.04 |            0.08 |            0.21 |
| 47.94 63.06 65.84 75.2 71.6 74.5    |   178786 |           0    |       6651 |          34 |              1.55 |      0.34 |            3.04 |           11.67 |
+-------------------------------------+----------+----------------+------------+-------------+-------------------+-----------+-----------------+-----------------+"""
    )
    best = ranker.best_model()
    assert best.n_indexed == 19152

    ranker = model_evaluation.ModelRankFilter()
    ranker.extend(results)
    best = ranker.best_model()
    assert best.n_indexed == 19152
    assert (
        str(ranker)
        == """\
+-------------------------------------+----------+-------------+--------------------+--------------+
| unit_cell                           |   volume |   n_indexed |   fraction_indexed |   likelihood |
|-------------------------------------+----------+-------------+--------------------+--------------|
| 68.02 68.03 68.12 109.6 109.5 109.3 |   242890 |       19152 |                 97 |         0.96 |
| 68.12 68.15 68.26 109.5 109.4 109.4 |   244274 |       19480 |                 98 |         0.96 |
| 47.94 63.06 65.84 75.2 71.6 74.5    |   178786 |        6651 |                 34 |         0.66 |
+-------------------------------------+----------+-------------+--------------------+--------------+"""
    )
Exemple #23
0
def test_scale_script_prepare_input():
    """Test prepare_input method of scaling script."""

    # test the components of the scaling script directly with a test reflection
    # table, experiments list and params.

    params, exp, reflections = generate_test_input()
    # try to pass in unequal number of reflections and experiments
    reflections.append(generate_test_reflections())
    with pytest.raises(ValueError):
        _ = ScalingAlgorithm(params, exp, reflections)

    params, exp, reflections = generate_test_input()
    # Try to use use_datasets when not identifiers set
    params.dataset_selection.use_datasets = [0]
    with pytest.raises(ValueError):
        _ = ScalingAlgorithm(params, exp, reflections)
    # Try to use use_datasets when not identifiers set
    params.dataset_selection.use_datasets = None
    params.dataset_selection.exclude_datasets = [0]
    with pytest.raises(ValueError):
        _ = ScalingAlgorithm(params, exp, reflections)

    # Now make two experiments with identifiers and select on them
    params, exp, reflections = generate_test_input(n=2)
    exp[0].identifier = "0"
    reflections[0].experiment_identifiers()[0] = "0"
    exp[1].identifier = "1"
    reflections[1].experiment_identifiers()[0] = "1"
    list1 = ExperimentList().append(exp[0])
    list2 = ExperimentList().append(exp[1])
    reflections[0].assert_experiment_identifiers_are_consistent(list1)
    reflections[1].assert_experiment_identifiers_are_consistent(list2)
    params.dataset_selection.use_datasets = [0]
    params, exp, script_reflections = prepare_input(params, exp, reflections)

    assert len(script_reflections) == 1

    # Try again, this time excluding
    params, exp, reflections = generate_test_input(n=2)
    exp[0].identifier = "0"
    reflections[0].experiment_identifiers()[0] = "0"
    exp[1].identifier = "1"
    reflections[1].experiment_identifiers()[1] = "1"
    params.dataset_selection.exclude_datasets = [0]
    params, exp, script_reflections = prepare_input(params, exp, reflections)

    assert len(script_reflections) == 1
    assert script_reflections[0] is reflections[1]

    # Try having two unequal space groups
    params, exp, reflections = generate_test_input(n=2)
    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": " P 1",
    }
    crystal = Crystal.from_dict(exp_dict)
    exp[0].crystal = crystal
    with pytest.raises(ValueError):
        _ = prepare_input(params, exp, reflections)

    # Test cutting data
    params, exp, reflections = generate_test_input(n=1)
    params.cut_data.d_min = 1.5
    params, _, script_reflections = prepare_input(params, exp, reflections)
    r = script_reflections[0]
    assert list(r.get_flags(r.flags.user_excluded_in_scaling)) == [
        False,
        False,
        True,
        True,
    ]

    # Ensure that the user_excluded_in_scaling flags are reset before applying any new
    # cutoffs by re-passing script_reflections to prepare_input
    params.cut_data.d_min = None
    params, _, script_reflections = prepare_input(params, exp,
                                                  script_reflections)
    r = script_reflections[0]
    assert list(r.get_flags(r.flags.user_excluded_in_scaling)) == [
        False,
        False,
        False,
        False,
    ]

    params.cut_data.d_max = 1.25
    params, _, script_reflections = prepare_input(params, exp, reflections)
    r = script_reflections[0]
    assert list(r.get_flags(r.flags.user_excluded_in_scaling)) == [
        True,
        True,
        False,
        False,
    ]

    params, exp, reflections = generate_test_input(n=1)
    reflections[0]["partiality"] = flex.double([0.5, 0.8, 1.0, 1.0])
    params.cut_data.partiality_cutoff = 0.75
    _, __, script_reflections = prepare_input(params, exp, reflections)
    r = script_reflections[0]
    assert list(r.get_flags(r.flags.user_excluded_in_scaling)) == [
        True,
        False,
        False,
        False,
    ]
from __future__ import division
import numpy as np
from simtbx.nanoBragg.anisotropic_mosaicity import AnisoUmats
from dxtbx.model import Crystal

cryst_dict = dict([('__id__', 'crystal'),
                   ('real_space_a', (-48.93914505851325, -61.4985726090971,
                                     0.23980318971727585)),
                   ('real_space_b', (-27.63556200961052, 72.26768337463876,
                                     13.81410546001183)),
                   ('real_space_c', (-42.92524538136074, 33.14788397044063,
                                     -259.2845460893375)),
                   ('space_group_hall_symbol', '-P 6 2')])

cryst = Crystal.from_dict(cryst_dict)

# mosaicities in degrees
eta_a, eta_b, eta_c = 0.02, 0.1, 0.03

# Generate mosaic models with randomized sampling, no derivatives
Nmos = 1000
A = AnisoUmats(num_random_samples=Nmos)

# spherical cap model
U, Uprime, Udblprime = A.generate_Umats(eta=[eta_a, eta_a, eta_a],
                                        crystal=cryst,
                                        how=2,
                                        verbose=True,
                                        compute_derivs=True)
from simtbx.nanoBragg.tst_gaussian_mosaicity import plotter2
U_by2, _, _ = A.generate_Umats(eta_a / 2.,