kernels.h 10.5 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
#ifndef OPENMM_KERNELS_H_
#define OPENMM_KERNELS_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.                                     *
 * -------------------------------------------------------------------------- */

35
36
37
38
#include "AndersenThermostat.h"
#include "BrownianIntegrator.h"
#include "CMMotionRemover.h"
#include "GBSAOBCForceField.h"
39
#include "KernelImpl.h"
40
41
#include "LangevinIntegrator.h"
#include "StandardMMForceField.h"
42
#include "Stream.h"
43
44
#include "System.h"
#include "VerletIntegrator.h"
45
46
47
48
49
50
51
#include <set>
#include <string>
#include <vector>

namespace OpenMM {

/**
52
 * This kernel is invoked by StandardMMForceField to calculate the forces acting on the system and the energy of the system.
53
 */
54
class CalcStandardMMForceFieldKernel : public KernelImpl {
55
public:
56
57
58
59
60
    enum NonbondedMethod {
        NoCutoff = 0,
        CutoffNonPeriodic = 1,
        CutoffPeriodic = 2
    };
61
    static std::string Name() {
62
        return "CalcStandardMMForceField";
63
    }
64
    CalcStandardMMForceFieldKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
65
66
    }
    /**
67
     * Initialize the kernel.
68
     * 
69
70
71
72
73
     * @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.
74
     */
75
    virtual void initialize(const System& system, const StandardMMForceField& force, const std::vector<std::set<int> >& exclusions) = 0;
76
    /**
77
     * Execute the kernel to calculate the forces.
78
     * 
79
     * @param context    the context in which to execute this kernel
80
     */
81
    virtual void executeForces(OpenMMContextImpl& context) = 0;
82
    /**
83
     * Execute the kernel to calculate the energy.
84
     * 
85
     * @param context    the context in which to execute this kernel
86
87
     * @return the potential energy due to the StandardMMForceField
     */
88
    virtual double executeEnergy(OpenMMContextImpl& context) = 0;
89
90
91
};

/**
92
 * This kernel is invoked by GBSAOBCForceField to calculate the forces acting on the system and the energy of the system.
93
 */
94
class CalcGBSAOBCForceFieldKernel : public KernelImpl {
95
96
97
98
public:
    static std::string Name() {
        return "CalcGBSAOBCForces";
    }
99
    CalcGBSAOBCForceFieldKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
100
101
    }
    /**
102
     * Initialize the kernel.
103
     * 
104
105
     * @param system     the System this kernel will be applied to
     * @param force      the GBSAOBCForceField this kernel will be used for
106
     */
107
    virtual void initialize(const System& system, const GBSAOBCForceField& force) = 0;
108
    /**
109
     * Execute the kernel to calculate the forces.
110
     * 
111
     * @param context    the context in which to execute this kernel
112
     */
113
    virtual void executeForces(OpenMMContextImpl& context) = 0;
114
    /**
115
     * Execute the kernel to calculate the energy.
116
     * 
117
     * @param context    the context in which to execute this kernel
118
119
     * @return the potential energy due to the GBSAOBCForceField
     */
120
    virtual double executeEnergy(OpenMMContextImpl& context) = 0;
121
122
123
124
125
126
127
128
129
130
};

/**
 * This kernel is invoked by VerletIntegrator to take one time step.
 */
class IntegrateVerletStepKernel : public KernelImpl {
public:
    static std::string Name() {
        return "IntegrateVerletStep";
    }
131
    IntegrateVerletStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
132
133
    }
    /**
134
     * Initialize the kernel.
135
     * 
136
137
     * @param system     the System this kernel will be applied to
     * @param integrator the VerletIntegrator this kernel will be used for
138
     */
139
    virtual void initialize(const System& system, const VerletIntegrator& integrator) = 0;
140
141
142
    /**
     * Execute the kernel.
     * 
143
144
     * @param context    the context in which to execute this kernel
     * @param integrator the VerletIntegrator this kernel is being used for
145
     */
146
    virtual void execute(OpenMMContextImpl& context, const VerletIntegrator& integrator) = 0;
147
148
149
150
151
152
153
154
155
156
};

/**
 * This kernel is invoked by LangevinIntegrator to take one time step.
 */
