Merge remote-tracking branch 'origin/release-4-6' into HEAD
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_adress_c / nb_kernel132_c_adress.c
1 /*
2  * Copyright (c) Erik Lindahl, David van der Spoel 2003
3  * 
4  * This file is generated automatically at compile time
5  * by the program mknb in the Gromacs distribution.
6  *
7  * Options used when generation this file:
8  * Language:         c
9  * Precision:        single
10  * Threads:          yes
11  * Software invsqrt: no
12  * PowerPC invsqrt:  no
13  * Prefetch forces:  no
14  * Adress kernel:  yes
15  * Comments:         no
16  */
17 #ifdef HAVE_CONFIG_H
18 #include<config.h>
19 #endif
20 #ifdef GMX_THREAD_SHM_FDECOMP
21 #include<thread_mpi.h>
22 #endif
23 #define ALMOST_ZERO 1e-30
24 #define ALMOST_ONE 1-(1e-30)
25 #include<math.h>
26
27 #include "nb_kernel132_adress.h"
28
29
30
31 /*
32  * Gromacs nonbonded kernel nb_kernel132_adress_cg
33  * Coulomb interaction:     Normal Coulomb
34  * VdW interaction:         Tabulated
35  * water optimization:      pairs of SPC/TIP3P interactions
36  * Calculate forces:        yes
37  */
38 void nb_kernel132_adress_cg(
39                     int *           p_nri,
40                     int *           iinr,
41                     int *           jindex,
42                     int *           jjnr,
43                     int *           shift,
44                     real *         shiftvec,
45                     real *         fshift,
46                     int *           gid,
47                     real *         pos,
48                     real *         faction,
49                     real *         charge,
50                     real *         p_facel,
51                     real *         p_krf,
52                     real *         p_crf,
53                     real *         Vc,
54                     int *           type,
55                     int *           p_ntype,
56                     real *         vdwparam,
57                     real *         Vvdw,
58                     real *         p_tabscale,
59                     real *         VFtab,
60                     real *         invsqrta,
61                     real *         dvda,
62                     real *         p_gbtabscale,
63                     real *         GBtab,
64                     int *           p_nthreads,
65                     int *           count,
66                     void *          mtx,
67                     int *           outeriter,
68                     int *           inneriter,
69                     real           force_cap,
70                     real *         wf)
71 {
72     int           nri,ntype,nthreads;
73     real         facel,krf,crf,tabscale,gbtabscale;
74     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
75     int           nn0,nn1,nouter,ninner;
76     real         shX,shY,shZ;
77     real         fscal,tx,ty,tz;
78     real         rinvsq;
79     real         qq,vcoul,vctot;
80     int           tj;
81     real         Vvdw6,Vvdwtot;
82     real         Vvdw12;
83     real         r,rt,eps,eps2;
84     int           n0,nnn;
85     real         Y,F,Geps,Heps2,Fp,VV;
86     real         FF;
87     real         fijD,fijR;
88     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
89     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
90     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
91     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
92     real         jx2,jy2,jz2,fjx2,fjy2,fjz2;
93     real         jx3,jy3,jz3,fjx3,fjy3,fjz3;
94     real         dx11,dy11,dz11,rsq11,rinv11;
95     real         dx12,dy12,dz12,rsq12,rinv12;
96     real         dx13,dy13,dz13,rsq13,rinv13;
97     real         dx21,dy21,dz21,rsq21,rinv21;
98     real         dx22,dy22,dz22,rsq22,rinv22;
99     real         dx23,dy23,dz23,rsq23,rinv23;
100     real         dx31,dy31,dz31,rsq31,rinv31;
101     real         dx32,dy32,dz32,rsq32,rinv32;
102     real         dx33,dy33,dz33,rsq33,rinv33;
103     real         qO,qH,qqOO,qqOH,qqHH;
104     real         c6,c12;
105     real         weight_cg1, weight_cg2, weight_product;
106     real         hybscal;
107
108     nri              = *p_nri;         
109     ntype            = *p_ntype;       
110     nthreads         = *p_nthreads;    
111     facel            = *p_facel;       
112     krf              = *p_krf;         
113     crf              = *p_crf;         
114     tabscale         = *p_tabscale;    
115     ii               = iinr[0];        
116     qO               = charge[ii];     
117     qH               = charge[ii+1];   
118     qqOO             = facel*qO*qO;    
119     qqOH             = facel*qO*qH;    
120     qqHH             = facel*qH*qH;    
121     tj               = 2*(ntype+1)*type[ii];
122     c6               = vdwparam[tj];   
123     c12              = vdwparam[tj+1]; 
124
125     nouter           = 0;              
126     ninner           = 0;              
127     
128     do
129     {
130         #ifdef GMX_THREAD_SHM_FDECOMP
131         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
132         nn0              = *count;         
133         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
134         *count           = nn1;            
135         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
136         if(nn1>nri) nn1=nri;
137         #else
138         nn0 = 0;
139         nn1 = nri;
140         #endif
141         
142         for(n=nn0; (n<nn1); n++)
143         {
144             is3              = 3*shift[n];     
145             shX              = shiftvec[is3];  
146             shY              = shiftvec[is3+1];
147             shZ              = shiftvec[is3+2];
148             nj0              = jindex[n];      
149             nj1              = jindex[n+1];    
150             ii               = iinr[n];        
151             ii3              = 3*ii;           
152             ix1              = shX + pos[ii3+0];
153             iy1              = shY + pos[ii3+1];
154             iz1              = shZ + pos[ii3+2];
155             ix2              = shX + pos[ii3+3];
156             iy2              = shY + pos[ii3+4];
157             iz2              = shZ + pos[ii3+5];
158             ix3              = shX + pos[ii3+6];
159             iy3              = shY + pos[ii3+7];
160             iz3              = shZ + pos[ii3+8];
161             weight_cg1       = wf[ii];         
162             vctot            = 0;              
163             Vvdwtot          = 0;              
164             fix1             = 0;              
165             fiy1             = 0;              
166             fiz1             = 0;              
167             fix2             = 0;              
168             fiy2             = 0;              
169             fiz2             = 0;              
170             fix3             = 0;              
171             fiy3             = 0;              
172             fiz3             = 0;              
173             
174             for(k=nj0; (k<nj1); k++)
175             {
176                 jnr              = jjnr[k];        
177                 weight_cg2       = wf[jnr];        
178                 weight_product   = weight_cg1*weight_cg2;
179                 if (weight_product < ALMOST_ZERO) {
180                        hybscal = 1.0;
181                 }
182                 else if (weight_product >= ALMOST_ONE)
183                 {
184                   /* force is zero, skip this molecule */
185                        continue;
186                 }
187                 else
188                 {
189                    hybscal = 1.0 - weight_product;
190                 }
191                 j3               = 3*jnr;          
192                 jx1              = pos[j3+0];      
193                 jy1              = pos[j3+1];      
194                 jz1              = pos[j3+2];      
195                 jx2              = pos[j3+3];      
196                 jy2              = pos[j3+4];      
197                 jz2              = pos[j3+5];      
198                 jx3              = pos[j3+6];      
199                 jy3              = pos[j3+7];      
200                 jz3              = pos[j3+8];      
201                 dx11             = ix1 - jx1;      
202                 dy11             = iy1 - jy1;      
203                 dz11             = iz1 - jz1;      
204                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
205                 dx12             = ix1 - jx2;      
206                 dy12             = iy1 - jy2;      
207                 dz12             = iz1 - jz2;      
208                 rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
209                 dx13             = ix1 - jx3;      
210                 dy13             = iy1 - jy3;      
211                 dz13             = iz1 - jz3;      
212                 rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
213                 dx21             = ix2 - jx1;      
214                 dy21             = iy2 - jy1;      
215                 dz21             = iz2 - jz1;      
216                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
217                 dx22             = ix2 - jx2;      
218                 dy22             = iy2 - jy2;      
219                 dz22             = iz2 - jz2;      
220                 rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
221                 dx23             = ix2 - jx3;      
222                 dy23             = iy2 - jy3;      
223                 dz23             = iz2 - jz3;      
224                 rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
225                 dx31             = ix3 - jx1;      
226                 dy31             = iy3 - jy1;      
227                 dz31             = iz3 - jz1;      
228                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
229                 dx32             = ix3 - jx2;      
230                 dy32             = iy3 - jy2;      
231                 dz32             = iz3 - jz2;      
232                 rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
233                 dx33             = ix3 - jx3;      
234                 dy33             = iy3 - jy3;      
235                 dz33             = iz3 - jz3;      
236                 rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
237                 rinv11           = 1.0/sqrt(rsq11);
238                 rinv12           = 1.0/sqrt(rsq12);
239                 rinv13           = 1.0/sqrt(rsq13);
240                 rinv21           = 1.0/sqrt(rsq21);
241                 rinv22           = 1.0/sqrt(rsq22);
242                 rinv23           = 1.0/sqrt(rsq23);
243                 rinv31           = 1.0/sqrt(rsq31);
244                 rinv32           = 1.0/sqrt(rsq32);
245                 rinv33           = 1.0/sqrt(rsq33);
246                 qq               = qqOO;           
247                 rinvsq           = rinv11*rinv11;  
248                 vcoul            = qq*rinv11;      
249                 vctot            = vctot+vcoul;    
250                 r                = rsq11*rinv11;   
251                 rt               = r*tabscale;     
252                 n0               = rt;             
253                 eps              = rt-n0;          
254                 eps2             = eps*eps;        
255                 nnn              = 8*n0;           
256                 Y                = VFtab[nnn];     
257                 F                = VFtab[nnn+1];   
258                 Geps             = eps*VFtab[nnn+2];
259                 Heps2            = eps2*VFtab[nnn+3];
260                 Fp               = F+Geps+Heps2;   
261                 VV               = Y+eps*Fp;       
262                 FF               = Fp+Geps+2.0*Heps2;
263                 Vvdw6            = c6*VV;          
264                 fijD             = c6*FF;          
265                 nnn              = nnn+4;          
266                 Y                = VFtab[nnn];     
267                 F                = VFtab[nnn+1];   
268                 Geps             = eps*VFtab[nnn+2];
269                 Heps2            = eps2*VFtab[nnn+3];
270                 Fp               = F+Geps+Heps2;   
271                 VV               = Y+eps*Fp;       
272                 FF               = Fp+Geps+2.0*Heps2;
273                 Vvdw12           = c12*VV;         
274                 fijR             = c12*FF;         
275                 Vvdwtot          = Vvdwtot+ Vvdw6 + Vvdw12;
276                 fscal            = (vcoul)*rinvsq-((fijD+fijR)*tabscale)*rinv11;
277                 fscal *= hybscal;
278                 tx               = fscal*dx11;     
279                 ty               = fscal*dy11;     
280                 tz               = fscal*dz11;     
281                 fix1             = fix1 + tx;      
282                 fiy1             = fiy1 + ty;      
283                 fiz1             = fiz1 + tz;      
284                 fjx1             = faction[j3+0] - tx;
285                 fjy1             = faction[j3+1] - ty;
286                 fjz1             = faction[j3+2] - tz;
287                 qq               = qqOH;           
288                 rinvsq           = rinv12*rinv12;  
289                 vcoul            = qq*rinv12;      
290                 vctot            = vctot+vcoul;    
291                 fscal            = (vcoul)*rinvsq; 
292                 fscal *= hybscal;
293                 tx               = fscal*dx12;     
294                 ty               = fscal*dy12;     
295                 tz               = fscal*dz12;     
296                 fix1             = fix1 + tx;      
297                 fiy1             = fiy1 + ty;      
298                 fiz1             = fiz1 + tz;      
299                 fjx2             = faction[j3+3] - tx;
300                 fjy2             = faction[j3+4] - ty;
301                 fjz2             = faction[j3+5] - tz;
302                 qq               = qqOH;           
303                 rinvsq           = rinv13*rinv13;  
304                 vcoul            = qq*rinv13;      
305                 vctot            = vctot+vcoul;    
306                 fscal            = (vcoul)*rinvsq; 
307                 fscal *= hybscal;
308                 tx               = fscal*dx13;     
309                 ty               = fscal*dy13;     
310                 tz               = fscal*dz13;     
311                 fix1             = fix1 + tx;      
312                 fiy1             = fiy1 + ty;      
313                 fiz1             = fiz1 + tz;      
314                 fjx3             = faction[j3+6] - tx;
315                 fjy3             = faction[j3+7] - ty;
316                 fjz3             = faction[j3+8] - tz;
317                 qq               = qqOH;           
318                 rinvsq           = rinv21*rinv21;  
319                 vcoul            = qq*rinv21;      
320                 vctot            = vctot+vcoul;    
321                 fscal            = (vcoul)*rinvsq; 
322                 fscal *= hybscal;
323                 tx               = fscal*dx21;     
324                 ty               = fscal*dy21;     
325                 tz               = fscal*dz21;     
326                 fix2             = fix2 + tx;      
327                 fiy2             = fiy2 + ty;      
328                 fiz2             = fiz2 + tz;      
329                 fjx1             = fjx1 - tx;      
330                 fjy1             = fjy1 - ty;      
331                 fjz1             = fjz1 - tz;      
332                 qq               = qqHH;           
333                 rinvsq           = rinv22*rinv22;  
334                 vcoul            = qq*rinv22;      
335                 vctot            = vctot+vcoul;    
336                 fscal            = (vcoul)*rinvsq; 
337                 fscal *= hybscal;
338                 tx               = fscal*dx22;     
339                 ty               = fscal*dy22;     
340                 tz               = fscal*dz22;     
341                 fix2             = fix2 + tx;      
342                 fiy2             = fiy2 + ty;      
343                 fiz2             = fiz2 + tz;      
344                 fjx2             = fjx2 - tx;      
345                 fjy2             = fjy2 - ty;      
346                 fjz2             = fjz2 - tz;      
347                 qq               = qqHH;           
348                 rinvsq           = rinv23*rinv23;  
349                 vcoul            = qq*rinv23;      
350                 vctot            = vctot+vcoul;    
351                 fscal            = (vcoul)*rinvsq; 
352                 fscal *= hybscal;
353                 tx               = fscal*dx23;     
354                 ty               = fscal*dy23;     
355                 tz               = fscal*dz23;     
356                 fix2             = fix2 + tx;      
357                 fiy2             = fiy2 + ty;      
358                 fiz2             = fiz2 + tz;      
359                 fjx3             = fjx3 - tx;      
360                 fjy3             = fjy3 - ty;      
361                 fjz3             = fjz3 - tz;      
362                 qq               = qqOH;           
363                 rinvsq           = rinv31*rinv31;  
364                 vcoul            = qq*rinv31;      
365                 vctot            = vctot+vcoul;    
366                 fscal            = (vcoul)*rinvsq; 
367                 fscal *= hybscal;
368                 tx               = fscal*dx31;     
369                 ty               = fscal*dy31;     
370                 tz               = fscal*dz31;     
371                 fix3             = fix3 + tx;      
372                 fiy3             = fiy3 + ty;      
373                 fiz3             = fiz3 + tz;      
374                 faction[j3+0]    = fjx1 - tx;      
375                 faction[j3+1]    = fjy1 - ty;      
376                 faction[j3+2]    = fjz1 - tz;      
377                 qq               = qqHH;           
378                 rinvsq           = rinv32*rinv32;  
379                 vcoul            = qq*rinv32;      
380                 vctot            = vctot+vcoul;    
381                 fscal            = (vcoul)*rinvsq; 
382                 fscal *= hybscal;
383                 tx               = fscal*dx32;     
384                 ty               = fscal*dy32;     
385                 tz               = fscal*dz32;     
386                 fix3             = fix3 + tx;      
387                 fiy3             = fiy3 + ty;      
388                 fiz3             = fiz3 + tz;      
389                 faction[j3+3]    = fjx2 - tx;      
390                 faction[j3+4]    = fjy2 - ty;      
391                 faction[j3+5]    = fjz2 - tz;      
392                 qq               = qqHH;           
393                 rinvsq           = rinv33*rinv33;  
394                 vcoul            = qq*rinv33;      
395                 vctot            = vctot+vcoul;    
396                 fscal            = (vcoul)*rinvsq; 
397                 fscal *= hybscal;
398                 tx               = fscal*dx33;     
399                 ty               = fscal*dy33;     
400                 tz               = fscal*dz33;     
401                 fix3             = fix3 + tx;      
402                 fiy3             = fiy3 + ty;      
403                 fiz3             = fiz3 + tz;      
404                 faction[j3+6]    = fjx3 - tx;      
405                 faction[j3+7]    = fjy3 - ty;      
406                 faction[j3+8]    = fjz3 - tz;      
407             }
408             
409             faction[ii3+0]   = faction[ii3+0] + fix1;
410             faction[ii3+1]   = faction[ii3+1] + fiy1;
411             faction[ii3+2]   = faction[ii3+2] + fiz1;
412             faction[ii3+3]   = faction[ii3+3] + fix2;
413             faction[ii3+4]   = faction[ii3+4] + fiy2;
414             faction[ii3+5]   = faction[ii3+5] + fiz2;
415             faction[ii3+6]   = faction[ii3+6] + fix3;
416             faction[ii3+7]   = faction[ii3+7] + fiy3;
417             faction[ii3+8]   = faction[ii3+8] + fiz3;
418             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
419             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
420             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
421             ggid             = gid[n];         
422             Vc[ggid]         = Vc[ggid] + vctot;
423             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
424             ninner           = ninner + nj1 - nj0;
425         }
426         
427         nouter           = nouter + nn1 - nn0;
428     }
429     while (nn1<nri);
430     
431     *outeriter       = nouter;         
432     *inneriter       = ninner;         
433 }
434
435
436
437
438
439 /*
440  * Gromacs nonbonded kernel nb_kernel132_adress_ex
441  * Coulomb interaction:     Normal Coulomb
442  * VdW interaction:         Tabulated
443  * water optimization:      pairs of SPC/TIP3P interactions
444  * Calculate forces:        yes
445  */
446 void nb_kernel132_adress_ex(
447                     int *           p_nri,
448                     int *           iinr,
449                     int *           jindex,
450                     int *           jjnr,
451                     int *           shift,
452                     real *         shiftvec,
453                     real *         fshift,
454                     int *           gid,
455                     real *         pos,
456                     real *         faction,
457                     real *         charge,
458                     real *         p_facel,
459                     real *         p_krf,
460                     real *         p_crf,
461                     real *         Vc,
462                     int *           type,
463                     int *           p_ntype,
464                     real *         vdwparam,
465                     real *         Vvdw,
466                     real *         p_tabscale,
467                     real *         VFtab,
468                     real *         invsqrta,
469                     real *         dvda,
470                     real *         p_gbtabscale,
471                     real *         GBtab,
472                     int *           p_nthreads,
473                     int *           count,
474                     void *          mtx,
475                     int *           outeriter,
476                     int *           inneriter,
477                     real           force_cap,
478                     real *         wf)
479 {
480     int           nri,ntype,nthreads;
481     real         facel,krf,crf,tabscale,gbtabscale;
482     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
483     int           nn0,nn1,nouter,ninner;
484     real         shX,shY,shZ;
485     real         fscal,tx,ty,tz;
486     real         rinvsq;
487     real         qq,vcoul,vctot;
488     int           tj;
489     real         Vvdw6,Vvdwtot;
490     real         Vvdw12;
491     real         r,rt,eps,eps2;
492     int           n0,nnn;
493     real         Y,F,Geps,Heps2,Fp,VV;
494     real         FF;
495     real         fijD,fijR;
496     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
497     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
498     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
499     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
500     real         jx2,jy2,jz2,fjx2,fjy2,fjz2;
501     real         jx3,jy3,jz3,fjx3,fjy3,fjz3;
502     real         dx11,dy11,dz11,rsq11,rinv11;
503     real         dx12,dy12,dz12,rsq12,rinv12;
504     real         dx13,dy13,dz13,rsq13,rinv13;
505     real         dx21,dy21,dz21,rsq21,rinv21;
506     real         dx22,dy22,dz22,rsq22,rinv22;
507     real         dx23,dy23,dz23,rsq23,rinv23;
508     real         dx31,dy31,dz31,rsq31,rinv31;
509     real         dx32,dy32,dz32,rsq32,rinv32;
510     real         dx33,dy33,dz33,rsq33,rinv33;
511     real         qO,qH,qqOO,qqOH,qqHH;
512     real         c6,c12;
513     real         weight_cg1, weight_cg2, weight_product;
514     real         hybscal;
515
516     nri              = *p_nri;         
517     ntype            = *p_ntype;       
518     nthreads         = *p_nthreads;    
519     facel            = *p_facel;       
520     krf              = *p_krf;         
521     crf              = *p_crf;         
522     tabscale         = *p_tabscale;    
523     ii               = iinr[0];        
524     qO               = charge[ii];     
525     qH               = charge[ii+1];   
526     qqOO             = facel*qO*qO;    
527     qqOH             = facel*qO*qH;    
528     qqHH             = facel*qH*qH;    
529     tj               = 2*(ntype+1)*type[ii];
530     c6               = vdwparam[tj];   
531     c12              = vdwparam[tj+1]; 
532
533     nouter           = 0;              
534     ninner           = 0;              
535     
536     do
537     {
538         #ifdef GMX_THREAD_SHM_FDECOMP
539         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
540         nn0              = *count;         
541         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
542         *count           = nn1;            
543         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
544         if(nn1>nri) nn1=nri;
545         #else
546         nn0 = 0;
547         nn1 = nri;
548         #endif
549         
550         for(n=nn0; (n<nn1); n++)
551         {
552             is3              = 3*shift[n];     
553             shX              = shiftvec[is3];  
554             shY              = shiftvec[is3+1];
555             shZ              = shiftvec[is3+2];
556             nj0              = jindex[n];      
557             nj1              = jindex[n+1];    
558             ii               = iinr[n];        
559             ii3              = 3*ii;           
560             ix1              = shX + pos[ii3+0];
561             iy1              = shY + pos[ii3+1];
562             iz1              = shZ + pos[ii3+2];
563             ix2              = shX + pos[ii3+3];
564             iy2              = shY + pos[ii3+4];
565             iz2              = shZ + pos[ii3+5];
566             ix3              = shX + pos[ii3+6];
567             iy3              = shY + pos[ii3+7];
568             iz3              = shZ + pos[ii3+8];
569             weight_cg1       = wf[ii];         
570             vctot            = 0;              
571             Vvdwtot          = 0;              
572             fix1             = 0;              
573             fiy1             = 0;              
574             fiz1             = 0;              
575             fix2             = 0;              
576             fiy2             = 0;              
577             fiz2             = 0;              
578             fix3             = 0;              
579             fiy3             = 0;              
580             fiz3             = 0;              
581             
582             for(k=nj0; (k<nj1); k++)
583             {
584                 jnr              = jjnr[k];        
585                 weight_cg2       = wf[jnr];        
586                 weight_product   = weight_cg1*weight_cg2;
587                 if (weight_product < ALMOST_ZERO) {
588                 /* force is zero, skip this molecule */
589                  continue;
590                 }
591                 else if (weight_product >= ALMOST_ONE)
592                 {
593                        hybscal = 1.0;
594                 }
595                 else
596                 {
597                    hybscal = weight_product;
598                 }
599                 j3               = 3*jnr;          
600                 jx1              = pos[j3+0];      
601                 jy1              = pos[j3+1];      
602                 jz1              = pos[j3+2];      
603                 jx2              = pos[j3+3];      
604                 jy2              = pos[j3+4];      
605                 jz2              = pos[j3+5];      
606                 jx3              = pos[j3+6];      
607                 jy3              = pos[j3+7];      
608                 jz3              = pos[j3+8];      
609                 dx11             = ix1 - jx1;      
610                 dy11             = iy1 - jy1;      
611                 dz11             = iz1 - jz1;      
612                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
613                 dx12             = ix1 - jx2;      
614                 dy12             = iy1 - jy2;      
615                 dz12             = iz1 - jz2;      
616                 rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
617                 dx13             = ix1 - jx3;      
618                 dy13             = iy1 - jy3;      
619                 dz13             = iz1 - jz3;      
620                 rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
621                 dx21             = ix2 - jx1;      
622                 dy21             = iy2 - jy1;      
623                 dz21             = iz2 - jz1;      
624                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
625                 dx22             = ix2 - jx2;      
626                 dy22             = iy2 - jy2;      
627                 dz22             = iz2 - jz2;      
628                 rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
629                 dx23             = ix2 - jx3;      
630                 dy23             = iy2 - jy3;      
631                 dz23             = iz2 - jz3;      
632                 rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
633                 dx31             = ix3 - jx1;      
634                 dy31             = iy3 - jy1;      
635                 dz31             = iz3 - jz1;      
636                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
637                 dx32             = ix3 - jx2;      
638                 dy32             = iy3 - jy2;      
639                 dz32             = iz3 - jz2;      
640                 rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
641                 dx33             = ix3 - jx3;      
642                 dy33             = iy3 - jy3;      
643                 dz33             = iz3 - jz3;      
644                 rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
645                 rinv11           = 1.0/sqrt(rsq11);
646                 rinv12           = 1.0/sqrt(rsq12);
647                 rinv13           = 1.0/sqrt(rsq13);
648                 rinv21           = 1.0/sqrt(rsq21);
649                 rinv22           = 1.0/sqrt(rsq22);
650                 rinv23           = 1.0/sqrt(rsq23);
651                 rinv31           = 1.0/sqrt(rsq31);
652                 rinv32           = 1.0/sqrt(rsq32);
653                 rinv33           = 1.0/sqrt(rsq33);
654                 qq               = qqOO;           
655                 rinvsq           = rinv11*rinv11;  
656                 vcoul            = qq*rinv11;      
657                 vctot            = vctot+vcoul;    
658                 r                = rsq11*rinv11;   
659                 rt               = r*tabscale;     
660                 n0               = rt;             
661                 eps              = rt-n0;          
662                 eps2             = eps*eps;        
663                 nnn              = 8*n0;           
664                 Y                = VFtab[nnn];     
665                 F                = VFtab[nnn+1];   
666                 Geps             = eps*VFtab[nnn+2];
667                 Heps2            = eps2*VFtab[nnn+3];
668                 Fp               = F+Geps+Heps2;   
669                 VV               = Y+eps*Fp;       
670                 FF               = Fp+Geps+2.0*Heps2;
671                 Vvdw6            = c6*VV;          
672                 fijD             = c6*FF;          
673                 nnn              = nnn+4;          
674                 Y                = VFtab[nnn];     
675                 F                = VFtab[nnn+1];   
676                 Geps             = eps*VFtab[nnn+2];
677                 Heps2            = eps2*VFtab[nnn+3];
678                 Fp               = F+Geps+Heps2;   
679                 VV               = Y+eps*Fp;       
680                 FF               = Fp+Geps+2.0*Heps2;
681                 Vvdw12           = c12*VV;         
682                 fijR             = c12*FF;         
683                 Vvdwtot          = Vvdwtot+ Vvdw6 + Vvdw12;
684                 fscal            = (vcoul)*rinvsq-((fijD+fijR)*tabscale)*rinv11;
685                 fscal *= hybscal;
686                 if(force_cap>0 && (fabs(fscal)> force_cap)){
687                 fscal=force_cap*fscal/fabs(fscal);
688                 }
689                 tx               = fscal*dx11;     
690                 ty               = fscal*dy11;     
691                 tz               = fscal*dz11;     
692                 fix1             = fix1 + tx;      
693                 fiy1             = fiy1 + ty;      
694                 fiz1             = fiz1 + tz;      
695                 fjx1             = faction[j3+0] - tx;
696                 fjy1             = faction[j3+1] - ty;
697                 fjz1             = faction[j3+2] - tz;
698                 qq               = qqOH;           
699                 rinvsq           = rinv12*rinv12;  
700                 vcoul            = qq*rinv12;      
701                 vctot            = vctot+vcoul;    
702                 fscal            = (vcoul)*rinvsq; 
703                 fscal *= hybscal;
704                 if(force_cap>0 && (fabs(fscal)> force_cap)){
705                 fscal=force_cap*fscal/fabs(fscal);
706                 }
707                 tx               = fscal*dx12;     
708                 ty               = fscal*dy12;     
709                 tz               = fscal*dz12;     
710                 fix1             = fix1 + tx;      
711                 fiy1             = fiy1 + ty;      
712                 fiz1             = fiz1 + tz;      
713                 fjx2             = faction[j3+3] - tx;
714                 fjy2             = faction[j3+4] - ty;
715                 fjz2             = faction[j3+5] - tz;
716                 qq               = qqOH;           
717                 rinvsq           = rinv13*rinv13;  
718                 vcoul            = qq*rinv13;      
719                 vctot            = vctot+vcoul;    
720                 fscal            = (vcoul)*rinvsq; 
721                 fscal *= hybscal;
722                 if(force_cap>0 && (fabs(fscal)> force_cap)){
723                 fscal=force_cap*fscal/fabs(fscal);
724                 }
725                 tx               = fscal*dx13;     
726                 ty               = fscal*dy13;     
727                 tz               = fscal*dz13;     
728                 fix1             = fix1 + tx;      
729                 fiy1             = fiy1 + ty;      
730                 fiz1             = fiz1 + tz;      
731                 fjx3             = faction[j3+6] - tx;
732                 fjy3             = faction[j3+7] - ty;
733                 fjz3             = faction[j3+8] - tz;
734                 qq               = qqOH;           
735                 rinvsq           = rinv21*rinv21;  
736                 vcoul            = qq*rinv21;      
737                 vctot            = vctot+vcoul;    
738                 fscal            = (vcoul)*rinvsq; 
739                 fscal *= hybscal;
740                 if(force_cap>0 && (fabs(fscal)> force_cap)){
741                 fscal=force_cap*fscal/fabs(fscal);
742                 }
743                 tx               = fscal*dx21;     
744                 ty               = fscal*dy21;     
745                 tz               = fscal*dz21;     
746                 fix2             = fix2 + tx;      
747                 fiy2             = fiy2 + ty;      
748                 fiz2             = fiz2 + tz;      
749                 fjx1             = fjx1 - tx;      
750                 fjy1             = fjy1 - ty;      
751                 fjz1             = fjz1 - tz;      
752                 qq               = qqHH;           
753                 rinvsq           = rinv22*rinv22;  
754                 vcoul            = qq*rinv22;      
755                 vctot            = vctot+vcoul;    
756                 fscal            = (vcoul)*rinvsq; 
757                 fscal *= hybscal;
758                 if(force_cap>0 && (fabs(fscal)> force_cap)){
759                 fscal=force_cap*fscal/fabs(fscal);
760                 }
761                 tx               = fscal*dx22;     
762                 ty               = fscal*dy22;     
763                 tz               = fscal*dz22;     
764                 fix2             = fix2 + tx;      
765                 fiy2             = fiy2 + ty;      
766                 fiz2             = fiz2 + tz;      
767                 fjx2             = fjx2 - tx;      
768                 fjy2             = fjy2 - ty;      
769                 fjz2             = fjz2 - tz;      
770                 qq               = qqHH;           
771                 rinvsq           = rinv23*rinv23;  
772                 vcoul            = qq*rinv23;      
773                 vctot            = vctot+vcoul;    
774                 fscal            = (vcoul)*rinvsq; 
775                 fscal *= hybscal;
776                 if(force_cap>0 && (fabs(fscal)> force_cap)){
777                 fscal=force_cap*fscal/fabs(fscal);
778                 }
779                 tx               = fscal*dx23;     
780                 ty               = fscal*dy23;     
781                 tz               = fscal*dz23;     
782                 fix2             = fix2 + tx;      
783                 fiy2             = fiy2 + ty;      
784                 fiz2             = fiz2 + tz;      
785                 fjx3             = fjx3 - tx;      
786                 fjy3             = fjy3 - ty;      
787                 fjz3             = fjz3 - tz;      
788                 qq               = qqOH;           
789                 rinvsq           = rinv31*rinv31;  
790                 vcoul            = qq*rinv31;      
791                 vctot            = vctot+vcoul;    
792                 fscal            = (vcoul)*rinvsq; 
793                 fscal *= hybscal;
794                 if(force_cap>0 && (fabs(fscal)> force_cap)){
795                 fscal=force_cap*fscal/fabs(fscal);
796                 }
797                 tx               = fscal*dx31;     
798                 ty               = fscal*dy31;     
799                 tz               = fscal*dz31;     
800                 fix3             = fix3 + tx;      
801                 fiy3             = fiy3 + ty;      
802                 fiz3             = fiz3 + tz;      
803                 faction[j3+0]    = fjx1 - tx;      
804                 faction[j3+1]    = fjy1 - ty;      
805                 faction[j3+2]    = fjz1 - tz;      
806                 qq               = qqHH;           
807                 rinvsq           = rinv32*rinv32;  
808                 vcoul            = qq*rinv32;      
809                 vctot            = vctot+vcoul;    
810                 fscal            = (vcoul)*rinvsq; 
811                 fscal *= hybscal;
812                 if(force_cap>0 && (fabs(fscal)> force_cap)){
813                 fscal=force_cap*fscal/fabs(fscal);
814                 }
815                 tx               = fscal*dx32;     
816                 ty               = fscal*dy32;     
817                 tz               = fscal*dz32;     
818                 fix3             = fix3 + tx;      
819                 fiy3             = fiy3 + ty;      
820                 fiz3             = fiz3 + tz;      
821                 faction[j3+3]    = fjx2 - tx;      
822                 faction[j3+4]    = fjy2 - ty;      
823                 faction[j3+5]    = fjz2 - tz;      
824                 qq               = qqHH;           
825                 rinvsq           = rinv33*rinv33;  
826                 vcoul            = qq*rinv33;      
827                 vctot            = vctot+vcoul;    
828                 fscal            = (vcoul)*rinvsq; 
829                 fscal *= hybscal;
830                 if(force_cap>0 && (fabs(fscal)> force_cap)){
831                 fscal=force_cap*fscal/fabs(fscal);
832                 }
833                 tx               = fscal*dx33;     
834                 ty               = fscal*dy33;     
835                 tz               = fscal*dz33;     
836                 fix3             = fix3 + tx;      
837                 fiy3             = fiy3 + ty;      
838                 fiz3             = fiz3 + tz;      
839                 faction[j3+6]    = fjx3 - tx;      
840                 faction[j3+7]    = fjy3 - ty;      
841                 faction[j3+8]    = fjz3 - tz;      
842             }
843             
844             faction[ii3+0]   = faction[ii3+0] + fix1;
845             faction[ii3+1]   = faction[ii3+1] + fiy1;
846             faction[ii3+2]   = faction[ii3+2] + fiz1;
847             faction[ii3+3]   = faction[ii3+3] + fix2;
848             faction[ii3+4]   = faction[ii3+4] + fiy2;
849             faction[ii3+5]   = faction[ii3+5] + fiz2;
850             faction[ii3+6]   = faction[ii3+6] + fix3;
851             faction[ii3+7]   = faction[ii3+7] + fiy3;
852             faction[ii3+8]   = faction[ii3+8] + fiz3;
853             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
854             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
855             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
856             ggid             = gid[n];         
857             Vc[ggid]         = Vc[ggid] + vctot;
858             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
859             ninner           = ninner + nj1 - nj0;
860         }
861         
862         nouter           = nouter + nn1 - nn0;
863     }
864     while (nn1<nri);
865     
866     *outeriter       = nouter;         
867     *inneriter       = ninner;         
868 }
869
870