"vscode:/vscode.git/clone" did not exist on "1d75fbfcaab73dc8e06f8af5accd8bc8b00ae376"
AmoebaReferenceKernels.h 21.8 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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 * -------------------------------------------------------------------------- *
 * 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:                                                                   *
 * 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
33
#include "openmm/AmoebaMultipoleForce.h"
#include "AmoebaReferenceMultipoleForce.h"
34
#include "SimTKReference/ReferenceNeighborList.h"
35
36
37
38
39
#include "SimTKUtilities/SimTKOpenMMRealType.h"

namespace OpenMM {

/**
40
 * This kernel is invoked by AmoebaBondForce to calculate the forces acting on the system and the energy of the system.
41
 */
42
class ReferenceCalcAmoebaBondForceKernel : public CalcAmoebaBondForceKernel {
43
public:
44
    ReferenceCalcAmoebaBondForceKernel(std::string name, 
45
46
                                               const Platform& platform,
                                               System& system);
47
    ~ReferenceCalcAmoebaBondForceKernel();
48
49
50
51
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
52
     * @param force      the AmoebaBondForce this kernel will be used for
53
     */
54
    void initialize(const System& system, const AmoebaBondForce& force);
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    /**
     * 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 numBonds;
    std::vector<int>   particle1;
    std::vector<int>   particle2;
    std::vector<RealOpenMM> length;
    std::vector<RealOpenMM> kQuadratic;
70
71
    RealOpenMM globalBondCubic;
    RealOpenMM globalBondQuartic;
72
73
74
75
    System& system;
};

/**
76
 * This kernel is invoked by AmoebaAngleForce to calculate the forces acting on the system and the energy of the system.
77
 */
78
class ReferenceCalcAmoebaAngleForceKernel : public CalcAmoebaAngleForceKernel {
79
public:
80
81
    ReferenceCalcAmoebaAngleForceKernel(std::string name, const Platform& platform, System& system);
    ~ReferenceCalcAmoebaAngleForceKernel();
82
83
84
85
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
86
     * @param force      the AmoebaAngleForce this kernel will be used for
87
     */
88
    void initialize(const System& system, const AmoebaAngleForce& force);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    /**
     * 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 numAngles;
    std::vector<int>   particle1;
    std::vector<int>   particle2;
    std::vector<int>   particle3;
    std::vector<RealOpenMM> angle;
    std::vector<RealOpenMM> kQuadratic;
105
106
107
108
    RealOpenMM globalAngleCubic;
    RealOpenMM globalAngleQuartic;
    RealOpenMM globalAnglePentic;
    RealOpenMM globalAngleSextic;
109
110
111
    System& system;
};

112
/**
113
 * This kernel is invoked by AmoebaInPlaneAngleForce to calculate the forces acting on the system and the energy of the system.
114
 */
115
class ReferenceCalcAmoebaInPlaneAngleForceKernel : public CalcAmoebaInPlaneAngleForceKernel {
116
public:
117
118
    ReferenceCalcAmoebaInPlaneAngleForceKernel(std::string name, const Platform& platform, System& system);
    ~ReferenceCalcAmoebaInPlaneAngleForceKernel();
119
120
121
122
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
123
     * @param force      the AmoebaInPlaneAngleForce this kernel will be used for
124
     */
125
    void initialize(const System& system, const AmoebaInPlaneAngleForce& force);
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    /**
     * 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 numAngles;
    std::vector<int>   particle1;
    std::vector<int>   particle2;
    std::vector<int>   particle3;
    std::vector<int>   particle4;
    std::vector<RealOpenMM> angle;
    std::vector<RealOpenMM> kQuadratic;
143
144
145
146
    RealOpenMM globalInPlaneAngleCubic;
    RealOpenMM globalInPlaneAngleQuartic;
    RealOpenMM globalInPlaneAnglePentic;
    RealOpenMM globalInPlaneAngleSextic;
147
148
149
    System& system;
};

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
 * This kernel is invoked by AmoebaPiTorsionForce to calculate the forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaPiTorsionForceKernel : public CalcAmoebaPiTorsionForceKernel {
public:
    ReferenceCalcAmoebaPiTorsionForceKernel(std::string name, const Platform& platform, System& system);
    ~ReferenceCalcAmoebaPiTorsionForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the AmoebaPiTorsionForce this kernel will be used for
     */
    void initialize(const System& system, const AmoebaPiTorsionForce& 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 numPiTorsions;
    std::vector<int>   particle1;
    std::vector<int>   particle2;
    std::vector<int>   particle3;
    std::vector<int>   particle4;
    std::vector<int>   particle5;
    std::vector<int>   particle6;
    std::vector<RealOpenMM> kTorsion;
    System& system;
};

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
 * This kernel is invoked by AmoebaStretchBendForce to calculate the forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaStretchBendForceKernel : public CalcAmoebaStretchBendForceKernel {
public:
    ReferenceCalcAmoebaStretchBendForceKernel(std::string name, const Platform& platform, System& system);
    ~ReferenceCalcAmoebaStretchBendForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the AmoebaStretchBendForce this kernel will be used for
     */
    void initialize(const System& system, const AmoebaStretchBendForce& 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 numStretchBends;
    std::vector<int>   particle1;
    std::vector<int>   particle2;
    std::vector<int>   particle3;
    std::vector<RealOpenMM> lengthABParameters;
    std::vector<RealOpenMM> lengthCBParameters;
    std::vector<RealOpenMM> angleParameters;
    std::vector<RealOpenMM> kParameters;
    System& system;
};
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

/**
 * This kernel is invoked by AmoebaOutOfPlaneBendForce to calculate the forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaOutOfPlaneBendForceKernel : public CalcAmoebaOutOfPlaneBendForceKernel {
public:
    ReferenceCalcAmoebaOutOfPlaneBendForceKernel(std::string name, const Platform& platform, System& system);
    ~ReferenceCalcAmoebaOutOfPlaneBendForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
     * @param force      the AmoebaOutOfPlaneBendForce this kernel will be used for
     */
    void initialize(const System& system, const AmoebaOutOfPlaneBendForce& 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 numOutOfPlaneBends;
    std::vector<int>   particle1;
    std::vector<int>   particle2;
    std::vector<int>   particle3;
    std::vector<int>   particle4;
    std::vector<RealOpenMM> kParameters;
    RealOpenMM globalOutOfPlaneBendAngleCubic;
    RealOpenMM globalOutOfPlaneBendAngleQuartic;
    RealOpenMM globalOutOfPlaneBendAnglePentic;
    RealOpenMM globalOutOfPlaneBendAngleSextic;
    System& system;
};

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/**
 * 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:
    ReferenceCalcAmoebaTorsionTorsionForceKernel(std::string name, const Platform& platform, System& system);
    ~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;
    std::vector< std::vector< std::vector< std::vector<RealOpenMM> > > > torsionTorsionGrids;

    System& system;
};

296
297
298
299
300
301
302
303
304
305
306
307
308
309
/**
 * 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:
    ReferenceCalcAmoebaMultipoleForceKernel(std::string name, const Platform& platform, System& system);
    ~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);
310
311
312
313
314
315
316
317
    /**
     * Setup for AmoebaReferenceMultipoleForce instance. 
     *
     * @param context        the current context
     *
     * @return pointer to initialized instance of AmoebaReferenceMultipoleForce
     */
    AmoebaReferenceMultipoleForce* setupAmoebaReferenceMultipoleForce(ContextImpl& context );
318
319
320
321
322
323
324
325
326
    /**
     * 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);
327
    /** 
328
     * Calculate the electrostatic potential given vector of grid coordinates.
329
     *
330
331
     * @param context                      context
     * @param inputGrid                    input grid coordinates
332
333
334
335
     * @param outputElectrostaticPotential output potential 
     */
    void getElectrostaticPotential(ContextImpl& context, const std::vector< Vec3 >& inputGrid,
                                   std::vector< double >& outputElectrostaticPotential );
336
337

    /**
338
     * Get the system multipole moments.
339
     *
340
341
342
     * @param context                context 
     * @param outputMultipoleMonents vector of multipole moments:
                                     (charge,
343
344
345
346
347
                                      dipole_x, dipole_y, dipole_z,
                                      quadrupole_xx, quadrupole_xy, quadrupole_xz,
                                      quadrupole_yx, quadrupole_yy, quadrupole_yz,
                                      quadrupole_zx, quadrupole_zy, quadrupole_zz )
     */
348
    void getSystemMultipoleMoments(ContextImpl& context, std::vector< double >& outputMultipoleMoments);
349

350
private:
351

352
    int numMultipoles;
353
    AmoebaMultipoleForce::NonbondedMethod nonbondedMethod;
354
    AmoebaMultipoleForce::PolarizationType polarizationType;
355
356
357
358
359
360
361
    std::vector<RealOpenMM> charges;
    std::vector<RealOpenMM> dipoles;
    std::vector<RealOpenMM> quadrupoles;
    std::vector<RealOpenMM> tholes;
    std::vector<RealOpenMM> dampingFactors;
    std::vector<RealOpenMM> polarity;
    std::vector<int>   axisTypes;
362
363
364
    std::vector<int>   multipoleAtomZs;
    std::vector<int>   multipoleAtomXs;
    std::vector<int>   multipoleAtomYs;
365
366
367
368
369
    std::vector< std::vector< std::vector<int> > > multipoleAtomCovalentInfo;

    int mutualInducedMaxIterations;
    RealOpenMM mutualInducedTargetEpsilon;

370
371
372
373
374
    bool usePme;
    RealOpenMM alphaEwald;
    RealOpenMM cutoffDistance;
    std::vector<int> pmeGridDimension;

375
376
377
    System& system;
};

Mark Friedrichs's avatar
Mark Friedrichs committed
378
379
380
381
382
383
384
385
386
387
388
/**
 * This kernel is invoked to calculate the vdw forces acting on the system and the energy of the system.
 */
class ReferenceCalcAmoebaVdwForceKernel : public CalcAmoebaVdwForceKernel {
public:
    ReferenceCalcAmoebaVdwForceKernel(std::string name, const Platform& platform, System& system);
    ~ReferenceCalcAmoebaVdwForceKernel();
    /**
     * Initialize the kernel.
     * 
     * @param system     the System this kernel will be applied to
389
     * @param force      the AmoebaVdwForce this kernel will be used for
Mark Friedrichs's avatar
Mark Friedrichs committed
390
391
392
393
394
395
396
397
398
399
400
401
402
     */
    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);
private:
    int numParticles;
403
    int useCutoff;
404
405
    int usePBC;
    double cutoff;
406
    double dispersionCoefficient;
Mark Friedrichs's avatar
Mark Friedrichs committed
407
    std::vector<int> indexIVs;
408
    std::vector< std::set<int> > allExclusions;
Mark Friedrichs's avatar
Mark Friedrichs committed
409
410
411
412
413
414
    std::vector<RealOpenMM> sigmas;
    std::vector<RealOpenMM> epsilons;
    std::vector<RealOpenMM> reductions;
    std::string sigmaCombiningRule;
    std::string epsilonCombiningRule;
    System& system;
415
    NeighborList* neighborList;
Mark Friedrichs's avatar
Mark Friedrichs committed
416
417
};

Mark Friedrichs's avatar
Mark Friedrichs committed
418
419
420
421
422
423
424
425
426
427
428
429
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
/**
 * 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:
    ReferenceCalcAmoebaWcaDispersionForceKernel(std::string name, const Platform& platform, System& system);
    ~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);
private:

    int numParticles;
    std::vector<RealOpenMM> radii;
    std::vector<RealOpenMM> epsilons;
    RealOpenMM epso; 
    RealOpenMM epsh; 
    RealOpenMM rmino; 
    RealOpenMM rminh; 
    RealOpenMM awater; 
    RealOpenMM shctd; 
    RealOpenMM dispoff;
    RealOpenMM slevy;
    RealOpenMM totalMaximumDispersionEnergy;
    System& system;
};
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
/**
 * 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:
    ReferenceCalcAmoebaGeneralizedKirkwoodForceKernel(std::string name, const Platform& platform, System& system);
    ~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);
 
    /**
483
     *  Get the 'include cavity term' flag.
484
485
486
487
488
489
     *
     *  @return includeCavityTerm
     */
    int getIncludeCavityTerm( void ) const;