class IntegrateLangevinStepKernel : public KernelImpl {
public:
    static std::string Name() {
        return "IntegrateLangevinStep";
    }
157
    IntegrateLangevinStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
158
159
    }
    /**
160
     * Initialize the kernel.
161
     * 
162
163
     * @param system     the System this kernel will be applied to
     * @param integrator the LangevinIntegrator this kernel will be used for
164
     */
165
    virtual void initialize(const System& system, const LangevinIntegrator& integrator) = 0;
166
167
168
    /**
     * Execute the kernel.
     * 
169
170
     * @param context    the context in which to execute this kernel
     * @param integrator the LangevinIntegrator this kernel is being used for
171
     */
172
    virtual void execute(OpenMMContextImpl& context, const LangevinIntegrator& integrator) = 0;
173
174
175
176
177
178
179
180
181
182
};

/**
 * This kernel is invoked by BrownianIntegrator to take one time step.
 */
class IntegrateBrownianStepKernel : public KernelImpl {
public:
    static std::string Name() {
        return "IntegrateBrownianStep";
    }
183
    IntegrateBrownianStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
184
185
    }
    /**
186
     * Initialize the kernel.
187
     * 
188
189
     * @param system     the System this kernel will be applied to
     * @param integrator the BrownianIntegrator this kernel will be used for
190
     */
191
    virtual void initialize(const System& system, const BrownianIntegrator& integrator) = 0;
192
193
194
    /**
     * Execute the kernel.
     * 
195
196
     * @param context    the context in which to execute this kernel
     * @param integrator the BrownianIntegrator this kernel is being used for
197
     */
198
    virtual void execute(OpenMMContextImpl& context, const BrownianIntegrator& integrator) = 0;
199
200
201
202
203
204
205
206
207
208
};

/**
 * This kernel is invoked by AndersenThermostat at the start of each time step to adjust the atom velocities.
 */
class ApplyAndersenThermostatKernel : public KernelImpl {
public:
    static std::string Name() {
        return "ApplyAndersenThermostat";
    }
209
    ApplyAndersenThermostatKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
210
211
    }
    /**
212
     * Initialize the kernel.
213
     * 
214
215
     * @param system     the System this kernel will be applied to
     * @param thermostat the AndersenThermostat this kernel will be used for
216
     */
217
    virtual void initialize(const System& system, const AndersenThermostat& thermostat) = 0;
218
219
220
    /**
     * Execute the kernel.
     * 
221
     * @param context    the context in which to execute this kernel
222
     */
223
    virtual void execute(OpenMMContextImpl& context) = 0;
224
225
226
227
228
229
230
231
232
233
};

/**
 * This kernel is invoked to calculate the kinetic energy of the system.
 */
class CalcKineticEnergyKernel : public KernelImpl {
public:
    static std::string Name() {
        return "CalcKineticEnergy";
    }
234
    CalcKineticEnergyKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
235
236
    }
    /**
237
     * Initialize the kernel.
238
     * 
239
     * @param system     the System this kernel will be applied to
240
     */
241
    virtual void initialize(const System& system) = 0;
242
243
244
    /**
     * Execute the kernel.
     * 
245
     * @param context    the context in which to execute this kernel
246
     */
247
    virtual double execute(OpenMMContextImpl& context) = 0;
248
249
};

250
251
252
253
254
255
256
257
258
259
260
/**
 * This kernel is invoked to remove center of mass motion from the system.
 */
class RemoveCMMotionKernel : public KernelImpl {
public:
    static std::string Name() {
        return "RemoveCMMotion";
    }
    RemoveCMMotionKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
    }
    /**
261
     * Initialize the kernel.
262
     * 
263
264
     * @param system     the System this kernel will be applied to
     * @param force      the CMMotionRemover this kernel will be used for
265
     */
266
    virtual void initialize(const System& system, const CMMotionRemover& force) = 0;
267
268
269
    /**
     * Execute the kernel.
     * 
270
     * @param context    the context in which to execute this kernel
271
     */
272
    virtual void execute(OpenMMContextImpl& context) = 0;
273
274
};

275
276
277
} // namespace OpenMM

#endif /*OPENMM_KERNELS_H_*/