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
110
      // Random number generator streams

      static const std::string ShuffleStream;

111
112
113
114
115
      // BrookVelocityCenterOfMassRemoval streams

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
      /**
       * 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 ); 

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
      /** 
       * 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
244
245
246
247
248
249
250
251
      /** 
       * Get log file reference
       * 
       * @return  log file reference
       *
       */
      
      FILE* getLog( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
252
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

      /* 
       * 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 );
278
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

      /* 
       * 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
314
      
315
316
   protected:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
317
      // number of particles
318

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

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

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

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

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

      // log file reference

      FILE* _log;

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

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

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

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

      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
349
       * Get particle stream dimensions
350
351
352
353
354
       * 
       * @param platform                  platform
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
355
      void _getParticleStreamDimensions( const Platform& platform );
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
      
      /* 
       * 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
374
#endif /* OPENMM_BROOK_COMMON_H_ */