Skip to main content

Tool for extracting dependency graphs from gotran ODE models

Project description

codecov CI github pages pre-commit.ci status

modelgraph

A tool for visualizing dependencies between different components of your model.

Motivation

Assume you have some model, represented as a system of ODEs with potentially several intermediate expressions. For example in the classical Hodgkin Huxley model of the squid axon from 1952 we have the following expressions

dV_dt = -(-i_Stim + i_Na + i_K + i_L)/Cm
i_Na = g_Na*m**3*h*(V - E_Na)

From this we can deduce that i_Na depends on the parameter g_Na, and since dV_dt depends on i_Na it also depends (indirectly) on the parameter g_Na.

In modelgraph we can visualize this dependency using the following code snippet

from modelgraph import DependencyGraph
import gotran

# Load ode using gotran
ode = gotran.load_ode("hodgkin_huxley_squid_axon_model_1952_original.ode")
# Build dependency graph
graph = DependencyGraph(ode)
# Get the components that depends on g_Na (we call this inverse dependents)
G = graph.inv_dependency_graph("g_Na")
# Visualize using matplotlib (python -m pip install matplotlib)
import matplotlib.pyplot as plt
nx.draw(G, with_labels=True, font_size=10, node_size=2000)
plt.savefig("g_Na_mpl.png")

_

# Or using pydot (python -m pip install pydot)
P = nx.nx_pydot.to_pydot(G)
P.write_png("g_Na_pydot.png")

_

It is also possible to go the other way around, i.e if you want to look at e.g dV_dt and see what it depends on

# Visualize what dV_dt depdens on
G_dV_dt = graph.dependency_graph("dV_dt")

nx.draw(G_dV_dt, with_labels=True, font_size=10, node_size=2000)
plt.savefig("dV_dt_mpl.png")

P_dV_dt = nx.nx_pydot.to_pydot(G_dV_dt)
P_dV_dt.write_png("dV_dt_pydot.png")

Here we only display the graph using pydot since the matplotlib version seems to be a bit messy if the graph becomes too large

_

Installation

Install with pip

python3 -m pip install modelgraph

GUI

There is also a graphical user interface. To use this you need to install streamlit

python -m pip install streamlit

You can run the the gui by passing in the .ode file as a command line argument e.g

python -m modelgraph demo/hodgkin_huxley_squid_axon_model_1952_original.ode

This will start a streamlit server, and the GUI is now hosted on http://localhost:8501

_

Documentation

Documentation is hosted at http://computationalphysiology.github.io/modelgraph.

Automated test

Tests are provided in the folder tests. You can run the tests with pytest

python3 -m pytest tests -vv

Contributing

See the contributing section

Authors

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modelgraph-1.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modelgraph-1.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file modelgraph-1.1.0.tar.gz.

File metadata

  • Download URL: modelgraph-1.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modelgraph-1.1.0.tar.gz
Algorithm Hash digest
SHA256 830485bff1db413b975204afcf7a995e5d1da727c41027555232b839244a63a8
MD5 d34f637b2c4e5b474201702f9b75c74b
BLAKE2b-256 7ad58c096d154884fe25d93399646f10239adb7148f5f34fd65802920ff19ece

See more details on using hashes here.

Provenance

The following attestation bundles were made for modelgraph-1.1.0.tar.gz:

Publisher: pypi.yml on ComputationalPhysiology/modelgraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modelgraph-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: modelgraph-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modelgraph-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c43d3b68a245195b3c48e0041d7d853e89d3b737ae765d02a1e39b4ca83be5b
MD5 cde62e19e4ae72d2be555fa1d29847d6
BLAKE2b-256 afe902098e524a7e636548a5f3850c86153706d00e52b5765b1f7eddec742b2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for modelgraph-1.1.0-py3-none-any.whl:

Publisher: pypi.yml on ComputationalPhysiology/modelgraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page