Skip to content

Commit

Permalink
Merge pull request #35 from rkingsbury/HOH
Browse files Browse the repository at this point in the history
Solution: enable passing EOS instance as engine
  • Loading branch information
rkingsbury authored Aug 22, 2023
2 parents b97301f + b377b1a commit 435eb49
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/pyEQL/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def get_osmotic_coefficient(self, solution):
# coefficient
for item in salts_dict:
# ignore HOH in the salt list
if item == "HOH":
if item.formula == "HOH":
continue

# determine alpha1 and alpha2 based on the type of salt
Expand Down
8 changes: 5 additions & 3 deletions src/pyEQL/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
pH: float = 7,
pE: float = 8.5,
solvent: str | list = "H2O",
engine: Literal["native", "ideal"] = "native",
engine: EOS | Literal["native", "ideal"] = "native",
database: str | Path | Store | None = None,
):
"""
Expand Down Expand Up @@ -147,8 +147,10 @@ def __init__(
# set the equation of state engine
self._engine = engine
# self.engine: Optional[EOS] = None
if self._engine == "ideal":
self.engine: EOS = IdealEOS()
if isinstance(self._engine, EOS):
self.engine: EOS = self._engine
elif self._engine == "ideal":
self.engine = IdealEOS()
elif self._engine == "native":
self.engine = NativeEOS()
else:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
import pytest
from pyEQL import Solution, ureg
from pyEQL.engines import IdealEOS, NativeEOS


@pytest.fixture()
Expand Down Expand Up @@ -88,6 +89,23 @@ def test_init_raises():
Solution(solvent=["D2O", "MeOH"])


def test_init_engines():
"""
Test passing an EOS instance as well as the ideal and native EOS
"""
ideal = IdealEOS()
s = Solution([["Na+", "4 mol/L"], ["Cl-", "4 mol/L"]], engine=ideal)
assert s.engine == ideal
s = Solution([["Na+", "4 mol/L"], ["Cl-", "4 mol/L"]], engine="ideal")
assert isinstance(s.engine, IdealEOS)
assert s.get_activity_coefficient("Na+").magnitude == 1
assert s.get_osmotic_coefficient().magnitude == 1
s = Solution([["Na+", "4 mol/L"], ["Cl-", "4 mol/L"]], engine="native")
assert isinstance(s.engine, NativeEOS)
assert s.get_activity_coefficient("Na+").magnitude < 1
assert s.get_osmotic_coefficient().magnitude != 1


# create an empty and test solutions with the same volume using substance / volume,
# substance/mass, and substance units
def test_solute_addition(s2, s3, s4):
Expand Down

0 comments on commit 435eb49

Please sign in to comment.