3.8. kda.graph_utils

3.8.1. Graph Utilities

This file contains a host of utility functions for NetworkX graphs.

generate_edges(G, vals, names=None, val_key='val', name_key='name')[source]

Generate edges for an input kinetic diagram G, where edges have attributes "name" (for rate constant variable names, e.g. "k12") and "val" (for the rate constant values, e.g. 100).

Parameters:
  • G (NetworkX.MultiDiGraph) – A kinetic diagram

  • vals (ndarray) – NxN array where N is the number of nodes in G. Contains the kinetic rate values for each transition in G. For example, assuming we have some values k12_val and k21_val, for a 2-state diagram vals = [[0, k12_val], [k21_val, 0]].

  • names (ndarray, optional) – NxN array where N is the number of nodes in G. Contains the kinetic rate variable names (as strings) for each transition in G. For example, for a 2-state diagram names = [[0, "k12"], ["k21", 0]].

  • val_key (str, optional) – Attribute key used to retrieve kinetic rate values from the edge data stored in G.edges. The default is "val".

  • name_key (str, optional) – Attribute key used to retrieve kinetic rate variable names from the edge data stored in G.edges. The default is "name".

find_all_unique_cycles(G)[source]

Finds all unique cycles in a kinetic diagram.

Parameters:

G (NetworkX.MultiDiGraph) – A kinetic diagram

Returns:

unique_cycles – List of cycles, where each cycle is a list of nodes in that cycle.

Return type:

list of lists of int

generate_K_string_matrix(N_states)[source]

Creates the string variant of the K-matrix based on the number of states in a diagram.

Parameters:

N_states (int) – The number of states in a diagram used to create a NxN matrix of strings.

Returns:

K_string – An NxN array of strings where N is the number of states in a diagram and the diagonal values of the array are zeros.

Return type:

ndarray

retrieve_rate_matrix(G, key='val')[source]

Retrieves rate matrix from a kinetic diagram.

Parameters:
  • G (NetworkX.MultiDiGraph) – A kinetic diagram

  • key (str, optional) – Attribute key used to retrieve edge data from G.edges. The default NetworkX edge key is "weight", however the kda edge keys are "name" (for rate constant names, e.g. "k12") and "val" (for the rate constant values, e.g. 100). Default is "val".

Returns:

rate_matrixNxN array where N is the number of nodes/states in the diagram G. Contains the values/rates for each edge.

Return type:

ndarray

get_ccw_cycle(cycle, order)[source]

Function used for obtaining the CCW version of an input cycle, primarily used for calculate_pi_difference() and calculate_thermo_force().

Parameters:
  • cycle (list of int) – List of node indices for cycle of interest, index zero. Order of node indices does not matter.

  • order (list of int) – List of integers of length 2 (e.g. [0, 1]), where the integers are nodes in cycle. The pair of nodes should be ordered such that a counter-clockwise path is followed.

Functions

find_all_unique_cycles(G)

Finds all unique cycles in a kinetic diagram.

generate_K_string_matrix(N_states)

Creates the string variant of the K-matrix based on the number of states in a diagram.

generate_edges(G, vals[, names, val_key, ...])

Generate edges for an input kinetic diagram G, where edges have attributes "name" (for rate constant variable names, e.g. "k12") and "val" (for the rate constant values, e.g. 100).

get_ccw_cycle(cycle, order)

Function used for obtaining the CCW version of an input cycle, primarily used for calculate_pi_difference() and calculate_thermo_force().

retrieve_rate_matrix(G[, key])

Retrieves rate matrix from a kinetic diagram.