"platforms/cuda/vscode:/vscode.git/clone" did not exist on "b9c09b791915317a9cf0452f1405d4b530de9413"
CpuCustomGBForce.h 12.7 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

/* Portions copyright (c) 2009-2014 Stanford University and Simbios.
 * Contributors: Peter Eastman
 *
 * 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.
 */

#ifndef OPENMM_CPU_CUSTOM_GB_FORCE_H__
#define OPENMM_CPU_CUSTOM_GB_FORCE_H__

#include "CompiledExpressionSet.h"
29
#include "CpuNeighborList.h"
30
31
#include "lepton/CompiledExpression.h"
#include "openmm/CustomGBForce.h"
32
#include "openmm/internal/vectorize.h"
33
34
35
36
#include <map>
#include <set>
#include <vector>

37
38
namespace OpenMM {

39
40
41
42
class CpuCustomGBForce {
private:
    bool cutoff;
    bool periodic;
43
    const CpuNeighborList* neighborList;
44
45
    float periodicBoxSize[3];
    float cutoffDistance;
46
    CompiledExpressionSet expressionSet;
47
48
49
50
51
    std::vector<Lepton::CompiledExpression> valueExpressions;
    std::vector<std::vector<Lepton::CompiledExpression> > valueDerivExpressions;
    std::vector<std::vector<Lepton::CompiledExpression> > valueGradientExpressions;
    std::vector<std::string> valueNames;
    std::vector<int> valueIndex;
52
    std::vector<CustomGBForce::ComputationType> valueTypes;
53
54
55
56
57
    std::vector<Lepton::CompiledExpression> energyExpressions;
    std::vector<std::vector<Lepton::CompiledExpression> > energyDerivExpressions;
    std::vector<std::vector<Lepton::CompiledExpression> > energyGradientExpressions;
    std::vector<std::string> paramNames;
    std::vector<int> paramIndex;
58
    std::vector<CustomGBForce::ComputationType> energyTypes;
59
60
61
    std::vector<int> particleParamIndex;
    std::vector<int> particleValueIndex;
    int xindex, yindex, zindex, rindex;
62
    // Workspace vectors
63
64
    std::vector<std::vector<float> > values, dEdV;
    std::vector<float> dVdR1, dVdR2, dVdX, dVdY, dVdZ;
65
66
67
68
69
70

    /**
     * Calculate a computed value of type SingleParticle
     * 
     * @param index            the index of the value to compute
     * @param numAtoms         number of atoms
71
     * @param posq             atom coordinates
72
73
74
75
     * @param values           the vector to store computed values into
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     */

76
    void calculateSingleParticleValue(int index, int numAtoms, float* posq, std::vector<std::vector<float> >& values,
77
                                      RealOpenMM** atomParameters);
78
79
80
81
82
83

    /**
     * Calculate a computed value that is based on particle pairs
     * 
     * @param index            the index of the value to compute
     * @param numAtoms         number of atoms
84
     * @param posq             atom coordinates
85
86
87
88
89
90
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param values           the vector to store computed values into
     * @param exclusions       exclusions[i] is the set of excluded indices for atom i
     * @param useExclusions    specifies whether to use exclusions
     */

91
92
93
    void calculateParticlePairValue(int index, int numAtoms, float* posq, RealOpenMM** atomParameters,
                                    std::vector<std::vector<float> >& values,
                                    const std::vector<std::set<int> >& exclusions, bool useExclusions, const fvec4& boxSize, const fvec4& invBoxSize);
94
95
96
97
98
99
100

    /**
     * Evaluate a single atom pair as part of calculating a computed value
     * 
     * @param index            the index of the value to compute
     * @param atom1            the index of the first atom in the pair
     * @param atom2            the index of the second atom in the pair
101
     * @param posq             atom coordinates
102
103
104
105
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param values           the vector to store computed values into
     */

106
107
    void calculateOnePairValue(int index, int atom1, int atom2, float* posq, RealOpenMM** atomParameters,
                               std::vector<std::vector<float> >& values, const fvec4& boxSize, const fvec4& invBoxSize);
108
109
110
111
112
113

    /**
     * Calculate an energy term of type SingleParticle
     * 
     * @param index            the index of the value to compute
     * @param numAtoms         number of atoms
114
     * @param posq             atom coordinates
115
116
117
118
119
120
121
     * @param values           the vector containing computed values
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param forces           forces on atoms are added to this
     * @param totalEnergy      the energy contribution is added to this
     * @param dEdV             the derivative of energy with respect to computed values is stored in this
     */

122
123
124
    void calculateSingleParticleEnergyTerm(int index, int numAtoms, float* posq, const std::vector<std::vector<float> >& values,
                                      RealOpenMM** atomParameters, float* forces,
                                      double* totalEnergy, std::vector<std::vector<float> >& dEdV);
125
126
127
128
129
130

    /**
     * Calculate an energy term that is based on particle pairs
     * 
     * @param index            the index of the term to compute
     * @param numAtoms         number of atoms
131
     * @param posq             atom coordinates
132
133
134
135
136
137
138
139
140
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param values           the vector containing computed values
     * @param exclusions       exclusions[i] is the set of excluded indices for atom i
     * @param useExclusions    specifies whether to use exclusions
     * @param forces           forces on atoms are added to this
     * @param totalEnergy      the energy contribution is added to this
     * @param dEdV             the derivative of energy with respect to computed values is stored in this
     */

141
142
    void calculateParticlePairEnergyTerm(int index, int numAtoms, float* posq, RealOpenMM** atomParameters,
                                    const std::vector<std::vector<float> >& values,
143
                                    const std::vector<std::set<int> >& exclusions, bool useExclusions,
144
145
                                    float* forces, double* totalEnergy, std::vector<std::vector<float> >& dEdV,
                                    const fvec4& boxSize, const fvec4& invBoxSize);
146
147
148
149
150
151
152

