Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions rmgpy/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def _apply_CHE_model(self, T):

if self.electrons != self.protons:
raise ReactionError("Number of electrons must equal number of protons! "
f"{self} has {self.electrons} protons and {self.electrons} electrons")
f"{self} has {self.protons} protons and {self.electrons} electrons")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this typo fix looks good



H2_thermo = ThermoData(Tdata=([300,400,500,600,800,1000,1500],'K'),
Expand Down Expand Up @@ -662,25 +662,29 @@ def get_entropy_of_reaction(self, T):
for product in self.products:
dSrxn += product.get_entropy(T)
return dSrxn

Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Trailing whitespace detected. Consider removing the trailing spaces.

Suggested change

Copilot uses AI. Check for mistakes.
def get_free_energy_of_non_charge_transfer_reaction(self, T):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll notice the other method had cython.declare lines. This helps Cython create faster code.


Comment on lines +666 to 667
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for this new method. Consider adding a docstring that explains what this method calculates and when it should be used. Based on its usage in _get_free_energy_of_charge_transfer_reaction and get_reversible_potential, this method calculates the standard free energy of reaction (without the electrochemical potential term), which is used for both charge transfer and non-charge transfer reactions.

Suggested change
def get_free_energy_of_non_charge_transfer_reaction(self, T):
def get_free_energy_of_non_charge_transfer_reaction(self, T):
"""
Return the standard free energy of reaction (ΔG°) in J/mol at temperature `T` in K,
excluding any electrochemical potential (i.e., without the -nFE term).
This method sums the free energies of the products and subtracts those of the reactants,
and is used as the base calculation for both charge transfer and non-charge transfer reactions.
Parameters
----------
T : float
Temperature in Kelvin at which to evaluate the free energy of reaction.
Returns
-------
float
The standard free energy of reaction in J/mol.
"""

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Cython type declarations. For consistency with other methods like get_enthalpy_of_reaction and get_entropy_of_reaction, this method should include Cython declarations. Consider adding:

cython.declare(dGrxn=cython.double, reactant=Species, product=Species)
Suggested change
cython.declare(dGrxn=cython.double, reactant=Species, product=Species)

Copilot uses AI. Check for mistakes.
def _get_free_energy_of_charge_transfer_reaction(self, T, potential=0.):

cython.declare(dGrxn=cython.double, reactant=Species, product=Species)

dGrxn = 0
dGrxn = 0.0
for reactant in self.reactants:
try:
dGrxn -= reactant.get_free_energy(T)
except Exception:
logging.error("Problem with reactant {!r} in reaction {!s}".format(reactant, self))
raise

for product in self.products:
try:
dGrxn += product.get_free_energy(T)
except Exception:
logging.error("Problem with product {!r} in reaction {!s}".format(reactant, self))
logging.error("Problem with product {!r} in reaction {!s}".format(product, self))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this typo fix looks good (but you could turn it into an f-string while you're at it)

raise
return dGrxn

def _get_free_energy_of_charge_transfer_reaction(self, T, potential=0.):

cython.declare(dGrxn=cython.double, reactant=Species, product=Species)
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused Cython variable declarations. The variables reactant and product are declared but no longer used in this method since it now delegates to get_free_energy_of_non_charge_transfer_reaction. Consider removing them from the declaration:

cython.declare(dGrxn=cython.double)
Suggested change
cython.declare(dGrxn=cython.double, reactant=Species, product=Species)
cython.declare(dGrxn=cython.double)

Copilot uses AI. Check for mistakes.

dGrxn = self.get_free_energy_of_non_charge_transfer_reaction(T)

if potential != 0.:
dGrxn -= self.electrons * constants.F * potential
Expand All @@ -697,19 +701,8 @@ def get_free_energy_of_reaction(self, T, potential=0.):
if self.is_charge_transfer_reaction():
return self._get_free_energy_of_charge_transfer_reaction(T, potential=potential)

dGrxn = 0.0
for reactant in self.reactants:
try:
dGrxn -= reactant.get_free_energy(T)
except Exception:
logging.error("Problem with reactant {!r} in reaction {!s}".format(reactant, self))
raise
for product in self.products:
try:
dGrxn += product.get_free_energy(T)
except Exception:
logging.error("Problem with product {!r} in reaction {!s}".format(reactant, self))
raise
# For non charge transfer reactions, we can use the free energy of the species
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is misleading. The code calculates free energy from enthalpy and entropy (H - T*S) rather than directly using species free energies. Consider updating the comment to: "For non charge transfer reactions, calculate free energy from enthalpy and entropy"

Suggested change
# For non charge transfer reactions, we can use the free energy of the species
# For non charge transfer reactions, calculate free energy from enthalpy and entropy

Copilot uses AI. Check for mistakes.
dGrxn = self.get_enthalpy_of_reaction(T) - T * self.get_entropy_of_reaction(T)

return dGrxn

Expand All @@ -721,7 +714,7 @@ def get_reversible_potential(self, T):
if not self.is_charge_transfer_reaction():
raise KineticsError("Cannot get reversible potential for non charge transfer reactions")

deltaG = self._get_free_energy_of_charge_transfer_reaction(T) #J/mol
deltaG = self.get_free_energy_of_non_charge_transfer_reaction(T) #J/mol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like renaming _get_free_energy_of_charge_transfer_reaction into self.get_free_energy_of_non_charge_transfer_reaction and calling it a refactoring. They sound like opposites! Was the previous wrong? what is it actually doing?

V0 = deltaG / self.electrons / constants.F # V = deltaG / n / F
return V0

Expand Down
Loading