Skip to content

Commit

Permalink
Improve the performance of ParmEd converter. (Fix MDAnalysis#3028) (M…
Browse files Browse the repository at this point in the history
…DAnalysis#3029)

Fixes MDAnalysis#3028

* Improves the performance of the ParmEd converter by using a dictionary lookup for the atomgroup to universe index mapping.
  • Loading branch information
HanatoK authored and lilyminium committed Dec 14, 2020
1 parent 7f83f4a commit a64eed9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Chronological list of authors
- Marcello Sega
- Nicholas Craven
- Ramon Crehuet
- Haochuan Chen

External code
-------------
Expand Down
3 changes: 2 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The rules for this file:
------------------------------------------------------------------------------
??/??/20 richardjgowers, IAlibay, orbeckst, tylerjereddy, jbarnoud,
yuxuanzhuang, lilyminium, VOD555, p-j-smith, bieniekmateusz,
calcraven, ianmkenney, rcrehuet, manuel.nuno.melo
calcraven, ianmkenney, rcrehuet, manuel.nuno.melo, hanatok

* 1.0.1

Expand Down Expand Up @@ -50,6 +50,7 @@ Fixes
(Issue #2934)

Enhancements
* Improved performance of the ParmEd converter (Issue #3028, PR #3029)
* Improved performances when parsing TPR files (PR #2804)

Changes (not affecting users)
Expand Down
6 changes: 4 additions & 2 deletions package/MDAnalysis/coordinates/ParmEd.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _read_first_frame(self):
}

def get_indices_from_subset(i, atomgroup=None, universe=None):
return atomgroup.index(universe.atoms[i])
return atomgroup[universe.atoms[i]]

class ParmEdConverter(base.ConverterBase):
"""Convert MDAnalysis AtomGroup or Universe to ParmEd :class:`~parmed.structure.Structure`.
Expand Down Expand Up @@ -263,8 +263,10 @@ def convert(self, obj):
struct.box = None

if hasattr(ag_or_ts, 'universe'):
atomgroup = {atom: index for index,
atom in enumerate(list(ag_or_ts))}
get_atom_indices = functools.partial(get_indices_from_subset,
atomgroup=list(ag_or_ts),
atomgroup=atomgroup,
universe=ag_or_ts.universe)
else:
get_atom_indices = lambda x: x
Expand Down

0 comments on commit a64eed9

Please sign in to comment.