From e42a13c61f8286769673137fb84ca895c05c7d21 Mon Sep 17 00:00:00 2001 From: Kiyoon Kim Date: Mon, 21 Oct 2024 17:09:57 +0900 Subject: [PATCH] refactor: use biotest --- pyproject.toml | 7 ++++++ requirements_test.txt | 1 + tests/test_helpers.py | 50 +++++-------------------------------------- 3 files changed, 13 insertions(+), 45 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a9f6081..070639a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,13 @@ max-line-length = 120 [tool.ruff.lint.isort] # combine-as-imports = true known-third-party = ["wandb"] +known-first-party = [ + "rust_graph", + "bio_data_to_db", + "apbs_binary", + "slack_helpers", + "biotest", +] ## Uncomment this if you want to use Python < 3.10 # required-imports = [ diff --git a/requirements_test.txt b/requirements_test.txt index 90c22de..4a44ffd 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,3 +1,4 @@ pytest pytest-cov numpy +biotest @ git+https://github.com/deargen/biotest@master diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 9545263..dc52510 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -5,9 +5,9 @@ from os import PathLike from pathlib import Path -import numpy as np import pytest +from biotest.compare_files import assert_two_pdb_files_within_tolerance from reduce_binary.helpers import protonate logger = logging.getLogger(__name__) @@ -15,47 +15,6 @@ SCRIPT_DIR = Path(__file__).resolve().parent -def check_pdb_atoms_almost_equal( - pdb1_str: str, - pdb2_str: str, -): - # ATOM 998 N PHE B 9 18.937-159.292 -13.075 1.00 30.49 N - pdb1_lines = pdb1_str.splitlines() - pdb2_lines = pdb2_str.splitlines() - assert len(pdb1_lines) == len(pdb2_lines) - - for pdb1_line, pdb2_line in zip(pdb1_lines, pdb2_lines): - if pdb1_line.startswith("ATOM") and pdb2_line.startswith("ATOM"): - coord_1 = ( - float(pdb1_line[32:38]), - float(pdb1_line[38:47]), - float(pdb1_line[47:56]), - ) - coord_2 = ( - float(pdb2_line[32:38]), - float(pdb2_line[38:47]), - float(pdb2_line[47:56]), - ) - - for c1, c2 in zip(coord_1, coord_2): - assert np.isclose( - c1, c2, atol=1e-3 - ), f"{pdb1_line.rstrip()} and {pdb2_line.rstrip()} are not equal." - - line1_except_coord = pdb1_line[:32] + pdb1_line[56:] - line2_except_coord = pdb2_line[:32] + pdb2_line[56:] - assert ( - line1_except_coord.rstrip() == line2_except_coord.rstrip() - ), f"{pdb1_line.rstrip()} and {pdb2_line.rstrip()} are not equal." - - else: - assert ( - pdb1_line.rstrip() == pdb2_line.rstrip() - ), f"{pdb1_line.rstrip()} and {pdb2_line.rstrip()} are not equal." - - return True - - @pytest.mark.parametrize( ("in_pdb_path", "answer_pdb_path"), [ @@ -81,7 +40,8 @@ def test_protonate(in_pdb_path: str | PathLike, answer_pdb_path: str | PathLike) remove_hydrogen_first=True, ) - check_pdb_atoms_almost_equal( - out_pdb_path.read_text(), - answer_pdb_path.read_text(), + assert_two_pdb_files_within_tolerance( + out_pdb_path, + answer_pdb_path, + tolerance=1e-3, )