ValidateOpenMM.h 12.3 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
#ifndef VALIDATE_OPENMM_H_
#define VALIDATE_OPENMM_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                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
 *                                                                            *
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
 * -------------------------------------------------------------------------- */

#include "OpenMM.h"
#include "../../../platforms/reference/include/ReferencePlatform.h"
#include "openmm/Context.h"
#include "openmm/System.h"

// free-energy plugin includes

//#define	INCLUDE_FREE_ENERGY_PLUGIN
#ifdef INCLUDE_FREE_ENERGY_PLUGIN
#include "../../../plugins/freeEnergy/openmmapi/include/OpenMMFreeEnergy.h"
#include "../../../plugins/freeEnergy/openmmapi/include/openmm/freeEnergyKernels.h"
41
42
//#include "../../../plugins/freeEnergy/platforms/reference/include/ReferenceFreeEnergyPlatform.h"
#include "../../../plugins/freeEnergy/platforms/reference/include/ReferenceFreeEnergyKernelFactory.h"
43
44
45
46
47
#endif

#include <sstream>
#include <typeinfo>

Peter Eastman's avatar
Peter Eastman committed
48
#include <limits>
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

namespace OpenMM {

typedef std::map< std::string, int > StringIntMap;
typedef StringIntMap::iterator StringIntMapI;
typedef StringIntMap::const_iterator StringIntMapCI;

typedef std::map< std::string, double > StringDoubleMap;
typedef StringDoubleMap::iterator StringDoubleMapI;
typedef StringDoubleMap::const_iterator StringDoubleMapCI;

typedef std::map< std::string, unsigned int > StringUIntMap;
typedef StringUIntMap::iterator StringUIntMapI;
typedef StringUIntMap::const_iterator StringUIntMapCI;

typedef std::vector< std::string > StringVector;
typedef StringVector::iterator StringVectorI;
typedef StringVector::const_iterator StringVectorCI;

typedef std::vector< int > IntVector;
typedef IntVector::iterator IntVectorI;
typedef IntVector::const_iterator IntVectorCI;

typedef std::map< std::string, std::vector<std::string> > StringStringVectorMap;
typedef StringStringVectorMap::iterator StringStringVectorMapI;
typedef StringStringVectorMap::const_iterator StringStringVectorMapCI;

/**
 * Base class w/ common functionality 
 */
class ValidateOpenMM {
public:

    ValidateOpenMM( void );
    ~ValidateOpenMM();

    // force names
    
    static const std::string HARMONIC_BOND_FORCE;
    static const std::string HARMONIC_ANGLE_FORCE;
    static const std::string PERIODIC_TORSION_FORCE;
    static const std::string RB_TORSION_FORCE;
    
    static const std::string NB_FORCE;
    static const std::string NB_SOFTCORE_FORCE;
    
    static const std::string NB_EXCEPTION_FORCE;
    static const std::string NB_EXCEPTION_SOFTCORE_FORCE;
    
    static const std::string GBSA_OBC_FORCE;
    static const std::string GBSA_OBC_SOFTCORE_FORCE;
    
    static const std::string GBVI_FORCE;
    static const std::string GBVI_SOFTCORE_FORCE;

    static const std::string CM_MOTION_REMOVER;
    static const std::string ANDERSEN_THERMOSTAT;
    static const std::string CUSTOM_BOND_FORCE;
    static const std::string CUSTOM_EXTERNAL_FORCE;
    static const std::string CUSTOM_NONBONDED_FORCE;

    /**
Peter Eastman's avatar
Peter Eastman committed
111
     * Return true if input number is nan or infinity
112
113
114
     *
     * @param number   number to test
     *
Peter Eastman's avatar
Peter Eastman committed
115
     * @return true if number is nan or infinity
116
117
     */
    
Peter Eastman's avatar
Peter Eastman committed
118
    static int isNanOrInfinity( double number );
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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
372
373
    
    /**
     * Get force name
     * 
     * @param force      OpenMM system force 
     *
     * @return force name or "NA" if force is not recognized
     */
    std::string getForceName(const Force& force ) const;

    /**
     * Copy force 
     * 
     * @param force      OpenMM system force to copy 
     *
     * @return force or NULL if not recognized
     */
    Force* copyForce(const Force& force) const;

    /**
     * Get copy of input system, but omit forces
     * 
     * @param systemToCopy   system to copy
     *
     * @return copy of system but w/o forces
     */
    System* copySystemExcludingForces( const System& systemToCopy ) const;

    /**
     *
     * Set the velocities/positions of context2 to those of context1
     * 
     * @param context1                 context1 
     * @param context2                 context2 
     *
     * @return 0
     */
    void synchContexts( const Context& context1, Context& context2 ) const;
    
    /**
     *
     * Get log FILE* reference
     * 
     * @return log
     *
     */
    FILE* getLog( ) const;
    
    /**
     *
     * Set log FILE* reference
     * 
     * @param log  log
     *
     */
    void setLog( FILE* log );
    
    /**---------------------------------------------------------------------------------------
    
       Copy constraints
    
       @param systemToCopy         system whose constraints are to be copied
       @param system               system to add constraints to
       @param log                  log file pointer -- may be NULL
    
       --------------------------------------------------------------------------------------- */
    
    void copyConstraints( const System& systemToCopy, System* system, FILE* log = NULL ) const;
    
