Пример #1
0
def test_MultiScalerFactory(generated_param, mock_scaling_component,
                            refl_list):
    """Test the MultiScalerFactory."""

    refl_list, explist = test_refl_and_exp_list(mock_scaling_component, 3)

    multiscaler = MultiScalerFactory.create(generated_param, explist,
                                            refl_list)
    assert isinstance(multiscaler, MultiScaler)
    assert len(multiscaler.single_scalers) == 3
    for i in range(3):
        assert set(multiscaler.single_scalers[i].reflection_table["id"]) == {i}

    # This time make one dataset bad, and check it gets removed
    r1 = generated_refl(not_integrated=True)
    r2 = generated_refl()
    r3 = generated_refl()
    new_list = [r1, r2, r3]
    multiscaler = MultiScalerFactory.create(
        generated_param, mock_explist_3exp(mock_scaling_component), new_list)
    assert isinstance(multiscaler, MultiScaler)
    assert len(multiscaler.single_scalers) == 2
    r1 = multiscaler.single_scalers[0].reflection_table
    assert list(r1.get_flags(
        r1.flags.integrated)) == [True, True, False, False]
    r2 = multiscaler.single_scalers[1].reflection_table
    assert list(r2.get_flags(
        r2.flags.integrated)) == [True, True, False, False]
Пример #2
0
def test_TargetScalerFactory(generated_param, mock_scaling_component):
    """Test the target scaler factory."""

    refl_list, explist = test_refl_and_exp_list(mock_scaling_component, 3)

    # Test standard initialisation.
    assert generated_param.scaling_options.use_free_set is False  # just to check
    explist[0].scaling_model.is_scaled = True
    explist[1].scaling_model.is_scaled = True
    target = TargetScalerFactory.create(generated_param, explist, refl_list)
    assert isinstance(target, TargetScaler)
    assert len(target.single_scalers) == 2
    assert len(target.unscaled_scalers) == 1
    assert set(target.single_scalers[0].reflection_table["id"]) == {0}
    assert set(target.single_scalers[1].reflection_table["id"]) == {1}
    assert set(target.unscaled_scalers[0].reflection_table["id"]) == {2}

    # Now test converting targetscaler to multiscaler
    multiscaler = MultiScalerFactory.create_from_targetscaler(target)
    assert isinstance(multiscaler, MultiScaler)
    assert len(multiscaler.single_scalers) == 3

    # Test for correct initialisation when scaling against a target model.
    generated_param.scaling_options.target_model = True
    target = TargetScalerFactory.create_for_target_against_reference(
        generated_param, explist, refl_list)
    assert isinstance(target.single_scalers[0], NullScaler)

    # This time make one dataset bad, and check it gets removed
    refl_list, explist = test_refl_and_exp_list(mock_scaling_component, 3)
    generated_param.scaling_options.target_model = False
    refl_list[1].unset_flags(flex.bool(4, True),
                             refl_list[1].flags.integrated_prf)
    refl_list[1].unset_flags(flex.bool(4, True),
                             refl_list[1].flags.integrated_sum)
    explist[0].scaling_model.is_scaled = True
    target = TargetScalerFactory.create(generated_param, explist, refl_list)
    assert isinstance(target, TargetScaler)
    assert len(target.single_scalers) == 1
    assert len(target.unscaled_scalers) == 1
    assert set(target.single_scalers[0].reflection_table["id"]) == {0}
    assert set(target.unscaled_scalers[0].reflection_table["id"]) == {2}

    refl_list, explist = test_refl_and_exp_list(mock_scaling_component, 3)
    refl_list[0].unset_flags(flex.bool(4, True),
                             refl_list[0].flags.integrated_prf)
    refl_list[0].unset_flags(flex.bool(4, True),
                             refl_list[0].flags.integrated_sum)
    explist[0].scaling_model.is_scaled = True
    explist[1].scaling_model.is_scaled = True
    target = TargetScalerFactory.create(generated_param, explist, refl_list)
    assert isinstance(target, TargetScaler)
    assert len(target.single_scalers) == 1
    assert len(target.unscaled_scalers) == 1
    assert set(target.single_scalers[0].reflection_table["id"]) == {1}
    assert set(target.unscaled_scalers[0].reflection_table["id"]) == {2}
