diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 68422604c..bc094bbc7 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -31,6 +31,9 @@ cdef extern from "cantera/base/xml.h" namespace "Cantera": XML_Node* findID(string) int nChildren() +cdef extern from "cantera/base/stringUtils.h" namespace "Cantera": + cdef Composition parseCompString(string) except + + cdef extern from "cantera/base/global.h" namespace "Cantera": cdef void CxxAddDirectory "Cantera::addDirectory" (string) cdef size_t CxxNpos "Cantera::npos" diff --git a/interfaces/cython/cantera/test/test_kinetics.py b/interfaces/cython/cantera/test/test_kinetics.py index f1ed19c2a..4525c93e1 100644 --- a/interfaces/cython/cantera/test/test_kinetics.py +++ b/interfaces/cython/cantera/test/test_kinetics.py @@ -677,8 +677,8 @@ class TestReaction(utilities.CanteraTest): def test_falloff(self): r = ct.FalloffReaction() - r.reactants = {'OH':2} - r.products = {'H2O2':1} + r.reactants = 'OH:2' + r.products = 'H2O2:1' r.high_rate = ct.Arrhenius(7.4e10, -0.37, 0.0) r.low_rate = ct.Arrhenius(2.3e12, -0.9, -1700*1000*4.184) r.falloff = ct.TroeFalloff((0.7346, 94, 1756, 5182)) @@ -724,8 +724,8 @@ class TestReaction(utilities.CanteraTest): species = ct.Species.listFromFile('pdep-test.cti') r = ct.ChebyshevReaction() - r.reactants = {'R5': 1, 'H': 1} - r.products = {'P5A': 1, 'P5B': 1} + r.reactants = 'R5:1, H:1' + r.products = 'P5A:1, P5B:1' r.set_parameters(Tmin=300.0, Tmax=2000.0, Pmin=1000, Pmax=10000000, coeffs=[[ 5.28830e+00, -1.13970e+00, -1.20590e-01, 1.60340e-02], [ 1.97640e+00, 1.00370e+00, 7.28650e-03, -3.04320e-02], diff --git a/interfaces/cython/cantera/utils.pyx b/interfaces/cython/cantera/utils.pyx index 5b8d4ea8f..c01e778d4 100644 --- a/interfaces/cython/cantera/utils.pyx +++ b/interfaces/cython/cantera/utils.pyx @@ -35,7 +35,11 @@ def appdelete(): """ Delete all global Cantera C++ objects """ CxxAppdelete() -cdef Composition comp_map(dict X) except *: +cdef Composition comp_map(X) except *: + if isinstance(X, (str, unicode, bytes)): + return parseCompString(stringify(X)) + + # assume X is dict-like cdef Composition m for species,value in X.items(): m[stringify(species)] = value