vermouth-martinize
vermouth-martinize copied to clipboard
slow subgraph
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