From dee4b7425ccc814f8d882c8e73048646545eb6b1 Mon Sep 17 00:00:00 2001 From: Fabian Zills <46721498+PythonFZ@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:32:34 +0100 Subject: [PATCH] fix IndexError --- znh5md/znh5md/h5ase.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/znh5md/znh5md/h5ase.py b/znh5md/znh5md/h5ase.py index edfb161..a87bfe4 100644 --- a/znh5md/znh5md/h5ase.py +++ b/znh5md/znh5md/h5ase.py @@ -17,11 +17,15 @@ def _gather_value(particles_data, key, idx): Returns None if the key is not present in the data. """ - if key in particles_data: - if key in [GRP.species, GRP.position, GRP.velocity, GRP.forces, GRP.momentum]: - # use PARTICLES_GRP - return rm_nan(particles_data[key][idx]) - return particles_data[key][idx] + try: + if key in particles_data: + if key in [GRP.species, GRP.position, GRP.velocity, GRP.forces, GRP.momentum]: + # use PARTICLES_GRP + return rm_nan(particles_data[key][idx]) + return particles_data[key][idx] + except IndexError: + # a property might not be available at all frames. + pass return None