kernel_gradient.cl 18.2 KB
Newer Older
1
2
// Gradient-based steepest descent minimizer
// Alternative to Solis-Wetts
3
4

__kernel void __attribute__ ((reqd_work_group_size(NUM_OF_THREADS_PER_BLOCK,1,1)))
5
6
gradient_minimizer(	
			char   dockpars_num_of_atoms,
7
8
9
10
11
			char   dockpars_num_of_atypes,
			int    dockpars_num_of_intraE_contributors,
			char   dockpars_gridsize_x,
			char   dockpars_gridsize_y,
			char   dockpars_gridsize_z,
12
13
14
							    		// g1 = gridsize_x
			uint   dockpars_gridsize_x_times_y, 		// g2 = gridsize_x * gridsize_y
			uint   dockpars_gridsize_x_times_y_times_z,	// g3 = gridsize_x * gridsize_y * gridsize_z
15
			float  dockpars_grid_spacing,
16
	 __global const float* restrict dockpars_fgrids, // This is too large to be allocated in __constant 
17
18
19
			int    dockpars_rotbondlist_length,
			float  dockpars_coeff_elec,
			float  dockpars_coeff_desolv,
20
21
	  __global      float* restrict dockpars_conformations_next,
	  __global      float* restrict dockpars_energies_next,
22
  	  __global 	int*   restrict dockpars_evals_of_new_entities,
23
	  __global      uint*  restrict dockpars_prng_states,
24
25
26
			int    dockpars_pop_size,
			int    dockpars_num_of_genes,
			float  dockpars_lsearch_rate,
27
			uint   dockpars_num_of_lsentities,
28
			float  dockpars_qasp,
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	     __constant float* atom_charges_const,
    	     __constant char*  atom_types_const,
	     __constant char*  intraE_contributors_const,
    	     __constant float* VWpars_AC_const,
    	     __constant float* VWpars_BD_const,
             __constant float* dspars_S_const,
             __constant float* dspars_V_const,
             __constant int*   rotlist_const,
    	     __constant float* ref_coords_x_const,
    	     __constant float* ref_coords_y_const,
             __constant float* ref_coords_z_const,
    	     __constant float* rotbonds_moving_vectors_const,
             __constant float* rotbonds_unit_vectors_const,
             __constant float* ref_orientation_quats_const,
43
44
45
	     __constant int*   rotbonds_const,
	     __constant int*   rotbonds_atoms_const,
	     __constant int*   num_rotating_atoms_per_rotbond_const,
46
    			// Specific gradient-minimizer args
Leonardo Solis's avatar
Leonardo Solis committed
47
		    	uint      	  gradMin_maxiters,
48
49
50
			uint      	  gradMin_maxfails
/*
			,
51
	    		float             gradMin_alpha,
52
    	     __constant float* gradMin_conformation_min_perturbation     // minimal values for gene perturbation, originally as the scalar "dxmin"
53
*/
54
55
56
57
58
59
60
61
62
)
//The GPU global function performs gradient-based minimization on (some) entities of conformations_next.
//The number of OpenCL compute units (CU) which should be started equals to num_of_minEntities*num_of_runs.
//This way the first num_of_lsentities entity of each population will be subjected to local search
//(and each CU carries out the algorithm for one entity).
//Since the first entity is always the best one in the current population,
//it is always tested according to the ls probability, and if it not to be
//subjected to local search, the entity with ID num_of_lsentities is selected instead of the first one (with ID 0).
{
63
64
	// -----------------------------------------------------------------------------
	// Determining entity, and its run, energy, and genotype
65
66
	__local int   entity_id;
	__local int   run_id;
Leonardo Solis's avatar
Leonardo Solis committed
67
68
69
70
71
72
73
74
75
76
  	__local float energy;
	__local float genotype[ACTUAL_GENOTYPE_LENGTH];

	// Variables for gradient minimizer
  	__local uint iteration_cnt;  	// minimizer iteration counter
	__local uint failure_cnt;  	// minimizer failure counter
	__local bool exit;		

	// Number of energy-evaluations counter
	__local int  evaluation_cnt;
77
78
79

	if (get_local_id(0) == 0)
	{
80
		// Choosing a random entity out of the entire population
Leonardo Solis's avatar
Leonardo Solis committed
81
/*
82
		run_id = get_group_id(0);
Leonardo Solis's avatar
Leonardo Solis committed
83
84
85
		//entity_id = (uint)(dockpars_pop_size * gpu_randf(dockpars_prng_states));
		entity_id = 0;
*/
86

Leonardo Solis's avatar
Leonardo Solis committed
87
///*
88
89
		run_id = get_group_id(0) / dockpars_num_of_lsentities;
		entity_id = get_group_id(0) % dockpars_num_of_lsentities;
90
91
92
93
94
95
96
97
98
99

		// Since entity 0 is the best one due to elitism,
		// it should be subjected to random selection
		if (entity_id == 0) {
			// If entity 0 is not selected according to LS-rate,
			// choosing an other entity
			if (100.0f*gpu_randf(dockpars_prng_states) > dockpars_lsearch_rate) {
				entity_id = dockpars_num_of_lsentities;					
			}
		}
Leonardo Solis's avatar
Leonardo Solis committed
100
//*/
101
		
Leonardo Solis's avatar
Leonardo Solis committed
102
		energy = dockpars_energies_next[run_id*dockpars_pop_size+entity_id];
103
104

		#if defined (DEBUG_MINIMIZER)
Leonardo Solis's avatar
Leonardo Solis committed
105
		printf("\nrun_id:  %5u entity_id: %5u  initial_energy: %.5f\n", run_id, entity_id, energy);
106
		#endif
Leonardo Solis's avatar
Leonardo Solis committed
107
108
109
110
111
112

		// Initializing gradient-minimizer counters and flags
    		iteration_cnt  = 0;
		failure_cnt    = 0;
		/*exit           = false;*/
		evaluation_cnt = 0;
113
114
	}

115
116
	barrier(CLK_LOCAL_MEM_FENCE);

Leonardo Solis's avatar
Leonardo Solis committed
117
  	async_work_group_copy(genotype,
118
119
120
  			      dockpars_conformations_next+(run_id*dockpars_pop_size+entity_id)*GENOTYPE_LENGTH_IN_GLOBMEM,
                              dockpars_num_of_genes, 0);

121
  	// -----------------------------------------------------------------------------
122
123
124
125
126
  	// Some OpenCL compilers don't allow declaring 
	// local variables within non-kernel functions.
	// These local variables must be declared in a kernel, 
	// and then passed to non-kernel functions.
	
127
	// Partial results for checking validity of genotype
Leonardo Solis's avatar
Leonardo Solis committed
128
	__local bool is_candidate_genotype_valid [ACTUAL_GENOTYPE_LENGTH];
129
           
130
	// Partial results of the gradient step
Leonardo Solis's avatar
Leonardo Solis committed
131
132
133
	__local float gradient          [ACTUAL_GENOTYPE_LENGTH];
	__local float candidate_energy;
	__local float candidate_genotype[ACTUAL_GENOTYPE_LENGTH];
134
135
136
137
138

	// -------------------------------------------------------------------
	// Calculate gradients (forces) for intermolecular energy
	// Derived from autodockdev/maps.py
	// -------------------------------------------------------------------
139
	// Gradient of the intermolecular energy per each ligand atom
140
141
142
	__local float gradient_inter_x[MAX_NUM_OF_ATOMS];
	__local float gradient_inter_y[MAX_NUM_OF_ATOMS];
	__local float gradient_inter_z[MAX_NUM_OF_ATOMS];
143

144
	// Gradient of the intramolecular energy per each ligand atom
145
146
147
148
	__local float gradient_intra_x[MAX_NUM_OF_ATOMS];
	__local float gradient_intra_y[MAX_NUM_OF_ATOMS];
	__local float gradient_intra_z[MAX_NUM_OF_ATOMS];
	__local float gradient_per_intracontributor[MAX_INTRAE_CONTRIBUTORS];
149

150
	// Accummulated gradient per each ligand atom
151
152
153
	__local float gradient_x[MAX_NUM_OF_ATOMS];
	__local float gradient_y[MAX_NUM_OF_ATOMS];
	__local float gradient_z[MAX_NUM_OF_ATOMS];	
154
155
	// -------------------------------------------------------------------

156
	// Ligand-atom position and partial energies
157
158
159
160
161
	__local float calc_coords_x[MAX_NUM_OF_ATOMS];
	__local float calc_coords_y[MAX_NUM_OF_ATOMS];
	__local float calc_coords_z[MAX_NUM_OF_ATOMS];
	__local float partial_energies[NUM_OF_THREADS_PER_BLOCK];

162
163
164
	#if defined (DEBUG_ENERGY_KERNEL5)
	__local float partial_interE[NUM_OF_THREADS_PER_BLOCK];
	__local float partial_intraE[NUM_OF_THREADS_PER_BLOCK];
165
	#endif
166
	// -----------------------------------------------------------------------------
167
168
169
170
171

	// Step size of the steepest descent
	float alpha;

	// Initilizing each (work-item)-specific alpha
Leonardo Solis's avatar
Leonardo Solis committed
172
173
174
	for(uint i = get_local_id(0); 
		 i < dockpars_num_of_genes; 
		 i+= NUM_OF_THREADS_PER_BLOCK) {
175
176
177
			if (i<3)      { alpha = TRANGENE_ALPHA;	}
			else if (i<6) { alpha = ROTAGENE_ALPHA; } 
			else 	      { alpha = TORSGENE_ALPHA;	}
Leonardo Solis's avatar
Leonardo Solis committed
178
179
180
181

			#if defined (DEBUG_MINIMIZER)
			//printf("(%-3u) %-15.15f\n", i, alpha);
			#endif
182
183
	}

184
	// Perform gradient-descent iterations
185

186
	#if 0
Leonardo Solis's avatar
Leonardo Solis committed
187
188
189
190
191
192
193
194
195
196
	// 7cpa
	float grid_center_x = 49.836;
	float grid_center_y = 17.609;
	float grid_center_z = 36.272;
	float ligand_center_x = 49.2216976744186;
	float ligand_center_y = 17.793953488372097;
	float ligand_center_z = 36.503837209302326;
	float shoemake_gene_u1 = 0.02;
	float shoemake_gene_u2 = 0.23;
	float shoemake_gene_u3 = 0.95;
197
	#endif
Leonardo Solis's avatar
Leonardo Solis committed
198

199
200
201
202
203
204
205
206
207
	#if 0
	// 3tmn
	float grid_center_x = 52.340;
	float grid_center_y = 15.029;
	float grid_center_z = -2.932;
	float ligand_center_x = 52.22740741;
	float ligand_center_y = 15.51751852;
	float ligand_center_z = -2.40896296;
	#endif
208

209
	do {
210
		#if 0
211
		// Specific input genotypes for a ligand with no rotatable bonds (1ac8).
Leonardo Solis's avatar
Leonardo Solis committed
212
		// Translation genes must be expressed in grids in OCLADock (genotype [0|1|2]).
213
214
		// However, for testing purposes, 
		// we start using translation values in real space (Angstrom): {31.79575, 93.743875, 47.699875}
Leonardo Solis's avatar
Leonardo Solis committed
215
		// Rotation genes are expresed in the Shoemake space: genotype [3|4|5]
216
		// xyz_gene_gridspace = gridcenter_gridspace + (input_gene_realspace - gridcenter_realspace)/gridsize
217
218

		// 1ac8				
Leonardo Solis's avatar
Leonardo Solis committed
219
220
221
222
223
224
		genotype[0] = 30 + (31.79575  - 31.924) / 0.375;
		genotype[1] = 30 + (93.743875 - 93.444) / 0.375;
		genotype[2] = 30 + (47.699875 - 47.924) / 0.375;
		genotype[3] = 0.1f;
		genotype[4] = 0.5f;
		genotype[5] = 0.9f;
225
		#endif
226

227
		#if 0
228
		// 3tmn
Leonardo Solis's avatar
Leonardo Solis committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
		genotype[0] = 30 + (ligand_center_x - grid_center_x) / 0.375;
		genotype[1] = 30 + (ligand_center_y - grid_center_y) / 0.375;
		genotype[2] = 30 + (ligand_center_z - grid_center_z) / 0.375;
		genotype[3] = shoemake_gene_u1;
		genotype[4] = shoemake_gene_u2;
		genotype[5] = shoemake_gene_u3;
		genotype[6] = 0.0f;
		genotype[7] = 0.0f;
		genotype[8] = 0.0f;
		genotype[9] = 0.0f;
		genotype[10] = 0.0f;
		genotype[11] = 0.0f;
		genotype[12] = 0.0f;
		genotype[13] = 0.0f;
		genotype[14] = 0.0f;
		genotype[15] = 0.0f;
		genotype[16] = 0.0f;
		genotype[17] = 0.0f;
		genotype[18] = 0.0f;
		genotype[19] = 0.0f;
		genotype[20] = 0.0f;
250
		#endif
251

252
253
254
255
256
257
258
259
		// Calculating gradient
		// =============================================================
		gpu_calc_gradient(
				dockpars_rotbondlist_length,
				dockpars_num_of_atoms,
				dockpars_gridsize_x,
				dockpars_gridsize_y,
				dockpars_gridsize_z,
260
261
262
								    	// g1 = gridsize_x
				dockpars_gridsize_x_times_y, 		// g2 = gridsize_x * gridsize_y
				dockpars_gridsize_x_times_y_times_z,	// g3 = gridsize_x * gridsize_y * gridsize_z
263
264
265
266
267
268
269
270
271
272
273
				dockpars_fgrids,
				dockpars_num_of_atypes,
				dockpars_num_of_intraE_contributors,
				dockpars_grid_spacing,
				dockpars_coeff_elec,
				dockpars_qasp,
				dockpars_coeff_desolv,
				// Some OpenCL compilers don't allow declaring 
				// local variables within non-kernel functions.
				// These local variables must be declared in a kernel, 
				// and then passed to non-kernel functions.
Leonardo Solis's avatar
Leonardo Solis committed
274
275
				genotype,
				&energy,
Leonardo Solis's avatar
Leonardo Solis committed
276
277
				&run_id,

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
				calc_coords_x,
				calc_coords_y,
				calc_coords_z,

			        atom_charges_const,
				atom_types_const,
				intraE_contributors_const,
				VWpars_AC_const,
				VWpars_BD_const,
				dspars_S_const,
				dspars_V_const,
				rotlist_const,
				ref_coords_x_const,
				ref_coords_y_const,
				ref_coords_z_const,
				rotbonds_moving_vectors_const,
				rotbonds_unit_vectors_const,
295
296
297
298
				ref_orientation_quats_const,
				rotbonds_const,
				rotbonds_atoms_const,
				num_rotating_atoms_per_rotbond_const
299
300
301
302
303
304
305
306
			 	// Gradient-related arguments
			 	// Calculate gradients (forces) for intermolecular energy
			 	// Derived from autodockdev/maps.py
				,
				dockpars_num_of_genes,
				gradient_inter_x,
				gradient_inter_y,
				gradient_inter_z,
307
308
309
				gradient_intra_x,
				gradient_intra_y,
				gradient_intra_z,
310
311
312
				gradient_x,
				gradient_y,
				gradient_z,
313
				gradient_per_intracontributor,
Leonardo Solis's avatar
Leonardo Solis committed
314
				gradient
315
316
				);
		// =============================================================
317

318
319
		barrier(CLK_LOCAL_MEM_FENCE);

320
321
		
		for(uint i = get_local_id(0); i < dockpars_num_of_genes; i+= NUM_OF_THREADS_PER_BLOCK) {
322
323

	     		// Taking step
Leonardo Solis's avatar
Leonardo Solis committed
324
			candidate_genotype[i] = genotype[i] - alpha * gradient[i];	
325
326

			#if defined (DEBUG_MINIMIZER)
Leonardo Solis's avatar
Leonardo Solis committed
327
			//printf("(%-3u) %-0.15f %-10.10f %-10.10f %-10.10f\n", i, alpha, genotype[i], gradient[i], candidate_genotype[i]);
328
			#endif
329

Leonardo Solis's avatar
Leonardo Solis committed
330
331
332
			// Checking if every gene of candidate_genotype
			// is neither a nan, not inf
   			is_candidate_genotype_valid[i] = (isnan(candidate_genotype[i]) == 0) && (isinf(candidate_genotype[i]) == 0);
333

Leonardo Solis's avatar
Leonardo Solis committed
334
			// Verifying that Shoemake genes 
335
336
			// do not get out of valid region
			if ((i > 2) && (i < 6)) {
Leonardo Solis's avatar
Leonardo Solis committed
337
338
339
340
341
				if (is_candidate_genotype_valid[i] == true) {
					//printf("BEFORE is_candidate_genotype_valid[%u]?: %s\n", i, (is_candidate_genotype_valid[i] == true)?"yes":"no");
					if ((candidate_genotype[i] < 0.0f) || (candidate_genotype[i] > 1.0f)){
						is_candidate_genotype_valid[i] = false;
						//printf("AFTER  is_candidate_genotype_valid[%u]?: %s\n", i, (is_candidate_genotype_valid[i] == true)?"yes":"no");
342
343
344
					}
				}
			}
345
	   	}
346
347
		
		barrier(CLK_LOCAL_MEM_FENCE);
348

349
350
351
352
353
354
355
356
		__local bool is_valid;

		// Reducing all "valid" values of genes
		// into their corresponding genotype
		if (get_local_id(0) == 0) { 
			is_valid = true;
			
		  	for(uint i = 0; i < dockpars_num_of_genes;i++) {
Leonardo Solis's avatar
Leonardo Solis committed
357
		    		is_valid = is_valid && is_candidate_genotype_valid[i];
358
359
			
				#if defined (DEBUG_MINIMIZER)
Leonardo Solis's avatar
Leonardo Solis committed
360
				//printf("is_candidate_genotype_valid[%u]?: %s\n", i, (is_candidate_genotype_valid[i] == true)?"yes":"no");
361
362
				#endif
		  	}
Leonardo Solis's avatar
Leonardo Solis committed
363
			/*
364
365
366
			if (is_valid == false) {
				exit = true;
			}
Leonardo Solis's avatar
Leonardo Solis committed
367
			*/
368
			#if defined (DEBUG_MINIMIZER)
369
			//printf("is_valid?: %s, exit?: %s\n", (is_valid == true)?"yes":"no", (exit == true)?"yes":"no");
Leonardo Solis's avatar
Leonardo Solis committed
370
371
372
			if (is_valid == false) {
				printf("Candidate genome is invalid!\n");
			}
373
			#endif
374
375
		}

376
		barrier(CLK_LOCAL_MEM_FENCE);
377

Leonardo Solis's avatar
Leonardo Solis committed
378
379
		/*if (exit == false) {*/
		if (is_valid == true) {
380
381
382
383
384
385
				// =============================================================
				gpu_calc_energy(dockpars_rotbondlist_length,
						dockpars_num_of_atoms,
						dockpars_gridsize_x,
						dockpars_gridsize_y,
						dockpars_gridsize_z,
386
387
388
										    	// g1 = gridsize_x
						dockpars_gridsize_x_times_y, 		// g2 = gridsize_x * gridsize_y
						dockpars_gridsize_x_times_y_times_z,	// g3 = gridsize_x * gridsize_y * gridsize_z
389
390
391
392
393
394
395
						dockpars_fgrids,
						dockpars_num_of_atypes,
						dockpars_num_of_intraE_contributors,
						dockpars_grid_spacing,
						dockpars_coeff_elec,
						dockpars_qasp,
						dockpars_coeff_desolv,
Leonardo Solis's avatar
Leonardo Solis committed
396
397
						candidate_genotype,
						&candidate_energy,
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
						&run_id,
						// Some OpenCL compilers don't allow declaring 
						// local variables within non-kernel functions.
						// These local variables must be declared in a kernel, 
						// and then passed to non-kernel functions.
						calc_coords_x,
						calc_coords_y,
						calc_coords_z,
						partial_energies,
						#if defined (DEBUG_ENERGY_KERNEL1)
						partial_interE,
						partial_intraE,
						#endif

						atom_charges_const,
						atom_types_const,
						intraE_contributors_const,
						VWpars_AC_const,
						VWpars_BD_const,
						dspars_S_const,
						dspars_V_const,
						rotlist_const,
						ref_coords_x_const,
						ref_coords_y_const,
						ref_coords_z_const,
						rotbonds_moving_vectors_const,
						rotbonds_unit_vectors_const,
						ref_orientation_quats_const
						);
				// =============================================================

				// Updating number of energy-evaluations counter
				if (get_local_id(0) == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
431
					evaluation_cnt = evaluation_cnt + 1;
432
				}
Leonardo Solis's avatar
Leonardo Solis committed
433
				barrier(CLK_LOCAL_MEM_FENCE);
434
435

				// Checking if E(candidate_genotype) < E(genotype)
Leonardo Solis's avatar
Leonardo Solis committed
436
				if (candidate_energy < energy){
437
438
					// Updating energy
					if (get_local_id(0) == 0) {				
Leonardo Solis's avatar
Leonardo Solis committed
439
						energy = candidate_energy;
440
441
442
443
444
445
446
					}

					for(uint i = get_local_id(0); 
					 	 i < dockpars_num_of_genes; 
					 	 i+= NUM_OF_THREADS_PER_BLOCK) {

						// Updating genotype
Leonardo Solis's avatar
Leonardo Solis committed
447
						genotype [i] = candidate_genotype[i];
448
449
			
						// Up-scaling alpha by one order magnitud
450
						alpha = alpha*/*10*/(5/(failure_cnt == 0?1:(failure_cnt)));
451
452

						#if defined (DEBUG_MINIMIZER)
Leonardo Solis's avatar
Leonardo Solis committed
453
						//printf("(%-3u) %-15.15f %-10.10f %-10.10f %-10.10f\n", i, alpha, genotype[i], gradient[i], candidate_genotype[i]);
454
455
456
457
458
						#endif
					}
				}
				// If E (candidate) is worse 
				else {
Leonardo Solis's avatar
Leonardo Solis committed
459
460
461
462
463
464
465
466
467
468
					// Update failure counter
					if (get_local_id(0) == 0) {
						failure_cnt = failure_cnt + 1;

						#if defined (DEBUG_MINIMIZER)
						printf("Candidate energy has not improved!\n");
						#endif
					}
					barrier(CLK_LOCAL_MEM_FENCE);

469
470
471
472
473
474
					// Down-scaling alpha by one order magnitud.
					// Genotype is not updated, meaning that search will be
					// started over from the same point from with different alpha
					for(uint i = get_local_id(0); 
						 i < dockpars_num_of_genes; 
						 i+= NUM_OF_THREADS_PER_BLOCK) {
Leonardo Solis's avatar
Leonardo Solis committed
475
						alpha = native_divide(alpha, 5*failure_cnt/*10*/);
476

Leonardo Solis's avatar
Leonardo Solis committed
477
478
479
480
						#if defined (DEBUG_MINIMIZER)
						//printf("(%-3u) %-15.15f\n", i, alpha);
						#endif
					}	
481
				} // End of energy comparison
Leonardo Solis's avatar
Leonardo Solis committed
482
			/*} // End of if(valid genotypes)*/
483
484
		} 
		else {
Leonardo Solis's avatar
Leonardo Solis committed
485
486
487
488
489
490
			// Update failure counter
			if (get_local_id(0) == 0) {
				failure_cnt = failure_cnt + 1;
			}
			barrier(CLK_LOCAL_MEM_FENCE);

491
492
493
494
495
496
			// Down-scaling alpha by one order magnitud.
			// Genotype is not updated, meaning that search will be
			// started over from the same point from with different alpha
			for(uint i = get_local_id(0); 
				 i < dockpars_num_of_genes; 
				 i+= NUM_OF_THREADS_PER_BLOCK) {
Leonardo Solis's avatar
Leonardo Solis committed
497
498
499
500
501
				alpha = native_divide(alpha, 5*failure_cnt/*10*/);

				#if defined (DEBUG_MINIMIZER)
				//printf("(%-3u) %-15.15f\n", i, alpha);
				#endif
502
503
			}
		} // End of if(exit==false)
504

505
		barrier(CLK_LOCAL_MEM_FENCE);
506

507
		// Updating number of stepest-descent iterations
508
		if (get_local_id(0) == 0) {
Leonardo Solis's avatar
Leonardo Solis committed
509
	    		iteration_cnt = iteration_cnt + 1;
510

511
			#if defined (DEBUG_MINIMIZER)
Leonardo Solis's avatar
Leonardo Solis committed
512
			printf("# mini-iters: %-3u, # ener-evals: %-3u, # failures: %-3u, energy: %f\n", iteration_cnt, evaluation_cnt, failure_cnt, energy);
513
			#endif
514

515
516
517
518
			#if defined (DEBUG_ENERGY_KERNEL5)
			printf("%-18s [%-5s]---{%-5s}   [%-10.8f]---{%-10.8f}\n", "-ENERGY-KERNEL5-", "GRIDS", "INTRA", partial_interE[0], partial_intraE[0]);
			#endif
		}
519

Leonardo Solis's avatar
Leonardo Solis committed
520
  	} while ((iteration_cnt < gradMin_maxiters) && (failure_cnt < gradMin_maxfails) /*&& (exit == false)*/);
521

522
	// -----------------------------------------------------------------------------
523

524
  	// Updating eval counter and energy
525
	if (get_local_id(0) == 0) {
526
		dockpars_evals_of_new_entities[run_id*dockpars_pop_size+entity_id] += evaluation_cnt;
Leonardo Solis's avatar
Leonardo Solis committed
527
		dockpars_energies_next[run_id*dockpars_pop_size+entity_id] = energy;
528

529
		#if defined (DEBUG_MINIMIZER)
Leonardo Solis's avatar
Leonardo Solis committed
530
		printf("-------> End of grad-min cycle, num of evals: %u, final energy: %.5f\n", evaluation_cnt, energy);
531
		#endif
532
	}
533

534
535
536
537
538
	// Mapping torsion angles
	for (uint gene_counter = get_local_id(0);
	     	  gene_counter < dockpars_num_of_genes;
	          gene_counter+= NUM_OF_THREADS_PER_BLOCK) {
		   if (gene_counter >= 6) {
Leonardo Solis's avatar
Leonardo Solis committed
539
			    map_angle(&(genotype[gene_counter]));
540
		   }
541
542
	}

543
	// Updating old offspring in population
544
545
546
	barrier(CLK_LOCAL_MEM_FENCE);

	async_work_group_copy(dockpars_conformations_next+(run_id*dockpars_pop_size+entity_id)*GENOTYPE_LENGTH_IN_GLOBMEM,
Leonardo Solis's avatar
Leonardo Solis committed
547
			      genotype,
548
			      dockpars_num_of_genes, 0);
549
}