Browse Source
add logger
Signed-off-by: shiyu22 <shiyu.chen@zilliz.com>
main
1 changed files with
19 additions and
12 deletions
-
rdkit.py
|
|
@ -12,11 +12,14 @@ |
|
|
|
# See the License for the specific language governing permissions and |
|
|
|
# limitations under the License. |
|
|
|
|
|
|
|
import logging |
|
|
|
from towhee import register |
|
|
|
from towhee.operator import Operator |
|
|
|
|
|
|
|
from rdkit import DataStructs, Chem |
|
|
|
|
|
|
|
log = logging.getLogger() |
|
|
|
|
|
|
|
@register(output_schema=['fingerprint']) |
|
|
|
class Rdkit(Operator): |
|
|
|
""" |
|
|
@ -35,6 +38,7 @@ class Rdkit(Operator): |
|
|
|
|
|
|
|
def __call__(self, smiles: str): |
|
|
|
mols = Chem.MolFromSmiles(smiles) |
|
|
|
try: |
|
|
|
if self.algorithm == 'daylight': |
|
|
|
fp = Chem.RDKFingerprint(mols, fpSize=self.size) |
|
|
|
elif self.algorithm == 'morgan': |
|
|
@ -47,6 +51,9 @@ class Rdkit(Operator): |
|
|
|
elif self.algorithm == 'maccs': |
|
|
|
from rdkit.Chem import MACCSkeys |
|
|
|
fp = MACCSkeys.GenMACCSKeys(mols) |
|
|
|
except Exception as e: |
|
|
|
log.error(f'{e}, cannot generate fingerprint of {smiles}.') |
|
|
|
raise KeyError(e) |
|
|
|
|
|
|
|
hex_fp = DataStructs.BitVectToFPSText(fp) |
|
|
|
fingerprint = bytes.fromhex(hex_fp) |
|
|
|