Example #1
0
def test_make_cluster_plots():
    from xfel.clustering.cluster import Cluster

    c1 = Cluster.from_iterable([
        (10.0, 10.0, 10.0, 90, 90, 90, "P1"),
        (10.1, 10.1, 10.1, 90, 90, 90, "P1"),
        (10.2, 10.2, 10.2, 90, 90, 90, "P1"),
    ])
    c2 = Cluster.from_iterable([
        (11.0, 11.0, 11.0, 90, 90, 90, "P1"),
        (11.1, 11.1, 11.1, 90, 90, 90, "P1"),
        (11.2, 11.2, 11.2, 90, 90, 90, "P1"),
        (11.3, 11.3, 11.3, 90, 90, 90, "P1"),
    ])
    clusters = [c1, c2]
    plots = make_cluster_plots(clusters)
    assert "uc_scatter_0" in plots
    assert "uc_scatter_1" in plots
    assert "uc_hist_0" in plots
    assert "uc_hist_1" in plots
    print(plots)
    assert len(plots["uc_hist_0"]["data"]) == 3
    assert len(plots["uc_hist_0"]["data"][0]["x"]) == 3
    assert len(plots["uc_hist_1"]["data"][0]["x"]) == 4
    assert len(plots["uc_scatter_0"]["data"]) == 3
    assert len(plots["uc_scatter_0"]["data"][0]["x"]) == 3
    assert len(plots["uc_scatter_1"]["data"][0]["x"]) == 4
Example #2
0
    def run(self, iterable):

        # with Capturing() as junk_output:
        errors = []
        try:
            ucs = Cluster.from_iterable(iterable=iterable)
            clusters, _ = ucs.ab_cluster(5000,
                                         log=False,
                                         write_file_lists=False,
                                         schnell=True,
                                         doplot=False)
        except Exception as e:
            print("IOTA ERROR (CLUSTERING): ", e)
            clusters = []
            errors.append(str(e))

        info = []
        if clusters:
            for cluster in clusters:
                uc_init = unit_cell(cluster.medians)
                symmetry = crystal.symmetry(unit_cell=uc_init,
                                            space_group_symbol="P1")
                groups = lattice_symmetry.metric_subgroups(
                    input_symmetry=symmetry, max_delta=3)
                top_group = groups.result_groups[0]
                best_sg = str(groups.lattice_group_info()).split("(")[0]
                best_uc = top_group["best_subsym"].unit_cell().parameters()
                uc_no_stdev = ("{:<6.2f} {:<6.2f} {:<6.2f} "
                               "{:<6.2f} {:<6.2f} {:<6.2f} "
                               "".format(
                                   best_uc[0],
                                   best_uc[1],
                                   best_uc[2],
                                   best_uc[3],
                                   best_uc[4],
                                   best_uc[5],
                               ))
                cluster_info = {
                    "number": len(cluster.members),
                    "pg": str(best_sg),
                    "uc": uc_no_stdev,
                }
                info.append(cluster_info)

        return info, errors
    def run(self, iterable):

        with Capturing() as junk_output:
            try:
                ucs = Cluster.from_iterable(iterable=iterable)
                clusters, _ = ucs.ab_cluster(5000,
                                             log=False,
                                             write_file_lists=False,
                                             schnell=True,
                                             doplot=False)
            except Exception:
                clusters = []

        if len(clusters) > 0:
            info = []
            for cluster in clusters:
                uc_init = unit_cell(cluster.medians)
                symmetry = crystal.symmetry(unit_cell=uc_init,
                                            space_group_symbol='P1')
                groups = lattice_symmetry.metric_subgroups(
                    input_symmetry=symmetry, max_delta=3)
                top_group = groups.result_groups[0]
                best_uc = top_group['best_subsym'].unit_cell().parameters()
                best_sg = top_group['best_subsym'].space_group_info()

                uc_no_stdev = "{:<6.2f} {:<6.2f} {:<6.2f} " \
                              "{:<6.2f} {:<6.2f} {:<6.2f} " \
                              "".format(best_uc[0], best_uc[1], best_uc[2],
                                        best_uc[3], best_uc[4], best_uc[5])
                cluster_info = {
                    'number': len(cluster.members),
                    'pg': str(best_sg),
                    'uc': uc_no_stdev
                }

                info.append(cluster_info)

        else:
            info = None

        return info
    def cluster_unit_cells(self):
        input = []
        for item in self.spotfinding_info:
            if item[4] is not None:
                try:
                    info_line = [float(i) for i in item[4]]
                    info_line.append(item[3])
                    input.append(info_line)
                except ValueError:
                    pass

        with misc.Capturing() as junk_output:
            try:
                ucs = Cluster.from_iterable(iterable=input)
                clusters, _ = ucs.ab_cluster(5000,
                                             log=False,
                                             write_file_lists=False,
                                             schnell=True,
                                             doplot=False)
            except Exception, e:
                clusters = []