Skip to content

Commit 50a873d

Browse files
authored
Merge pull request #182 from KingsburyLab/bugfix
Bugfix in get_total_amount; CHANGELOG for next version
2 parents 1514a95 + 8bb933a commit 50a873d

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

AUTHORS.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ developed and maintained by the Kingsbury Lab at Princeton University.
55

66
Other contributors, listed alphabetically, are:
77

8-
* Kirill Pushkarev (@kirill-push)
9-
* Dhruv Duseja (@DhruvDuseja)
10-
* Andrew Rosen (@arosen93)
11-
* Hernan Grecco (@hgrecco)
8+
- Arpit Bhardwaj (@abhardwaj73)
9+
- Dhruv Duseja (@DhruvDuseja)
10+
- Hernan Grecco (@hgrecco)
11+
- Jaebeom Park (@Jaebeom-P)
12+
- Kirill Pushkarev (@kirill-push)
13+
- Andrew Rosen (@arosen93)
14+
- Sui Xiong Tay (@SuixiongTay)
1215

1316
(If you think that your name belongs here, please let the maintainer know)

CHANGELOG.md

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.6] - 2024-09-01
9+
10+
### Fixed
11+
12+
- `Solution.get_total_amount`: Bugfix that caused an error when called on certain elements
13+
without specifying an oxidation state. For example, `get_total_amount('N')` could raise
14+
an exception in a solution containing `Na` (but no `N`) due to a flaw in a logical
15+
test.
16+
- `Solution._adjust_charge_balance`: Removed a misleading and redundant log message (#162, @SuixiongTay)
17+
18+
### Added
19+
20+
- `gibbs_mix`: A new keyword argument `activity_correction` was added to `gibbs_mix`. It defaults
21+
to `True` (no change from prior behavior), but can be set to `False` in order to calculate the
22+
ideal mixing energy, which is equivalent to only considering entropic effects. (#178, @Jaebeom-P)
23+
- `standardize_formula`: Improve formatting of ammonium sulfate salts. Aqueous ammonium sulfate previously
24+
standardized to `H8S(NO2)2(aq)`, now it will display as `(NH4)2SO4(aq)`.
25+
26+
### Changed
27+
28+
- **BREAKING** `entropy_mix` now returns the ideal mixing _entropy_ in units of J/K rather than the mixing
29+
_energy_ in J. This was done to improve clarity with respect to the function name. An `activity_correction`
30+
kwarg was added to `gibbs_mix` so that you can still calculate the ideal mixing energy by setting it to `False`.
31+
(#178, @Jaebeom-P)
32+
- Revise documentation of `gibbs_mix`, `entropy_mix`, and `donnan_eql`. (#178, @Jaebeom-P)
33+
- CI: Improve comprehensiveness of CI dependency testing. (#163, #164, @abhardwaj73)
34+
835
## [1.1.5] - 2024-07-28
936

1037
### Fixed

src/pyEQL/solution.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,8 @@ def get_total_amount(self, element: str, units: str) -> Quantity:
11611161
:meth:`get_amount`
11621162
:func:`pyEQL.utils.interpret_units`
11631163
"""
1164-
TOT: Quantity = 0
1164+
_units = interpret_units(units)
1165+
TOT: Quantity = ureg.Quantity(0, _units)
11651166

11661167
# standardize the element formula and units
11671168
el = str(Element(element.split("(")[0]))
@@ -1178,7 +1179,7 @@ def get_total_amount(self, element: str, units: str) -> Quantity:
11781179
else:
11791180
species = []
11801181
for k, v in comp_by_element.items():
1181-
if el in k:
1182+
if k.split("(")[0] == el:
11821183
species.extend(v)
11831184

11841185
# loop through the species of interest, adding moles of element
@@ -2294,9 +2295,7 @@ def _adjust_charge_balance(self, atol=1e-8) -> None:
22942295
self.logger.info("balance_charge is None, so no charge balancing will be performed.")
22952296
return
22962297

2297-
self.logger.info(
2298-
f"Adjusting {self._cb_species} to compensate."
2299-
)
2298+
self.logger.info(f"Adjusting {self._cb_species} to compensate.")
23002299

23012300
if self.balance_charge == "pH":
23022301
# the charge imbalance associated with the H+ / OH- system can be expressed

src/pyEQL/utils.py

+6
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ def standardize_formula(formula: str):
137137
elif sform == "C2I2ClO2[-1]":
138138
sform = "CI2ClCOO[-1]"
139139

140+
# ammonium sulfate salts
141+
elif sform == "H8S(NO2)2(aq)":
142+
sform = "(NH4)2SO4(aq)"
143+
elif sform == "H4SNO4[-1]":
144+
sform = "NH4SO4[-1]"
145+
140146
# TODO - consider adding recognition of special formulas like MeOH for methanol or Cit for citrate
141147
return sform
142148

tests/test_solution.py

+1
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ def test_components_by_element(s1, s2):
476476
def test_get_total_amount(s2):
477477
assert np.isclose(s2.get_total_amount("Na(1)", "g").magnitude, 8 * 58, 44)
478478
assert np.isclose(s2.get_total_amount("Na", "mol").magnitude, 8)
479+
assert np.isclose(s2.get_total_amount("N", "mol").magnitude, 0)
479480
assert np.isclose(s2.get_total_amount("Na", "ppm").magnitude, 4 * 23300, rtol=0.02)
480481
sox = Solution({"Fe+2": "10 mM", "Fe+3": "40 mM", "Cl-": "50 mM"}, pH=3)
481482
assert np.isclose(sox.get_total_amount("Fe(2)", "mol/L").magnitude, 0.01)

tests/test_utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def test_standardize_formula():
5252
# Cl+Br
5353
assert standardize_formula("CBrCl2COO-") == "CBrCl2COO[-1]"
5454
assert standardize_formula("CBr2ClCOO-") == "CBr2ClCOO[-1]"
55+
assert standardize_formula("(NH4)2SO4") == "(NH4)2SO4(aq)"
56+
assert standardize_formula("NH4SO4-") == "NH4SO4[-1]"
5557

5658

5759
def test_formula_dict():

0 commit comments

Comments
 (0)