head	1.2;
access;
symbols
	release-2-6:1.1
	release-2-6-beta-2:1.1
	release-2-6-beta-1:1.1
	release-2-5:1.1
	release-2-5-beta-3:1.1
	release-2-5-beta-2:1.1;
locks; strict;
comment	@ * @;


1.2
date	2008.06.30.22.55.38;	author char;	state Exp;
branches;
next	1.1;

1.1
date	2003.04.04.15.54.22;	author jim;	state Exp;
branches;
next	;


desc
@@


1.2
log
@*** added new softcore FEP and TI ***
@
text
@/**
***  Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by
***  The Board of Trustees of the University of Illinois.
***  All rights reserved.
**/

/*
   Common operations for ComputeNonbonded classes
*/

#include "ComputeNonbondedInl.h"

// 3 inline functions to handle explicit calculation of separation-shifted
// vdW for FEP and TI, and a shifted electrostatics potential for decoupling

/* ******************************************** */
/* vdW energy, force and lambda2 energy for FEP */
/* ******************************************** */
inline void fep_vdw_forceandenergies (BigReal A, BigReal B, BigReal r2, 
  BigReal myVdwShift, BigReal myVdwShift2, BigReal switchdist2, BigReal cutoff2, 
  BigReal myVdwLambda, BigReal myVdwLambda2, BigReal switchfactor,
  BigReal* alch_vdw_energy, BigReal* alch_vdw_force, 
  BigReal* alch_vdw_energy_2) {
  const BigReal r2_1 = r2 + myVdwShift;  //myVdwShift already multplied by relevant (1-vdwLambda)
  const BigReal r6_1 = r2_1*r2_1*r2_1;
  const BigReal r2_2 = r2 + myVdwShift2;
  const BigReal r6_2 = r2_2*r2_2*r2_2;
  
  // switching function (this is correct whether switching is active or not)
  const BigReal switchmul = r2 > switchdist2? \
           switchfactor*(cutoff2 - r2)*(cutoff2 - r2)*(cutoff2 - 3.*switchdist2 + 2.*r2) \
           : 1.;
  const BigReal switchmul2 = (r2 > switchdist2)? \
           12.*switchfactor*(cutoff2 - r2)*(r2 - switchdist2) : 0.;
  // separation-shifted vdW force and energy
  *alch_vdw_energy = A/(r6_1*r6_1) - B/r6_1;
  *alch_vdw_force =  myVdwLambda * (  \
                    + (12.*(*alch_vdw_energy) + 6.*B/r6_1)/r2_1 * switchmul \
                    + (*alch_vdw_energy) * switchmul2);
  *alch_vdw_energy *= myVdwLambda*switchmul;
  *alch_vdw_energy_2 = (A/(r6_2*r6_2) - B/r6_2) * myVdwLambda2 * switchmul;
}

/* ********************************** */
/* vdW energy, force and dU/dl for TI */
/* ********************************** */
inline void ti_vdw_force_energy_dUdl (BigReal A, BigReal B, BigReal r2, 
  BigReal myVdwShift, BigReal switchdist2, BigReal cutoff2, 
  BigReal myVdwLambda, BigReal fepVdwShiftCoeff, BigReal switchfactor, 
  BigReal* alch_vdw_energy, BigReal* alch_vdw_force, BigReal* alch_vdw_dUdl) {
  const BigReal r2_1 = r2 + myVdwShift;  //myVdwShift already multplied by relevant (1-vdwLambda)
  const BigReal r6_1 = r2_1*r2_1*r2_1;
    
  // switching function (this is correct whether switching is active or not)
  const BigReal switchmul = r2 > switchdist2? \
           switchfactor*(cutoff2 - r2)*(cutoff2 - r2)*(cutoff2 - 3.*switchdist2 + 2.*r2) \
           : 1.;
  const BigReal switchmul2 = (r2 > switchdist2)? \
           12.*switchfactor*(cutoff2 - r2)*(r2 - switchdist2) : 0.;
  // separation-shifted vdW force and energy
  *alch_vdw_energy = A/(r6_1*r6_1) - B/r6_1;
  *alch_vdw_force =  myVdwLambda * (  \
                    + (12.*(*alch_vdw_energy) + 6.*B/r6_1)/r2_1 * switchmul \
                    + (*alch_vdw_energy) * switchmul2);
  *alch_vdw_dUdl = (myVdwLambda * fepVdwShiftCoeff * (
            (6*A/(r6_1*r6_1) - 3*B/r6_1) / r2_1 ) + (*alch_vdw_energy))
            * switchmul;  // dU/dlambda
  *alch_vdw_energy *= myVdwLambda*switchmul;
}
  
