Exemplo n.º 1
0
 def __init__(self, parameters_dict, configdict, is_scaled=False):
     """Create the phyiscal scaling model components."""
     super(PhysicalScalingModel, self).__init__(configdict, is_scaled)
     if "scale" in configdict["corrections"]:
         scale_setup = parameters_dict["scale"]
         self._components["scale"] = SmoothScaleComponent1D(
             scale_setup["parameters"], scale_setup["parameter_esds"])
     if "decay" in configdict["corrections"]:
         decay_setup = parameters_dict["decay"]
         self._components["decay"] = SmoothBScaleComponent1D(
             decay_setup["parameters"], decay_setup["parameter_esds"])
     if "absorption" in configdict["corrections"]:
         absorption_setup = parameters_dict["absorption"]
         self._components["absorption"] = SHScaleComponent(
             absorption_setup["parameters"],
             absorption_setup["parameter_esds"])
Exemplo n.º 2
0
def test_SHScalefactor():
    """Test the spherical harmonic absorption component."""
    initial_param = 0.1
    initial_val = 0.2

    SF = SHScaleComponent(flex.double([initial_param] * 3))
    assert SF.n_params == 3
    assert list(SF.parameters) == [initial_param] * 3

    # Test functionality just by setting sph_harm_table directly and calling
    # update_reflection_data to initialise the harmonic values.
    harmonic_values = sparse.matrix(3, 1)
    harmonic_values[0, 0] = initial_val
    harmonic_values[1, 0] = initial_val
    harmonic_values[2, 0] = initial_val
    SF.data = {"sph_harm_table": harmonic_values}
    SF.update_reflection_data()
    print(SF.harmonic_values)
    assert SF.harmonic_values[0][0, 0] == initial_val
    assert SF.harmonic_values[0][0, 1] == initial_val
    assert SF.harmonic_values[0][0, 2] == initial_val
    s, d = SF.calculate_scales_and_derivatives()
    assert list(s) == [1.0 + (3.0 * initial_val * initial_param)]
    assert d[0, 0] == initial_val
    assert d[0, 1] == initial_val
    assert d[0, 2] == initial_val
    s, d = SF.calculate_scales_and_derivatives()

    # Test functionality of passing in a selection
    harmonic_values = sparse.matrix(3, 2)
    harmonic_values[0, 0] = initial_val
    harmonic_values[0, 1] = initial_val
    harmonic_values[2, 0] = initial_val
    SF.data = {"sph_harm_table": harmonic_values}
    SF.update_reflection_data(flex.bool([False, True]))
    assert SF.harmonic_values[0].n_rows == 1
    assert SF.harmonic_values[0].n_cols == 3
    assert SF.n_refl[0] == 1

    # Test setting of restraints and that restraints are calculated.
    # Not testing actual calculation as may want to change the form.
    SF.parameter_restraints = flex.double([0.1, 0.2, 0.3])
    assert SF.parameter_restraints == flex.double([0.1, 0.2, 0.3])
    restraints = SF.calculate_restraints()
    assert restraints[0] is not None
    assert restraints[1] is not None
    jacobian_restraints = SF.calculate_jacobian_restraints()
    assert jacobian_restraints[0] is not None
    assert jacobian_restraints[1] is not None