OpenMMBrookInterface.h 12.6 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
54
55
#include "NonbondedForce.h"
#include "OpenMMContext.h"
#include "System.h"
#include "ReferencePlatform.h"
#include "VerletIntegrator.h"

namespace OpenMM {

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

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

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

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

313
314
315
316
317
318
319
320
321
      /** 
       * Set BrookBondParameters for LJ 14 force
       * 
       * @param brookBondParameters brookBondParameters for LJ 14 force
       *
       * @return  DefaultReturnValue
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
322
      int setNonBonded14ForceParameters( BrookBondParameters* brookBondParameters );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
323
324
325
326
327
328
329
330
331
      
      /** 
       * Get positions stream
       * 
       * @return particle positions 
       *
       */
         
      BrookStreamImpl* getParticlePositions( void );
332
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
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
382
383
      /** 
       * 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
      /** 
       * Print forces to file 
       * 
       * @param context     context
       *
       */
      
      void printForcesToFile( OpenMMContextImpl& context );
      
      /* 
       * Print contents of object to file
       *
       * @param fileName     file name
       * @param streams      streams to print
       *
       * @return DefaultReturnValue
       *
       * */
      
      int printStreamsToFile( std::string fileName, std::vector<BrookStreamImpl*>& streams );
      
405
406
   private:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
407
408
409
      static const int DefaultReturnValue = 0;
      static const int ErrorReturnValue   = -1;

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

      // log file reference

      FILE* _log;

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

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

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

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

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

432
433
       BrookBondParameters* _bondParameters[LastBondForce];

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

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

440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
       // used to calculate energy

       NonbondedForce*       _refForceField;
       System*               _refSystem;
       OpenMMContext*        _refOpenMMContext;
       ReferencePlatform*    _referencePlatform;
       VerletIntegrator*     _refVerletIntegrator;

      /** 
       * 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
460
461
462
463
464
465
466
467
468
469
470
      /** 
       * Get BrookBondParameters at specified index
       * 
       * @param   index
       *
       * @return  BrookBondParameters* object
       *
       */
      
      BrookBondParameters* _getBondParameters( BondParameterIndices index ) const;
      
471
472
473
474
475
};

} // namespace OpenMM

#endif /* OPENMM_BROOK_INTERFACE_H_ */