File size: 8,171 Bytes
4a8b134 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | #!/usr/bin/env python
"""
System Verification Script
Verifies all components are properly configured and working
Run with: python verify_system.py
"""
import os
import sys
import json
from pathlib import Path
def check_file_exists(file_path: str, description: str = "") -> bool:
"""Check if a file exists"""
desc = f" ({description})" if description else ""
if os.path.exists(file_path):
print(f" โ
{file_path}{desc}")
return True
else:
print(f" โ {file_path}{desc} - NOT FOUND")
return False
def check_python_version() -> bool:
"""Check Python version"""
print("\n๐ Python Version:")
version = f"{sys.version_info.major}.{sys.version_info.minor}"
if sys.version_info >= (3, 10):
print(f" โ
Python {version} (requirement: 3.10+)")
return True
else:
print(f" โ Python {version} (requirement: 3.10+)")
return False
def check_virtual_env() -> bool:
"""Check if in virtual environment"""
print("\n๐ง Virtual Environment:")
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
print(f" โ
Virtual environment detected")
return True
else:
print(f" โ ๏ธ Not in virtual environment (recommended for production)")
return False
def check_package(package_name: str, description: str = "") -> bool:
"""Check if a package is installed"""
try:
__import__(package_name)
desc = f" - {description}" if description else ""
print(f" โ
{package_name}{desc}")
return True
except ImportError:
desc = f" - {description}" if description else ""
print(f" โ {package_name}{desc} - NOT INSTALLED")
return False
def check_core_packages() -> bool:
"""Check core dependencies"""
print("\n๐ฆ Core Dependencies:")
core_packages = [
("fastapi", "FastAPI web framework"),
("uvicorn", "ASGI server"),
("pydantic", "Data validation"),
("numpy", "Numerical computing"),
("pandas", "Data processing"),
("requests", "HTTP client"),
("torch", "PyTorch deep learning"),
]
all_installed = True
for package, desc in core_packages:
if not check_package(package, desc):
all_installed = False
return all_installed
def check_optional_packages() -> bool:
"""Check optional but recommended packages"""
print("\nโญ Optional Packages (recommended):")
optional_packages = [
("DeepPurpose", "AI prediction model"),
("tdc", "Therapeutic Data Commons"),
]
all_installed = True
for package, desc in optional_packages:
result = check_package(package, desc)
if not result:
print(f" โน๏ธ To install: pip install git+https://github.com/kexinhuang12345/{package}.git")
all_installed = False
return all_installed
def check_gpu() -> bool:
"""Check GPU availability"""
print("\n๐ฎ GPU Support:")
try:
import torch
if torch.cuda.is_available():
print(f" โ
GPU detected: {torch.cuda.get_device_name(0)}")
print(f" CUDA Version: {torch.version.cuda}")
print(f" Device Count: {torch.cuda.device_count()}")
return True
else:
print(f" โน๏ธ No GPU detected - using CPU mode")
print(f" (System will still work, but predictions will be slower)")
return False
except ImportError:
print(f" โ PyTorch not installed")
return False
def check_project_structure() -> bool:
"""Check project file structure"""
print("\n๐ Project Structure:")
required_files = [
("app/main.py", "FastAPI application"),
("app/config.py", "Configuration"),
("app/models.py", "Data models"),
("app/local_tdc.py", "Local drug database"),
("app/pipelines/__init__.py", "Pipeline module"),
("app/pipelines/disease_targets.py", "Disease targets"),
("app/pipelines/protein_sequences.py", "Protein sequences"),
("app/pipelines/drug_library.py", "Drug library"),
("app/pipelines/ai_screening.py", "AI screening"),
("app/pipelines/result_processing.py", "Result processing"),
("requirements.txt", "Dependencies"),
("start.bat", "Windows startup"),
("start.sh", "Linux/Mac startup"),
("test_api.py", "Tests"),
("PRODUCTION_GUIDE.md", "Documentation"),
]
all_present = True
for file_path, description in required_files:
if not check_file_exists(file_path, description):
all_present = False
return all_present
def check_config_files() -> bool:
"""Check configuration values"""
print("\nโ๏ธ Configuration:")
try:
from app.config import settings
print(f" โ
Config loaded successfully")
print(f" Device: {settings.DEVICE}")
print(f" Max Drugs: {settings.MAX_DRUGS_FOR_DEMO}")
print(f" Batch Size: {settings.BATCH_SIZE}")
print(f" API Version: {settings.API_VERSION}")
return True
except Exception as e:
print(f" โ Config loading failed: {str(e)}")
return False
def check_data_models() -> bool:
"""Check data models"""
print("\n๐ Data Models:")
try:
from app.models import (
ScreeningRequest,
ScreeningResponse,
DrugCandidate,
DiseaseSearchRequest,
)
print(f" โ
All data models loaded")
return True
except Exception as e:
print(f" โ Data models failed: {str(e)}")
return False
def check_pipelines() -> bool:
"""Check pipeline modules"""
print("\n๐ Pipeline Modules:")
try:
from app.pipelines import (
DiseaseTargetPipeline,
ProteinSequencePipeline,
DrugLibraryPipeline,
AIScreeningPipeline,
ResultProcessingPipeline,
)
print(f" โ
All pipelines loaded")
return True
except Exception as e:
print(f" โ Pipelines failed: {str(e)}")
return False
def main():
"""Run all checks"""
print("\n" + "="*70)
print(" ๐งฌ DRUG REPURPOSING SYSTEM - VERIFICATION")
print("="*70)
checks = []
# Run all checks
checks.append(("Python Version", check_python_version()))
checks.append(("Virtual Environment", check_virtual_env()))
checks.append(("Core Dependencies", check_core_packages()))
checks.append(("Optional Dependencies", check_optional_packages()))
checks.append(("GPU Support", check_gpu()))
checks.append(("Project Structure", check_project_structure()))
checks.append(("Configuration", check_config_files()))
checks.append(("Data Models", check_data_models()))
checks.append(("Pipeline Modules", check_pipelines()))
# Summary
print("\n" + "="*70)
print(" ๐ VERIFICATION SUMMARY")
print("="*70)
passed = sum(1 for _, result in checks if result)
total = len(checks)
for check_name, result in checks:
status = "โ
PASS" if result else "โ FAIL"
print(f"{check_name:.<50} {status}")
print("\n" + "="*70)
if passed == total:
print("โ
ALL CHECKS PASSED - SYSTEM READY")
print("="*70)
print("\nNext steps:")
print(" 1. Start the API: python start.bat (Windows) or ./start.sh (Linux/Mac)")
print(" 2. Visit: http://localhost:8000/docs")
print(" 3. Test the /api/v1/screen endpoint")
print("\nFor help: See PRODUCTION_GUIDE.md or QUICK_START.md")
return 0
else:
failures = total - passed
print(f"โ ๏ธ {failures} CHECK(S) FAILED")
print("="*70)
print("\nSee above for details and recommendations.")
print("Missing packages can be installed with requirements.txt:")
print(" pip install -r requirements.txt")
return 1
if __name__ == "__main__":
sys.exit(main())
|