Refactor AqueousEquilibrium to use composition instead of inheritance#475
Merged
Refactor AqueousEquilibrium to use composition instead of inheritance#475
Conversation
Co-authored-by: K20shores <[email protected]>
Co-authored-by: K20shores <[email protected]>
Copilot
AI
changed the title
[WIP] Refactor
Refactor AqueousEquilibrium to use composition instead of inheritance
Jul 24, 2025
AqueousEquilibrium
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #475 +/- ##
==========================================
+ Coverage 83.63% 84.85% +1.22%
==========================================
Files 48 49 +1
Lines 4093 4815 +722
==========================================
+ Hits 3423 4086 +663
- Misses 670 729 +59 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
K20shores
requested changes
Jul 24, 2025
| Returns: | ||
| Dict: A dictionary representation of the AqueousEquilibrium object. | ||
| """ | ||
| serialize_dict = { |
Collaborator
There was a problem hiding this comment.
create a temporary object and call serialize so that we don't duplicated the dictionary
Contributor
Author
There was a problem hiding this comment.
Done! I've added a _create_serialize_dict() helper method to eliminate the code duplication between serialize() and serialize_static(). The serialize_static() method now creates a temporary object and calls the helper method, following the exact same pattern used in Arrhenius, Troe, and other reaction classes. Commit: 8280e80
… adding helper method Co-authored-by: K20shores <[email protected]>
K20shores
approved these changes
Jul 24, 2025
mattldawson
approved these changes
Jul 24, 2025
boulderdaze
approved these changes
Jul 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors the
AqueousEquilibriumclass inmusica.mechanism_configurationto use composition instead of inheritance from_AqueousEquilibrium, following the established pattern used in other reaction classes likeArrhenius,Troe, andBranched.Changes Made
1. Composition Pattern Implementation
class AqueousEquilibrium(_AqueousEquilibrium):toclass AqueousEquilibrium:self._instance = _AqueousEquilibrium()@propertydecorators that delegate toself._instance2. Python/C++ Object Conversion
Speciesobjects and C++_ReactionComponentobjects(float, Species)in reactants and productsPhaseobjects and string names foraerosol_phaseandaerosol_phase_water3. Serialize Method Refactoring
serialize()from static method to instance method operating on Python-visible dataserialize_static()method for compatibility with C++_AqueousEquilibriumobjectsmechanism_configuration.pyto handle both Python and C++ objects correctly4. Complete Property Coverage
All properties now properly delegate to
self._instance:name,aerosol_phase,aerosol_phase_waterreactants,products(with Python ↔ C++ conversion)A,C,k_reverse,other_propertiestype(returnsReactionType.AqueousEquilibrium)Example Usage
Pattern Consistency
This refactoring exactly matches the composition pattern established in:
arrhenius.pytroe.pybranched.pycondensed_phase_arrhenius.pyBenefits
Fixes #445.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.