OpenMMBrookInterface.h 12 KB
Newer Older
1
2
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
#ifndef OPENMM_BROOK_INTERFACE_H_
#define OPENMM_BROOK_INTERFACE_H_

/* -------------------------------------------------------------------------- *
 *                                   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 "kernels.h"
#include "../../reference/src/SimTKUtilities/SimTKOpenMMRealType.h"
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
37
#include "BrookBondParameters.h"
38
39
#include "BrookBonded.h"
#include "BrookNonBonded.h"
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
40
#include "BrookGbsa.h"
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "NonbondedForce.h"
#include "OpenMMContext.h"
#include "System.h"

namespace OpenMM {

/**
 * OpenMM-Brook interface methods
 */
class OpenMMBrookInterface {

   public:
  
54
      OpenMMBrookInterface( int streamWidth, int duplicationFactor );
55
56
57
58
59
60
  
      ~OpenMMBrookInterface();
  
      /**
       * Get reference Context
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
61
       * @param numberOfParticles  number of particles
62
63
64
65
66
       *
       * @return  OpenMMContext
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
67
      OpenMMContext* getReferenceOpenMMContext( int numberOfParticles );
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
      
      /** 
       * 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
Mods  
Mark Friedrichs committed
91
92
93
94
95
96
97
98
99
      /** 
       * Get number of particles
       * 
       * @return   number of particles
       *
       */
      
      int getNumberOfParticles( void ) const;
      
Mark Friedrichs's avatar
Mark Friedrichs committed
100
101
102
103
104
105
106
107
108
109
110
      /** 
       * Set number of particles
       * 
       * @param numberOfParticles number of particles
       *
       * @return DefaultReturnValue
       *
       */
      
      int setNumberOfParticles( int numberOfParticles );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      /** 
       * Get particle stream width
       * 
       * @return    particle stream width
       *
       */
      
      int getParticleStreamWidth( void ) const;
      
      /** 
       * Get particle stream size
       * 
       * @return    particle stream size
       *
       */
      
      int getParticleStreamSize( void ) const;
      
129
130
131
132
133
134
135
136
137
      /** 
       * Get log file reference
       * 
       * @return  log file reference
       *
       */
      
      FILE* getLog( void ) const;
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
138
139
140
141
142
143
144
145
146
      /** 
       * Zero forces
       *
       * @param context OpenMMContextImpl context 
       *
       */
      
      void zeroForces( OpenMMContextImpl& context );
      
147
148
149
150
151
152
153
154
155
156
157
158
159
      /** 
       * Compute forces
       *
       * @param context OpenMMContextImpl context 
       *
       */
      
      void computeForces( OpenMMContextImpl& context );
      
      /** 
       * Compute energy
       *
       * @param context OpenMMContextImpl context 
Mark Friedrichs's avatar
Mark Friedrichs committed
160
161
162
       * @param system  system reference
       *
       * @return potential energy
163
164
165
       *
       */
      
Mark Friedrichs's avatar
Mark Friedrichs committed
166
      double computeEnergy( OpenMMContextImpl& context, System& system );
167
168
169
170
171
172
173
174
      
      /** 
       * Set trigger Force Kernel
       *
       * @param triggerForceKernel kernel to calculate force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
175
      void setTriggerForceKernel( void* triggerForceKernel );
176
177
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
178
       * Get trigger Force Kernel
179
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
180
       * @return triggerForceKernel kernel to calculate force
181
182
183
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
184
      void* getTriggerForceKernel( void ) const;
185
186
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
187
       * Set trigger Energy Kernel
188
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
189
       * @param triggerEnergyKernel kernel to calculate force
190
191
192
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
193
      void setTriggerEnergyKernel( void* triggerEnergyKernel );
194
195
196
197
      
      /** 
       * Get trigger Energy Kernel
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
198
       * @return triggerEnergyKernel kernel to calculate force
199
200
201
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
202
      void* getTriggerEnergyKernel( 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 BrookNonBonded reference
       * 
       * @return BrookNonBonded reference
       *
       */
      
      BrookNonBonded& getBrookNonBonded( void );
      
      /** 
       * Get BrookGbsa reference
       * 
       * @return BrookGbsa reference
       *
       */
      
      BrookGbsa& getBrookGbsa( void );
      
222
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
223
       * Get BrookBondParameters for harmonic bond force
224
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
225
226
227
228
       * @return brookBondParameters for BrookBondParameters for harmonic bond force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
229
      BrookBondParameters* getHarmonicBondForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
230
231
232
233
234
      
      /** 
       * Set BrookBondParameters for harmonic bond force
       * 
       * @param brookBondParameters BrookBondParameters for harmonic bond force
235
236
237
238
239
240
241
       *
       * @return DefaultReturnValue
       *
       */
      
      int setHarmonicBondForceParameters( BrookBondParameters* brookBondParameters );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
242
243
244
245
246
247
248
      /** 
       * Get BrookBondParameters for harmonic angle force
       * 
       * @return brookBondParameters for BrookBondParameters for harmonic angle force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
249
      BrookBondParameters* getHarmonicAngleForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
250
      
251
252
253
254
255
256
257
258
259
260
261
262
      /** 
       * Set BrookBondParameters for harmonic angle force
       * 
       * @param brookBondParameters brookBondParameters for BrookBondParameters for harmonic angle force
       *
       * @return DefaultReturnValue
       *
       */
      
