2
2
3
3
from __future__ import annotations # for all the python 3.8 users out there.
4
4
5
- from typing import Any , Literal
5
+ from typing import TYPE_CHECKING , Any
6
6
7
7
try :
8
8
from typing import Self # type: ignore[attr-defined]
15
15
16
16
from molpipeline .abstract_pipeline_elements .mol2any .mol2bitvector import (
17
17
ABCMorganFingerprintPipelineElement ,
18
+ FPReturnAsOption ,
18
19
)
19
- from molpipeline .utils .molpipeline_types import RDKitMol
20
+
21
+ if TYPE_CHECKING :
22
+ from molpipeline .utils .molpipeline_types import RDKitMol
20
23
21
24
22
25
class MolToMorganFP (ABCMorganFingerprintPipelineElement ):
@@ -33,7 +36,7 @@ def __init__(
33
36
use_features : bool = False ,
34
37
n_bits : int = 2048 ,
35
38
counted : bool = False ,
36
- return_as : Literal [ "sparse" , "dense" , "explicit_bit_vect" ] = "sparse" ,
39
+ return_as : FPReturnAsOption = "sparse" ,
37
40
name : str = "MolToMorganFP" ,
38
41
n_jobs : int = 1 ,
39
42
uuid : str | None = None ,
@@ -52,12 +55,13 @@ def __init__(
52
55
counted: bool, default=False
53
56
If True, the fingerprint will be counted.
54
57
If False, the fingerprint will be binary.
55
- return_as: Literal["sparse", "dense", "explicit_bit_vect"] , default="sparse"
58
+ return_as: FPReturnAsOption , default="sparse"
56
59
Type of output. When "sparse" the fingerprints will be returned as a
57
60
scipy.sparse.csr_matrix holding a sparse representation of the bit vectors.
58
- With "dense" a numpy matrix will be returned.
59
- With "explicit_bit_vect" the fingerprints will be returned as a list of
60
- RDKit's rdkit.DataStructs.cDataStructs.ExplicitBitVect.
61
+ With "dense" a numpy matrix will be returned. With "rdkit" the fingerprints
62
+ will be returned as a list of one of RDKit's ExplicitBitVect,
63
+ IntSparseBitVect, UIntSparseBitVect, etc. depending on the fingerprint
64
+ and parameters.
61
65
name: str, default="MolToMorganFP"
62
66
Name of PipelineElement
63
67
n_jobs: int, default=1
@@ -88,7 +92,7 @@ def __init__(
88
92
)
89
93
if not isinstance (n_bits , int ) or n_bits < 1 :
90
94
raise ValueError (
91
- f"Number of bits has to be a integer > 0! (Received: { n_bits } )"
95
+ f"Number of bits has to be a integer > 0! (Received: { n_bits } )" ,
92
96
)
93
97
self ._n_bits = n_bits
94
98
self ._feature_names = [f"morgan_{ i } " for i in range (self ._n_bits )]
@@ -105,6 +109,7 @@ def get_params(self, deep: bool = True) -> dict[str, Any]:
105
109
-------
106
110
dict[str, Any]
107
111
Dictionary of parameters.
112
+
108
113
"""
109
114
parameters = super ().get_params (deep )
110
115
if deep :
@@ -125,6 +130,7 @@ def set_params(self, **parameters: Any) -> Self:
125
130
-------
126
131
Self
127
132
MolToMorganFP pipeline element with updated parameters.
133
+
128
134
"""
129
135
parameter_copy = dict (parameters )
130
136
n_bits = parameter_copy .pop ("n_bits" , None )
@@ -143,6 +149,7 @@ def _get_fp_generator(
143
149
-------
144
150
rdFingerprintGenerator.FingerprintGenerator
145
151
RDKit fingerprint generator.
152
+
146
153
"""
147
154
return rdFingerprintGenerator .GetMorganGenerator (
148
155
radius = self .radius ,
@@ -160,12 +167,13 @@ def _explain_rdmol(self, mol_obj: RDKitMol) -> dict[int, list[tuple[int, int]]]:
160
167
Returns
161
168
-------
162
169
dict[int, list[tuple[int, int]]]
163
- Dictionary with bit position as key and list of tuples with atom index and radius as value.
170
+ Dictionary with bit position as key and list of tuples with atom index
171
+ and radius as value.
172
+
164
173
"""
165
174
fp_generator = self ._get_fp_generator ()
166
175
additional_output = AllChem .AdditionalOutput ()
167
176
additional_output .AllocateBitInfoMap ()
168
177
# using the dense fingerprint here, to get indices after folding
169
178
_ = fp_generator .GetFingerprint (mol_obj , additionalOutput = additional_output )
170
- bit_info = additional_output .GetBitInfoMap ()
171
- return bit_info
179
+ return additional_output .GetBitInfoMap ()
0 commit comments