#!/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())