gbsaObcReductions.cl 2.85 KB
Newer Older
1
2
#define DIELECTRIC_OFFSET 0.009f
#define PROBE_RADIUS 0.14f
3
4
5
6
7
8

/**
 * Reduce the Born sums to compute the Born radii.
 */

__kernel void reduceBornSum(int bufferSize, int numBuffers, float alpha, float beta, float gamma,
9
#ifdef SUPPORTS_64_BIT_ATOMICS
10
            __global const long* restrict bornSum,
11
#else
12
            __global const real* restrict bornSum,
13
#endif
14
            __global const float2* restrict params, __global real* restrict bornRadii, __global real* restrict obcChain) {
15
16
17
18
19
    unsigned int index = get_global_id(0);
    while (index < NUM_ATOMS) {
        // Get summed Born data

        int totalSize = bufferSize*numBuffers;
20
#ifdef SUPPORTS_64_BIT_ATOMICS
21
        real sum = (1/(real) 0x100000000)*bornSum[index];
22
#else
23
        real sum = bornSum[index];
24
25
        for (int i = index+bufferSize; i < totalSize; i += bufferSize)
            sum += bornSum[i];
26
#endif
27
28
29
30
31

        // Now calculate Born radius and OBC term.

        float offsetRadius = params[index].x;
        sum *= 0.5f*offsetRadius;
32
33
34
35
36
37
38
        real sum2 = sum*sum;
        real sum3 = sum*sum2;
        real tanhSum = tanh(alpha*sum - beta*sum2 + gamma*sum3);
        real nonOffsetRadius = offsetRadius + DIELECTRIC_OFFSET;
        real radius = 1/(1/offsetRadius - tanhSum/nonOffsetRadius);
        real chain = offsetRadius*(alpha - 2*beta*sum + 3*gamma*sum2);
        chain = (1-tanhSum*tanhSum)*chain / nonOffsetRadius;
39
40
41
42
43
44
45
46
47
48
        bornRadii[index] = radius;
        obcChain[index] = chain;
        index += get_global_size(0);
    }
}

/**
 * Reduce the Born force.
 */

49
__kernel void reduceBornForce(int bufferSize, int numBuffers, __global real* bornForce,
50
#ifdef SUPPORTS_64_BIT_ATOMICS
51
            __global const long* restrict bornForceIn,
52
#endif
53
54
            __global real* restrict energyBuffer, __global const float2* restrict params, __global const real* restrict bornRadii, __global const real* restrict obcChain) {
    real energy = 0.0f;
55
56
57
58
59
    unsigned int index = get_global_id(0);
    while (index < NUM_ATOMS) {
        // Sum the Born force

        int totalSize = bufferSize*numBuffers;
60
#ifdef SUPPORTS_64_BIT_ATOMICS
61
        real force = (1/(real) 0x100000000)*bornForceIn[index];
62
#else
63
        real force = bornForce[index];
64
65
        for (int i = index+bufferSize; i < totalSize; i += bufferSize)
            force += bornForce[i];
66
#endif
67
68
69
        // Now calculate the actual force

        float offsetRadius = params[index].x;
70
71
72
73
        real bornRadius = bornRadii[index];
        real r = offsetRadius+DIELECTRIC_OFFSET+PROBE_RADIUS;
        real ratio6 = pow((offsetRadius+DIELECTRIC_OFFSET)/bornRadius, (real) 6);
        real saTerm = SURFACE_AREA_FACTOR*r*r*ratio6;
74
75
76
77
78
79
80
81
        force += saTerm/bornRadius;
        energy += saTerm;
        force *= bornRadius*bornRadius*obcChain[index];
        bornForce[index] = force;
        index += get_global_size(0);
    }
    energyBuffer[get_global_id(0)] += energy/-6.0f;
}