BrookCommon.h 10.4 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
#ifndef OPENMM_BROOK_COMMON_H_
#define OPENMM_BROOK_COMMON_H_
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
Mark Friedrichs committed
38
39
#include "BrookFloatStreamInternal.h"
#include "BrookIntStreamInternal.h"
40
41
42
43
44
#include "BrookPlatform.h"

namespace OpenMM {

/**
45
 * This kernel is invoked by NonbondedForce to calculate the forces acting on the system.
46
47
48
49
50
51
52
53
54
55
 */
class BrookCommon {

   public:
  
      // return values

      static const int DefaultReturnValue = 0;
      static const int ErrorReturnValue   = -1;

Mark Friedrichs's avatar
Mark Friedrichs committed
56
57
58
59
60
61
      // ---------------------------------------------------------------------------------------

      // Stream names
     
      // bonded stream names

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
62
      static const std::string BondedParticleIndicesStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
      static const std::string BondedParametersStream;
      static const std::string UnrolledForceStream;
      static const std::string BondedChargeStream;
      static const std::string BondedInverseMapStreams;

      // nonbonded stream names

      static const std::string NonBondedExclusionStream;
      static const std::string OuterVdwStream;
      static const std::string InnerSigmaStream;
      static const std::string InnerEpsilonStream;
      static const std::string NonBondedChargeStream;
      static const std::string PartialForceStream;

      // OBC Gbsa streams

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
79
80
81
      static const std::string ObcParticleRadiiStream;
      static const std::string ObcScaledParticleRadiiStream;
      static const std::string ObcParticleRadiiWithDielectricOffsetStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
82
83
84
85
86
      static const std::string ObcBornRadiiStream;
      static const std::string ObcBornRadii2Stream;
      static const std::string ObcIntermediateForceStream;
      static const std::string ObcChainStream;

Mark Friedrichs's avatar
Mark Friedrichs committed
87
88
89
90
91
92
      // Stochastic Dynamics streams

      static const std::string SDPC1Stream;
      static const std::string SDPC2Stream;
      static const std::string SD2XStream;
      static const std::string SD1VStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
93
94
95
      static const std::string VPrimeStream;
      static const std::string XPrimeStream;
      static const std::string InverseMassStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
96
97
98

      // Shake streams

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
99
100
      static const std::string ShakeParticleIndicesStream;
      static const std::string ShakeParticleParameterStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
101
102
103
104
105
106
      static const std::string ShakeXCons0Stream;
      static const std::string ShakeXCons1Stream;
      static const std::string ShakeXCons2Stream;
      static const std::string ShakeXCons3Stream;
      static const std::string ShakeInverseMapStream;

Mark Friedrichs's avatar
Mark Friedrichs committed
107
108
109
      // Random number generator streams

      static const std::string ShuffleStream;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
110
      static const std::string RandomValuesStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
111

112
113
114
115
116
      // BrookVelocityCenterOfMassRemoval streams

      static const std::string BrookVelocityCenterOfMassRemovalWorkStream;
      static const std::string BrookVelocityCenterOfMassRemovalMassStream;

Mark Friedrichs's avatar
Mark Friedrichs committed
117
118
119
120
121
122
123
      // ---------------------------------------------------------------------------------------

     /** 
      * Constructor
      * 
      */
     
124
125
      BrookCommon( );
  
Mark Friedrichs's avatar
Mark Friedrichs committed
126
127
128
129
130
     /** 
      * Destructor
      * 
      */
     
131
132
133
      ~BrookCommon();
  
      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
134
       * Return number of particles
135
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
136
       * @return number of particles
137
138
139
       *
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
140
      int getNumberOfParticles( void ) const; 
141
142

      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
143
       * Get particle ceiling parameter
144
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
145
       * @return particle ceiling parameter
146
147
148
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
149
      int getParticleSizeCeiling( void ) const;
150
151
      
      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
152
       * Get particle stream width
153
154
155
       *
       * @param platform platform reference
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
156
       * @return particle stream width
157
158
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
159
      int getParticleStreamWidth( const Platform& platform ); 
160
161

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
162
       * Get particle stream width
163
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
164
       * @return particle stream width
165
166
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
167
      int getParticleStreamWidth( void ) const; 
168
169

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
170
       * Get particle stream height
171
172
173
       *
       * @param platform platform reference
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
174
       * @return particle stream height
175
176
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
177
      int getParticleStreamHeight( const Platform& platform ); 
178
179

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
180
       * Get particle stream height
181
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
182
       * @return particle stream height
183
184
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
185
      int getParticleStreamHeight( void ) const;
186
187

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
188
       * Get particle stream size
189
190
191
       * 
       * @param platform platform reference
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
192
       * @return particle stream size
193
194
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
195
      int getParticleStreamSize( const Platform& platform ); 
196
197

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
198
       * Get particle stream size
199
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
200
       * @return particle stream size
201
202
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
203
      int getParticleStreamSize( void ) const; 
204

Mark Friedrichs's avatar
Mark Friedrichs committed
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
      /**
       * Get flag signalling whether active
       * 
       * @return flag signalling whether active
       */

