CpuGbsa.h 12.8 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
92
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
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

/* 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 __CpuGbsa_H__
#define __CpuGbsa_H__

#include "GbsaParameters.h"

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

class CpuGbsa {

   private:

      // used for direct calls from Gromacs

      static CpuGbsa* _cpuGbsa;

      // GBSA parameters

      GbsaParameters* _gbsaParameters;

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

      bool _includeAceApproximation;

      // work arrays and their accessors

      float* _gbsaBornForce;
      float* _gbsaBornRadiiTemp;

      float* getGbsaBornForce( void );
      float* getGbsaBornRadiiTemp( void );

      // initialize data members (more than
      // one constructor, so centralize intialization here)

      void initializeDataMembers( void );

      // convert units for energy/force

      float _forceConversionFactor;
      float _energyConversionFactor;

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

   public:

       // constructors/destructor

       CpuGbsa( int numberOfAtoms, const t_topology* top, FILE* log );
       CpuGbsa( GbsaParameters* gbsaParameters );

       ~CpuGbsa( );

      // override of new/delete

      static void* operator new( size_t size ); 
      static void  operator delete( void *p );

      static void* operator new[]( size_t size ); 
      static void  operator delete[]( void *p );

      // accessor for the energy

		float getEnergy( void ) const { return _gbsaEnergy; }

      // accessor for static member _cpuGbsa

      static int setCpuGbsa( CpuGbsa* cpuGbsa ){ _cpuGbsa = cpuGbsa; return 0; };
      static CpuGbsa* getCpuGbsa( void ){ return _cpuGbsa; };
      static int deleteCpuGbsa( void );

      // accessors for Gbsa parameters

      GbsaParameters* getGbsaParameters( void ) const { return _gbsaParameters; };
      int setGbsaParameters( GbsaParameters* gbsaParameters ){ _gbsaParameters = gbsaParameters; return 0; };
 
      // accessors ACE approximation

      bool includeAceApproximation( void ) const { return _includeAceApproximation; };
      int setIncludeAceApproximation( bool includeAceApproximation ){ _includeAceApproximation = includeAceApproximation; return 0; };

      // energy/force conversion factors

      float getForceConversionFactor(  void  ) const { return _forceConversionFactor;  };  
      float getEnergyConversionFactor( void  ) const { return _energyConversionFactor; };  

      int setForceConversionFactor(  float forceConversionFactor  ){ _forceConversionFactor  = forceConversionFactor;  return 0; };  
      int setEnergyConversionFactor( float energyConversionFactor ){ _energyConversionFactor = energyConversionFactor; return 0; };  

      /**---------------------------------------------------------------------------------------
      
         Get Born energy and forces based on J. Phys. Chem. A V101 No 16, p. 3005 (Simbios)
      
         @param atomCoordinates   atomic coordinates
         @param partialCharges    partial charges
         @param forces            forces (output); if not set on input, then memory is allocated
         @param log               if set, then print error messages to log file
      
         @return force array
      
         --------------------------------------------------------------------------------------- */
      
      static float** computeGbsaForces( const rvec *atomCoordinates, const float* partialCharges,
                                        float** forces, FILE* log );
      
      /**---------------------------------------------------------------------------------------
      
         Get Born radii based on J. Phys. Chem. A V101 No 16, p. 3005 (Simbios)
      
         @param atomCoordinates   atomic coordinates
         @param bornRadii         output array of Born radii
      
         @return array of Born radii
      
         --------------------------------------------------------------------------------------- */
      
      int computeBornRadii( const rvec *atomCoordinates, float* bornRadii );
      
      /**---------------------------------------------------------------------------------------
      
         Get exclusions for specific atom (Simbios)
      
         @param numberOfAtoms         number of atoms
         @param gbsaBondsArray        array of bonds
         @param atomI                 atom index of atom for which exclusions are to be set
         @param exclusionWorkArray    exclusionWorkArray[j] = 1, if atom j is to be excluded
                                      value may be null on input in which space is allocated
         @param previousIndex         previousIndex -- if < 0, then iniitialize all entries to 0
         @param log                   if set, then print error messages to log file
      
         @return 0
      
         --------------------------------------------------------------------------------------- */
      
      int getExclusionsForAtom( int numberOfAtoms, gbsaBonds** gbsaBondsArray,
                                int atomI, int* exclusionWorkArray, int previousIndex,
                                FILE* log ) const;

      /**---------------------------------------------------------------------------------------
      
         Set exclusions for specific atom (Simbios)
      
         @param gbsaBonds           gbsa bond
         @param setValue            set value
         @param exclusionWorkArray  exclusionWorkArray[j] = 1, if atom j is to be excluded
                                    value may be null on input in which space is allocated
         @param log                 if set, then print error messages to log file
      
         @return array of Born radii
      
         --------------------------------------------------------------------------------------- */
      
      int setExclusionValue( gbsaBonds* gbsaBonds, int setValue, int* exclusionWorkArray, FILE* log ) const;
         
      /**---------------------------------------------------------------------------------------
      
         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
      
         --------------------------------------------------------------------------------------- */
      
      float** computeBornEnergyForces( float* bornRadii, const rvec *atomCoordinates,
                                       const float* partialCharges, float** forces );
      
      /**---------------------------------------------------------------------------------------
      
         Get Born energy and forces based on J. Phys. Chem. A V101 No 16, p. 3005 (Simbios)
      
         @param top               GMX t_topology struct
         @param bornRadii         Born radii
         @param atomCoordinates   atomic coordinates
         @param partialCharges    atom partial charges
         @param energy            energy
         @param debugOn           enable debug
         @param debugAtomI        debug flag for atomI (outer loop atom)
         @param debugAtomJ        debug flag for atomJ (inner loop atom)
         @param debugReport       flag signalling what quantities are to be saved for comparisons
         @param saveLoopForces    flag signalling whether intermediate results for each loop
                                  are to be retained
         @param printOn           print flag 
         @param unsetDebugValue   ?
         @param numberOfDebugStreams 
                                  number of debug streams
         @param debugStreams      array of debug streams
         @param forces            force array (may be null)
         @param log               if set, then print error messages to log file
      
         @return 0 always; fixed value for G_pol in array 'gPolFixed'
      
         --------------------------------------------------------------------------------------- */
      
      float** computeBornEnergyForcesDebug( const t_topology* top, 
                                            float* bornRadii, const rvec *atomCoordinates,
                                            const float* partialCharges, float* energy,
                                            bool debugOn, int debugAtomI, int debugAtomJ,
                                            int debugReport, bool* saveLoopForces,
                                            bool printOn, float unsetDebugValue, int numberOfDebugStreams,
                                            float** debugStreams, float** forces, FILE* log );
 
      /**---------------------------------------------------------------------------------------
      
         Write Born energy and forces (Simbios)
      
         @param top               GMX t_topology struct
         @param atomCoordinates   atomic coordinates
         @param partialCharges    partial atom charges
         @param forces            force array
         @param gbsaResultsFileName  output file name
         @param log               if set, then print error messages to log file
      
         @return 0 always
      
         --------------------------------------------------------------------------------------- */
      
      int writeBornEnergyForces( const t_topology* top, const rvec *atomCoordinates,
                                 const float* partialCharges, float** forces,
                                 const char* gbsaResultsFileName, FILE* log ) const;

      /**---------------------------------------------------------------------------------------
      
         Print state to log file (Simbios)
      
         title             title (optional)
         log               print state to log file
      
         @return 0 always;
      
         --------------------------------------------------------------------------------------- */
      
      int logState( const char* title, FILE* log ) const;

      /**---------------------------------------------------------------------------------------
      
         Write Tinker xyz file (Simbios)
      
         @param numberOfAtoms      number of atoms
         @param atomCoordinates    atom coordinates
         @param header             header
         @param xyzFileName        output file name
         @param gbsaBondsArray     bond array -- used to print 1-2 bonds
         @param top                GMX t_topology struct
         @param log                if set, then print error messages to log file
      
         @return 0 unless error detected
      
         Currently no attempt is made to get the atom name/type to accurately 
         reflect the Tinker names/types. Rather method is used to output atoms
         in Gromacs order and then reorder those in a corresponding xyz file
         w/ the correct atom names/types so that they match the Gromacs order
         This makes it easier to compare results between Gromacs and Tinker
      
         --------------------------------------------------------------------------------------- */
      
      static int writeXyzFile( int numberOfAtoms, const rvec* atomCoordinates, 
                               const char* header, const char* xyzFileName,
                               gbsaBonds** gbsaBondsArray, const t_topology* top, FILE* log );
      
};

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

#endif // __CpuGbsa_H__