BrookCommon.h 10.1 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

/* -------------------------------------------------------------------------- *
 *                                   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.               *
 *                                                                            *
12
13
 * Portions copyright (c) 2009 Stanford University and the Authors.           *
 * Authors: Mark Friedrichs, Mike Houston                                     *
14
15
 * Contributors:                                                              *
 *                                                                            *
16
17
18
19
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
20
 *                                                                            *
21
22
23
24
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
25
 *                                                                            *
26
27
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
28
29
30
31
32
 * -------------------------------------------------------------------------- */

#include <vector>
#include <set>

Mark Friedrichs's avatar
Mark Friedrichs committed
33
34
#include "BrookFloatStreamInternal.h"
#include "BrookIntStreamInternal.h"
35
36
37
38
39
#include "BrookPlatform.h"

namespace OpenMM {

/**
40
 * This kernel is invoked by NonbondedForce to calculate the forces acting on the system.
41
42
43
44
45
46
47
48
49
50
 */
class BrookCommon {

   public:
  
      // return values

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

Mark Friedrichs's avatar
Mark Friedrichs committed
51
52
53
54
55
56
      // ---------------------------------------------------------------------------------------

      // Stream names
     
      // bonded stream names

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
57
      static const std::string BondedParticleIndicesStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
      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
74
75
76
      static const std::string ObcParticleRadiiStream;
      static const std::string ObcScaledParticleRadiiStream;
      static const std::string ObcParticleRadiiWithDielectricOffsetStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
77
78
79
80
81
      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
82
83
84
85
86
87
      // 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
88
89
90
      static const std::string VPrimeStream;
      static const std::string XPrimeStream;
      static const std::string InverseMassStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
91
92
93

      // Shake streams

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
94
95
      static const std::string ShakeParticleIndicesStream;
      static const std::string ShakeParticleParameterStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
96
97
98
99
100
101
      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
102
103
104
      // Random number generator streams

      static const std::string ShuffleStream;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
105
      static const std::string RandomValuesStream;
Mark Friedrichs's avatar
Mark Friedrichs committed
106

107
108
109
110
111
      // BrookVelocityCenterOfMassRemoval streams

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

Mark Friedrichs's avatar
Mark Friedrichs committed
112
113
114
115
116
117
118
      // ---------------------------------------------------------------------------------------

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

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
135
      int getNumberOfParticles( void ) const; 
136
137

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

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
154
      int getParticleStreamWidth( const Platform& platform ); 
155
156

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
157
       * Get particle stream width
158
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
159
       * @return particle stream width
160
161
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
162
      int getParticleStreamWidth( void ) const; 
163
164

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
165
       * Get particle stream height
166
167
168
       *
       * @param platform platform reference
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
169
       * @return particle stream height
170
171
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
172
      int getParticleStreamHeight( const Platform& platform ); 
173
174

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
175
       * Get particle stream height
176
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
177
       * @return particle stream height
178
179
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
180
      int getParticleStreamHeight( void ) const;
181
182

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
183
       * Get particle stream size
184
185
186
       * 
       * @param platform platform reference
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
187
       * @return particle stream size
188
189
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
190
      int getParticleStreamSize( const Platform& platform ); 
191
192

      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
193
       * Get particle stream size
194
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
195
       * @return particle stream size
196
197
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
198
      int getParticleStreamSize( void ) const; 
199

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

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
      /** 
       * 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
240
241
242
243
244
245
246
247
      /** 
       * Get log file reference
       * 
       * @return  log file reference
       *
       */
      
      FILE* getLog( void ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

      /* 
       * 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 );
274
275
276
277
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

      /* 
       * 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
310
      
311
312
   protected:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
313
      // number of particles
314

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
315
      int _numberOfParticles;
316

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
317
      // particle stream dimensions
318

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
319
320
321
      int _particleStreamWidth;
      int _particleStreamHeight;
      int _particleStreamSize;
322

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
323
      // particle size mod
324

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
325
      int _particleSizeModified;
326
327
328
329
330

      // log file reference

      FILE* _log;

Mark Friedrichs's avatar
Mark Friedrichs committed
331
      // active flag 
Mark Friedrichs's avatar
Mark Friedrichs committed
332

Mark Friedrichs's avatar
Mark Friedrichs committed
333
      int _isActive;
Mark Friedrichs's avatar
Mark Friedrichs committed
334

335
      /**
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
336
       * Set number of particles
337
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
338
       * @param numberOfParticles number of particles
339
340
341
       *
       */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
342
      int setNumberOfParticles( int numberOfParticles ); 
343
344

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