CpuImplicitSolvent.h 15.2 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

/* Portions copyright (c) 2006 Stanford University and Simbios.
 * Contributors: Pande Group
 *
 * 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.
 */

#ifndef __CpuImplicitSolvent_H__
#define __CpuImplicitSolvent_H__

#include "ImplicitSolventParameters.h"
29
#include <vector>
30
31
32

// ---------------------------------------------------------------------------------------

33
class OPENMM_EXPORT CpuImplicitSolvent {
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

   private:

      // used for direct calls 

      static CpuImplicitSolvent* _cpuImplicitSolvent;

      // parameters

      ImplicitSolventParameters* _implicitSolventParameters;

      // flag to signal whether ACE approximation
      // is to be included

      int _includeAceApproximation;

      // force index call 

      int _forceCallIndex;

      // work arrays

56
      std::vector<RealOpenMM> _bornForce;
57
58
59

      // Born radii and force

60
61
      std::vector<RealOpenMM> _bornRadii;
      std::vector<RealOpenMM> _tempBornRadii;
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

      // convert units for energy/force

      RealOpenMM _forceConversionFactor;
      RealOpenMM _energyConversionFactor;

      // Ed, 2007-04-27: Store the energy internally

      RealOpenMM _implicitSolventEnergy; 

      /**---------------------------------------------------------------------------------------
      
         Initialize data members -- potentially more than
         one constructor, so centralize intialization here
      
         --------------------------------------------------------------------------------------- */

      void _initializeDataMembers( void );

   protected:

      /**---------------------------------------------------------------------------------------
      
         Return implicitSolventBornForce, a work array of size _implicitSolventParameters->getNumberOfAtoms()*sizeof( RealOpenMM )
         On first call, memory for array is allocated if not set
      
         @return array
      
         --------------------------------------------------------------------------------------- */
      
92
      std::vector<RealOpenMM>& getBornForce( void );
93
94
95
96
97
98
99
100
101
102

      /**---------------------------------------------------------------------------------------
      
         Return Born radii temp work array of size=_implicitSolventParameters->getNumberOfAtoms()
         On first call, memory for array is allocated if not set
      
         @return array
      
         --------------------------------------------------------------------------------------- */
      
103
      std::vector<RealOpenMM>& getBornRadiiTemp( void );
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

      /**---------------------------------------------------------------------------------------
      
         Set energy 

         @param energy new energy
      
         ireturn SimTKOpenMMCommon::DefaultReturn
      
         --------------------------------------------------------------------------------------- */

		int setEnergy( RealOpenMM energy );

   public:

      /**---------------------------------------------------------------------------------------
      
         Constructor
      
         @param implicitSolventParameters    ImplicitSolventParameters reference
      
         @return CpuImplicitSolvent object
      
         --------------------------------------------------------------------------------------- */

       CpuImplicitSolvent( ImplicitSolventParameters* implicitSolventParameters );

      /**---------------------------------------------------------------------------------------
      
         Destructor
      
         --------------------------------------------------------------------------------------- */

137
      virtual ~CpuImplicitSolvent( );
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

      /**---------------------------------------------------------------------------------------
      
         Delete static _cpuImplicitSolvent object if set
      
         @return SimTKOpenMMCommon::DefaultReturn if _cpuImplicitSolvent was set; 
                 otherwise return SimTKOpenMMCommon::ErrorReturn
      
         --------------------------------------------------------------------------------------- */

      static int deleteCpuImplicitSolvent( void );

      /**---------------------------------------------------------------------------------------
      
         Set static member _cpuImplicitSolvent
      
         @return SimTKOpenMMCommon::DefaultReturn
      
         --------------------------------------------------------------------------------------- */

      static int setCpuImplicitSolvent( CpuImplicitSolvent* cpuImplicitSolvent );

      /**---------------------------------------------------------------------------------------
      
         Get static member cpuImplicitSolvent
      
         @return static member cpuImplicitSolvent
      
         --------------------------------------------------------------------------------------- */
      
      static CpuImplicitSolvent* getCpuImplicitSolvent( void );

      /**---------------------------------------------------------------------------------------
      
         Get number of atoms
      
         @return number of atoms
      
         --------------------------------------------------------------------------------------- */

		int getNumberOfAtoms( void ) const;

      /**---------------------------------------------------------------------------------------
      
         Get energy 
      
         @return energy
      
         --------------------------------------------------------------------------------------- */

		RealOpenMM getEnergy( void ) const;

      /**---------------------------------------------------------------------------------------
      
         Return ImplicitSolventParameters
      
         @return ImplicitSolventParameters
      
         --------------------------------------------------------------------------------------- */
      
      ImplicitSolventParameters* getImplicitSolventParameters( void ) const;

      /**---------------------------------------------------------------------------------------
      
         Set ImplicitSolventParameters
      
         @param ImplicitSolventParameters
      
         @return SimTKOpenMMCommon::DefaultReturn 
      
         --------------------------------------------------------------------------------------- */
      
      int setImplicitSolventParameters( ImplicitSolventParameters* implicitSolventParameters );
 
      /**---------------------------------------------------------------------------------------
      
         Return flag signalling whether AceApproximation for nonpolar term is to be included
      
         @return flag
      
         --------------------------------------------------------------------------------------- */

      int includeAceApproximation( void ) const;

      /**---------------------------------------------------------------------------------------
      
         Set flag indicating whether AceApproximation is to be included
      
         @param includeAceApproximation new includeAceApproximation value
      
         @return SimTKOpenMMCommon::DefaultReturn 
      
         --------------------------------------------------------------------------------------- */
      
