Skip to content

rahulkhorana/protVizEnc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Protein Pocket Visualization

Analyze protein structures, predict binding pockets with P2Rank, and visualize them in 3D.

Features

  • 🧬 Fetch PDB structures from RCSB PDB
  • 🤖 Encode proteins with ESM2 (protein language model)
  • 🔍 Predict binding pockets using P2Rank (AlphaFold model)
  • 📊 Interactive 3D visualization with py3Dmol
  • 🌐 Clean web interface

Prerequisites

1. Python 3.12+

python --version  # Should be 3.12 or higher

2. P2Rank Installation

Download and install P2Rank:

# Create tools directory
mkdir -p ~/tools
cd ~/tools

# Download P2Rank 2.5.1
wget https://github.com/rdk/p2rank/releases/download/2.5.1/p2rank_2.5.1.tar.gz
tar -xzf p2rank_2.5.1.tar.gz

# Verify installation
~/tools/p2rank_2.5.1/prank -h

3. Set Environment Variable

Add to your ~/.zshrc or ~/.bashrc:

export P2RANK_BIN="$HOME/tools/p2rank_2.5.1/prank"

Then reload:

source ~/.zshrc  # or source ~/.bashrc

Installation

1. Clone/Navigate to Project

cd <BASE>/protVizEnc

2. Create Virtual Environment

python -m venv .env
source .env/bin/activate

3. Install Dependencies

pip install --upgrade pip
pip install fastapi uvicorn aiohttp biopython py3Dmol transformers torch

Running the Application

1. Activate Virtual Environment

cd <BASE>/protVizEnc
source .env/bin/activate

2. Start the Server

uvicorn backend.api:app --reload

You should see:

INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [XXXX] using WatchFiles
INFO:     Application startup complete.

3. Open in Browser

Navigate to:

http://127.0.0.1:8000/

4. Test the Application

  1. Enter a PDB ID (e.g., 1ubq)
  2. Click "Analyze"
  3. Wait for analysis (may take 10-30 seconds first time)
  4. View results:
    • Left panel: Predicted pockets with scores
    • Right panel: Interactive 3D visualization

Example PDB IDs to Try

  • 1ubq - Ubiquitin (small, fast, ~4 pockets)
  • 3aid - HIV-1 Protease
  • 1fbl - Protein kinase
  • 2src - Tyrosine kinase

API Usage

Endpoint: POST /api/analyze

Request:

{
  "source": "1ubq"
}

Response:

{
  "html": "<div>...</div>",
  "pockets": [
    {
      "id": 1,
      "name": "pocket1",
      "score": 4.71,
      "probability": 0.207,
      "combined_score": 0.445,
      "rank": 1,
      "center": [34.08, 38.75, 19.20],
      "residues": [
        {"chain": "A", "resnum": 11},
        {"chain": "A", "resnum": 34}
      ]
    }
  ]
}

Command Line Test

curl -X POST http://127.0.0.1:8000/api/analyze \
  -H "Content-Type: application/json" \
  -d '{"source": "1ubq"}' | jq '.pockets | length'

Project Structure

protVizEnc/
├── backend/
│   ├── api.py           # FastAPI server + CORS
│   ├── structures.py    # PDB fetching and parsing
│   ├── encoders.py      # ESM2 protein encoding
│   ├── pockets.py       # P2Rank integration
│   ├── annotations.py   # Structure annotations
│   └── viz.py           # py3Dmol visualization
├── frontend/
│   └── index.html       # Web interface
├── .env/                # Virtual environment
└── README.md

How It Works

Backend Flow

  1. Fetch Structure: Download PDB from RCSB or load local file
  2. Encode Protein: Run ESM2 transformer model for embeddings
  3. Predict Pockets: Run P2Rank with AlphaFold model
  4. Parse Results: Extract pocket scores, probabilities, residues
  5. Generate Viz: Create py3Dmol HTML with annotations
  6. Return JSON: Send HTML + pocket data to frontend

P2Rank Configuration

  • Model: alphafold (works without conservation data)
  • CSV Parsing: Strips whitespace from column names
  • Residue Format: Space-separated A_11 A_34 A_36
  • Output: Predictions CSV with scores, probabilities, centers

Troubleshooting

Port Already in Use

# Find and kill process on port 8000
lsof -ti:8000 | xargs kill -9

P2Rank Not Found

# Check environment variable
echo $P2RANK_BIN

# Should output: /Users/rahulkhorana/tools/p2rank_2.5.1/prank
# If not, add to ~/.zshrc and reload

No Pockets Detected

  • P2Rank may not find pockets for all proteins
  • Try a different PDB ID
  • Check server logs for errors

CORS Errors

  • Ensure server is running on http://127.0.0.1:8000
  • CORS is enabled for all origins in development

Development

Run Tests

# Test pocket detection
python -c "
import asyncio
from backend.pockets import run_fpocket_and_collect
from backend.structures import load_structure_and_pdb_text

async def test():
    _, pdb = await load_structure_and_pdb_text('1ubq')
    pockets = await run_fpocket_and_collect(pdb)
    print(f'Found {len(pockets)} pockets')

asyncio.run(test())
"

Stop Server

# Press Ctrl+C in terminal where uvicorn is running
# Or kill all uvicorn processes:
pkill -f uvicorn

Credits


License

MIT

About

visualize a pocket on local lol

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published