Skip to content

Commit 8e7cfd2

Browse files
authored
Merge pull request #5 from ReactionMechanismGenerator/pyrms
Pyrms and improved flux diagrams
2 parents 2022d92 + b8644d7 commit 8e7cfd2

6 files changed

Lines changed: 59 additions & 25 deletions

File tree

Manifest.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ git-tree-sha1 = "70885e5e038cba1c4c17a84ad6c40756e10a4fb5"
9191
uuid = "19ecbf4d-ef7c-5e4b-b54a-0a0ff23c5aed"
9292
version = "0.5.0"
9393

94+
[[Colors]]
95+
deps = ["ColorTypes","FixedPointNumbers","InteractiveUtils","Printf","Reexport"]
96+
name = "Colors"
97+
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
98+
version = "0.9.4"
99+
94100
[[ColorTypes]]
95101
deps = ["FixedPointNumbers", "Random", "Test"]
96102
git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09"

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "0.1.0"
66
[deps]
77
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
88
Clp = "e2554f3b-3117-50c0-817c-e040a3ddf72d"
9+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
910
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
1011
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
1112
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ SpecialFunctions
1313
Images
1414
PyPlot
1515
Dierckx
16+
Colors

src/Domain.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ export AbstractVariableKDomain
3232
jacuptodate::MArray{Tuple{1},Bool,1,1}=MVector(false)
3333
t::MArray{Tuple{1},W2,1,1}=MVector(0.0)
3434
end
35-
function ConstantTPDomain(;phase::E2,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{String,E},constantspecies::Array{String,1}=Array{String,1}(),
36-
sparse::Bool=false,sensitivity::Bool=false) where {E<:Real,E2<:AbstractPhase,Q<:AbstractInterface,W<:Real}
37-
35+
function ConstantTPDomain(;phase::E2,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{X,X2},constantspecies::Array{X3,1}=Array{String,1}(),
36+
sparse::Bool=false,sensitivity::Bool=false) where {E<:Real,E2<:AbstractPhase,Q<:AbstractInterface,W<:Real,X,X2,X3}
3837
#set conditions and initialconditions
3938
T = 0.0
4039
P = 0.0
@@ -106,8 +105,8 @@ export ConstantTPDomain
106105
jacuptodate::MArray{Tuple{1},Bool,1,1}=MVector(false)
107106
t::MArray{Tuple{1},W2,1,1}=MVector(0.0)
108107
end
109-
function ConstantVDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{String,E},constantspecies::Array{String,1}=Array{String,1}(),
110-
sparse::Bool=false,sensitivity::Bool=false) where {E<:Real,Z<:IdealGas,Q<:AbstractInterface}
108+
function ConstantVDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{X,E},constantspecies::Array{X2,1}=Array{String,1}(),
109+
sparse::Bool=false,sensitivity::Bool=false) where {E,X,X2,Z<:IdealGas,Q<:AbstractInterface}
111110

112111
#set conditions and initialconditions
113112
T = 0.0
@@ -174,8 +173,8 @@ export ConstantVDomain
174173
jacuptodate::MArray{Tuple{1},Bool,1,1}=MVector(false)
175174
t::MArray{Tuple{1},W2,1,1}=MVector(0.0)
176175
end
177-
function ParametrizedTPDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{String,Any},constantspecies::Array{String,1}=Array{String,1}(),
178-
sparse::Bool=false,sensitivity::Bool=false) where {Z<:IdealGas,Q<:AbstractInterface}
176+
function ParametrizedTPDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{X,Any},constantspecies::Array{X2,1}=Array{String,1}(),
177+
sparse::Bool=false,sensitivity::Bool=false) where {X,X2,Z<:IdealGas,Q<:AbstractInterface}
179178

180179
#set conditions and initialconditions
181180
T = 0.0
@@ -257,8 +256,8 @@ export ParametrizedTPDomain
257256
jacuptodate::MArray{Tuple{1},Bool,1,1}=MVector(false)
258257
t::MArray{Tuple{1},W2,1,1}=MVector(0.0)
259258
end
260-
function ParametrizedVDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{String,Any},constantspecies::Array{String,1}=Array{String,1}(),
261-
sparse::Bool=false,sensitivity::Bool=false) where {E<:Real,Z<:IdealGas,Q<:AbstractInterface}
259+
function ParametrizedVDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{X,Any},constantspecies::Array{X2,1}=Array{String,1}(),
260+
sparse::Bool=false,sensitivity::Bool=false) where {X,X2,E<:Real,Z<:IdealGas,Q<:AbstractInterface}
262261

