vermouth.graph_utils module¶
-
class
vermouth.graph_utils.
MappingGraphMatcher
(*args, edge_match=None, node_match=None, **kwargs)[source]¶ Bases:
networkx.algorithms.isomorphism.isomorphvf2.GraphMatcher
-
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.
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: - graph (
-
vermouth.graph_utils.
get_attrs
(node, attrs)[source]¶ Returns multiple values from a dictionary in order.
Parameters: - node (dict) – The dict from which items should be taken.
- attrs (collections.abc.Iterable) – The keys which values should be taken.
Returns: A tuple containing the value of every key in attrs in the same order, where missing values are None.
Return type:
-
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: - graph (networkx.Graph) – The graph to condense.
- attrs (collections.abc.Iterable[collections.abc.Hashable]) – The node attributes that determine node equivalence.
Returns: The resulting coarser graph, where equivalent nodes are contracted to a single node.
Return type:
-
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: - graph (networkx.Graph) – The graph to partition
- partitions (collections.abc.Iterable[collections.abc.Iterable[collections.abc.Hashable]]) – E.g. a list of lists of node indices, describing the partitions. Will be sorted by lowest index.
Returns: The coarser graph.
Return type:
-
vermouth.graph_utils.
rate_match
(residue, bead, match)[source]¶ A helper function which rates how well
match
describes the isomorphism betweenresidue
andbead
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 bymatch
. Required node attributes:atomname: The name of an atom.
Returns: The number of entries in match where the atomname in
residue
matches the atomname inbead
.Return type: - residue (networkx.Graph) –