Skip to content

Pre-allocate trajectory storage when frame count is known #60

Description

@bjmorgan

Summary

When the number of frames is known upfront (common for post-processing a completed simulation), pre-allocate numpy arrays for trajectory storage instead of growing Python lists with per-frame appends.

Background

Atom.trajectory and Site.trajectory currently grow by list append per frame. For long trajectories this means repeated list resizing, and the resulting Python lists are less efficient for downstream numerical analysis (residence times, transition counting, MSD) than contiguous numpy arrays.

Scope

  • When frame count is known (e.g. trajectory_from_structures where len(structures) is available), pre-allocate numpy arrays
  • Atom.trajectory becomes a pre-allocated np.ndarray of site indices (with a sentinel value for unassigned)
  • Site.trajectory -- consider whether this also benefits from pre-allocation, or whether the variable-length contents (list of atom indices per frame) make this less straightforward
  • Downstream analysis methods should work with the array representation without conversion

Files

  • site_analysis/atom.py -- trajectory attribute
  • site_analysis/site.py -- trajectory attribute
  • site_analysis/trajectory.py -- append_timestep, trajectory_from_structures

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions