Skip to content

Commit

Permalink
TST: Add tests for the cone-angle remove_anchor_hydrogens keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas van Beek committed Feb 14, 2022
1 parent 4217bee commit dbf0811
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_cone_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
import numpy as np
import pytest
import yaml
from scm.plams import readpdb, Settings
from scm.plams import readpdb, Settings, Molecule

from CAT.base import prep
from CAT.workflows import CONE_ANGLE
from nanoCAT.cone_angle import get_cone_angle

PATH = Path("tests") / "test_files"
CONE_ANGLE_PATH = PATH / "cone_angle"

MOL = readpdb(PATH / "CCCC[O-]@O5.pdb")
MOL_AMMONIUM = Molecule(PATH / "pentyl_ammonium.xyz")
MOL_AMMONIUM.guess_bonds()


class TestConeAngle:
Expand All @@ -42,6 +45,24 @@ def test_raise(self, kwargs: dict[str, Any], exc_type: type[Exception]) -> None:
with pytest.raises(exc_type):
get_cone_angle(MOL, **kwargs)

REMOVE_H_PARAMS = {
"default": (False, (220, 232)),
"remove_hydrogens": (True, 81),
}

@pytest.mark.parametrize("remove_h,ref", REMOVE_H_PARAMS.values(), ids=REMOVE_H_PARAMS)
def test_remove_hydrogens(self, remove_h: bool, ref: float | tuple[float, float]) -> None:
out = get_cone_angle(MOL_AMMONIUM, 5, remove_anchor_hydrogens=remove_h)

# NOTE: The pentyl ammonium system seems to converge to one of two cone-angles
if isinstance(ref, tuple):
try:
np.testing.assert_allclose(out, ref[0], rtol=0, atol=1)
except AssertionError:
np.testing.assert_allclose(out, ref[1], rtol=0, atol=1)
else:
np.testing.assert_allclose(out, ref, rtol=0, atol=1)


class TestWorkflow:
with open(PATH / "cone_angle_setting.yaml", "r") as f:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_files/pentyl_ammonium.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
20

C 1.28630756 -0.77573787 -0.00000000
C 2.47070405 0.18372642 -0.00000000
C 3.79013383 -0.60191494 -0.00000000
C 4.99312868 0.34819422 -0.00000000
C 6.30623936 -0.43099753 -0.00000000
N 0.00000000 0.00000000 -0.00000000
H 1.27610811 -1.40641630 0.89215764
H 1.27610811 -1.40641630 -0.89215764
H 2.41877024 0.82374106 0.88651503
H 2.41877024 0.82374106 -0.88651503
H 3.82571104 -1.24461252 -0.88535152
H 3.82571104 -1.24461252 0.88535152
H 4.94575858 0.99045146 0.88526603
H 4.94575858 0.99045146 -0.88526603
H 6.37663529 -1.06240433 0.88601442
H 7.14484734 0.26410989 -0.00000000
H 6.37663529 -1.06240433 -0.88601442
H -0.04282656 0.58998902 -0.82749495
H -0.04282656 0.58998902 0.82749495
H -0.79342064 -0.63569277 -0.00000000

0 comments on commit dbf0811

Please sign in to comment.