Skip to content

Commit 2fcbae9

Browse files
Merge pull request #2245 from prody/copilot/fix-system-size-limitation
Fix writeNMD residue number overflow for large systems (>9999 residues)
2 parents 2c9efde + 164a3d0 commit 2fcbae9

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

prody/dynamics/nmdfile.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,40 @@ def writeNMD(filename, modes, atoms):
422422
try:
423423
data = atoms.getResnums()
424424
if data is not None:
425+
if data.max() > 9999:
426+
LOGGER.warn('Residue numbers exceed 9999. Renumbering residues '
427+
'in NMD output to be compatible with NMWiz/VMD PDB '
428+
'format (max 9999 per chain).')
429+
try:
430+
chids = atoms.getChids()
431+
except Exception:
432+
chids = None
433+
new_data = np.empty_like(data)
434+
if chids is not None:
435+
for chid in np.unique(chids):
436+
mask = (chids == chid)
437+
chain_resnums = data[mask]
438+
unique_res = {}
439+
counter = 0
440+
for r in chain_resnums:
441+
if r not in unique_res:
442+
counter += 1
443+
unique_res[r] = (counter - 1) % 9999 + 1
444+
new_data[mask] = np.array([unique_res[r]
445+
for r in chain_resnums])
446+
else:
447+
unique_res = {}
448+
counter = 0
449+
for i, r in enumerate(data):
450+
if r not in unique_res:
451+
counter += 1
452+
unique_res[r] = (counter - 1) % 9999 + 1
453+
new_data[i] = unique_res[r]
454+
data = new_data
425455
out.write('resids ')
426456
data.tofile(out, ' ')
427457
out.write('\n')
428-
except:
458+
except Exception:
429459
pass
430460
try:
431461
data = atoms.getChids()

0 commit comments

Comments
 (0)