PCA not showing progress bar on mean structure calculation
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
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)
It would also be convenient for PCA.transform() to take a verbose flag because it takes a long time to complete
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
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)
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
For completeness, can you also demonstrate
pca_space = PSF_pca.transform(atomgroup, n_components=n_pcs, verbose=True)
in a notebook, please?
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