From 0c4f6567ac0f2e0a390b6fea1e972b58119f942a Mon Sep 17 00:00:00 2001 From: James Krieger Date: Thu, 10 Mar 2022 13:18:07 +0000 Subject: [PATCH] norm option in writeScipionModes for defvec fix --- prody/dynamics/functions.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/prody/dynamics/functions.py b/prody/dynamics/functions.py index 5d7bbd2b7..f876ab0fb 100644 --- a/prody/dynamics/functions.py +++ b/prody/dynamics/functions.py @@ -381,7 +381,7 @@ def parseScipionModes(run_path, title=None): def writeScipionModes(output_path, modes, write_star=False, scores=None, - only_sqlite=False, collectivityThreshold=0.): + only_sqlite=False, collectivityThreshold=0., norm=True): """Writes *modes* to a set of files that can be recognised by Scipion. A directory called **"modes"** will be created if it doesn't already exist. Filenames inside will start with **"vec"** and have the mode number as the extension. @@ -407,6 +407,10 @@ def writeScipionModes(output_path, modes, write_star=False, scores=None, :arg collectivityThreshold: collectivity threshold below which modes are not enabled Default is 0. :type collectivityThreshold: float + + :arg norm: whether to normalize mode vectors before calculating collectivities + Default is **True** + :type norm: bool """ if not isinstance(output_path, str): raise TypeError('output_path should be a string, not {0}' @@ -438,6 +442,10 @@ def writeScipionModes(output_path, modes, write_star=False, scores=None, raise TypeError('collectivityThreshold should be float, not {0}' .format(type(collectivityThreshold))) + if not isinstance(norm, bool): + raise TypeError('norm should be boolean, not {0}' + .format(type(norm))) + if modes.numModes() == 1 and not isinstance(modes, NMA): old_modes = modes modes = NMA(old_modes) @@ -457,6 +465,12 @@ def writeScipionModes(output_path, modes, write_star=False, scores=None, modefiles.append(writeArray(modes_dir + 'vec.{0}'.format(mode_num), mode.getArray(), '%12.4e', '')) + if norm: + eigvecs = modes.getEigvecs() + eigvecs /= np.array([((evecs[:, i]) ** 2).sum() ** 0.5 + for i in range(evecs.shape[1])]) + modes.setEigens(eigvecs, eigvals) + if modes.numModes() > 1: order = modes.getIndices() collectivities = list(calcCollectivity(modes))