OpenMMBrookInterface.h 11.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#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.               *
 *                                                                            *
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
#include "openmm/kernels.h"
31
#include "../../reference/src/SimTKUtilities/SimTKOpenMMRealType.h"
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
32
#include "BrookBondParameters.h"
33
34
#include "BrookBonded.h"
#include "BrookNonBonded.h"
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
35
#include "BrookGbsa.h"
36
#include "openmm/NonbondedForce.h"
37
#include "openmm/Context.h"
38
#include "openmm/System.h"
39
40
41
42
43
44
45
46
47
48

namespace OpenMM {

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

   public:
  
49
      OpenMMBrookInterface( int streamWidth, int duplicationFactor );
50
51
52
53
54
55
  
      ~OpenMMBrookInterface();
  
      /**
       * Get reference Context
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
56
       * @param numberOfParticles  number of particles
57
       *
58
       * @return  Context
59
60
61
       *
       */
      
62
      Context* getReferenceContext( int numberOfParticles );
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
      
      /** 
       * 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
86
87
88
89
90
91
92
93
94
      /** 
       * Get number of particles
       * 
       * @return   number of particles
       *
       */
      
      int getNumberOfParticles( void ) const;
      
Mark Friedrichs's avatar
Mark Friedrichs committed
95
96
97
98
99
100
101
102
103
104
      /** 
       * Set number of particles
       * 
       * @param numberOfParticles number of particles
       *
       * @return DefaultReturnValue
       *
       */
      
      int setNumberOfParticles( int numberOfParticles );
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

      /**
       * Get the current time
       *
       * @return   the current time
       *
       */

      double getTime( void ) const;

      /**
       * Set the current time
       *
       * @param time the current time
       *
       * @return DefaultReturnValue
       *
       */

      int setTime( double time);
Mark Friedrichs's avatar
Mark Friedrichs committed
125
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
      /** 
       * Get particle stream width
       * 
       * @return    particle stream width
       *
       */
      
      int getParticleStreamWidth( void ) const;
      
      /** 
       * Get particle stream size
       * 
       * @return    particle stream size
       *
       */
      
      int getParticleStreamSize( void ) const;
      
144
145
146
147
148
149
150
151
152
      /** 
       * Get log file reference
       * 
       * @return  log file reference
       *
       */
      
      FILE* getLog( void ) const;
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
153
154
155
      /** 
       * Zero forces
       *
156
       * @param context ContextImpl context 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
157
158
159
       *
       */
      
160
      void zeroForces( ContextImpl& context );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
161
      
162
163
164
      /** 
       * Compute forces
       *
165
       * @param context ContextImpl context 
166
167
168
       *
       */
      
169
      void computeForces( ContextImpl& context );
170
171
172
173
      
      /** 
       * Compute energy
       *
174
       * @param context ContextImpl context 
Mark Friedrichs's avatar
Mark Friedrichs committed
175
176
177
       * @param system  system reference
       *
       * @return potential energy
178
179
180
       *
       */
      
181
      double computeEnergy( ContextImpl& context, System& system );
182
183
184
185
186
187
188
189
      
      /** 
       * Set trigger Force Kernel
       *
       * @param triggerForceKernel kernel to calculate force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
190
      void setTriggerForceKernel( void* triggerForceKernel );
191
192
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
193
       * Get trigger Force Kernel
194
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
195
       * @return triggerForceKernel kernel to calculate force
196
197
198
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
199
      void* getTriggerForceKernel( void ) const;
200
201
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
202
       * Set trigger Energy Kernel
203
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
204
       * @param triggerEnergyKernel kernel to calculate force
205
206
207
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
208
      void setTriggerEnergyKernel( void* triggerEnergyKernel );
209
210
211
212
      
      /** 
       * Get trigger Energy Kernel
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
213
       * @return triggerEnergyKernel kernel to calculate force
214
215
216
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
217
      void* getTriggerEnergyKernel( void ) const;
218
      
Mark Friedrichs's avatar
Mark Friedrichs committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
      /** 
       * Get BrookNonBonded reference
       * 
       * @return BrookNonBonded reference
       *
       */
      
      BrookNonBonded& getBrookNonBonded( void );
      
      /** 
       * Get BrookGbsa reference
       * 
       * @return BrookGbsa reference
       *
       */
      
      BrookGbsa& getBrookGbsa( void );
      
237
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
238
       * Get BrookBondParameters for harmonic bond force
239
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
240
241
242
243
       * @return brookBondParameters for BrookBondParameters for harmonic bond force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
244
      BrookBondParameters* getHarmonicBondForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
245
246
247
248
249
      
