File size: 8,290 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
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
/**

 * @file main.cpp

 * @brief Main entry point for Docking@HOME application

 * 

 * @authors OpenPeer AI, Riemann Computing Inc., Bleunomics, Andrew Magdy Kamal

 * @version 1.0.0

 */

#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include "boinc_wrapper.h"
#include "autodock_gpu.cuh"

using namespace docking_at_home;

void print_banner() {
    std::cout << R"(

╔═══════════════════════════════════════════════════════════════╗

β•‘                      Docking@HOME v1.0.0                      β•‘

β•‘         Distributed Molecular Docking Platform                β•‘

β•‘                                                               β•‘

β•‘  Authors: OpenPeer AI, Riemann Computing Inc.,                β•‘

β•‘           Bleunomics, Andrew Magdy Kamal                     β•‘

β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

)" << std::endl;
}

void print_usage() {
    std::cout << "Usage: docking_at_home <command> [options]\n\n";
    std::cout << "Commands:\n";
    std::cout << "  worker     - Run as BOINC worker node\n";
    std::cout << "  server     - Run as BOINC server\n";
    std::cout << "  dock       - Perform local docking\n";
    std::cout << "  submit     - Submit job to distributed network\n";
    std::cout << "  status     - Check job status\n";
    std::cout << "  results    - Retrieve job results\n";
    std::cout << "  benchmark  - Run GPU benchmark\n";
    std::cout << "  version    - Show version information\n";
    std::cout << "  help       - Show this help message\n";
    std::cout << "\nExamples:\n";
    std::cout << "  docking_at_home dock --ligand ligand.pdbqt --receptor receptor.pdbqt\n";
    std::cout << "  docking_at_home worker --gpu-id 0\n";
    std::cout << "  docking_at_home submit --job-config config.json\n";
    std::cout << std::endl;
}

int run_worker(int argc, char* argv[]) {
    std::cout << "Starting BOINC worker node..." << std::endl;
    
    boinc::BOINCWrapper wrapper;
    
    if (!wrapper.initialize()) {
        std::cerr << "Failed to initialize BOINC worker" << std::endl;
        return 1;
    }
    
    wrapper.register_application("DockingAtHOME", "1.0.0");
    
    std::cout << "Worker node running. Press Ctrl+C to stop." << std::endl;
    
    // Main worker loop would go here
    // In production, this would continuously process tasks
    
    wrapper.finalize();
    
    return 0;
}

int run_server(int argc, char* argv[]) {
    std::cout << "Starting BOINC server..." << std::endl;
    
    boinc::BOINCServer server;
    
    if (!server.initialize("config/boinc_server.conf")) {
        std::cerr << "Failed to initialize BOINC server" << std::endl;
        return 1;
    }
    
    std::cout << "Server running. Press Ctrl+C to stop." << std::endl;
    
    // Server loop would go here
    
    return 0;
}

