#!/usr/bin/env python3 """ Example: Using Docking@HOME Python API Authors: OpenPeer AI, Riemann Computing Inc., Bleunomics, Andrew Magdy Kamal """ import asyncio from pathlib import Path import sys # Add parent directory to path if running standalone sys.path.insert(0, str(Path(__file__).parent.parent / "python")) from docking_at_home.cli import console async def main(): """Example workflow using Python API""" console.print("[bold]Docking@HOME Python API Example[/bold]\n") # Example 1: Submit a docking job console.print("[cyan]Example 1: Submitting a docking job[/cyan]") job_config = { "ligand": "examples/data/ligand.pdbqt", "receptor": "examples/data/receptor.pdbqt", "num_runs": 100, "use_gpu": True, "distributed": False } console.print(f"Configuration: {job_config}") job_id = "EXAMPLE_JOB_001" console.print(f"Job ID: {job_id}\n") # Example 2: Monitor job progress console.print("[cyan]Example 2: Monitoring job progress[/cyan]") progress_info = { "status": "running", "progress": 0.65, "runs_completed": 65, "total_runs": 100, "time_elapsed": 120.5, "estimated_completion": 185.0 } console.print(f"Status: {progress_info['status']}") console.print(f"Progress: {progress_info['progress']*100:.1f}%") console.print(f"Time elapsed: {progress_info['time_elapsed']:.1f}s\n") # Example 3: Retrieve and analyze results console.print("[cyan]Example 3: Analyzing results[/cyan]") results = { "job_id": job_id, "total_poses": 100, "unique_clusters": 12, "best_binding_energy": -8.45, "top_poses": [ {"rank": 1, "energy": -8.45, "rmsd": 0.85}, {"rank": 2, "energy": -8.23, "rmsd": 1.12}, {"rank": 3, "energy": -7.98, "rmsd": 1.45}, {"rank": 4, "energy": -7.76, "rmsd": 1.89}, {"rank": 5, "energy": -7.54, "rmsd": 2.01}, ] } console.print(f"Total poses generated: {results['total_poses']}") console.print(f"Unique clusters: {results['unique_clusters']}") console.print(f"Best binding energy: {results['best_binding_energy']} kcal/mol") console.print("\n[bold]Top 5 poses:[/bold]") for pose in results['top_poses']: console.print( f" Rank {pose['rank']}: " f"Energy = {pose['energy']:.2f} kcal/mol, " f"RMSD = {pose['rmsd']:.2f} Å" ) # Example 4: Using Cloud Agents for optimization console.print("\n[cyan]Example 4: AI-powered task optimization[/cyan]") try: from src.cloud_agents.orchestrator import CloudAgentsOrchestrator, Task, ComputeNode orchestrator = CloudAgentsOrchestrator() await orchestrator.initialize() # Register compute nodes node1 = ComputeNode( node_id="node_gpu_01", cpu_cores=16, gpu_available=True, gpu_type="RTX 3090", memory_gb=64 ) orchestrator.register_node(node1) # Submit tasks task = Task( task_id="task_001", ligand_file="ligand.pdbqt", receptor_file="receptor.pdbqt", priority="high" ) orchestrator.submit_task(task) # Get system statistics stats = orchestrator.get_system_statistics() console.print(f"Active nodes: {stats['active_nodes']}") console.print(f"GPU nodes: {stats['gpu_nodes']}") console.print(f"Total tasks: {stats['total_tasks']}") except ImportError: console.print("[yellow]Cloud Agents module not available[/yellow]") console.print("\n[bold green]Example completed successfully![/bold green]") if __name__ == "__main__": asyncio.run(main())