From cb84a99e61684137ca6cc502e661d6a8f95a4b28 Mon Sep 17 00:00:00 2001 From: Jonathan Barnoud Date: Mon, 29 Jun 2020 17:05:18 +0100 Subject: [PATCH 1/2] Make the TPR parser a bit faster A function in the TPR parser calls list.pop thousands of times, which is slow. This commit avoids that exansive call. Taking the TPR from https://github.com/bioexcel/covid_modelling_simulation_data/tree/master/spike_protein/full_spike/trimer the parsing time on my computer goes from 25.6s to 9.39s. On a more pathological TPR file, it goes from 3 minutes to about 6s. --- package/MDAnalysis/topology/tpr/obj.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/package/MDAnalysis/topology/tpr/obj.py b/package/MDAnalysis/topology/tpr/obj.py index b14f5bd5198..eabe4c6e694 100644 --- a/package/MDAnalysis/topology/tpr/obj.py +++ b/package/MDAnalysis/topology/tpr/obj.py @@ -125,10 +125,7 @@ def __init__(self, name, long_name, natoms): self.natoms = natoms def process(self, atom_ndx): - while atom_ndx: - # format for all info: (type, [atom1, atom2, ...]) - # yield atom_ndx.pop(0), [atom_ndx.pop(0) for i in range(self.natoms)] - - # but currently only [atom1, atom2, ...] is interested - atom_ndx.pop(0) - yield [atom_ndx.pop(0) for i in range(self.natoms)] + # The format for all record is (type, atom1, atom2, ...) + # but we are only interested in the atoms. + for cursor in range(0, len(atom_ndx), self.natoms + 1): + yield atom_ndx[cursor + 1: cursor + 1 + self.natoms] From 174dd400375aeb4dc5798dadf8ed0421a200f80d Mon Sep 17 00:00:00 2001 From: Jonathan Barnoud Date: Mon, 29 Jun 2020 17:16:09 +0100 Subject: [PATCH 2/2] Update changelog for #2804 --- package/CHANGELOG | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index a0aea381aac..d3b93a24e16 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -13,7 +13,8 @@ The rules for this file: * release numbers follow "Semantic Versioning" http://semver.org ------------------------------------------------------------------------------ -??/??/?? richardjgowers, IAlibay, hmacdope, orbeckst, cbouy, lilyminium +??/??/?? richardjgowers, IAlibay, hmacdope, orbeckst, cbouy, lilyminium, + jbarnoud * 2.0.0 @@ -32,6 +33,7 @@ Enhancements token (Issue #2468, PR #2707) * Added the `from_smiles` classmethod to the Universe (Issue #2468, PR #2707) * Added computation of Mean Squared Displacements (#2438, PR #2619) + * Improved performances when parsing TPR files (PR #2804) Changes * Changes development status from Beta to Mature (Issue #2773)