kCalculateCDLJEwaldReciprocal.h 4.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2009 Stanford University and the Authors.           *
 * Authors: Rossen P. Apostolov, Peter Eastman                                     *
 * Contributors:                                                              *
 *                                                                            *
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
 *                                                                            *
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
 * -------------------------------------------------------------------------- */

/**
 * This file contains the kernel for evaluating nonbonded forces using the
 * Ewald summation method (Reciprocal space summation).
 */


__global__ void kCalculateCDLJEwaldReciprocalForces_kernel()
{
35
    const float eps0 = 1.0f/(4.0f*3.1415926535f*cSim.epsfac);
36
37
38

    unsigned int atomID1    = threadIdx.x + blockIdx.x * blockDim.x;

39
    while (atomID1 < cSim.atoms)
40
    {
41
42
43
        float4 apos1 = cSim.pPosq[atomID1];
        float4 af    = cSim.pForce4[atomID1];
        unsigned int atomID2 = 0;
44
45
        while (atomID2 < cSim.atoms)
        {
46
47
48
49
50
51
            float4 apos2 = cSim.pPosq[atomID2];
            float scale = 2.0f*apos1.w*apos2.w/(cSim.cellVolume*eps0);

            int lowry = 0;
            int lowrz = 1;

52
            for(int rx = 0; rx < cSim.kmaxX; rx++)
53
54
            {
                float kx = rx*cSim.recipBoxSizeX;
55
                for(int ry = lowry; ry < cSim.kmaxY; ry++)
56
57
                {
                    float ky = ry*cSim.recipBoxSizeY;
58
                    for (int rz = lowrz; rz < cSim.kmaxZ; rz++)
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
                    {
                        float kz = rz*cSim.recipBoxSizeZ;
                        float k2 = kx*kx + ky*ky + kz*kz;
                        float ek = exp(k2*cSim.factorEwald);

                        float arg1 = kx*apos1.x + ky*apos1.y + kz*apos1.z;
                        float arg2 = kx*apos2.x + ky*apos2.y + kz*apos2.z;
                        float sinI = sin(arg1);
                        float sinJ = sin(arg2);
                        float cosI = cos(arg1);
                        float cosJ = cos(arg2);

                        float f = scale * ek * (-sinI*cosJ + cosI*sinJ) / k2;
                        af.x -= kx*f;
                        af.y -= ky*f;
                        af.z -= kz*f;

76
                        lowrz = 1 - cSim.kmaxZ;
77
                    }
78
                    lowry = 1 - cSim.kmaxY;
79
                }
80
81
            }
            atomID2++;
82
       }
83
84
       cSim.pForce4[atomID1] = af;
       atomID1 += blockDim.x * gridDim.x;
85
86
87

    }
}