Skip to content

Support sliced iteration for all Readers #1081

@kain88-de

Description

@kain88-de

Expected behaviour

for ts in u.trajectory[start:stop:step] should always work.

Actual behaviour

This only works for readers that implement random access

Solution

I know that this is only efficiently to implement for a random access reader. But we should still be able to iterate through the trajectory with a sliced iterator, it's just that we need to pay the iteration cost for the full trajectory. There is nothing stopping us from yielding only the requested frames. To notify the user that his action are slow because of the trajectory format we can just print a warning telling him that computations can be speed up by switching to a random access reader.

I'm stumbling on this right now because we are writing a library on top of MDAnalysis at work which plans to use sliced iterators. We don't support this for all readers though so I'm left with writing MDAnalysis wrapper to support sliced iteration for all trajectory types.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions