BrookNonBonded.h 15.5 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
#ifndef OPENMM_BROOK_NONBONDED_H_
#define OPENMM_BROOK_NONBONDED_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
37

/* -------------------------------------------------------------------------- *
 *                                   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>
#include <set>

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
38
#include "BrookStreamImpl.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
39
40
41
42
43
44
#include "BrookPlatform.h"
#include "BrookCommon.h"

namespace OpenMM {

/**
45
 * This kernel is invoked by NonbondedForce to calculate the forces acting on the system.
Mark Friedrichs's avatar
Mark Friedrichs committed
46
47
48
49
50
 */
class BrookNonBonded : public BrookCommon {

   public:
  
Mark Friedrichs's avatar
Mark Friedrichs committed
51
     BrookNonBonded( );
Mark Friedrichs's avatar
Mark Friedrichs committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  
      ~BrookNonBonded();
  
      /**
       * Return number of force streams
       * 
       * @return number of force streams
       *
       */

      int getNumberOfForceStreams( void ) const; 

      /** 
       * Get duplication factor
       * 
       * @return   duplication factor
       *
       */
      
      int getDuplicationFactor( void ) const;
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
74
       * Get particle ceiling parameter
Mark Friedrichs's avatar
Mark Friedrichs committed
75
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
76
       * @return particle ceiling parameter
Mark Friedrichs's avatar
Mark Friedrichs committed
77
78
79
       *
       */
         
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
80
      int getParticleSizeCeiling( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
143
144
145
146
147
148
149
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
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
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
 
      /** 
       * Get outer loop unroll
       * 
       * @return   outer loop unroll (fixed value)
       *
       */
      
      int getOuterLoopUnroll( void ) const;
      
      /** 
       * Set outer loop unroll
       * 
       * @param  outer loop unroll (fixed value)
       *
       * @return updated outer loop unroll (fixed value)
       *
       */
      
      int setOuterLoopUnroll( int outerUnroll );
      
      /**
       * Return unrolling for inner loops
       * 
       * @return outer loop unrolling
       */

      int getInnerLoopUnroll( void ) const; 

      /**
       * Get j-stream width
       *
       * @param platform platform reference
       *
       * @return j-stream width
       */

      int getJStreamWidth( const Platform& platform ); 

      /**
       * Get j-stream width
       *
       * @return j-stream width
       */

      int getJStreamWidth( void ) const; 

      /**
       * Get j-stream height
       *
       * @param platform platform reference
       *
       * @return j-stream height
       */

      int getJStreamHeight( const Platform& platform ); 

      /**
       * Get j-stream height
       *
       * @return j-stream height
       */

      int getJStreamHeight( void ) const;

      /**
       * Get j-stream size
       * 
       * @param platform platform reference
       *
       * @return j-stream size
       */

      int getJStreamSize( const Platform& platform ); 

      /**
       * Get j-stream size
       * 
       * @return j-stream size
       */

      int getJStreamSize( void ) const; 

      /**
       * Get partial force stream width
       *
       * @param platform platform reference
       *
       * @return partial force stream width
       */

      int getPartialForceStreamWidth( const Platform& platform ); 

      /**
       * Get partial force stream width
       *
       * @return partial force stream width
       */

      int getPartialForceStreamWidth( void ) const; 

      /**
       * Get partial force stream height
       *
       * @param platform platform reference
       *
       * @return partial force stream height
       */

      int getPartialForceStreamHeight( const Platform& platform ); 

      /**
       * Get partial force stream height
       *
       * @return partial force stream height
       */

      int getPartialForceStreamHeight( void ) const;

      /**
       * Get partial force stream size
       * 
       * @param platform platform reference
       *
       * @return partial force stream size
       */

      int getPartialForceStreamSize( const Platform& platform ); 

      /**
       * Get partial force stream size
       * 
       * @return partial force stream size
       */

      int getPartialForceStreamSize( void ) const; 

      /**
       * Get partial force stream size
       * 
       * @return partial force stream size
       */

      /**
       * Get exclusion stream width
       * 
       * @return exclusion stream width
       */

      int getExclusionStreamWidth( void ) const; 

      /**
       * Get exclusion stream size
       * 
       * @return exclusion stream size
       */

      int getExclusionStreamSize( void ) const; 

      /** 
       * Get exclusion stream 
       *
       * @return  exclusion stream
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
247
      BrookFloatStreamInternal* getExclusionStream( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
248
249
250
251
252
253
254
255
      
      /** 
       * Get vdw stream 
       *
       * @return  vdw stream
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
256
      BrookFloatStreamInternal* getOuterVdwStream( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
257
258
259
260
261
262
263
264
      
      /** 
       * Get charge stream 
       *
       * @return  charge stream
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
265
      BrookFloatStreamInternal* getChargeStream( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
266
267
268
269
270
271
272
273
      
      /** 
       * Get sigma-eps stream 
       *
       * @return  sigma-eps stream
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
274
      BrookFloatStreamInternal* getInnerSigmaStream( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
275
276
277
278
279
280
281
282
      
      /** 
       * Get epsilon stream 
       *
       * @return  epsilon stream
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
283
      BrookFloatStreamInternal* getInnerEpsilonStream( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
284
285
286
287
288
289
290
291
      
      /** 
       * Get force streams 
       *
       * @return  force streams
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
292
      BrookFloatStreamInternal** getForceStreams( void );
Mark Friedrichs's avatar
Mark Friedrichs committed
293
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
294
295
296
297
298
299
300
      /** 
       * Compute forces
       * 
       */
      
      void computeForces( BrookStreamImpl& positionStream, BrookStreamImpl& forceStream );
      
Mark Friedrichs's avatar
Mark Friedrichs committed
301
302
303
304
305
306
307
308
309
310
311
312
      /** 
       * Return true if force[index] stream is set 
       *
       * @return  true  if index is valid && force[index] stream is set; else false
       *
       */
      
      int isForceStreamSet( int index ) const;
      
      /* 
       * Setup of nonbonded ixns
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
313
314
315
316
       * @param numberOfParticles         number of particles
       * @param nonbondedParameters   vector of nonbonded parameters [particleI][0=c6]
       *                                                             [particleI][1=c12]
       *                                                             [particleI][2=charge]
Mark Friedrichs's avatar
Mark Friedrichs committed
317
318
319
320
321
322
       * @param platform              Brook platform
       * @param log                   optional Log file reference
       *
       * @return nonzero value if error
       * */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
323
      int setup( int numberOfParticles, const std::vector<std::vector<double> >& nonbondedParameters,
Mark Friedrichs's avatar
Mark Friedrichs committed
324
                 const std::vector<std::set<int> >& exclusions,  const Platform& platform );
Mark Friedrichs's avatar
Mark Friedrichs committed
325
      
326
327
328
329
330
331
332
333
334
335
336
      /** 
       * Set duplication factor
       * 
       * @param   duplication factor
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setDuplicationFactor( int duplicationFactor );
      
Mark Friedrichs's avatar
Mark Friedrichs committed
337
338
339
340
341
342
343
344
345
      /* 
       * Get contents of object
       *
       * @param level of dump
       *
       * @return string containing contents
       *
       * */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
346
      std::string getContentsString( int level = 0 ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
347
348
349
350
351
352
353

   private:
   
      // fixed number of force streams

      static const int NumberOfForceStreams     = 4;

Mark Friedrichs's avatar
Mark Friedrichs committed
354
355
356
357
358
359
360
361
362
363
364
      // streams indices

      enum { 
              ExclusionStream,
              OuterVdwStream,
              ChargeStream,
              InnerSigmaStream,
              InnerEpsilonStream,
              LastStreamIndex
           };

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
365
      // particle ceiling
Mark Friedrichs's avatar
Mark Friedrichs committed
366

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
367
      int _particleSizeCeiling;
Mark Friedrichs's avatar
Mark Friedrichs committed
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

      // unroll in i/j dimensions

      int _outerUnroll;
      int _innerUnroll;

      // duplication factor

      int _duplicationFactor;

      // force stream width

      int _partialForceStreamWidth;
      int _partialForceStreamHeight;
      int _partialForceStreamSize;

      // exclusions stream dimensions

      int _exclusionStreamWidth;
      int _exclusionStreamHeight;
      int _exclusionStreamSize;

      // j-stream dimensions

      int _jStreamWidth;
      int _jStreamHeight;
      int _jStreamSize;

Mark Friedrichs's avatar
Mark Friedrichs committed
396
      // internal streams
Mark Friedrichs's avatar
Mark Friedrichs committed
397

Mark Friedrichs's avatar
Mark Friedrichs committed
398
399
      BrookFloatStreamInternal* _nonbondedStreams[LastStreamIndex];
      BrookFloatStreamInternal* _nonbondedForceStreams[NumberOfForceStreams];
Mark Friedrichs's avatar
Mark Friedrichs committed
400

Mark Friedrichs's avatar
Mark Friedrichs committed
401
402
403
      /* 
       * Setup of stream dimensions for exclusion stream
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
404
405
       * @param particleStreamSize        particle stream size
       * @param particleStreamWidth       particle stream width
Mark Friedrichs's avatar
Mark Friedrichs committed
406
407
408
409
410
       *
       * @return ErrorReturnValue if error, else DefaultReturnValue
       *
       * */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
411
      int _initializeExclusionStreamSize( int particleStreamSize, int particleStreamWidth );
Mark Friedrichs's avatar
Mark Friedrichs committed
412
      
Mark Friedrichs's avatar
Mark Friedrichs committed
413
414
415
416
417
418
419
420
421
      /** 
       * Initialize exclusion stream dimensions and stream
       * 
       * @param platform                  platform
       *
       * @return nonzero value if error
       *
       */
      
422
      int _initializeExclusionStream( const Platform& platform );
Mark Friedrichs's avatar
Mark Friedrichs committed
423
424
425
426
            
      /** 
       * Set exclusion (4x4)
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
427
428
       * @param i                         particle i index
       * @param j                         particle j index
Mark Friedrichs's avatar
Mark Friedrichs committed
429
430
431
432
433
434
435
       * @param exclusionStreamWidth      exclusion stream width
       * @param exclusion                 array of packed exclusions
       *
       * @return nonzero value if error
       *
       */
      
436
      int _setExclusion( int i, int j, int exclusionStreamWidth, BrookOpenMMFloat* exclusion );
Mark Friedrichs's avatar
Mark Friedrichs committed
437
438
439
440
      
      /** 
       * Initialize exclusions
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
441
       * @param exclusions                vector of sets containing exclusions (1 set entry for every particle)
Mark Friedrichs's avatar
Mark Friedrichs committed
442
443
444
445
446
447
       * @param platform                  platform
       *
       * @return nonzero value if error
       *
       */
      
448
      int _initializeExclusions( const std::vector<std::set<int> >& exclusionsVector, const Platform& platform );
Mark Friedrichs's avatar
Mark Friedrichs committed
449

Mark Friedrichs's avatar
Mark Friedrichs committed
450
451
452
      /** 
       * Initialize stream dimensions
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
453
       * @param numberOfParticles             number of particles
Mark Friedrichs's avatar
Mark Friedrichs committed
454
455
456
457
458
459
       * @param platform                  platform
       *
       * @return ErrorReturnValue if error, else DefaultReturnValue
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
460
      int _initializeStreamSizes( int numberOfParticles, const Platform& platform );
Mark Friedrichs's avatar
Mark Friedrichs committed
461
      
Mark Friedrichs's avatar
Mark Friedrichs committed
462
463
464
465
466
467
468
469
470
      /** 
       * Initialize stream dimensions and streams
       * 
       * @param platform                  platform
       *
       * @return nonzero value if error
       *
       */
      
471
      int _initializeStreams( const Platform& platform );
Mark Friedrichs's avatar
Mark Friedrichs committed
472
473
474
475
      
      /* 
       * Setup of j-stream dimensions
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
476
477
       * @param particleStreamSize        particle stream size
       * @param particleStreamWidth       particle stream width
Mark Friedrichs's avatar
Mark Friedrichs committed
478
479
480
481
482
483
484
       *
       * @return ErrorReturnValue if error, else DefaultReturnValue
       *
       * @throw  OpenMMException  if jStreamWidth < 1 || innerUnroll < 1
       *
       * */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
485
      int _initializeJStreamSize( int particleStreamSize, int particleStreamWidth );
Mark Friedrichs's avatar
Mark Friedrichs committed
486
487
488
489

      /* 
       * Setup of outer vdw stream size
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
490
491
       * @param particleStreamSize        particle stream size
       * @param particleStreamWidth       particle stream width
Mark Friedrichs's avatar
Mark Friedrichs committed
492
493
494
495
496
497
       *
       * @return ErrorReturnValue if error, else DefaultReturnValue
       *
       * @throw  OpenMMException  if jStreamWidth < 1 || innerUnroll < 1
       *
       * */
Mark Friedrichs's avatar
Mark Friedrichs committed
498
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
499
      int _initializeOuterVdwStreamSize( int particleStreamSize, int particleStreamWidth );
Mark Friedrichs's avatar
Mark Friedrichs committed
500

Mark Friedrichs's avatar
Mark Friedrichs committed
501
502
503
504
505
506
507
508
509
510
511
512
      /** 
       * Set sigma & epsilon given c6 & c12 (geometric rule)
       * 
       * @param c6                        vdw c6
       * @param c12                       vdw c12
       * @param sigma                     massaged sigma
       * @param epsilon                   massaged epsilon
       *
       * @return nonzero value if error
       *
       */
      
513
      int _setSigmaEpsilon( double c6, double c12, double* sigma , double* epsilon );
Mark Friedrichs's avatar
Mark Friedrichs committed
514
515
516
517

      /** 
       * Initialize vdw & charge
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
518
       * @param exclusions                vector of sets containing exclusions (1 set entry for every particle)
Mark Friedrichs's avatar
Mark Friedrichs committed
519
520
521
522
523
524
       * @param platform                  platform
       *
       * @return nonzero value if error
       *
       */
      
525
526
527
528
529
      int _initializeVdwAndCharge( const std::vector<std::vector<double> >& nonbondedParameters, const Platform& platform );
      
      /** 
       * Initialize vdw & charge
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
530
       * @param exclusions                vector of sets containing exclusions (1 set entry for every particle)
531
532
533
534
535
536
537
       * @param platform                  platform
       *
       * @return nonzero value if error
       *
       */
      
      int _initializeJStreamVdw( const std::vector<std::vector<double> >& nonbondedParameters, const Platform& platform );
Mark Friedrichs's avatar
Mark Friedrichs committed
538
      
Mark Friedrichs's avatar
Mark Friedrichs committed
539
540
541
      /* 
       * Setup of stream dimensions for partial force streams
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
542
543
       * @param particleStreamSize        particle stream size
       * @param particleStreamWidth       particle stream width
Mark Friedrichs's avatar
Mark Friedrichs committed
544
545
546
547
548
       *
       * @return ErrorReturnValue if error, else DefaultReturnValue
       *
       * */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
549
      int _initializePartialForceStreamSize( int particleStreamSize, int particleStreamWidth );
Mark Friedrichs's avatar
Mark Friedrichs committed
550
      
551
552
553
554
555
556
557
558
559
560
561
562
563
564
      /* 
       * Utility to compute distances between two points
       *
       * @param idx1       index of point1 into array 
       * @param idx2       index of point2 into array 
       * @param coord      array of points p1={coord[0], coord[1], coord[2] },
       *                                   p2={coord[3], coord[4], coord[5] },
       *                                   p3={coord[6], coord[7], coord[8] }
       *
       * @return distance
       *
       * */
      
      float _computeDistance( int idx1, int idx2, float* coord );
Mark Friedrichs's avatar
Mark Friedrichs committed
565
566
567
568
};

} // namespace OpenMM

Mark Friedrichs's avatar
Mark Friedrichs committed
569
#endif /* OPENMM_BROOK_NONBONDED_H_ */