    /**
     * Evaluate a single atom pair as part of calculating an energy term
     * 
     * @param index            the index of the term to compute
     * @param atom1            the index of the first atom in the pair
     * @param atom2            the index of the second atom in the pair
153
     * @param posq             atom coordinates
154
155
156
157
158
159
160
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param values           the vector containing computed values
     * @param forces           forces on atoms are added to this
     * @param totalEnergy      the energy contribution is added to this
     * @param dEdV             the derivative of energy with respect to computed values is stored in this
     */

161
162
163
164
    void calculateOnePairEnergyTerm(int index, int atom1, int atom2, float* posq, RealOpenMM** atomParameters,
                               const std::vector<std::vector<float> >& values,
                               float* forces, double* totalEnergy, std::vector<std::vector<float> >& dEdV,
                               const fvec4& boxSize, const fvec4& invBoxSize);
165
166
167
168
169

    /**
     * Apply the chain rule to compute forces on atoms
     * 
     * @param numAtoms         number of atoms
170
     * @param posq             atom coordinates
171
172
173
174
175
176
177
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param values           the vector containing computed values
     * @param exclusions       exclusions[i] is the set of excluded indices for atom i
     * @param forces           forces on atoms are added to this
     * @param dEdV             the derivative of energy with respect to computed values is stored in this
     */

178
179
    void calculateChainRuleForces(int numAtoms, float* posq, RealOpenMM** atomParameters,
                                    const std::vector<std::vector<float> >& values,
180
                                    const std::vector<std::set<int> >& exclusions,
181
182
                                    float* forces, std::vector<std::vector<float> >& dEdV,
                                    const fvec4& boxSize, const fvec4& invBoxSize);
183
184
185
186
187
188

    /**
     * Evaluate a single atom pair as part of applying the chain rule
     * 
     * @param atom1            the index of the first atom in the pair
     * @param atom2            the index of the second atom in the pair
189
     * @param posq             atom coordinates
190
191
192
193
194
195
196
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param values           the vector containing computed values
     * @param forces           forces on atoms are added to this
     * @param dEdV             the derivative of energy with respect to computed values is stored in this
     * @param isExcluded       specifies whether this is an excluded pair
     */

197
198
199
200
201
202
203
204
205
206
    void calculateOnePairChainRule(int atom1, int atom2, float* posq, RealOpenMM** atomParameters,
                               const std::vector<std::vector<float> >& values,
                               float* forces, std::vector<std::vector<float> >& dEdV,
                               bool isExcluded, const fvec4& boxSize, const fvec4& invBoxSize);

    /**
     * Compute the displacement and squared distance between two points, optionally using
     * periodic boundary conditions.
     */
    void getDeltaR(const fvec4& posI, const fvec4& posJ, fvec4& deltaR, float& r2, bool periodic, const fvec4& boxSize, const fvec4& invBoxSize) const;
207
208
209
210
211
212
213

public:

    /**
     * Construct a new CpuCustomGBForce.
     */

214
215
216
     CpuCustomGBForce(int numAtoms, const std::vector<Lepton::CompiledExpression>& valueExpressions,
                          const std::vector<std::vector<Lepton::CompiledExpression> >& valueDerivExpressions,
                          const std::vector<std::vector<Lepton::CompiledExpression> >& valueGradientExpressions,
217
                          const std::vector<std::string>& valueNames,
218
                          const std::vector<CustomGBForce::ComputationType>& valueTypes,
219
                          const std::vector<Lepton::CompiledExpression>& energyExpressions,
220
221
                          const std::vector<std::vector<Lepton::CompiledExpression> >& energyDerivExpressions,
                          const std::vector<std::vector<Lepton::CompiledExpression> >& energyGradientExpressions,
222
                          const std::vector<CustomGBForce::ComputationType>& energyTypes,
223
224
225
226
227
228
229
230
231
232
233
                          const std::vector<std::string>& parameterNames);

     ~CpuCustomGBForce();

    /**
     * Set the force to use a cutoff.
     * 
     * @param distance            the cutoff distance
     * @param neighbors           the neighbor list to use
     */

234
    void setUseCutoff(float distance, const CpuNeighborList& neighbors);
235
236
237
238
239
240
241
242
243

    /**
     * Set the force to use periodic boundary conditions.  This requires that a cutoff has
     * already been set, and the smallest side of the periodic box is at least twice the cutoff
     * distance.
     * 
     * @param boxSize             the X, Y, and Z widths of the periodic box
     */

244
    void setPeriodic(RealVec& boxSize);
245
246
247
248
249

    /**
     * Calculate custom GB ixn
     * 
     * @param numberOfAtoms    number of atoms
250
     * @param posq             atom coordinates
251
252
253
254
255
256
257
     * @param atomParameters   atomParameters[atomIndex][paramterIndex]
     * @param exclusions       exclusions[i] is the set of excluded indices for atom i
     * @param globalParameters the values of global parameters
     * @param forces           force array (forces added)
     * @param totalEnergy      total energy
     */

258
259
    void calculateIxn(int numberOfAtoms, float* posq, RealOpenMM** atomParameters, const std::vector<std::set<int> >& exclusions,
                     std::map<std::string, double>& globalParameters, float* forces, double* totalEnergy);
260
261
};

262
263
} // namespace OpenMM

264
#endif // OPENMM_CPU_CUSTOM_GB_FORCE_H__