calcenergy.cl 43.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*

OCLADock, an OpenCL implementation of AutoDock 4.2 running a Lamarckian Genetic Algorithm
Copyright (C) 2017 TU Darmstadt, Embedded Systems and Applications Group, Germany. All rights reserved.

AutoDock is a Trade Mark of the Scripps Research Institute.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/


25
#include "calcenergy_basic.h"
Leonardo Solis's avatar
Leonardo Solis committed
26
27
28
29

// All related pragmas are in defines.h (accesible by host and device code)

void gpu_calc_energy(	    int    dockpars_rotbondlist_length,
Leonardo Solis's avatar
Leonardo Solis committed
30
31
32
33
			    char   dockpars_num_of_atoms,
			    char   dockpars_gridsize_x,
			    char   dockpars_gridsize_y,
			    char   dockpars_gridsize_z,
Leonardo Solis's avatar
Leonardo Solis committed
34
		#if defined (RESTRICT_ARGS)
Leonardo Solis's avatar
Leonardo Solis committed
35
			__global const float* restrict dockpars_fgrids, // cannot be allocated in __constant (too large)
Leonardo Solis's avatar
Leonardo Solis committed
36
		#else
Leonardo Solis's avatar
Leonardo Solis committed
37
			__global const float* dockpars_fgrids, // cannot be allocated in __constant (too large)
Leonardo Solis's avatar
Leonardo Solis committed
38
		#endif
Leonardo Solis's avatar
Leonardo Solis committed
39
40
41
42
43
44
		            char   dockpars_num_of_atypes,
		            int    dockpars_num_of_intraE_contributors,
			    float  dockpars_grid_spacing,
			    float  dockpars_coeff_elec,
			    float  dockpars_qasp,
			    float  dockpars_coeff_desolv,
Leonardo Solis's avatar
Leonardo Solis committed
45

Leonardo Solis's avatar
Leonardo Solis committed
46
47
48
		    __local float* genotype,
		    __local float* energy,
		    __local int*   run_id,
lvs's avatar
lvs committed
49

50
51
52
53
                    // 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
54
55
56
57
		    __local float* calc_coords_x,
		    __local float* calc_coords_y,
		    __local float* calc_coords_z,
		    __local float* partial_energies,
Leonardo Solis's avatar
Leonardo Solis committed
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
	         __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

		 // -------------------------------------------------------------------
		 // L30nardoSV
		 // Gradient-related arguments
		 // Calculate gradients (forces) for intermolecular energy
		 // Derived from autodockdev/maps.py
		 // -------------------------------------------------------------------
		
		 // "is_enabled_gradient_calc": enables gradient calculation.
		 // In Genetic-Generation: no need for gradients
		 // In Gradient-Minimizer: must calculate gradients
			    ,
		    __local bool*  is_enabled_gradient_calc,
	    	    __local float* gradient_inter_x,
	            __local float* gradient_inter_y,
	            __local float* gradient_inter_z
  		 // -------------------------------------------------------------------				
Leonardo Solis's avatar
Leonardo Solis committed
90
91
92
93
94
95
96
97
)