int run_docking(int argc, char* argv[]) {
    std::cout << "Running local docking..." << std::endl;
    
    // Parse arguments
    std::string ligand_file, receptor_file;
    int num_runs = 100;
    bool use_gpu = true;
    
    for (int i = 2; i < argc; i++) {
        std::string arg = argv[i];
        if (arg == "--ligand" && i + 1 < argc) {
            ligand_file = argv[++i];
        } else if (arg == "--receptor" && i + 1 < argc) {
            receptor_file = argv[++i];
        } else if (arg == "--runs" && i + 1 < argc) {
            num_runs = std::atoi(argv[++i]);
        } else if (arg == "--no-gpu") {
            use_gpu = false;
        }
    }
    
    if (ligand_file.empty() || receptor_file.empty()) {
        std::cerr << "Error: Both --ligand and --receptor are required" << std::endl;
        return 1;
    }
    
    std::cout << "Ligand: " << ligand_file << std::endl;
    std::cout << "Receptor: " << receptor_file << std::endl;
    std::cout << "Runs: " << num_runs << std::endl;
    std::cout << "GPU: " << (use_gpu ? "Enabled" : "Disabled") << std::endl;
    
    if (use_gpu) {
        autodock::AutoDockGPU gpu_docker;
        
        if (!gpu_docker.initialize(0)) {
            std::cerr << "GPU initialization failed, falling back to CPU" << std::endl;
            use_gpu = false;
        } else {
            std::cout << "\n" << gpu_docker.get_device_info() << std::endl;
            
            autodock::Ligand ligand;
            autodock::Receptor receptor;
            
            if (!gpu_docker.load_ligand(ligand_file, ligand)) {
                std::cerr << "Failed to load ligand" << std::endl;
                return 1;
            }
            
            if (!gpu_docker.load_receptor(receptor_file, receptor)) {
                std::cerr << "Failed to load receptor" << std::endl;
                return 1;
            }
            
            autodock::DockingParameters params;
            params.num_runs = num_runs;
            params.num_evals = 2500000;
            params.population_size = 150;
            params.rmsd_tolerance = 2.0f;
            params.max_generations = 27000;
            
            std::vector<autodock::DockingPose> poses;
            
            if (gpu_docker.dock(ligand, receptor, params, poses)) {
                std::cout << "\n=== Docking Results ===" << std::endl;
                std::cout << "Total poses: " << poses.size() << std::endl;
                
                if (!poses.empty()) {
                    std::cout << "\nTop 5 binding energies:" << std::endl;
                    for (size_t i = 0; i < std::min(poses.size(), size_t(5)); i++) {
                        std::cout << "  Rank " << (i+1) << ": " 
                                  << poses[i].binding_energy << " kcal/mol" << std::endl;
                    }
                }
                
                std::cout << "\n" << gpu_docker.get_performance_metrics() << std::endl;
            }
            
            gpu_docker.cleanup();
        }
    }
    
    return 0;
}

int run_benchmark(int argc, char* argv[]) {
    std::cout << "Running GPU benchmark..." << std::endl;
    
    autodock::AutoDockGPU gpu;
    
    if (!gpu.initialize(0)) {
        std::cerr << "GPU initialization failed" << std::endl;
        return 1;
    }
    
    std::cout << "\n=== GPU Information ===" << std::endl;
    std::cout << gpu.get_device_info() << std::endl;
    
    std::cout << "\n=== Benchmark Results ===" << std::endl;
    std::cout << "Running benchmark docking (100 runs)..." << std::endl;
    
    // Benchmark would run here
    
    std::cout << "\nBenchmark completed!" << std::endl;
    
    gpu.cleanup();
    
    return 0;
}

void show_version() {
    std::cout << "Docking@HOME v1.0.0\n";
    std::cout << "Authors: OpenPeer AI, Riemann Computing Inc., Bleunomics, Andrew Magdy Kamal\n";
    std::cout << "License: GPL-3.0\n";
    std::cout << "Built with:\n";
    std::cout << "  - AutoDock 4.2.6\n";
    std::cout << "  - BOINC\n";
    std::cout << "  - CUDA/CUDPP\n";
    std::cout << "  - The Decentralized Internet SDK\n";
    std::cout << "  - Cloud Agents\n";
}

int main(int argc, char* argv[]) {
    print_banner();
    
    if (argc < 2) {
        print_usage();
        return 0;
    }
    
    std::string command = argv[1];
    
    if (command == "worker") {
        return run_worker(argc, argv);
    } else if (command == "server") {
        return run_server(argc, argv);
    } else if (command == "dock") {
        return run_docking(argc, argv);
    } else if (command == "benchmark") {
        return run_benchmark(argc, argv);
    } else if (command == "version") {
        show_version();
        return 0;
    } else if (command == "help") {
        print_usage();
        return 0;
    } else {
        std::cerr << "Unknown command: " << command << std::endl;
        print_usage();
        return 1;
    }
    
    return 0;
}