# Identification and visualization of structural motifs in chemical compounds that are key to decision-making in QSAR and QSPR models

## Environment (uv)

Notebook-by-notebook descriptions for both QSAR and QSPR are in [`../docs/notebooks.md`](../docs/notebooks.md).

Run from the repository root:

```
uv venv .venv
uv sync
```

## Random Forest motif visualization

From the repository root:

```bash
./.venv/bin/python qspr/random-forest/smiles_motif_visualization.py --smiles "CC(=O)OC1=CC=CC=C1C(=O)O"
```

or visualize a filtered AqSolDB row:

```bash
./.venv/bin/python qspr/random-forest/smiles_motif_visualization.py --dataset-index 0 --top-n-bits 8
```

Outputs are written to `qspr/random-forest/outputs/` as:

- `*_motif_grid.png`: one panel per top bit, with normalized opacity-based highlighting
- `*_motif_overlay.png`: top active Morgan-bit motifs overlaid on a single molecule
- `*_motif_bits.csv`: bit ids, BorutaShap importance, occurrence counts, and motif fragments

The motif ranking in this script is computed from BorutaShap (SHAP-based) importances.
Useful runtime controls:

```bash
./.venv/bin/python qspr/random-forest/smiles_motif_visualization.py \
  --smiles "CC(=O)OC1=CC=CC=C1C(=O)O" \
  --boruta-trials 10 \
  --boruta-sample
```
