mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

BUG: streamlines only returns the dx_array, dy_array of last frame

Open lilyminium opened this issue 1 year ago • 5 comments

Expected behavior

From a skim over the docs and code my impression was that streamlines.generate_streamlines would incorporate all frames between start_frame and end_frame in the dx_array, but looking more closely at the code I'm not sure that happens. Is it supposed to?

Actual behavior

I can get this test to pass with start_frame=0, start_frame=1, and start_frame=2.

https://github.com/MDAnalysis/mdanalysis/blob/6ec838b0a018bc8cd2338ede866bbe78a184c6b2/testsuite/MDAnalysisTests/visualization/test_streamlines.py#L54-L80

Because xy_deltas_to_write is returned from this function, it looks like the results get re-set for each frame:

https://github.com/MDAnalysis/mdanalysis/blob/6ec838b0a018bc8cd2338ede866bbe78a184c6b2/package/MDAnalysis/visualization/streamlines.py#L201-L214

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)")
  • Which version of Python (python -V)?
  • Which operating system?

lilyminium avatar Apr 01 '24 03:04 lilyminium

@tylerjereddy could you please spare a quick glance 👀 here?

orbeckst avatar Apr 01 '24 07:04 orbeckst

I saw the ping, I'll try to check soon-ish. I'm under some pressure to get SciPy released to support NumPy 2 series, but will try to make some time.

tylerjereddy avatar Apr 01 '24 20:04 tylerjereddy

I agree with Lily that there's a bug here.

The lack of input validation is also pretty jarring, I can give an obscure floating point value to the test start frame value and it still passes (pretty silly):

--- a/testsuite/MDAnalysisTests/visualization/test_streamlines.py
+++ b/testsuite/MDAnalysisTests/visualization/test_streamlines.py
@@ -88,7 +88,7 @@ def test_streamplot_2D_zero_return(membrane_xtc, univ, tmpdir):
                                                         trajectory_file_path=membrane_xtc,
                                                         grid_spacing=20,
                                                         MDA_selection='name POX',
-                                                        start_frame=1,
+                                                        start_frame=np.sqrt(17),
                                                         end_frame=2,
                                                         xmin=univ.atoms.positions[...,0].min(),
                                                         xmax=univ.atoms.positions[...,0].max(),

So yeah, definitely some issues here. Not sure that Lily should be burdened with fixing them all at this time, but definitely good to have issue(s) open so folks can be aware.

tylerjereddy avatar Apr 07 '24 21:04 tylerjereddy

@tylerjereddy is this bug something you could fix?

orbeckst avatar May 08 '24 06:05 orbeckst

Probably, it sounds like Lily may fix it during the refactor to AnalysisBase in any case though.

tylerjereddy avatar May 08 '24 15:05 tylerjereddy