================================================================================
SUPPLEMENTARY PROTOCOL: AUTOMATED CHEMBL CURATION, FEATURE ENGINEERING, 
100-MODEL QSAR BENCHMARKING, AND VIRTUAL SCREENING (TARGET: GSK3B)

AUTHORS & COPYRIGHT: (c) V.N. Balaji and Jinu Raj. All rights reserved.
================================================================================

1. OVERVIEW
-----------
This document details the computational environment setup, directory architecture, 
input requirements, and execution steps for running the comprehensive ChEMBL QSAR 
pipeline for Cyclin-dependent kinase 2 (CDK2). 

The protocol is divided into two sequential phases:
- Phase 1: Data Curation & Feature Engineering (`CHEMBL_DOWNLOAD.py`)
- Phase 2: 100-Model Benchmarking, Consensus Ensemble, & Virtual Screening (`RUN_100MODELS.py`)

2. DIRECTORY ARCHITECTURE & SETUP (WSL2 UBUNTU)
-----------------------------------------------
The pipeline operates within a designated base workspace (`/mnt/f/TARGET_MODEL`). 
Before executing the scripts, initialize the directory structure and verify file 
placements using the following commands:

    # 1. Create the base working directory
    mkdir -p /mnt/f/TARGET_MODEL
    cd /mnt/f/TARGET_MODEL

    # 2. Verify script and reference database placement
    # Ensure both scripts are placed in `/mnt/f/TARGET_MODEL/`:
    #   - CHEMBL_DOWNLOAD.py
    #   - RUN_100MODELS.py

    # Ensure reference databases are placed in `/mnt/f/TARGET_MODEL/`:
    #   - KLIFS_SMILES_unique.csv
    #   - UNIVERSAL_DIVERSE_DECOYS_5000.csv

3. COMPUTATIONAL ENVIRONMENT & DEPENDENCIES
-------------------------------------------
The workflow requires Python 3.8+ with standard cheminformatics, machine learning, 
and deep learning libraries. GPU acceleration (CUDA) is highly recommended for 
the PyTorch deep tabular models in Phase 2.

    # Create and activate a dedicated Conda environment
    conda create -n qsar_pipeline python=3.10 -y
    conda activate qsar_pipeline

    # Install cheminformatics and data science stack
    conda install -c conda-forge rdkit pandas numpy matplotlib seaborn pillow requests -y

    # Install Machine Learning and Deep Learning stack (Phase 2 dependencies)
    pip install scikit-learn xgboost lightgbm catboost
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
    
    # Install ChEMBL API client and Word document generator
    pip install chembl_webresource_client python-docx scipy

4. INPUT REQUIREMENTS
---------------------
A. Reference Databases (Required for Phase 2 Virtual Screening):
   - `KLIFS_SMILES_unique.csv`: Used for cross-database target benchmarking and identifying novel hinge-binding cores.
   - `UNIVERSAL_DIVERSE_DECOYS_5000.csv`: Used as the negative/background dataset for calculating enrichment metrics (EF1%, EF5%).

B. Target Configuration File (`target.txt`):
   Phase 2 reads the target name from a text file. You must create a `target.txt` file containing the target name.

5. EXECUTION PROTOCOL (TARGET: GSK3B)
------------------------------------
**PHASE 1: Data Curation & Feature Engineering**
Execute the download script using the `-t` flag to fetch and process GSK3B (ChEMBL ID: CHEMBL301):

    cd /mnt/f/TARGET_MODEL
    python3 CHEMBL_DOWNLOAD.py -t "GSK3B"

**PHASE 2: 100-Model Benchmarking & Virtual Screening**
Create the target file and execute the benchmarking script. This script automatically detects GPU acceleration (CUDA) and reads the pre-processed `_CURATED.csv` and `_RAW_UNSCALED_FEATURES.csv` files generated in Phase 1.

    cd /mnt/f/TARGET_MODEL
    echo "GSK3B" > target.txt
    python3 RUN_100MODELS.py

