NAMD
ComputeNonbondedAlch.h
Go to the documentation of this file.
1 
7 /*****************************************************************************
8  * Inline Lennard-Jones energy/force/utility functions for alchemy *
9  *****************************************************************************/
10 
11 /* Lennard-Jones force and energy.
12  *
13  * If using conventional soft-core, r2 should be passed as r2 + myVdwShift and
14  * the final result should be scaled by myVdwLambda.
15  */
16 inline void vdw_forceandenergy(const BigReal A, const BigReal B,
17  const BigReal r2, BigReal *U, BigReal *F) {
18  const BigReal inv_r2 = 1. / r2;
19  const BigReal inv_r6 = inv_r2*inv_r2*inv_r2;
20  *U = inv_r6*(A*inv_r6 - B);
21  *F = 6*inv_r2*(2*(*U) + B*inv_r6);
22 }
23 
24 // Same as above, energy only.
25 inline void vdw_energy(const BigReal A, const BigReal B,
26  const BigReal r2, BigReal *U) {
27  const BigReal inv_r2 = 1. / r2;
28  const BigReal inv_r6 = inv_r2*inv_r2*inv_r2;
29  *U = inv_r6*(A*inv_r6 - B);
30 }
31 
32 /* Multipliers for the vdW potential switching function and its derivative.
33  * This is correct even if switching is not active.
34  */
35 inline void vdw_switch(const BigReal r2, const BigReal switchdist2,
36  const BigReal cutoff2, const BigReal switchfactor, BigReal* switchmul,
37  BigReal* switchmul2) {
38  if (r2 <= switchdist2) {
39  // "switching off" will always fall through here.
40  *switchmul = 1.0;
41  *switchmul2 = 0.0;
42  } else {
43  const BigReal cdiff2 = (cutoff2 - r2);
44  const BigReal sdiff2 = (r2 - switchdist2);
45  *switchmul = switchfactor*cdiff2*cdiff2*(cdiff2 + 3*sdiff2);
46  *switchmul2 = 12*switchfactor*cdiff2*sdiff2;
47  }
48 }
49 
50 /* Force shifted Lennard-Jones force and energy.
51  *
52  * If using conventional soft-core, r2 and switchdist2 should be passed as
53  * r2 + myVdwShift and switchdist2 + myVdwShift and the final result should be
54  * scaled by myVdwLambda
55  */
56 inline void vdw_fswitch_forceandenergy(const BigReal A, const BigReal B,
57  const BigReal r2, const BigReal switchdist2, const BigReal cutoff2,
58  BigReal* U, BigReal* F) {
59  // TODO: Some rearrangement could be done to use rsqrt() instead?
60  const BigReal inv_r2 = 1. / r2;
61  const BigReal inv_r6 = inv_r2*inv_r2*inv_r2;
62  const BigReal inv_r3 = sqrt(inv_r6);
63  const BigReal inv_cutoff6 = 1. / (cutoff2*cutoff2*cutoff2);
64  const BigReal inv_cutoff3 = sqrt(inv_cutoff6);
65  const BigReal switchdist6 = switchdist2*switchdist2*switchdist2;
66  const BigReal k_vdwa = A / (1 - switchdist6*inv_cutoff6);
67  const BigReal k_vdwb = B / (1 - sqrt(switchdist6*inv_cutoff6));
68  const BigReal tmpa = inv_r6 - inv_cutoff6;
69  const BigReal tmpb = inv_r3 - inv_cutoff3;
70  *U = k_vdwa*tmpa*tmpa - k_vdwb*tmpb*tmpb;
71  *F = 6*inv_r2*(2*k_vdwa*tmpa*inv_r6 - k_vdwb*tmpb*inv_r3);
72 }
73 
74 // Same as above, energy only.
75 inline void vdw_fswitch_energy(const BigReal A, const BigReal B,
76  const BigReal r2, const BigReal switchdist2, const BigReal cutoff2,
77  BigReal* U) {
78  // TODO: Some rearrangement could be done to use rsqrt() instead?
79  const BigReal inv_r2 = 1. / r2;
80  const BigReal inv_r6 = inv_r2*inv_r2*inv_r2;
81  const BigReal inv_r3 = sqrt(inv_r6);
82  const BigReal inv_cutoff6 = 1. / (cutoff2*cutoff2*cutoff2);
83  const BigReal inv_cutoff3 = sqrt(inv_cutoff6);
84  const BigReal switchdist6 = switchdist2*switchdist2*switchdist2;
85  const BigReal k_vdwa = A / (1 - switchdist6*inv_cutoff6);
86  const BigReal k_vdwb = B / (1 - sqrt(switchdist6*inv_cutoff6));
87  const BigReal tmpa = inv_r6 - inv_cutoff6;
88  const BigReal tmpb = inv_r3 - inv_cutoff3;
89  *U = k_vdwa*tmpa*tmpa - k_vdwb*tmpb*tmpb;
90 }
91 
92 /* Energy shifts for the vdW force/potential switching functions.
93  *
94  * If using conventional soft-core, switchdist2 should be passed as
95  * switchdist2 + myVdwShift.
96  */
97 inline void vdw_fswitch_shift(const BigReal A, const BigReal B,
98  const BigReal switchdist2, const BigReal cutoff2, BigReal* dU) {
99  // TODO: Some rearrangement could be done to use rsqrt() instead.
100  const BigReal cutoff6 = cutoff2*cutoff2*cutoff2;
101  const BigReal switchdist6 = switchdist2*switchdist2*switchdist2;
102  const BigReal v_vdwa = -A / (cutoff6*switchdist6);
103  const BigReal v_vdwb = -B / sqrt(cutoff6*switchdist6);
104  *dU = v_vdwa - v_vdwb; //deltaV2 from Steinbach & Brooks
105 }
106 
void vdw_fswitch_energy(const BigReal A, const BigReal B, const BigReal r2, const BigReal switchdist2, const BigReal cutoff2, BigReal *U)
void vdw_forceandenergy(const BigReal A, const BigReal B, const BigReal r2, BigReal *U, BigReal *F)
const BigReal A
void vdw_switch(const BigReal r2, const BigReal switchdist2, const BigReal cutoff2, const BigReal switchfactor, BigReal *switchmul, BigReal *switchmul2)
void vdw_fswitch_forceandenergy(const BigReal A, const BigReal B, const BigReal r2, const BigReal switchdist2, const BigReal cutoff2, BigReal *U, BigReal *F)
void vdw_energy(const BigReal A, const BigReal B, const BigReal r2, BigReal *U)
const BigReal B
void vdw_fswitch_shift(const BigReal A, const BigReal B, const BigReal switchdist2, const BigReal cutoff2, BigReal *dU)
__global__ void const int const TileList *__restrict__ TileExcl *__restrict__ const int *__restrict__ const int const float2 *__restrict__ const int *__restrict__ const float3 const float3 const float3 const float4 *__restrict__ const float cutoff2
double BigReal
Definition: common.h:114