AmoebaReferenceKernels.h 19.2 KB
Newer Older
1
2
3
4
#ifndef AMOEBA_OPENMM_REFERENCE_KERNELS_H_
#define AMOEBA_OPENMM_REFERENCE_KERNELS_H_

/* -------------------------------------------------------------------------- *
5
 *                              OpenMMAmoeba                                  *
6
7
8
9
10
11
 * -------------------------------------------------------------------------- *
 * 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.               *
 *                                                                            *
12
 * Portions copyright (c) 2008-2020 Stanford University and the Authors.      *
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 * Authors:                                                                   *
 * 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/>.      *
 * -------------------------------------------------------------------------- */

#include "openmm/System.h"
31
#include "openmm/amoebaKernels.h"
32
#include "openmm/AmoebaMultipoleForce.h"
peastman's avatar
peastman committed
33
#include "openmm/HippoNonbondedForce.h"
34
#include "AmoebaReferenceMultipoleForce.h"
peastman's avatar
peastman committed
35
#include "AmoebaReferenceHippoNonbondedForce.h"
36
#include "AmoebaReferenceVdwForce.h"
37
38
#include "ReferenceNeighborList.h"
#include "SimTKOpenMMRealType.h"
39
40
41

namespace OpenMM {

42
43
44
45
46
/**
 * This kernel is invoked by AmoebaTorsionTorsionForce to calculate the forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaTorsionTorsionForceKernel : public CalcAmoebaTorsionTorsionForceKernel {
public:
47
    ReferenceCalcAmoebaTorsionTorsionForceKernel(const std::string& name, const Platform& platform, const System& system);
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    ~ReferenceCalcAmoebaTorsionTorsionForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the AmoebaTorsionTorsionForce this kernel will be used for
     */
    void initialize(const System& system, const AmoebaTorsionTorsionForce& force);
    /**
     * Execute the kernel to calculate the forces and/or energy.
     *
     * @param context        the context in which to execute this kernel
     * @param includeForces  true if forces should be calculated
     * @param includeEnergy  true if the energy should be calculated
     * @return the potential energy due to the force
     */
    double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
private:
    int numTorsionTorsions;
    std::vector<int>   particle1;
    std::vector<int>   particle2;
    std::vector<int>   particle3;
    std::vector<int>   particle4;
    std::vector<int>   particle5;
    std::vector<int>   chiralCheckAtom;
    std::vector<int>   gridIndices;

    int numTorsionTorsionGrids;
peastman's avatar
peastman committed
76
    std::vector< std::vector< std::vector< std::vector<double> > > > torsionTorsionGrids;
77

78
    const System& system;
79
    bool usePeriodic;
80
81
};

82
83
84
85
86
/**
 * This kernel is invoked by AmoebaMultipoleForce to calculate the forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaMultipoleForceKernel : public CalcAmoebaMultipoleForceKernel {
public:
87
    ReferenceCalcAmoebaMultipoleForceKernel(const std::string& name, const Platform& platform, const System& system);
88
89
90
91
92
93
94
95
    ~ReferenceCalcAmoebaMultipoleForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the AmoebaMultipoleForce this kernel will be used for
     */
    void initialize(const System& system, const AmoebaMultipoleForce& force);
96
97
98
99
100
101
102
    /**
     * Setup for AmoebaReferenceMultipoleForce instance. 
     *
     * @param context        the current context
     *
     * @return pointer to initialized instance of AmoebaReferenceMultipoleForce
     */
103
    AmoebaReferenceMultipoleForce* setupAmoebaReferenceMultipoleForce(ContextImpl& context);
104
105
106
107
108
109
110
111
112
    /**
     * Execute the kernel to calculate the forces and/or energy.
     *
     * @param context        the context in which to execute this kernel
     * @param includeForces  true if forces should be calculated
     * @param includeEnergy  true if the energy should be calculated
     * @return the potential energy due to the force
     */
    double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
113
114
115
116
117
118
119
    /**
     * Get the induced dipole moments of all particles.
     * 
     * @param context    the Context for which to get the induced dipoles
     * @param dipoles    the induced dipole moment of particle i is stored into the i'th element
     */
    void getInducedDipoles(ContextImpl& context, std::vector<Vec3>& dipoles);
120
    /**
121
122
123
124
125
     * Get the fixed dipole moments of all particles in the global reference frame.
     * 
     * @param context    the Context for which to get the fixed dipoles
     * @param dipoles    the fixed dipole moment of particle i is stored into the i'th element
     */
126
    void getLabFramePermanentDipoles(ContextImpl& context, std::vector<Vec3>& dipoles);
