Skip to content

Commit f2500f6

Browse files
authored
Merge pull request #6 from ReactionMechanismGenerator/updatepycall
use improved pycall syntax
2 parents fc9bcec + 24f6c92 commit f2500f6

3 files changed

Lines changed: 105 additions & 101 deletions

File tree

src/Parse.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,22 @@ function getatomdictfromrdkit(mol)
113113
retrives the number of each type of atom and the number of bonds of an rdkit molecule
114114
"""
115115
atmD = Dict{String,Int64}()
116-
for atm in mol[:GetAtoms]()
117-
v = elementdict[atm[:GetAtomicNum]()]
116+
for atm in mol.GetAtoms()
117+
v = elementdict[atm.GetAtomicNum()]
118118
if v in keys(atmD)
119119
atmD[v] += 1
120120
else
121121
atmD[v] = 1
122122
end
123123
end
124-
nbonds = length(mol[:GetBonds]())
124+
nbonds = length(mol.GetBonds())
125125
return atmD,nbonds
126126
end
127127
export getatomdictfromrdkit
128128

129-
getatomdictsmiles(smiles) = getatomdictfromrdkit(Chem[:AddHs](Chem[:MolFromSmiles](smiles)))
129+
getatomdictsmiles(smiles) = getatomdictfromrdkit(Chem.AddHs(Chem.MolFromSmiles(smiles)))
130130
export getatomdictsmiles
131-
getatomdictinchi(inchi) = getatomdictfromrdkit(Chem[:AddHs](Chem[:MolFromInchi](inchi)))
131+
getatomdictinchi(inchi) = getatomdictfromrdkit(Chem.AddHs(Chem.MolFromInchi(inchi)))
132132
export getatomdictinchi
133133

134134
function getspeciesradius(atomdict::Dict{String,Int64},nbonds::Int64)

src/fluxdiagrams.jl

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ function drawspc(spc::Species,path::String=".")
4242
end
4343
end
4444
if spc.inchi != ""
45-
mol = molecule[:Molecule]()[:fromInChI](spc.inchi)
45+
mol = molecule.Molecule().fromInChI(spc.inchi)
4646
elseif spc.smiles != ""
47-
mol = molecule[:Molecule]()[:fromSMILES](spc.smiles)
47+
mol = molecule.Molecule().fromSMILES(spc.smiles)
4848
else
4949
throw(error("no smiles or inchi for molecule $name"))
5050
end
51-
mol[:draw](joinpath(path,fname))
51+
mol.draw(joinpath(path,fname))
5252
end
5353
export drawspc
5454

@@ -203,16 +203,16 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
203203
end
204204
end
205205

206-
graph = pydot[:Dot]("flux_diagram",graph_type="digraph",overlap="false")
207-
graph[:set_rankdir]("LR")
208-
graph[:set_fontname]("sans")
209-
graph[:set_fontsize]("10")
206+
graph = pydot.Dot("flux_diagram",graph_type="digraph",overlap="false")
207+
graph.set_rankdir("LR")
208+
graph.set_fontname("sans")
209+
graph.set_fontsize("10")
210210

211211
for index in nodes
212212
species = specieslist[index]
213-
node = pydot[:Node](name=species.name)
214-
node[:set_penwidth](maximumnodepenwidth)
215-
graph[:add_node](node)
213+
node = pydot.Node(name=species.name)
214+
node.set_penwidth(maximumnodepenwidth)
215+
graph.add_node(node)
216216

217217
speciesindex = string(species.name,".png")
218218
imagepath = ""
@@ -228,22 +228,22 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
228228
end
229229
end
230230
if isfile(imagepath)
231-
node[:set_image](imagepath)
232-
node[:set_label](" ")
231+
node.set_image(imagepath)
232+
node.set_label(" ")
233233
end
234234
end
235235

236236
for (reactantindex,productindex) in edges
237237
if reactantindex in nodes && productindex in nodes
238238
reactant = specieslist[reactantindex]
239239
product = specieslist[productindex]
240-
edge = pydot[:Edge](reactant.name,product.name)
241-
edge[:set_penwidth](maximumedgepenwidth)
242-
graph[:add_edge](edge)
240+
edge = pydot.Edge(reactant.name,product.name)
241+
edge.set_penwidth(maximumedgepenwidth)
242+
graph.add_edge(edge)
243243
end
244244
end
245245

246-
graph = pydot[:graph_from_dot_data](graph[:create_dot](prog="dot"))[1]
246+
graph = pydot.graph_from_dot_data(graph.create_dot(prog="dot"))[1]
247247

248248
for t in 1:length(ts)
249249
slope = -maximumnodepenwidth / log10(concentrationtol)
@@ -255,15 +255,15 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
255255
species_string = string("\"",species.name,"\"")
256256
end
257257

258-
node = graph[:get_node](species_string)[1]
258+
node = graph.get_node(species_string)[1]
259259
concentration = concentrations[index,t] / maxconcentration
260260
if concentration < concentrationtol
261261
penwidth = 0.0
262262
else
263263
penwidth = round((slope*log10(concentration)+maximumnodepenwidth)*1.0e3)/1.0e3
264264
end
265265

266-
node[:set_penwidth](penwidth)
266+
node.set_penwidth(penwidth)
267267
end
268268

269269
slope = -maximumedgepenwidth / log10(speciesratetolerance)
@@ -294,25 +294,25 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
294294
product_string = string("\"",product.name,"\"")
295295
end
296296

297-
edge = graph[:get_edge](reactant_string,product_string)[1]
297+
edge = graph.get_edge(reactant_string,product_string)[1]
298298

299299
speciesrate = speciesrates[reactantindex,productindex,t] / maxspeciesrate
300300
if speciesrate < 0
301-
edge[:set_dir]("back")
301+
edge.set_dir("back")
302302
speciesrate = -speciesrate
303303
else
304-
edge[:set_dir]("forward")
304+
edge.set_dir("forward")
305305
end
306306

307307
if speciesrate < speciesratetolerance
308308
penwidth = 0.0
309-
edge[:set_dir]("none")
309+
edge.set_dir("none")
310310
else
311311
penwidth = round((slope*log10(speciesrate) + maximumedgepenwidth)*1.0e3)/1.0e3
312312
end
313313

314-
edge[:set_penwidth](penwidth)
315-
edge[:set_color](getcolor(speciesrates[reactantindex,productindex,t],maxspeciesrate,minspeciesrate,colorscheme))
314+
edge.set_penwidth(penwidth)
315+
edge.set_color(getcolor(speciesrates[reactantindex,productindex,t],maxspeciesrate,minspeciesrate,colorscheme))
316316

317317
end
318318
end
@@ -324,10 +324,10 @@ function makefluxdiagrams(bsol,ts;centralspecieslist=Array{String,1}(),superimpo
324324
label = "t = 10^$tval s"
325325
end
326326

327-
graph[:set_label](label)
328-
graph[:write_dot](joinpath(outputdirectory,"flux_diagram_$t.dot"))
329-
graph[:write_png](joinpath(outputdirectory,"flux_diagram_$t.png"))
330-
graph[:write_svg](joinpath(outputdirectory,"flux_diagram_$t.svg"))
327+
graph.set_label(label)
328+
graph.write_dot(joinpath(outputdirectory,"flux_diagram_$t.dot"))
329+
graph.write_png(joinpath(outputdirectory,"flux_diagram_$t.png"))
330+
graph.write_svg(joinpath(outputdirectory,"flux_diagram_$t.svg"))
331331
end
332332
return FluxDiagram(ts,outputdirectory)
333333
end

src/yml.jl

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
function convertchemkin2yml(chemkinpath;spcdictpath="",output="chem.rms")
22
if spcdictpath != ""
3-
spcs,rxns = chemkin[:loadChemkinFile](chemkinpath,dictionaryPath=spcdictpath)
3+
spcs,rxns = chemkin.loadChemkinFile(chemkinpath,dictionaryPath=spcdictpath)
44
else
5-
spcs,rxns = chemkin[:loadChemkinFile](chemkinpath)
5+
spcs,rxns = chemkin.loadChemkinFile(chemkinpath)
66
end
77
writeyml(spcs,rxns;path=output)
88
end
99

1010
function writeyml(spcs,rxns;path="chem.rms")
1111
D = getmechdict(spcs,rxns)
12-
yaml[:dump](D,stream=pybuiltin("file")(path,"w"))
12+
yaml.dump(D,stream=pybuiltin("file")(path,"w"))
1313
end
1414

1515
function getmechdict(spcs,rxns)
@@ -24,103 +24,107 @@ function getmechdict(spcs,rxns)
2424
end
2525

2626
function getradicals(obj::T) where {T}
27-
sm = obj[:molecule][1][:toSMILES]()
27+
sm = obj.molecule[1].toSMILES()
2828
if sm == "[O][O]"
2929
return 0
3030
else
31-
return obj[:molecule][1][:multiplicity]-1
31+
return obj.molecule[1].multiplicity-1
3232
end
3333
end
3434

3535
function obj2dict(obj,spcs;label="solvent")
3636
D = Dict([])
37-
if pybuiltin("isinstance")(obj,species[:Species])
38-
D["name"] = obj[:label]
37+
if pybuiltin("isinstance")(obj,species.Species)
38+
D["name"] = obj.label
3939
D["type"] = "Species"
40-
D["smiles"] = obj[:molecule][1][:toSMILES]()
41-
D["thermo"] = obj2dict(obj[:thermo],spcs)
40+
if length(obj.molecule) == 0
41+
println(obj)
42+
println(obj.label)
43+
end
44+
D["smiles"] = obj.molecule[1].toSMILES()
45+
D["thermo"] = obj2dict(obj.thermo,spcs)
4246
if D["smiles"] != "[O][O]"
43-
D["radicalelectrons"] = obj[:molecule][1][:multiplicity]-1
47+
D["radicalelectrons"] = obj.molecule[1].multiplicity-1
4448
else
4549
D["radicalelectrons"] = 0
4650
end
47-
elseif pybuiltin("isinstance")(obj,nasa[:NASA])
48-
D["polys"] = [obj2dict(k,spcs) for k in obj[:polynomials]]
51+
elseif pybuiltin("isinstance")(obj,nasa.NASA)
52+
D["polys"] = [obj2dict(k,spcs) for k in obj.polynomials]
4953
D["type"] = "NASA"
50-
elseif pybuiltin("isinstance")(obj,nasa[:NASAPolynomial])
54+
elseif pybuiltin("isinstance")(obj,nasa.NASAPolynomial)
5155
D["type"] = "NASApolynomial"
52-
D["coefs"] = PyVector(obj[:coeffs])
53-
D["Tmax"] = obj[:Tmax][:value_si]
54-
D["Tmin"] = obj[:Tmin][:value_si]
55-
elseif pybuiltin("isinstance")(obj,reaction[:Reaction])
56-
D["reactants"] = [x[:label] for x in obj[:reactants]]
57-
D["products"] = [x[:label] for x in obj[:products]]
58-
D["kinetics"] = obj2dict(obj[:kinetics],spcs)
56+
D["coefs"] = PyVector(obj.coeffs)
57+
D["Tmax"] = obj.Tmax.value_si
58+
D["Tmin"] = obj.Tmin.value_si
59+
elseif pybuiltin("isinstance")(obj,reaction.Reaction)
60+
D["reactants"] = [x.label for x in obj.reactants]
61+
D["products"] = [x.label for x in obj.products]
62+
D["kinetics"] = obj2dict(obj.kinetics,spcs)
5963
D["type"] = "ElementaryReaction"
60-
D["radicalchange"] = sum([getradicals(x) for x in obj[:products]])-sum([getradicals(x) for x in obj[:reactants]])
61-
elseif pybuiltin("isinstance")(obj,arrhenius[:Arrhenius])
64+
D["radicalchange"] = sum([getradicals(x) for x in obj.products])-sum([getradicals(x) for x in obj.reactants])
65+
elseif pybuiltin("isinstance")(obj,arrhenius.Arrhenius)
6266
D["type"] = "Arrhenius"
63-
D["A"] = obj[:A][:value_si]
64-
D["Ea"] = obj[:Ea][:value_si]
65-
D["n"] = obj[:n][:value_si]
66-
elseif pybuiltin("isinstance")(obj,arrhenius[:PDepArrhenius])
67+
D["A"] = obj.A.value_si
68+
D["Ea"] = obj.Ea.value_si
69+
D["n"] = obj.n.value_si
70+
elseif pybuiltin("isinstance")(obj,arrhenius.PDepArrhenius)
6771
D["type"] = "PdepArrhenius"
68-
D["Ps"] = PyVector(obj[:pressures][:value_si])
69-
D["arrs"] = [obj2dict(x,spcs) for x in obj[:arrhenius]]
70-
elseif pybuiltin("isinstance")(obj,arrhenius[:MultiArrhenius])
72+
D["Ps"] = PyVector(obj.pressures.value_si)
73+
D["arrs"] = [obj2dict(x,spcs) for x in obj.arrhenius]
74+
elseif pybuiltin("isinstance")(obj,arrhenius.MultiArrhenius)
7175
D["type"] = "MultiArrhenius"
72-
D["arrs"] = [obj2dict(x,spcs) for x in obj[:arrhenius]]
73-
elseif pybuiltin("isinstance")(obj,arrhenius[:MultiPDepArrhenius])
76+
D["arrs"] = [obj2dict(x,spcs) for x in obj.arrhenius]
77+
elseif pybuiltin("isinstance")(obj,arrhenius.MultiPDepArrhenius)
7478
D["type"] = "MultiPdepArrhenius"
75-
D["parrs"] = [obj2dict(x,spcs) for x in obj[:arrhenius]]
76-
elseif pybuiltin("isinstance")(obj,falloff[:ThirdBody])
79+
D["parrs"] = [obj2dict(x,spcs) for x in obj.arrhenius]
80+
elseif pybuiltin("isinstance")(obj,falloff.ThirdBody)
7781
D["type"] = "ThirdBody"
78-
D["arr"] = obj2dict(obj[:arrheniusLow],spcs)
79-
D["efficiencies"] = Dict([spcs[i][:label]=>float(val) for (i,val) in enumerate(obj[:getEffectiveColliderEfficiencies](spcs)) if val != 1])
80-
elseif pybuiltin("isinstance")(obj,falloff[:Lindemann])
82+
D["arr"] = obj2dict(obj.arrheniusLow,spcs)
83+
D["efficiencies"] = Dict([spcs[i].label=>float(val) for (i,val) in enumerate(obj.getEffectiveColliderEfficiencies(spcs)) if val != 1])
84+
elseif pybuiltin("isinstance")(obj,falloff.Lindemann)
8185
D["type"] = "Lindemann"
82-
D["arrhigh"] = obj2dict(obj[:arrheniusHigh],spcs)
83-
D["arrlow"] = obj2dict(obj[:arrheniusLow],spcs)
84-
D["efficiencies"] = Dict([spcs[i][:label]=>float(val) for (i,val) in enumerate(obj[:getEffectiveColliderEfficiencies](spcs)) if val != 1])
85-
elseif pybuiltin("isinstance")(obj,falloff[:Troe])
86+
D["arrhigh"] = obj2dict(obj.arrheniusHigh,spcs)
87+
D["arrlow"] = obj2dict(obj.arrheniusLow,spcs)
88+
D["efficiencies"] = Dict([spcs[i].label=>float(val) for (i,val) in enumerate(obj.getEffectiveColliderEfficiencies(spcs)) if val != 1])
89+
elseif pybuiltin("isinstance")(obj,falloff.Troe)
8690
D["type"] = "Troe"
87-
D["arrhigh"] = obj2dict(obj[:arrheniusHigh],spcs)
88-
D["arrlow"] = obj2dict(obj[:arrheniusLow],spcs)
89-
D["efficiencies"] = Dict([spcs[i][:label]=>float(val) for (i,val) in enumerate(obj[:getEffectiveColliderEfficiencies](spcs)) if val != 1])
90-
D["a"] = obj[:alpha]
91-
D["T1"] = obj[:T1][:value_si]
92-
if !isa(obj[:T2],Nothing)
93-
D["T2"] = obj[:T2][:value_si]
91+
D["arrhigh"] = obj2dict(obj.arrheniusHigh,spcs)
92+
D["arrlow"] = obj2dict(obj.arrheniusLow,spcs)
93+
D["efficiencies"] = Dict([spcs[i].label=>float(val) for (i,val) in enumerate(obj.getEffectiveColliderEfficiencies(spcs)) if val != 1])
94+
D["a"] = obj.alpha
95+
D["T1"] = obj.T1.value_si
96+
if !isa(obj.T2,Nothing)
97+
D["T2"] = obj.T2.value_si
9498
else
9599
D["T2"] = 0.0
96100
end
97-
D["T3"] = obj[:T3][:value_si]
98-
elseif pybuiltin("isinstance")(obj,chebyshev[:Chebyshev])
101+
D["T3"] = obj.T3.value_si
102+
elseif pybuiltin("isinstance")(obj,chebyshev.Chebyshev)
99103
D["type"] = "Chebyshev"
100-
n,m = size(obj[:coeffs][:value_si])
101-
D["coefs"] = PyVector([PyVector(obj[:coeffs][:value_si][i,:]) for i in 1:n])
102-
D["Tmin"] = obj[:Tmin][:value_si]
103-
D["Tmax"] = obj[:Tmax][:value_si]
104-
D["Pmin"] = obj[:Pmin][:value_si]
105-
D["Pmax"] = obj[:Pmax][:value_si]
106-
elseif pybuiltin("isinstance")(obj,wilhoit[:Wilhoit])
104+
n,m = size(obj.coeffs.value_si)
105+
D["coefs"] = PyVector([PyVector(obj.coeffs.value_si[i,:]) for i in 1:n])
106+
D["Tmin"] = obj.Tmin.value_si
107+
D["Tmax"] = obj.Tmax.value_si
108+
D["Pmin"] = obj.Pmin.value_si
109+
D["Pmax"] = obj.Pmax.value_si
110+
elseif pybuiltin("isinstance")(obj,wilhoit.Wilhoit)
107111
D["type"] = "Wilhoit"
108-
D["coefs"] = [obj[:a0],obj[:a1],obj[:a2],obj[:a3]]
109-
D["Cp0"] = obj[:Cp0][:value_si]
110-
D["Cpinf"] = obj[:CpInf][:value_si]
111-
D["H0"] = obj[:H0][:value_si]
112-
D["S0"] = obj[:S0][:value_si]
113-
D["B"] = obj[:B][:value_si]
114-
elseif pybuiltin("isinstance")(obj,solvation[:SolventData])
112+
D["coefs"] = [obj.a0,obj.a1,obj.a2,obj.a3]
113+
D["Cp0"] = obj.Cp0.value_si
114+
D["Cpinf"] = obj.CpInf.value_si
115+
D["H0"] = obj.H0.value_si
116+
D["S0"] = obj.S0.value_si
117+
D["B"] = obj.B.value_si
118+
elseif pybuiltin("isinstance")(obj,solvation.SolventData)
115119
D["type"] = "Solvent"
116120
D["name"] = label
117121
dsub = dict()
118122
dsub["type"] = "RiedelViscosity"
119-
dsub["A"] = obj[:A][:value_si]
120-
dsub["B"] = obj[:B][:value_si]
121-
dsub["C"] = obj[:C][:value_si]
122-
dsub["D"] = obj[:D][:value_si]
123-
dsub["E"] = obj[:E][:value_si]
123+
dsub["A"] = obj.A.value_si
124+
dsub["B"] = obj.B.value_si
125+
dsub["C"] = obj.C.value_si
126+
dsub["D"] = obj.D.value_si
127+
dsub["E"] = obj.E.value_si
124128
D["mu"] = dsub
125129
elseif pybuiltin("is")(obj,pybuiltin("None"))
126130
return pybuiltin("None")

0 commit comments

Comments
 (0)