//The GPU device function calculates the energy of the entity described by genotype, dockpars and the liganddata
//arrays in constant memory and returns it in the energy parameter. The parameter run_id has to be equal to the ID
//of the run whose population includes the current entity (which can be determined with blockIdx.x), since this
//determines which reference orientation should be used.
{
	int contributor_counter;
lvs's avatar
lvs committed
98
	/*char*/uint atom1_id, atom2_id, atom1_typeid, atom2_typeid;
Leonardo Solis's avatar
Leonardo Solis committed
99
100
101
102
103
104
105
106
107
108
109

	// Name changed to distance_leo to avoid
	// errors as "distance" is the name of OpenCL function
	//float subx, suby, subz, distance;
	float subx, suby, subz, distance_leo;

	float x, y, z, dx, dy, dz, q;
	float cube[2][2][2];
	float weights[2][2][2];
	int x_low, x_high, y_low, y_high, z_low, z_high;

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

// -------------------------------------------------------------------
// L30nardoSV
// Replacing rotation genes: from spherical space to Shoemake space
// gene [0:2]: translation -> kept as original x, y, z
// gene [3:5]: rotation    -> transformed into Shoemake (u1: adimensional, u2&u3: sexagesimal)
// gene [6:N]: torsions	   -> kept as original angles	(all in sexagesimal)

// Shoemake ranges:
// u1: [0, 1]
// u2: [0: 2PI] or [0: 360]

// Random generator in the host is changed:
// LCG (original, myrand()) -> CPP std (rand())
// -------------------------------------------------------------------

// Original code commented out
/*
Leonardo Solis's avatar
Leonardo Solis committed
128
129
	float phi, theta, genrotangle, rotation_angle, sin_angle;
	float genrot_unitvec[3], rotation_unitvec[3], rotation_movingvec[3];
130
131
132
133
134
135
*/
	float rotation_angle, sin_angle;
	float rotation_unitvec[3], rotation_movingvec[3];



Leonardo Solis's avatar
Leonardo Solis committed
136
137
138
139
140
141
	int rotation_counter, rotation_list_element;
	float atom_to_rotate[3];
	int atom_id, rotbond_id;
	float quatrot_left_x, quatrot_left_y, quatrot_left_z, quatrot_left_q;
	float quatrot_temp_x, quatrot_temp_y, quatrot_temp_z, quatrot_temp_q;

142
143
144
145
146
147
148
149
150
151
        // 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.
	/*	
	__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];
	*/
Leonardo Solis's avatar
Leonardo Solis committed
152
153
154

	partial_energies[get_local_id(0)] = 0.0f;

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
	// -------------------------------------------------------------------
	// L30nardoSV
	// Calculate gradients (forces) for intermolecular energy
	// Derived from autodockdev/maps.py
	// -------------------------------------------------------------------
	if (*is_enabled_gradient_calc) {
		for (atom1_id = get_local_id(0);
		     atom1_id < dockpars_num_of_atoms;
		     atom1_id+= NUM_OF_THREADS_PER_BLOCK) {
			gradient_inter_x[atom1_id] = 0.0f;
			gradient_inter_y[atom1_id] = 0.0f;
			gradient_inter_z[atom1_id] = 0.0f;
		}
	}




Leonardo Solis's avatar
Leonardo Solis committed
173
174
	//CALCULATE CONFORMATION

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// -------------------------------------------------------------------
// L30nardoSV
// Replacing rotation genes: from spherical space to Shoemake space
// gene [0:2]: translation -> kept as original x, y, z
// gene [3:5]: rotation    -> transformed into Shoemake (u1: adimensional, u2&u3: sexagesimal)
// gene [6:N]: torsions	   -> kept as original angles	(all in sexagesimal)

// Shoemake ranges:
// u1: [0, 1]
// u2: [0: 2PI] or [0: 360]

// Random generator in the host is changed:
// LCG (original, myrand()) -> CPP std (rand())
// -------------------------------------------------------------------
/*
Leonardo Solis's avatar
Leonardo Solis committed
190
191
192
193
	//calculate vectors for general rotation
	phi         = genotype[3]*DEG_TO_RAD;
	theta       = genotype[4]*DEG_TO_RAD;
	genrotangle = genotype[5]*DEG_TO_RAD;
194
195
196
197
198
199
200
201
*/

	// Rotational genes in the Shoemake space expressed in radians
	float u1, u2, u3; 
	
	u1 = genotype[3];
	u2 = genotype[4]*DEG_TO_RAD;
	u3 = genotype[5]*DEG_TO_RAD;
Leonardo Solis's avatar
Leonardo Solis committed
202
203


204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#if defined (IMPROVE_GRID)
// -------------------------------------------------------------------
// L30nardoSV
// Replacing rotation genes: from spherical space to Shoemake space
// gene [0:2]: translation -> kept as original x, y, z
// gene [3:5]: rotation    -> transformed into Shoemake (u1: adimensional, u2&u3: sexagesimal)
// gene [6:N]: torsions	   -> kept as original angles	(all in sexagesimal)

// Shoemake ranges:
// u1: [0, 1]
// u2: [0: 2PI] or [0: 360]

// Random generator in the host is changed:
// LCG (original, myrand()) -> CPP std (rand())
// -------------------------------------------------------------------

// Original code is commented out
/*
Leonardo Solis's avatar
Leonardo Solis committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
	#if defined (NATIVE_PRECISION)
	sin_angle = native_sin(theta);
	genrot_unitvec [0] = sin_angle*native_cos(phi);
	genrot_unitvec [1] = sin_angle*native_sin(phi);
	genrot_unitvec [2] = native_cos(theta);
	#elif defined (HALF_PRECISION)
	sin_angle = half_sin(theta);
	genrot_unitvec [0] = sin_angle*half_cos(phi);
	genrot_unitvec [1] = sin_angle*half_sin(phi);
	genrot_unitvec [2] = half_cos(theta);
	#else	// Full precision
	sin_angle = sin(theta);
	genrot_unitvec [0] = sin_angle*cos(phi);
	genrot_unitvec [1] = sin_angle*sin(phi);
	genrot_unitvec [2] = cos(theta);
	#endif
238
*/
Leonardo Solis's avatar
Leonardo Solis committed
239
240
241
242
243
244
245

	// INTERMOLECULAR for-loop (intermediate results)
	// It stores a product of two chars
	unsigned int mul_tmp;

	unsigned char g1 = dockpars_gridsize_x;
	unsigned int  g2 = dockpars_gridsize_x * dockpars_gridsize_y;
246
  	unsigned int  g3 = dockpars_gridsize_x * dockpars_gridsize_y * dockpars_gridsize_z;
Leonardo Solis's avatar
Leonardo Solis committed
247
248
249
250
251
252

	unsigned int ylow_times_g1, yhigh_times_g1;
	unsigned int zlow_times_g2, zhigh_times_g2;

	unsigned int cube_000;
	unsigned int cube_100;
253
  	unsigned int cube_010;
Leonardo Solis's avatar
Leonardo Solis committed
254
255
	unsigned int cube_110;
	unsigned int cube_001;
256
257
258
  	unsigned int cube_101;
  	unsigned int cube_011;
  	unsigned int cube_111;
Leonardo Solis's avatar
Leonardo Solis committed
259
260

#else
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// -------------------------------------------------------------------
// L30nardoSV
// Replacing rotation genes: from spherical space to Shoemake space
// gene [0:2]: translation -> kept as original x, y, z
// gene [3:5]: rotation    -> transformed into Shoemake (u1: adimensional, u2&u3: sexagesimal)
// gene [6:N]: torsions	   -> kept as original angles	(all in sexagesimal)

// Shoemake ranges:
// u1: [0, 1]
// u2: [0: 2PI] or [0: 360]

// Random generator in the host is changed:
// LCG (original, myrand()) -> CPP std (rand())
// -------------------------------------------------------------------

// Original code commented out
/*
Leonardo Solis's avatar
Leonardo Solis committed
278
279
280
281
	sin_angle = sin(theta);
	genrot_unitvec [0] = sin_angle*cos(phi);
	genrot_unitvec [1] = sin_angle*sin(phi);
	genrot_unitvec [2] = cos(theta);
282
*/
Leonardo Solis's avatar
Leonardo Solis committed
283
284
#endif

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305





















Leonardo Solis's avatar
Leonardo Solis committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
	// ================================================
	// Iterating over elements of rotation list
	// ================================================
	for (rotation_counter = get_local_id(0);
	     rotation_counter < dockpars_rotbondlist_length;
	     rotation_counter+=NUM_OF_THREADS_PER_BLOCK)
	{
		rotation_list_element = rotlist_const[rotation_counter];

		if ((rotation_list_element & RLIST_DUMMY_MASK) == 0)	//if not dummy rotation
		{
			atom_id = rotation_list_element & RLIST_ATOMID_MASK;

			//capturing atom coordinates
			if ((rotation_list_element & RLIST_FIRSTROT_MASK) != 0)	//if firts rotation of this atom
			{
				atom_to_rotate[0] = ref_coords_x_const[atom_id];
				atom_to_rotate[1] = ref_coords_y_const[atom_id];
				atom_to_rotate[2] = ref_coords_z_const[atom_id];
			}
			else
			{
				atom_to_rotate[0] = calc_coords_x[atom_id];
				atom_to_rotate[1] = calc_coords_y[atom_id];
				atom_to_rotate[2] = calc_coords_z[atom_id];
			}

			//capturing rotation vectors and angle
			if ((rotation_list_element & RLIST_GENROT_MASK) != 0)	//if general rotation
			{
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// -------------------------------------------------------------------
// L30nardoSV
// Replacing rotation genes: from spherical space to Shoemake space
// gene [0:2]: translation -> kept as original x, y, z
// gene [3:5]: rotation    -> transformed into Shoemake (u1: adimensional, u2&u3: sexagesimal)
// gene [6:N]: torsions	   -> kept as original angles	(all in sexagesimal)

// Shoemake ranges:
// u1: [0, 1]
// u2: [0: 2PI] or [0: 360]

// Random generator in the host is changed:
// LCG (original, myrand()) -> CPP std (rand())
// -------------------------------------------------------------------
/*
Leonardo Solis's avatar
Leonardo Solis committed
351
352
353
				rotation_unitvec[0] = genrot_unitvec[0];
				rotation_unitvec[1] = genrot_unitvec[1];
				rotation_unitvec[2] = genrot_unitvec[2];
354
				rotation_angle = genrotangle;
355
356
357
358
359
*/
				// Moved back in here
				// Transforming Shoemake (u1, u2, u3) into quaternions
				// FIXME: add precision choices with preprocessor directives: 
				// NATIVE_PRECISION, HALF_PRECISION, Full precision
360

361
362
363

				// Used to test if u1 is within the valid range [0,1]
/*
364
365
366
367
368
369
370
				if (u1 > 1) {
					u1 = 0.9f;
				}

				if (u1 < 0) {
					u1 = 0.1f;
				}
371
*/
372
373
374
375
376
377

				quatrot_left_q = native_sqrt(1 - u1) * native_sin(u2); 
				quatrot_left_x = native_sqrt(1 - u1) * native_cos(u2);
				quatrot_left_y = native_sqrt(u1)     * native_sin(u3);
				quatrot_left_z = native_sqrt(u1)     * native_cos(u3);

378
				// Used to test if u1 is within the valid range [0,1]
379
380
381
382
383
384
/*
				if ((1-u1) < 0) {
					printf("u1:%f 1-u1:%f sqrt(1-u1):%f\n", u1, (1-u1), sqrt(1-u1));
				}
*/

385
386

				// Kept as the original
Leonardo Solis's avatar
Leonardo Solis committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
				rotation_movingvec[0] = genotype[0];
				rotation_movingvec[1] = genotype[1];
				rotation_movingvec[2] = genotype[2];
			}
			else	//if rotating around rotatable bond
			{
				rotbond_id = (rotation_list_element & RLIST_RBONDID_MASK) >> RLIST_RBONDID_SHIFT;

				rotation_unitvec[0] = rotbonds_unit_vectors_const[3*rotbond_id];
				rotation_unitvec[1] = rotbonds_unit_vectors_const[3*rotbond_id+1];
				rotation_unitvec[2] = rotbonds_unit_vectors_const[3*rotbond_id+2];
				rotation_angle = genotype[6+rotbond_id]*DEG_TO_RAD;

				rotation_movingvec[0] = rotbonds_moving_vectors_const[3*rotbond_id];
				rotation_movingvec[1] = rotbonds_moving_vectors_const[3*rotbond_id+1];
				rotation_movingvec[2] = rotbonds_moving_vectors_const[3*rotbond_id+2];

				//in addition, performing the first movement which is needed only if rotating around rotatable bond
				atom_to_rotate[0] -= rotation_movingvec[0];
				atom_to_rotate[1] -= rotation_movingvec[1];
				atom_to_rotate[2] -= rotation_movingvec[2];
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

// -------------------------------------------------------------------
// L30nardoSV
// Replacing rotation genes: from spherical space to Shoemake space
// gene [0:2]: translation -> kept as original x, y, z
// gene [3:5]: rotation    -> transformed into Shoemake (u1: adimensional, u2&u3: sexagesimal)
// gene [6:N]: torsions	   -> kept as original angles	(all in sexagesimal)

// Shoemake ranges:
// u1: [0, 1]
// u2: [0: 2PI] or [0: 360]

// Random generator in the host is changed:
// LCG (original, myrand()) -> CPP std (rand())
// -------------------------------------------------------------------
				// Moved back in here
				// Transforming torsion angles into quaternions
				// FIXME: add precision choices with preprocessor directives: 
				// NATIVE_PRECISION, HALF_PRECISION, Full precision
				rotation_angle = rotation_angle/2;
428
429
				quatrot_left_q = native_cos(rotation_angle);
				sin_angle      = native_sin(rotation_angle);
430
431
432
433
				quatrot_left_x = sin_angle*rotation_unitvec[0];
				quatrot_left_y = sin_angle*rotation_unitvec[1];
				quatrot_left_z = sin_angle*rotation_unitvec[2];

Leonardo Solis's avatar
Leonardo Solis committed
434
435
436
437
			}

			//performing rotation

438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459

// -------------------------------------------------------------------
// L30nardoSV
// Replacing rotation genes: from spherical space to Shoemake space
// gene [0:2]: translation -> kept as original x, y, z
// gene [3:5]: rotation    -> transformed into Shoemake (u1: adimensional, u2&u3: sexagesimal)
// gene [6:N]: torsions	   -> kept as original angles	(all in sexagesimal)

// Shoemake ranges:
// u1: [0, 1]
// u2: [0: 2PI] or [0: 360]

// Random generator in the host is changed:
// LCG (original, myrand()) -> CPP std (rand())
// -------------------------------------------------------------------

// Original code is commented out
// The purpose of this block of code is to ultimately
// calculate quatrot_left_q, quatrot_left_x, quatrot_left_y, quatrot_left_z.
// The calculation of these is moved to each respective case:
// a) if generarl rotation, b) if rotating around rotatable bond
/*
Leonardo Solis's avatar
Leonardo Solis committed
460
461
462
#if defined (NATIVE_PRECISION)
			rotation_angle = native_divide(rotation_angle,2);
			quatrot_left_q = native_cos(rotation_angle);
463
			sin_angle      = native_sin(rotation_angle);
Leonardo Solis's avatar
Leonardo Solis committed
464
465
466
#elif defined (HALF_PRECISION)
			rotation_angle = half_divide(rotation_angle,2);
			quatrot_left_q = half_cos(rotation_angle);
467
			sin_angle      = half_sin(rotation_angle);
Leonardo Solis's avatar
Leonardo Solis committed
468
469
470
#else	// Full precision
			rotation_angle = rotation_angle/2;
			quatrot_left_q = cos(rotation_angle);
471
			sin_angle      = sin(rotation_angle);
Leonardo Solis's avatar
Leonardo Solis committed
472
473
474
475
#endif
			quatrot_left_x = sin_angle*rotation_unitvec[0];
			quatrot_left_y = sin_angle*rotation_unitvec[1];
			quatrot_left_z = sin_angle*rotation_unitvec[2];
476
477
478
479
480
481
482
483
*/







Leonardo Solis's avatar
Leonardo Solis committed
484
485
486
487
488
489
490
491
492
493
494
495
496

			if ((rotation_list_element & RLIST_GENROT_MASK) != 0)	// if general rotation,
																														// two rotations should be performed
																														// (multiplying the quaternions)
			{
				//calculating quatrot_left*ref_orientation_quats_const,
				//which means that reference orientation rotation is the first
				quatrot_temp_q = quatrot_left_q;
				quatrot_temp_x = quatrot_left_x;
				quatrot_temp_y = quatrot_left_y;
				quatrot_temp_z = quatrot_left_z;

				quatrot_left_q = quatrot_temp_q*ref_orientation_quats_const[4*(*run_id)]-
497
498
499
						 quatrot_temp_x*ref_orientation_quats_const[4*(*run_id)+1]-
						 quatrot_temp_y*ref_orientation_quats_const[4*(*run_id)+2]-
						 quatrot_temp_z*ref_orientation_quats_const[4*(*run_id)+3];
Leonardo Solis's avatar
Leonardo Solis committed
500
				quatrot_left_x = quatrot_temp_q*ref_orientation_quats_const[4*(*run_id)+1]+
501
502
503
						 ref_orientation_quats_const[4*(*run_id)]*quatrot_temp_x+
						 quatrot_temp_y*ref_orientation_quats_const[4*(*run_id)+3]-
						 ref_orientation_quats_const[4*(*run_id)+2]*quatrot_temp_z;
Leonardo Solis's avatar
Leonardo Solis committed
504
				quatrot_left_y = quatrot_temp_q*ref_orientation_quats_const[4*(*run_id)+2]+
505
506
507
						 ref_orientation_quats_const[4*(*run_id)]*quatrot_temp_y+
						 ref_orientation_quats_const[4*(*run_id)+1]*quatrot_temp_z-
						 quatrot_temp_x*ref_orientation_quats_const[4*(*run_id)+3];
Leonardo Solis's avatar
Leonardo Solis committed
508
				quatrot_left_z = quatrot_temp_q*ref_orientation_quats_const[4*(*run_id)+3]+
509
510
511
						 ref_orientation_quats_const[4*(*run_id)]*quatrot_temp_z+
						 quatrot_temp_x*ref_orientation_quats_const[4*(*run_id)+2]-
						 ref_orientation_quats_const[4*(*run_id)+1]*quatrot_temp_y;
Leonardo Solis's avatar
Leonardo Solis committed
512
513
514
515

			}

			quatrot_temp_q = 0 -
516
517
518
					 quatrot_left_x*atom_to_rotate [0] -
					 quatrot_left_y*atom_to_rotate [1] -
					 quatrot_left_z*atom_to_rotate [2];
Leonardo Solis's avatar
Leonardo Solis committed
519
			quatrot_temp_x = quatrot_left_q*atom_to_rotate [0] +
520
521
					 quatrot_left_y*atom_to_rotate [2] -
					 quatrot_left_z*atom_to_rotate [1];
Leonardo Solis's avatar
Leonardo Solis committed
522
			quatrot_temp_y = quatrot_left_q*atom_to_rotate [1] -
523
524
					 quatrot_left_x*atom_to_rotate [2] +
					 quatrot_left_z*atom_to_rotate [0];
Leonardo Solis's avatar
Leonardo Solis committed
525
			quatrot_temp_z = quatrot_left_q*atom_to_rotate [2] +
526
527
					 quatrot_left_x*atom_to_rotate [1] -
					 quatrot_left_y*atom_to_rotate [0];
Leonardo Solis's avatar
Leonardo Solis committed
528
529

			atom_to_rotate [0] = 0 -
530
531
532
533
					  quatrot_temp_q*quatrot_left_x +
					  quatrot_temp_x*quatrot_left_q -
					  quatrot_temp_y*quatrot_left_z +
					  quatrot_temp_z*quatrot_left_y;
Leonardo Solis's avatar
Leonardo Solis committed
534
			atom_to_rotate [1] = 0 -
535
536
537
538
					  quatrot_temp_q*quatrot_left_y +
					  quatrot_temp_x*quatrot_left_z +
					  quatrot_temp_y*quatrot_left_q -
					  quatrot_temp_z*quatrot_left_x;
Leonardo Solis's avatar
Leonardo Solis committed
539
			atom_to_rotate [2] = 0 -
540
541
542
543
					  quatrot_temp_q*quatrot_left_z -
					  quatrot_temp_x*quatrot_left_y +
					  quatrot_temp_y*quatrot_left_x +
					  quatrot_temp_z*quatrot_left_q;
Leonardo Solis's avatar
Leonardo Solis committed
544
545
546
547
548
549
550
551
552
553
554
555

			//performing final movement and storing values
			calc_coords_x[atom_id] = atom_to_rotate [0] + rotation_movingvec[0];
			calc_coords_y[atom_id] = atom_to_rotate [1] + rotation_movingvec[1];
			calc_coords_z[atom_id] = atom_to_rotate [2] + rotation_movingvec[2];

		} // End if-statement not dummy rotation

		barrier(CLK_LOCAL_MEM_FENCE);

	} // End rotation_counter for-loop

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611




	// -------------------------------------------------------------------
	// L30nardoSV
	// Calculate gradients (forces) for intermolecular energy
	// Derived from autodockdev/maps.py
	// -------------------------------------------------------------------
	// Variables to store gradient of 
	// the intermolecular energy per each ligand atom

	// 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.
	/*
	__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];
	*/

	// Deltas dx, dy, dz are already normalized 
	// (by host/src/getparameters.cpp) in OCLaDock.
	// The correspondance between vertices in xyz axes is:
	// 0, 1, 2, 3, 4, 5, 6, 7  and  000, 100, 010, 001, 101, 110, 011, 111
	/*
            deltas: (x-x0)/(x1-x0), (y-y0...
            vertices: (000, 100, 010, 001, 101, 110, 011, 111)        

                  Z
                  '
                  3 - - - - 6
                 /.        /|
                4 - - - - 7 |
                | '       | |
                | 0 - - - + 2 -- Y
                '/        |/
                1 - - - - 5
               /
              X
	*/

	// Intermediate values for vectors in x-direction
	float x10, x52, x43, x76;
	float vx_z0, vx_z1;

	// Intermediate values for vectors in y-direction
	float y20, y51, y63, y74;
	float vy_z0, vy_z1;

	// Intermediate values for vectors in z-direction
	float z30, z41, z62, z75;
	float vz_y0, vz_y1;
	// -------------------------------------------------------------------

Leonardo Solis's avatar
Leonardo Solis committed
612
613
614
615
616
617
618
619
620
621
622
623
624
625
	// ================================================
	// CALCULATE INTERMOLECULAR ENERGY
	// ================================================
	for (atom1_id = get_local_id(0);
	     atom1_id < dockpars_num_of_atoms;
	     atom1_id+= NUM_OF_THREADS_PER_BLOCK)
	{
		atom1_typeid = atom_types_const[atom1_id];
		x = calc_coords_x[atom1_id];
		y = calc_coords_y[atom1_id];
		z = calc_coords_z[atom1_id];
		q = atom_charges_const[atom1_id];

		if ((x < 0) || (y < 0) || (z < 0) || (x >= dockpars_gridsize_x-1)
626
627
				                  || (y >= dockpars_gridsize_y-1)
						  || (z >= dockpars_gridsize_z-1)){
Leonardo Solis's avatar
Leonardo Solis committed
628
			partial_energies[get_local_id(0)] += 16777216.0f; //100000.0f;
629
630
631
632
633
634
635
636
637
638
639
640
641
			
			// -------------------------------------------------------------------
			// L30nardoSV
			// Calculate gradients (forces) for intermolecular energy
			// Derived from autodockdev/maps.py
			// -------------------------------------------------------------------

			if (*is_enabled_gradient_calc) {
				// Penalty values are valid as long as they are high
				gradient_inter_x[atom1_id] += 16777216.0f;
				gradient_inter_y[atom1_id] += 16777216.0f;
				gradient_inter_z[atom1_id] += 16777216.0f;
			}
Leonardo Solis's avatar
Leonardo Solis committed
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
		}
		else
		{
			//get coordinates
			x_low = (int)floor(x); y_low = (int)floor(y); z_low = (int)floor(z);
			x_high = (int)ceil(x); y_high = (int)ceil(y); z_high = (int)ceil(z);
			dx = x - x_low; dy = y - y_low; dz = z - z_low;

			//calculate interpolation weights
			weights [0][0][0] = (1-dx)*(1-dy)*(1-dz);
			weights [1][0][0] = dx*(1-dy)*(1-dz);
			weights [0][1][0] = (1-dx)*dy*(1-dz);
			weights [1][1][0] = dx*dy*(1-dz);
			weights [0][0][1] = (1-dx)*(1-dy)*dz;
			weights [1][0][1] = dx*(1-dy)*dz;
			weights [0][1][1] = (1-dx)*dy*dz;
			weights [1][1][1] = dx*dy*dz;

			//capturing affinity values
#if defined (IMPROVE_GRID)
			ylow_times_g1  = y_low*g1;
			yhigh_times_g1 = y_high*g1;
664
		  	zlow_times_g2  = z_low*g2;
Leonardo Solis's avatar
Leonardo Solis committed
665
666
667
668
669
670
671
672
673
674
675
676
677
678
			zhigh_times_g2 = z_high*g2;

			cube_000 = x_low  + ylow_times_g1  + zlow_times_g2;
			cube_100 = x_high + ylow_times_g1  + zlow_times_g2;
			cube_010 = x_low  + yhigh_times_g1 + zlow_times_g2;
			cube_110 = x_high + yhigh_times_g1 + zlow_times_g2;
			cube_001 = x_low  + ylow_times_g1  + zhigh_times_g2;
			cube_101 = x_high + ylow_times_g1  + zhigh_times_g2;
			cube_011 = x_low  + yhigh_times_g1 + zhigh_times_g2;
			cube_111 = x_high + yhigh_times_g1 + zhigh_times_g2;
			mul_tmp = atom1_typeid*g3;

			cube [0][0][0] = *(dockpars_fgrids + cube_000 + mul_tmp);
			cube [1][0][0] = *(dockpars_fgrids + cube_100 + mul_tmp);
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
			cube [0][1][0] = *(dockpars_fgrids + cube_010 + mul_tmp);
		        cube [1][1][0] = *(dockpars_fgrids + cube_110 + mul_tmp);
		        cube [0][0][1] = *(dockpars_fgrids + cube_001 + mul_tmp);
			cube [1][0][1] = *(dockpars_fgrids + cube_101 + mul_tmp);
                        cube [0][1][1] = *(dockpars_fgrids + cube_011 + mul_tmp);
                        cube [1][1][1] = *(dockpars_fgrids + cube_111 + mul_tmp);

			// -------------------------------------------------------------------
			// L30nardoSV
			// Calculate gradients (forces) corresponding to 
			// "atype" intermolecular energy
			// Derived from autodockdev/maps.py
			// -------------------------------------------------------------------

			if (*is_enabled_gradient_calc) {
				// vector in x-direction
				/*
				x10 = grid[int(vertices[1])] - grid[int(vertices[0])] # z = 0
				x52 = grid[int(vertices[5])] - grid[int(vertices[2])] # z = 0
				x43 = grid[int(vertices[4])] - grid[int(vertices[3])] # z = 1
				x76 = grid[int(vertices[7])] - grid[int(vertices[6])] # z = 1
				vx_z0 = (1-yd) * x10 + yd * x52     #  z = 0
				vx_z1 = (1-yd) * x43 + yd * x76     #  z = 1
				gradient[0] = (1-zd) * vx_z0 + zd * vx_z1 
				*/

				x10 = cube [1][0][0] - cube [0][0][0]; // z = 0
				x52 = cube [1][1][0] - cube [0][1][0]; // z = 0
				x43 = cube [1][0][1] - cube [0][0][1]; // z = 1
				x76 = cube [1][1][1] - cube [0][1][1]; // z = 1
				vx_z0 = (1 - dy) * x10 + dy * x52;     // z = 0
				vx_z1 = (1 - dy) * x43 + dy * x76;     // z = 1
711
				gradient_inter_x[atom1_id] += (1 - dz) * vx_z0 + dz * vx_z1;
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729

				// vector in y-direction
				/*
				y20 = grid[int(vertices[2])] - grid[int(vertices[0])] # z = 0
				y51 = grid[int(vertices[5])] - grid[int(vertices[1])] # z = 0
				y63 = grid[int(vertices[6])] - grid[int(vertices[3])] # z = 1
				y74 = grid[int(vertices[7])] - grid[int(vertices[4])] # z = 1
				vy_z0 = (1-xd) * y20 + xd * y51     #  z = 0
				vy_z1 = (1-xd) * y63 + xd * y74     #  z = 1
				gradient[1] = (1-zd) * vy_z0 + zd * vy_z1
				*/

				y20 = cube[0][1][0] - cube [0][0][0];	// z = 0
				y51 = cube[1][1][0] - cube [1][0][0];	// z = 0
				y63 = cube[0][1][1] - cube [0][0][1];	// z = 1
				y74 = cube[1][1][1] - cube [1][0][1];	// z = 1
				vy_z0 = (1 - dx) * y20 + dx * y51;	// z = 0
				vy_z1 = (1 - dx) * y63 + dx * y74;	// z = 1
730
				gradient_inter_y[atom1_id] += (1 - dz) * vy_z0 + dz * vy_z1;
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748

				// vectors in z-direction
				/*	
				z30 = grid[int(vertices[3])] - grid[int(vertices[0])] # y = 0
				z41 = grid[int(vertices[4])] - grid[int(vertices[1])] # y = 0
				z62 = grid[int(vertices[6])] - grid[int(vertices[2])] # y = 1
				z75 = grid[int(vertices[7])] - grid[int(vertices[5])] # y = 1
				vz_y0 = (1-xd) * z30 + xd * z41     # y = 0
				vz_y1 = (1-xd) * z62 + xd * z75     # y = 1
				gradient[2] = (1-yd) * vz_y0 + yd * vz_y1
				*/

				z30 = cube [0][0][1] - cube [0][0][0];	// y = 0
				z41 = cube [1][0][1] - cube [1][0][0];	// y = 0
				z62 = cube [0][1][1] - cube [0][1][0];	// y = 1 
				z75 = cube [1][1][1] - cube [1][1][0];	// y = 1
				vz_y0 = (1 - dx) * z30 + dx * z41;	// y = 0
				vz_y1 = (1 - dx) * z62 + dx * z75;	// y = 1
749
				gradient_inter_z[atom1_id] += (1 - dy) * vz_y0 + dy * vz_y1;
750
751
752
753
			}
			// -------------------------------------------------------------------
			// -------------------------------------------------------------------
			
Leonardo Solis's avatar
Leonardo Solis committed
754
#else
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
			// -------------------------------------------------------------------
			// L30nardoSV
			// FIXME: this block within the "#else" preprocessor directive 
			// provides NO gradient corresponding to "atype" intermolecular energy
			// -------------------------------------------------------------------	

			cube [0][0][0] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_low, x_low);
			cube [1][0][0] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_low, x_high);
			cube [0][1][0] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_high, x_low);
			cube [1][1][0] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,					      							      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_high, x_high);
			cube [0][0][1] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_low, x_low);
			cube [1][0][1] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_low, x_high);
			cube [0][1][1] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_high, x_low);
			cube [1][1][1] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_high, x_high);
