KingsburyLab / pyEQL

A Python library for solution chemistry
Other
66 stars 21 forks source link

Enhancement: prevent accidental double-setting of pH #201

Open rkingsbury opened 1 week ago

rkingsbury commented 1 week ago

Currently, it is possible to specify pH by including H+ in the composition dictionary:

>>> initial_conditions = {
    'HCO3-': 1.0e-3,
    'CO3--': 1.0e-4,
    'H+': 1.0e-7 # Note: instead of including H+ here, you could use the pH keyword argument
}
>>> Solution(initial_conditions).pH
4.00

However, this overrides whatever is specified in the pH keyword argument, which is the intended way to set the pH:

>>> Solution(initial_conditions, pH=10).pH
4.000

I think it's OK that the composition dictionary overrides the pH keyword argument, but there should be a warning raised when this happens (at a minimum). Also, I think if a user specifies a non-default pH AND has H+ in their composition dictionary, there should probably be a ValueError since the user's intent is not clear in that case.

This should be fixed in Solution.__init__ here .

gnuhpdiem commented 5 days ago

Hello, can I work on this issue?

rkingsbury commented 5 days ago

Hi @gnuhpdiem , yes, please feel welcome to give it a try!