Skip to content

Fix writeNMD residue number overflow for large systems (>9999 residues)#2245

Merged
jamesmkrieger merged 2 commits into
mainfrom
copilot/fix-system-size-limitation
Jul 19, 2026
Merged

Fix writeNMD residue number overflow for large systems (>9999 residues)#2245
jamesmkrieger merged 2 commits into
mainfrom
copilot/fix-system-size-limitation

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

NMWiz reads resids from NMD files and writes a temporary PDB for VMD to load. The PDB format allocates 4 characters (columns 23–26) for residue sequence numbers, so any value ≥ 10000 overflows into adjacent coordinate columns, causing VMD to misparse atom positions — manifesting as atoms "stretched along a line" or collapsed into a plane.

Change

  • prody/dynamics/nmdfile.pywriteNMD: Before writing resids, check max(resnums) > 9999. If exceeded, renumber residues per-chain sequentially starting from 1 (wrapping modulo 9999), and emit a warning. Systems with all residue numbers ≤ 9999 are unaffected.
# Large phage system with 20,412 Cα atoms — residue numbers go up to 20412
writeNMD('anm_modes.nmd', anm[:5], phage.select('calpha'))
# @> WARNING Residue numbers exceed 9999. Renumbering residues in NMD output
#    to be compatible with NMWiz/VMD PDB format (max 9999 per chain).
# Previously: NMWiz would place ~half the atoms at wrong coordinates in VMD
# Now: all atoms render at their correct positions

The renumbering is per-chain so that multi-chain systems (e.g. viral capsids with many subunits, each ≤ 9999 residues) preserve intra-chain relative ordering. The original residue numbers are preserved in the in-memory AtomGroup; only the NMD file output is affected.

Copilot AI changed the title [WIP] Fix system size limitation in writeNMD and NMWiz Fix writeNMD residue number overflow for large systems (>9999 residues) Jul 13, 2026
Copilot AI requested a review from jamesmkrieger July 13, 2026 07:32
@jamesmkrieger
jamesmkrieger marked this pull request as ready for review July 16, 2026 11:29

@karolamik13 karolamik13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked. See below.

The old code:
$ python test.py
@> Connecting wwPDB FTP server RCSB PDB (USA).
@> Downloading PDB files via FTP failed, trying HTTP.
@> 1tqn downloaded (1tqn.pdb.gz)
@> PDB download via HTTP completed (1 downloaded, 0 failed).
@> 468 atoms and 1 coordinate set(s) were parsed in 0.03s.
@> Hessian was built in 0.28s.
@> 5 modes were calculated in 0.15s.

$ grep '^resids' 1tqn_large_resids.nmd | head
resids 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047

New code:
$ python test.py
@> PDB file is found in working directory (1tqn.pdb.gz).
@> 468 atoms and 1 coordinate set(s) were parsed in 0.01s.
@> Hessian was built in 0.21s.
@> 5 modes were calculated in 0.13s.

$ grep '^resids' 1tqn_large_resids.nmd | head
resids 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

test.py looks like this:

from prody import *
ca = parsePDB('1tqn', subset='ca')
original_resnums = ca.getResnums()
ca.setResnums(original_resnums + 10000)
anm = calcANM(ca, n_modes=5)[0]
writeNMD('1tqn_large_resids.nmd', anm[:5], ca)

@jamesmkrieger

Copy link
Copy Markdown
Contributor

What happens when you open the nmd file? Does the original give the strange behaviour of atoms on a line and the fixed one not?

@jamesmkrieger

Copy link
Copy Markdown
Contributor

Yes, I confirm it works.

On main, your code gives this
image

On the fix branch, we get this
image

@jamesmkrieger
jamesmkrieger merged commit 2fcbae9 into main Jul 19, 2026
12 checks passed
@jamesmkrieger
jamesmkrieger deleted the copilot/fix-system-size-limitation branch July 19, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System size limitation in writeNMD and/or NMWiz

3 participants