BrookBonded.h 15.5 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
#ifndef OPENMM_BROOK_BONDED_H_
#define OPENMM_BROOK_BONDED_H_
Mark Friedrichs's avatar
Mark Friedrichs committed
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
35
36

/* -------------------------------------------------------------------------- *
 *                                   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, Mark Friedrichs                                    *
 * 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.                                     *
 * -------------------------------------------------------------------------- */

#include <vector>

Mark Friedrichs's avatar
Mark Friedrichs committed
37
38
#include "BrookFloatStreamInternal.h"
#include "BrookIntStreamInternal.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "BrookPlatform.h"
#include "BrookCommon.h"
#include "OpenMMContext.h"

namespace OpenMM {

/**
 * This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
 */
class BrookBonded : public BrookCommon {

   public:
  
Mark Friedrichs's avatar
Mark Friedrichs committed
52
53
54
55
56
57
      /** 
       *
       * BrookBonded constructor
       * 
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
58
59
      BrookBonded( );
  
Mark Friedrichs's avatar
Mark Friedrichs committed
60
61
62
63
64
65
66
      /** 
       *
       * BrookBonded desstructor
       * 
       */
      
      ~BrookBonded( );
Mark Friedrichs's avatar
Mark Friedrichs committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  
      /**
       * Initialize the kernel, setting up the values of all the force field parameters.
       * 
       * @param bondIndices               the two atoms connected by each bond term
       * @param bondParameters            the force parameters (length, k) for each bond term
       * @param angleIndices              the three atoms connected by each angle term
       * @param angleParameters           the force parameters (angle, k) for each angle term
       * @param periodicTorsionIndices    the four atoms connected by each periodic torsion term
       * @param periodicTorsionParameters the force parameters (k, phase, periodicity) for each periodic torsion term
       * @param rbTorsionIndices          the four atoms connected by each Ryckaert-Bellemans torsion term
       * @param rbTorsionParameters       the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
       * @param bonded14Indices           each element contains the indices of two atoms whose nonbonded interactions should be reduced since
       *                                  they form a bonded 1-4 pair
       * @param nonbondedParameters       the nonbonded force parameters (charge, sigma, epsilon) for each atom
       * @param lj14Scale                 the factor by which van der Waals interactions should be reduced for bonded 1-4 pairs
       * @param coulomb14Scale            the factor by which Coulomb interactions should be reduced for bonded 1-4 pairs
       * @param log                       log reference
       *
       * @return nonzero value if error
       *
       */

      int setup( int numberOfAtoms, 
                 const std::vector<std::vector<int> >& bondIndices,            const std::vector<std::vector<double> >& bondParameters,
                 const std::vector<std::vector<int> >& angleIndices,           const std::vector<std::vector<double> >& angleParameters,
                 const std::vector<std::vector<int> >& periodicTorsionIndices, const std::vector<std::vector<double> >& periodicTorsionParameters,
                 const std::vector<std::vector<int> >& rbTorsionIndices,       const std::vector<std::vector<double> >& rbTorsionParameters,
                 const std::vector<std::vector<int> >& bonded14Indices,        const std::vector<std::vector<double> >& nonbondedParameters,
Mark Friedrichs's avatar
Mark Friedrichs committed
96
                 double lj14Scale, double coulomb14Scale, const Platform& platform );
Mark Friedrichs's avatar
Mark Friedrichs committed
97

Mark Friedrichs's avatar
Mark Friedrichs committed
98
99
100
101
102
103
104
105
106
      /**
       * Get inverse map stream width
       * 
       * @return stream width
       *
       */

      int getInverseMapStreamWidth( void ) const;
      
Mark Friedrichs's avatar
Mark Friedrichs committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
      /**
       * Return number of parameter streams
       * 
       * @return number of parameter streams
       *
       */

      int getNumberOfParameterStreams( void ) const; 

      /**
       * Return number of force streams
       * 
       * @return number of force streams
       *
       */

      int getNumberOfForceStreams( void ) const; 

      /**
       * Return stream count for specifed index (i, j, k, l)
       * 
       * @return stream count for specifed index
       *
       * @throw throws OpenMMException if index out of range
       */

      int getInverseMapStreamCount( int index ) const; 

      /**
       * Return max stream count
       * 
       * @return max stream count
       */

      int getMaxInverseMapStreamCount( void ) const; 

Mark Friedrichs's avatar
Mark Friedrichs committed
143
144
145
146
147
148
149
150
151
152
153
      /**
       * Return max stream count for specified index
       * 
       * @param index index of force stream
       *
       * @return max stream count
       *
       */

