Hi,
When doing the following (might upload the large file if needed):
from group_selfies import (
fragment_mols,
Group,
MolecularGraph,
GroupGrammar
)
# extracting a set of reasonable groups using fragmentation
lotus = [x.strip() for i, x in enumerate(open("data/lotus_smiles.csv")) if i > 0]
subset = lotus
# import random
# random.seed(42)
# subset = random.sample(lotus, 1000)
fragments = fragment_mols(subset, convert=True, method="default") # use custom fragmentation technique
# Very slow
# fragments_mmpa = fragment_mols(subset, convert=True, method="mmpa") # use MMPA fragmentation
fragments_valid = remove_problematic_fragments(fragments)
vocab_fragment = dict([(f"frag{idx}", Group(f"frag{idx}", frag)) for idx, frag in enumerate(fragments_valid)])
# Very slow
# vocab_fragment_mmpa = dict([(f"frag{idx}", Group(f"frag{idx}", frag)) for idx, frag in enumerate(fragments_mmpa)])
grammar_fragment = GroupGrammar(vocab=vocab_fragment)
# Very slow
# grammar_fragment_mmpa = GroupGrammar(vocab=vocab_fragment_mmpa)
grammar_fragment.to_file("lotus_grammar.txt")
# Very slow
# grammar_fragment_mmpa.to_file("lotus_grammar_mmpa.txt")
the
vocab_fragment = dict([(f"frag{idx}", Group(f"frag{idx}", frag)) for idx, frag in enumerate(fragments_valid)])
fails as some of the fragments cannot be grouped, with following message error:
[16:55:17] Explicit valence for atom # 5 C, 5, is greater than permitted
Traceback (most recent call last):
File "/Users/adrutz/micromamba/envs/default/lib/python3.10/site-packages/group_selfies/utils/group_utils.py", line 73, in group_parser
Chem.SanitizeMol(mapped, sanitizeOps = Chem.SanitizeFlags.SANITIZE_ALL ^ Chem.SanitizeFlags.SANITIZE_CLEANUPCHIRALITY)# ^ Chem.SanitizeFlags.SANITIZE_FINDRADICALS)
rdkit.Chem.rdchem.AtomValenceException: Explicit valence for atom # 5 C, 5, is greater than permitted
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/adrutz/micromamba/envs/default/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-81-4bd9ed7a6acf>", line 1, in <module>
vocab_fragment = dict([(f"frag{idx}", Group(f"frag{idx}", frag)) for idx, frag in enumerate(fragments)])
File "<ipython-input-81-4bd9ed7a6acf>", line 1, in <listcomp>
vocab_fragment = dict([(f"frag{idx}", Group(f"frag{idx}", frag)) for idx, frag in enumerate(fragments)])
File "/Users/adrutz/micromamba/envs/default/lib/python3.10/site-packages/group_selfies/group_mol_graph.py", line 355, in __init__
self.mol = group_parser(self.canonsmiles, sanitize=sanitize)
File "/Users/adrutz/micromamba/envs/default/lib/python3.10/site-packages/group_selfies/utils/group_utils.py", line 77, in group_parser
raise ValueError(f'Issue in parsing group {s}')
ValueError: Issue in parsing group C[C@@H]1C(*1)C[C@H]2(*1)[C@H](C(*1)C(*1)[C@]3(C)C(*1)(*1)CC(*1)[C@H]32*1)[C@]1(CCC*1)C*1
Therefore, I had to do the following to make it work:
from group_selfies import (
fragment_mols,
Group,
MolecularGraph,
GroupGrammar
)
##
def remove_problematic_fragments(fragments):
valid_fragments = []
for fragment in fragments:
try:
Group(f"fragmentTest", fragment)
valid_fragments.append(fragment)
except:
print(f"Removing problematic fragment: {fragment}")
return valid_fragments
##
# extracting a set of reasonable groups using fragmentation
lotus = [x.strip() for i, x in enumerate(open("data/lotus_smiles.csv")) if i > 0]
subset = lotus
# import random
# random.seed(42)
# subset = random.sample(lotus, 1000)
fragments = fragment_mols(subset, convert=True, method="default") # use custom fragmentation technique
# Very slow
# fragments_mmpa = fragment_mols(subset, convert=True, method="mmpa") # use MMPA fragmentation
fragments_valid = remove_problematic_fragments(fragments)
vocab_fragment = dict([(f"frag{idx}", Group(f"frag{idx}", frag)) for idx, frag in enumerate(fragments_valid)])
# Very slow
# vocab_fragment_mmpa = dict([(f"frag{idx}", Group(f"frag{idx}", frag)) for idx, frag in enumerate(fragments_mmpa)])
grammar_fragment = GroupGrammar(vocab=vocab_fragment)
# Very slow
# grammar_fragment_mmpa = GroupGrammar(vocab=vocab_fragment_mmpa)
grammar_fragment.to_file("lotus_grammar.txt")
# Very slow
# grammar_fragment_mmpa.to_file("lotus_grammar_mmpa.txt")
I suppose this should not be the case?
Hi,
When doing the following (might upload the large file if needed):
the
fails as some of the fragments cannot be grouped, with following message error:
Therefore, I had to do the following to make it work:
I suppose this should not be the case?