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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
      /** 
       * Get number of particles
       * 
       * @return   number of particles
       *
       */
      
      int getNumberOfParticles( void ) const;
      
      /** 
       * Get particle stream width
       * 
       * @return    particle stream width
       *
       */
      
      int getParticleStreamWidth( void ) const;
      
      /** 
       * Get particle stream size
       * 
       * @return    particle stream size
       *
       */
      
      int getParticleStreamSize( void ) const;
      
      /** 
       * Get LJ-14 scale factor
       * 
       * @return    LJ-14 scale factor
       *
       */
      
      double getLj14Scale( void ) const;
      
      /** 
       * Get Coulomb scale factor
       * 
       * @return    Coulomb scale factor
       *
       */
      
      double getCoulomb14Scale( void ) const;

138
139
140
141
142
143
144
145
146
      /** 
       * Get log file reference
       * 
       * @return  log file reference
       *
       */
      
      FILE* getLog( void ) const;
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
147
148
149
150
151
152
153
154
155
      /** 
       * Zero forces
       *
       * @param context OpenMMContextImpl context 
       *
       */
      
      void zeroForces( OpenMMContextImpl& context );
      
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
      /** 
       * Compute forces
       *
       * @param context OpenMMContextImpl context 
       *
       */
      
      void computeForces( OpenMMContextImpl& context );
      
      /** 
       * Compute energy
       *
       * @param context OpenMMContextImpl context 
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
172
      double computeEnergy( OpenMMContextImpl& context );
173
174
175
176
177
178
179
180
      
      /** 
       * Set trigger Force Kernel
       *
       * @param triggerForceKernel kernel to calculate force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
181
      void setTriggerForceKernel( void* triggerForceKernel );
182
183
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
184
       * Get trigger Force Kernel
185
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
186
       * @return triggerForceKernel kernel to calculate force
187
188
189
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
190
      void* getTriggerForceKernel( void ) const;
191
192
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
193
       * Set trigger Energy Kernel
194
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
195
       * @param triggerEnergyKernel kernel to calculate force
196
197
198
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
199
      void setTriggerEnergyKernel( void* triggerEnergyKernel );
200
201
202
203
      
      /** 
       * Get trigger Energy Kernel
       *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
204
       * @return triggerEnergyKernel kernel to calculate force
205
206
207
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
208
      void* getTriggerEnergyKernel( void ) const;
209
210
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
211
       * Get BrookBondParameters for harmonic bond force
212
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
213
214
215
216
       * @return brookBondParameters for BrookBondParameters for harmonic bond force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
217
      BrookBondParameters* getHarmonicBondForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
218
219
220
221
222
      
      /** 
       * Set BrookBondParameters for harmonic bond force
       * 
       * @param brookBondParameters BrookBondParameters for harmonic bond force
223
224
225
226
227
228
229
       *
       * @return DefaultReturnValue
       *
       */
      
      int setHarmonicBondForceParameters( BrookBondParameters* brookBondParameters );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
230
231
232
233
234
235
236
      /** 
       * Get BrookBondParameters for harmonic angle force
       * 
       * @return brookBondParameters for BrookBondParameters for harmonic angle force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
237
      BrookBondParameters* getHarmonicAngleForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
238
      
239
240
241
242
243
244
245
246
247
248
249
250
      /** 
       * 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
251
252
253
254
255
256
       * Get BrookBondParameters for periodic torsion force
       * 
       * @return brookBondParameters for BrookBondParameters for periodic torsion force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
257
      BrookBondParameters* getPeriodicTorsionForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
258
259
260

      /** 
       * Set BrookBondParameters for periodic torsion force
261
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
262
       * @param brookBondParameters for periodic torsion force
263
264
265
266
267
268
269
270
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setPeriodicTorsionForceParameters( BrookBondParameters* brookBondParameters );
      
      /** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
271
       * Get BrookBondParameters for RB torsion force
272
       * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
273
274
275
276
       * @return brookBondParameters for BrookBondParameters for RB torsion force
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
277
      BrookBondParameters* getRBTorsionForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
278
279
280
281
282

      /** 
       * Set BrookBondParameters for RB torsion force
       * 
       * @param brookBondParameters brookBondParameters for RB torsion force
283
284
285
286
287
288
289
       *
       * @return  DefaultReturnValue
       *
       */
      
      int setRBTorsionForceParameters( BrookBondParameters* brookBondParameters );
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
290
291
292
293
294
295
296
      /** 
       * Get BrookBondParameters for LJ 14 forces
       * 
       * @return brookBondParameters for BrookBondParameters for LJ 14 forces
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
297
      BrookBondParameters* getNonBonded14ForceParameters( void ) const;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
298

299
300
301
302
      /** 
       * Set BrookBondParameters for LJ 14 force
       * 
       * @param brookBondParameters brookBondParameters for LJ 14 force
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
303
304
       * @param lj14Scale           LJ 14 scale factor
       * @param coulomb14Scale        Coulomb 14 scale factor
305
306
307
308
309
       *
       * @return  DefaultReturnValue
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
310
      int setNonBonded14ForceParameters( BrookBondParameters* brookBondParameters, double lj14Scale, double coulomb14Scale );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
311
312
313
314
315
316
317
318
319
      
      /** 
       * Get positions stream
       * 
       * @return particle positions 
       *
       */
         
      BrookStreamImpl* getParticlePositions( void );
320
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
321
322
323
324
325
326
327
328
329
330
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
      /** 
       * 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 );

372
373
   private:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
374
375
376
      static const int DefaultReturnValue = 0;
      static const int ErrorReturnValue   = -1;

377
378
379
380
381
382
      enum BondParameterIndices { HarmonicBondIndex, HarmonicAngleIndex, PeriodicTorsionForceIndex, RbTorsionForceIndex, LJ14Index, LastBondForce };

      // log file reference

      FILE* _log;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
383
384
385
      int _particleStreamWidth;
      int _particleStreamSize;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
386
       // number of particles
387

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
388
       int _numberOfParticles;
389
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
390
391
392
       double _lj14Scale;
       double _coulomb14Scale;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
393
       // Brook bonded, nonbonded, Gbsa
394
395
396

       BrookBonded* _brookBonded;
       BrookNonBonded* _brookNonBonded;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
397
       BrookGbsa* _brookGbsa;
398

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
399
400
401
       void* _triggerForceKernel;
       void* _triggerEnergyKernel;

402
403
       BrookBondParameters* _bondParameters[LastBondForce];

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
404
405
406
407
408
409
       // context-related fields

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

410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
       // 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
430
431
432
433
434
435
436
437
438
439
440
      /** 
       * Get BrookBondParameters at specified index
       * 
       * @param   index
       *
       * @return  BrookBondParameters* object
       *
       */
      
      BrookBondParameters* _getBondParameters( BondParameterIndices index ) const;
      
441
442
443
444
445
};

} // namespace OpenMM

#endif /* OPENMM_BROOK_INTERFACE_H_ */