      int getMaxInverseMapStreamCount( int index ) const; 

Mark Friedrichs's avatar
Mark Friedrichs committed
154
155
156
157
158
159
      /**
       * Return Brook stream handle
       * 
       * @return 
       */

Mark Friedrichs's avatar
Mark Friedrichs committed
160
      BrookFloatStreamInternal* getBrookAtomIndices( void ) const; 
Mark Friedrichs's avatar
Mark Friedrichs committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

      /**
       * Get LJ 14 scale factor
       *
       * @return  LJ 14 scaling (fudge) factor
       * 
       */

       BrookOpenMMFloat getLJ_14Scale( void ) const;

      /** 
       * Get Coulomb factor
       * 
       * @return Coulomb factor
       *
       */
      
      BrookOpenMMFloat getCoulombFactor( void ) const;

      /** 
       * Get bonded atom indices stream
       * 
       * @return  atom indices stream
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
187
      BrookFloatStreamInternal* getAtomIndicesStream( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
188
      
189
190
191
192
193
194
195
196
197
      /** 
       * Get bonded charge stream
       * 
       * @return  charge stream
       *
       */
      
      BrookFloatStreamInternal* getChargeStream( void ) const;
      
Mark Friedrichs's avatar
Mark Friedrichs committed
198
199
200
201
202
203
204
      /** 
       * Get array of bonded parameter streams
       * 
       * @return  array of bonded parameter streams
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
205
      BrookFloatStreamInternal** getBondedParameterStreams( void );
Mark Friedrichs's avatar
Mark Friedrichs committed
206
207
208
209
210
211
212
213
      
      /** 
       * Get array of force streams
       * 
       * @return  array
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
214
      BrookFloatStreamInternal** getBondedForceStreams( void );
Mark Friedrichs's avatar
Mark Friedrichs committed
215
216
217
218
219
220
221
222
223
224
      
      /** 
       * Get array of inverse map streams
       * 
       * @param index  array index 
       *
       * @return  array inverse map streams
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
225
      BrookFloatStreamInternal** getInverseStreamMapsStreams( int index );
Mark Friedrichs's avatar
Mark Friedrichs committed
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
257
258
259
260
261
262
263
264
265
266
267
268
      
      /** 
       * Return true if force[index] stream is set
       *
       * @param    index into force stream
       * @return   true if index is valid && force[index] stream is set; else false
       *
       */
      
      int isForceStreamSet( int index ) const;
       
      /** 
       * Return true if paramsterSet[index] stream is set
       *
       * @param    index into parameter stream
       *
       * @return   true if index is valid && paramsterSet[index] stream is set; else false
       *
       */
      
      int isParameterStreamSet( int index ) const;
          
      /** 
       * Return string showing if all inverse map streams are set
       *
       * @param    index into inverse map stream array
       *
       * @return   informative string
       *
       */
      
      std::string checkInverseMapStream( int index ) const;

