Skip to content

Commit

Permalink
handle indices in parseScipionModes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Oct 16, 2023
1 parent 93535f0 commit f885662
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions prody/dynamics/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,37 @@ def parseScipionModes(metadata_file, title=None, pdb=None):
vectors = np.zeros((dof, n_modes))
vectors[:, 0] = mode1

eigvals = np.zeros(n_modes)
eigvals = {}
indices = []

try:
eigvals[0] = float(row1['_nmaEigenval'])
indices.append(int(row1['_order_'])-1)
found_indices = True
except KeyError:
found_indices = False

try:
if found_indices:
eigvals[indices[0]] = float(row1['_nmaEigenval'])
else:
eigvals[0] = float(row1['_nmaEigenval'])
found_eigvals = True
except:
except KeyError:
found_eigvals = False

for i, row in enumerate(star_loop[1:]):
vectors[:, i+1] = parseArray(top_dirs + row['_nmaModefile']).reshape(-1)
if found_eigvals:
if found_eigvals and not found_indices:
eigvals[i+1] = float(row['_nmaEigenval'])
if found_indices:
index = int(row['_order_'])-1
indices.append(index)
if found_eigvals:
eigvals[index] = float(row['_nmaEigenval'])

if not found_eigvals:
log_fname = run_path + '/logs/run.stdout'
fi = open(log_fname, 'r')
logFileName = run_path + '/logs/run.stdout'
fi = open(logFileName, 'r')
lines = fi.readlines()
fi.close()

Expand All @@ -435,7 +450,22 @@ def parseScipionModes(metadata_file, title=None, pdb=None):
else:
nma = GNM(title)

nma.setEigens(vectors, eigvals)
nma.setEigens(vectors, np.array(list(eigvals.values())))

if found_indices:
n_modes = np.max(indices) + 1
vectors2 = np.ones((dof, n_modes))
eigvals2 = np.ones((n_modes))

for i, index in enumerate(indices):
vectors2[:, index] = vectors[:, i]
eigvals2[index] = eigvals[index]

nma2 = type(nma)(title)
nma2.setEigens(vectors2, eigvals2)

nma = nma2[indices]

return nma


Expand Down Expand Up @@ -495,7 +525,7 @@ def writeScipionModes(output_path, modes, write_star=False, scores=None,
raise TypeError('collectivityThreshold should be float, not {0}'
.format(type(collectivityThreshold)))

if modes.numModes() == 1 and not isinstance(modes, NMA):
if modes.numModes() == 1 and not isinstance(modes, (NMA, ModeSet)):
old_modes = modes
modes = NMA(old_modes)
modes.setEigens(old_modes.getArray().reshape(-1, 1))
Expand Down

0 comments on commit f885662

Please sign in to comment.