-
Notifications
You must be signed in to change notification settings - Fork 240
Refactored reaction.py to add get_free_energy_of_non_charge_transfer_reaction for code reuse and circular dependency prevention #2810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
|
||
|
||
H2_thermo = ThermoData(Tdata=([300,400,500,600,800,1000,1500],'K'), | ||
|
@@ -662,25 +662,29 @@ def get_entropy_of_reaction(self, T): | |
for product in self.products: | ||
dSrxn += product.get_entropy(T) | ||
return dSrxn | ||
|
||
def get_free_energy_of_non_charge_transfer_reaction(self, T): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll notice the other method had |
||
|
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
||
dGrxn = self.get_free_energy_of_non_charge_transfer_reaction(T) | ||
|
||
if potential != 0.: | ||
dGrxn -= self.electrons * constants.F * potential | ||
|
@@ -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 | ||
dGrxn = self.get_enthalpy_of_reaction(T) - T * self.get_entropy_of_reaction(T) | ||
|
||
return dGrxn | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like renaming |
||
V0 = deltaG / self.electrons / constants.F # V = deltaG / n / F | ||
return V0 | ||
|
||
|
There was a problem hiding this comment.
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