Leonardo Solis's avatar
Leonardo Solis committed
800
801
802
803
804
805
806
807
808
809
810
811
#endif

			//calculating affinity energy
			partial_energies[get_local_id(0)] += TRILININTERPOL(cube, weights);

			//capturing electrostatic values
			atom1_typeid = dockpars_num_of_atypes;

#if defined (IMPROVE_GRID)
			mul_tmp = atom1_typeid*g3;
			cube [0][0][0] = *(dockpars_fgrids + cube_000 + mul_tmp);
			cube [1][0][0] = *(dockpars_fgrids + cube_100 + mul_tmp);
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
      			cube [0][1][0] = *(dockpars_fgrids + cube_010 + mul_tmp);
      			cube [1][1][0] = *(dockpars_fgrids + cube_110 + mul_tmp);
		       	cube [0][0][1] = *(dockpars_fgrids + cube_001 + mul_tmp);
		        cube [1][0][1] = *(dockpars_fgrids + cube_101 + mul_tmp);
		        cube [0][1][1] = *(dockpars_fgrids + cube_011 + mul_tmp);
		        cube [1][1][1] = *(dockpars_fgrids + cube_111 + mul_tmp);

			// -------------------------------------------------------------------
			// L30nardoSV
			// Calculate gradients (forces) corresponding to 
			// "elec" intermolecular energy
			// Derived from autodockdev/maps.py
			// -------------------------------------------------------------------

			if (*is_enabled_gradient_calc) {
				// vector in x-direction
				x10 = cube [1][0][0] - cube [0][0][0]; // z = 0
				x52 = cube [1][1][0] - cube [0][1][0]; // z = 0
				x43 = cube [1][0][1] - cube [0][0][1]; // z = 1
				x76 = cube [1][1][1] - cube [0][1][1]; // z = 1
				vx_z0 = (1 - dy) * x10 + dy * x52;     // z = 0
				vx_z1 = (1 - dy) * x43 + dy * x76;     // z = 1
				gradient_inter_x[atom1_id] += (1 - dz) * vx_z0 + dz * vx_z1;

				// vector in y-direction
				y20 = cube[0][1][0] - cube [0][0][0];	// z = 0
				y51 = cube[1][1][0] - cube [1][0][0];	// z = 0
				y63 = cube[0][1][1] - cube [0][0][1];	// z = 1
				y74 = cube[1][1][1] - cube [1][0][1];	// z = 1
				vy_z0 = (1 - dx) * y20 + dx * y51;	// z = 0
				vy_z1 = (1 - dx) * y63 + dx * y74;	// z = 1
				gradient_inter_y[atom1_id] += (1 - dz) * vy_z0 + dz * vy_z1;

				// vectors in z-direction
				z30 = cube [0][0][1] - cube [0][0][0];	// y = 0
				z41 = cube [1][0][1] - cube [1][0][0];	// y = 0
				z62 = cube [0][1][1] - cube [0][1][0];	// y = 1 
				z75 = cube [1][1][1] - cube [1][1][0];	// y = 1
				vz_y0 = (1 - dx) * z30 + dx * z41;	// y = 0
				vz_y1 = (1 - dx) * z62 + dx * z75;	// y = 1
				gradient_inter_z[atom1_id] += (1 - dy) * vz_y0 + dy * vz_y1;
			}
			// -------------------------------------------------------------------
			// -------------------------------------------------------------------
