Skip to content

CNApy 2 - #574

Open
axelvonkamp wants to merge 67 commits into
masterfrom
cnapy2
Open

axelvonkamp wants to merge 67 commits into
masterfrom
cnapy2

Conversation

@axelvonkamp

Copy link
Copy Markdown
Member

Draft PR to check new tests

Axel von Kamp and others added 30 commits July 21, 2026 09:51
HiGHS can be used via a new optlang interface, primarily for LPs
OSQP is now used in make_scenario_feasible when neither CPLEX nor Gurobi are available
various minor GUI improvements
### Motivation
- Replace the previous `QTreeWidget`-based implementation with a model/view approach to separate data and presentation and make the reaction list more maintainable and efficient.
- Provide an explicit row data object and table model so coloring, tooltips, sorting and editing logic are encapsulated in the model layer.
- Preserve the existing reactions-list behavior (dragging, selection, editing scenario cells, pinning, column hide/copy) while making future UI changes easier.

### Description
- Added `ReactionListItem` as a lightweight row-data container that stores per-column text, background/foreground colors, tooltips, sort values, pin and hidden state, and emits change notifications to the model via `_emit_changed`.
- Implemented `ReactionListModel` subclassing `QAbstractTableModel` to provide row/column counts, `data`/`setData`, `flags`, header text, insertion/removal (`add_item`/`takeTopLevelItem`/`clear`), and a `sort` implementation that keeps pinned rows at the top.
- Replaced the previous `QTreeWidget` subclass with `DragableTableView` (a `QTableView` subclass) and a `ReactionListRootItem` adapter so existing code that iterates tree-like rows still works; updated `ReactionList` to instantiate and wire `ReactionListModel` + `DragableTableView` and to use model signals (`itemChanged`) instead of widget `itemChanged` events.
- Kept external API/behavior compatible by providing adapter methods such as `findItems`, `takeTopLevelItem`, `indexOfTopLevelItem`, `setCurrentItem`, `scrollToItem`, `editItem`, and retaining context-menu, pin/unpin, coloring, clipboard export and scenario editing logic.

### Testing
- Ran `python3 -m py_compile cnapy/gui_elements/reactions_list.py` which succeeded.
- Ran `python3 -m py_compile cnapy/gui_elements/central_widget.py cnapy/gui_elements/reactions_list.py` which succeeded and verified the updated usage points compile cleanly.
- Ran quick static checks (`git diff --check`) with no reported problems; attempted to import the module at runtime with `python -c "from cnapy.gui_elements.reactions_list import ReactionListModel, ReactionListColumn"` but the import failed due to the test environment missing system OpenGL library (`libGL.so.1`) which prevents Qt GUI initialization, so dynamic run-time GUI tests could not be executed in this CI environment.
…tes to table widget

### Motivation
- Modernize the reactions list to a model/view design to improve performance and simplify item manipulation.
- Remove direct dependence on `QTreeWidgetItem` and tree APIs to allow clearer sorting, hiding and selection handling.
- Use a proper table for metabolites in the reaction mask to better present columns and enable stable item data storage.

### Description
- Introduced `ReactionListModel` (subclass of `QAbstractTableModel`) and `ReactionListItem` as the row data object, and replaced the `QTreeWidget` with `DragableTableView` (a `QTableView` wrapper) for the reactions list UI.
- Replaced many direct tree operations with model-based operations (`reaction_model.items`) and updated signal connections to use `ReactionListModel.itemChanged`.
- Updated sorting, column header access and context menu code to use `horizontalHeader()` and table-based APIs, and adjusted blocking comments to reflect signal changes.
- Implemented row hiding for search via `ReactionListItem.setHidden` and rewrote `update_selected` to use a compiled regex for matching ids/names/annotations.
- Converted the metabolites list in `ReactionMask` from a `QTreeWidget` to a `QTableWidget`, storing the metabolite object in `Qt.UserRole` and updated `emit_jump_to_metabolite` accordingly.

### Testing
- Ran the project unit test suite with `pytest` against the modified code and observed no test failures.
- Performed automated model-level sanity checks for the reactions list model (add/clear/sort/item-change) which completed successfully.
- No automated UI tests were added; manual UI smoke tests were exercised during development (not included in automated test results).
…ionList and ReactionMask

