Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

feat(engine): Implement Incremental Energy Grid for High-Performance Optimization#40

Merged
TKanX merged 36 commits intomainfrom
feature/39-implement-high-performance-incremental-energy-engine-with-zero-clone-optimization
Sep 1, 2025
Merged

feat(engine): Implement Incremental Energy Grid for High-Performance Optimization#40
TKanX merged 36 commits intomainfrom
feature/39-implement-high-performance-incremental-energy-engine-with-zero-clone-optimization

Conversation

@TKanX
Copy link
Member

@TKanX TKanX commented Sep 1, 2025

Summary:

Introduces a major architectural enhancement to the core engine: a new EnergyGrid for high-performance, incremental energy updates. Previously, energy calculations required cloning the entire molecular system for each proposed rotamer change, which was computationally expensive. The new EnergyGrid pre-calculates and stores all pairwise sidechain interaction energies and allows for the rapid calculation of the energy change (ΔE) of a single rotamer move without re-calculating the entire system's energy. This is managed through a SystemView and transactional system state updates, virtually eliminating system cloning during the optimization loops and dramatically improving performance.

Changes:

  • Implemented EnergyGrid for Incremental Updates:

    • energy_grid.rs: Created the EnergyGrid struct, which maintains a complete matrix of pairwise interaction energies between all active residues.
    • calculate_delta_for_move: A new key function that computes the change in energy (ΔE) for a proposed rotamer move by looking up pre-calculated energies and calculating only the interactions involving the moved sidechain.
    • apply_move: Efficiently updates the grid's state by applying the pre-calculated ΔE, avoiding a full energy recalculation.
  • Introduced SystemView for Transactional Operations:

    • transaction.rs: Implemented SystemView, a temporary mutable view of the system state.
    • It provides transactional methods (transaction and transaction_doublet) that allow for speculative rotamer placements. The system is automatically reverted to its original state after the transaction, ensuring the main optimization loop operates on a consistent state.
  • Refactored Optimization Tasks to use EnergyGrid:

    • place.rs: The main placement workflow was refactored to build the EnergyGrid once and then use calculate_delta_for_move and apply_move within its optimization loops (clash resolution, SA, refinement).
    • doublet_optimization.rs: The task now uses SystemView and its transactional capabilities to evaluate pairs without expensive system clones.
  • Streamlined Energy Calculation and Parameterization:

    • The total_energy task was removed, as its functionality is now encapsulated within the EnergyGrid.
    • The Parameterizer was further refined, separating core parameter calculation from the final application step to improve logic flow.
    • Logic for residue selection and atom queries was moved into a dedicated engine::utils::query module for better organization.

TKanX added 30 commits August 29, 2025 16:02
… topology retrieval and enhancing parallel evaluation
@TKanX TKanX self-assigned this Sep 1, 2025
Copilot AI review requested due to automatic review settings September 1, 2025 09:30
@TKanX TKanX added enhancement ✨ New feature or request performance ⚡ Performance improvements and code optimizations labels Sep 1, 2025
@TKanX TKanX linked an issue Sep 1, 2025 that may be closed by this pull request
31 tasks
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a major architectural enhancement to the core engine by introducing an EnergyGrid for high-performance, incremental energy updates. The new system pre-calculates pairwise sidechain interaction energies and allows rapid calculation of energy changes (ΔE) for single rotamer moves without re-calculating the entire system's energy, dramatically improving performance by virtually eliminating expensive system cloning during optimization loops.

  • Introduced EnergyGrid and SystemView for incremental energy calculations and transactional operations
  • Refactored optimization workflows to use the new energy grid system
  • Reorganized utility functions into dedicated query module for better code organization

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/scream-core/src/workflows/place.rs Refactored main placement workflow to use EnergyGrid and SystemView for optimization phases
crates/scream-core/src/engine/energy_grid.rs New EnergyGrid implementation for incremental energy calculations
crates/scream-core/src/engine/transaction.rs New SystemView for transactional rotamer operations
crates/scream-core/src/engine/utils/query.rs Moved and enhanced residue selection and atom query functions
crates/scream-core/src/engine/tasks/doublet_optimization.rs Updated to use SystemView with performance optimizations
crates/scream-core/src/engine/tasks/el_energy.rs Updated to work with reorganized utility functions
crates/scream-core/src/engine/tasks/interaction_energy.rs Removed duplicated utility function, now uses shared implementation
crates/scream-core/src/engine/tasks/clash_detection.rs Simplified interface by removing progress reporting parameter
crates/scream-core/src/engine/context.rs Removed duplicated functions, now delegates to query module
crates/scream-core/src/engine/mod.rs Added new modules to engine module exports
crates/scream-core/Cargo.toml Added wide crate dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@TKanX TKanX merged commit 5726f1b into main Sep 1, 2025
2 checks passed
@TKanX TKanX deleted the feature/39-implement-high-performance-incremental-energy-engine-with-zero-clone-optimization branch September 1, 2025 09:34
TKanX added a commit that referenced this pull request Sep 28, 2025
…ormance-incremental-energy-engine-with-zero-clone-optimization

feat(engine): Implement Incremental Energy Grid for High-Performance Optimization
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement ✨ New feature or request performance ⚡ Performance improvements and code optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement High-Performance Incremental Energy Engine with Zero-Clone Optimization

2 participants