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
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.trajectoryandSite.trajectorycurrently 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
trajectory_from_structureswherelen(structures)is available), pre-allocate numpy arraysAtom.trajectorybecomes a pre-allocatednp.ndarrayof 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 straightforwardFiles
site_analysis/atom.py--trajectoryattributesite_analysis/site.py--trajectoryattributesite_analysis/trajectory.py--append_timestep,trajectory_from_structures