      int setHarmonicAngleForceParameters( BrookBondParameters* brookBondParameters );
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
263
264
265
266
267
268
       * Get BrookBondParameters for periodic torsion force
       * 
       * @return brookBondParameters for BrookBondParameters for periodic torsion force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
269
      BrookBondParameters* getPeriodicTorsionForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
270
271
272

      /** 
       * Set BrookBondParameters for periodic torsion force
273
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
274
       * @param brookBondParameters for periodic torsion force
275
276
277
278
279
280
281
282
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setPeriodicTorsionForceParameters( BrookBondParameters* brookBondParameters );
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
283
       * Get BrookBondParameters for RB torsion force
284
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
285
286
287
288
       * @return brookBondParameters for BrookBondParameters for RB torsion force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
289
      BrookBondParameters* getRBTorsionForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
290
291
292
293
294

      /** 
       * Set BrookBondParameters for RB torsion force
       * 
       * @param brookBondParameters brookBondParameters for RB torsion force
295
296
297
298
299
300
301
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setRBTorsionForceParameters( BrookBondParameters* brookBondParameters );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
302
303
304
305
306
307
308
      /** 
       * Get BrookBondParameters for LJ 14 forces
       * 
       * @return brookBondParameters for BrookBondParameters for LJ 14 forces
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
309
      BrookBondParameters* getNonBonded14ForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
310

311
312
313
314
315
316
317
318
319
      /** 
       * Set BrookBondParameters for LJ 14 force
       * 
       * @param brookBondParameters brookBondParameters for LJ 14 force
       *
       * @return  DefaultReturnValue
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
320
      int setNonBonded14ForceParameters( BrookBondParameters* brookBondParameters );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
321
322
323
324
325
326
327
328
329
      
      /** 
       * Get positions stream
       * 
       * @return particle positions 
       *
       */
         
      BrookStreamImpl* getParticlePositions( void );
330
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
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
      /** 
       * Set positions stream
       * 
       * @param positions Brook stream containing particle positions
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setParticlePositions( BrookStreamImpl* positions );
      
      /** 
       * Get velocities stream
       * 
       * @return particle velocities
       *
       */
             
      BrookStreamImpl* getParticleVelocities( void );
       
      /** 
       * Set velocities stream
       * 
       * @param velocities Brook stream containing particle velocities
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setParticleVelocities( BrookStreamImpl* velocities );
      
      /** 
       * Get forces stream
       * 
       * @return ParticleForces
       *
       */
             
      BrookStreamImpl* getParticleForces( void );

      /** 
       * Set forces stream
       * 
       * @param forces Brook stream containing particle forces
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setParticleForces( BrookStreamImpl* forces );

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
382
383
384
385
386
387
388
389
390
      /** 
       * Print forces to file 
       * 
       * @param context     context
       *
       */
      
      void printForcesToFile( OpenMMContextImpl& context );
      
391
392
   private:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
393
394
395
      static const int DefaultReturnValue = 0;
      static const int ErrorReturnValue   = -1;

396
397
398
399
400
401
      enum BondParameterIndices { HarmonicBondIndex, HarmonicAngleIndex, PeriodicTorsionForceIndex, RbTorsionForceIndex, LJ14Index, LastBondForce };

      // log file reference

      FILE* _log;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
402
403
404
      int _particleStreamWidth;
      int _particleStreamSize;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
405
       // number of particles
406

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
407
       int _numberOfParticles;
408
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
409
       // Brook bonded, nonbonded, Gbsa
410

Mark Friedrichs's avatar
Mark Friedrichs committed
411
412
413
       BrookBonded     _brookBonded;
       BrookNonBonded  _brookNonBonded;
       BrookGbsa       _brookGbsa;
414

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
415
416
417
       void* _triggerForceKernel;
       void* _triggerEnergyKernel;

418
419
       BrookBondParameters* _bondParameters[LastBondForce];

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
420
421
422
423
424
425
       // context-related fields

       BrookStreamImpl* _positions;
       BrookStreamImpl* _velocities;
       BrookStreamImpl* _forces;

426
427
428
429
430
431
432
433
434
435
436
437
      /** 
       * Set BrookBondParameters 
       * 
       * @param index
       * @param brookBondParameters brookBondParameters for BrookBondParameters
       *
       * @return DefaultReturnValue
       *
       */
      
      int _setBondParameters( BondParameterIndices index, BrookBondParameters* brookBondParameters );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
438
439
440
441
442
443
444
445
446
447
448
      /** 
       * Get BrookBondParameters at specified index
       * 
       * @param   index
       *
       * @return  BrookBondParameters* object
       *
       */
      
      BrookBondParameters* _getBondParameters( BondParameterIndices index ) const;
      
449
450
451
452
453
};

} // namespace OpenMM

#endif /* OPENMM_BROOK_INTERFACE_H_ */