6. GENERATED OUTPUTS (SUPPLEMENTARY DATA ARTIFACTS)
---------------------------------------------------
All outputs are saved to the target-specific subdirectory: `/mnt/f/TARGET_MODEL/GSK3B/`

**PHASE 1 OUTPUTS (Data Curation & Diversity Profiling):**
  1. `CHEMBL301_RAW.csv` & `CHEMBL301_CURATED.csv`: Unfiltered and strictly curated bioactivity records (IC50 -> pIC50).
  2. `CHEMBL301_RAW_UNSCALED_FEATURES.csv`: Raw 4,313-dimensional feature matrix.
  3. `CHEMBL301_DIVERSITY.png` (Fig 1), `CHEMBL301_TOP15_SCAFFOLDS.png` (Fig 2), `CHEMBL301_CLUSTER8_DECORATIONS.png` (Fig 3).
  4. `CHEMBL301_METHODS.docx`: Publication-ready Materials and Methods prose.

**PHASE 2 OUTPUTS (100-Model Benchmarking & Virtual Screening):**
  **Data Splits & Preprocessing:**
  5. `CHEMBL301_SPLIT_80_STRATIFIED_TRAIN.csv` & `CHEMBL301_SPLIT_20_STRATIFIED_VALTEST.csv`: The strict 10-bin stratified 80/20 data partitions.
  6. `CHEMBL301_FEATURES_ZSCORE_TRAIN.csv` & `CHEMBL301_normalization_constants.json`: Z-score scaled training features and the scaler dictionary (mean/std) to prevent data leakage.
  7. `CHEMBL301_100MODELS_FEATURE_PRUNING_REPORT.txt`: Log detailing the 5-stage feature pruning (Zero-Variance, Collinearity, Mutual Information).
  8. `CHEMBL301_TOP15_MI_FEATURES_STRATIFIED.csv`: Top 15 features ranked by Random Forest Gini importance and Mutual Information.

  **Model Performance & Predictions:**
  9. `CHEMBL301_FINAL_100_MODEL_RESULTS.csv`: Full benchmarking results (CV R2, RMSE, MAE, Enrichment metrics) for all 100 architectures.
  10. `CHEMBL301_100MODELS_SHEET1_ALL100_RANKED.csv` & `_SHEET2_CV_GT_050.csv`: Ranked performance sheets.
  11. `CHEMBL301_100MODELS_BENCHMARK.xlsx`: Master Excel workbook consolidating all performance metrics, feature importances, and the consensus ensemble summary.
  12. `CHEMBL301_RAW_PREDICTIONS.csv`: Raw pIC50 predictions across all 100 models for every compound in the dataset.
  13. `CHEMBL301_100MODELS_SUMMARY_METRICS.json` & `_RUNTIME_LOG.txt`: Metadata and computational runtime profiling logs.

  **Virtual Screening (KLIFS Reference Kinome):**
  14. `CHEMBL301_100MODELS_KLIFS_ALL_SCREENED.csv`: Full predictions on the KLIFS kinome dataset using the Top 5 ensemble.
  15. `CHEMBL301_100MODELS_KLIFS_TOP5_HITS.csv`: High-confidence consensus hits identified by the Top 5 ensemble.

  **Enrichment & Screening Visualizations:**
  16. `CHEMBL301_100MODELS_Figure_4_Top5_Consolidated.png` & `_Full100pct.png`: Decoy enrichment curves demonstrating retrospective screening performance (Figure 4).
  17. `CHEMBL301_100MODELS_KLIFS_Consensus_Bar.png`: Bar chart displaying the distribution of known vs. novel KLIFS hits across consensus tiers.
  18. `CHEMBL301_100MODELS_KLIFS_New_Consensus_5_Hits.png`: 3x3 2D molecular grid of the top strictly novel KLIFS hits.
  19. `CHEMBL301_100MODELS_KLIFS_New_Hits_CPK_ESP.png`: Advanced CPK/Electrostatic Potential rendering of the top novel hits (Figure 6 / Supp Fig S1).
  20. `CHEMBL301_ENRICHMENT_PLOTS/` (Directory): Contains 25 PNG files, charting the individual decoy enrichment curves for all 100 architectures.