127
128
129
130
131
132
133
    /**
     * Get the total dipole moments of all particles in the global reference frame.
     * 
     * @param context    the Context for which to get the fixed dipoles
     * @param dipoles    the fixed dipole moment of particle i is stored into the i'th element
     */
    void getTotalDipoles(ContextImpl& context, std::vector<Vec3>& dipoles);
134
    /** 
135
     * Calculate the electrostatic potential given vector of grid coordinates.
136
     *
137
138
     * @param context                      context
     * @param inputGrid                    input grid coordinates
139
140
141
     * @param outputElectrostaticPotential output potential 
     */
    void getElectrostaticPotential(ContextImpl& context, const std::vector< Vec3 >& inputGrid,
142
                                   std::vector< double >& outputElectrostaticPotential);
143
144

    /**
145
     * Get the system multipole moments.
146
     *
147
     * @param context                context 
148
     * @param outputMultipoleMoments vector of multipole moments:
149
                                     (charge,
150
151
152
                                      dipole_x, dipole_y, dipole_z,
                                      quadrupole_xx, quadrupole_xy, quadrupole_xz,
                                      quadrupole_yx, quadrupole_yy, quadrupole_yz,
153
                                      quadrupole_zx, quadrupole_zy, quadrupole_zz)
154
     */
Lee-Ping Wang's avatar
Lee-Ping Wang committed
155
    void getSystemMultipoleMoments(ContextImpl& context, std::vector< double >& outputMultipoleMoments);
156
157
158
159
160
161
162
    /**
     * Copy changed parameters over to a context.
     *
     * @param context    the context to copy parameters to
     * @param force      the AmoebaMultipoleForce to copy the parameters from
     */
    void copyParametersToContext(ContextImpl& context, const AmoebaMultipoleForce& force);
163
164
165
166
167
168
169
170
171
    /**
     * Get the parameters being used for PME.
     * 
     * @param alpha   the separation parameter
     * @param nx      the number of grid points along the X axis
     * @param ny      the number of grid points along the Y axis
     * @param nz      the number of grid points along the Z axis
     */
    void getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const;
172

173
private:
174

175
    int numMultipoles;
176
    AmoebaMultipoleForce::NonbondedMethod nonbondedMethod;
177
    AmoebaMultipoleForce::PolarizationType polarizationType;
peastman's avatar
peastman committed
178
179
180
181
182
183
    std::vector<double> charges;
    std::vector<double> dipoles;
    std::vector<double> quadrupoles;
    std::vector<double> tholes;
    std::vector<double> dampingFactors;
    std::vector<double> polarity;
184
    std::vector<int>   axisTypes;
185
186
187
    std::vector<int>   multipoleAtomZs;
    std::vector<int>   multipoleAtomXs;
    std::vector<int>   multipoleAtomYs;
188
189
190
    std::vector< std::vector< std::vector<int> > > multipoleAtomCovalentInfo;

    int mutualInducedMaxIterations;
peastman's avatar
peastman committed
191
    double mutualInducedTargetEpsilon;
192
    std::vector<double> extrapolationCoefficients;
193

194
    bool usePme;
peastman's avatar
peastman committed
195
196
    double alphaEwald;
    double cutoffDistance;
197
198
    std::vector<int> pmeGridDimension;

199
    const System& system;
200
201
};

Mark Friedrichs's avatar
Mark Friedrichs committed
202
203
204
205
206
/**
 * This kernel is invoked to calculate the vdw forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaVdwForceKernel : public CalcAmoebaVdwForceKernel {
public:
207
    ReferenceCalcAmoebaVdwForceKernel(const std::string& name, const Platform& platform, const System& system);
Mark Friedrichs's avatar
Mark Friedrichs committed
208
209
210
211
212
    ~ReferenceCalcAmoebaVdwForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
213
     * @param force      the AmoebaVdwForce this kernel will be used for
Mark Friedrichs's avatar
Mark Friedrichs committed
214
215
216
217
218
219
220
221
222
223
224
     */
    void initialize(const System& system, const AmoebaVdwForce& force);
    /**
     * Execute the kernel to calculate the forces and/or energy.
     *
     * @param context        the context in which to execute this kernel
     * @param includeForces  true if forces should be calculated
     * @param includeEnergy  true if the energy should be calculated
     * @return the potential energy due to the force
     */
    double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
225
226
227
228
229
230
231
    /**
     * Copy changed parameters over to a context.
     *
     * @param context    the context to copy parameters to
     * @param force      the AmoebaVdwForce to copy the parameters from
     */
    void copyParametersToContext(ContextImpl& context, const AmoebaVdwForce& force);
