Index: Controller.C
===================================================================
RCS file: /namd/cvsroot/namd2/src/Controller.C,v
retrieving revision 1.1236
diff -r1.1236 Controller.C
1064c1064
<       if (simParameters->wattailcorr) {
---
>       if (simParameters->LJcorrection) {
1066,1068c1066
<         //printf("Volume is %f\n", volume);
<         //printf("Applying tail correction of %f to virial\n", molecule->tail_corr_virial / volume);
<         virial_normal += Tensor::identity(molecule->tail_corr_virial / volume);
---
>         virial_normal += Tensor::identity(molecule->LRdisp_corr / (volume));
1368c1366
<     if (simParameters->wattailcorr) {
---
>     if (simParameters->LJcorrection) {
1370,1372c1368
<       //printf("Volume is %f\n", volume);
<       //printf("Applying tail correction of %f to energy\n", molecule->tail_corr_ener / volume);
<       ljEnergy += molecule->tail_corr_ener / volume;
---
>       ljEnergy += molecule->LRdisp_corr / volume;
Index: Molecule.C
===================================================================
RCS file: /namd/cvsroot/namd2/src/Molecule.C,v
retrieving revision 1.1160
diff -r1.1160 Molecule.C
8118a8119,8204
>   // long-range dispersion correction (FB)
>   // Allen and Tildesley, Computer Simulation of Liquids, 1991
>   // J. Chem. Phys. 120, 9665 (2004)
>   // integrated for NAMD's LJ switch function
>   
>   if (simParams->LJcorrection) {
>     Real A; Real B;
>     Real A14; Real B14;
>     
>     // first calculate average dispersion coefficient
>     
>     // count LJ types (probably available elsewhere...?)
>     i = 0;
>     while (params->get_vdw_pair_params(i, i, &A, &B, &A14, &B14)) { i ++; }
>     int LJtypecount = i;
>     
>     Real BTable[LJtypecount*LJtypecount];
>     for (i = 0; i < LJtypecount; i++) {
>       for (int j = 0; j < LJtypecount; j++) {
>         params->get_vdw_pair_params(i, j, &A, &B, &A14, &B14);
>         BTable[i*LJtypecount + j] = B;
>       }
>     }
> 
>     int numAtomsByLjType[LJtypecount];
>     for (i = 0; i < LJtypecount; i++) {numAtomsByLjType[i]=0;}
>     for (i = 0; i < numAtoms;  i++) {numAtomsByLjType[atoms[i].vdw_type] ++;}
> 
>     BigReal sumOfBs = 0; int count = 0;
>     for (i = 0;  i < LJtypecount;  i++) {
>       if (numAtomsByLjType[i]) {
>         for (int j = 0;  j < LJtypecount;  j++) {
>           if (i == j) {
>             sumOfBs += (numAtomsByLjType[i] - 1) * numAtomsByLjType[j] * BTable[i*LJtypecount + j];
>             count += (numAtomsByLjType[i] - 1) * numAtomsByLjType[j];
>           }
>           else {
>             sumOfBs += (numAtomsByLjType[i]) * numAtomsByLjType[j] * BTable[i*LJtypecount + j];
>             count += (numAtomsByLjType[i]) * numAtomsByLjType[j];
>           }
>         }
>       }
>     }
>     
> 
>     // this naive algorithm (time-consuming n*(n-1)/2) gives the same result
>     //BigReal sumOfBs = 0; int count = 0;
>     //for (i = 0;  i < numAtoms;  i++) {
>     //  for (int j = i + 1; j < numAtoms; j++) {
>     //    params->get_vdw_pair_params(atoms[i].vdw_type, atoms[j].vdw_type, &A, &B, &A14, &B14);
>     //    sumOfBs += B;
>     //    count ++;
>     //  }
>     //}
> 
> 
>     // discard modified / excluded pairings
>     // should be negligible but more correct
>     
>     for (i=0; i < numExclusions; i++) {
>       int a1 = exclusions[i].atom1;
>       int a2 = exclusions[i].atom2;
>       if (a1 != a2) {  
>         params->get_vdw_pair_params(atoms[a1].vdw_type, atoms[a2].vdw_type, &A, &B, &A14, &B14);
>         sumOfBs -= B;
>         count -= 1;
>       }
>     }
>     
>     BigReal LJAvgB = sumOfBs / count;
>     iout << iINFO << "AVERAGE B VALUE FOR LONG RANGE DISPERSION CORRECTION: " 
>       << LJAvgB << "\n" << endi;
>     
>     BigReal rswitch = simParams->switchingDist;
>     BigReal rcut = simParams->cutoff;
>     
>     LRdisp_corr = (-16 * LJAvgB * numAtoms * numAtoms * PI) / (3 * (rcut+rswitch) * (rcut+rswitch) * (rcut+rswitch));
>     
>     iout << iINFO << "LONG-RANGE DISPERSION CORRECTION: " 
>       << LRdisp_corr << " KCAL * A^3 * MOL-1 \n" << endi;
>       
>   }
>   
>   // end dispersion correction
> 
> 
Index: Molecule.h
===================================================================
RCS file: /namd/cvsroot/namd2/src/Molecule.h,v
retrieving revision 1.1082
diff -r1.1082 Molecule.h
334,336c334
<   // data for tail corrections
<   BigReal tail_corr_ener;
<   BigReal tail_corr_virial;
---
>   BigReal LRdisp_corr;
Index: SimParameters.C
===================================================================
RCS file: /namd/cvsroot/namd2/src/SimParameters.C,v
retrieving revision 1.1276
diff -r1.1276 SimParameters.C
446c446,450
<    opts.optionalB("main", "waterTailCorr", "Apply VDW tail corrections to water", &wattailcorr, FALSE);
---
> 
>    opts.optionalB("main", "LJcorrection", 
>       "Apply analytical correction to energy and pressure for long-range dispersion interactions",
>       &LJcorrection, FALSE);
> 
Index: SimParameters.h
===================================================================
RCS file: /namd/cvsroot/namd2/src/SimParameters.h,v
retrieving revision 1.1151
diff -r1.1151 SimParameters.h
87c87
<   Bool wattailcorr; // flag for whether water tail corrections should be used
---
>   Bool LJcorrection; // flag for analytical long-range correction to LJ dispersion
