OpenMM_CWrapper.h 16.9 KB
Newer Older
1
/* --------------------------------------------------------------------------
2
 *     OpenMM(tm) PROTOTYPE C wrapper function declarations (June 2009)
3
4
 * --------------------------------------------------------------------------
 * This header should be included by a C main program that would like to
5
 * access the OpenMM API through the C wrappers. Please note that this is an
6
 * experimental prototype, not an official part of OpenMM; it is just an 
7
8
9
 * example of how the C++ API can be wrapped for access from C.
 *
 * This set of wrappers is incomplete. If you add more, please send them
Michael Sherman's avatar
Michael Sherman committed
10
11
 * to us. Improvements in substance and style would also be greatly 
 * appreciated. If you have ideas (or better code) please post to the OpenMM 
12
13
 * forum on simtk.org/home/openmm or if you're shy you can email Michael 
 * Sherman at msherman@stanford.edu.
14
15
16
17
18
19
20
21
22
 *
 * Note: this header must be includable in both ANSI C and C++ code, because
 * the function declarations must be common to both the users and the
 * implementing code, which is in C++.
 * -------------------------------------------------------------------------- */

#ifndef OPENMM_CWRAPPER_H_
#define OPENMM_CWRAPPER_H_

23
24
25
26
/* Declare incomplete types corresponding to each of the OpenMM objects that
 * we want to make available. This allows us to have unique pointer types
 * for each object to maintain some semblance of type safety.
 */
Michael Sherman's avatar
Michael Sherman committed
27

28
/* These first three types represent the three OpenMM runtime objects that
29
30
 * must persist from call to call during an OpenMM-powered simulation. 
 * OpenMM_Integrator is the generic type of all Integrator objects. */
Michael Sherman's avatar
Michael Sherman committed
31
typedef struct OpenMM_System_s      OpenMM_System;
32
typedef struct OpenMM_Integrator_s  OpenMM_Integrator;
Michael Sherman's avatar
Michael Sherman committed
33
typedef struct OpenMM_Context_s     OpenMM_Context;
34

35
36
37
/* This is the generic type of all Force objects. */
typedef struct OpenMM_Force_s       OpenMM_Force;

38
39
40
41
42
43
44
45
46
47
/* This struct collects all the runtime object pointers together to 
 * facilitate use of an opaque handle in high-level C or Fortran code 
 * that doesn't have (or want) access to OpenMM declarations. This
 * does not have an equivalent in the OpenMM C++ API. */
typedef struct OpenMM_RuntimeObjects_s {
    OpenMM_System*      system;
    OpenMM_Integrator*  integrator;
    OpenMM_Context*     context;
} OpenMM_RuntimeObjects;

48
49
50
51
typedef double                          OpenMM_Vec3[3];
typedef struct OpenMM_Vec3Array_s       OpenMM_Vec3Array;
typedef struct OpenMM_BondArray_s   OpenMM_BondArray;
typedef struct OpenMM_String_s          OpenMM_String;
Michael Sherman's avatar
Michael Sherman committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

/*
 * OpenMM_Integrator is the generic type for all integrators. Cast your
 * specific pointer type to the generic one for communication with functions
 * that take type OpenMM_Integrator.
 */
typedef struct OpenMM_VerletIntegrator_s        OpenMM_VerletIntegrator;
typedef struct OpenMM_LangevinIntegrator_s      OpenMM_LangevinIntegrator;

/*
 * OpenMM_Force is the generic type for all Force objects. Create the
 * concrete Force object and then cast it to the generic type.
 */
typedef struct OpenMM_NonbondedForce_s          OpenMM_NonbondedForce;
typedef struct OpenMM_GBSAOBCForce_s            OpenMM_GBSAOBCForce;
67
68
69
typedef struct OpenMM_HarmonicBondForce_s       OpenMM_HarmonicBondForce;
typedef struct OpenMM_HarmonicAngleForce_s      OpenMM_HarmonicAngleForce;
typedef struct OpenMM_PeriodicTorsionForce_s    OpenMM_PeriodicTorsionForce;
Michael Sherman's avatar
Michael Sherman committed
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

