mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

PCA not showing progress bar on mean structure calculation

Open rsexton2 opened this issue 3 years ago • 2 comments

Expected behavior

Progress bar should be shown when computing mean structure for PCA when verbose=True.

Actual behavior

Progress bar is shown for PCA calculation but not for mean structure calculation.

Code to reproduce the behavior

import MDAnalysis as mda
import MDAnalysis.analysis.pca as pca
from MDAnalysis.tests.datafiles import PSF, DCD
u = mda.Universe(PSF, DCD)
PSF_pca = pca.PCA(u, select='backbone')
PSF_pca.run(verbose=True)

Current version of MDAnalysis

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

rsexton2 avatar Aug 05 '22 18:08 rsexton2

Progress bar is shown for mean structure calculation when verbose=True is passed to the class constructor

PSF_pca = pca.PCA(u, select='backbone', verbose=True)

rsexton2 avatar Aug 05 '22 18:08 rsexton2

It would also be convenient for PCA.transform() to take a verbose flag because it takes a long time to complete

rsexton2 avatar Aug 05 '22 19:08 rsexton2

Hi @rsexton2 and @orbeckst , I took the liberty of creating a small PR implementing the requested fix : please let me know if this helps and if it's correct?

This is also my first proper open-source contribution, very happy to edit/mend/read more things!

Sampurna

SampurnaM avatar Mar 25 '24 16:03 SampurnaM

As per comments in #4531 :)

Screenshots attached to show how the progress bar looks now, for PCA.transform():

Current version of MDAnalysis

Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.version)") 2.8.0-dev0 Which version of Python (python -V)? Python 3.12.2 Which operating system? Ubuntu 20.04.6 LTS

Code to reproduce the behavior

import MDAnalysis as mda
import MDAnalysis.analysis.pca as pca
from MDAnalysis.tests.datafiles import PSF, DCD
u = mda.Universe(PSF, DCD)
PSF_pca = pca.PCA(u, select='backbone')
PSF_pca.run(verbose=True)
n_pcs = np.where(PSF_pca.results.cumulated_variance > 0.95)[0][0]
atomgroup = u.select_atoms('backbone')
pca_space = PSF_pca.transform(atomgroup, n_components=n_pcs, verbose=True)

image

Testing the function logic in JupyterLab for the older MDA 2.7.0 version, in a different environment

Current version of MDAnalysis

Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.version)") 2.7.0 Which version of Python (python -V)? Python 3.10.8 Which operating system? Ubuntu 20.04.6 LTS

image

SampurnaM avatar Mar 26 '24 15:03 SampurnaM

For completeness, can you also demonstrate

pca_space = PSF_pca.transform(atomgroup, n_components=n_pcs, verbose=True)

in a notebook, please?

orbeckst avatar Mar 26 '24 16:03 orbeckst

Here it is.

Note:

JupyterLab version: 4.1.5 For using tqdm , I had to install ipywidgets in mdanalysis-dev environment and jupyterlab-widgets in the base !conda install -n base -c conda-forge jupyterlab_widgets !conda install -n mdanalysis-dev -c conda-forge ipywidgets

image

SampurnaM avatar Mar 27 '24 10:03 SampurnaM