      /* 
       * Get contents of object
       *
       *
       * @param level   level of dump
       *
       * @return string containing contents
       *
       * */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
269
      std::string getContentsString( int level = 0 ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
270
271
272
273
274
275
276
277
278
279
280

   private:
   
      static const int NumberOfParameterStreams = 5;
      static const int NumberOfForceStreams     = 4;
      static const int MaxNumberOfInverseMaps   = 9;

      enum { StreamI, StreamJ, StreamK, StreamL, StreamMax };

      // inverse map stream width

Mark Friedrichs's avatar
Mark Friedrichs committed
281
      int _inverseMapStreamWidth;
Mark Friedrichs's avatar
Mark Friedrichs committed
282
283
284
285
286
287
288
289
290
291
292
293

      // actual max number of inverse maps 

      int _maxNumberOfInverseMaps;

      // scale factors for 1-4 ixn

      BrookOpenMMFloat _ljScale;
      BrookOpenMMFloat _coulombFactor;

      // streams

Mark Friedrichs's avatar
Mark Friedrichs committed
294
295
296
297
298
      BrookFloatStreamInternal* _atomIndicesStream;
      BrookFloatStreamInternal* _bondedParameters[NumberOfParameterStreams];
      BrookFloatStreamInternal* _bondedForceStreams[NumberOfForceStreams];
      BrookFloatStreamInternal* _chargeStream;
      BrookFloatStreamInternal* _inverseStreamMaps[NumberOfForceStreams][MaxNumberOfInverseMaps];
Mark Friedrichs's avatar
Mark Friedrichs committed
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

      int _maxInverseMapStreamCount[NumberOfForceStreams];
      int _inverseMapStreamCount[NumberOfForceStreams];

      // helper methods in setup of parameters

      void flipQuartet( int ibonded, int *atoms );
      int matchTorsion( int i, int j, int k, int l, int nbondeds, int *atoms );
      int matchAngle( int i, int j, int k, int nbondeds, int *atoms, int *flag );
      int matchBond( int i, int j, int nbondeds, int *atoms, int *flag );
      int matchPair( int i, int j, int nbondeds, int *atoms );

      /**
       * Setup Ryckaert-Bellemans parameters/atom indices
       * 
       * @param nbondeds                  number of bonded entries
       * @param atoms                     array of atom indices
       * @param params                    arrays of bond parameters
       * @param rbTorsionIndices          the four atoms connected by each Ryckaert-Bellemans torsion term
       * @param rbTorsionParameters       the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
       *
       * @return nonzero value if error
       *
       */

      int addRBDihedrals( int *nbondeds, int *atoms, BrookOpenMMFloat* params[], const std::vector<std::vector<int> >& rbTorsionIndices,  
                          const std::vector<std::vector<double> >& rbTorsionParameters );

      /**
       * Setup periodic torsion parameters/atom indices
       * 
       * @param nbondeds                  number of bonded entries
       * @param atoms                     array of atom indices
       * @param params                    arrays of bond parameters
       * @param periodicTorsionIndices    the four atoms connected by each periodic torsion term
       * @param periodicTorsionParameters the force parameters (k, phase, periodicity) for each periodic torsion term
       *
       * @return nonzero value if error
       *
       */

      int addPDihedrals( int *nbondeds, int *atoms, BrookOpenMMFloat* params[], const std::vector<std::vector<int> >& periodicTorsionIndices,  
                          const std::vector<std::vector<double> >& periodicTorsionParameters );

      /**
       * Setup angle bond parameters/atom indices
       * 
       * @param nbondeds                  number of bonded entries
       * @param atoms                     array of atom indices
       * @param params                    arrays of bond parameters
       * @param angleIndices              the angle bond atom indices
       * @param angleParameters           the angle parameters (angle in radians, force constant)
       *
       * @return nonzero value if error
       *
       */

      int addAngles( int *nbondeds, int *atoms, BrookOpenMMFloat* params[], const std::vector<std::vector<int> >& angleIndices,
                     const std::vector<std::vector<double> >& angleParameters );

      /**
       * Setup harmonic bond parameters/atom indices
       * 
       * @param nbondeds                  number of bonded entries
       * @param atoms                     array of atom indices
       * @param params                    arrays of bond parameters
       * @param bondIndices               two harmonic bond atom indices
       * @param bondParameters            the force parameters (distance, k)
       *
       * @return nonzero value if error
       *
       */

      int addBonds( int *nbondeds, int *atoms, BrookOpenMMFloat* params[], const std::vector<std::vector<int> >& bondIndices,
                    const std::vector<std::vector<double> >& bondParameters );

      /**
       * Setup LJ/Coulomb 1-4 parameters/atom indices
       * 
       * @param nbondeds                  number of bonded entries
       * @param atoms                     array of atom indices
       * @param params                    arrays of bond parameters
       * @param charges                   array of charges
       * @param bonded14Indices           each element contains the indices of two atoms whose nonbonded interactions should be reduced since
       *                                  they form a bonded 1-4 pair
       * @param nonbondedParameters       the nonbonded force parameters (charge, sigma, epsilon) for each atom
       * @param lj14Scale                 the factor by which van der Waals interactions should be reduced for bonded 1-4 pairs
       *
       * @return nonzero value if error
       *
       */

      int addPairs( int *nbondeds, int *atoms, BrookOpenMMFloat* params[], BrookOpenMMFloat* charges,
                    const std::vector<std::vector<int> >& bonded14Indices, const std::vector<std::vector<double> >& nonbondedParameters,
                    double lj14Scale, double coulombScale );
      
      /**
       * Create and load inverse maps for bonded ixns
       * 
       * @param nbondeds                  number of bonded entries
       * @param natoms                    number of atoms
       * @param atoms                     arrays of atom indices (atoms[numberOfBonds][4])
       * @param platform                  BrookPlatform reference
       * @param log                       log file reference (optional)
       *
       * @return nonzero value if error
       *
       */

      int loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookPlatform& platform );
      
      /**
       * Validate inverse map count
       * 
       * @param index index to check (1-4) 
       * @param count count for index
       *
       * @return -1 if count invalid
       *
       * @tthrow OpenMMException exeception if count invalid
       *
       */

      int validateInverseMapStreamCount( int index, int count ) const;
      
};

} // namespace OpenMM

Mark Friedrichs's avatar
Mark Friedrichs committed
428
#endif /* OPENMM_BROOK_BONDED_H_ */