OpenMMBrookInterface.h 12.7 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
      /** 
       * 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;

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

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

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

331
332
333
334
      /** 
       * Set BrookBondParameters for LJ 14 force
       * 
       * @param brookBondParameters brookBondParameters for LJ 14 force
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
335
336
       * @param lj14Scale           LJ 14 scale factor
       * @param coulomb14Scale        Coulomb 14 scale factor
337
338
339
340
341
       *
       * @return  DefaultReturnValue
       *
       */
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
342
      int setNonBonded14ForceParameters( BrookBondParameters* brookBondParameters, double lj14Scale, double coulomb14Scale );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
343
344
345
346
347
348
349
350
351
      
      /** 
       * Get positions stream
       * 
       * @return particle positions 
       *
       */
         
      BrookStreamImpl* getParticlePositions( void );
352
      
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
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
397
398
399
400
401
402
403
      /** 
       * 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 );

404
405
   private:
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
406
407
408
      static const int DefaultReturnValue = 0;
      static const int ErrorReturnValue   = -1;

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

      // log file reference

      FILE* _log;

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

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

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
420
       int _numberOfParticles;
421
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
422
423
424
       double _lj14Scale;
       double _coulomb14Scale;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
425
       // Brook bonded, nonbonded, Gbsa
426

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

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

434
435
       BrookBondParameters* _bondParameters[LastBondForce];

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

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

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

} // namespace OpenMM

#endif /* OPENMM_BROOK_INTERFACE_H_ */