vermouth.graph_utils module

class vermouth.graph_utils.MappingGraphMatcher(*args, edge_match=None, node_match=None, **kwargs)[source]

Bases: networkx.algorithms.isomorphism.isomorphvf2.GraphMatcher

semantic_feasibility(G1_node, G2_node)[source]

Returns True if mapping G1_node to G2_node is semantically feasible. Adapted from networkx.algorithms.isomorphism.vf2userfunc._semantic_feasibility.

vermouth.graph_utils.add_element_attr(molecule)[source]

Adds an element attribute to every node in molecule, based on that node’s atomname attribute.

Parameters:molecule (networkx.Graph) – The graph of which nodes should get an element attribute.
Raises:ValueError – If no element could be guessed for a node.
vermouth.graph_utils.categorical_cartesian_product(graph1, graph2, attributes=())[source]
vermouth.graph_utils.categorical_maximum_common_subgraph(graph1, graph2, attributes=())[source]
vermouth.graph_utils.categorical_modular_product(graph1, graph2, attributes=())[source]
vermouth.graph_utils.collect_residues(graph, attrs=('chain', 'resid', 'resname', 'insertion_code'))[source]

Creates groups of indices based on the node attributes with keys attrs. All nodes in graph will be part of exactly one group.

Parameters:
  • graph (networkx.Graph) – The graph whose node indices should be grouped.
  • attrs (Sequence) – The attribute keys that should be used to group node indices. The associated values should be hashable.
Returns:

The keys are the found node attributes, the values the associated node indices.

Return type:

dict[tuple, set]

vermouth.graph_utils.get_attrs(node, attrs)[source]

Returns multiple values from a dictionary in order.

Parameters:
Returns:

A tuple containing the value of every key in attrs in the same order, where missing values are None.

Return type:

tuple

vermouth.graph_utils.make_residue_graph(graph, attrs=('chain', 'resid', 'resname', 'insertion_code'))[source]

Create a new graph based on graph, where nodes with identical attribute values for the attribute names in attrs will be contracted into a single, coarser node. With the default arguments it will create a graph with one node per residue. Resulting (coarse) nodes will have the same attributes as the constructing nodes, but only those that have identical values. In addition, they’ll have attributes ‘graph’, ‘nnodes’, ‘nedges’ and ‘density’.

Parameters:
Returns:

The resulting coarser graph, where equivalent nodes are contracted to a single node.

Return type:

networkx.Graph

vermouth.graph_utils.partition_graph(graph, partitions)[source]

Create a new graph based on graph, where nodes are aggregated based on partitions, similar to quotient_graph(), except that it only accepts pre-made partitions, and edges are not given a ‘weight’ attribute. Much fast than the quotient_graph, since it creates edges based on existing edges rather than trying all possible combinations.

Parameters:
Returns:

The coarser graph.

Return type:

networkx.Graph

vermouth.graph_utils.rate_match(residue, bead, match)[source]

A helper function which rates how well match describes the isomorphism between residue and bead based on the number of matching atomnames.

Parameters:
  • residue (networkx.Graph) –

    A graph. Required node attributes:

    atomname:The name of an atom.
  • bead (networkx.Graph) –

    A subgraph of residue where the isomorphism is described by match. Required node attributes:

    atomname:The name of an atom.
Returns:

The number of entries in match where the atomname in residue matches the atomname in bead.

Return type:

int