Skip to content

Commit

Permalink
allow cantera output to use RMG names
Browse files Browse the repository at this point in the history
Added an option to 'toCantera' methods in Species and Reaction
to allow for the name of the species/reaction to be the RMG name
instead of the chemkin name. The default behavior is still the same.

This is one step in addressing issue #1065.
  • Loading branch information
goldmanm committed Jun 30, 2017
1 parent 9c9db7c commit 82e1744
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 12 additions & 3 deletions rmgpy/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ def toChemkin(self, speciesList=None, kinetics=True):
else:
return rmgpy.chemkin.writeReactionString(self)

def toCantera(self, speciesList=None):
def toCantera(self, speciesList=None, useChemkinIdentifier = True):
"""
Converts the RMG Reaction object to a Cantera Reaction object
with the appropriate reaction class.
If useChemkinIdentifier is set to False, the species label is used
instead. Be sure that species' labels are unique when setting it False.
"""
from rmgpy.kinetics import Arrhenius, ArrheniusEP, MultiArrhenius, PDepArrhenius, MultiPDepArrhenius, Chebyshev, ThirdBody, Lindemann, Troe

Expand All @@ -208,14 +211,20 @@ def toCantera(self, speciesList=None):
# for initializing the cantera reaction object
ctReactants = {}
for reactant in self.reactants:
reactantName = reactant.toChemkin() # Use the chemkin name for the species
if useChemkinIdentifier:
reactantName = reactant.toChemkin()
else:
reactantName = reactant.label
if reactantName in ctReactants:
ctReactants[reactantName] += 1
else:
ctReactants[reactantName] = 1
ctProducts = {}
for product in self.products:
productName = product.toChemkin() # Use the chemkin name for the species
if useChemkinIdentifier:
productName = product.toChemkin()
else:
productName = product.label
if productName in ctProducts:
ctProducts[productName] += 1
else:
Expand Down
11 changes: 8 additions & 3 deletions rmgpy/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,13 @@ def toChemkin(self):
from rmgpy.chemkin import getSpeciesIdentifier
return getSpeciesIdentifier(self)

def toCantera(self):
def toCantera(self, useChemkinIdentifier = True):
"""
Converts the RMG Species object to a Cantera Species object
with the appropriate thermo data.
If useChemkinIdentifier is set to False, the species label is used
instead. Be sure that species' labels are unique when setting it False.
"""
import cantera as ct

Expand All @@ -273,8 +276,10 @@ def toCantera(self):
elementDict[symbol] = 1
else:
elementDict[symbol] += 1

ctSpecies = ct.Species(self.toChemkin(), elementDict)
if useChemkinIdentifier:
ctSpecies = ct.Species(self.toChemkin(), elementDict)
else:
ctSpecies = ct.Species(self.label, elementDict)
if self.thermo:
try:
ctSpecies.thermo = self.thermo.toCantera()
Expand Down

0 comments on commit 82e1744

Please sign in to comment.