Skip to content

Commit

Permalink
Merge pull request #1552 from jamesmkrieger/pca_missed_quiet
Browse files Browse the repository at this point in the history
add missed quiet check
  • Loading branch information
jamesmkrieger authored May 17, 2022
2 parents 9bc18a2 + a257f98 commit 45cd0d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
11 changes: 5 additions & 6 deletions prody/apps/prody_apps/prody_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def prody_pca(coords, **kwargs):
prefix = kwargs.get('prefix')
nmodes = kwargs.get('nmodes')
selstr = kwargs.get('select')
quiet = kwargs.pop('quiet', False)
altloc = kwargs.get('altloc')

ext = splitext(coords)[1].lower()
Expand Down Expand Up @@ -96,11 +95,11 @@ def prody_pca(coords, **kwargs):
raise ImportError('Please install threadpoolctl to control threads')

with threadpool_limits(limits=nproc, user_api="blas"):
pca.buildCovariance(dcd, aligned=kwargs.get('aligned'), quiet=quiet)
pca.buildCovariance(dcd, aligned=kwargs.get('aligned'))
pca.calcModes(nmodes)
ensemble = dcd
else:
pca.buildCovariance(dcd, aligned=kwargs.get('aligned'), quiet=quiet)
pca.buildCovariance(dcd, aligned=kwargs.get('aligned'))
pca.calcModes(nmodes)
ensemble = dcd

Expand Down Expand Up @@ -133,10 +132,10 @@ def prody_pca(coords, **kwargs):
raise ImportError('Please install threadpoolctl to control threads')

with threadpool_limits(limits=nproc, user_api="blas"):
pca.buildCovariance(ensemble, aligned=kwargs.get('aligned'), quiet=quiet)
pca.buildCovariance(ensemble, aligned=kwargs.get('aligned'))
pca.calcModes(nmodes)
else:
pca.buildCovariance(ensemble, aligned=kwargs.get('aligned'), quiet=quiet)
pca.buildCovariance(ensemble, aligned=kwargs.get('aligned'))
pca.calcModes(nmodes)

LOGGER.info('Writing numerical output.')
Expand Down Expand Up @@ -269,7 +268,7 @@ def addCommand(commands):
subparser = commands.add_parser('pca',
help='perform principal component analysis calculations')

subparser.add_argument('--quiet', help="suppress info messages to stderr",
subparser.add_argument('--quiet', help='suppress info messages to stderr',
action=Quiet, nargs=0)

subparser.add_argument('--examples', action=UsageExample, nargs=0,
Expand Down
21 changes: 13 additions & 8 deletions prody/dynamics/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ def buildCovariance(self, coordsets, **kwargs):
if n_atoms < 3:
raise ValueError('coordsets must have more than 3 atoms')
dof = n_atoms * 3
LOGGER.info('Covariance is calculated using {0} coordinate sets.'
.format(len(coordsets)))
if not quiet:
LOGGER.info('Covariance is calculated using {0} coordinate sets.'
.format(len(coordsets)))
s = (n_confs, dof)
if weights is None:
if coordsets.dtype == float:
Expand All @@ -158,13 +159,16 @@ def buildCovariance(self, coordsets, **kwargs):
cov = np.zeros((dof, dof))
coordsets = coordsets.reshape((n_confs, dof))
mean = coordsets.mean(0)
LOGGER.progress('Building covariance', n_confs,
if not quiet:
LOGGER.progress('Building covariance', n_confs,
'_prody_pca')
for i, coords in enumerate(coordsets.reshape(s)):
deviations = coords - mean
cov += np.outer(deviations, deviations)
LOGGER.update(n_confs, label='_prody_pca')
LOGGER.finish()
if not quiet:
LOGGER.update(n_confs, label='_prody_pca')
if not quiet:
LOGGER.finish()
cov /= n_confs
self._cov = cov
else:
Expand All @@ -185,7 +189,8 @@ def buildCovariance(self, coordsets, **kwargs):
self._trace = self._cov.trace()
self._dof = dof
self._n_atoms = n_atoms
LOGGER.report('Covariance matrix calculated in %2fs.', '_prody_pca')
if not quiet:
LOGGER.report('Covariance matrix calculated in %2fs.', '_prody_pca')

def calcModes(self, n_modes=20, turbo=True):
"""Calculate principal (or essential) modes. This method uses
Expand Down Expand Up @@ -255,10 +260,10 @@ def performSVD(self, coordsets):
coordsets._getCoords())

n_confs = deviations.shape[0]
if n_confs < 3:
if n_confs <= 3:
raise ValueError('coordsets must have more than 3 coordinate sets')
n_atoms = deviations.shape[1]
if n_atoms < 3:
if n_atoms <= 3:
raise ValueError('coordsets must have more than 3 atoms')

dof = n_atoms * 3
Expand Down
3 changes: 2 additions & 1 deletion prody/utilities/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def progress(self, msg, steps, label=None, **kwargs):

if not hasattr(self, '_verb'):
self._verb = self._getverbosity()
self._setverbosity('progress')
if self._level < logging.WARNING:
self._setverbosity('progress')
self._n_progress += 1

def update(self, step, msg=None, label=None):
Expand Down

0 comments on commit 45cd0d8

Please sign in to comment.