Skip to content

Commit

Permalink
mol2rdkit_phys_chem: Add setter for descriptor list
Browse files Browse the repository at this point in the history
    - Add setter for descriptor list to validate user
      provided descriptor names at a central position
      in the code.
  • Loading branch information
JochenSiegWork committed May 17, 2024
1 parent 0749536 commit 64061a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions molpipeline/mol2any/mol2rdkit_phys_chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ def __init__(
uuid: Optional[str], optional (default=None)
UUID of the PipelineElement. If None, a new UUID is generated.
"""
if descriptor_list is not None:
for descriptor_name in descriptor_list:
if descriptor_name not in RDKIT_DESCRIPTOR_DICT:
raise ValueError(
f"Unknown descriptor function with name: {descriptor_name}"
)
self._descriptor_list = descriptor_list
else:
self._descriptor_list = DEFAULT_DESCRIPTORS
self.descriptor_list = descriptor_list
self._return_with_errors = return_with_errors
self._log_exceptions = log_exceptions
super().__init__(
Expand Down Expand Up @@ -111,6 +103,20 @@ def descriptor_list(self) -> list[str]:
"""
return self._descriptor_list[:]

@descriptor_list.setter
def descriptor_list(self, descriptor_list: list[str] | None) -> None:
if descriptor_list is None or descriptor_list is DEFAULT_DESCRIPTORS:
# if None or DEFAULT_DESCRIPTORS are used, set the default descriptors
self._descriptor_list = DEFAULT_DESCRIPTORS
else:
# check all user defined descriptors are valid
for descriptor_name in descriptor_list:
if descriptor_name not in RDKIT_DESCRIPTOR_DICT:
raise ValueError(
f"Unknown descriptor function with name: {descriptor_name}"
)
self._descriptor_list = descriptor_list

def pretransform_single(
self, value: RDKitMol
) -> Union[npt.NDArray[np.float_], InvalidInstance]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def test_unknown_descriptor_name(self) -> None:
self.assertRaises(
ValueError,
MolToRDKitPhysChem,
**{"descriptor_list": ["__NotADescriptor11Name4374737834hggghgddd"]},
**{"descriptor_list": ["__NotADescriptor11Name:)"]},
)

def test_exception_handling(self) -> None:
Expand Down

0 comments on commit 64061a2

Please sign in to comment.