diff --git a/src/stk/_internal/building_block.py b/src/stk/_internal/building_block.py index f3f01f160..f5a25cffc 100644 --- a/src/stk/_internal/building_block.py +++ b/src/stk/_internal/building_block.py @@ -782,6 +782,7 @@ def _with_functional_groups( """ self._functional_groups = tuple(functional_groups) + self._fg_repr = repr(self._functional_groups) return self def with_functional_groups( @@ -812,6 +813,7 @@ def _with_canonical_atom_ordering(self) -> typing.Self: functional_group.with_ids(id_map) for functional_group in self._functional_groups ) + self._fg_repr = repr(self._functional_groups) self._placer_ids = frozenset( id_map[placer_id] for placer_id in self._placer_ids ) diff --git a/src/stk/_internal/topology_graphs/host_guest/complex.py b/src/stk/_internal/topology_graphs/host_guest/complex.py index 15669d4f8..f692ebd42 100644 --- a/src/stk/_internal/topology_graphs/host_guest/complex.py +++ b/src/stk/_internal/topology_graphs/host_guest/complex.py @@ -37,7 +37,7 @@ def __init__( building_block: BuildingBlock, start_vector: tuple[float, float, float] = (1.0, 0.0, 0.0), end_vector: tuple[float, float, float] = (1.0, 0.0, 0.0), - displacement: tuple[float, float, float] = (1.0, 0.0, 0.0), + displacement: tuple[float, float, float] = (0.0, 0.0, 0.0), ) -> None: """ Initialize a :class:`.Guest` instance. @@ -410,7 +410,7 @@ class Complex(TopologyGraph): *Changing the Position of the Guest* You can change the position and orientation of the - :class:`.Guest`, as well as its displacement + :class:`.Guest`. .. testcode:: changing-the-position-of-the-guest @@ -449,6 +449,13 @@ class Complex(TopologyGraph): ), ) + .. tip:: + + The host of a :class:`.Complex` will always be placed at the + origin, not at the centroid of the input building block. Therefore, + to place a guest at the centroid of the host use + `displacement=(0, 0, 0)`, which is the default behaviour. + """ def __init__( @@ -521,7 +528,7 @@ def _get_vertices_from_guests( target=guest.get_end_vector(), ), ] - return building_block_vertices # type: ignore + return building_block_vertices # type: ignore[return-value] def clone(self) -> Complex: return self._clone() diff --git a/src/stk/_internal/writers/turbomole.py b/src/stk/_internal/writers/turbomole.py index a26dcacf2..22aeb9406 100644 --- a/src/stk/_internal/writers/turbomole.py +++ b/src/stk/_internal/writers/turbomole.py @@ -1,9 +1,3 @@ -""" -Turbomole Writer -================ - -""" - from __future__ import annotations import typing @@ -11,6 +5,7 @@ from stk._internal.molecule import Molecule from stk._internal.periodic_info import PeriodicInfo from stk._internal.utilities.utilities import OneOrMany +import pathlib class TurbomoleWriter: @@ -144,7 +139,7 @@ def to_string( def write( self, molecule: Molecule, - path: str, + path: pathlib.Path | str, atom_ids: typing.Optional[OneOrMany[int]] = None, periodic_info: typing.Optional[PeriodicInfo] = None, ) -> None: diff --git a/tests/molecular/molecules/building_block/case_data.py b/tests/molecular/molecules/building_block/case_data.py index 0fb4a3a44..094c39b1f 100644 --- a/tests/molecular/molecules/building_block/case_data.py +++ b/tests/molecular/molecules/building_block/case_data.py @@ -1,59 +1,12 @@ -class CaseData: - """ - A test case. - - Attributes - ---------- - building_block : :class:`.BuildingBlock` - The building block to test. - - functional_groups : :class:`tuple` of :class:`.FunctionalGroup` - The functional groups :attr:`.building_block` should be - holding. - - known_repr : str - The representation of the building block. - - core_atom_ids : :class:`tuple` of :class:`int` - The correct core atom ids for :attr:`.building_block`. - - placer_ids : :class:`tuple` of :class:`int` - The correct *placer* ids for :attr:`.building_block`. - - """ +import stk +from dataclasses import dataclass +from collections.abc import Sequence - def __init__( - self, - building_block, - functional_groups, - known_repr, - core_atom_ids, - placer_ids, - ): - """ - Initialize a :class:`.CaseData` instance. - Parameters - ---------- - building_block : :class:`.BuildingBlock` - The building block to test. - - functional_groups : :class:`tuple` of :class:`.FunctionalGroup` - The functional groups `building_block` should be holding. - - known_repr : str - The representation of the building block. - - core_atom_ids : :class:`tuple` of :class:`int` - The correct core atom ids for `building_block`. - - placer_ids : :class:`tuple` of :class:`int` - The correct *placer* ids for `building_block`. - - """ - - self.building_block = building_block - self.functional_groups = functional_groups - self.known_repr = known_repr - self.core_atom_ids = core_atom_ids - self.placer_ids = placer_ids +@dataclass(slots=True, frozen=True) +class CaseData: + building_block: stk.BuildingBlock + functional_groups: Sequence[stk.FunctionalGroup] + known_repr: str + core_atom_ids: Sequence[int] + placer_ids: Sequence[int] diff --git a/tests/molecular/molecules/building_block/conftest.py b/tests/molecular/molecules/building_block/conftest.py index bd387e265..4fe37a693 100644 --- a/tests/molecular/molecules/building_block/conftest.py +++ b/tests/molecular/molecules/building_block/conftest.py @@ -3,10 +3,13 @@ import pytest import stk from pytest_lazyfixture import lazy_fixture +from collections import abc # Fixtures need be visible for lazy_fixture() calls. from .fixtures import * # noqa +from .case_data import CaseData + @pytest.fixture( params=( @@ -17,7 +20,7 @@ lazy_fixture("init_from_rdkit_mol"), ), ) -def case_data(request): +def case_data(request) -> CaseData: """ A :class:`.CaseData` instance. @@ -27,7 +30,7 @@ def case_data(request): @pytest.fixture -def building_block(case_data): +def building_block(case_data: CaseData) -> stk.BuildingBlock: """ A :class:`.BuildingBlock` instance. @@ -48,18 +51,17 @@ def building_block(case_data): ), ) ) -def get_functional_groups(request): +def get_functional_groups( + request: pytest.FixtureRequest, +) -> abc.Iterable[stk.FunctionalGroup]: """ - Yield the functional groups of a `molecule`. + Get the functional groups of a `molecule`. - Parameters - ---------- - molecule : :class:`.Molecule` - The molecule whose functional groups should be gotten. + Parameters: + molecule: + The molecule whose functional groups should be gotten. - Yields - ------ - :class:`.FunctionalGroup` + Returns: A functional group of `molecule`. """ diff --git a/tests/molecular/molecules/building_block/fixtures/init_from_file.py b/tests/molecular/molecules/building_block/fixtures/init_from_file.py index 606d0be86..9c05409e5 100644 --- a/tests/molecular/molecules/building_block/fixtures/init_from_file.py +++ b/tests/molecular/molecules/building_block/fixtures/init_from_file.py @@ -1,104 +1,26 @@ import pytest import stk - +from collections.abc import Sequence from ..case_data import CaseData +from dataclasses import dataclass @pytest.fixture( - params=[ - "building_block.mol", - ], + params=["building_block.mol"], ) def path(tmpdir, request): return tmpdir / request.param +@dataclass(frozen=True, slots=True) class InitFromFileData: - """ - Stores data for the :meth:`.BuildingBlock.init_from_file`. - - Attributes - ---------- - building_block : :class:`.BuildingBlock` - The building block, which will be written to a file, so that it - can be initialized from it. - - init_functional_groups : :class:`iterable` - Passed to the `functional_groups` parameter of - :meth:`.BuildingBlock.init_from_file`. - - init_placer_ids : :class:`tuple` or :class:`NoneType` - Passed to the `placer_ids` parameter of - :meth:`.BuildingBlock.init_from_file`. - - case_data_functional_groups : :class:`tuple` - The functional groups the initialized building block should - have. - - case_data_core_atom_ids : :class:`tuple` of :class:`int` - The ids of core atoms the initialized building block should - have. - - case_data_placer_ids : :class:`tuple` of :class:`int` - The ids of *placer* atoms the initialized building block should - have. - - known_repr : str - The representation of the building block. - - """ - - def __init__( - self, - building_block, - init_functional_groups, - init_placer_ids, - case_data_functional_groups, - case_data_core_atom_ids, - case_data_placer_ids, - known_repr, - ): - """ - Initialize a :class:`.InitFromData` instance. - - Parameters - ---------- - building_block : :class:`.BuildingBlock` - The building block, which will be written to a file, so - that it can be initialized from it. - - init_functional_groups : :class:`iterable` - Passed to the `functional_groups` parameter of - :meth:`.BuildingBlock.init_from_file`. - - init_placer_ids : :class:`tuple` or :class:`NoneType` - Passed to the `placer_ids` parameter of - :meth:`.BuildingBlock.init_from_file`. - - case_data_functional_groups : :class:`tuple` - The functional groups the initialized building block should - have. - - case_data_core_atom_ids : :class:`tuple` of :class:`int` - The ids of core atoms the initialized building block should - have. - - case_data_placer_ids : :class:`tuple` of :class:`int` - The ids of *placer* atoms the initialized building block - should have. - - known_repr : str - The representation of the building block. - - """ - - self.building_block = building_block - self.init_functional_groups = init_functional_groups - self.init_placer_ids = init_placer_ids - self.case_data_functional_groups = case_data_functional_groups - self.case_data_core_atom_ids = case_data_core_atom_ids - self.case_data_placer_ids = case_data_placer_ids - self.known_repr = known_repr + building_block: stk.BuildingBlock + init_functional_groups: Sequence[stk.FunctionalGroup] + init_placer_ids: Sequence[int] | None + case_data_functional_groups: Sequence[stk.FunctionalGroup] + case_data_core_atom_ids: Sequence[int] + case_data_placer_ids: Sequence[int] + known_repr: str @pytest.fixture( diff --git a/tests/molecular/molecules/building_block/test_get_core_atom_ids.py b/tests/molecular/molecules/building_block/test_get_core_atom_ids.py index c8b28cb64..73222bd68 100644 --- a/tests/molecular/molecules/building_block/test_get_core_atom_ids.py +++ b/tests/molecular/molecules/building_block/test_get_core_atom_ids.py @@ -1,19 +1,16 @@ import itertools as it +from .case_data import CaseData -def test_get_core_atom_ids(case_data): + +def test_get_core_atom_ids(case_data: CaseData) -> None: """ Test :meth:`.BuildingBlock.get_core_atom_ids`. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. Holds the building block to test and the correct - core atom ids. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. Holds the building block to test and the correct + core atom ids. """ diff --git a/tests/molecular/molecules/building_block/test_get_functional_groups.py b/tests/molecular/molecules/building_block/test_get_functional_groups.py index c6dd4e86e..5664ab69c 100644 --- a/tests/molecular/molecules/building_block/test_get_functional_groups.py +++ b/tests/molecular/molecules/building_block/test_get_functional_groups.py @@ -2,20 +2,19 @@ from ..utilities import is_equivalent_functional_group +import stk +from collections.abc import Sequence +from .case_data import CaseData -def test_get_functional_groups(case_data): + +def test_get_functional_groups(case_data: CaseData) -> None: """ Test :meth:`.BuildingBlock.get_functional_groups`. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. Holds the building block to test and the correct - functional groups. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. Holds the building block to test and the correct + functional groups. """ @@ -25,21 +24,19 @@ def test_get_functional_groups(case_data): ) -def _test_get_functional_groups(building_block, functional_groups): +def _test_get_functional_groups( + building_block: stk.BuildingBlock, + functional_groups: Sequence[stk.FunctionalGroup], +) -> None: """ Test :meth:`.BuildingBlock.get_functional_groups`. - Parameters - ---------- - building_block : :class:`.BuildingBlock` - The building block to test. - - functional_groups : :class:`tuple` of :class:`.FunctionalGroup` - The correct functional groups. + Parameters: + building_block: + The building block to test. - Returns - ------- - None : :class:`NoneType` + functional_groups: + The correct functional groups. """ diff --git a/tests/molecular/molecules/building_block/test_get_num_functional_groups.py b/tests/molecular/molecules/building_block/test_get_num_functional_groups.py index 22d5db98b..06ec5e0d5 100644 --- a/tests/molecular/molecules/building_block/test_get_num_functional_groups.py +++ b/tests/molecular/molecules/building_block/test_get_num_functional_groups.py @@ -1,16 +1,14 @@ -def test_get_num_functional_groups(case_data): +from .case_data import CaseData + + +def test_get_num_functional_groups(case_data: CaseData) -> None: """ Test :meth:`.BuildingBlock.get_num_functional_groups`. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. Holds the building block to test and the - correct number of functional groups. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. Holds the building block to test and the correct + functional groups. """ diff --git a/tests/molecular/molecules/building_block/test_get_placer_ids.py b/tests/molecular/molecules/building_block/test_get_placer_ids.py index 7ac1d2b8a..193ab465f 100644 --- a/tests/molecular/molecules/building_block/test_get_placer_ids.py +++ b/tests/molecular/molecules/building_block/test_get_placer_ids.py @@ -1,19 +1,17 @@ import itertools as it +from .case_data import CaseData +import stk -def test_get_placer_ids(case_data): + +def test_get_placer_ids(case_data: CaseData) -> None: """ Test :meth:`.BuildingBlock.get_placer_ids`. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. Holds the building block to test and the - correct placer ids. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. Holds the building block to test and the + correct placer ids. """ @@ -23,21 +21,19 @@ def test_get_placer_ids(case_data): ) -def _test_get_placer_ids(building_block, placer_ids): +def _test_get_placer_ids( + building_block: stk.BuildingBlock, + placer_ids: tuple[int, ...], +) -> None: """ Test :meth:`.BuildingBlock.get_placer_ids`. - Parameters - ---------- - building_block : :class:`.BuildingBlock` - The building block to test. - - placer_ids : :class:`tuple` of :class:`int` - The correct placer ids. + Parameters: + building_block: + The building block to test. - Returns - ------- - None : :class:`NoneType` + placer_ids: + The correct placer ids. """ diff --git a/tests/molecular/molecules/building_block/test_repr.py b/tests/molecular/molecules/building_block/test_repr.py index ae8735aa5..977230b5c 100644 --- a/tests/molecular/molecules/building_block/test_repr.py +++ b/tests/molecular/molecules/building_block/test_repr.py @@ -1,16 +1,15 @@ -def test_repr(case_data): +from .case_data import CaseData + +import stk + + +def test_repr(case_data: CaseData) -> None: """ Test :meth:`.BuildingBlock.__repr__`. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. Holds the building block to test and the correct - functional groups. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. Holds the building block to test. """ @@ -20,22 +19,18 @@ def test_repr(case_data): ) -def _test_repr(building_block, known_repr): +def _test_repr(building_block: stk.BuildingBlock, known_repr: str) -> None: """ Test :meth:`.BuildingBlock.get_functional_groups`. - Parameters - ---------- - building_block : :class:`.BuildingBlock` - The building block to test. - - functional_groups : :class:`tuple` of :class:`.FunctionalGroup` - The correct functional groups. + Parameters: + building_block: + The building block to test. - Returns - ------- - None : :class:`NoneType` + known_repr: + The correct representation. """ + print(building_block.__repr__(), known_repr) assert building_block.__repr__() == known_repr diff --git a/tests/molecular/molecules/building_block/test_with_functional_groups.py b/tests/molecular/molecules/building_block/test_with_functional_groups.py index f52ff9100..819021744 100644 --- a/tests/molecular/molecules/building_block/test_with_functional_groups.py +++ b/tests/molecular/molecules/building_block/test_with_functional_groups.py @@ -4,24 +4,26 @@ is_equivalent_building_block, is_equivalent_molecule, ) +import stk +from collections.abc import Sequence, Callable, Iterator -def test_with_functional_groups(building_block, get_functional_groups): +def test_with_functional_groups( + building_block: stk.BuildingBlock, + get_functional_groups: Callable[ + [stk.BuildingBlock], Iterator[stk.FunctionalGroup] + ], +) -> None: """ Test :meth:`.BuildingBlock.with_functional_groups`. - Parameters - ---------- - building_block : :class:`.BuildingBlock` - The building block to test. + Parameters: + building_block: + The building block to test. - get_functional_groups : :class:`callable` - Takes a single parameter, `building_block` and returns the - `functional_groups` parameter to use for this test. - - Returns - ------- - None : :class:`NoneType` + get_functional_groups: + Takes a single parameter, `building_block` and returns the + `functional_groups` parameter to use for this test. """ @@ -35,21 +37,19 @@ def test_with_functional_groups(building_block, get_functional_groups): has_same_structure(building_block, clone) -def _test_with_functional_groups(building_block, functional_groups): +def _test_with_functional_groups( + building_block: stk.BuildingBlock, + functional_groups: Sequence[stk.FunctionalGroup], +) -> None: """ Test :meth:`.BuildingBlock.with_functional_groups`. - Parameters - ---------- - building_block : :class:`.BuildingBlock` - The building block to test. - - functional_groups : :class:`tuple` of :class:`.FunctionalGroup` - The functional groups the new building block should hold. + Parameters: + building_block: + The building block to test. - Returns - ------- - None : :class:`NoneType` + functional_groups: + The functional groups the new building block should hold. """ diff --git a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex0.npy b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex0.npy index ce4d87d46..726a889fe 100644 Binary files a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex0.npy and b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex0.npy differ diff --git a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex1.npy b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex1.npy index daa87a20e..59481adc4 100644 Binary files a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex1.npy and b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex1.npy differ diff --git a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex2.npy b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex2.npy index daa87a20e..59481adc4 100644 Binary files a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex2.npy and b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex2.npy differ diff --git a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex3.npy b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex3.npy index 67b597ccb..91bc24f8e 100644 Binary files a/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex3.npy and b/tests/molecular/molecules/molecule/fixtures/position_matrices/host_guest_complex3.npy differ diff --git a/tests/molecular/writers/mdl_mol/case_data.py b/tests/molecular/writers/mdl_mol/case_data.py index b09cd1049..c44ddeae9 100644 --- a/tests/molecular/writers/mdl_mol/case_data.py +++ b/tests/molecular/writers/mdl_mol/case_data.py @@ -1,37 +1,10 @@ -class CaseData: - """ - A :class:`.MolWriter` test case. - - Attributes - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.MolWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - """ +import stk - def __init__(self, molecule, writer, string): - """ - Initialize a :class:`.CaseData` instance. +from dataclasses import dataclass - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - writer : :class:`.MolWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - """ - - self.molecule = molecule - self.writer = writer - self.string = string +@dataclass(slots=True, frozen=True) +class CaseData: + molecule: stk.Molecule + writer: stk.MolWriter + string: str diff --git a/tests/molecular/writers/mdl_mol/test_to_string.py b/tests/molecular/writers/mdl_mol/test_to_string.py index 20cd70ffe..119bee06b 100644 --- a/tests/molecular/writers/mdl_mol/test_to_string.py +++ b/tests/molecular/writers/mdl_mol/test_to_string.py @@ -1,15 +1,15 @@ -def test_to_string(case_data): +import stk + +from .case_data import CaseData + + +def test_to_string(case_data: CaseData) -> None: """ Test writing of molecule to a string. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. """ @@ -20,24 +20,23 @@ def test_to_string(case_data): ) -def _test_to_string(molecule, writer, string): +def _test_to_string( + molecule: stk.Molecule, + writer: stk.MolWriter, + string: str, +) -> None: """ Test that the written string matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.MolWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - Returns - ------- - None : :class:`NoneType` + string: + The expected output string. """ diff --git a/tests/molecular/writers/mdl_mol/test_write.py b/tests/molecular/writers/mdl_mol/test_write.py index 751059e64..be73a0d21 100644 --- a/tests/molecular/writers/mdl_mol/test_write.py +++ b/tests/molecular/writers/mdl_mol/test_write.py @@ -1,18 +1,19 @@ -def test_write(case_data, tmp_path): +import stk + +from .case_data import CaseData +import pathlib + + +def test_write(case_data: CaseData, tmp_path: pathlib.Path) -> None: """ Test writing of molecule to a file. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. + Parameters: + case_data: + A test case. - tmp_path : :class:`pathlib2.Path` - Path to temporary directory. - - Returns - ------- - None : :class:`NoneType` + tmp_path: + Path to temporary directory. """ @@ -24,27 +25,27 @@ def test_write(case_data, tmp_path): ) -def _test_write(molecule, writer, string, file_path): +def _test_write( + molecule: stk.Molecule, + writer: stk.MolWriter, + string: str, + file_path: pathlib.Path, +) -> None: """ Test that the written file content matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.MolWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - file_path : :class:`str` - Path to temporary file. + string: + The expected output string. - Returns - ------- - None : :class:`NoneType` + file_path: + Path to temporary file. """ diff --git a/tests/molecular/writers/pdb/case_data.py b/tests/molecular/writers/pdb/case_data.py index 8392c829c..f62af625e 100644 --- a/tests/molecular/writers/pdb/case_data.py +++ b/tests/molecular/writers/pdb/case_data.py @@ -1,45 +1,11 @@ -class CaseData: - """ - A :class:`.PdbWriter` test case. - - Attributes - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.PdbWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - periodic_info : :class:`.PeriodicInfo` - Information about periodic cell. Required for testing writing - of constructed molecules with periodic unit cells. - - """ +import stk - def __init__(self, molecule, writer, string, periodic_info): - """ - Initialize a :class:`.CaseData` instance. +from dataclasses import dataclass - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - writer : :class:`.PdbWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - periodic_info : :class:`.PeriodicInfo` - Information about periodic cell. - - """ - - self.molecule = molecule - self.writer = writer - self.string = string - self.periodic_info = periodic_info +@dataclass(slots=True, frozen=True) +class CaseData: + molecule: stk.Molecule + writer: stk.PdbWriter + string: str + periodic_info: stk.PeriodicInfo | None diff --git a/tests/molecular/writers/pdb/conftest.py b/tests/molecular/writers/pdb/conftest.py index 6aeae6a62..bfea4490d 100644 --- a/tests/molecular/writers/pdb/conftest.py +++ b/tests/molecular/writers/pdb/conftest.py @@ -109,7 +109,7 @@ def _get_cof_case() -> CaseData: " 30 \nCONECT 3 35 " "\nCONECT 14 36 \nEND\n" ), - periodic_info=construction_result.get_periodic_info(), + periodic_info=construction_result.get_periodic_info(), # type: ignore[attr-defined] ) diff --git a/tests/molecular/writers/pdb/test_to_string.py b/tests/molecular/writers/pdb/test_to_string.py index 74a16aff1..1b36c8e98 100644 --- a/tests/molecular/writers/pdb/test_to_string.py +++ b/tests/molecular/writers/pdb/test_to_string.py @@ -1,15 +1,15 @@ -def test_to_string(case_data): +import stk + +from .case_data import CaseData + + +def test_to_string(case_data: CaseData) -> None: """ Test writing of molecule to a string. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. """ @@ -21,27 +21,27 @@ def test_to_string(case_data): ) -def _test_to_string(molecule, writer, string, periodic_info=None): +def _test_to_string( + molecule: stk.Molecule, + writer: stk.PdbWriter, + string: str, + periodic_info: stk.PeriodicInfo | None = None, +) -> None: """ Test that the written string matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.PdbWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - periodic_info : :class:`.PeriodicInfo` - Periodic information. + string: + The expected output string. - Returns - ------- - None : :class:`NoneType` + periodic_info: + Periodic information. """ diff --git a/tests/molecular/writers/pdb/test_write.py b/tests/molecular/writers/pdb/test_write.py index c9fb786a4..2d5a5edd0 100644 --- a/tests/molecular/writers/pdb/test_write.py +++ b/tests/molecular/writers/pdb/test_write.py @@ -1,18 +1,19 @@ -def test_write(case_data, tmp_path): +import stk + +from .case_data import CaseData +import pathlib + + +def test_write(case_data: CaseData, tmp_path: pathlib.Path) -> None: """ Test writing of molecule to a file. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. + Parameters: + case_data: + A test case. - tmp_path : :class:`pathlib2.Path` - Path to temporary directory. - - Returns - ------- - None : :class:`NoneType` + tmp_path: + Path to temporary directory. """ @@ -26,35 +27,30 @@ def test_write(case_data, tmp_path): def _test_write( - molecule, - writer, - string, - file_path, - periodic_info=None, + molecule: stk.Molecule, + writer: stk.PdbWriter, + string: str, + file_path: pathlib.Path, + periodic_info: stk.PeriodicInfo | None = None, ): """ Test that the written file content matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.PdbWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - periodic_info : :class:`.PeriodicInfo` - Periodic information. + string: + The expected output string. - file_path : :class:`str` - Path to temporary file. + file_path: + Path to temporary file. - Returns - ------- - None : :class:`NoneType` + periodic_info: + Periodic information. """ diff --git a/tests/molecular/writers/turbomole/case_data.py b/tests/molecular/writers/turbomole/case_data.py index 475580943..42edaa19c 100644 --- a/tests/molecular/writers/turbomole/case_data.py +++ b/tests/molecular/writers/turbomole/case_data.py @@ -1,45 +1,11 @@ -class CaseData: - """ - A :class:`.TurbomoleWriter` test case. - - Attributes - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.TurbomoleWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - periodic_info : :class:`.PeriodicInfo` - Information about periodic cell. Required for testing writing - of constructed molecules with periodic unit cells. - - """ +import stk - def __init__(self, molecule, writer, string, periodic_info): - """ - Initialize a :class:`.CaseData` instance. +from dataclasses import dataclass - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - writer : :class:`.TurbomoleWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - periodic_info : :class:`.PeriodicInfo` - Information about periodic cell. - - """ - - self.molecule = molecule - self.writer = writer - self.string = string - self.periodic_info = periodic_info +@dataclass(slots=True, frozen=True) +class CaseData: + molecule: stk.Molecule + writer: stk.TurbomoleWriter + string: str + periodic_info: stk.PeriodicInfo | None diff --git a/tests/molecular/writers/turbomole/conftest.py b/tests/molecular/writers/turbomole/conftest.py index f041585e8..eb7ec3835 100644 --- a/tests/molecular/writers/turbomole/conftest.py +++ b/tests/molecular/writers/turbomole/conftest.py @@ -43,7 +43,7 @@ def _get_cof_case() -> CaseData: "1.6749 H\n 7.9667 16.1026 53.582 H\n 7.7801 15.8075 5" "1.7756 H\n$end\n" ), - periodic_info=construction_result.get_periodic_info(), + periodic_info=construction_result.get_periodic_info(), # type: ignore[attr-defined] ) diff --git a/tests/molecular/writers/turbomole/test_to_string.py b/tests/molecular/writers/turbomole/test_to_string.py index 498bc3aa8..c0d81f1fc 100644 --- a/tests/molecular/writers/turbomole/test_to_string.py +++ b/tests/molecular/writers/turbomole/test_to_string.py @@ -1,15 +1,15 @@ -def test_to_string(case_data): +import stk + +from .case_data import CaseData + + +def test_to_string(case_data: CaseData) -> None: """ Test writing of molecule to a string. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. """ @@ -21,27 +21,27 @@ def test_to_string(case_data): ) -def _test_to_string(molecule, writer, string, periodic_info=None): +def _test_to_string( + molecule: stk.Molecule, + writer: stk.TurbomoleWriter, + string: str, + periodic_info: stk.PeriodicInfo | None = None, +) -> None: """ Test that the written string matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.TurbomoleWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - periodic_info : :class:`.PeriodicInfo` - Periodic information. + string: + The expected output string. - Returns - ------- - None : :class:`NoneType` + periodic_info: + Periodic information. """ diff --git a/tests/molecular/writers/turbomole/test_write.py b/tests/molecular/writers/turbomole/test_write.py index c64e11d83..7f63372a2 100644 --- a/tests/molecular/writers/turbomole/test_write.py +++ b/tests/molecular/writers/turbomole/test_write.py @@ -1,21 +1,21 @@ -def test_write(case_data, tmp_path): +import stk + +from .case_data import CaseData +import pathlib + + +def test_write(case_data: CaseData, tmp_path: pathlib.Path) -> None: """ Test writing of molecule to a file. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. + Parameters: + case_data: + A test case. - tmp_path : :class:`pathlib2.Path` - Path to temporary directory. - - Returns - ------- - None : :class:`NoneType` + tmp_path: + Path to temporary directory. """ - _test_write( molecule=case_data.molecule, writer=case_data.writer, @@ -26,35 +26,30 @@ def test_write(case_data, tmp_path): def _test_write( - molecule, - writer, - string, - file_path, - periodic_info=None, + molecule: stk.Molecule, + writer: stk.TurbomoleWriter, + string: str, + file_path: pathlib.Path, + periodic_info: stk.PeriodicInfo | None = None, ): """ Test that the written file content matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.TurbomoleWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - periodic_info : :class:`.PeriodicInfo` - Periodic information. + string: + The expected output string. - file_path : :class:`str` - Path to temporary file. + file_path: + Path to temporary file. - Returns - ------- - None : :class:`NoneType` + periodic_info: + Periodic information. """ diff --git a/tests/molecular/writers/xyz/case_data.py b/tests/molecular/writers/xyz/case_data.py index 13a6c1060..962c5fc4e 100644 --- a/tests/molecular/writers/xyz/case_data.py +++ b/tests/molecular/writers/xyz/case_data.py @@ -1,37 +1,10 @@ -class CaseData: - """ - A :class:`.XyzWriter` test case. - - Attributes - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.XyzWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - """ +import stk - def __init__(self, molecule, writer, string): - """ - Initialize a :class:`.CaseData` instance. +from dataclasses import dataclass - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - writer : :class:`.XyzWriter` - The writer to test. - - string : :class:`str` - The expected output string. - - """ - - self.molecule = molecule - self.writer = writer - self.string = string +@dataclass(slots=True, frozen=True) +class CaseData: + molecule: stk.Molecule + writer: stk.XyzWriter + string: str diff --git a/tests/molecular/writers/xyz/test_to_string.py b/tests/molecular/writers/xyz/test_to_string.py index c13ca7952..c56ae2f35 100644 --- a/tests/molecular/writers/xyz/test_to_string.py +++ b/tests/molecular/writers/xyz/test_to_string.py @@ -1,15 +1,15 @@ -def test_to_string(case_data): +import stk + +from .case_data import CaseData + + +def test_to_string(case_data: CaseData) -> None: """ Test writing of molecule to a string. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. - - Returns - ------- - None : :class:`NoneType` + Parameters: + case_data: + A test case. """ @@ -20,24 +20,23 @@ def test_to_string(case_data): ) -def _test_to_string(molecule, writer, string): +def _test_to_string( + molecule: stk.Molecule, + writer: stk.XyzWriter, + string: str, +) -> None: """ Test that the written string matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.XyzWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - Returns - ------- - None : :class:`NoneType` + string: + The expected output string. """ diff --git a/tests/molecular/writers/xyz/test_write.py b/tests/molecular/writers/xyz/test_write.py index aa8bccb75..d02452ba6 100644 --- a/tests/molecular/writers/xyz/test_write.py +++ b/tests/molecular/writers/xyz/test_write.py @@ -1,18 +1,19 @@ -def test_write(case_data, tmp_path): +import stk + +from .case_data import CaseData +import pathlib + + +def test_write(case_data: CaseData, tmp_path: pathlib.Path) -> None: """ Test writing of molecule to a file. - Parameters - ---------- - case_data : :class:`.CaseData` - A test case. + Parameters: + case_data: + A test case. - tmp_path : :class:`pathlib2.Path` - Path to temporary directory. - - Returns - ------- - None : :class:`NoneType` + tmp_path: + Path to temporary directory. """ @@ -24,27 +25,27 @@ def test_write(case_data, tmp_path): ) -def _test_write(molecule, writer, string, file_path): +def _test_write( + molecule: stk.Molecule, + writer: stk.XyzWriter, + string: str, + file_path: pathlib.Path, +) -> None: """ Test that the written file content matches expected string. - Parameters - ---------- - molecule : :class:`.Molecule` - Molecule to test. - - writer : :class:`.XyzWriter` - The writer to test. + Parameters: + molecule: + Molecule to test. - string : :class:`str` - The expected output string. + writer: + The writer to test. - file_path : :class:`str` - Path to temporary file. + string: + The expected output string. - Returns - ------- - None : :class:`NoneType` + file_path: + Path to temporary file. """