monteCarloBarostat.cl 1.36 KB
Newer Older
1
2
3
4
/**
 * Scale the particle positions with each axis independent.
 */

5
6
__kernel void scalePositions(float scaleX, float scaleY, float scaleZ, int numMolecules, real4 periodicBoxSize, real4 invPeriodicBoxSize,
        real4 periodicBoxVecX, real4 periodicBoxVecY, real4 periodicBoxVecZ, __global real4* restrict posq,
7
8
9
10
11
12
13
14
        __global const int* restrict moleculeAtoms, __global const int* restrict moleculeStartIndex) {
    for (int index = get_global_id(0); index < numMolecules; index += get_global_size(0)) {
        int first = moleculeStartIndex[index];
        int last = moleculeStartIndex[index+1];
        int numAtoms = last-first;

        // Find the center of each molecule.

15
        real3 center = (real3) 0;
16
        for (int atom = first; atom < last; atom++)
17
            center += posq[moleculeAtoms[atom]].xyz;
18
19
20
21
        center /= (real) numAtoms;

        // Move it into the first periodic box.

22
23
24
25
        real3 oldCenter = center;
        APPLY_PERIODIC_TO_POS(center)
        real3 delta = oldCenter-center;;
        real3 scaleXYZ = (real3) (scaleX, scaleY, scaleZ);
26
27
28
29
30
31
32
33
34
35
36

        // Now scale the position of the molecule center.

        delta = center*(scaleXYZ-1)-delta;
        for (int atom = first; atom < last; atom++) {
            real4 pos = posq[moleculeAtoms[atom]];
            pos.xyz += delta.xyz;
            posq[moleculeAtoms[atom]] = pos;
        }
    }
}