ReferenceKernels.h 11.9 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
35
#ifndef OPENMM_REFERENCEKERNELS_H_
#define OPENMM_REFERENCEKERNELS_H_

/* -------------------------------------------------------------------------- *
 *                                   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) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

#include "kernels.h"
36
#include "SimTKUtilities/SimTKOpenMMRealType.h"
37
#include "SimTKReference/ReferenceNeighborList.h"
38

39
class CpuObc;
40
class ReferenceAndersenThermostat;
41
class ReferenceBrownianDynamics;
42
43
class ReferenceStochasticDynamics;
class ReferenceShakeAlgorithm;
44
class ReferenceVerletDynamics;
45

46
47
48
49
50
namespace OpenMM {

/**
 * This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
 */
51
class ReferenceCalcStandardMMForceFieldKernel : public CalcStandardMMForceFieldKernel {
52
public:
53
    ReferenceCalcStandardMMForceFieldKernel(std::string name, const Platform& platform) : CalcStandardMMForceFieldKernel(name, platform) {
54
    }
55
    ~ReferenceCalcStandardMMForceFieldKernel();
56
    /**
57
     * Initialize the kernel.
58
     * 
59
60
61
62
63
     * @param system     the System this kernel will be applied to
     * @param force      the StandardMMForceField this kernel will be used for
     * @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
     *                   nonbonded forces.  Bonded 1-4 pairs are also included in this list, since they should be omitted from
     *                   the standard nonbonded calculation.
64
     */
65
    void initialize(const System& system, const StandardMMForceField& force, const std::vector<std::set<int> >& exclusions);
66
    /**
67
     * Execute the kernel to calculate the forces.
68
     * 
69
     * @param context    the context in which to execute this kernel
70
     */
71
    void executeForces(OpenMMContextImpl& context);
72
    /**
73
     * Execute the kernel to calculate the energy.
74
     * 
75
     * @param context    the context in which to execute this kernel
76
77
     * @return the potential energy due to the StandardMMForceField
     */
78
    double executeEnergy(OpenMMContextImpl& context);
79
80
81
82
private:
    int numAtoms, numBonds, numAngles, numPeriodicTorsions, numRBTorsions, num14;
    int **bondIndexArray, **angleIndexArray, **periodicTorsionIndexArray, **rbTorsionIndexArray, **exclusionArray, **bonded14IndexArray;
    RealOpenMM **bondParamArray, **angleParamArray, **periodicTorsionParamArray, **rbTorsionParamArray, **atomParamArray, **bonded14ParamArray;
83
84
85
86
    RealOpenMM nonbondedCutoff, periodicBoxSize[3];
    std::vector<std::set<int> > exclusions;
    NonbondedMethod nonbondedMethod;
    NeighborList* neighborList;
87
88
89
90
91
};

/**
 * This kernel is invoked by GBSAOBCForceField to calculate the forces acting on the system.
 */
92
class ReferenceCalcGBSAOBCForceFieldKernel : public CalcGBSAOBCForceFieldKernel {
93
public:
94
    ReferenceCalcGBSAOBCForceFieldKernel(std::string name, const Platform& platform) : CalcGBSAOBCForceFieldKernel(name, platform) {
95
    }
96
    ~ReferenceCalcGBSAOBCForceFieldKernel();
97
    /**
98
     * Initialize the kernel.
99
     * 
100
101
     * @param system     the System this kernel will be applied to
     * @param force      the GBSAOBCForceField this kernel will be used for
102
     */
103
    void initialize(const System& system, const GBSAOBCForceField& force);
104
    /**
105
     * Execute the kernel to calculate the forces.
106
     * 
107
     * @param context    the context in which to execute this kernel
108
     */
109
    void executeForces(OpenMMContextImpl& context);
110
    /**
111
     * Execute the kernel to calculate the energy.
112
     * 
113
     * @param context    the context in which to execute this kernel
114
115
     * @return the potential energy due to the GBSAOBCForceField
     */
116
    double executeEnergy(OpenMMContextImpl& context);
117
118
119
private:
    CpuObc* obc;
    std::vector<RealOpenMM> charges;
120
121
122
123
124
125
126
};

/**
 * This kernel is invoked by VerletIntegrator to take one time step.
 */
class ReferenceIntegrateVerletStepKernel : public IntegrateVerletStepKernel {
public:
127
128
    ReferenceIntegrateVerletStepKernel(std::string name, const Platform& platform) : IntegrateVerletStepKernel(name, platform),
        dynamics(0), shake(0), masses(0), shakeParameters(0), constraintIndices(0) {
129
    }
130
    ~ReferenceIntegrateVerletStepKernel();
131
    /**
132
     * Initialize the kernel.
133
     * 
134
135
     * @param system     the System this kernel will be applied to
     * @param integrator the VerletIntegrator this kernel will be used for
136
     */
137
    void initialize(const System& system, const VerletIntegrator& integrator);
138
139
140
    /**
     * Execute the kernel.
     * 
141
142
     * @param context    the context in which to execute this kernel
     * @param integrator the VerletIntegrator this kernel is being used for
143
     */
144
    void execute(OpenMMContextImpl& context, const VerletIntegrator& integrator);
145
146
147
148
149
150
151
152
private:
    ReferenceVerletDynamics* dynamics;
    ReferenceShakeAlgorithm* shake;
    RealOpenMM* masses;
    RealOpenMM** shakeParameters;
    int** constraintIndices;
    int numConstraints;
    double prevStepSize;
153
154
155
156
157
158
159
};

/**
 * This kernel is invoked by LangevinIntegrator to take one time step.
 */
class ReferenceIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel {
public:
160
161
    ReferenceIntegrateLangevinStepKernel(std::string name, const Platform& platform) : IntegrateLangevinStepKernel(name, platform),
        dynamics(0), shake(0), masses(0), shakeParameters(0), constraintIndices(0) {
162
    }
163
    ~ReferenceIntegrateLangevinStepKernel();
164
    /**
165
     * Initialize the kernel, setting up the atomic masses.
166
     * 
167
168
     * @param system     the System this kernel will be applied to
     * @param integrator the LangevinIntegrator this kernel will be used for
169
     */
170
    void initialize(const System& system, const LangevinIntegrator& integrator);
171
172
173
    /**
     * Execute the kernel.
     * 
174
175
     * @param context    the context in which to execute this kernel
     * @param integrator the LangevinIntegrator this kernel is being used for
176
     */
177
    void execute(OpenMMContextImpl& context, const LangevinIntegrator& integrator);
178
179
180
181
182
183
184
185
private:
    ReferenceStochasticDynamics* dynamics;
    ReferenceShakeAlgorithm* shake;
    RealOpenMM* masses;
    RealOpenMM** shakeParameters;
    int** constraintIndices;
    int numConstraints;
    double prevTemp, prevFriction, prevStepSize;
186
187
188
189
190
191
192
};

/**
 * This kernel is invoked by BrownianIntegrator to take one time step.
 */
class ReferenceIntegrateBrownianStepKernel : public IntegrateBrownianStepKernel {
public:
193
194
    ReferenceIntegrateBrownianStepKernel(std::string name, const Platform& platform) : IntegrateBrownianStepKernel(name, platform),
        dynamics(0), shake(0), masses(0), shakeParameters(0), constraintIndices(0) {
195
    }
196
    ~ReferenceIntegrateBrownianStepKernel();
197
    /**
198
     * Initialize the kernel.
199
     * 
200
201
     * @param system     the System this kernel will be applied to
     * @param integrator the BrownianIntegrator this kernel will be used for
202
     */
203
    void initialize(const System& system, const BrownianIntegrator& integrator);
204
205
206
    /**
     * Execute the kernel.
     * 
207
208
     * @param context    the context in which to execute this kernel
     * @param integrator the BrownianIntegrator this kernel is being used for
209
     */
210
    void execute(OpenMMContextImpl& context, const BrownianIntegrator& integrator);
211
212
213
214
215
216
217
218
private:
    ReferenceBrownianDynamics* dynamics;
    ReferenceShakeAlgorithm* shake;
    RealOpenMM* masses;
    RealOpenMM** shakeParameters;
    int** constraintIndices;
    int numConstraints;
    double prevTemp, prevFriction, prevStepSize;
219
220
221
222
223
224
225
};

/**
 * This kernel is invoked by AndersenThermostat at the start of each time step to adjust the atom velocities.
 */
class ReferenceApplyAndersenThermostatKernel : public ApplyAndersenThermostatKernel {
public:
226
    ReferenceApplyAndersenThermostatKernel(std::string name, const Platform& platform) : ApplyAndersenThermostatKernel(name, platform), thermostat(0) {
227
    }
228
    ~ReferenceApplyAndersenThermostatKernel();
229
    /**
230
     * Initialize the kernel.
231
     * 
232
233
     * @param system     the System this kernel will be applied to
     * @param thermostat the AndersenThermostat this kernel will be used for
234
     */
235
    void initialize(const System& system, const AndersenThermostat& thermostat);
236
237
238
    /**
     * Execute the kernel.
     * 
239
     * @param context    the context in which to execute this kernel
240
     */
241
    void execute(OpenMMContextImpl& context);
242
243
244
private:
    ReferenceAndersenThermostat* thermostat;
    RealOpenMM* masses;
245
246
247
248
249
250
251
};

/**
 * This kernel is invoked to calculate the kinetic energy of the system.
 */
class ReferenceCalcKineticEnergyKernel : public CalcKineticEnergyKernel {
public:
252
    ReferenceCalcKineticEnergyKernel(std::string name, const Platform& platform) : CalcKineticEnergyKernel(name, platform) {
253
254
    }
    /**
255
     * Initialize the kernel.
256
     * 
257
     * @param system     the System this kernel will be applied to
258
     */
259
    void initialize(const System& system);
260
261
262
    /**
     * Execute the kernel.
     * 
263
     * @param context    the context in which to execute this kernel
264
     */
265
    double execute(OpenMMContextImpl& context);
266
267
private:
    std::vector<double> masses;
268
269
};

270
271
272
273
274
275
276
277
278
279
/**
 * This kernel is invoked to remove center of mass motion from the system.
 */
class ReferenceRemoveCMMotionKernel : public RemoveCMMotionKernel {
public:
    ReferenceRemoveCMMotionKernel(std::string name, const Platform& platform) : RemoveCMMotionKernel(name, platform) {
    }
    /**
     * Initialize the kernel, setting up the atomic masses.
     * 
280
281
     * @param system     the System this kernel will be applied to
     * @param force      the CMMotionRemover this kernel will be used for
282
     */
283
    void initialize(const System& system, const CMMotionRemover& force);
284
285
286
    /**
     * Execute the kernel.
     * 
287
     * @param context    the context in which to execute this kernel
288
     */
289
    void execute(OpenMMContextImpl& context);
290
291
private:
    std::vector<double> masses;
292
    int frequency;
293
294
};

295
296
297
} // namespace OpenMM

#endif /*OPENMM_REFERENCEKERNELS_H_*/