Skip to content

Conversation

@harryswift01
Copy link
Contributor

@harryswift01 harryswift01 commented Aug 1, 2025

Summary

This PR signifies a large and significant restructure in how CodeEntropy performs entropy calculations. The core change involves transitioning from a per-molecule computation model to a per-timestep approach. Additionally, entropy values are now grouped across molecule types, improving the interpretability and consistency of the results. These changes lay the groundwork for more scalable and scientifically robust analyses.

Changes

Refactor entropy computation granularity:

  • Replaced the per-molecule entropy calculation with a per-timestep approach to improve temporal resolution and consistency.
  • Refactored the entropy computation workflow into modular functions for better maintainability and readability.
  • Ensured correct slicing of timesteps during entropy accumulation to avoid misalignment across frames.

Introduce molecule-type Grouping:

  • Implemented grouping of molecules by type.
  • Updated build_conformational_states and related functions to support type-based aggregation.

Testing and validation:

  • Added new test cases to validate per-timestep entropy computation and molecule-type.
  • Refined existing tests to reflect the updated methodology.

Impact

  • Enhances scientific accuracy and resolution of entropy calculations.
  • Improves code modularity and maintainability for future extensions.
  • Enables more meaningful comparisons across molecule types in complex systems.
  • Reduces computational redundancy and improves performance in matrix operations.

skfegan and others added 26 commits July 3, 2025 17:00
…calculating the covariance matrices and separating the entropy calculation from the loop that makes the matrices. Part 1.
…ding:

- Modified force and torque matrix initializations to use None instead of empty lists, enabling clearer checks for uninitialized matrices.
- Updated the logic that accumulates force and torque covariance matrices to handle cases where matrices have different shapes.
- Introduced a new helper method `_pad_and_add` that pads two 2D numpy arrays with zeros to the maximum dimensions of both arrays, then returns their element-wise sum.
- This method ensures that when covariance matrices from different frames have incompatible shapes, they can still be safely combined without losing data.
- Updated `LevelManager.create_force_and_torque_matrix` to use `_pad_and_add` when accumulating matrices with mismatched shapes.
- Cleaned up some list initializations and matrix sub-block assembly for clarity and consistency.
- Fixed handling of dihedrals in entropy calculations by cycling through each dihedral individually rather than processing them as a batch. This change ensures correct assignment of conformations per dihedral.
… storage

- Removed the `_pad_and_add` function from `get_beads` so it returns only the actual bead selections without added padding.
- Changed force and torque matrix storage from large pre-allocated lists with None placeholders to dictionaries keyed by `(molecule_id, residue_id)`.
- These changes eliminate unnecessary data padding and improve direct access to relevant matrices.
- Result is cleaner data structures and simpler, more reliable indexing.
- Ensured correct indentation to prevent excessive looping
- Passed appropriate `force_matrix`, `torque_matrix`, and `states` within the loop of `_process_united_atom_entropy`
- Used correct keys for accessing matrices to maintain consistency and accuracy
…able components:

- Extracted dihedral conformation logic into a new helper method.
- Modularized the `_compute_entropies` method to delegate level-specific logic cleanly, including:
 - United atom level: per-residue dihedral state assignment and entropy processing.
 - Residue level: molecule-wide dihedral state assignment and entropy processing.
 - Polymer level: vibrational entropy only.
- Introduced `_initialize_molecules`, `_build_covariance_matrices`, and `_update_force_torque_matrices` to encapsulate setup logic and matrix construction.
- Implemented `_handle_water_entropy` to isolate water-specific entropy logic and update selection strings accordingly.
- Ensured all new methods follow consistent naming and parameter conventions.
…s to `LevelManager`

- Relocating the following functions as they deal more intrinsically with the levels rather than the entropy calculations
 - Relocated `compute_dihedral_conformations` to `LevelManager`
 - Relocated `build_covariance_matrices` to `LevelManager`
 - Relocated `update_force_torque_matrices` to `LevelManager`
@harryswift01 harryswift01 added this to the 1.0.0 release milestone Aug 1, 2025
@harryswift01 harryswift01 requested a review from jimboid August 1, 2025 14:48
@harryswift01 harryswift01 self-assigned this Aug 1, 2025
@harryswift01 harryswift01 linked an issue Aug 1, 2025 that may be closed by this pull request
@harryswift01 harryswift01 changed the title Refactor entropy calculation: switch to per-timestep computation with molecule-type averaging Refactor entropy calculation: switch to per-timestep computation with molecule-type grouping Aug 1, 2025
@harryswift01 harryswift01 changed the title Refactor entropy calculation: switch to per-timestep computation with molecule-type grouping Refactor entropy calculations: switch to per-timestep computation with molecule-type grouping Aug 1, 2025
Copy link
Member

@jimboid jimboid left a comment

Choose a reason for hiding this comment

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

The PR looks good to merge. I think there are some things we can look at in future:

  • I can look at parallelism
  • The new matrix math looks ripe for optimisation

But I don't think these are blockers for v1.0.0, we can work on them in a branch and if they are ready then they are ready, if not then they are not. But the priority is polishing for release.

@harryswift01 harryswift01 merged commit 33361c5 into main Aug 4, 2025
7 checks passed
@harryswift01 harryswift01 deleted the 30-averaging-over-molecules-of-the-same-type branch August 4, 2025 09:48
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.

Averaging over molecules of the same type

4 participants