      int isActive( void ) const; 

      /**
       * Set flag signalling whether active
       * 
       * @param isActive  flag signalling whether active
       *
       * @return DefaultReturnValue
       */

      int setIsActive( int isActive ); 

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
      /** 
       * Set log file reference
       * 
       * @param  log file reference
       *
       * @return DefaultReturnValue
       *
       */
      
      int setLog( FILE* log );

      /* 
       * Get contents of object
       *
       * @param level of dump
       *
       * @return string containing contents
       *
       * */
      
      std::string getContents( int level ) const;

Mark Friedrichs's avatar
Mark Friedrichs committed
245
246
247
248
249
250
251
252
      /** 
       * Get log file reference
       * 
       * @return  log file reference
       *
       */
      
      FILE* getLog( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

      /* 
       * Given number of stream elements and width, returns the appropriate
       * height of the stream
       *
       * @param streamSize   stream size 
       * @param width        stream width
       *
       * @return stream height
       *
       */
      
      static int getStreamHeight( int streamSize, int streamWidth );
      
      /* 
       * Given number of stream elements, get stream width & height
       *
       * @param streamSize    stream size 
       * @param streamWidth   output stream width
       * @param streamHeight  output stream height
       *
       * @return stream height
       *
       */
      
      static void getStreamDimensions( int streamSize, int *streamWidth, int *streamHeight );
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

      /* 
       * Allocate array
       *
       * @param length        length of array
       * @param width         width  of array
       *
       * @return ptr to array
       *
       */
      
      RealOpenMM** allocateRealArray( int length, int width ) const;
      
      /* 
       * Free array
       *
       * @param array         array to be freed (assumed allocated using BrookCommon::allocateRealArray
       *
       * @return DefaultReturnValue
       *
       */
      
      int disposeRealArray( RealOpenMM** array ) const;

      /* 
       * Copy 1D BrookOpenMMFloat* array to 2D array of RealOpenMM
       *
       * @param length        length of array
       * @param width         width  of array
       * @param array1D       array to copy
       *
       * @return ptr to array
       *
       */
      
      RealOpenMM** copy1DArrayTo2DArray( int length, int width, BrookOpenMMFloat* array1D ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
315
      
316
317
   protected:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
318
      // number of particles
319

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
320
      int _numberOfParticles;
321

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
322
      // particle stream dimensions
323

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
324
325
326
      int _particleStreamWidth;
      int _particleStreamHeight;
      int _particleStreamSize;
327

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
328
      // particle size mod
329

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
330
      int _particleSizeModified;
331
332
333
334
335

      // log file reference

      FILE* _log;

Mark Friedrichs's avatar
Mark Friedrichs committed
336
      // active flag 
Mark Friedrichs's avatar
Mark Friedrichs committed
337

Mark Friedrichs's avatar
Mark Friedrichs committed
338
      int _isActive;
Mark Friedrichs's avatar
Mark Friedrichs committed
339

340
      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
341
       * Set number of particles
342
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
343
       * @param numberOfParticles number of particles
344
345
346
       *
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
347
      int setNumberOfParticles( int numberOfParticles ); 
348
349

      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
350
       * Get particle stream dimensions
351
352
353
354
355
       * 
       * @param platform                  platform
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
356
      void _getParticleStreamDimensions( const Platform& platform );
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
      
      /* 
       * Get line
       *
       * @param tab         tab
       * @param description description
       * @param value       value
       *
       * @return string containing contents
       *
       * */
      
      std::string _getLine( const std::string& tab, const std::string& description, const std::string& value ) const;
      
};

} // namespace OpenMM

Mark Friedrichs's avatar
Mark Friedrichs committed
375
#endif /* OPENMM_BROOK_COMMON_H_ */