File size: 7,154 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
/**
* @file autodock_gpu.cuh
* @brief CUDA/CUDPP-accelerated AutoDock molecular docking engine
*
* This header defines GPU-accelerated molecular docking algorithms using
* CUDA and CUDPP primitives for high-performance parallel docking.
*
* @authors OpenPeer AI, Riemann Computing Inc., Bleunomics, Andrew Magdy Kamal
* @version 1.0.0
* @date 2025
*/
#ifndef DOCKING_AT_HOME_AUTODOCK_GPU_CUH
#define DOCKING_AT_HOME_AUTODOCK_GPU_CUH
#include <cuda_runtime.h>
#include <cudpp.h>
#include <vector>
#include <string>
namespace docking_at_home {
namespace autodock {
/**
* @struct Atom
* @brief Represents an atom in 3D space
*/
struct Atom {
float x, y, z; // Coordinates
int type; // Atom type
float charge; // Partial charge
float radius; // Van der Waals radius
};
/**
* @struct Ligand
* @brief Represents a ligand molecule
*/
struct Ligand {
std::vector<Atom> atoms;
int num_rotatable_bonds;
float center_x, center_y, center_z;
std::string name;
};
/**
* @struct Receptor
* @brief Represents a receptor (protein) molecule
*/
struct Receptor {
std::vector<Atom> atoms;
float grid_min_x, grid_min_y, grid_min_z;
float grid_max_x, grid_max_y, grid_max_z;
float grid_spacing;
std::string name;
};
/**
* @struct DockingParameters
* @brief Parameters for docking simulation
*/
struct DockingParameters {
int num_runs; // Number of docking runs
int num_evals; // Number of energy evaluations
int population_size; // GA population size
float rmsd_tolerance; // RMSD clustering tolerance
int max_generations; // Maximum GA generations
float mutation_rate; // GA mutation rate
float crossover_rate; // GA crossover rate
bool use_local_search; // Enable local search
int num_threads_per_block; // CUDA threads per block
int num_blocks; // CUDA blocks
};
/**
* @struct DockingPose
* @brief Represents a docking pose (conformation)
*/
struct DockingPose {
float translation[3]; // Translation vector
float rotation[4]; // Quaternion rotation
std::vector<float> torsions; // Torsion angles
float binding_energy; // Binding energy (kcal/mol)
float intermolecular_energy;
float internal_energy;
float torsional_energy;
float rank;
};
/**
* @class AutoDockGPU
* @brief GPU-accelerated AutoDock implementation
*/
class AutoDockGPU {
public:
AutoDockGPU();
~AutoDockGPU();
/**
* @brief Initialize GPU resources
* @param device_id CUDA device ID
* @return true if initialization successful
*/
bool initialize(int device_id = 0);
/**
* @brief Load ligand from PDBQT file
* @param filename Path to ligand file
* @param ligand Output ligand structure
* @return true if loading successful
*/
bool load_ligand(const std::string& filename, Ligand& ligand);
/**
* @brief Load receptor from PDBQT file
* @param filename Path to receptor file
* @param receptor Output receptor structure
* @return true if loading successful
*/
bool load_receptor(const std::string& filename, Receptor& receptor);
/**
* @brief Perform molecular docking
* @param ligand Input ligand
* @param receptor Input receptor
* @param params Docking parameters
* @param poses Output vector of docking poses
* @return true if docking successful
*/
bool dock(const Ligand& ligand,
const Receptor& receptor,
const DockingParameters& params,
std::vector<DockingPose>& poses);
/**
* @brief Get GPU device information
* @return Device info string
*/
std::string get_device_info();
/**
* @brief Get performance metrics
* @return Metrics string
*/
std::string get_performance_metrics();
/**
* @brief Cleanup GPU resources
*/
void cleanup();
private:
bool is_initialized_;
int device_id_;
cudaDeviceProp device_prop_;
CUDPPHandle cudpp_handle_;
// Device memory pointers
Atom* d_ligand_atoms_;
Atom* d_receptor_atoms_;
float* d_energy_grid_;
float* d_population_;
float* d_energies_;
// Host memory
size_t ligand_atoms_size_;
size_t receptor_atoms_size_;
// Performance tracking
float total_computation_time_;
int total_evaluations_;
// Private methods
bool allocate_device_memory(const Ligand& ligand, const Receptor& receptor);
bool transfer_to_device(const Ligand& ligand, const Receptor& receptor);
bool compute_energy_grid(const Receptor& receptor);
bool run_genetic_algorithm(const DockingParameters& params,
std::vector<DockingPose>& poses);
bool cluster_results(std::vector<DockingPose>& poses, float rmsd_tolerance);
void free_device_memory();
};
// CUDA kernel declarations
/**
* @brief Calculate pairwise energy between atoms (GPU kernel)
*/
__global__ void calculate_energy_kernel(
const Atom* ligand_atoms,
const Atom* receptor_atoms,
int num_ligand_atoms,
int num_receptor_atoms,
float* energies
);
/**
* @brief Genetic algorithm population evaluation (GPU kernel)
*/
__global__ void evaluate_population_kernel(
const float* population,
const Atom* ligand_atoms,
const Atom* receptor_atoms,
const float* energy_grid,
float* fitness_values,
int population_size,
int num_genes
);
/**
* @brief Genetic algorithm crossover operator (GPU kernel)
*/
__global__ void crossover_kernel(
float* population,
const float* parent_indices,
float crossover_rate,
int population_size,
int num_genes,
unsigned long long seed
);
/**
* @brief Genetic algorithm mutation operator (GPU kernel)
*/
__global__ void mutation_kernel(
float* population,
float mutation_rate,
int population_size,
int num_genes,
unsigned long long seed
);
/**
* @brief Local search optimization (GPU kernel)
*/
__global__ void local_search_kernel(
float* population,
const float* energy_grid,
float* fitness_values,
int population_size,
int num_genes,
int num_iterations
);
/**
* @brief RMSD calculation for clustering (GPU kernel)
*/
__global__ void rmsd_kernel(
const DockingPose* poses,
float* rmsd_matrix,
int num_poses
);
/**
* @brief Sort poses by energy using CUDPP
*/
bool sort_poses_by_energy(DockingPose* d_poses, int num_poses, CUDPPHandle cudpp);
/**
* @brief Parallel reduction to find minimum energy using CUDPP
*/
bool find_min_energy(const float* d_energies, int num_energies,
float& min_energy, CUDPPHandle cudpp);
} // namespace autodock
} // namespace docking_at_home
#endif // DOCKING_AT_HOME_AUTODOCK_GPU_CUH
|