Mark Friedrichs's avatar
Mark Friedrichs committed
232
233
private:
    int numParticles;
234
    int useCutoff;
235
236
    int usePBC;
    double cutoff;
237
    double dispersionCoefficient;
238
    AmoebaReferenceVdwForce vdwForce;
239
    const System& system;
240
    NeighborList* neighborList;
Mark Friedrichs's avatar
Mark Friedrichs committed
241
242
};

Mark Friedrichs's avatar
Mark Friedrichs committed
243
244
245
246
247
/**
 * This kernel is invoked to calculate the WCA dispersion forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaWcaDispersionForceKernel : public CalcAmoebaWcaDispersionForceKernel {
public:
248
    ReferenceCalcAmoebaWcaDispersionForceKernel(const std::string& name, const Platform& platform, const System& system);
Mark Friedrichs's avatar
Mark Friedrichs committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
    ~ReferenceCalcAmoebaWcaDispersionForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the AmoebaMultipoleForce this kernel will be used for
     */
    void initialize(const System& system, const AmoebaWcaDispersionForce& force);
    /**
     * Execute the kernel to calculate the forces and/or energy.
     *
     * @param context        the context in which to execute this kernel
     * @param includeForces  true if forces should be calculated
     * @param includeEnergy  true if the energy should be calculated
     * @return the potential energy due to the force
     */
    double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
266
267
268
269
270
271
272
    /**
     * Copy changed parameters over to a context.
     *
     * @param context    the context to copy parameters to
     * @param force      the AmoebaWcaDispersionForce to copy the parameters from
     */
    void copyParametersToContext(ContextImpl& context, const AmoebaWcaDispersionForce& force);
Mark Friedrichs's avatar
Mark Friedrichs committed
273
274
275
private:

    int numParticles;
peastman's avatar
peastman committed
276
277
278
279
280
281
282
283
284
285
286
    std::vector<double> radii;
    std::vector<double> epsilons;
    double epso; 
    double epsh; 
    double rmino; 
    double rminh; 
    double awater; 
    double shctd; 
    double dispoff;
    double slevy;
    double totalMaximumDispersionEnergy;
287
    const System& system;
Mark Friedrichs's avatar
Mark Friedrichs committed
288
};
289

290
291
292
293
294
/**
 * This kernel is invoked to calculate the Gerneralized Kirkwood forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel : public CalcAmoebaGeneralizedKirkwoodForceKernel {
public:
295
    ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel(const std::string& name, const Platform& platform, const System& system);
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
    ~ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the AmoebaMultipoleForce this kernel will be used for
     */
    void initialize(const System& system, const AmoebaGeneralizedKirkwoodForce& force);
    /**
     * Execute the kernel to calculate the forces and/or energy.
     *
     * @param context        the context in which to execute this kernel
     * @param includeForces  true if forces should be calculated
     * @param includeEnergy  true if the energy should be calculated
     * @return the potential energy due to the force
     */
    double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
 
    /**
315
     *  Get the 'include cavity term' flag.
316
317
318
     *
     *  @return includeCavityTerm
     */
319
    int getIncludeCavityTerm() const;
320
321

    /**
322
     *  Get the number of particles.
323
324
325
     *
     *  @return number of particles
     */
326
    int getNumParticles() const;
327
328

    /**
329
     *  Get Direct Polarization flag.
330
331
332
333
     *
     *  @return directPolarization
     *
     */
334
    int getDirectPolarization() const;
335
336

    /**
337
     *  Get the solute dielectric.
338
339
340
341
     *
     *  @return soluteDielectric
     *
     */
peastman's avatar
peastman committed
342
    double getSoluteDielectric() const;
343
344

    /**
345
     *  Get the solvent dielectric.
346
347
348
349
     *
     *  @return solventDielectric
     *
     */
peastman's avatar
peastman committed
350
    double getSolventDielectric() const;
351
352

    /**
353
     *  Get the dielectric offset.
354
355
356
357
     *
     *  @return dielectricOffset
     *
     */
peastman's avatar
peastman committed
358
    double getDielectricOffset() const;
359
360

    /**
361
     *  Get the probe radius.
362
363
364
365
     *
     *  @return probeRadius
     *
     */
peastman's avatar
peastman committed
366
    double getProbeRadius() const;
367
368

    /**
369
     *  Get the surface area factor.
370
371
372
373
     *
     *  @return surfaceAreaFactor
     *
     */
peastman's avatar
peastman committed
374
    double getSurfaceAreaFactor() const;
375
376

    /**
377
     *  Get the vector of particle radii.
378
379
380
381
     *
     *  @param atomicRadii vector of atomic radii
     *
     */
