Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make reaction path contents available as Python data structure #173

Open
speth opened this issue Apr 18, 2023 · 1 comment
Open

Make reaction path contents available as Python data structure #173

speth opened this issue Apr 18, 2023 · 1 comment
Labels
feature-request New feature request

Comments

@speth
Copy link
Member

speth commented Apr 18, 2023

Abstract

The Python ReactionPathDiagram class could be extended to provide a graph representation of the reaction paths using Python's native data types. This would allow users to perform operations on the reaction network using tools for working with graphs, such as NetworkX or graph-tool, enabling new opportunities for analysis and presentation of reaction networks.

This would provide a means of implementing #4 and #26 as part of the Python interface.

Motivation

Describe the need for the proposed change:

  • What problem is it trying to solve?
    • The existing ReactionPathDiagram class in Python is mostly limited to just providing a few output formatting options for graphviz.
  • Who is affected by the change?
    • Users who want to perform analysis of reaction pathways and generate custom visualizations
  • Why is this a good solution?
    • Provides flexibility for users to work with the graph library of their choice, and avoids re-inventing the wheel by implementing graph algorithms in Cantera

Possible Solutions

The reaction path diagram can be represented as a list of nodes (species) and a list of directed edges (fluxes). This could be converted to Python using the AnyMap class as an intermediary, with a structure such as:

rpath = {
    'species': {'H', 'OH', 'H2', 'HO2', 'H2O2', 'H2O'},
    'fluxes': [
        ('H', 'OH', 0.011545),
        ('OH', 'H', 23.8658),
        ('H', 'H2', 0.00376924),
        ('H2', 'H', 0.0268195),
        ('H', 'HO2', 12.469),
        ('HO2', 'H', 3.96906e-21),
        ...
    ]
}

This structure lends itself to easily being convertible to a NetworkX DiGraph object. For example:

import networkx as nx
DG = nx.DiGraph()
DG.add_nodes_from(rpath['species'])
DG.add_weighted_edges_from(rpath['fluxes'])
@speth speth added the feature-request New feature request label Apr 18, 2023
@rwest
Copy link
Member

rwest commented Apr 18, 2023

I like this idea. I've sometimes needed things like a cumulative flux analysis rather than instantaneous. I think this could maybe simplify implementation of such things.

I also sometimes like to reformat graphviz dot file output. Eg changing styles, or putting pictures of molecules in place of names. Not sure what is the best way to enable such customization (I used to run regular expressions over the Cantera-generated .dot file) but maybe now is the time to think about it.

Update: I came across this gist with some of my flux diagram stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature request
Projects
None yet
Development

No branches or pull requests

2 participants