    /**---------------------------------------------------------------------------------------
    
       Get force dependencies
    
       @param forceName            force to check if there exist any dependencies
       @param returnVector         vector of forces the input force is dependent on (example: GBSAOBC force requires Nonbonded force since
                                   on Cuda platofrm they are computed in same loop and hence are inseparable)
    
       --------------------------------------------------------------------------------------- */
    
    void getForceDependencies( std::string forceName, StringVector& returnVector ) const;
    
    /**
     * Write masses to parameter file
     *
     * @param filePtr    file to write masses to
     * @param system     write masses in system
     */
    
    void writeMasses( FILE* filePtr, const System& system ) const;
    
    /**
     * Write constraints to parameter file
     *
     * @param filePtr    file to write constraints to
     * @param system     write constraints in system
     *
     */
    
    void writeConstraints( FILE* filePtr, const System& system ) const;
    
    /**
     * Write harmonicBondForce parameters to file
     *
     * @param filePtr                file to write forces to
     * @param harmonicBondForce     write harmonicBondForce parameters
     *
     */
    
    void writeHarmonicBondForce( FILE* filePtr, const HarmonicBondForce& harmonicBondForce ) const;

    /**
     * Write harmonicAngleForce parameters to file
     *
     * @param filePtr                file to write forces to
     * @param harmonicAngleForce     write harmonicAngleForce parameters
     *
     */
    
    void writeHarmonicAngleForce( FILE* filePtr, const HarmonicAngleForce& harmonicAngleForce ) const;
    
    /**
     * Write rbTorsionForce parameters to file
     *
     * @param filePtr                file to write forces to
     * @param rbTorsionForce         write rbTorsionForce parameters
     *
     */
    
    void writeRbTorsionForce( FILE* filePtr, const RBTorsionForce& rbTorsionForce ) const;
    
    /**
     * Write periodicTorsionForce parameters to file
     *
     * @param filePtr                file to write forces to
     * @param periodicTorsionForce   write periodicTorsionForce parameters
     *
     */
    
    void writePeriodicTorsionForce( FILE* filePtr, const PeriodicTorsionForce& periodicTorsionForce ) const;
    
    /**
     * Write nonbonded parameters to file
     *
     * @param filePtr                file to write forces to
     * @param nonbondedForce         write nonbondedForce parameters
     *
     */
    
    void writeNonbondedForce( FILE* filePtr, const NonbondedForce & nonbondedForce ) const;
    
    /**
     * Write GBSAOBCForce parameters to file
     *
     * @param filePtr                file to write forces to
     * @param gbsaObcForce           write gbsaObcForce parameters
     *
     */
    
    void writeGbsaObcForce( FILE* filePtr, const GBSAOBCForce& gbsaObcForce ) const;
    
    /**
     * Write GBSA GB/VI Force parameters to file
     *
     * @param filePtr                file to write forces to
     * @param gbviObcForce           write gbviObcForce parameters
     *
     */
    
    void writeGBVIForce( FILE* filePtr, const GBVIForce& gbviForce ) const;
    
#ifdef INCLUDE_FREE_ENERGY_PLUGIN
    
    /**
     * Write nonbonded softcore parameters to file
     *
     * @param filePtr                file to write forces to
     * @param nonbondedForce         write nonbondedForce parameters
     */
    
    void writeNonbondedSoftcoreForce( FILE* filePtr, const NonbondedSoftcoreForce & nonbondedSoftcoreForce ) const;

    /**
     * Write GBSAOBCSoftcoreForce parameters to file
     *
     * @param filePtr                file to write forces to
     * @param gbsaObcForce           write gbsaObcForce parameters
     *
     */
    
    void writeGbsaObcSoftcoreForce( FILE* filePtr, const GBSAOBCSoftcoreForce& gbsaObcForce ) const;
    
    /**
     * Write GBSA GB/VI softcore force parameters to file
     *
     * @param filePtr                file to write forces to
     * @param gbviObcForce           write gbviObcForce parameters
     *
     */
    
    void writeGBVISoftcoreForce( FILE* filePtr, const GBVISoftcoreForce& gbviSoftcoreForce ) const;
    
#endif
    
    /**
     * Write coordinates, velocities, ... to file
     *
     * @param filePtr                file to write Vec3 entries to
     * @param vect3Array             write array of Vec3
     *
     */
    
    void writeVec3( FILE* filePtr, const std::vector<Vec3>& vect3Array ) const;
    
    /**
     * Write context info to file (positions, velocities, forces, energies)
     *
     * @param filePtr                file to write entries to
     * @param context                write context positions, velocities, forces, energies to file
     *
     */
    
    void writeContext( FILE* filePtr, const Context& context ) const;
    
    /**
     * Write integrator
     *
     * @param filePtr                file to write integrator info to
     * @param integrator             write integrator info (time step, seed, ... as applicable)
     *
     */
    
    void writeIntegrator( FILE* filePtr, const Integrator& integrator ) const;
    
    /**
     * Write parameter file
     * @param context                context whose entries are to be written to file
     * @param parameterFileName      file name
     *
     */
    
    void writeParameterFile( const Context& context, const std::string& parameterFileName ) const;
    
private:

    FILE* _log;

    // map of force dependencies (e.g., GBSAObc requires NB force on CudaPlatform)

    StringStringVectorMap _forceDependencies;
};


} // namespace OpenMM

#endif /*VALIDATE_OPENMM_H_*/