### Motivation
- Replace the legacy `QTreeWidget`-based reaction list with a model/view `QTableView` to improve separation of data and view logic, simplify iteration and updating, and enable more robust sorting and selection behavior.
- Centralize per-row data in a `ReactionListItem` data object and use a `QAbstractTableModel` (`ReactionListModel`) to avoid direct DOM-style traversal of widget children and to make signaling and updates more explicit.
- Replace the metabolites `QTreeWidget` in the reaction mask with a `QTableWidget` to present Id/Name columns and reliably store metabolite objects as item data.

### Description
- Introduced `ReactionListItem` as a plain row-data object and implemented `ReactionListModel` (`QAbstractTableModel`) to back the reaction table, with `itemChanged` signaling and sorting support via `sort()` and `sort_value()`.
- Replaced the previous `DragableTreeWidget` with `DragableTableView` and updated `ReactionList` to use `ReactionListModel` / `DragableTableView`, including wiring `itemChanged` to `handle_item_changed` and adapting all list operations to `reaction_model.items` (add/clear/take/sort/find/hide/etc.).
- Updated search/filtering in `update_selected` to use a compiled wildcard-to-regex search and hide non-matching rows via the model/view, and changed several header / context-menu calls to use the horizontal header API.
- Reworked `ReactionMask` metabolites from a `QTreeWidget` to a `QTableWidget`, storing metabolite objects in `Qt.UserRole`, updating double-click/jump logic, and enabling sorting and proper item tooltips.
- Adjusted `central_widget` coloring code to iterate over `reaction_model.items` and changed a few signal/blocking comments to reflect selection vs item-change semantics.

### Testing
- No automated tests were executed as part of this change.
Axel von Kamp and others added 4 commits September 21, 2026 14:54
environment
option to install a github branch
Windows installer switched to Miniforge3 as this is a signed package
that is less likely to be blocked than micromaba
@axelvonkamp
axelvonkamp marked this pull request as ready for review September 22, 2026 13:24
@axelvonkamp

Copy link
Copy Markdown
Member Author

This branch can be directly installed with
install_cnapy_here.bat cnapy2
or
install_cnapy_here.sh cnapy2

chatgpt-codex-connector[bot]

This comment was marked as outdated.

axelvonkamp and others added 18 commits September 22, 2026 15:53
this is the safest and easiest way to track model changes via the console
New lptools_highs/plot_trace_highs/highs_lp_cache reimplement
plot_flux_space on reusable HiGHS LPs (threaded for 3D plots with
yield axes, thread count chosen automatically). PlotSpaceDialog uses
it and falls back to straindesign's plot_flux_space on errors.
Includes tests and benchmark scripts.

developed with Claude Sonnet 5/5.5 and Opus 5.5
- look up reactions/metabolites by exact ID
- jump list cycles through the occurrences of a reaction on Escher maps
- mark the project as changed only when an Escher map is actually edited
- QEventLoop for collecting Escher map data
- search highlighting follows the current map and is reset on the others
- add "Zoom to canvas" toolbar button for CNApy and Escher maps
Wraps cnapy.core.replace_ids for the model's reactions or metabolites and
keeps the GUI in sync: maps, reaction ID lists, history, scenario/
computed/FVA values and the model tabs use the new IDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTLmyZsCQxGHHwZ7TonQwo
…el, new tests

- scenario reactions can have a scenario value (new Scenario column in the
  scenario tab); it is saved/loaded and applied in load_scenario_into_model
- make scenario feasible: the adjusted biomass reaction gets the bounds of the
  original one and the growth rate as scenario value, all changes of a run form
  one undo step, guards against a biomass fixed to 0 or a duplicate adjusted
  biomass reaction
- new Scenario menu entry to move all scenario reactions into the model
  (clears the scenario history)
- weights_key also uses scenario annotations; scenario annotations are reverted
  when leaving the model context
- scenario tab: annotations are shown after loading, reaction ID edits and
  deletions of annotations are recorded correctly; flux column text is black
- new tests for scenario files (.scen/.val), scenario undo/redo, project files
  (.cna, SBML/JSON export), core functions (yield optimization, make scenario
  feasible, element balances, replace_ids, FluxVectorContainer) and EFM/MCS
  computation; tests README updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants