Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ComputeNonbondedBase2.h

Go to the documentation of this file.
00001 
00007 EXCLUDED( FAST( foo bar ) )
00008 EXCLUDED( MODIFIED( foo bar ) )
00009 EXCLUDED( NORMAL( foo bar ) )
00010 NORMAL( MODIFIED( foo bar ) )
00011 ALCHPAIR( NOT_ALCHPAIR( foo bar ) )
00012 
00013 ALCHPAIR(
00014   // get alchemical nonbonded scaling parameters (once per pairlist)
00015   myLambda = ALCH1(lambdaUp) ALCH2(lambdaDown);
00016   FEP(myLambda2 = ALCH1(lambda2Up) ALCH2(lambda2Down);)
00017   myElecLambda =  ALCH1(elecLambdaUp) ALCH2(elecLambdaDown); 
00018   FEP(myElecLambda2 = ALCH1(elecLambda2Up) ALCH2(elecLambda2Down);)
00019   myVdwLambda =  ALCH1(vdwLambdaUp) ALCH2(vdwLambdaDown); 
00020   FEP(myVdwLambda2 = ALCH1(vdwLambda2Up) ALCH2(vdwLambda2Down);) 
00021   myVdwShift =  ALCH1(vdwShiftUp) ALCH2(vdwShiftDown); 
00022   FEP(myVdwShift2 =  ALCH1(vdwShift2Up) ALCH2(vdwShift2Down);) 
00023 )
00024 
00025 #ifdef ARCH_POWERPC
00026      __alignx(16, table_four);
00027      __alignx(16, p_1);
00028 #pragma unroll(1)
00029 #endif
00030 
00031 #ifndef ARCH_POWERPC
00032 #pragma ivdep
00033 #endif
00034 
00035 
00036   
00037     for (k=0; k<npairi; ++k) {      
00038       TABENERGY(
00039       const int numtypes = simParams->tableNumTypes;
00040       const float table_spacing = simParams->tableSpacing;
00041       const int npertype = (int) (mynearbyint(simParams->tableMaxDist / simParams->tableSpacing) + 1);
00042       )
00043 
00044       int table_i = (r2iilist[2*k] >> 14) + r2_delta_expc;  // table_i >= 0 
00045       const int j = pairlisti[k];
00046       register const CompAtom *p_j = p_1 + j;
00047       // const CompAtomExt *pExt_j = pExt_1 + j;
00048       
00049       BigReal diffa = r2list[k] - r2_table[table_i];
00050       const BigReal* const table_four_i = table_four + 16*table_i;
00051 
00052 #if  ( FAST( 1 + ) TABENERGY( 1 + ) 0 ) // FAST or TABENERGY
00053       const LJTable::TableEntry * lj_pars = 
00054               lj_row + 2 * p_j->vdwType MODIFIED(+ 1);
00055 #endif
00056       
00057       TABENERGY(
00058       register const int tabtype = -1 - ( lj_pars->A < 0 ? lj_pars->A : 0 );
00059       )
00060       
00061 #if ( SHORT( FAST( 1+ ) ) 0 ) 
00062       Force *f_j = f_1 + j;
00063 #endif
00064         
00065 #if ( FULL( 1+ ) 0 )
00066       Force *fullf_j = fullf_1 + j;
00067 #endif
00068 
00069       //Power PC aliasing and alignment constraints
00070 #ifdef ARCH_POWERPC
00071       __alignx(16, table_four_i);
00072       FAST (
00073       __alignx(16, lj_pars);
00074       )
00075       __alignx(16, p_j);
00076       
00077 #if ( FULL( 1+ ) 0 )
00078 #pragma disjoint (*table_four_i, *fullf_j)
00079 #pragma disjoint (*p_j,          *fullf_j)
00080 #if ( SHORT( FAST( 1+ ) ) 0 ) 
00081 #pragma disjoint (*f_j    , *fullf_j)
00082 #pragma disjoint (*fullf_j, *f_j)
00083 #endif   //Short + fast
00084 #endif   //Full
00085 
00086 #if ( SHORT( FAST( 1+ ) ) 0 ) 
00087 #pragma disjoint (*table_four_i, *f_j)
00088 #pragma disjoint (*p_j,          *f_j)
00089 #pragma disjoint (*lj_pars,      *f_j)
00090       __prefetch_by_load ((void *)&f_j->x);
00091 #endif //Short + Fast
00092 
00093 #endif   //ARCH_POWERPC
00094 
00095       /*
00096       BigReal modf = 0.0;
00097       int atom2 = p_j->id;
00098       register char excl_flag = ( (atom2 >= excl_min && atom2 <= excl_max) ?
00099                                         excl_flags[atom2-excl_min] : 0 );
00100       if ( excl_flag ) { ++exclChecksum; }
00101       SELF( if ( j < j_hgroup ) { excl_flag = EXCHCK_FULL; } )
00102       if ( excl_flag ) {
00103         if ( excl_flag == EXCHCK_FULL ) {
00104           lj_pars = lj_null_pars;
00105           modf = 1.0;
00106         } else {
00107           ++lj_pars;
00108           modf = modf_mod;
00109         }
00110       }
00111       */
00112 
00113       BigReal kqq = kq_i * p_j->charge;
00114 
00115       LES( BigReal lambda_pair = lambda_table_i[p_j->partition]; )
00116 
00117       register const BigReal p_ij_x = p_i_x - p_j->position.x;
00118       register const BigReal p_ij_y = p_i_y - p_j->position.y;
00119       register const BigReal p_ij_z = p_i_z - p_j->position.z;
00120       
00121 #if ( FAST(1+) 0 )
00122       const BigReal A = scaling * lj_pars->A;
00123       const BigReal B = scaling * lj_pars->B;
00124 
00125       BigReal vdw_d = A * table_four_i[0] - B * table_four_i[2];
00126       BigReal vdw_c = A * table_four_i[1] - B * table_four_i[3];
00127       BigReal vdw_b = A * table_four_i[4] - B * table_four_i[6];
00128       BigReal vdw_a = A * table_four_i[5] - B * table_four_i[7];
00129 
00130       ALCHPAIR (
00131         // Alchemical free energy calculation
00132         // Pairlists are separated so that lambda-coupled pairs are handled
00133         // independently from normal nonbonded (inside ALCHPAIR macro).
00134         // The separation-shifted van der Waals potential and a shifted 
00135         // electrostatics potential for decoupling are calculated explicitly.
00136         // Would be faster with lookup tables but because only a small minority
00137         // of nonbonded pairs are lambda-coupled the impact is minimal. 
00138         // Explicit calculation also makes things easier to modify.
00139         
00140         const BigReal r2 = r2list[k] - r2_delta;
00141 
00142         // These are now inline functions (in ComputeNonbondedFep.C) to 
00143         // tidy the code
00144 
00145         FEP(fep_vdw_forceandenergies(A,B,r2,myVdwShift,myVdwShift2,switchdist2,
00146           cutoff2, myVdwLambda, myVdwLambda2, Fep_WCA_repuOn, Fep_WCA_dispOn,
00147           WCA_rcut1, WCA_rcut2, switchfactor, &alch_vdw_energy, 
00148           &alch_vdw_force,&alch_vdw_energy_2);)
00149         TI(ti_vdw_force_energy_dUdl(A,B,r2,myVdwShift,switchdist2,
00150           cutoff2, myVdwLambda, alchVdwShiftCoeff, switchfactor, 
00151           &alch_vdw_energy, &alch_vdw_force, &alch_vdw_dUdl);)
00152       )
00153       
00154       NOT_ALCHPAIR(
00155       TABENERGY(
00156         if (tabtype >= 0) {
00157           register BigReal r1;
00158           r1 = sqrt(p_ij_x*p_ij_x + p_ij_y*p_ij_y + p_ij_z*p_ij_z);
00159           //CkPrintf("%i %i %f %f %i\n", npertype, tabtype, r1, table_spacing, (int) (mynearbyint(r1 / table_spacing)));
00160           register int eneraddress;
00161           eneraddress = 2 * ((npertype * tabtype) + ((int) mynearbyint(r1 / table_spacing)));
00162           //CkPrintf("Using distance bin %i for distance %f\n", eneraddress, r1);
00163           vdw_d = 0.;
00164           vdw_c = 0.;
00165           vdw_b = table_ener[eneraddress + 1] / r1;
00166           vdw_a = (-1/2.) * diffa * vdw_b;
00167           ENERGY(
00168             register BigReal vdw_val = table_ener[eneraddress];
00169             //CkPrintf("Found vdw energy of %f\n", vdw_val);
00170             vdwEnergy += LAM(lambda_pair *) vdw_val;
00171             FEP( vdwEnergy_s += d_lambda_pair * vdw_val; )
00172           )
00173         }  else {
00174       )
00175       ENERGY(
00176         register BigReal vdw_val =
00177           ( ( diffa * vdw_d * (1/6.)+ vdw_c * (1/4.)) * diffa + vdw_b *(1/2.)) * diffa + vdw_a;
00178         vdwEnergy -= LAM(lambda_pair *) vdw_val;
00179         FEP(vdwEnergy_s -= vdw_val;)
00180       )
00181       TABENERGY( } ) /* endif (tabtype >= 0) */
00182       ) // NOT_ALCHPAIR
00183 
00184       ALCHPAIR(
00185         ENERGY(vdwEnergy   += alch_vdw_energy;)
00186         FEP(vdwEnergy_s += alch_vdw_energy_2;)
00187         TI(ALCH1(vdwEnergy_ti_1) ALCH2(vdwEnergy_ti_2) += alch_vdw_dUdl;)
00188       ) // ALCHPAIR
00189       
00190 #endif // FAST
00191 
00192 #if ( FAST(1+) 0 )
00193      INT( 
00194       register BigReal vdw_dir;
00195       vdw_dir = ( diffa * vdw_d + vdw_c ) * diffa + vdw_b;
00196       //BigReal force_r =  LAM(lambda_pair *) vdw_dir;
00197       reduction[pairVDWForceIndex_X] += force_sign * vdw_dir * p_ij_x;
00198       reduction[pairVDWForceIndex_Y] += force_sign * vdw_dir * p_ij_y;
00199       reduction[pairVDWForceIndex_Z] += force_sign * vdw_dir * p_ij_z;
00200       )
00201 
00202 #if ( SHORT(1+) 0 ) // Short-range electrostatics
00203 
00204       NORMAL(
00205       BigReal fast_d = kqq * table_four_i[8];
00206       BigReal fast_c = kqq * table_four_i[9];
00207       BigReal fast_b = kqq * table_four_i[10];
00208       BigReal fast_a = kqq * table_four_i[11];
00209       )
00210       MODIFIED(
00211       BigReal modfckqq = (1.0-modf_mod) * kqq;
00212       BigReal fast_d = modfckqq * table_four_i[8];
00213       BigReal fast_c = modfckqq * table_four_i[9];
00214       BigReal fast_b = modfckqq * table_four_i[10];
00215       BigReal fast_a = modfckqq * table_four_i[11];
00216       )
00217     
00218       {
00219       ENERGY(
00220       register BigReal fast_val =
00221         ( ( diffa * fast_d * (1/6.)+ fast_c * (1/4.)) * diffa + fast_b *(1/2.)) * diffa + fast_a;
00222       NOT_ALCHPAIR (
00223         electEnergy -=  LAM(lambda_pair *) fast_val;
00224         FEP(electEnergy_s -= fast_val;)
00225       )
00226       ) //ENERGY
00227       ALCHPAIR(
00228         ENERGY(electEnergy   -= myElecLambda * fast_val;)
00229         FEP(electEnergy_s -= myElecLambda2 * fast_val;)
00230         TI(
00231           NOENERGY(register BigReal fast_val = 
00232             ( ( diffa * fast_d * (1/6.)+ fast_c * (1/4.)) * diffa + fast_b *(1/2.)) * diffa + fast_a;)
00233           ALCH1(electEnergy_ti_1) ALCH2(electEnergy_ti_2)  -= fast_val;
00234         )
00235       )
00236 
00237       INT(
00238       register BigReal fast_dir =
00239       ( diffa * fast_d + fast_c ) * diffa + fast_b;
00240       // force_r -= -1.0 * LAM(lambda_pair *) fast_dir;
00241       reduction[pairElectForceIndex_X] +=  force_sign * fast_dir * p_ij_x;
00242       reduction[pairElectForceIndex_Y] +=  force_sign * fast_dir * p_ij_y;
00243       reduction[pairElectForceIndex_Z] +=  force_sign * fast_dir * p_ij_z;
00244       )
00245       }
00246 
00247 
00248      /*****  JE - Go  *****/
00249      // Now Go energy should appear in VDW place -- put vdw_b back into place
00250      NORMAL (
00251      GO (
00252        BigReal goNative = 0;
00253        BigReal goNonnative = 0;
00254        BigReal goForce = 0;
00255        //  Ported by JLai -- JE - added (
00256        const BigReal r2go = square(p_ij_x, p_ij_y, p_ij_z);
00257        const BigReal rgo = sqrt(r2go);
00258        register const CompAtomExt *pExt_j = pExt_1 + j;
00259        
00260        if (ComputeNonbondedUtil::goMethod == 1) {
00261          goForce = mol->get_go_force(rgo, pExt_i.id, pExt_j->id, &goNative, &goNonnative);
00262        } else {  // goMethod == 3
00263          goForce = mol->get_go_force_new(rgo, pExt_i.id, pExt_j->id, &goNative, &goNonnative);
00264        }
00265        
00266        fast_b += goForce;
00267        //       printf("FORCE: \t%4.2f\t%4.2f\t%4.2f\t%4.2f\n", goForce, p_ij_x, p_ij_y, p_ij_z);
00268        //BigReal goEnergy = mol->get_go_energy_new(rgo, pExt_i.id, pExt_j->id);
00269        {
00270        ENERGY(
00271          NOT_ALCHPAIR (
00272                        // JLai
00273                        goEnergyNative +=  goNative;
00274                        goEnergyNonnative += goNonnative;
00275          )
00276        ) //ENERGY                                                                                                                                                  
00277          INT(
00278            reduction[pairVDWForceIndex_X] +=  force_sign * goForce * p_ij_x;
00279            reduction[pairVDWForceIndex_Y] +=  force_sign * goForce * p_ij_y;
00280            reduction[pairVDWForceIndex_Z] +=  force_sign * goForce * p_ij_z;
00281          )
00282        }
00283        // End of INT 
00284 
00285        //DebugM(3,"rgo:" << rgo << ", pExt_i.id:" << pExt_i.id << ", pExt_j->id:" << pExt_j->id << \
00286          //      ", goForce:" << goForce << ", fast_b:" << fast_b << std::endl);
00287      ) // End of GO macro 
00288      /*****  JE - End Go  *****/
00289      // End of port JL
00290      ) // End of Normal MACRO
00291 
00292       // Combined short-range electrostatics and VdW force:
00293       NOT_ALCHPAIR(
00294         fast_d += vdw_d;
00295         fast_c += vdw_c;
00296         fast_b += vdw_b;
00297         fast_a += vdw_a;  // not used!
00298       )
00299       register BigReal fast_dir =
00300                   (diffa * fast_d + fast_c) * diffa + fast_b;
00301       BigReal force_r =  LAM(lambda_pair *) fast_dir;
00302       ALCHPAIR(
00303         force_r *= myElecLambda; 
00304         force_r += alch_vdw_force;
00305         // special ALCH forces already multiplied by relevant lambda
00306       )
00307           
00308 #ifndef NAMD_CUDA
00309       register BigReal tmp_x = force_r * p_ij_x;
00310       PAIR( virial_xx += tmp_x * p_ij_x; )
00311       PAIR( virial_xy += tmp_x * p_ij_y; )
00312       PAIR( virial_xz += tmp_x * p_ij_z; )
00313 
00314       f_i_x += tmp_x;
00315       f_j->x -= tmp_x;
00316 
00317       register BigReal tmp_y = force_r * p_ij_y;
00318       PAIR( virial_yy += tmp_y * p_ij_y; )
00319       PAIR( virial_yz += tmp_y * p_ij_z; )
00320       f_i_y += tmp_y;
00321       f_j->y -= tmp_y;
00322       
00323       register BigReal tmp_z = force_r * p_ij_z;
00324       PAIR( virial_zz += tmp_z * p_ij_z; )
00325       f_i_z += tmp_z;
00326       f_j->z -= tmp_z;
00327 
00328       PPROF(
00329         const BigReal p_j_z = p_j->position.z;
00330         int n2 = (int)floor((p_j_z-pressureProfileMin)*invThickness);
00331         pp_clamp(n2, pressureProfileSlabs);
00332         int p_j_partition = p_j->partition;
00333 
00334         pp_reduction(pressureProfileSlabs, n1, n2, 
00335                      p_i_partition, p_j_partition, pressureProfileAtomTypes,
00336                      tmp_x*p_ij_x, tmp_y * p_ij_y, tmp_z*p_ij_z,
00337                      pressureProfileReduction);
00338 
00339       )
00340 #endif
00341 
00342 #endif // SHORT
00343 #endif // FAST
00344 
00345 #if ( FULL (EXCLUDED( SHORT ( 1+ ) ) ) 0 ) 
00346       const BigReal* const slow_i = slow_table + 4*table_i;
00347 
00348 #ifdef ARCH_POWERPC  //Alignment and aliasing constraints
00349       __alignx (16, slow_i);
00350 #if ( SHORT( FAST( 1+ ) ) 0 ) 
00351 #pragma disjoint (*slow_i, *f_j)
00352 #endif
00353 #pragma disjoint (*slow_i, *fullf_j)
00354 #endif  //ARCH_POWERPC
00355 
00356 #endif //FULL 
00357 
00358 
00359 #if ( FULL (MODIFIED( SHORT ( 1+ ) ) ) 0 ) 
00360       const BigReal* const slow_i = slow_table + 4*table_i;
00361 
00362 #ifdef ARCH_POWERPC //Alignment and aliasing constraints
00363       __alignx (16, slow_i);
00364 #if ( SHORT( FAST( 1+ ) ) 0 ) 
00365 #pragma disjoint (*slow_i, *f_j)
00366 #endif
00367 #pragma disjoint (*slow_i, *fullf_j)
00368 #endif //ARCH_POWERPC
00369 
00370 #endif //FULL
00371       
00372 #if ( FULL( 1+ ) 0 )
00373       BigReal slow_d = table_four_i[8 SHORT(+ 4)];
00374       BigReal slow_c = table_four_i[9 SHORT(+ 4)];
00375       BigReal slow_b = table_four_i[10 SHORT(+ 4)];
00376       BigReal slow_a = table_four_i[11 SHORT(+ 4)];
00377       EXCLUDED(
00378       SHORT(
00379       slow_a +=    slow_i[0];
00380       slow_b += 2.*slow_i[1];
00381       slow_c += 4.*slow_i[2];
00382       slow_d += 6.*slow_i[3];
00383       )
00384       NOSHORT(
00385       slow_d -= table_four_i[12];
00386       slow_c -= table_four_i[13];
00387       slow_b -= table_four_i[14];
00388       slow_a -= table_four_i[15];
00389       )
00390       )
00391       MODIFIED(
00392       SHORT(
00393       slow_a +=    modf_mod * slow_i[0];
00394       slow_b += 2.*modf_mod * slow_i[1];
00395       slow_c += 4.*modf_mod * slow_i[2];
00396       slow_d += 6.*modf_mod * slow_i[3];
00397       )
00398       NOSHORT(
00399       slow_d -= modf_mod * table_four_i[12];
00400       slow_c -= modf_mod * table_four_i[13];
00401       slow_b -= modf_mod * table_four_i[14];
00402       slow_a -= modf_mod * table_four_i[15];
00403       )
00404       )
00405       slow_d *= kqq;
00406       slow_c *= kqq;
00407       slow_b *= kqq;
00408       slow_a *= kqq;
00409 
00410       ENERGY(
00411       register BigReal slow_val =
00412         ( ( diffa * slow_d *(1/6.)+ slow_c * (1/4.)) * diffa + slow_b *(1/2.)) * diffa + slow_a;
00413       
00414       NOT_ALCHPAIR (
00415         fullElectEnergy -= LAM(lambda_pair *) slow_val;
00416         FEP(fullElectEnergy_s -= slow_val;) 
00417       )
00418       ) // ENERGY
00419           
00420       ALCHPAIR(
00421         ENERGY(fullElectEnergy   -= myElecLambda * slow_val;)
00422         FEP(fullElectEnergy_s -= myElecLambda2 * slow_val;)
00423         TI(
00424           NOENERGY(register BigReal slow_val =
00425                 ( ( diffa * slow_d *(1/6.)+ slow_c * (1/4.)) * diffa + slow_b *(1/2.)) * diffa + slow_a;)
00426           ALCH1(fullElectEnergy_ti_1) ALCH2(fullElectEnergy_ti_2) -= slow_val;
00427         )
00428       )
00429 
00430       INT( {
00431       register BigReal slow_dir =
00432         ( diffa * slow_d + slow_c ) * diffa + slow_b;
00433       reduction[pairElectForceIndex_X] += force_sign * slow_dir * p_ij_x;
00434       reduction[pairElectForceIndex_Y] += force_sign * slow_dir * p_ij_y;
00435       reduction[pairElectForceIndex_Z] += force_sign * slow_dir * p_ij_z;
00436       } )
00437 
00438 
00439       NOT_ALCHPAIR (
00440         FAST(
00441         NOSHORT(
00442         slow_d += vdw_d;
00443         slow_c += vdw_c;
00444         slow_b += vdw_b;
00445         slow_a += vdw_a; // unused!
00446         )
00447         )
00448       )
00449       register BigReal slow_dir = (diffa * slow_d + slow_c) * diffa + slow_b;
00450       BigReal fullforce_r = slow_dir LAM(* lambda_pair);
00451       ALCHPAIR (
00452         fullforce_r *= myElecLambda;
00453         FAST( NOSHORT(
00454           fullforce_r += alch_vdw_force;
00455         ))
00456       )
00457           
00458 #ifndef NAMD_CUDA
00459       {
00460       register BigReal tmp_x = fullforce_r * p_ij_x;
00461       PAIR( fullElectVirial_xx += tmp_x * p_ij_x; )
00462       PAIR( fullElectVirial_xy += tmp_x * p_ij_y; )
00463       PAIR( fullElectVirial_xz += tmp_x * p_ij_z; )
00464       fullf_i_x += tmp_x;
00465       fullf_j->x -= tmp_x;
00466       register BigReal tmp_y = fullforce_r * p_ij_y;
00467       PAIR( fullElectVirial_yy += tmp_y * p_ij_y; )
00468       PAIR( fullElectVirial_yz += tmp_y * p_ij_z; )
00469       fullf_i_y += tmp_y;
00470       fullf_j->y -= tmp_y;
00471       register BigReal tmp_z = fullforce_r * p_ij_z;
00472       PAIR( fullElectVirial_zz += tmp_z * p_ij_z; )
00473       fullf_i_z += tmp_z;
00474       fullf_j->z -= tmp_z;
00475 
00476       PPROF(
00477         const BigReal p_j_z = p_j->position.z;
00478         int n2 = (int)floor((p_j_z-pressureProfileMin)*invThickness);
00479         pp_clamp(n2, pressureProfileSlabs);
00480         int p_j_partition = p_j->partition;
00481 
00482         pp_reduction(pressureProfileSlabs, n1, n2, 
00483                      p_i_partition, p_j_partition, pressureProfileAtomTypes,
00484                      tmp_x*p_ij_x, tmp_y * p_ij_y, tmp_z*p_ij_z,
00485                      pressureProfileReduction);
00486 
00487       )
00488 
00489       }
00490 #endif
00491 #endif //FULL
00492 
00493    } // for pairlist
00494 

Generated on Fri May 25 04:07:14 2012 for NAMD by  doxygen 1.3.9.1