<jupyter_start><jupyter_text>CF explanationThe following example find CFs for a given molecule where the HIV activity is zero.<jupyter_code>def predictor_function(smiles, selfies):
    # print('inut:',smiles)
    labels = []
    for sml in smiles:
        nodes, adj_mat = gen_smiles2graph(sml)
        pred = gcnmodel((nodes[np.newaxis, ...], adj_mat[np.newaxis, ...])).numpy()
        labels.append(pred)

    labels = np.array(labels).flatten()
    bin_labels = np.where(labels > 0.5, np.ones(len(labels)), np.zeros(len(labels)))
    target_act = np.zeros(len(labels))
    return abs(bin_labels - target_act).astype(bool)
basic = exmol.get_basic_alphabet()
stoned_kwargs = {"num_samples": 1500, "alphabet": basic, "max_mutations": 2}
example_base = "C=CCN(CC=C)C(=O)Nc1ccc(C(=O)NN=Cc2cccc(OC)c2OC)cc1"
space = exmol.sample_space(
    example_base,
    predictor_function,
    stoned_kwargs={"num_samples": 1500, "alphabet": basic, "max_mutations": 2},
)
exps = exmol.cf_explain(space)
fkw = {"figsize": (8, 6)}
mpl.rc("axes", titlesize=12)
exmol.plot_cf(exps, figure_kwargs=fkw, mol_size=(450, 400), nrows=1)
plt.savefig("gnn-simple.png", dpi=180)
svg = exmol.insert_svg(exps, mol_fontsize=16)
# with open("gnn-simple.svg", "w") as f:
#    f.write(svg)
font = {"family": "normal", "weight": "normal", "size": 22}
exmol.plot_space(
    space,
    exps,
    figure_kwargs=fkw,
    mol_size=(300, 200),
    offset=0,
    cartoon=True,
    rasterized=True,
)
plt.scatter([], [], label="Counterfactual", s=150, color=plt.get_cmap("viridis")(1.0))
plt.scatter([], [], label="Same Class", s=150, color=plt.get_cmap("viridis")(0.0))
plt.legend(fontsize=22)
plt.tight_layout()
svg = exmol.insert_svg(exps, mol_fontsize=16)
# with open("gnn-space.svg", "w") as f:
# f.write(svg)
# skunk.display(svg)
exps = exmol.cf_explain(space, nmols=19)
fkw = {"figsize": (12, 10)}
mpl.rc("axes", titlesize=10)
exmol.plot_cf(
    exps, figure_kwargs=fkw, mol_size=(450, 400), mol_fontsize=26, nrows=4, ncols=5
)
plt.savefig("gnn-simple-20.png", bbox_inches="tight", dpi=300)
svg = exmol.insert_svg(exps, mol_fontsize=14)
# with open("gnn-simple-20.svg", "w") as f:
#    f.write(svg)
fkw = {"figsize": (8, 6)}
font = {"family": "normal", "weight": "normal", "size": 22}

exmol.plot_space(space, exps, figure_kwargs=fkw, mol_size=(350, 300), mol_fontsize=22)
plt.scatter([], [], label="Same Label", s=150, color=plt.get_cmap("viridis")(1.0))
plt.scatter([], [], label="Counterfactual", s=150, color=plt.get_cmap("viridis")(0.0))
plt.legend(fontsize=22)
plt.savefig("gnn-space.png", bbox_inches="tight", dpi=180)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19358533791523483, 'fraction_numerical': 0.042000763650248185, 'mean_word_length': 5.599496221662468, 'pattern_counts': {'":': 15, '<': 5, '<?xml version=': 0, '>': 6, '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': '665768', 'license': 'MIT', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1060, 'n_words': 185, 'path': 'paper/GNN.ipynb', 'repo_name': 'varnerjwpu/exmol', 'size': '2619'}