Пример #3
0
def test_TargetScalerFactory(generated_param, mock_scaling_component):
    """Test the target scaler factory."""

    refl_list, explist = test_refl_and_exp_list(mock_scaling_component, 3)

    # Test standard initialisation.
    assert generated_param.scaling_options.use_free_set is False  # just to check
    target = TargetScalerFactory.create(
        generated_param, explist, refl_list, is_scaled_list=[True, True, False]
    )
    assert isinstance(target, TargetScaler)
    assert len(target.single_scalers) == 2
    assert len(target.unscaled_scalers) == 1
    assert set(target.single_scalers[0].reflection_table["id"]) == {0}
    assert set(target.single_scalers[1].reflection_table["id"]) == {1}
    assert set(target.unscaled_scalers[0].reflection_table["id"]) == {2}

    # Test for correct initialisation hen scaling against a target model.
    generated_param.scaling_options.target_model = True
    target = TargetScalerFactory.create(
        generated_param, explist, refl_list, is_scaled_list=[True, True, False]
    )
    assert isinstance(target.single_scalers[0], NullScaler)
    assert isinstance(target.single_scalers[1], NullScaler)

    # Now test converting targetscaler to multiscaler
    multiscaler = MultiScalerFactory.create_from_targetscaler(target)
    assert isinstance(multiscaler, MultiScaler)
    assert len(multiscaler.single_scalers) == 3

    # This time make one dataset bad, and check it gets removed
    refl_list, explist = test_refl_and_exp_list(mock_scaling_component, 3)
    generated_param.scaling_options.target_model = False
    refl_list[1]["d"] = flex.double([-0.1, -0.1, -0.1, -0.1])
    target = TargetScalerFactory.create(
        generated_param, explist, refl_list, is_scaled_list=[True, False, False]
    )
    assert isinstance(target, TargetScaler)
    assert len(target.single_scalers) == 1
    assert len(target.unscaled_scalers) == 1
    assert set(target.single_scalers[0].reflection_table["id"]) == {0}
    assert set(target.unscaled_scalers[0].reflection_table["id"]) == {2}

    refl_list, explist = test_refl_and_exp_list(mock_scaling_component, 3)
    refl_list[0]["d"] = flex.double([-0.1, -0.1, -0.1, -0.1])
    target = TargetScalerFactory.create(
        generated_param, explist, refl_list, is_scaled_list=[True, True, False]
    )
    assert isinstance(target, TargetScaler)
    assert len(target.single_scalers) == 1
    assert len(target.unscaled_scalers) == 1
    assert set(target.single_scalers[0].reflection_table["id"]) == {1}
    assert set(target.unscaled_scalers[0].reflection_table["id"]) == {2}
Пример #4
0
    def scale(self):
        """The main scaling algorithm."""

        if self.scaler.id_ == "target":
            ### FIXME add in quick prescaling round if large scale difference?
            self.scaler.perform_scaling()

            if (self.params.scaling_options.only_target
                    or self.params.scaling_options.target_model
                    or self.params.scaling_options.target_mtz):

                self.scaler = targeted_scaling_algorithm(self.scaler)
                return
            # Now pass to a multiscaler ready for next round of scaling.
            self.scaler.expand_scales_to_all_reflections()
            self.scaler = MultiScalerFactory.create_from_targetscaler(
                self.scaler)

        # From here onwards, scaler should only be a SingleScaler
        # or MultiScaler (not TargetScaler).
        self.scaler = scaling_algorithm(self.scaler)