Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

130 add fix attribute output type #131

Merged
merged 4 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ def set_params(self, **parameters: Any) -> Self:
class ABCMorganFingerprintPipelineElement(MolToRDKitGenFPElement, abc.ABC):
"""Abstract Class for Morgan fingerprints."""

@property
def output_type(self) -> str:
"""Get output type."""
if self.counted:
return "integer"
return "binary"

# pylint: disable=R0913
def __init__(
self,
Expand Down
14 changes: 12 additions & 2 deletions molpipeline/estimators/chemprop/neural_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@


class ChempropNeuralFP(ABCChemprop):
"""Wrap Chemprop in a sklearn like transformer returning the neural fingerprint as a numpy array."""
"""Wrap Chemprop in a sklearn like transformer returning the neural fingerprint as a numpy array.

This class is not a (grand-) child of MolToAnyPipelineElement, as it does not support the `pretransform_single`
method. To maintain compatibility with the MolToAnyPipelineElement, the `output_type` property is implemented.
It can be used as any other transformer in the pipeline, except in the `MolToConcatenatedVector`.
"""

@property
def output_type(self) -> str:
"""Return the output type of the transformer."""
return "float"

def __init__(
self,
Expand Down Expand Up @@ -52,7 +62,7 @@ def __init__(

def fit(
self,
X: MoleculeDataset, # pylint: disable=invalid-name
X: MoleculeDataset,
y: Sequence[int | float] | npt.NDArray[np.int_ | np.float64],
) -> Self:
"""Fit the model.
Expand Down
5 changes: 5 additions & 0 deletions test_extras/test_chemprop/test_neural_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ def test_json_serialization(self) -> None:
chemprop_json = recursive_to_json(chemprop_fp_encoder)
chemprop_encoder_copy = recursive_from_json(chemprop_json)
compare_params(self, chemprop_fp_encoder, chemprop_encoder_copy)

def test_output_type(self) -> None:
"""Test the output type."""
chemprop_fp_encoder = get_neural_fp_encoder()
self.assertEqual(chemprop_fp_encoder.output_type, "float")
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def test_counted_bits(self) -> None:
self.assertTrue(np.any(output_counted > output_binary))

def test_output_types(self) -> None:
"""Test if the output types are correct for counted and binary fingerprints."""
mol_fp = MolToMorganFP(counted=False)
self.assertEqual(mol_fp.output_type, "binary")
mol_fp = MolToMorganFP(counted=True)
self.assertEqual(mol_fp.output_type, "integer")

def test_return_value_types(self) -> None:
"""Test equality of different output_types."""

smi2mol = SmilesToMol()
Expand Down