Skip to content

Support per-frame analysis by AnalysisBase-based classes for streamed trajectories #5183

@PardhavMaradani

Description

@PardhavMaradani

Is your feature request related to a problem?

AnalysisBase-based analysis classes currently cannot be used for streamed trajectories (as clarified by @orbeckst on Discord).

To illustrate, here is a streaming trajectory setup based on the IMD workshop for which DSSP analysis is needed:

import MDAnalysis as mda
from MDAnalysis.analysis.dssp import DSSP

top = "/tmp/imd-workshop-2025/workshop/sample_simulation/GROMACS/input/start.gro"
u = mda.Universe(top, "imd://localhost:8889")

We cannot run the full analysis because there is no concept of frame length for streamed trajectories, so

run = DSSP(u).run()

throws a RuntimeError: IMDReader: n_frames is unknown exception as expected.

We also cannot use the start and stop params because we can't access arbitrary fames. So, something like this

run = DSSP(u).run(start=0, stop=1)`

throws a ValueError: IMDReader: Cannot expect a start index from a stream, 'start' must be None exception.

The only other option available to call run(...) is to pass a frames array. Naturally, we cannot pass arbitrary frames, but even passing the current frame as follows

run = DSSP(u).run(frames=[u.trajectory.frame])

throws a TypeError: Streamed Trajectories must be an indexed using a slice exception as only slicing using a step ([::n]) or all frames sequentially ([:]) is currently supported.

This limits the choices to use any standalone functions for these analysis types (if they exist) or create a separate universe per frame to run the analysis on, both of which are not ideal.

Describe the solution you'd like

I'd like to be able to do something like the following:

run = DSSP(u).run(frames=[u.trajectory.frame])

where the current streamed trajectory frame is passed and get the analysis results for this current frame.

Describe alternatives you've considered

For DSSP analysis, there is a standalone assign function, but that requires re-inventing quite bit of what is already done in the DSSP class setup. Another alternative suggested by @marinegor is to create a new universe for the current frame and run the analysis class on it. Though this is simpler than using standalone functions (if they exist), it comes with quite a bit of overhead.

Additional context

My current use case is to show secondary structures computed by the DSSP analysis class for streamed trajectories in realtime in MolecularNodes (cc: @BradyAJohnston ). However, the ability to run any other AnalysisBase-based analysis classes would probably benefit a lot of streamed trajectory use cases in the future.

I will create a PR that supports the approach described in the "solution you'd like" section above. Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions