Skip to content

Commit 9a2cd43

Browse files
authored
Improved PDBWriter performance using range & caching (#4472)
* Improvements to PDBWriter's performance
1 parent 8df5115 commit 9a2cd43

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

package/CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The rules for this file:
1515

1616
-------------------------------------------------------------------------------
1717
??/??/?? IAlibay, HeetVekariya, marinegor, lilyminium, RMeli,
18-
ljwoods2, aditya292002, pstaerk, PicoCentauri
18+
ljwoods2, aditya292002, pstaerk, PicoCentauri, BFedder
1919

2020
* 2.8.0
2121

@@ -32,6 +32,7 @@ Fixes
3232
* Fix deploy action to use the correct version of the pypi upload action.
3333

3434
Enhancements
35+
* Improved performance of PDBWriter (Issue #2785, PR #4472)
3536
* Added parsing of arbitrary columns of the LAMMPS dump parser. (Issue #3504)
3637
* Documented the r0 attribute in the `Contacts` class and added the
3738
`n_initial_contacts` attribute, with documentation. (Issue #2604, PR #4415)

package/MDAnalysis/coordinates/PDB.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
import logging
150150
import collections
151151
import numpy as np
152+
import functools
152153

153154
from ..lib import util
154155
from ..lib.util import store_init_arguments
@@ -1028,6 +1029,7 @@ def _write_next_frame(self, ts=None, **kwargs):
10281029
self._check_pdb_coordinates()
10291030
self._write_timestep(ts, **kwargs)
10301031

1032+
@functools.cache
10311033
def _deduce_PDB_atom_name(self, atomname, resname):
10321034
"""Deduce how the atom name should be aligned.
10331035
@@ -1217,7 +1219,7 @@ def validate_chainids(chainids, default):
12171219
else:
12181220
atom_ids = np.arange(len(atoms)) + 1
12191221

1220-
for i, atom in enumerate(atoms):
1222+
for i in range(len(atoms)):
12211223
vals = {}
12221224
vals['serial'] = util.ltruncate_int(atom_ids[i], 5) # check for overflow here?
12231225
vals['name'] = self._deduce_PDB_atom_name(atomnames[i], resnames[i])

0 commit comments

Comments
 (0)