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