typedef enum {
    OpenMM_NonbondedForce_NoCutoff            = 0,
    OpenMM_NonbondedForce_CutoffNonPeriodic   = 1,
    OpenMM_NonbondedForce_CutoffPeriodic      = 2,
    OpenMM_NonbondedForce_Ewald               = 3
} OpenMM_NonbondedForce_NonbondedMethod;


typedef struct OpenMM_State_s               OpenMM_State;
typedef enum {
    OpenMM_State_Positions   = 1, 
    OpenMM_State_Velocities  = 2,
    OpenMM_State_Forces      = 4,
    OpenMM_State_Energy      = 8,
    OpenMM_State_Parameters  = 16
} OpenMM_State_DataType;

/* Conversion constants from openmm/Units.h */

/*
 * The number of nanometers in an Angstrom.
 */
static const double OpenMM_NmPerAngstrom = 0.1;
/*
 * The number of Angstroms in a nanometer.
 */
static const double OpenMM_AngstromsPerNm = 10.0;
/*
 * The number of picoseconds in a femtosecond.
 */
static const double OpenMM_PsPerFs = 0.001;
/*
 * The number of femtoseconds in a picosecond.
 */
static const double OpenMM_FsPerPs = 1000.0;
/*
 * The number of kJ in a kcal.
 */
static const double OpenMM_KJPerKcal = 4.184;
/*
 * The number of kcal in a kJ.
 */
static const double OpenMM_KcalPerKJ = 1.0/4.184;
/*
 * The number of radians in a degree.
 */
static const double OpenMM_RadiansPerDegree = 3.1415926535897932385/180.0;
/*
 * The number of degrees in a radian.
 */
static const double OpenMM_DegreesPerRadian = 180.0/3.1415926535897932385;
/*
 * This is the conversion factor that takes you from a van der Waals radius
 * (defined as 1/2 the minimum energy separation) to the related Lennard Jones 
 * "sigma" parameter (defined as the zero crossing separation). The value
 * is 2*pow(2, -1/6).
 */
static const double OpenMM_SigmaPerVdwRadius = 1.78179743628068;


