Skip to content

Optimization: refactor PHREEQC _setup_ppsol to reduce redundant code #354

@rkingsbury

Description

@rkingsbury

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions