File size: 4,074 Bytes
35aaa09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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())