Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writeScipion option norm to normalise #1936

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion prody/dynamics/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def parseScipionModes(metadata_file, title=None, pdb=None, parseIndices=False):


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.
Expand All @@ -538,6 +538,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}'
Expand Down Expand Up @@ -567,6 +571,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, ModeSet)):
old_modes = modes
modes = NMA(old_modes)
Expand All @@ -586,6 +594,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))
Expand Down
Loading