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}
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}
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)