Skip to content

Commit

Permalink
Add tol parameter to lammps.extract_u_nk for case where rounding erro…
Browse files Browse the repository at this point in the history
…rs are greater than machine precision
  • Loading branch information
jaclark5 committed Feb 9, 2025
1 parent 243b5c8 commit 1c301a8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/alchemlyb/parsing/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ def extract_u_nk(
column_volume=6,
prec=4,
force=False,
tol=None,
):
"""Return reduced potentials `u_nk` from LAMMPS dump file(s).
Expand Down Expand Up @@ -566,6 +567,10 @@ def extract_u_nk(
Number of decimal places defined used in ``round()`` function.
force : bool, default=False
If ``True`` the dataframe will be created, even if not all lambda and lambda prime combinations are available.
tol : float, default=None
Tolerance in checking that the difference between lambda and lambda' states is zero. If None, this tolerance is set
to ``np.finfo(float).eps``. Take care in increasing this value! It's more likely that something is wrong with your
column indexing.
Results
-------
Expand All @@ -582,6 +587,9 @@ def extract_u_nk(
"""

if tol is None:
tol = np.finfo(float).eps

# Collect Files
if isinstance(fep_files, list):
files = fep_files
Expand Down Expand Up @@ -778,10 +786,10 @@ def extract_u_nk(
lambda1, lambda12
)
)
if lambda1 == lambda12 and not np.all(tmp_df2["dU_nk"][0] == 0):
if lambda1 == lambda12 and not np.all(tmp_df2["dU_nk"][0] <= tol):
raise ValueError(
f"The difference in dU should be zero when lambda = lambda', {lambda1} = {lambda12},"
" Check that 'column_dU' was defined correctly."
f"The difference in dU should be zero when lambda = lambda', {lambda1} = {lambda12}, not "
f"{np.max(tmp_df2['dU_nk'][0])}. Check that 'column_dU' was defined correctly or increase `tol`"
)

if (
Expand Down

0 comments on commit 1c301a8

Please sign in to comment.