Skip to content

Commit

Permalink
Remove zero-concentration ions from solutions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisamarshall committed Jan 2, 2017
1 parent 9f8cd02 commit 89039a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions ionize/Solution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ def __init__(self, ions=[], concentrations=[]):
else:
ion = copy.copy(ion)
ion.context(self)
assert concentration >= 0, 'Concentrations must be positive.'
self._contents[ion] = concentration
if concentration == 0:
continue
elif concentration <0:
raise ValueError('Concentrations must be positive.')
else:
self._contents[ion] = concentration

self._hydronium = database['hydronium']
self._hydroxide = database['hydroxide']
Expand Down Expand Up @@ -206,6 +210,8 @@ def __sub__(self, other):
ion, concentration = other
new_contents = dict(self._contents)
new_contents[ion] = self.concentration(ion) - concentration
if new_contents[ion]==0:
del new_contents[ion]
return Solution(new_contents.keys(), new_contents.values())
except:
raise TypeError('Solutions add to other Solutions or to an'
Expand Down
3 changes: 2 additions & 1 deletion ionize/Solution/titrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def equilibrate_CO2(self, partial_pressure=atmospheric_CO2):

def min_func(concentration):
new_sol = self + (CO2, concentration)
deionized = concentration * (1-sum(new_sol[CO2].ionization_fraction()))
with CO2.context(new_sol):
deionized = concentration * (1-sum(CO2.ionization_fraction()))
return deionized - eq

with warnings.catch_warnings():
Expand Down
2 changes: 1 addition & 1 deletion ionize/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.3'
__version__ = '1.1.0'

0 comments on commit 89039a9

Please sign in to comment.