#if defined(__cplusplus)
extern "C" {
#endif

/* OpenMM_Vec3Array */
extern OpenMM_Vec3Array*    OpenMM_Vec3Array_create(int n);
extern int                  OpenMM_Vec3Array_size(const OpenMM_Vec3Array*);
extern void                 OpenMM_Vec3Array_resize(OpenMM_Vec3Array*, int n);
extern void                 OpenMM_Vec3Array_destroy(OpenMM_Vec3Array*);
extern void                 OpenMM_Vec3Array_append(OpenMM_Vec3Array*, const double[3]);
extern void                 OpenMM_Vec3Array_get(const OpenMM_Vec3Array*, int i, double[3]);
142
143
144
extern void                 OpenMM_Vec3Array_getScaled(const OpenMM_Vec3Array*, int i, double s, double[3]);
extern void                 OpenMM_Vec3Array_set(OpenMM_Vec3Array*, int i, const double[3]);
extern void                 OpenMM_Vec3Array_setScaled(OpenMM_Vec3Array*, int i, const double[3], double s);
Michael Sherman's avatar
Michael Sherman committed
145
extern void                 OpenMM_Vec3_scale(const double in[3], double s, double out[3]);
Michael Sherman's avatar
Michael Sherman committed
146

147
148
149
150
151
152
153
154
155
/* OpenMM_BondArray */
extern OpenMM_BondArray*    OpenMM_BondArray_create(int n);
extern int                  OpenMM_BondArray_size(const OpenMM_BondArray*);
extern void                 OpenMM_BondArray_resize(OpenMM_BondArray*, int n);
extern void                 OpenMM_BondArray_destroy(OpenMM_BondArray*);
extern void                 OpenMM_BondArray_append(OpenMM_BondArray*, int p1, int p2);
extern void                 OpenMM_BondArray_get(const OpenMM_BondArray*, int i, int* p1, int* p2);
extern void                 OpenMM_BondArray_set(OpenMM_BondArray*, int i, int p1, int p2);

Michael Sherman's avatar
Michael Sherman committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* OpenMM_String */
extern OpenMM_String*       OpenMM_String_create(const char* init);
extern void                 OpenMM_String_destroy(OpenMM_String*);
extern int                  OpenMM_String_length(const OpenMM_String*);
extern const char*          OpenMM_String_getAsC(const OpenMM_String*);
extern void                 OpenMM_String_get(const OpenMM_String*, char* buf, int buflen);
extern void                 OpenMM_String_set(OpenMM_String*, const char* buf);

/* OpenMM::Platform */
extern void OpenMM_Platform_loadPluginsFromDirectory(const char*);
extern const char* OpenMM_Platform_getDefaultPluginsDirectory();

/* OpenMM::System */
extern OpenMM_System* OpenMM_System_create();
170
extern void           OpenMM_System_destroy (OpenMM_System*);
Michael Sherman's avatar
Michael Sherman committed
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
extern int    OpenMM_System_addParticle(OpenMM_System*, double mass);
extern void   OpenMM_System_setParticleMass(OpenMM_System*, int ix, double mass);
extern double OpenMM_System_getParticleMass(const OpenMM_System*, int ix);

extern int  OpenMM_System_addConstraint(OpenMM_System*, int p1, int p2, double distance);
extern void OpenMM_System_setConstraintParameters(OpenMM_System*, int ix, 
                                                  int p1, int p2, double distance);
extern void OpenMM_System_getConstraintParameters(const OpenMM_System*, int ix, 
                                                  int* p1, int* p2, double* distance);

extern int                 OpenMM_System_addForce(OpenMM_System*, OpenMM_Force*);
extern OpenMM_Force*       OpenMM_System_updForce(OpenMM_System*, int ix);
extern const OpenMM_Force* OpenMM_System_getForce(const OpenMM_System*, int ix);

extern int OpenMM_System_getNumParticles(const OpenMM_System*);
extern int OpenMM_System_getNumConstraints(const OpenMM_System*);
extern int OpenMM_System_getNumForces(const OpenMM_System*);
Michael Sherman's avatar
Michael Sherman committed
189
190
191
192
193
194

/* OpenMM::NonbondedForce */
extern OpenMM_NonbondedForce* OpenMM_NonbondedForce_create();
extern void OpenMM_NonbondedForce_destroy              (OpenMM_NonbondedForce*);
extern void OpenMM_NonbondedForce_setNonbondedMethod   (OpenMM_NonbondedForce*, 
                                                        OpenMM_NonbondedForce_NonbondedMethod);
195
196
extern OpenMM_NonbondedForce_NonbondedMethod
            OpenMM_NonbondedForce_getNonbondedMethod   (const OpenMM_NonbondedForce*);
Michael Sherman's avatar
Michael Sherman committed
197
extern void OpenMM_NonbondedForce_setCutoffDistance    (OpenMM_NonbondedForce*, double);
198
extern double OpenMM_NonbondedForce_getCutoffDistance  (const OpenMM_NonbondedForce*);
Michael Sherman's avatar
Michael Sherman committed
199
200
extern void OpenMM_NonbondedForce_setPeriodicBoxVectors(OpenMM_NonbondedForce*, 
                                                        const OpenMM_Vec3,const OpenMM_Vec3,const OpenMM_Vec3);
201
202
203
extern void OpenMM_NonbondedForce_getPeriodicBoxVectors(const OpenMM_NonbondedForce*, 
                                                        OpenMM_Vec3, OpenMM_Vec3, OpenMM_Vec3);
extern int  OpenMM_NonbondedForce_addParticle(OpenMM_NonbondedForce*,
Michael Sherman's avatar
Michael Sherman committed
204
205
206
                                              double charge,
                                              double sigmaInNm,
                                              double vdwEnergyInKJ);
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
extern void OpenMM_NonbondedForce_setParticleParameters(OpenMM_NonbondedForce*, int index,
                                                        double charge,
                                                        double sigmaInNm,
                                                        double vdwEnergyInKJ);
extern void OpenMM_NonbondedForce_getParticleParameters(const OpenMM_NonbondedForce*, int index,
                                                        double* charge,
                                                        double* sigmaInNm,
                                                        double* vdwEnergyInKJ);
extern int OpenMM_NonbondedForce_getNumParticles(const OpenMM_NonbondedForce*);
extern int OpenMM_NonbondedForce_getNumExceptions(const OpenMM_NonbondedForce*);
extern int OpenMM_NonbondedForce_addException(OpenMM_NonbondedForce*, int p1, int p2, 
                                              double chargeProd, double sigma, double epsilon);
extern void OpenMM_NonbondedForce_getExceptionParameters(const OpenMM_NonbondedForce*, int index, int* p1, int* p2, 
                                                         double* chargeProd, double* sigma, double* epsilon);
extern void OpenMM_NonbondedForce_setExceptionParameters(OpenMM_NonbondedForce*, int index, int p1, int p2, 
                                                         double chargeProd, double sigma, double epsilon);
extern void OpenMM_NonbondedForces_createExceptionsFromBonds(OpenMM_NonbondedForce*, const OpenMM_BondArray*,
                                                             double coulomb14Scale, double lj14Scale);

Michael Sherman's avatar
Michael Sherman committed
226
227
228
229
230
231

/* OpenMM::GBSAOBCForce */
extern OpenMM_GBSAOBCForce* OpenMM_GBSAOBCForce_create();
extern void OpenMM_GBSAOBCForce_destroy             (OpenMM_GBSAOBCForce*);
extern void OpenMM_GBSAOBCForce_setSolventDielectric(OpenMM_GBSAOBCForce*, double);
extern void OpenMM_GBSAOBCForce_setSoluteDielectric (OpenMM_GBSAOBCForce*, double);
Michael Sherman's avatar
Michael Sherman committed
232
extern int  OpenMM_GBSAOBCForce_addParticle(OpenMM_GBSAOBCForce*,
Michael Sherman's avatar
Michael Sherman committed
233
234
235
236
                                            double charge,
                                            double radiusInNm,
                                            double scalingFactor);

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
/* OpenMM::HarmonicBondForce */
extern OpenMM_HarmonicBondForce* OpenMM_HarmonicBondForce_create();
extern void OpenMM_HarmonicBondForce_destroy(OpenMM_HarmonicBondForce*);
extern int OpenMM_HarmonicBondForce_getNumBonds(const OpenMM_HarmonicBondForce*);
extern int OpenMM_HarmonicBondForce_addBond(OpenMM_HarmonicBondForce*, int p1, int p2, double len, double k);
extern void OpenMM_HarmonicBondForce_getBondParameters(const OpenMM_HarmonicBondForce*, int ix, int* p1, int* p2, double* len, double* k);
extern void OpenMM_HarmonicBondForce_setBondParameters(OpenMM_HarmonicBondForce*, int ix, int p1, int p2, double len, double k);

/* OpenMM::HarmonicAngleForce */
extern OpenMM_HarmonicAngleForce* OpenMM_HarmonicAngleForce_create();
extern void OpenMM_HarmonicAngleForce_destroy(OpenMM_HarmonicAngleForce*);
extern int OpenMM_HarmonicAngleForce_getNumAngles(const OpenMM_HarmonicAngleForce*);
extern int OpenMM_HarmonicAngleForce_addAngle(OpenMM_HarmonicAngleForce*, int p1, int p2, int p3, double angle, double k);
extern void OpenMM_HarmonicAngleForce_getAngleParameters(const OpenMM_HarmonicAngleForce*, int ix, int* p1, int* p2, int* p3, double* angle, double* k);
extern void OpenMM_HarmonicAngleForce_setAngleParameters(OpenMM_HarmonicAngleForce*, int ix, int p1, int p2, int p3, double angle, double k);

/* OpenMM::PeriodicTorsionForce */
extern OpenMM_PeriodicTorsionForce* OpenMM_PeriodicTorsionForce_create();
extern void OpenMM_PeriodicTorsionForce_destroy(OpenMM_PeriodicTorsionForce*);
extern int OpenMM_PeriodicTorsionForce_getNumTorsions(const OpenMM_PeriodicTorsionForce*);
extern int OpenMM_PeriodicTorsionForce_addTorsion(OpenMM_PeriodicTorsionForce*, int p1, int p2, int p3, int p4,
                                                int periodicity, double phase, double k);
extern void OpenMM_PeriodicTorsionForce_getTorsionParameters(const OpenMM_PeriodicTorsionForce*, int ix, int* p1, int* p2, int* p3, int* p4,
                                                           int* periodicity, double* phase, double* k);
extern void OpenMM_PeriodicTorsionForce_setTorsionParameters(OpenMM_PeriodicTorsionForce*, int ix, int p1, int p2, int p3, int p4,
                                                           int periodicity, double phase, double k);

Michael Sherman's avatar
Michael Sherman committed
264
265
266
267
268
269
270
271
/* OpenMM::Integrator */
extern void OpenMM_Integrator_step(OpenMM_Integrator*, int numSteps);
extern void OpenMM_Integrator_destroy(OpenMM_Integrator*);
/* OpenMM::VerletIntegrator */
extern OpenMM_VerletIntegrator* OpenMM_VerletIntegrator_create(double stepSzInPs);
extern void                     OpenMM_VerletIntegrator_destroy(OpenMM_VerletIntegrator*);
extern void                     OpenMM_VerletIntegrator_step(OpenMM_VerletIntegrator*, int numSteps);
/* OpenMM::LangevinIntegrator */
272
extern OpenMM_LangevinIntegrator* OpenMM_LangevinIntegrator_create(double temperature, double frictionInPerPs, double stepSzInPs);
273
extern void                       OpenMM_LangevinIntegrator_destroy(OpenMM_LangevinIntegrator*);
Michael Sherman's avatar
Michael Sherman committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
extern void                       OpenMM_LangevinIntegrator_step(OpenMM_LangevinIntegrator*, int numSteps);

/* OpenMM::Context */
extern OpenMM_Context*  OpenMM_Context_create(OpenMM_System*, OpenMM_Integrator*);
extern void             OpenMM_Context_destroy(OpenMM_Context*);
extern void             OpenMM_Context_setPositions(OpenMM_Context*, const OpenMM_Vec3Array*);
extern void             OpenMM_Context_setVelocities(OpenMM_Context*, const OpenMM_Vec3Array*);
extern OpenMM_State*    OpenMM_Context_createState(const OpenMM_Context*, int types);
extern const char*      OpenMM_Context_getPlatformName(const OpenMM_Context*);

/* OpenMM::State */
extern void     OpenMM_State_destroy(OpenMM_State*);
extern double   OpenMM_State_getTime(const OpenMM_State*);
extern double   OpenMM_State_getPotentialEnergy(const OpenMM_State*);
extern double   OpenMM_State_getKineticEnergy(const OpenMM_State*);
extern const OpenMM_Vec3Array* OpenMM_State_getPositions(const OpenMM_State*);
extern const OpenMM_Vec3Array* OpenMM_State_getVelocities(const OpenMM_State*);

292
293
294
295
296
297
298
299
300
301
302
/* OpenMM_Runtime_Objects */
extern OpenMM_RuntimeObjects* OpenMM_RuntimeObjects_create();
extern void                   OpenMM_RuntimeObjects_clear(OpenMM_RuntimeObjects*);
extern void                   OpenMM_RuntimeObjects_destroy(OpenMM_RuntimeObjects*);
extern void                   OpenMM_RuntimeObjects_setSystem(OpenMM_RuntimeObjects*, OpenMM_System*);
extern void                   OpenMM_RuntimeObjects_setIntegrator(OpenMM_RuntimeObjects*, OpenMM_Integrator*);
extern void                   OpenMM_RuntimeObjects_setContext(OpenMM_RuntimeObjects*, OpenMM_Context*);
extern OpenMM_System*         OpenMM_RuntimeObjects_getSystem(OpenMM_RuntimeObjects*);
extern OpenMM_Integrator*     OpenMM_RuntimeObjects_getIntegrator(OpenMM_RuntimeObjects*);
extern OpenMM_Context*        OpenMM_RuntimeObjects_getContext(OpenMM_RuntimeObjects*);

Michael Sherman's avatar
Michael Sherman committed
303
304
305
306
307

#if defined(__cplusplus)
}
#endif

308
#endif /*OPENMM_CWRAPPER_H_*/
Michael Sherman's avatar
Michael Sherman committed
309
310
311
312