ReactionMechanismGenerator / RMG-Py

Python version of the amazing Reaction Mechanism Generator (RMG).
http://reactionmechanismgenerator.github.io/RMG-Py/
Other
400 stars 228 forks source link

Add to_cantera_kinetics for SurfaceArrhenius and StickingCoefficient kinetics classes #2597

Open sevyharris opened 10 months ago

sevyharris commented 10 months ago

Motivation or Problem

We want to be able to convert from RMG surface reaction kinetics to Cantera kinetics for simulation purposes. It's faster to do this in memory than through loading a whole file.

Description of Changes

This PR implements the to_cantera_kinetics functions so RMG reaction objects can be easily converted to Cantera objects

Testing

COMING SOON: a Jupyter notebook to help compare an example RMG/Cantera surface mechanism

Reviewer Tips

COMING SOON: a Jupyter notebook to help compare an example RMG/Cantera surface mechanism

github-actions[bot] commented 10 months ago

Regression Testing Results

⚠️ One or more regression tests failed. Please download the failed results and run the tests locally or check the log to see why.

Detailed regression test results. ### Regression test aromatics: Reference: Execution time (DD:HH:MM:SS): 00:00:01:05 Current: Execution time (DD:HH:MM:SS): 00:00:01:06 Reference: Memory used: 2139.01 MB Current: Memory used: 2149.48 MB
aromatics Passed Core Comparison ✅ Original model has 15 species. Test model has 15 species. ✅ Original model has 11 reactions. Test model has 11 reactions. ✅
aromatics Failed Edge Comparison ❌ Original model has 106 species. Test model has 106 species. ✅ Original model has 358 reactions. Test model has 358 reactions. ✅ Non-identical thermo! ❌ original: `C=CC1C=CC2=CC1C=C2` tested: `C=CC1C=CC2=CC1C=C2` |Hf(300K) |S(300K) |Cp(300K) |Cp(400K) |Cp(500K) |Cp(600K) |Cp(800K) |Cp(1000K) |Cp(1500K) | |----------|----------|----------|----------|----------|----------|----------|----------|----------| | 83.22| 82.78| 35.48| 45.14| 53.78| 61.40| 73.58| 82.20| 95.08| | 83.22| 84.16| 35.48| 45.14| 53.78| 61.40| 73.58| 82.20| 95.08| Identical thermo comments: thermo: Thermo group additivity estimation: group(Cs-(Cds-Cds)(Cds-Cds)CsH) + group(Cs-(Cds-Cds)(Cds-Cds)CsH) + group(Cds-Cds(Cds-Cds)(Cds-Cds)) + group(Cds- CdsCsH) + group(Cds-CdsCsH) + group(Cds-CdsCsH) + group(Cds-CdsCsH) + group(Cds-Cds(Cds-Cds)H) + group(Cds-Cds(Cds-Cds)H) + group(Cds-CdsHH) + Estimated bicyclic component: polycyclic(s3_5_6_ane) - ring(Cyclohexane) - ring(Cyclopentane) + ring(1,3-Cyclohexadiene) + ring(Cyclopentadiene)
Observables Test Case: Aromatics Comparison ✅ All Observables varied by less than 0.500 on average between old model and new model in all conditions! aromatics Passed Observable Testing ✅
### Regression test liquid_oxidation: Reference: Execution time (DD:HH:MM:SS): 00:00:02:11 Current: Execution time (DD:HH:MM:SS): 00:00:02:12 Reference: Memory used: 2280.03 MB Current: Memory used: 2269.09 MB
liquid_oxidation Failed Core Comparison ❌ Original model has 37 species. Test model has 37 species. ✅ Original model has 216 reactions. Test model has 215 reactions. ❌ The original model has 1 reactions that the tested model does not have. ❌ rxn: `CCO[O](30) <=> [OH](22) + CC=O(69)` origin: intra_H_migration
liquid_oxidation Failed Edge Comparison ❌ Original model has 202 species. Test model has 202 species. ✅ Original model has 1610 reactions. Test model has 1610 reactions. ✅ The original model has 1 reactions that the tested model does not have. ❌ rxn: `CCO[O](30) <=> [OH](22) + CC=O(69)` origin: intra_H_migration The tested model has 1 reactions that the original model does not have. ❌ rxn: `CCO[O](30) <=> C[CH]OO(73)` origin: intra_H_migration Non-identical kinetics! ❌ original: rxn: `CCCCCO[O](104) + CC(CC(C)OO)O[O](103) <=> oxygen(1) + CCCCC[O](127) + CC([O])CC(C)OO(129)` origin: Peroxyl_Disproportionation tested: rxn: `CCCCCO[O](103) + CC(CC(C)OO)O[O](104) <=> oxygen(1) + CCCCC[O](128) + CC([O])CC(C)OO(127)` origin: Peroxyl_Disproportionation |k(1bar)|300K |400K |500K |600K |800K |1000K |1500K |2000K | |-------|-------|-------|-------|-------|-------|-------|-------|-------| |k(T): | 7.79| 7.46| 7.21| 7.00| 6.67| 6.41| 5.94| 5.60| |k(T): | 3.52| 4.27| 4.71| 5.01| 5.39| 5.61| 5.91| 6.06| kinetics: `Arrhenius(A=(3.18266e+20,'cm^3/(mol*s)'), n=-2.694, Ea=(0.053,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing Ea raised from 0.0 to 0.2 kJ/mol to match endothermicity of reaction.""")` kinetics: `Arrhenius(A=(3.2e+12,'cm^3/(mol*s)'), n=0, Ea=(4.096,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing_Ext-5R-R""")` kinetics: Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing Ea raised from 0.0 to 0.2 kJ/mol to match endothermicity of reaction. kinetics: Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing_Ext-5R-R
Observables Test Case: liquid_oxidation Comparison ✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions! liquid_oxidation Passed Observable Testing ✅
### Regression test nitrogen: Reference: Execution time (DD:HH:MM:SS): 00:00:01:25 Current: Execution time (DD:HH:MM:SS): 00:00:01:24 Reference: Memory used: 2278.15 MB Current: Memory used: 2270.99 MB
nitrogen Failed Core Comparison ❌ Original model has 41 species. Test model has 41 species. ✅ Original model has 359 reactions. Test model has 360 reactions. ❌ The tested model has 1 reactions that the original model does not have. ❌ rxn: `HNO(48) + HCO(13) <=> NO(38) + CH2O(18)` origin: H_Abstraction
nitrogen Failed Edge Comparison ❌ Original model has 132 species. Test model has 132 species. ✅ Original model has 995 reactions. Test model has 997 reactions. ❌ Non-identical thermo! ❌ original: `O1[C]=N1` tested: `O1[C]=N1` |Hf(300K) |S(300K) |Cp(300K) |Cp(400K) |Cp(500K) |Cp(600K) |Cp(800K) |Cp(1000K) |Cp(1500K) | |----------|----------|----------|----------|----------|----------|----------|----------|----------| | 116.46| 53.90| 11.62| 12.71| 13.49| 13.96| 14.14| 13.85| 13.58| | 141.64| 58.66| 12.26| 12.27| 12.09| 11.96| 12.26| 12.72| 12.15| thermo: Thermo group additivity estimation: group(O2s-CdN3d) + group(N3d-OCd) + group(Cd-HN3dO) + ring(Cyclopropene) + radical(CdJ-NdO) thermo: Thermo group additivity estimation: group(O2s-CdN3d) + group(N3d-OCd) + group(Cd-HN3dO) + ring(oxirene) + radical(CdJ-NdO) The tested model has 2 reactions that the original model does not have. ❌ rxn: `HNO(48) + HCO(13) <=> NO(38) + CH2O(18)` origin: H_Abstraction rxn: `HON(T)(83) + HCO(13) <=> NO(38) + CH2O(18)` origin: Disproportionation Non-identical kinetics! ❌ original: rxn: `NCO(66) <=> O1[C]=N1(126)` origin: Intra_R_Add_Endocyclic tested: rxn: `NCO(66) <=> O1[C]=N1(126)` origin: Intra_R_Add_Endocyclic |k(1bar)|300K |400K |500K |600K |800K |1000K |1500K |2000K | |-------|-------|-------|-------|-------|-------|-------|-------|-------| |k(T): | -49.54| -33.65| -24.16| -17.85| -10.01| -5.35| 0.80| 3.82| |k(T): | -66.25| -46.19| -34.19| -26.21| -16.28| -10.36| -2.54| 1.31| kinetics: `Arrhenius(A=(6.95187e+18,'s^-1'), n=-1.628, Ea=(88.327,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Backbone0_N-2R!H-inRing_N-1R!H-inRing_Sp-2R!H-1R!H""")` kinetics: `Arrhenius(A=(6.95187e+18,'s^-1'), n=-1.628, Ea=(111.271,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Backbone0_N-2R!H-inRing_N-1R!H-inRing_Sp-2R!H-1R!H""")` Identical kinetics comments: kinetics: Estimated from node Backbone0_N-2R!H-inRing_N-1R!H-inRing_Sp-2R!H-1R!H
Observables Test Case: NC Comparison ✅ All Observables varied by less than 0.200 on average between old model and new model in all conditions! nitrogen Passed Observable Testing ✅
### Regression test oxidation: Reference: Execution time (DD:HH:MM:SS): 00:00:02:36 Current: Execution time (DD:HH:MM:SS): 00:00:02:33 Reference: Memory used: 2121.69 MB Current: Memory used: 2155.22 MB
oxidation Passed Core Comparison ✅ Original model has 59 species. Test model has 59 species. ✅ Original model has 694 reactions. Test model has 694 reactions. ✅
oxidation Passed Edge Comparison ✅ Original model has 230 species. Test model has 230 species. ✅ Original model has 1526 reactions. Test model has 1526 reactions. ✅
Observables Test Case: Oxidation Comparison ✅ All Observables varied by less than 0.500 on average between old model and new model in all conditions! oxidation Passed Observable Testing ✅
### Regression test sulfur: Reference: Execution time (DD:HH:MM:SS): 00:00:00:56 Current: Execution time (DD:HH:MM:SS): 00:00:00:54 Reference: Memory used: 2224.98 MB Current: Memory used: 2243.64 MB
sulfur Passed Core Comparison ✅ Original model has 27 species. Test model has 27 species. ✅ Original model has 74 reactions. Test model has 74 reactions. ✅
sulfur Failed Edge Comparison ❌ Original model has 89 species. Test model has 89 species. ✅ Original model has 227 reactions. Test model has 227 reactions. ✅ The original model has 1 reactions that the tested model does not have. ❌ rxn: `O(4) + SO2(15) (+N2) <=> SO3(16) (+N2)` origin: primarySulfurLibrary The tested model has 1 reactions that the original model does not have. ❌ rxn: `O(4) + SO2(15) (+N2) <=> SO3(16) (+N2)` origin: primarySulfurLibrary
Observables Test Case: SO2 Comparison ✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions! sulfur Passed Observable Testing ✅
### Regression test superminimal: Reference: Execution time (DD:HH:MM:SS): 00:00:00:35 Current: Execution time (DD:HH:MM:SS): 00:00:00:34 Reference: Memory used: 2372.77 MB Current: Memory used: 2385.61 MB
superminimal Passed Core Comparison ✅ Original model has 13 species. Test model has 13 species. ✅ Original model has 21 reactions. Test model has 21 reactions. ✅
superminimal Passed Edge Comparison ✅ Original model has 18 species. Test model has 18 species. ✅ Original model has 28 reactions. Test model has 28 reactions. ✅
### Regression test RMS_constantVIdealGasReactor_superminimal: Reference: Execution time (DD:HH:MM:SS): 00:00:02:35 Current: Execution time (DD:HH:MM:SS): 00:00:02:30 Reference: Memory used: 2785.42 MB Current: Memory used: 2770.87 MB
RMS_constantVIdealGasReactor_superminimal Passed Core Comparison ✅ Original model has 13 species. Test model has 13 species. ✅ Original model has 19 reactions. Test model has 19 reactions. ✅
RMS_constantVIdealGasReactor_superminimal Passed Edge Comparison ✅ Original model has 13 species. Test model has 13 species. ✅ Original model has 19 reactions. Test model has 19 reactions. ✅
Observables Test Case: RMS_constantVIdealGasReactor_superminimal Comparison ✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions! RMS_constantVIdealGasReactor_superminimal Passed Observable Testing ✅
### Regression test RMS_CSTR_liquid_oxidation: Reference: Execution time (DD:HH:MM:SS): 00:00:06:25 Current: Execution time (DD:HH:MM:SS): 00:00:06:12 Reference: Memory used: 2762.94 MB Current: Memory used: 2765.73 MB
RMS_CSTR_liquid_oxidation Failed Core Comparison ❌ Original model has 37 species. Test model has 37 species. ✅ Original model has 232 reactions. Test model has 233 reactions. ❌ The tested model has 1 reactions that the original model does not have. ❌ rxn: `CCO[O](34) <=> [OH](21) + CC=O(62)` origin: intra_H_migration
RMS_CSTR_liquid_oxidation Failed Edge Comparison ❌ Original model has 206 species. Test model has 206 species. ✅ Original model has 1508 reactions. Test model has 1508 reactions. ✅ The original model has 2 reactions that the tested model does not have. ❌ rxn: `CCCO[O](34) <=> CC[CH]OO(51)` origin: intra_H_migration rxn: `CCO[O](36) <=> C[CH]OO(62)` origin: intra_H_migration The tested model has 2 reactions that the original model does not have. ❌ rxn: `CCO[O](34) <=> [OH](21) + CC=O(62)` origin: intra_H_migration rxn: `CCCO[O](35) <=> [OH](21) + CCC=O(44)` origin: intra_H_migration Non-identical kinetics! ❌ original: rxn: `CCCO[O](34) + CCCC(C)O[O](33) <=> oxygen(1) + CCC[O](96) + CCCC(C)[O](61)` origin: Peroxyl_Disproportionation tested: rxn: `CCCO[O](35) + CCCC(C)O[O](33) <=> oxygen(1) + CCC[O](95) + CCCC(C)[O](65)` origin: Peroxyl_Disproportionation |k(1bar)|300K |400K |500K |600K |800K |1000K |1500K |2000K | |-------|-------|-------|-------|-------|-------|-------|-------|-------| |k(T): | 3.69| 4.39| 4.82| 5.10| 5.45| 5.66| 5.94| 6.08| |k(T): | 7.83| 7.49| 7.23| 7.02| 6.68| 6.42| 5.95| 5.61| kinetics: `Arrhenius(A=(3.2e+12,'cm^3/(mol*s)'), n=0, Ea=(3.866,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing_Ext-5R-R""")` kinetics: `Arrhenius(A=(3.18266e+20,'cm^3/(mol*s)'), n=-2.694, Ea=(0,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing""")` kinetics: Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing_Ext-5R-R kinetics: Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing
Observables Test Case: RMS_CSTR_liquid_oxidation Comparison ✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions! RMS_CSTR_liquid_oxidation Passed Observable Testing ✅
### Regression test fragment: Reference: Execution time (DD:HH:MM:SS): 00:00:00:40 Current: Execution time (DD:HH:MM:SS): 00:00:00:40 Reference: Memory used: 2056.96 MB Current: Memory used: 2066.37 MB
fragment Passed Core Comparison ✅ Original model has 10 species. Test model has 10 species. ✅ Original model has 2 reactions. Test model has 2 reactions. ✅
fragment Passed Edge Comparison ✅ Original model has 33 species. Test model has 33 species. ✅ Original model has 47 reactions. Test model has 47 reactions. ✅
Observables Test Case: fragment Comparison ✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions! fragment Passed Observable Testing ✅
### Regression test RMS_constantVIdealGasReactor_fragment: Reference: Execution time (DD:HH:MM:SS): 00:00:03:13 Current: Execution time (DD:HH:MM:SS): 00:00:03:08 Reference: Memory used: 2937.09 MB Current: Memory used: 2955.57 MB
RMS_constantVIdealGasReactor_fragment Passed Core Comparison ✅ Original model has 10 species. Test model has 10 species. ✅ Original model has 2 reactions. Test model has 2 reactions. ✅
RMS_constantVIdealGasReactor_fragment Passed Edge Comparison ✅ Original model has 27 species. Test model has 27 species. ✅ Original model has 24 reactions. Test model has 24 reactions. ✅
Observables Test Case: RMS_constantVIdealGasReactor_fragment Comparison ✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions! RMS_constantVIdealGasReactor_fragment Passed Observable Testing ✅