peastman's avatar
peastman committed
382
    void getAtomicRadii(std::vector<double>& atomicRadii) const;
383
384

    /**
385
     *  Get the vector of scale factors.
386
387
388
389
     *
     *  @param scaleFactors vector of scale factors
     *
     */
peastman's avatar
peastman committed
390
    void getScaleFactors(std::vector<double>& scaleFactors) const;
391
392

    /**
393
     *  Get the vector of charges.
394
395
396
397
     *
     *  @param charges vector of charges
     *
     */
peastman's avatar
peastman committed
398
    void getCharges(std::vector<double>& charges) const;
399

400
401
402
403
404
405
406
407
    /**
     * Copy changed parameters over to a context.
     *
     * @param context    the context to copy parameters to
     * @param force      the AmoebaGeneralizedKirkwoodForce to copy the parameters from
     */
    void copyParametersToContext(ContextImpl& context, const AmoebaGeneralizedKirkwoodForce& force);

408
409
410
private:

    int numParticles;
peastman's avatar
peastman committed
411
412
413
414
415
416
417
418
    std::vector<double> atomicRadii;
    std::vector<double> scaleFactors;
    std::vector<double> charges;
    double soluteDielectric;
    double solventDielectric;
    double dielectricOffset;
    double probeRadius;
    double surfaceAreaFactor;
419
420
    int includeCavityTerm;
    int directPolarization;
421
    const System& system;
422
423
};

peastman's avatar
peastman committed
424
425
426
427
428
/**
 * This kernel is invoked by HippoNonbondedForce to calculate the forces acting on the system and the energy of the system.
 */
class ReferenceCalcHippoNonbondedForceKernel : public CalcHippoNonbondedForceKernel {
public:
429
    ReferenceCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, const System& system);
peastman's avatar
peastman committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
    ~ReferenceCalcHippoNonbondedForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the HippoNonbondedForce this kernel will be used for
     */
    void initialize(const System& system, const HippoNonbondedForce& force);
    /**
     * Setup for AmoebaReferenceHippoNonbondedForce instance. 
     *
     * @param context        the current context
     *
     * @return pointer to initialized instance of AmoebaReferenceHippoNonbondedForce
     */
    void setupAmoebaReferenceHippoNonbondedForce(ContextImpl& context);
    /**
     * Execute the kernel to calculate the forces and/or energy.
     *
     * @param context        the context in which to execute this kernel
     * @param includeForces  true if forces should be calculated
     * @param includeEnergy  true if the energy should be calculated
     * @return the potential energy due to the force
     */
    double execute(ContextImpl& context, bool includeForces, bool includeEnergy);
    /**
     * Get the induced dipole moments of all particles.
     * 
     * @param context    the Context for which to get the induced dipoles
     * @param dipoles    the induced dipole moment of particle i is stored into the i'th element
     */
    void getInducedDipoles(ContextImpl& context, std::vector<Vec3>& dipoles);
    /**
     * Get the fixed dipole moments of all particles in the global reference frame.
     * 
     * @param context    the Context for which to get the fixed dipoles
     * @param dipoles    the fixed dipole moment of particle i is stored into the i'th element
     */
    void getLabFramePermanentDipoles(ContextImpl& context, std::vector<Vec3>& dipoles);
    /**
     * Get the total dipole moments of all particles in the global reference frame.
     * 
     * @param context    the Context for which to get the fixed dipoles
     * @param dipoles    the fixed dipole moment of particle i is stored into the i'th element
     */
    void getTotalDipoles(ContextImpl& context, std::vector<Vec3>& dipoles);
    /**
     * Copy changed parameters over to a context.
     *
     * @param context    the context to copy parameters to
     * @param force      the HippoNonbondedForce to copy the parameters from
     */
    void copyParametersToContext(ContextImpl& context, const HippoNonbondedForce& force);
    /**
     * Get the parameters being used for PME.
     * 
     * @param alpha   the separation parameter
     * @param nx      the number of grid points along the X axis
     * @param ny      the number of grid points along the Y axis
     * @param nz      the number of grid points along the Z axis
     */
    void getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const;
    /**
     * Get the parameters being used for dispersion PME.
     * 
     * @param alpha   the separation parameter
     * @param nx      the number of grid points along the X axis
     * @param ny      the number of grid points along the Y axis
     * @param nz      the number of grid points along the Z axis
     */
    void getDPMEParameters(double& alpha, int& nx, int& ny, int& nz) const;

private:

    AmoebaReferenceHippoNonbondedForce* ixn;
    int numParticles;
};

508
509
510
} // namespace OpenMM

#endif /*AMOEBA_OPENMM_REFERENCE_KERNELS_H*/