This repository was archived by the owner on Mar 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
Refactor Core Data Models for Mutability, Safety, and Performance #7
Copy link
Copy link
Labels
enhancement ✨New feature or requestNew feature or requestperformance ⚡Performance improvements and code optimizationsPerformance improvements and code optimizations
Milestone
Description
Description:
The current data model, based on Vec<T> and usize indices, is highly optimized for initial construction via the MolecularSystemBuilder but is fundamentally brittle and unsafe for the dynamic modifications required by side-chain packing algorithms. Operations such as deleting a residue or mutating a side-chain cause cascading index invalidations across the entire MolecularSystem, leading to data inconsistency and making safe implementation of core algorithms nearly impossible. Redundant data fields (chain_id, res_id in Atom) further complicate state management.
Tasks:
-
Introduce Arena Dependency:
- Add the
slotmapcrate toscream-core's dependencies. It provides a well-tested and high-performanceSlotMapcollection suitable for this purpose.
- Add the
-
Redefine Core Data Structures:
-
Atom: Removeindex,res_id, andchain_id. Add aparent: ResidueKeyfield to link it to its parent residue. -
Residue: Replaceatom_indices: Vec<usize>withatoms: Vec<AtomKey>. Add aparent: ChainKeyfield. Theatom_name_mapwill now mapStringtoAtomKey. -
Chain: Replaceresidues: Vec<Residue>withresidues: Vec<ResidueKey>. Theresidue_mapwill now map the residue sequence number toResidueKey.
-
-
Redesign
MolecularSystem:- Replace
atoms: Vec<Atom>,chains: Vec<Chain>withatoms: SlotMap<AtomKey, Atom>,residues: SlotMap<ResidueKey, Residue>, andchains: SlotMap<ChainKey, Chain>. - Implement a comprehensive and safe public API for all structural queries and modifications (e.g.,
add_atom_to_residue,remove_residue,get_atom_mut). - Update mapping tables (
atom_serial_map,chain_id_map) to store arena keys instead ofusizeindices.
- Replace
-
Update
MolecularSystemBuilder:- Refactor the builder to work with the new arena-based
MolecularSystem.start_chain,start_residue, andadd_atomwill now insert into the arenas and manage the stable keys.
- Refactor the builder to work with the new arena-based
-
Adapt Downstream Code:
- Modify the
bgf.rsI/O implementation to use the new builder and correctly traverse the redesignedMolecularSystemfor writing. - Update all public-facing methods that previously returned
&[Atom]or&[Chain]to provide iterators over the arena collections.
- Modify the
-
Rewrite Unit Tests:
- Thoroughly update and expand unit tests for
system.rs,chain.rs,residue.rs, andbuilder.rsto validate the new data model's correctness, especially for modification and deletion scenarios. - Add tests to ensure that attempting to use a key after its corresponding entity has been deleted results in a predictable and safe failure (e.g.,
Noneorpanic).
- Thoroughly update and expand unit tests for
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancement ✨New feature or requestNew feature or requestperformance ⚡Performance improvements and code optimizationsPerformance improvements and code optimizations