Skip to content

Commit

Permalink
Ensure that atom-pairs are always sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas van Beek committed Jan 22, 2020
1 parent c5b38c6 commit ed5acd5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions FOX/functions/cp2k_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,22 @@ def set_keys(settings: Settings, param: pd.DataFrame) -> None:

param['keys'] = key_list
param['param'] = param['param'].astype(float)
param.index = _sort_index(param.index)
_populate_keys(settings, param)


def _sort_index(index: pd.MultiIndex) -> pd.MultiIndex:
ret = []
for i, j in index:
j_split = j.split()
if len(j_split) == 2:
ret.append((i, ' '.join(k for k in sorted(j_split))))
else:
ret.append((i, j))

return pd.MultiIndex.from_tuples(ret, names=index.names)


def _populate_keys(settings: Settings, param: pd.DataFrame) -> None:
"""Populate the settings blocks specified in :func:`.set_keys`.
Expand Down

0 comments on commit ed5acd5

Please sign in to comment.