<jupyter_start><jupyter_text>Testing self-specificity<jupyter_code>import rdkit.Chem as Chem

def test_one(reaction_smiles):
    retro_canonical = extract_one_template(reaction_smiles)
    if retro_canonical is None:
        return -1
    product = Chem.MolFromSmiles(reaction_smiles.split('>')[-1])
    pattern = Chem.MolFromSmarts(retro_canonical[1:].split(')>>')[0])
    matches = set(frozenset(x) for x in product.GetSubstructMatches(pattern))
    return len(matches)

inputs = data.loc[data['dataset']=='train']['rxn_smiles']
num_matches = Parallel(n_jobs=num_cores, verbose=3)(delayed(test_one)(i) for i in inputs)
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.DataFrame({'pop': num_matches})
plot = df['pop'].hist(bins=[x+0.5 for x in range(10)])
plot.set_title("Template self-specificity ({} total examples)".format(len(num_matches)))
plot.set_xlabel("Number of matches")
plot.set_ylabel("Number of examples")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14479166666666668, 'fraction_numerical': 0.009375, 'mean_word_length': 6.813008130081301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '208302', 'license': 'MIT', 'n_tokens_mistral': 350, 'n_tokens_neox': 336, 'n_words': 61, 'path': 'retrosim/scripts/extract_templates.ipynb', 'repo_name': 'medicine-wave/retrosim', 'size': '960'}