Exemplo n.º 1
0
    def get_knob_graphs(self, min_scut=7.0, max_scut=9.0, scut_increment=0.5):
        """

        Parameters
        ----------
        min_scut: float
        max_scut: float
        scut_increment: float
            values between min and max scut at scut_increment are used as iSocket cutoffs for getting graphs

        Returns
        -------
        knob_graphs: list[nextworkx.Graph]
            List of graph objects representing each connected component subgraph at range of scut and kcut values.
            Each graph g has a g.graph dictionary containing the data needed to populate the database.
        """
        kg = self.get_knob_group(cutoff=max_scut)
        if kg is not None:
            scuts = list(
                numpy.arange(min_scut, max_scut + scut_increment,
                             scut_increment))
            kcuts = list(range(4))
            g = kg.graph
            knob_graphs = []
            for scut, kcut in itertools.product(scuts[::-1], kcuts):
                h = kg.filter_graph(g=g, cutoff=scut, min_kihs=kcut)
                h = graph_to_plain_graph(g=h)
                # if is null graph
                if h.number_of_nodes() == 0:
                    continue
                if networkx.connected.is_connected(h):
                    ccs = [h]
                else:
                    ccs = sorted(networkx.connected_component_subgraphs(
                        h, copy=True),
                                 key=lambda x: len(x.nodes()),
                                 reverse=True)
                for cc_num, cc in enumerate(ccs):
                    name = isomorphism_checker(cc, graph_list=_graph_list)
                    d = dict(scut=scut,
                             kcut=kcut,
                             code=self.code,
                             cc_num=cc_num,
                             preferred=self.is_preferred,
                             mmol=self.mmol,
                             name=name,
                             nodes=cc.number_of_nodes(),
                             edges=cc.number_of_edges())
                    cc.graph.update(d)
                    knob_graphs.append(cc)
        else:
            knob_graphs = []
        return knob_graphs
Exemplo n.º 2
0
def add_unknowns(knob_graphs, mode):
    """ Name all new unknown graphs, add them to unknown_pickle and to database.

    Parameters
    ----------
    knob_graphs: list(networkx.Graph)
    mode: str
        Allowed values: 'production' or 'testing'.

    Returns
    -------
    None
    """
    large_graph_list = AtlasHandler().get_graph_list(atlas=False,
                                                     cyclics=False,
                                                     paths=False,
                                                     unknowns=True)
    assert not all_graphs_named(knob_graphs=knob_graphs)
    assert all(
        isomorphism_checker(x, graph_list=large_graph_list)
        for x in knob_graphs)
    next_number_to_add = max([int(x.name[1:]) for x in large_graph_list]) + 1
    to_add_to_atlas = []
    for i, g in enumerate(knob_graphs):
        n = isomorphism_checker(g, graph_list=knob_graphs[:i])
        if n is None:
            h = graph_to_plain_graph(g)
            n = 'U{}'.format(next_number_to_add)
            h.name = n
            to_add_to_atlas.append(h)
            next_number_to_add += 1
        g.graph['name'] = n
    large_graph_list += to_add_to_atlas
    unknown_pickle = global_settings["unknown_graphs"][mode]
    with open(unknown_pickle, 'wb') as foo:
        pickle.dump(large_graph_list, foo)
    populate_atlas(graph_list=to_add_to_atlas)
    return
Exemplo n.º 3
0
def name_against_unknowns(knob_graphs):
    """ Checks each unnamed graph for isomorphism against list of 'unknown' (large) graphs.

    Parameters
    ----------
    knob_graphs: list(networkx.Graph)

    Returns
    -------
    None
    """
    large_graph_list = AtlasHandler().get_graph_list(atlas=False,
                                                     cyclics=False,
                                                     paths=False,
                                                     unknowns=True)
    for g in knob_graphs:
        if g.graph['name'] is None:
            name = isomorphism_checker(g, graph_list=large_graph_list)
            if name is not None:
                g.graph['name'] = name
    return
Exemplo n.º 4
0
 def test_complete_graph(self):
     g = complete_graph(8)
     self.assertIsNone(isomorphism_checker(g))
Exemplo n.º 5
0
 def test_pentamer(self):
     pent = cycle_graph(5)
     self.assertEqual(isomorphism_checker(pent), "G38")
Exemplo n.º 6
0
 def test_octomer(self):
     octamer = cycle_graph(8)
     self.assertEqual(
         isomorphism_checker(octamer, graph_list=self.graph_list), "C8")