Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError will be raised if concatenated amber output file has been ingested #326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The rules for this file:
* 2.1.0

Changes
- ValueError raised if concatenated amber output file is passed to amber
parser (issue #315, PR #326).
- Change the % based string formatting to {} based string formatting (issue #323, PR #324).
- Use loguru instead of logging for log (issue #301, PR #303).

Expand Down
9 changes: 8 additions & 1 deletion src/alchemlyb/parsing/amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,18 @@ def extract(outfile, T):
"^ NSTEP", "^ ---", ["NSTEP", "DV/DL"], extra=line
)
if nstep != old_nstep and dvdl is not None and nstep is not None:
if finished:
raise ValueError(
"TI Energy detected after the TIMINGS section. Did you concatenate the output file?"
)
file_datum.gradients.append(dvdl)
nensec += 1
old_nstep = nstep
elif line.startswith("MBAR Energy analysis") and file_datum.have_mbar:
if finished:
raise ValueError(
"MBAR Energy detected after the TIMINGS section. Did you concatenate the output file?"
)
mbar = secp.extract_section(
"^MBAR", "^ ---", file_datum.mbar_lambdas, extra=line
)
Expand All @@ -356,7 +364,6 @@ def extract(outfile, T):
)
elif line == " 5. TIMINGS\n":
finished = True
break

if high_E_cnt:
logger.warning(
Expand Down
33 changes: 33 additions & 0 deletions src/alchemlyb/tests/parsing/test_amber.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Amber parser tests.

"""
import bz2
import logging

import pandas as pd
Expand Down Expand Up @@ -250,3 +251,35 @@ def test_u_nk_improper(improper_filename, names=("time", "lambdas")):
assert u_nk.index.names == names
except Exception:
assert "0.5626" in improper_filename


def test_concatenated_amber_u_nk(tmp_path):
with bz2.open(load_bace_example()["data"]["complex"]["decharge"][0], "rt") as file:
content = file.read()

with open(tmp_path / "amber.out", "w") as f:
f.write(content)
f.write("\n")
f.write(content)

with pytest.raises(
ValueError,
match="MBAR Energy detected after the TIMINGS section.",
):
extract(tmp_path / "amber.out", 298)


def test_concatenated_amber_dhdl(tmp_path):
with bz2.open(load_bace_example()["data"]["complex"]["decharge"][0], "rt") as file:
content = file.read().replace("MBAR Energy analysis", "")

with open(tmp_path / "amber.out", "w") as f:
f.write(content)
f.write("\n")
f.write(content)

with pytest.raises(
ValueError,
match="TI Energy detected after the TIMINGS section.",
):
extract(tmp_path / "amber.out", 298)