Refactor SimpolPhaseTransfer to use composition instead of inheritance#494
Refactor SimpolPhaseTransfer to use composition instead of inheritance#494
Conversation
Co-authored-by: K20shores <[email protected]>
Co-authored-by: K20shores <[email protected]>
SimpolPhaseTransfer| """Get the reaction type.""" | ||
| return ReactionType.SimpolPhaseTransfer | ||
|
|
||
| def _create_serialize_dict(self, instance) -> Dict: |
There was a problem hiding this comment.
Remove _create_serialize_dict and place the dictionary directly in serialize
There was a problem hiding this comment.
Removed the _create_serialize_dict helper method and inlined the dictionary creation directly in both serialize() and serialize_static() methods. (7aa8eab)
…ation Co-authored-by: K20shores <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #494 +/- ##
==========================================
+ Coverage 84.85% 85.04% +0.18%
==========================================
Files 49 49
Lines 4815 4873 +58
==========================================
+ Hits 4086 4144 +58
Misses 729 729 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| @staticmethod | ||
| def serialize(instance) -> Dict: | ||
| def serialize_static(instance) -> Dict: |
There was a problem hiding this comment.
Create a local copy to call serialize so that the dictionary doesn't need to be duplicated
There was a problem hiding this comment.
Modified serialize_static() to create a local SimpolPhaseTransfer object and call its serialize() method, eliminating the dictionary duplication. (28e352c)
Co-authored-by: K20shores <[email protected]>
| aerosol_phase_species (Union[Species, Tuple[float, Species]]): The aerosol phase species involved in the reaction. | ||
| B (List[float]): The B parameters [unitless]. | ||
| other_properties (Dict[str, Any]): A dictionary of other properties of the simplified phase transfer reaction rate constant. | ||
| unknown_properties (Dict[str, Any]): A dictionary of other properties of the simplified phase transfer reaction rate constant. |
There was a problem hiding this comment.
This should be labelled other_properties as above
There was a problem hiding this comment.
Fixed the docstring parameter name to match the actual parameter name other_properties. (95e34e7)
Co-authored-by: mattldawson <[email protected]>
This PR refactors the
SimpolPhaseTransferclass inmusica.mechanism_configurationto use composition instead of inheritance from_SimpolPhaseTransfer, following the established pattern used in theArrheniusclass.Changes Made
Core Refactoring
SimpolPhaseTransferno longer inherits from_SimpolPhaseTransferself._instance = _SimpolPhaseTransfer()to hold the internal C++ instance@propertydecorators to delegate toself._instanceAttribute Handling
gas_phase_speciesandaerosol_phase_speciesproperties convert between PythonSpecies/(float, Species)tuples and C++_ReactionComponentobjectsgas_phaseandaerosol_phaseaccept bothPhaseobjects and strings, converting to string names for the C++ instanceBparameter is validated as a list of exactly 4 elements on assignmentSerialization Updates
serialize()from static method to instance method using only Python-visible dataserialize_static()method for backward compatibility with C++_SimpolPhaseTransferobjectsmechanism_configuration.pyto handle both C++ and Python instances separatelyPublic Interface
typeproperty returningReactionType.SimpolPhaseTransferExample Usage
Validation
All existing tests continue to pass as the public API remains unchanged. The refactoring follows the same pattern established in similar classes like
Arrhenius.Fixes #452.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.