Skip to content

Commit de8bbf8

Browse files
committed
Sort energies by lambda.
1 parent 05ca87c commit de8bbf8

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/sire/mol/_dynamics.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def _exit_dynamics_block(
475475
nrg += self._pressure * volume
476476
if excess_chemical_potential is not None:
477477
nrg += excess_chemical_potential * num_waters
478-
nrgs[str(sim_lambda_value)] = nrg * kcal_per_mol
478+
nrgs[f"{sim_lambda_value:.5f}"] = nrg * kcal_per_mol
479479

480480
if lambda_windows is not None:
481481
# get the index of the simulation lambda value in the
@@ -494,6 +494,7 @@ def _exit_dynamics_block(
494494
not has_lambda_index
495495
or abs(lambda_index - i) <= num_energy_neighbours
496496
):
497+
key = f"{lambda_value:.5f}"
497498
self._omm_mols.set_lambda(
498499
lambda_value,
499500
rest2_scale=rest2_scale,
@@ -506,9 +507,9 @@ def _exit_dynamics_block(
506507
nrg += self._pressure * volume
507508
if excess_chemical_potential is not None:
508509
nrg += excess_chemical_potential * num_waters
509-
nrgs[str(lambda_value)] = nrg * kcal_per_mol
510+
nrgs[key] = nrg * kcal_per_mol
510511
else:
511-
nrgs[str(lambda_value)] = null_energy * kcal_per_mol
512+
nrgs[key] = null_energy * kcal_per_mol
512513

513514
self._omm_mols.set_lambda(
514515
sim_lambda_value,
@@ -866,7 +867,10 @@ def energy_trajectory(self):
866867

867868
def current_energies(self):
868869
try:
869-
return self._nrgs
870+
# Sort the energies by key to ensure consistent ordering.
871+
nrgs = self._nrgs.copy()
872+
nrgs = dict(sorted(nrgs.items(), key=lambda item: item[0]))
873+
return nrgs
870874
except Exception:
871875
return {}
872876

0 commit comments

Comments
 (0)