Skip to content

Commit

Permalink
Merge pull request #110 from vandrw/master
Browse files Browse the repository at this point in the history
fix #104 Add check for dot symbol and warn user
  • Loading branch information
MarioKrenn6240 authored Nov 23, 2023
2 parents 120b776 + 00756c6 commit 832ada9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions selfies/utils/encoding_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ def selfies_to_encoding(
selfies += "[nop]" * (pad_to_len - len_selfies(selfies))

# integer encode
char_list = split_selfies(selfies)
integer_encoded = [vocab_stoi[char] for char in char_list]

integer_encoded = []
for char in split_selfies(selfies):
if (char == ".") and ("." not in vocab_stoi):
raise KeyError(
"The SELFIES string contains two unconnected molecules "
"(given by the '.' character), but vocab_stoi does not "
"contain the '.' key. Please add it to the vocabulary "
"or separate the molecules."
)

integer_encoded.append(vocab_stoi[char])

if enc_type == "label":
return integer_encoded

Expand Down

0 comments on commit 832ada9

Please sign in to comment.