From 33a1bb51c0572326549b237938dc1e4916d646a0 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Sun, 11 Jun 2023 11:58:10 +0100 Subject: [PATCH 1/3] update --- CHANGES | 2 ++ src/alchemlyb/parsing/amber.py | 9 ++++++++- src/alchemlyb/tests/parsing/test_amber.py | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index d5f6b9fc..f2f289c7 100644 --- a/CHANGES +++ b/CHANGES @@ -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 #324). - Change the % based string formatting to {} based string formatting (issue #323, PR #324). - Use loguru instead of logging for log (issue #301, PR #303). diff --git a/src/alchemlyb/parsing/amber.py b/src/alchemlyb/parsing/amber.py index 543d4d54..6bb5441f 100644 --- a/src/alchemlyb/parsing/amber.py +++ b/src/alchemlyb/parsing/amber.py @@ -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 ) @@ -356,7 +364,6 @@ def extract(outfile, T): ) elif line == " 5. TIMINGS\n": finished = True - break if high_E_cnt: logger.warning( diff --git a/src/alchemlyb/tests/parsing/test_amber.py b/src/alchemlyb/tests/parsing/test_amber.py index 0d186cc7..9433da71 100644 --- a/src/alchemlyb/tests/parsing/test_amber.py +++ b/src/alchemlyb/tests/parsing/test_amber.py @@ -1,6 +1,7 @@ """Amber parser tests. """ +import bz2 import logging import pandas as pd @@ -250,3 +251,19 @@ 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_output(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="Did you concatenate the output file?", + ): + extract(tmp_path / "amber.out", 298) From d0bdfbcf5b5fc2eb2eb0c66f76951a27e4f0385e Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Sun, 11 Jun 2023 12:00:47 +0100 Subject: [PATCH 2/3] update --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f2f289c7..1b5ae203 100644 --- a/CHANGES +++ b/CHANGES @@ -19,7 +19,7 @@ The rules for this file: Changes - ValueError raised if concatenated amber output file is passed to amber - parser (issue #315, PR #324). + 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). From 4e0e2e27c65f88137b93039782e1b6feea6b9732 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Sun, 11 Jun 2023 12:26:43 +0100 Subject: [PATCH 3/3] update --- src/alchemlyb/tests/parsing/test_amber.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/alchemlyb/tests/parsing/test_amber.py b/src/alchemlyb/tests/parsing/test_amber.py index 9433da71..21b6064e 100644 --- a/src/alchemlyb/tests/parsing/test_amber.py +++ b/src/alchemlyb/tests/parsing/test_amber.py @@ -253,7 +253,7 @@ def test_u_nk_improper(improper_filename, names=("time", "lambdas")): assert "0.5626" in improper_filename -def test_concatenated_amber_output(tmp_path): +def test_concatenated_amber_u_nk(tmp_path): with bz2.open(load_bace_example()["data"]["complex"]["decharge"][0], "rt") as file: content = file.read() @@ -264,6 +264,22 @@ def test_concatenated_amber_output(tmp_path): with pytest.raises( ValueError, - match="Did you concatenate the output file?", + 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)