Skip to content

Commit

Permalink
wip changes for stickingcoeffcient issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Khalil committed Jul 13, 2022
1 parent 71286f6 commit e09705b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
54 changes: 34 additions & 20 deletions rmgpy/cantera.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,26 +256,40 @@ def reaction_to_dicts(obj, spcs):
length 1, but a MultiArrhenius or MultiPDepArrhenius will be longer.
"""

try:
reaction_list = []
if isinstance(obj.kinetics, MultiArrhenius) or isinstance(obj.kinetics, MultiPDepArrhenius):
list_of_cantera_reactions = obj.to_cantera(use_chemkin_identifier=True)
else:
list_of_cantera_reactions = [ obj.to_cantera(use_chemkin_identifier=True) ]

for reaction in list_of_cantera_reactions:
reaction_data = reaction.input_data
efficiencies = getattr(obj.kinetics, 'efficiencies', {})
if efficiencies:
reaction_data["efficiencies"] = {spcs[i].to_chemkin(): float(val) for i, val in enumerate(obj.kinetics.get_effective_collider_efficiencies(spcs)) if val != 1}

reaction_list.append(reaction_data)
return reaction_list
except:
print('passing')
print(type(obj.kinetics))
print(str(obj))
return []
#try:
reaction_list = []
if isinstance(obj.kinetics, MultiArrhenius) or isinstance(obj.kinetics, MultiPDepArrhenius):
list_of_cantera_reactions = obj.to_cantera(use_chemkin_identifier=True)
else:
list_of_cantera_reactions = [ obj.to_cantera(use_chemkin_identifier=True) ]

for reaction in list_of_cantera_reactions:
reaction_data = reaction.input_data
efficiencies = getattr(obj.kinetics, 'efficiencies', {})
if efficiencies:
reaction_data["efficiencies"] = {spcs[i].to_chemkin(): float(val) for i, val in enumerate(obj.kinetics.get_effective_collider_efficiencies(spcs)) if val != 1}
# if isinstance(obj.kinetics, StickingCoefficient):
# reaction_data.pop('equation', None)
# reaction_data['equation'] = str(obj)
reaction_list.append(reaction_data)

# for reaction in list_of_cantera_reactions:
# reaction_data = reaction.input_data
# efficiencies = getattr(obj.kinetics, 'efficiencies', {})
# if efficiencies:
# reaction_data["efficiencies"] = {spcs[i].to_chemkin(): float(val) for i, val in enumerate(obj.kinetics.get_effective_collider_efficiencies(spcs)) if val != 1}

# reaction_list.append(reaction_data)

# if isinstance[obj.kinetics, StickingCoefficient]:
# print(str(obj))

return reaction_list
# except:
# print('passing')
# print(type(obj.kinetics))
# print(str(obj))
# return []


def obj_to_dict(obj, spcs, names=None, label="solvent"):
Expand Down
2 changes: 1 addition & 1 deletion rmgpy/reaction.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cdef class Reaction:

cpdef bint is_surface_reaction(self)

cpdef bint has_template(self, list reactants, list products)
cpdef bint has_template(self, list ct_reactants, list ct_products)

cpdef bint matches_species(self, list reactants, list products=?)

Expand Down
23 changes: 21 additions & 2 deletions rmgpy/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import os.path
from copy import deepcopy
from functools import reduce
from sre_parse import fix_flags
from urllib.parse import quote

import cython
Expand Down Expand Up @@ -245,6 +246,22 @@ def to_chemkin(self, species_list=None, kinetics=True):
else:
return rmgpy.chemkin.write_reaction_string(self)


def fix_reaction(self, ct_reactions, ct_products):
"""
Fixes the formatting of StickingCoefficients reaction equations
"""
rxn_stoic = [f'{v} {k}' for k,v in ct_reactions.items() if v !=1]
rxn_stoic.extend([k for k,v in ct_reactions.items() if v == 1])

prod_stoic = [f'{v} {k}' for k,v in ct_products.items() if v !=1]
prod_stoic.extend([k for k,v in ct_products.items() if v == 1])

equation = ' + '.join(rxn_stoic) + ' <=> ' + ' + '.join(prod_stoic)
return equation



def to_cantera(self, species_list=None, use_chemkin_identifier=False):
"""
Converts the RMG Reaction object to a Cantera Reaction object
Expand Down Expand Up @@ -281,9 +298,9 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
ct_products[product_name] += 1
else:
ct_products[product_name] = 1

if self.specific_collider: # add a specific collider if exists
ct_collider[self.specific_collider.to_chemkin() if use_chemkin_identifier else self.specific_collider.label] = 1

if self.kinetics:
if isinstance(self.kinetics, Arrhenius):
# Create an Elementary Reaction
Expand Down Expand Up @@ -340,7 +357,8 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
b = self.kinetics._n.value_si
Ea = self.kinetics._Ea.value_si * 1000 # convert from J/mol to J/kmol
rate = ct.StickingArrheniusRate(A, b, Ea)
ct_reaction = ct.Reaction(equation=str(self), rate=rate)
equation = self.fix_reaction(ct_reactants, ct_products)
ct_reaction = ct.Reaction(equation=equation, rate=rate)


elif isinstance(self.kinetics, Lindemann):
Expand Down Expand Up @@ -378,6 +396,7 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
else:
raise Exception('Cantera reaction cannot be created because there was no kinetics.')


def get_url(self):
"""
Get a URL to search for this reaction in the rmg website.
Expand Down

0 comments on commit e09705b

Please sign in to comment.