diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index fc08b267..cff12835 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -53,7 +53,7 @@ jobs: run: | case "${{ matrix.special }}" in "; minimum version") - conda create -n test -c conda-forge python=${{ matrix.version }} rdkit==2018.03.1 numpy=1.15.0 pandas=0.23.0 h5py=2.7.0 scipy=0.19.1 contextlib2==0.6.0 typing-extensions==3.7.4.3 pytest==5.4.0 pyyaml=5.1.0 pytest-cov pytest-mock + conda create -n test -c conda-forge python=${{ matrix.version }} rdkit==2018.03.1 numpy=1.15.0 pandas=0.23.0 h5py=2.7.0 scipy=0.19.1 contextlib2==0.6.0 typing-extensions==3.7.4.3 pytest==5.4.0 pyyaml=5.1.0 packaging==16.8 pytest-cov pytest-mock source $CONDA/bin/activate test pip install schema==0.7.2 Nano-Utils==0.4.3 AssertionLib==2.2.3 plams==1.5.1 qmflows==0.11.0 pip install -e . --no-dependencies diff --git a/CAT/_mol_str_parser.py b/CAT/_mol_str_parser.py index 9abad6c0..5f4214ac 100644 --- a/CAT/_mol_str_parser.py +++ b/CAT/_mol_str_parser.py @@ -20,7 +20,8 @@ import textwrap from typing import Any, Callable -from nanoutils import PartialPrepend, VersionInfo +from nanoutils import PartialPrepend +from packaging.version import Version try: import rdkit @@ -28,10 +29,10 @@ except ModuleNotFoundError: # Precaution against sphinx mocking raising a TypeError FLAGS = 0 - RDKIT_VERSION = VersionInfo(0, 0, 0) + RDKIT_VERSION = Version("0.0.0") else: FLAGS = Chem.SanitizeFlags.SANITIZE_ALL ^ Chem.SanitizeFlags.SANITIZE_ADJUSTHS - RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__) + RDKIT_VERSION = Version(rdkit.__version__) __all__ = ["FormatEnum", "str_to_rdmol"] @@ -72,8 +73,8 @@ class FormatEnum(enum.Enum): SMILES = PartialPrepend(str_to_rdmol, Chem.MolFromSmiles, "SMILES string", sanitize=False) TPL = PartialPrepend(str_to_rdmol, Chem.MolFromTPLBlock, "TPL block", sanitize=False) TPL_FILE = PartialPrepend(str_to_rdmol, Chem.MolFromTPLFile, "TPL file", sanitize=False) - if RDKIT_VERSION >= (2020, 3, 3): + if RDKIT_VERSION >= Version("2020.03.3"): SVG = PartialPrepend(str_to_rdmol, Chem.MolFromRDKitSVG, "SVG string", sanitize=False, removeHs=False) - if RDKIT_VERSION >= (2020, 9, 1): + if RDKIT_VERSION >= Version("2020.09.1"): PNG = PartialPrepend(str_to_rdmol, Chem.MolFromPNGString, "PNG string") PNG_FILE = PartialPrepend(str_to_rdmol, Chem.MolFromPNGFile, "PNG file") diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c0477f54..a289af62 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,7 +8,11 @@ This project adheres to `Semantic Versioning `_. 0.10.2 ****** -* *placeholder*. +* Added the option to specify dummy atoms as anchor group. +* Added the option to specify the format type of anchor groups (SMILES, SMARTS, *etc.*). +* Fixed an issue wherein anchor-group-parsing could fail for mono-atomic anchors. +* Added ``packaging`` and ``rdkit-pypi`` as dependencies; + manually installing ``rdkit`` via conda is no longer necessary. 0.10.1 diff --git a/conftest.py b/conftest.py index 31e55f6e..71712d13 100644 --- a/conftest.py +++ b/conftest.py @@ -6,7 +6,7 @@ import pytest import rdkit -from nanoutils import VersionInfo +from packaging.version import Version from CAT import logger @@ -14,8 +14,7 @@ @pytest.fixture(scope="session", autouse=True) def rdkit_version() -> None: """Validate the rdkit version.""" - rdkit_version = VersionInfo.from_str(rdkit.__version__) - if rdkit_version < (2021, 3, 4): + if Version(rdkit.__version__) < Version("2021.03.4"): warnings.warn( "The CAT test suite requires RDKit >= 2021.03.4 to properly run; " f"observed version: {rdkit.__version__}" diff --git a/setup.py b/setup.py index cb00ddde..6831c4d7 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ version=version['__version__'], description=('A collection of tools designed for the automatic ' 'construction of chemical compounds.'), - long_description=f'{readme}\n\n', + long_description=readme + "\n\n", long_description_content_type='text/x-rst', author=['Bas van Beek', 'Jelena Belic'], author_email='b.f.van.beek@vu.nl', @@ -100,6 +100,7 @@ 'typing-extensions>=3.7.4.3', 'qmflows>=0.11.0', 'rdkit-pypi>=2018.03.1', + 'packaging>=1.16.8', ], setup_requires=[ 'pytest-runner', diff --git a/tests/test_entry_points.py b/tests/test_entry_points.py index 2906a1fc..4b79a6f1 100644 --- a/tests/test_entry_points.py +++ b/tests/test_entry_points.py @@ -11,7 +11,7 @@ import pytest import numpy as np from scm.plams import Molecule -from nanoutils import VersionInfo +from packaging.version import Version from CAT.data_handling.entry_points import main @@ -27,8 +27,6 @@ DB_PATH = PATH / 'database' PATH_REF = PATH / 'ligand_ref' -RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__) - class TestMain: @pytest.fixture(scope="class", autouse=True) @@ -60,7 +58,10 @@ def test_raise(self) -> None: main([f'{filename}bob']) @pytest.mark.parametrize("filename", PATH_DICT.values(), ids=PATH_DICT.keys()) - @pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4") + @pytest.mark.xfail( + Version(rdkit.__version__) < Version("2021.03.4"), + reason="requires rdkit >= 2021.03.4", + ) def test_mol(self, filename: str) -> None: mol = Molecule(LIG_PATH / filename) mol_ref = Molecule(PATH_REF / filename) diff --git a/tests/test_gen_job_manager.py b/tests/test_gen_job_manager.py index da9714c1..0ae1b9bc 100644 --- a/tests/test_gen_job_manager.py +++ b/tests/test_gen_job_manager.py @@ -1,6 +1,5 @@ """Tests for the :mod:`CAT.gen_job_manager.GenJobManager` class in :mod:`CAT.gen_job_manager`.""" -import re from os.path import (join, abspath) from collections import abc @@ -8,7 +7,7 @@ import numpy as np from scm.plams import Settings, JobManager, AMSJob, AMSResults from assertionlib import assertion -from nanoutils import VersionInfo +from packaging.version import Version from CAT.gen_job_manager import GenJobManager from CAT.utils import get_formula @@ -19,11 +18,6 @@ FOLDER = 'test_plams_workdir' -NUMPY_VERSION = VersionInfo._make( - int(i) for i in re.match(r'(\d+).(\d+).(\d+)', np.__version__).groups() -) - - def test_init() -> None: """Test :meth:`CAT.gen_job_manager.GenJobManager.__init__`.""" manager = GenJobManager(SETTINGS, PATH, FOLDER) @@ -40,7 +34,10 @@ def test_init() -> None: assertion.eq(manager.input, join(ABSPATH, FOLDER, SETTINGS.hashing)) -@pytest.mark.skipif(NUMPY_VERSION < (1, 16, 0), reason="Unpickling requires numpy >= 1.16.0") +@pytest.mark.skipif( + Version(np.__version__) < Version("1.16.0"), + reason="Unpickling requires numpy >= 1.16.0", +) def test_load_job() -> None: """Test :meth:`CAT.gen_job_manager.GenJobManager.load_job`.""" filename = join(PATH, FOLDER, 'QD_opt_part1', 'QD_opt_part1.hash') diff --git a/tests/test_ligand_anchoring.py b/tests/test_ligand_anchoring.py index 0f800d97..4918e142 100644 --- a/tests/test_ligand_anchoring.py +++ b/tests/test_ligand_anchoring.py @@ -19,7 +19,7 @@ from scm.plams import from_smiles, Molecule, to_rdmol, PT from assertionlib import assertion from schema import SchemaError -from nanoutils import VersionInfo +from packaging.version import Version from CAT.utils import get_template, KindEnum, AnchorTup, FormatEnum from CAT.base import prep_input @@ -36,8 +36,6 @@ PATH = Path('tests') / 'test_files' -RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__) - class TestGetFunctionalGroups: """Tests for :func:`CAT.attachment.ligand_anchoring.get_functional_groups`.""" @@ -158,7 +156,10 @@ def get_h5py_group(self) -> Generator[h5py.Group, None, None]: }) @pytest.mark.parametrize("kwargs_id,kwargs", OPTIONS_DICT.items(), ids=OPTIONS_DICT.keys()) - @pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4") + @pytest.mark.xfail( + Version(rdkit.__version__) < Version("2021.03.4"), + reason="requires rdkit >= 2021.03.4", + ) def test_options(self, kwargs_id: str, kwargs: Dict[str, Any], group: h5py.Group) -> None: # Parse the anchoring options mol = from_smiles("OC(=O)CCCCC") diff --git a/tests/test_ligand_attach.py b/tests/test_ligand_attach.py index a63b6f6f..8adc60e3 100644 --- a/tests/test_ligand_attach.py +++ b/tests/test_ligand_attach.py @@ -10,7 +10,7 @@ import h5py import numpy as np from assertionlib import assertion -from nanoutils import VersionInfo +from packaging.version import Version from scm.plams import Settings, Molecule from CAT.base import prep @@ -26,8 +26,6 @@ QD_PATH = PATH / 'qd' DB_PATH = PATH / 'database' -RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__) - def test_get_rotmat1() -> None: """Test :func:`CAT.attachment.ligand_attach._get_rotmat1`.""" @@ -119,7 +117,10 @@ def run_cat(self, request: "_pytest.fixtures.SubRequest") -> Generator[DihedTup, for file in files: shutil.rmtree(file, ignore_errors=True) - @pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4") + @pytest.mark.xfail( + Version(rdkit.__version__) < Version("2021.03.4"), + reason="requires rdkit >= 2021.03.4", + ) def test_atoms(self, output: DihedTup) -> None: dtype = [("symbols", "U2"), ("coords", "f8", 3)] atoms = np.fromiter( @@ -159,7 +160,10 @@ def run_cat( for file in files: shutil.rmtree(file, ignore_errors=True) - @pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4") + @pytest.mark.xfail( + Version(rdkit.__version__) < Version("2021.03.4"), + reason="requires rdkit >= 2021.03.4", + ) def test_atoms(self, output: AllignmentTup) -> None: dtype = [("symbols", "S2"), ("coords", "f8", 3)] iterator = ((at.symbol, at.coords) for at in output.mol) @@ -215,7 +219,10 @@ def run_cat( for file in files: shutil.rmtree(file, ignore_errors=True) - @pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4") + @pytest.mark.xfail( + Version(rdkit.__version__) < Version("2021.03.4"), + reason="requires rdkit >= 2021.03.4", + ) def test_atoms(self, output: AllignmentTup) -> None: dtype = [("symbols", "S2"), ("coords", "f8", 3)] iterator = ((at.symbol, at.coords) for at in output.mol) diff --git a/tests/test_multi_ligand.py b/tests/test_multi_ligand.py index 2ece2882..1d9459ce 100644 --- a/tests/test_multi_ligand.py +++ b/tests/test_multi_ligand.py @@ -8,8 +8,9 @@ import pytest import rdkit -from nanoutils import delete_finally, VersionInfo +from nanoutils import delete_finally from scm.plams import Settings +from packaging.version import Version from CAT import base PATH = Path('tests') / 'test_files' @@ -18,8 +19,6 @@ QD_PATH = PATH / 'qd' DB_PATH = PATH / 'database' -RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__) - with open(PATH / 'input3.yaml', 'r') as f: SETTINGS = Settings(yaml.load(f, Loader=yaml.FullLoader)) @@ -33,7 +32,10 @@ def _iterfiles(file1, file2): @delete_finally(LIG_PATH, QD_PATH, DB_PATH) -@pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4") +@pytest.mark.xfail( + Version(rdkit.__version__) < Version("2021.03.4"), + reason="requires rdkit >= 2021.03.4", +) def test_multi_ligand() -> None: """Test :mod:`CAT.multi_ligand`.""" base.prep(SETTINGS.copy())