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