Skip to content

Commit

Permalink
Tidy up reaction.py, removing fix_reaction
Browse files Browse the repository at this point in the history
This function is only used in one place for one very specific thing
so I inlined it. It also had a vague name.

I then commented it out, because I'm not clear why it's needed.
If it is needed, we can restore it (and put a comment as to why)
  • Loading branch information
rwest committed Mar 23, 2024
1 parent 4eadacf commit dc3befb
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions rmgpy/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,6 @@ 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):
"""
Expand Down Expand Up @@ -368,8 +356,14 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
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)
## I'm not sure why the following is necessary instead of the line above.
## If there was reasoning in a commit message, it got lost in a rebase.
#rxn_stoic = [f"{v} {k}" for k, v in ct_reactants.items() if v != 1]
#rxn_stoic.extend([k for k, v in ct_reactants.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)
#ct_reaction = ct.Reaction(equation=equation, rate=rate)

elif isinstance(self.kinetics, Lindemann):
high_rate = self.kinetics.arrheniusHigh.to_cantera_kinetics(arrhenius_class=True)
Expand Down

0 comments on commit dc3befb

Please sign in to comment.