Skip to content

Commit 21b4f28

Browse files
authored
Merge pull request #251 from isaacsas/graph-tweak
Switch Catlab to imports
2 parents 6f888bc + f13bf1e commit 21b4f28

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/Catalyst.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ include("latexify_recipes.jl")
2727

2828
# for making and saving graphs
2929
import Base.Iterators: flatten
30-
using Catlab.Graphics.Graphviz
31-
import Catlab.Graphics.Graphviz: Graph, Edge
30+
import Catlab.Graphics.Graphviz: Graph, Edge, Attributes, Node, Digraph, run_graphviz
3231
include("graphs.jl")
3332
export Graph, savegraph
3433

src/graphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function Graph(rn::ReactionSystem)
6363
(!isempty(es)) && push!(edges, es)
6464

6565
stmts = vcat(stmts, collect(flatten(edges)))
66-
g = Graphviz.Digraph("G", stmts; graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)
66+
g = Digraph("G", stmts; graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)
6767
return g
6868
end
6969

src/latexify_recipes.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,16 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
4545
eol = double_linebreak ? "\\\\\\\\\n" : "\\\\\n"
4646

4747
mathjax && (str *= "\\require{mhchem}\n")
48-
49-
5048
backwards_reaction = false
5149
rxs = ModelingToolkit.equations(rn)
50+
@variables t
51+
52+
# this should replace A(t) with A in equations however, currently substituter rewrites
53+
# things like x/y as inv(y)*x^1 which looks worse... for now we leave a stub that can
54+
# be updated when substitution preserves expressions better.
55+
# subber = ModelingToolkit.substituter([s(t) => s() for s in states(rn)])
56+
subber = x -> x
57+
5258
for (i, r) in enumerate(rxs)
5359
if backwards_reaction
5460
backwards_reaction = false
@@ -57,7 +63,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
5763
str *= "\\ce{ "
5864

5965
### Expand functions to maths expressions
60-
rate = r.rate isa Operation ? Expr(r.rate) : r.rate
66+
rate = r.rate isa Operation ? Expr(subber(r.rate)) : r.rate
6167
expand && (rate = recursive_clean!(rate))
6268
expand && (rate = recursive_clean!(rate))
6369

@@ -72,7 +78,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
7278
poststr = mathjax ? "]" : "\$]"
7379
if i + 1 <= length(rxs) && issetequal(r.products,rxs[i+1].substrates) && issetequal(r.substrates,rxs[i+1].products)
7480
### Bi-directional arrows
75-
rate_backwards = Expr(rxs[i+1].rate)
81+
rate_backwards = rxs[i+1].rate isa Operation ? Expr(subber(rxs[i+1].rate)) : rxs[i+1].rate
7682
expand && (rate_backwards = recursive_clean!(rate_backwards))
7783
expand && (rate_backwards = recursive_clean!(rate_backwards))
7884
str *= " &<=>"

0 commit comments

Comments
 (0)