Skip to content

Commit c029395

Browse files
committed
raise error for invalid smiles and return None
1 parent 97839d9 commit c029395

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

chebai/preprocessing/reader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,13 @@ def _read_data(self, raw_data: str) -> List[int]:
203203
print(f"RDKit failed to process {raw_data}")
204204
print(f"\t{e}")
205205
try:
206+
mol = Chem.MolFromSmiles(raw_data.strip())
207+
if mol is None:
208+
raise ValueError(f"Invalid SMILES: {raw_data}")
206209
return [self._get_token_index(v[1]) for v in _tokenize(raw_data)]
207210
except ValueError as e:
208211
print(f"could not process {raw_data}")
209-
print(f"\t{e}")
212+
print(f"\tError: {e}")
210213
return None
211214

212215

0 commit comments

Comments
 (0)