From cd02b9d5fbd398513d159097db85c03914bab453 Mon Sep 17 00:00:00 2001 From: Sofiia Chorna Date: Wed, 4 Sep 2024 14:58:33 +0200 Subject: [PATCH] Move environments sorting out of condition --- python/chemiscope/explore.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/chemiscope/explore.py b/python/chemiscope/explore.py index ff6fc48db..6a882b3ae 100644 --- a/python/chemiscope/explore.py +++ b/python/chemiscope/explore.py @@ -111,6 +111,10 @@ def soap_kpca_featurize(frames, environments): # Pick frames and properties related to the environments if provided if environments is not None: + # Sort environments by structure id and atom id + environments = sorted(environments, key=lambda x: (x[0], x[1])) + + # Check structure indexes unique_structures = list({env[0] for env in environments}) if any(index >= len(frames) for index in unique_structures): raise IndexError( @@ -118,9 +122,6 @@ def soap_kpca_featurize(frames, environments): ) if len(unique_structures) != len(frames): - # Sort environments by structure id and atom id - environments = sorted(environments, key=lambda x: (x[0], x[1])) - # Pick frames corresponding to the environments frames = [frames[index] for index in unique_structures]