|
1 | | -__all__ = ["Dynamics"] |
| 1 | +__all__ = ["Dynamics": |
2 | 2 |
|
3 | 3 |
|
4 | 4 | class DynamicsData: |
@@ -475,7 +475,8 @@ def _exit_dynamics_block( |
475 | 475 | nrg += self._pressure * volume |
476 | 476 | if excess_chemical_potential is not None: |
477 | 477 | nrg += excess_chemical_potential * num_waters |
478 | | - nrgs[f"{sim_lambda_value:.5f}"] = nrg * kcal_per_mol |
| 478 | + # Store the potential energy for the current lambda value. |
| 479 | + nrg_sim_lambda_value = nrg |
479 | 480 |
|
480 | 481 | if lambda_windows is not None: |
481 | 482 | # get the index of the simulation lambda value in the |
@@ -510,6 +511,10 @@ def _exit_dynamics_block( |
510 | 511 | nrgs[key] = nrg * kcal_per_mol |
511 | 512 | else: |
512 | 513 | nrgs[key] = null_energy * kcal_per_mol |
| 514 | + else: |
| 515 | + nrgs[f"{sim_lambda_value:.5f}"] = ( |
| 516 | + nrg_sim_lambda_value * kcal_per_mol |
| 517 | + ) |
513 | 518 |
|
514 | 519 | self._omm_mols.set_lambda( |
515 | 520 | sim_lambda_value, |
@@ -865,12 +870,15 @@ def current_kinetic_energy(self): |
865 | 870 | def energy_trajectory(self): |
866 | 871 | return self._energy_trajectory.clone() |
867 | 872 |
|
868 | | - def current_energies(self): |
| 873 | + def current_energies(self, sort: bool = False): |
869 | 874 | try: |
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 |
| 875 | + if sort: |
| 876 | + nrgs = self._nrgs.copy() |
| 877 | + sorted_items = sorted(list(nrgs.items())[2:], key=lambda x: x[0]) |
| 878 | + nrgs = dict(list(nrgs.items())[:2] + sorted_items) |
| 879 | + return nrgs |
| 880 | + else: |
| 881 | + return self._nrgs |
874 | 882 | except Exception: |
875 | 883 | return {} |
876 | 884 |
|
@@ -2208,11 +2216,12 @@ def energy_trajectory(self, to_pandas: bool = False, to_alchemlyb: bool = False) |
2208 | 2216 | else: |
2209 | 2217 | return t |
2210 | 2218 |
|
2211 | | - def current_energies(self): |
| 2219 | + def current_energies(self, sort: bool = False): |
2212 | 2220 | """ |
2213 | 2221 | Return a dictionary of the most recent energy trajectory entry. |
| 2222 | + If 'sort' is True, then the dictionary will be sorted by key. |
2214 | 2223 | """ |
2215 | | - return self._d.current_energies() |
| 2224 | + return self._d.current_energies(sort=sort) |
2216 | 2225 |
|
2217 | 2226 | def to_xml(self, f=None): |
2218 | 2227 | """ |
|
0 commit comments