/* ************************************************************************* */
/* Explicit shifted potential to replace long-range PME electrostatics       */
/* with a short-range substitute - achieves the main objectives of alchemical*/
/* decoupling more cheaply than doing it as pure PME                         */
/* ***************************************************************************/
inline void shiftedpotential(BigReal r2, BigReal cutoff2, BigReal kqq,
  BigReal myElecLambda, BigReal* shiftedElec, BigReal* shiftedElecForce) {
  const BigReal r = sqrt(r2);
  BigReal shiftVal = r2/cutoff2 - 1.0; shiftVal *= shiftVal;
  BigReal dShiftVal = 2.0 * (r2/cutoff2 - 1.0) * 2.0*r/cutoff2;
  *shiftedElec = - kqq * shiftVal / r;
  *shiftedElecForce = - kqq \
    * (dShiftVal/r - shiftVal/r2) * (1 / r) * (1 - myElecLambda);
}

#define FEPFLAG
#define CALCENERGY

#define NBTYPE NBPAIR
#include "ComputeNonbondedBase.h"
#define FULLELECT
#include "ComputeNonbondedBase.h"
#define MERGEELECT
#include "ComputeNonbondedBase.h"
#undef MERGEELECT
#define SLOWONLY
#include "ComputeNonbondedBase.h"
#undef SLOWONLY
#undef FULLELECT
#undef  NBTYPE

#define NBTYPE NBSELF
#include "ComputeNonbondedBase.h"
#define FULLELECT
#include "ComputeNonbondedBase.h"
#define MERGEELECT
#include "ComputeNonbondedBase.h"
#undef MERGEELECT
#define SLOWONLY
#include "ComputeNonbondedBase.h"
#undef SLOWONLY
#undef FULLELECT
#undef  NBTYPE

#undef CALCENERGY
#undef FEPFLAG

/*************THERMODYNAMIC INTEGRATION*************/
#define TIFLAG
#define CALCENERGY

#define NBTYPE NBPAIR
#include "ComputeNonbondedBase.h"
#define FULLELECT
#include "ComputeNonbondedBase.h"
#define MERGEELECT
#include "ComputeNonbondedBase.h"
#undef MERGEELECT
#define SLOWONLY
#include "ComputeNonbondedBase.h"
#undef SLOWONLY
#undef FULLELECT
#undef  NBTYPE

#define NBTYPE NBSELF
#include "ComputeNonbondedBase.h"
#define FULLELECT
#include "ComputeNonbondedBase.h"
#define MERGEELECT
#include "ComputeNonbondedBase.h"
#undef MERGEELECT
#define SLOWONLY
#include "ComputeNonbondedBase.h"
#undef SLOWONLY
#undef FULLELECT
#undef  NBTYPE

#undef CALCENERGY

#define NBTYPE NBPAIR
#include "ComputeNonbondedBase.h"
#define FULLELECT
#include "ComputeNonbondedBase.h"
#define MERGEELECT
#include "ComputeNonbondedBase.h"
#undef MERGEELECT
#define SLOWONLY
#include "ComputeNonbondedBase.h"
#undef SLOWONLY
#undef FULLELECT
#undef  NBTYPE

#define NBTYPE NBSELF
#include "ComputeNonbondedBase.h"
#define FULLELECT
#include "ComputeNonbondedBase.h"
#define MERGEELECT
#include "ComputeNonbondedBase.h"
#undef MERGEELECT
#define SLOWONLY
#include "ComputeNonbondedBase.h"
#undef SLOWONLY
#undef FULLELECT
#undef  NBTYPE

#undef TIFLAG

@


1.1
log
@Split ComputeNonbondedBase.C into smaller files to build on T3E.
@
text
@d13 73
d117 60
@

