vermouth-martinize icon indicating copy to clipboard operation
vermouth-martinize copied to clipboard

slow subgraph

Open fgrunewald opened this issue 1 year ago • 7 comments

it appears nx.subgraph is rather slow, which directly affects a bunch of processes in martinize2. Mostly it is used when making the residue graph. Depending on the complexity of the residues a dumb implementation like shown below is about 5-10 times faster I assume because it scales much better than whatever nx does.

Why do you then not simply implement that you may ask: Something something ISMAGS now dies.

def _custom_subgraph(graph, nodes):
    """
    Make a custom subgraph copy of nodes from graph.
    """
    subgraph = nx.Graph()
    for node in nodes:
        subgraph.add_node(node, **graph.nodes[node])
        for neighbor in graph.edges(node):
            if neighbor in nodes:
                subgraph.add_edge(node, neighbor)
    return subgraph

fgrunewald avatar Jul 25 '22 12:07 fgrunewald