Skip to content

Commit

Permalink
WIP db refresh - nearly all tests passing!
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Aug 12, 2023
1 parent 29f999d commit 438801c
Show file tree
Hide file tree
Showing 8 changed files with 42,222 additions and 6,209 deletions.
2 changes: 1 addition & 1 deletion docs/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ expect certain parameter names. The following are the currently-used internal
names:

- 'diffusion_coefficient' - diffusion coefficient
- 'pitzer_parameters_activity' - coefficients for the Pitzer model for activity correction
- 'model_parameters.activity_pitzer' - coefficients for the Pitzer model for activity correction
- 'pitzer_parameters_volume'- coefficients for the Pitzer model for partial molar volume
- 'erying_viscosity_coefficients' - coefficients for an Erying-type viscosity correction model
- 'partial_molar_volume'- the partial molar volume (used if Pitzer parameters are not available)
Expand Down
48,165 changes: 42,081 additions & 6,084 deletions src/pyEQL/database/pyeql_db.json
100644 → 100755

Large diffs are not rendered by default.

52 changes: 20 additions & 32 deletions src/pyEQL/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

# import the parameters database
# the pint unit registry
from pyEQL import paramsDB as db
from pyEQL import unit
from pyEQL.logging_system import logger
from pyEQL.salt_ion_match import generate_salt_list
Expand Down Expand Up @@ -212,18 +211,14 @@ def get_activity_coefficient(self, solution, solute):
logger.warning("No salts found that contain solute %s. Returning unit activity coefficient." % solute)
return unit("1 dimensionless")

# search the database for pitzer parameters for 'Salt'
db.search_parameters(Salt.formula)

# use the Pitzer model for higher ionic strength, if the parameters are available

# search for Pitzer parameters
if db.has_parameter(Salt.formula, "pitzer_parameters_activity"):
param = solution.get_property(Salt.formula, "model_parameters.activity_pitzer")
if param is not None:
if verbose is True:
print("Calculating activity coefficient based on parent salt %s" % Salt.formula)

param = db.get_property(Salt.formula, "pitzer_parameters_activity")

# determine alpha1 and alpha2 based on the type of salt
# see the May reference for the rules used to determine
# alpha1 and alpha2 based on charge
Expand Down Expand Up @@ -252,10 +247,10 @@ def get_activity_coefficient(self, solution, solute):
molality,
alpha1,
alpha2,
param.get_value()[0],
param.get_value()[1],
param.get_value()[2],
param.get_value()[3],
unit(param["Beta0"]["value"]).magnitude,
unit(param["Beta1"]["value"]).magnitude,
unit(param["Beta2"]["value"]).magnitude,
unit(param["Cphi"]["value"]).magnitude,
Salt.z_cation,
Salt.z_anion,
Salt.nu_cation,
Expand Down Expand Up @@ -434,21 +429,17 @@ def get_osmotic_coefficient(self, solution):

molality_sum += concentration

# search the database for pitzer parameters for 'salt'
db.search_parameters(item.formula)

if db.has_parameter(item.formula, "pitzer_parameters_activity"):
param = db.get_property(item.formula, "pitzer_parameters_activity")

param = solution.get_property(item.formula, "model_parameters.activity_pitzer")
if param is not None:
osmotic_coefficient = ac.get_osmotic_coefficient_pitzer(
ionic_strength,
concentration,
alpha1,
alpha2,
param.get_value()[0],
param.get_value()[1],
param.get_value()[2],
param.get_value()[3],
unit(param["Beta0"]["value"]).magnitude,
unit(param["Beta1"]["value"]).magnitude,
unit(param["Beta2"]["value"]).magnitude,
unit(param["Cphi"]["value"]).magnitude,
item.z_cation,
item.z_anion,
item.nu_cation,
Expand Down Expand Up @@ -477,16 +468,13 @@ def get_solute_volume(self, solution):
# identify the predominant salt in the solution
Salt = solution.get_salt()

# search the database for pitzer parameters for 'salt'
# db.search_parameters(Salt.formula)

solute_vol = 0 * unit("L")

# use the pitzer approach if parameters are available

pitzer_calc = False

param = solution.get_property(Salt.formula, "pitzer_parameters_volume")
param = solution.get_property(Salt.formula, "model_parameters.molar_volume_pitzer")
if param is not None:
# determine the average molality of the salt
# this is necessary for solutions inside e.g. an ion exchange
Expand All @@ -513,11 +501,11 @@ def get_solute_volume(self, solution):
molality,
alpha1,
alpha2,
param.get_value()[0],
param.get_value()[1],
param.get_value()[2],
param.get_value()[3],
param.get_value()[4],
unit(param["Beta0"]["value"]).magnitude,
unit(param["Beta1"]["value"]).magnitude,
unit(param["Beta2"]["value"]).magnitude,
unit(param["Cphi"]["value"]).magnitude,
unit(param["V_o"]["value"]).magnitude,
Salt.z_cation,
Salt.z_anion,
Salt.nu_cation,
Expand Down Expand Up @@ -549,9 +537,9 @@ def get_solute_volume(self, solution):
if pitzer_calc is True and solute in [Salt.anion, Salt.cation]:
continue

part_vol = solution.get_property(solute, "partial_molar_volume")
part_vol = solution.get_property(solute, "size.molar_volume")
if part_vol is not None:
solute_vol += part_vol * mol
solute_vol += part_vol * mol * unit("1 mol")
logger.info("Updated solution volume using direct partial molar volume for solute %s" % solute)

else:
Expand Down
3 changes: 2 additions & 1 deletion src/pyEQL/salt_ion_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def generate_salt_list(Solution, unit="mol/kg"):
Returns:
-------
dict
A dictionary of Salt objects, keyed to the formula of the salt.
A dictionary of Salt objects, where Salt objects are the keys and
the amounts are the values.
"""
salt_list = {}
Expand Down
5 changes: 4 additions & 1 deletion src/pyEQL/solute.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def uncertainty(self):
return float(self.value.split(" ")[2])
return np.nan

def as_dict(self):
return dict(asdict(self).items())


@dataclass
class Solute:
Expand Down Expand Up @@ -123,7 +126,7 @@ def from_formula(cls, formula: str):
)

def as_dict(self):
return {k: str(v) for k, v in asdict(self).items()}
return dict(asdict(self).items())

# set output of the print() statement
def __str__(self):
Expand Down
Loading

0 comments on commit 438801c

Please sign in to comment.