      int setIncludeAceApproximation( int includeAceApproximation );

      /**---------------------------------------------------------------------------------------
      
         Return ForceConversionFactor for units
      
         @return ForceConversionFactor
      
         --------------------------------------------------------------------------------------- */
      
      RealOpenMM getForceConversionFactor(  void  ) const;

      /**---------------------------------------------------------------------------------------
      
         Set ForceConversionFactor
      
         @param ForceConversionFactor (units conversion)
      
         @return SimTKOpenMMCommon::DefaultReturn 
      
         --------------------------------------------------------------------------------------- */
      
      int setForceConversionFactor(  RealOpenMM forceConversionFactor  );

      /**---------------------------------------------------------------------------------------
      
         Return EnergyConversionFactor for units
      
         @return EnergyConversionFactor
      
         --------------------------------------------------------------------------------------- */
      
      RealOpenMM getEnergyConversionFactor( void  ) const;

      /**---------------------------------------------------------------------------------------
      
         Set EnergyConversionFactor
      
         @param EnergyConversionFactor (units conversion)
      
         @return SimTKOpenMMCommon::DefaultReturn 
      
         --------------------------------------------------------------------------------------- */
      
      int setEnergyConversionFactor( RealOpenMM energyConversionFactor );

      /**---------------------------------------------------------------------------------------
      
         Return ForceCallIndex -- number of times forces have been calculated
      
         @return ForceCallIndex
      
         --------------------------------------------------------------------------------------- */
      
      int getForceCallIndex( void ) const;
      
      /**---------------------------------------------------------------------------------------
      
         Increment ForceCallIndex
      
         @return incremented forceCallIndex
      
         --------------------------------------------------------------------------------------- */
      
      int incrementForceCallIndex( void );
      
      /**---------------------------------------------------------------------------------------
      
         Return Born radii: size = _implicitSolventParameters->getNumberOfAtoms()
         On first call, memory for array is allocated if not set
      
         @return array
      
         --------------------------------------------------------------------------------------- */
      
307
      std::vector<RealOpenMM>& getBornRadii( void );
308
309
310
311
312
313
314
315
316
      
      /**---------------------------------------------------------------------------------------
      
         Return Born radii: size = _implicitSolventParameters->getNumberOfAtoms()
      
         @return array
      
         --------------------------------------------------------------------------------------- */
      
317
      const std::vector<RealOpenMM>& getBornRadiiConst( void ) const;
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
      
      /**---------------------------------------------------------------------------------------
      
         Get Born energy and forces
      
         @param atomCoordinates   atomic coordinates
         @param partialCharges    partial charges
         @param forces            forces (output); if not set on input, then memory is allocated
         @param updateBornRadii   if set, then Born radii are updated for current configuration; 
                                  otherwise radii correspond to configuration from previous iteration
      
         @return SimTKOpenMMCommon::DefaultReturn 
      
         --------------------------------------------------------------------------------------- */
      
333
      int computeImplicitSolventForces( std::vector<OpenMM::RealVec>& atomCoordinates,
334
                                               const RealOpenMM* partialCharges,
335
                                               std::vector<OpenMM::RealVec>& forces, int updateBornRadii = 0 );
336
337
338
339
340
341
342
343
344
345
346
347
348
      
      /**---------------------------------------------------------------------------------------
      
         Get Born radii based on J. Phys. Chem. A V101 No 16, p. 3005 (Simbios)
      
         @param atomCoordinates   atomic coordinates dimension: [0-numberAtoms-1][0-2]
         @param bornRadii         output array of Born radii
         @param obcChain          output array of OBC chain derivative
      
         @return array of Born radii
      
         --------------------------------------------------------------------------------------- */
      
349
      virtual int computeBornRadii( std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<RealOpenMM>& bornRadii );
350
351
352
353
354
355
356
357
358
359
360
361
362
363
      
      /**---------------------------------------------------------------------------------------
      
         Get Born energy and forces based on J. Phys. Chem. A V101 No 16, p. 3005 (Simbios)
      
         @param bornRadii         Born radii
         @param atomCoordinates   atomic coordinates
         @param partialCharges    partial charges
         @param forces            forces
      
         @return force array
      
         --------------------------------------------------------------------------------------- */
      
364
      virtual int computeBornEnergyForces( std::vector<RealOpenMM>& bornRadii, std::vector<OpenMM::RealVec>& atomCoordinates,
365
                                           const RealOpenMM* partialCharges, std::vector<OpenMM::RealVec>& forces );
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
      
      /**---------------------------------------------------------------------------------------
      
         Get nonpolar solvation force constribution via ACE approximation
      
         @param implicitSolventParameters parameters
         @param bornRadii                 Born radii
         @param energy                    energy (output): value is incremented from input value 
         @param forces                    forces: values are incremented from input values
      
         @return SimTKOpenMMCommon::DefaultReturn
      
         --------------------------------------------------------------------------------------- */
      
      int computeAceNonPolarForce( const ImplicitSolventParameters* implicitSolventParameters,
381
382
                                   const std::vector<RealOpenMM>& bornRadii, RealOpenMM* energy,
                                   std::vector<RealOpenMM>& forces ) const;
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

      /**---------------------------------------------------------------------------------------
            
         Get string w/ state 
         
         @param title               title (optional)
            
         @return string containing state
            
         --------------------------------------------------------------------------------------- */
      
      std::string getStateString( const char* title ) const;
};

// ---------------------------------------------------------------------------------------

#endif // __CpuImplicitSolvent_H__