Esempio n. 1
0
def test_score_screw_axes_equivalent_axes():
    """Test the score_screw_axes function (when equivalent axes present)."""
    laue_group_info = laue_groups["P m -3"]

    # unique axis 21a, but should pick up 21b, 21c
    reflections = flex.reflection_table()
    reflections["miller_index"] = flex.miller_index([(0, 1, 0), (0, 2, 0),
                                                     (0, 0, 1), (0, 0, 2)])
    reflections["intensity"] = flex.double([0.05, 100.0, 0.02, 100.0])
    reflections["variance"] = flex.double([1.0, 1.0, 1.0, 1.0])

    axes, scores = score_screw_axes(laue_group_info, reflections)
    assert len(scores) == 1
    assert len(axes) == 1
    assert axes[0].name == "21a"
    assert scores[0] > 0.99
Esempio n. 2
0
def run_sys_abs_checks(experiments, reflections, d_min=None, significance_level=0.95):
    """Check for systematic absences in the data for the laue group.

    Select the good data, merge, test screw axes and score possible space
    groups. The crystals are updated with the most likely space group.
    """

    if (
        "inverse_scale_factor" in reflections[0]
        and "intensity.scale.value" in reflections[0]
    ):
        logger.info("Attempting to perform absence checks on scaled data")
        reflections = filter_reflection_table(
            reflections[0], intensity_choice=["scale"], d_min=d_min
        )
        reflections["intensity"] = reflections["intensity.scale.value"]
        reflections["variance"] = reflections["intensity.scale.variance"]
    else:
        logger.info(
            "Attempting to perform absence checks on unscaled profile-integrated data"
        )
        reflections = filter_reflection_table(
            reflections[0], intensity_choice=["profile"], d_min=d_min
        )
        reflections["intensity"] = reflections["intensity.prf.value"]
        reflections["variance"] = reflections["intensity.prf.variance"]

    # now merge
    space_group = experiments[0].crystal.get_space_group()
    reflections["asu_miller_index"] = map_indices_to_asu(
        reflections["miller_index"], space_group
    )
    reflections["inverse_scale_factor"] = flex.double(reflections.size(), 1.0)
    merged = (
        _reflection_table_to_iobs(
            reflections, experiments[0].crystal.get_unit_cell(), space_group
        )
        .merge_equivalents(use_internal_variance=False)
        .array()
    )
    merged_reflections = flex.reflection_table()
    merged_reflections["intensity"] = merged.data()
    merged_reflections["variance"] = merged.sigmas() ** 2
    merged_reflections["miller_index"] = merged.indices()

    # Get the laue class from the space group.
    laue_group = str(space_group.build_derived_patterson_group().info())
    logger.info("Laue group: %s", laue_group)
    if laue_group not in laue_groups:
        logger.info("No absences to check for this laue group")
        return

    # Score the screw axes.
    screw_axes, screw_axis_scores = score_screw_axes(
        laue_groups[laue_group], merged_reflections, significance_level
    )

    logger.info(
        simple_table(
            [
                [
                    a.name,
                    "%.3f" % score,
                    str(a.n_refl_used[0]),
                    str(a.n_refl_used[1]),
                    "%.3f" % a.mean_I,
                    "%.3f" % a.mean_I_abs,
                    "%.3f" % a.mean_I_sigma,
                    "%.3f" % a.mean_I_sigma_abs,
                ]
                for a, score in zip(screw_axes, screw_axis_scores)
            ],
            column_headers=[
                "Screw axis",
                "Score",
                "No. present",
                "No. absent",
                "<I> present",
                "<I> absent",
                "<I/sig> present",
                "<I/sig> absent",
            ],
        ).format()
    )

    # Score the space groups from the screw axis scores.
    space_groups, scores = score_space_groups(
        screw_axis_scores, laue_groups[laue_group]
    )

    logger.info(
        simple_table(
            [[sg, "%.4f" % score] for sg, score in zip(space_groups, scores)],
            column_headers=["Space group", "score"],
        ).format()
    )

    # Find the best space group and update the experiments.
    best_sg = space_groups[scores.index(max(scores))]
    logger.info("Recommended space group: %s", best_sg)
    if "enantiomorphic pairs" in laue_groups[laue_group]:
        if best_sg in laue_groups[laue_group]["enantiomorphic pairs"]:
            logger.info(
                "Space group with equivalent score (enantiomorphic pair): %s",
                laue_groups[laue_group]["enantiomorphic pairs"][best_sg],
            )

    new_sg = sgtbx.space_group_info(symbol=best_sg).group()
    for experiment in experiments:
        experiment.crystal.set_space_group(new_sg)
Esempio n. 3
0
def run_sys_abs_checks(experiments,
                       merged_reflections,
                       significance_level=0.95):
    """Check for systematic absences in the data for the laue group.

    Using a reflection table containing merged data, test screw axes and score
    possible space groups. The crystals are updated with the most likely space
    group.
    """
    # Get the laue class from the space group.
    space_group = experiments[0].crystal.get_space_group()
    laue_group = str(space_group.build_derived_patterson_group().info())
    logger.info("Laue group: %s", laue_group)
    if laue_group not in laue_groups:
        logger.info("No absences to check for this laue group")
        return

    # Score the screw axes.
    screw_axes, screw_axis_scores = score_screw_axes(laue_groups[laue_group],
                                                     merged_reflections,
                                                     significance_level)

    logger.info(
        simple_table(
            [[
                a.name,
                "%.3f" % score,
                str(a.n_refl_used[0]),
                str(a.n_refl_used[1]),
                "%.3f" % a.mean_I,
                "%.3f" % a.mean_I_abs,
                "%.3f" % a.mean_I_sigma,
                "%.3f" % a.mean_I_sigma_abs,
            ] for a, score in zip(screw_axes, screw_axis_scores)],
            column_headers=[
                "Screw axis",
                "Score",
                "No. present",
                "No. absent",
                "<I> present",
                "<I> absent",
                "<I/sig> present",
                "<I/sig> absent",
            ],
        ).format())

    # Score the space groups from the screw axis scores.
    space_groups, scores = score_space_groups(screw_axis_scores,
                                              laue_groups[laue_group])

    logger.info(
        simple_table(
            [[sg, "%.4f" % score] for sg, score in zip(space_groups, scores)],
            column_headers=["Space group", "score"],
        ).format())

    # Find the best space group and update the experiments.
    best_sg = space_groups[scores.index(max(scores))]
    logger.info("Recommended space group: %s", best_sg)
    if "enantiomorphic pairs" in laue_groups[laue_group]:
        if best_sg in laue_groups[laue_group]["enantiomorphic pairs"]:
            logger.info(
                "Space group with equivalent score (enantiomorphic pair): %s",
                laue_groups[laue_group]["enantiomorphic pairs"][best_sg],
            )

    new_sg = sgtbx.space_group_info(symbol=best_sg).group()
    for experiment in experiments:
        experiment.crystal.set_space_group(new_sg)