263262
#set conditions and initialconditions
264263
T = 0.0
@@ -340,8 +339,8 @@ export ParametrizedVDomain
340339
jacuptodate::MArray{Tuple{1},Bool,1,1}=MVector(false)
341340
t::MArray{Tuple{1},W2,1,1}=MVector(0.0)
342341
end
343-
function ConstantTVDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{String,E},constantspecies::Array{String,1}=Array{String,1}(),
344-
sparse=false,sensitivity=false) where {E<:Real, Z<:AbstractPhase,Q<:AbstractInterface,W<:Real}
342+
function ConstantTVDomain(;phase::Z,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{X,E},constantspecies::Array{X2,1}=Array{String,1}(),
343+
sparse=false,sensitivity=false) where {E,X,X2, Z<:AbstractPhase,Q<:AbstractInterface,W<:Real}
345344
#set conditions and initialconditions
346345
T = 0.0
347346
V = 0.0
@@ -415,8 +414,8 @@ export ConstantTVDomain
415414
jacuptodate::MArray{Tuple{1},Bool,1,1}=MVector(false)
416415
t::MArray{Tuple{1},W2,1,1}=MVector(0.0)
417416
end
418-
function ParametrizedTConstantVDomain(;phase::IdealDiluteSolution,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{String,Any},constantspecies::Array{String,1}=Array{String,1}(),
419-
sparse::Bool=false,sensitivity::Bool=false) where {Q<:AbstractInterface}
417+
function ParametrizedTConstantVDomain(;phase::IdealDiluteSolution,interfaces::Array{Q,1}=Array{EmptyInterface,1}(),initialconds::Dict{X,X3},constantspecies::Array{X2,1}=Array{String,1}(),
418+
sparse::Bool=false,sensitivity::Bool=false) where {X,X2,X3,Q<:AbstractInterface}
420419
#set conditions and initialconditions
421420
T = 0.0
422421
P = 0.0

src/ReactionMechanismSimulator.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ module ReactionMechanismSimulator
1919
copy!(Chem,pyimport_conda("rdkit.Chem","rdkit","rmg"))
2020
copy!(molecule,pyimport_conda("rmgpy.molecule","rmgpy","rmg"))
2121
copy!(pydot,pyimport_conda("pydot","pydot","rmg"))
22-
copy!(chemkin,pyimport_conda("rmgpy.chemkin","rmgpy","rmg"))
23-
copy!(species,pyimport_conda("rmgpy.species","rmgpy","rmg"))
24-
copy!(reaction,pyimport_conda("rmgpy.reaction","rmgpy","rmg"))
25-
copy!(nasa,pyimport_conda("rmgpy.thermo.nasa","rmgpy","rmg"))
26-
copy!(wilhoit,pyimport_conda("rmgpy.thermo.wilhoit","rmgpy","rmg"))
27-
copy!(arrhenius,pyimport_conda("rmgpy.kinetics.arrhenius","rmgpy","rmg"))
28-
copy!(falloff,pyimport_conda("rmgpy.kinetics.falloff","rmgpy","rmg"))
29-
copy!(chebyshev,pyimport_conda("rmgpy.kinetics.chebyshev","rmgpy","rmg"))
30-
copy!(solvation,pyimport_conda("rmgpy.data.solvation","rmgpy","rmg"))
22+
copy!(chemkin,pyimport_conda("rmgpy.chemkin","rmg","rmg"))
23+
copy!(species,pyimport_conda("rmgpy.species","rmg","rmg"))
24+
copy!(reaction,pyimport_conda("rmgpy.reaction","rmg","rmg"))
25+
copy!(nasa,pyimport_conda("rmgpy.thermo.nasa","rmg","rmg"))
26+
copy!(wilhoit,pyimport_conda("rmgpy.thermo.wilhoit","rmg","rmg"))
27+
copy!(arrhenius,pyimport_conda("rmgpy.kinetics.arrhenius","rmg","rmg"))
28+
copy!(falloff,pyimport_conda("rmgpy.kinetics.falloff","rmg","rmg"))
29+
copy!(chebyshev,pyimport_conda("rmgpy.kinetics.chebyshev","rmg","rmg"))
30+
copy!(solvation,pyimport_conda("rmgpy.data.solvation","rmg","rmg"))
3131
copy!(yaml,pyimport_conda("yaml","yaml"))
3232
copy!(os,pyimport_conda("os","os"))
3333
end

src/fluxdiagrams.jl

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using PyCall
22
using SparseArrays
33
using Images
4+
using Colors
45
import Base: length
56

