schrodinger.application.matsci.graph module

Module containing methods applied on networkx graph

Copyright Schrodinger, LLC. All rights reserved.

exception schrodinger.application.matsci.graph.NetworkLoopError

Bases: Exception

Raised when the whole network is infinite

__init__(*args, **kwargs)
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

schrodinger.application.matsci.graph.get_sub_graphs(graph)

Generator of the disconnect graphs in the passed graph.

Parameters

graph ('networkx.classes.graph.Graph') – The graph to find subgraphs in

Return type

‘networkx.classes.graph.Graph’

Returns

subgraph of the graph

schrodinger.application.matsci.graph.get_fused_cycles(graph)

Return cycles (fused and non-fused) in the graph

Parameters

graph ('networkx.classes.graph.Graph') – The graph to find cycles in

Return type

list(set)

Returns

list of sets of nodes that make each cycle

schrodinger.application.matsci.graph.get_sorted_shortest_path(graph, end_nodes, max_fix=False)

Get the shortest path with lowest indexes. Networkx does not handle degeneracy due to cycles properly, so using all_shortest_paths to compare each path

Parameters
  • graph ('networkx.classes.graph.Graph') – The graph to calculate the shortest path in

  • end_nodes (list) – The start and end nodes

  • max_fix (bool) – Whether to fix internal degeneracy when maximum number of path checks are reached

Returns

The sorted shortest path.

Return type

list of node index for shortest ordered path between the end nodes

schrodinger.application.matsci.graph.break_infinite_segment(graph, end_nodes)

Break a infinite loop segment to make it finite

Parameters
  • graph ('networkx.classes.graph.Graph') – The graph to make finite

  • end_nodes (list) – The start and end nodes

Raises

NetworkLoopError – If the segment cannot be made finite

schrodinger.application.matsci.graph.find_backbone(graph, prefer_indexes=None, max_fix=True)

Find the shortest path between atoms that are furthest apart

Parameters
  • graph ('networkx.classes.graph.Graph') – The graph to find longest path in

  • prefer_indexes (set) – A list of preferred atom indexes to choose for the head and tail of the backbone. For paths of equal lengths, the chosen path will start and end with atoms in the prefer_indexes set if one is available. Can be used, for instance, to prefer backbones that start and end with hydrogen atoms.

  • max_fix (bool) – Whether to fix internal degeneracy when maximum number of path checks are reached

Return type

list

Returns

list of nodes in the longest path in the graph. Between the two end node, the node with lower index is considered as the first element of the list and the other as the last. In case of degeneracy due to cycles nodes in the path, the shortest path containing lowest indexes is selected.

schrodinger.application.matsci.graph.find_segments(graph)

Find the segments in the input graph. Segments are path containing nodes where no node appears in a segment twice. Longest segments are always created first and then recursively smaller ones.

Parameters

graph ('networkx.classes.graph.Graph') – The graph to find segments in

Return type

list(list)

Returns

list of list of nodes. Each sublist is a list of ordered nodes, starting from lower index of the two end nodes, forming the longest path graph not containing the nodes already considered.