ReferenceCustomGBIxn.h 16.1 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

/* Portions copyright (c) 2009 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 __ReferenceCustomGBIxn_H__
#define __ReferenceCustomGBIxn_H__

#include "ReferenceNeighborList.h"
#include "lepton/ExpressionProgram.h"
#include "openmm/CustomGBForce.h"
#include <map>
#include <set>
#include <vector>

35
namespace OpenMM {
36
37
38
39
40
41
42
43

class ReferenceCustomGBIxn {

   private:

      bool cutoff;
      bool periodic;
      const OpenMM::NeighborList* neighborList;
44
      OpenMM::RealVec periodicBoxVectors[3];
45
46
      RealOpenMM cutoffDistance;
      std::vector<Lepton::ExpressionProgram> valueExpressions;
47
      std::vector<std::vector<Lepton::ExpressionProgram> > valueDerivExpressions;
48
      std::vector<std::vector<Lepton::ExpressionProgram> > valueGradientExpressions;
49
50
51
52
      std::vector<std::string> valueNames;
      std::vector<OpenMM::CustomGBForce::ComputationType> valueTypes;
      std::vector<Lepton::ExpressionProgram> energyExpressions;
      std::vector<std::vector<Lepton::ExpressionProgram> > energyDerivExpressions;
53
      std::vector<std::vector<Lepton::ExpressionProgram> > energyGradientExpressions;
54
55
56
57
58
59
60
      std::vector<std::string> paramNames;
      std::vector<OpenMM::CustomGBForce::ComputationType> energyTypes;
      std::vector<std::string> particleParamNames;
      std::vector<std::string> particleValueNames;

      /**---------------------------------------------------------------------------------------

61
         Calculate a computed value of type SingleParticle
62

63
64
         @param index            the index of the value to compute
         @param numAtoms         number of atoms
65
         @param atomCoordinates  atom coordinates
66
67
68
         @param values           the vector to store computed values into
         @param globalParameters the values of global parameters
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
69
70
71

         --------------------------------------------------------------------------------------- */

72
      void calculateSingleParticleValue(int index, int numAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<std::vector<RealOpenMM> >& values,
73
74
                                        const std::map<std::string, double>& globalParameters, RealOpenMM** atomParameters) const;

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
      /**---------------------------------------------------------------------------------------

         Calculate a computed value that is based on particle pairs

         @param index            the index of the value to compute
         @param numAtoms         number of atoms
         @param atomCoordinates  atom coordinates
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
         @param values           the vector to store computed values into
         @param globalParameters the values of global parameters
         @param exclusions       exclusions[i] is the set of excluded indices for atom i
         @param useExclusions    specifies whether to use exclusions

         --------------------------------------------------------------------------------------- */

90
      void calculateParticlePairValue(int index, int numAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters,
91
                                      std::vector<std::vector<RealOpenMM> >& values,
92
93
94
                                      const std::map<std::string, double>& globalParameters,
                                      const std::vector<std::set<int> >& exclusions, bool useExclusions) const;

95
96
97
98
99
100
101
102
103
104
105
106
107
108
      /**---------------------------------------------------------------------------------------

         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
         @param atomCoordinates  atom coordinates
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
         @param globalParameters the values of global parameters
         @param values           the vector to store computed values into

         --------------------------------------------------------------------------------------- */

109
      void calculateOnePairValue(int index, int atom1, int atom2, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters,
110
                                 const std::map<std::string, double>& globalParameters,
111
112
113
114
115
116
117
118
                                 std::vector<std::vector<RealOpenMM> >& values) const;

      /**---------------------------------------------------------------------------------------

         Calculate an energy term of type SingleParticle

         @param index            the index of the value to compute
         @param numAtoms         number of atoms
119
         @param atomCoordinates  atom coordinates
120
121
122
         @param values           the vector containing computed values
         @param globalParameters the values of global parameters
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
123
         @param forces           forces on atoms are added to this
124
125
         @param totalEnergy      the energy contribution is added to this
         @param dEdV             the derivative of energy with respect to computed values is stored in this
126

127
128
         --------------------------------------------------------------------------------------- */

129
130
      void calculateSingleParticleEnergyTerm(int index, int numAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, const std::vector<std::vector<RealOpenMM> >& values,
                                        const std::map<std::string, double>& globalParameters, RealOpenMM** atomParameters, std::vector<OpenMM::RealVec>& forces,
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
                                        RealOpenMM* totalEnergy, std::vector<std::vector<RealOpenMM> >& dEdV) const;

      /**---------------------------------------------------------------------------------------

         Calculate an energy term that is based on particle pairs

         @param index            the index of the term to compute
         @param numAtoms         number of atoms
         @param atomCoordinates  atom coordinates
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
         @param values           the vector containing computed values
         @param globalParameters the values of global parameters
         @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

         --------------------------------------------------------------------------------------- */
150

