cgsmiles.graph_utils module¶
Molecule utilites
- cgsmiles.graph_utils.annotate_fragments(meta_graph, molecule)[source]¶
Given a low resolution graph and a high resolution graph figure out which fragments belong to the nodes on the low resolution graph. Note that the nodes in the high resolution graph need to be annotated with ‘fragid’ that needs to match the lower resolution graph nodes.
- cgsmiles.graph_utils.merge_graphs(source_graph, target_graph, fragid=None, max_node=None)[source]¶
Merge the target_graph into source_graph. Atom and residue index of the newly added nodes are offset to follow the last node of source_graph, unless the fragid and/or max_node are explicitly provided.
- Parameters:
source_graph (networkx.Graph) – the graph into which to merge
target_graph (networkx.Graph) – the graph to be merged into source graph
fragid (int) – the fragid to be used on all newly added nodes
max_node (int) – the maxmimum node from which to start adding the new nodes
- Returns:
A dict mapping the node indices of the added molecule to their new indices in this molecule.
- Return type:
- cgsmiles.graph_utils.set_atom_names_atomistic(molecule, meta_graph=None)[source]¶
Set atomnames according to commonly used convention in molecular dynamics (MD) forcefields. This convention is defined as element plus counter for atom in residue.
- Parameters:
molecule (networkx.Graph) – the molecule for which to adjust the atomnames
meta_graph (networkx.Graph) – optional; get the fragments from the meta_graph attributes which is faster in some cases
- cgsmiles.graph_utils.sort_nodes_by_attr(graph, sort_attr='fragid', relative_attr=[('ez_isomer_atoms', True)])[source]¶
Sort nodes in graph by attribute and relable the graph in place.
- Parameters:
graph (networkx.Graph) – the graph to sort nodes of
sort_attr (collections.abc.Hashable) – the attribute to use for sorting
relative_attr (tuple(str, bool)) – a list of attributes that are sensetive to the ordering of nodes (i.e. refer to other nodes). The second element indicates the depth. If False the value of attr are node keys. If True we expect the value to be an itertable with node keys.
- Returns:
graph with nodes sorted in correct order
- Return type: