The phreeqc and phreeq2026 engines contain several bits of common code that can be refactored to eliminate redundancy, thus improving quality, robustness, and test coverage. Specifically:
- Both
PhreeqcEOS and Phreeqc2026EOS contain a _setup_ppsol method. The purpose of this private method is to convey the pyEQL.solution composition to the underlying wrapper (phreeqpython or IPHREEQC, respectively) in a way that those wrappers can understand. Most of the contents of _setup_ppsol relates to reformatting the pyEQL composition into PHREEQC format, which is identical between both wrappers. Only a small bit of each method at the end (here and here, respectively) is different between the two.
- Similarly, the
get_activity_coefficient method of both wrappers contains a small code block whose purpose is to reformat pyEQL solute names such as Na[+1] into Na+, etc. There is similar, but not identical, code in _setup_ppsol
# translate the species into keys that phreeqc will understand
k = standardize_formula(solute)
spl = k.split("[")
el = spl[0]
chg = spl[1].split("]")[0]
if chg[-1] == "1":
chg = chg[0] # just pass + or -, not +1 / -1
k = el + chg
Optimization Task
- Split
_setup_ppsol into two or more private methods. The first (or more) are shared between both wrappers (so, implemented only in Phreeqc2026EOS and inherited by PhreeqcEOS ) and handles "translating" pyEQL compositions into PHREEQC format. The second or last private method is the wrapper-specific code
- One of the private methods should replace the code block in
get_activity_coefficient with a private method that does this translation of keys. This can likely be utilized in _setup_ppsol as well.
The
phreeqcandphreeq2026engines contain several bits of common code that can be refactored to eliminate redundancy, thus improving quality, robustness, and test coverage. Specifically:PhreeqcEOSandPhreeqc2026EOScontain a_setup_ppsolmethod. The purpose of this private method is to convey thepyEQL.solutioncomposition to the underlying wrapper (phreeqpythonorIPHREEQC, respectively) in a way that those wrappers can understand. Most of the contents of_setup_ppsolrelates to reformatting thepyEQLcomposition into PHREEQC format, which is identical between both wrappers. Only a small bit of each method at the end (here and here, respectively) is different between the two.get_activity_coefficientmethod of both wrappers contains a small code block whose purpose is to reformatpyEQLsolute names such asNa[+1]intoNa+, etc. There is similar, but not identical, code in_setup_ppsolOptimization Task
_setup_ppsolinto two or more private methods. The first (or more) are shared between both wrappers (so, implemented only inPhreeqc2026EOSand inherited byPhreeqcEOS) and handles "translating"pyEQLcompositions into PHREEQC format. The second or last private method is the wrapper-specific codeget_activity_coefficientwith a private method that does this translation of keys. This can likely be utilized in_setup_ppsolas well.