67
struct FluxDiagram{T<:Real}
@@ -63,16 +64,18 @@ export drawspecies
6364

6465
"""
6566
generates and returns the image of a single flux diagram at the given time point
67+
all PyPlot colorscheme names are valid inputs for colorscheme
6668
"""
6769
function getfluxdiagram(bsol,t;centralspecieslist=Array{String,1}(),superimpose=false,
6870
maximumnodecount=50, maximumedgecount=50, concentrationtol=1e-6, speciesratetolerance=1e-6,
69-
maximumnodepenwidth=10.0,maximumedgepenwidth=10.0,radius=1,centralreactioncount=-1,outputdirectory="fluxdiagrams")
71+
maximumnodepenwidth=10.0,maximumedgepenwidth=10.0,radius=1,centralreactioncount=-1,outputdirectory="fluxdiagrams",
72+
colorscheme="viridis")
7073

7174
fd = makefluxdiagrams(bsol,[t]; centralspecieslist=centralspecieslist,superimpose=superimpose,
7275
maximumnodecount=maximumnodecount, maximumedgecount=maximumedgecount, concentrationtol=concentrationtol,
7376
speciesratetolerance=speciesratetolerance,maximumnodepenwidth=maximumnodepenwidth,
7477
maximumedgepenwidth=maximumedgepenwidth,radius=radius,centralreactioncount=centralreactioncount,
75-
outputdirectory=outputdirectory)
78+
outputdirectory=outputdirectory,colorscheme=colorscheme)
7679

7780
return getdiagram(fd,1)
7881
end
@@ -81,10 +84,12 @@ export getfluxdiagram
8184
"""
8285
generates a series of flux diagrams at the time points indicated
8386
each flux diagram will have the same nodes and edges as determined by the options
87+
all PyPlot colorscheme names are valid inputs for colorscheme
8488
"""
8589
function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpose=false,
8690
maximumnodecount=50, maximumedgecount=50, concentrationtol=1e-6, speciesratetolerance=1e-6,
87-
maximumnodepenwidth=10.0,maximumedgepenwidth=10.0,radius=1,centralreactioncount=-1,outputdirectory="fluxdiagrams")
91+
maximumnodepenwidth=10.0,maximumedgepenwidth=10.0,radius=1,centralreactioncount=-1,outputdirectory="fluxdiagrams",
92+
colorscheme="viridis")
8893

8994
specieslist = bsol.domain.phase.species
9095
speciesnamelist = getfield.(specieslist,:name)
@@ -262,6 +267,15 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
262267
end
263268

264269
slope = -maximumedgepenwidth / log10(speciesratetolerance)
270+
minspeciesrate = Inf
271+
for index in 1:length(edges)
272+
reactantindex,productindex = edges[index]
273+
sprate = abs(speciesrates[reactantindex,productindex,t])
274+
if sprate > speciesratetolerance && minspeciesrate > sprate
275+
minspeciesrate = sprate
276+
end
277+
end
278+
265279
for index in 1:length(edges)
266280
reactantindex,productindex = edges[index]
267281
if reactantindex in nodes && productindex in nodes
@@ -298,6 +312,7 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
298312
end
299313

300314
edge[:set_penwidth](penwidth)
315+
edge[:set_color](getcolor(speciesrates[reactantindex,productindex,t],maxspeciesrate,minspeciesrate,colorscheme))
301316

302317
end
303318
end
@@ -312,6 +327,7 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
312327
graph[:set_label](label)
313328
graph[:write_dot](joinpath(outputdirectory,"flux_diagram_$t.dot"))
314329
graph[:write_png](joinpath(outputdirectory,"flux_diagram_$t.png"))
330+
graph[:write_svg](joinpath(outputdirectory,"flux_diagram_$t.svg"))
315331
end
316332
return FluxDiagram(ts,outputdirectory)
317333
end
@@ -369,3 +385,14 @@ function addadjacentnodes!(targetnodeindex,nodes,edges,phase,maxreactionrates,ma
369385
end
370386
end
371387
end
388+
389+
function getcolor(speciesrate,maxspeciesrate,minspeciesrate,colorscheme="viridis")
390+
"""
391+
gives the color corresponding to the scaled log species rate
392+
for a given PyPlot color scheme
393+
"""
394+
scale = log(maxspeciesrate)-log(minspeciesrate)
395+
value = (log(abs(speciesrate))-log(minspeciesrate))/scale
396+
out = PyPlot.get_cmap(colorscheme)(value)[1:3]
397+
return "#"*hex(RGB(out...))
398+
end

0 commit comments

Comments
 (0)