    /**
490
     *  Get the number of particles.
491
492
493
494
495
496
     *
     *  @return number of particles
     */
    int getNumParticles( void ) const;

    /**
497
     *  Get Direct Polarization flag.
498
499
500
501
502
503
504
     *
     *  @return directPolarization
     *
     */
    int getDirectPolarization( void ) const;

    /**
505
     *  Get the solute dielectric.
506
507
508
509
510
511
512
     *
     *  @return soluteDielectric
     *
     */
    RealOpenMM getSoluteDielectric( void ) const;

    /**
513
     *  Get the solvent dielectric.
514
515
516
517
518
519
520
     *
     *  @return solventDielectric
     *
     */
    RealOpenMM getSolventDielectric( void ) const;

    /**
521
     *  Get the dielectric offset.
522
523
524
525
526
527
528
     *
     *  @return dielectricOffset
     *
     */
    RealOpenMM getDielectricOffset( void ) const;

    /**
529
     *  Get the probe radius.
530
531
532
533
534
535
536
     *
     *  @return probeRadius
     *
     */
    RealOpenMM getProbeRadius( void ) const;

    /**
537
     *  Get the surface area factor.
538
539
540
541
542
543
544
     *
     *  @return surfaceAreaFactor
     *
     */
    RealOpenMM getSurfaceAreaFactor( void ) const;

    /**
545
     *  Get the vector of particle radii.
546
547
548
549
550
551
552
     *
     *  @param atomicRadii vector of atomic radii
     *
     */
    void getAtomicRadii( std::vector<RealOpenMM>& atomicRadii ) const;

    /**
553
     *  Get the vector of scale factors.
554
555
556
557
558
559
560
     *
     *  @param scaleFactors vector of scale factors
     *
     */
    void getScaleFactors( std::vector<RealOpenMM>& scaleFactors ) const;

    /**
561
     *  Get the vector of charges.
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
     *
     *  @param charges vector of charges
     *
     */
    void getCharges( std::vector<RealOpenMM>& charges ) const;

private:

    int numParticles;
    std::vector<RealOpenMM> atomicRadii;
    std::vector<RealOpenMM> scaleFactors;
    std::vector<RealOpenMM> charges;
    RealOpenMM soluteDielectric;
    RealOpenMM solventDielectric;
    RealOpenMM dielectricOffset;
    RealOpenMM probeRadius;
    RealOpenMM surfaceAreaFactor;
    int includeCavityTerm;
    int directPolarization;
    System& system;
};

584
585
586
} // namespace OpenMM

#endif /*AMOEBA_OPENMM_REFERENCE_KERNELS_H*/