Skip to content

Commit a84f86d

Browse files
committed
deps take 2
1 parent 3bc5b28 commit a84f86d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lobster/tokenization/_mgm_tokenizer_transform.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import importlib.resources
2+
from importlib.util import find_spec
23
from os import PathLike
34
from typing import Any, Callable, Dict, List, Literal, Optional, Union
45

5-
import selfies as sf
66
import torch
77
from transformers.tokenization_utils_base import (
88
BatchEncoding,
@@ -27,6 +27,13 @@
2727
uniform_sample,
2828
)
2929

30+
_SELFIES_AVAILABLE = False
31+
32+
if find_spec("selfies"):
33+
import selfies as sf
34+
35+
_SELFIES_AVAILABLE = True
36+
3037
logger = logging.get_logger(__name__)
3138

3239

@@ -204,10 +211,12 @@ def preprocess_seq(self, seq: str) -> str:
204211
return seq
205212

206213
def get_selfies_length(self, seq: str) -> int:
214+
assert _SELFIES_AVAILABLE, "selfies not available. This dependency is part of the mgm extra"
207215
symbols = list(sf.split_selfies(seq))
208216
return len(symbols)
209217

210218
def crop_selfies(self, seq: str, max_len: int, crop_left: bool) -> str:
219+
assert _SELFIES_AVAILABLE, "selfies not available. This dependency is part of the mgm extra"
211220
symbols = list(sf.split_selfies(seq))
212221
if crop_left:
213222
symbols = symbols[-max_len:]

0 commit comments

Comments
 (0)