KingsburyLab / pyEQL

A Python library for solution chemistry
Other
64 stars 17 forks source link

Br(None) species - oxidation state error #116

Closed jaichanders closed 5 months ago

jaichanders commented 5 months ago

I get the following error when attempting to calculate activities after speciation of solutions containing Bromide:

File ...\lib\site-packages\pyEQL\solution.py:1147 in get_total_amount ox = float(element.split("(")[-1].split(")")[0]) ValueError: could not convert string to float: 'None'

The species ['Br (aq)'] with the key 'Br(None)' seems to be responsible.

If I manually override this step by changing the key to Br(0) in debug mode, I get the following error from a few lines below

TypeError: argument of type 'NoneType' is not iterable

The minimum code for reproduction is:

from pyEQL import Solution

s = Solution({'Na+':'0.5 mol/kg','Br-':'0.5 mol/kg'}, pH=7, balance_charge='Br-')
s.equilibrate()
act = s.list_activities()

Though this is related to issue #60 (speciation followed by activity calculation), that one seems to be about the theoretical implications of using different models for speciation and activity calculation. Hence, I have opened a separate issue.

rkingsbury commented 5 months ago

Thank you for reporting and for trying to troubleshoot @jaichanders ! I think this will be straightforward to address. Just to confirm, are you using the latest version (0.14.0)?

jaichanders commented 5 months ago

Yes, METADATA says Version: 0.14.0. Thank you for the quick response!

rkingsbury commented 5 months ago

This is partly related to a recent change #106 and ultimately due to a bug in the underlying pymatgen package. See https://github.com/materialsproject/pymatgen/issues/3687

rkingsbury commented 5 months ago

Fixed as of v0.15.0, which I've just uploaded to PyPI

Also FYI, list_activities has been deprecated from some time, and will be removed soon. I suggest using print or a list comprehension instead.