151
      void calculateParticlePairEnergyTerm(int index, int numAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters,
152
                                      const std::vector<std::vector<RealOpenMM> >& values,
153
154
                                      const std::map<std::string, double>& globalParameters,
                                      const std::vector<std::set<int> >& exclusions, bool useExclusions,
155
                                      std::vector<OpenMM::RealVec>& forces, RealOpenMM* totalEnergy, std::vector<std::vector<RealOpenMM> >& dEdV) const;
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

      /**---------------------------------------------------------------------------------------

         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
         @param atomCoordinates  atom coordinates
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
         @param globalParameters the values of global parameters
         @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

         --------------------------------------------------------------------------------------- */
173

174
      void calculateOnePairEnergyTerm(int index, int atom1, int atom2, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters,
175
                                 const std::map<std::string, double>& globalParameters,
176
                                 const std::vector<std::vector<RealOpenMM> >& values,
177
                                 std::vector<OpenMM::RealVec>& forces, RealOpenMM* totalEnergy, std::vector<std::vector<RealOpenMM> >& dEdV) const;
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

      /**---------------------------------------------------------------------------------------

         Apply the chain rule to compute forces on atoms

         @param numAtoms         number of atoms
         @param atomCoordinates  atom coordinates
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
         @param values           the vector containing computed values
         @param globalParameters the values of global parameters
         @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

         --------------------------------------------------------------------------------------- */

194
      void calculateChainRuleForces(int numAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters,
195
196
197
                                      const std::vector<std::vector<RealOpenMM> >& values,
                                      const std::map<std::string, double>& globalParameters,
                                      const std::vector<std::set<int> >& exclusions,
198
                                      std::vector<OpenMM::RealVec>& forces, std::vector<std::vector<RealOpenMM> >& dEdV) const;
199
200
201
202
203
204
205
206
207
208
209
210
211

      /**---------------------------------------------------------------------------------------

         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
         @param atomCoordinates  atom coordinates
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
         @param globalParameters the values of global parameters
         @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
212
         @param isExcluded       specifies whether this is an excluded pair
213
214
215

         --------------------------------------------------------------------------------------- */

216
      void calculateOnePairChainRule(int atom1, int atom2, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters,
217
218
                                 const std::map<std::string, double>& globalParameters,
                                 const std::vector<std::vector<RealOpenMM> >& values,
219
                                 std::vector<OpenMM::RealVec>& forces, std::vector<std::vector<RealOpenMM> >& dEdV,
220
                                 bool isExcluded) const;
221
222
223
224
225
226
227
228
229
230

   public:

      /**---------------------------------------------------------------------------------------

         Constructor

         --------------------------------------------------------------------------------------- */

       ReferenceCustomGBIxn(const std::vector<Lepton::ExpressionProgram>& valueExpressions,
231
                            const std::vector<std::vector<Lepton::ExpressionProgram> > valueDerivExpressions,
232
                            const std::vector<std::vector<Lepton::ExpressionProgram> > valueGradientExpressions,
233
234
235
236
                            const std::vector<std::string>& valueNames,
                            const std::vector<OpenMM::CustomGBForce::ComputationType>& valueTypes,
                            const std::vector<Lepton::ExpressionProgram>& energyExpressions,
                            const std::vector<std::vector<Lepton::ExpressionProgram> > energyDerivExpressions,
237
                            const std::vector<std::vector<Lepton::ExpressionProgram> > energyGradientExpressions,
238
239
240
241
242
243
244
245
246
                            const std::vector<OpenMM::CustomGBForce::ComputationType>& energyTypes,
                            const std::vector<std::string>& parameterNames);

      /**---------------------------------------------------------------------------------------

         Destructor

         --------------------------------------------------------------------------------------- */

247
       ~ReferenceCustomGBIxn();
248
249
250
251
252
253
254
255
256
257

      /**---------------------------------------------------------------------------------------

         Set the force to use a cutoff.

         @param distance            the cutoff distance
         @param neighbors           the neighbor list to use

         --------------------------------------------------------------------------------------- */

258
      void setUseCutoff(RealOpenMM distance, const OpenMM::NeighborList& neighbors);
259
260
261
262
263
264
265

      /**---------------------------------------------------------------------------------------

         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.

266
         @param vectors    the vectors defining the periodic box
267
268
269

         --------------------------------------------------------------------------------------- */

270
      void setPeriodic(OpenMM::RealVec* vectors);
271
272
273

      /**---------------------------------------------------------------------------------------

274
         Calculate custom GB ixn
275
276
277

         @param numberOfAtoms    number of atoms
         @param atomCoordinates  atom coordinates
278
279
         @param atomParameters   atomParameters[atomIndex][paramterIndex]
         @param exclusions       exclusions[i] is the set of excluded indices for atom i
280
281
282
283
284
285
         @param globalParameters the values of global parameters
         @param forces           force array (forces added)
         @param totalEnergy      total energy

         --------------------------------------------------------------------------------------- */

286
287
      void calculateIxn(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, RealOpenMM** atomParameters, const std::vector<std::set<int> >& exclusions,
                       std::map<std::string, double>& globalParameters, std::vector<OpenMM::RealVec>& forces, RealOpenMM* totalEnergy) const;
288
289
290
291
292

// ---------------------------------------------------------------------------------------

};

293
294
} // namespace OpenMM

295
#endif // __ReferenceCustomGBIxn_H__