From 558e48ea06268442a01e9106ef3074f7f45af5cd Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Sat, 25 Jan 2025 16:56:45 -0500 Subject: [PATCH] cantera 3 updates --- environment.yml | 5 ++--- rmgpy/reaction.py | 16 +++++++-------- rmgpy/tools/canteramodel.py | 23 +++++++++------------ test/rmgpy/reactionTest.py | 4 ++-- test/rmgpy/speciesTest.py | 36 ++++++++++++++++----------------- test/rmgpy/transportDataTest.py | 24 +++++++++++++--------- 6 files changed, 53 insertions(+), 55 deletions(-) diff --git a/environment.yml b/environment.yml index a5e272232d..6dcd5db2a4 100644 --- a/environment.yml +++ b/environment.yml @@ -25,7 +25,6 @@ name: rmg_env channels: - conda-forge - - cantera - rmg dependencies: # System-level dependencies - we could install these at the OS level @@ -46,7 +45,7 @@ dependencies: # external software tools for chemistry - conda-forge::coolprop - - cantera::cantera =2.6 + - conda-forge::cantera >= 3 - conda-forge::mopac # see https://github.com/ReactionMechanismGenerator/RMG-Py/pull/2639#issuecomment-2050292972 - conda-forge::cclib >=1.6.3,<1.9 @@ -59,7 +58,7 @@ dependencies: - conda-forge::cython >=0.25.2 - conda-forge::scikit-learn - conda-forge::scipy >=1.9 - - conda-forge::numpy >=1.10.0 + - conda-forge::numpy >=1.10.0,<2 - conda-forge::pydot - conda-forge::jinja2 - conda-forge::jupyter diff --git a/rmgpy/reaction.py b/rmgpy/reaction.py index 1997824afc..507a8b098b 100644 --- a/rmgpy/reaction.py +++ b/rmgpy/reaction.py @@ -348,20 +348,20 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False): elif isinstance(self.kinetics, ThirdBody): if ct_collider is not None: - ct_reaction = ct.ThreeBodyReaction(reactants=ct_reactants, products=ct_products, third_body=ct_collider) + ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products, third_body=ct_collider) else: - ct_reaction = ct.ThreeBodyReaction(reactants=ct_reactants, products=ct_products) + ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products) elif isinstance(self.kinetics, Troe): if ct_collider is not None: - ct_reaction = ct.FalloffReaction( + ct_reaction = ct.Reaction( reactants=ct_reactants, products=ct_products, - tbody=ct_collider, + third_body=ct_collider, rate=ct.TroeRate() ) else: - ct_reaction = ct.FalloffReaction( + ct_reaction = ct.Reaction( reactants=ct_reactants, products=ct_products, rate=ct.TroeRate() @@ -369,14 +369,14 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False): elif isinstance(self.kinetics, Lindemann): if ct_collider is not None: - ct_reaction = ct.FalloffReaction( + ct_reaction = ct.Reaction( reactants=ct_reactants, products=ct_products, - tbody=ct_collider, + third_body=ct_collider, rate=ct.LindemannRate() ) else: - ct_reaction = ct.FalloffReaction( + ct_reaction = ct.Reaction( reactants=ct_reactants, products=ct_products, rate=ct.LindemannRate() diff --git a/rmgpy/tools/canteramodel.py b/rmgpy/tools/canteramodel.py index 15d26c2947..28cca1253d 100644 --- a/rmgpy/tools/canteramodel.py +++ b/rmgpy/tools/canteramodel.py @@ -840,20 +840,15 @@ def check_equivalent_falloff(fall1, fall2): for j in range(ct_rxn1.rate.data.shape[1]): assert check_nearly_equal(ct_rxn1.rate.data[i, j], ct_rxn2.rate.data[i, j], dE), \ "Similar Chebyshev coefficients" - - elif isinstance(ct_rxn1, ct.ThreeBodyReaction): - assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency" - assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies" - - elif isinstance(ct_rxn1, ct.FalloffReaction): - assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency" - assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies" - if ct_rxn1.falloff or ct_rxn2.falloff: - check_equivalent_falloff(ct_rxn1.falloff, ct_rxn2.falloff) - if ct_rxn1.high_rate or ct_rxn2.high_rate: - check_equivalent_arrhenius(ct_rxn1.high_rate, ct_rxn2.high_rate) - if ct_rxn1.low_rate or ct_rxn2.low_rate: - check_equivalent_arrhenius(ct_rxn1.low_rate, ct_rxn2.low_rate) + else: + assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency" + assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies" + if ct_rxn1.falloff or ct_rxn2.falloff: + check_equivalent_falloff(ct_rxn1.falloff, ct_rxn2.falloff) + if ct_rxn1.high_rate or ct_rxn2.high_rate: + check_equivalent_arrhenius(ct_rxn1.high_rate, ct_rxn2.high_rate) + if ct_rxn1.low_rate or ct_rxn2.low_rate: + check_equivalent_arrhenius(ct_rxn1.low_rate, ct_rxn2.low_rate) except Exception as e: print("Cantera reaction {0} failed equivalency check on: {1}".format(ct_rxn1, e)) diff --git a/test/rmgpy/reactionTest.py b/test/rmgpy/reactionTest.py index 4e1cc0cc50..3fd801105f 100644 --- a/test/rmgpy/reactionTest.py +++ b/test/rmgpy/reactionTest.py @@ -2954,7 +2954,7 @@ def test_pdep_arrhenius(self): # Check that the reaction string is the same assert repr(converted_obj) == repr(ct_obj) # Check that the Arrhenius rates are identical - assert str(converted_obj.rates) == str(ct_obj.rates) + assert converted_obj.rate.rates == ct_obj.rate.rates def test_multi_pdep_arrhenius(self): """ @@ -2975,7 +2975,7 @@ def test_multi_pdep_arrhenius(self): # Check that the reaction string is the same assert repr(converted_rxn) == repr(ct_rxn) # Check that the Arrhenius rates are identical - assert str(converted_rxn.rates) == str(ct_rxn.rates) + assert converted_rxn.rate.rates == ct_rxn.rate.rates def test_chebyshev(self): """ diff --git a/test/rmgpy/speciesTest.py b/test/rmgpy/speciesTest.py index 6c2f558b21..dcbdd43453 100644 --- a/test/rmgpy/speciesTest.py +++ b/test/rmgpy/speciesTest.py @@ -458,24 +458,24 @@ def test_cantera(self): rmg_ct_species = rmg_species.to_cantera(use_chemkin_identifier=True) - ct_species = ct.Species.fromCti( - """species(name=u'Ar', - atoms='Ar:1', - thermo=(NASA([200.00, 1000.00], - [ 2.50000000E+00, 0.00000000E+00, 0.00000000E+00, - 0.00000000E+00, 0.00000000E+00, -7.45375000E+02, - 4.37967000E+00]), - NASA([1000.00, 6000.00], - [ 2.50000000E+00, 0.00000000E+00, 0.00000000E+00, - 0.00000000E+00, 0.00000000E+00, -7.45375000E+02, - 4.37967000E+00])), - transport=gas_transport(geom='atom', - diam=3.33, - well_depth=136.501, - dipole=2.0, - polar=1.0, - rot_relax=15.0))""" - ) + ct_species = ct.Species.from_yaml(""" +name: Ar +composition: {Ar: 1} +thermo: + model: NASA7 + temperature-ranges: [200.0, 1000.0, 6000.0] + data: + - [2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967] + - [2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967] +transport: + model: gas + geometry: atom + diameter: 3.33 + well-depth: 136.501 + dipole: 2.0 + polarizability: 1.0 + rotational-relaxation: 15.0 +""") assert type(rmg_ct_species) == type(ct_species) assert rmg_ct_species.name == ct_species.name assert rmg_ct_species.composition == ct_species.composition diff --git a/test/rmgpy/transportDataTest.py b/test/rmgpy/transportDataTest.py index 59dee0a542..ab7f244430 100644 --- a/test/rmgpy/transportDataTest.py +++ b/test/rmgpy/transportDataTest.py @@ -161,16 +161,20 @@ def test_to_cantera(self): rmg_ct_transport = transport.to_cantera() import cantera as ct - ct_species = ct.Species.fromCti( - """species(name=u'Ar', - atoms='Ar:1', - transport=gas_transport(geom='atom', - diam=3.33, - well_depth=136.501, - dipole=2.0, - polar=1.0, - rot_relax=15.0))""" - ) + ct_species = ct.Species.from_yaml(""" +name: Ar +composition: {Ar: 1} +thermo: + model: constant-cp +transport: + model: gas + geometry: atom + diameter: 3.33 + well-depth: 136.501 + dipole: 2.0 + polarizability: 1.0 + rotational-relaxation: 15.0 +""") ct_transport = ct_species.transport