Leonardo Solis's avatar
Leonardo Solis committed
856
857

#else
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
			// -------------------------------------------------------------------
			// L30nardoSV
			// FIXME: this block within the "#else" preprocessor directive 
			// provides NO gradient corresponding to "elec" intermolecular energy
			// -------------------------------------------------------------------

			cube [0][0][0] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y, 
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_low, x_low);
			cube [1][0][0] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_low, x_high);
			cube [0][1][0] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
                                                      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_high, x_low);
			cube [1][1][0] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_high, x_high);
			cube [0][0][1] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_low, x_low);
			cube [1][0][1] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_low, x_high);
			cube [0][1][1] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_high, x_low);
			cube [1][1][1] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_high, x_high);
Leonardo Solis's avatar
Leonardo Solis committed
904
905
906
907
908
909
910
911
912
913
914
915
#endif

			//calculating electrosatic energy
			partial_energies[get_local_id(0)] += q * TRILININTERPOL(cube, weights);

			//capturing desolvation values
			atom1_typeid = dockpars_num_of_atypes+1;

#if defined (IMPROVE_GRID)
			mul_tmp = atom1_typeid*g3;
			cube [0][0][0] = *(dockpars_fgrids + cube_000 + mul_tmp);
			cube [1][0][0] = *(dockpars_fgrids + cube_100 + mul_tmp);
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
      			cube [0][1][0] = *(dockpars_fgrids + cube_010 + mul_tmp);
      			cube [1][1][0] = *(dockpars_fgrids + cube_110 + mul_tmp);
      			cube [0][0][1] = *(dockpars_fgrids + cube_001 + mul_tmp);
      			cube [1][0][1] = *(dockpars_fgrids + cube_101 + mul_tmp);
      			cube [0][1][1] = *(dockpars_fgrids + cube_011 + mul_tmp);
      			cube [1][1][1] = *(dockpars_fgrids + cube_111 + mul_tmp);

			// -------------------------------------------------------------------
			// L30nardoSV
			// Calculate gradients (forces) corresponding to 
			// "dsol" intermolecular energy
			// Derived from autodockdev/maps.py
			// -------------------------------------------------------------------

			if (*is_enabled_gradient_calc) {
				// vector in x-direction
				x10 = cube [1][0][0] - cube [0][0][0]; // z = 0
				x52 = cube [1][1][0] - cube [0][1][0]; // z = 0
				x43 = cube [1][0][1] - cube [0][0][1]; // z = 1
				x76 = cube [1][1][1] - cube [0][1][1]; // z = 1
				vx_z0 = (1 - dy) * x10 + dy * x52;     // z = 0
				vx_z1 = (1 - dy) * x43 + dy * x76;     // z = 1
				gradient_inter_x[atom1_id] += (1 - dz) * vx_z0 + dz * vx_z1;

				// vector in y-direction
				y20 = cube[0][1][0] - cube [0][0][0];	// z = 0
				y51 = cube[1][1][0] - cube [1][0][0];	// z = 0
				y63 = cube[0][1][1] - cube [0][0][1];	// z = 1
				y74 = cube[1][1][1] - cube [1][0][1];	// z = 1
				vy_z0 = (1 - dx) * y20 + dx * y51;	// z = 0
				vy_z1 = (1 - dx) * y63 + dx * y74;	// z = 1
				gradient_inter_y[atom1_id] += (1 - dz) * vy_z0 + dz * vy_z1;

				// vectors in z-direction
				z30 = cube [0][0][1] - cube [0][0][0];	// y = 0
				z41 = cube [1][0][1] - cube [1][0][0];	// y = 0
				z62 = cube [0][1][1] - cube [0][1][0];	// y = 1 
				z75 = cube [1][1][1] - cube [1][1][0];	// y = 1
				vz_y0 = (1 - dx) * z30 + dx * z41;	// y = 0
				vz_y1 = (1 - dx) * z62 + dx * z75;	// y = 1
				gradient_inter_z[atom1_id] += (1 - dy) * vz_y0 + dy * vz_y1;
			}
			// -------------------------------------------------------------------
			// -------------------------------------------------------------------
Leonardo Solis's avatar
Leonardo Solis committed
960
961

#else
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
			// -------------------------------------------------------------------
			// L30nardoSV
			// FIXME: this block within the "#else" preprocessor directive 
			// provides NO gradient corresponding to "dsol" intermolecular energy
			// -------------------------------------------------------------------

			cube [0][0][0] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_low, x_low);
			cube [1][0][0] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_low, x_high);
			cube [0][1][0] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_high, x_low);
			cube [1][1][0] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_low, y_high, x_high);
			cube [0][0][1] = GETGRIDVALUE(dockpars_fgrids, 
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_low, x_low);
			cube [1][0][1] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,
						      dockpars_gridsize_z,
						      atom1_typeid, z_high, y_low, x_high);
			cube [0][1][1] = GETGRIDVALUE(dockpars_fgrids,
						      dockpars_gridsize_x,
						      dockpars_gridsize_y,