-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Refactor Mechanism
in musica.mechanism_configuration
to use Python wrapper classes consistently for reactions, species, and phases.
Acceptance Criteria
Mechanism
no longer inherits directly from_Mechanism
.- Holds internal instance
_instance
of_Mechanism
. - Constructor accepts Python-native objects: reactions (list of Python reaction classes), species (list of Python Species), phases (list of Python Phase), version (Python Version).
reactions
attribute wraps and manages internal C++ reaction objects but exposes Python reaction classes.to_dict()
uses Python classes’serialize()
methods exclusively; no direct C++ class checks.- Remove all direct C++ type checks; rely on Python class hierarchy or duck typing.
export()
usesMechanismSerializer.serialize
passing the PythonMechanism
instance.MechanismSerializer.serialize()
validates type, creates directory, and writes JSON or YAML fromto_dict()
output.- Raise errors for unsupported file formats and unsupported reaction types using Python classes.
Ideas
- Implement composition pattern: hold
_Mechanism
instance inself._instance
. - Map Python reaction classes in
to_dict()
instead of C++ types. - Use
isinstance
checks with Python classes only. - Avoid static methods for serialization; prefer instance methods.
- Handle version as a Python class member, not as a C++ member.
Tasks
- Change
class Mechanism(_Mechanism)
toclass Mechanism
holdingself._instance
. - Update
__init__
to accept Python reaction, species, phase, version objects and create_Mechanism
instance internally. - Refactor
to_dict()
to iterate Python-side lists and call theirserialize()
methods. - Remove C++-type checks (
_Arrhenius
,_Branched
, etc.); rely on Python class type checks. - Update
export()
method to callMechanismSerializer.serialize(self, file_path)
. - Modify
MechanismSerializer.serialize()
to accept PythonMechanism
and useto_dict()
. - Add proper error handling for unknown reaction types based on Python classes.
Metadata
Metadata
Assignees
Labels
No labels