Graphs - graph.py

This page documents MatSimPy functions that create and modify NetworkX graphs.

init_graph_from_atm

def init_graph_from_atm(atm)
Initializes an unconnected, undirected graph from a provided ASE atoms object.

Parameters:

  • atm (ASE atoms object): The input molecule.

Returns:

  • g (nx graph object): An unconnected graph made up of the atoms in our molecule, with attributes for the number and symbol of the element for each node.

c_subgraph_finder

Adapted from web resource. 1

def c_subgraph_finder(graf)
Takes a graph and returns every connected subgraph it has. Adapted from resource in footnote.

Parameters:

  • graf (nx graph object): The input graph.

Returns:

  • subgraphs (dict): A dictionary object, containing the connected subgraphs of graf, organized by size.

graph_visual

def graph_visual(graf, cdict, label_string = "Type", printout = False, font = [22, "black"])
Produces a labelled matplotlib visualization of a nx graph object.

Parameters:

  • graf (nx graph): An input graph, with labelled nodes.
  • cdict (ditc): A dict object containing int-colour combinations for each label type (i.e. {1 : “Red”, 2: “Blue”}).
  • label_string (str): A str object used to pick the visualized label type, default is “Type”.
  • printout (bool): A bool object that determines if the colour-coding is printed to the user, default is False.
  • font (list): A list that contains the font size (int) and the font colour (str) of the user’s choice, default is [22, “black”].

Returns:

  • None

gdegree

def gdegree(graf)
Obtains an array counting degrees of nodes present in a graph. Similar but distinct from the G.degree already present in the nx package.

Parameters:

  • graf (nx graph): Input graph.

Returns:

  • g_count (np array): An array indicating the number of nodes with i edges in graf, where i is the index of g_count.

state_stacker

def state_stacker(state_array, num_class, readout = True)
Produces arrays that contain information on uniqueness of state compositions for regions of interest with distinct class numbers present.

Parameters:

  • state_array (array): A numpy array that acts as a dataset of ROI data containing types/classifications.
  • num_class (int): The number of different classes in the data that we are being asked to sort.
  • readout (bool): Determines if the user is shown a readout of the stacked states.

Returns:

  • unique_states (array): The unique states present in the input data.
  • unique_counts (array): Counts for unique states.
  • unique_firsts (array): Indices for first instances of unique states.
  • unique_inverse (array): The mapping needed to recreate the input data.

Footnotes

  1. Adapted from link