Skip to content

Commit

Permalink
refactor: use biotest
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Oct 21, 2024
1 parent 4a15082 commit e42a13c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 45 deletions.
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
pytest-cov
numpy
biotest @ git+https://github.com/deargen/biotest@master
50 changes: 5 additions & 45 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,16 @@
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__)

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"),
[
Expand All @@ -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,
)

0 comments on commit e42a13c

Please sign in to comment.