      /** 
       * Set BrookBondParameters for harmonic bond force
       * 
       * @param brookBondParameters BrookBondParameters for harmonic bond force
250
251
252
253
254
255
256
       *
       * @return DefaultReturnValue
       *
       */
      
      int setHarmonicBondForceParameters( BrookBondParameters* brookBondParameters );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
257
258
259
260
261
262
263
      /** 
       * Get BrookBondParameters for harmonic angle force
       * 
       * @return brookBondParameters for BrookBondParameters for harmonic angle force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
264
      BrookBondParameters* getHarmonicAngleForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
265
      
266
267
268
269
270
271
272
273
274
275
276
277
      /** 
       * 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
278
279
280
281
282
283
       * Get BrookBondParameters for periodic torsion force
       * 
       * @return brookBondParameters for BrookBondParameters for periodic torsion force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
284
      BrookBondParameters* getPeriodicTorsionForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
285
286
287

      /** 
       * Set BrookBondParameters for periodic torsion force
288
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
289
       * @param brookBondParameters for periodic torsion force
290
291
292
293
294
295
296
297
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setPeriodicTorsionForceParameters( BrookBondParameters* brookBondParameters );
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
298
       * Get BrookBondParameters for RB torsion force
299
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
300
301
302
303
       * @return brookBondParameters for BrookBondParameters for RB torsion force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
304
      BrookBondParameters* getRBTorsionForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
305
306
307
308
309

      /** 
       * Set BrookBondParameters for RB torsion force
       * 
       * @param brookBondParameters brookBondParameters for RB torsion force
310
311
312
313
314
315
316
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setRBTorsionForceParameters( BrookBondParameters* brookBondParameters );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
317
318
319
320
321
322
323
      /** 
       * Get BrookBondParameters for LJ 14 forces
       * 
       * @return brookBondParameters for BrookBondParameters for LJ 14 forces
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
324
      BrookBondParameters* getNonBonded14ForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
325

326
327
328
329
330
331
332
333
334
      /** 
       * Set BrookBondParameters for LJ 14 force
       * 
       * @param brookBondParameters brookBondParameters for LJ 14 force
       *
       * @return  DefaultReturnValue
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
335
      int setNonBonded14ForceParameters( BrookBondParameters* brookBondParameters );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
336
337
338
339
340
341
342
343
344
      
      /** 
       * Get positions stream
       * 
       * @return particle positions 
       *
       */
         
      BrookStreamImpl* getParticlePositions( void );
345
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
      /** 
       * 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
397
398
399
400
401
402
403
      /** 
       * Print forces to file 
       * 
       * @param context     context
       *
       */
      
404
      void printForcesToFile( ContextImpl& context );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
405
      
406
407
   private:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
408
409
410
      static const int DefaultReturnValue = 0;
      static const int ErrorReturnValue   = -1;

411
412
413
414
415
416
      enum BondParameterIndices { HarmonicBondIndex, HarmonicAngleIndex, PeriodicTorsionForceIndex, RbTorsionForceIndex, LJ14Index, LastBondForce };

      // log file reference

      FILE* _log;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
417
418
419
      int _particleStreamWidth;
      int _particleStreamSize;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
420
       // number of particles
421

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
422
       int _numberOfParticles;
423
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
424
       // Brook bonded, nonbonded, Gbsa
425

Mark Friedrichs's avatar
Mark Friedrichs committed
426
427
428
       BrookBonded     _brookBonded;
       BrookNonBonded  _brookNonBonded;
       BrookGbsa       _brookGbsa;
429

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
430
431
432
       void* _triggerForceKernel;
       void* _triggerEnergyKernel;

433
434
       BrookBondParameters* _bondParameters[LastBondForce];

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
435
436
437
438
439
       // context-related fields

       BrookStreamImpl* _positions;
       BrookStreamImpl* _velocities;
       BrookStreamImpl* _forces;
440
       double _time;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
441

442
443
444
445
446
447
448
449
450
451
452
453
      /** 
       * 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
454
455
456
457
458
459
460
461
462
463
464
      /** 
       * Get BrookBondParameters at specified index
       * 
       * @param   index
       *
       * @return  BrookBondParameters* object
       *
       */
      
      BrookBondParameters* _getBondParameters( BondParameterIndices index ) const;
      
465
466
467
468
469
};

} // namespace OpenMM

#endif /* OPENMM_BROOK_INTERFACE_H_ */