Skip to content

Commit

Permalink
Move environments sorting out of condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiia-chorna committed Sep 4, 2024
1 parent 313233d commit cd02b9d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions python/chemiscope/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ 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(
"Some or more indices are greater than the length of the frames"
)

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]

Expand Down

0 comments on commit cd02b9d

Please sign in to comment.