beep boop this comment was written by a bot :robot:

codecov[bot] commented 10 months ago

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 55.38%. Comparing base (9749453) to head (c9b30ea). Report is 6 commits behind head on main.

:exclamation: Current head c9b30ea differs from pull request most recent head e875da7

Please upload reports for the commit e875da7 to get more accurate results.

Files Patch % Lines
rmgpy/reaction.py 0.00% 5 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2597 +/- ## ========================================== + Coverage 54.79% 55.38% +0.58% ========================================== Files 125 124 -1 Lines 37156 36876 -280 ========================================== + Hits 20361 20424 +63 + Misses 16795 16452 -343 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 7 months ago

This pull request is being automatically marked as stale because it has not received any interaction in the last 90 days. Please leave a comment if this is still a relevant pull request, otherwise it will automatically be closed in 30 days.

rwest commented 5 months ago

This looks helpful, and indeed necessary for https://github.com/ReactionMechanismGenerator/RMG-Py/pull/2321.

What would be some suitable unit tests? Can we go in both directions (to and from Cantera) allowing round-trip testing? Else I guess a few specific examples of different rate types and stoichiometries to check the units?

github-actions[bot] commented 2 months ago

This pull request is being automatically marked as stale because it has not received any interaction in the last 90 days. Please leave a comment if this is still a relevant pull request, otherwise it will automatically be closed in 30 days.