"plugins/rpmd/platforms/hip/src/HipRpmdKernelFactory.cpp" did not exist on "fa2c41927c878332b7f9bc5856025fd04f6d95ba"
Commit c97d87d0 authored by Michael Sherman's avatar Michael Sherman
Browse files

Some minor mods/additions to C wrappers (primarily for Fortran support).

parent e19d9e71
......@@ -99,7 +99,7 @@ myWritePDBFrame(int frameNum, double timeInPs, double energyInKcal,
{
int n;
// Write out in PDB format -- printf is so much more compact than formatted cout.
/* Write out in PDB format. */
printf("MODEL %d\n", frameNum);
printf("REMARK 250 time=%.3f ps; energy=%.3f kcal/mole\n",
timeInPs, energyInKcal);
......@@ -123,15 +123,15 @@ int main() {
double time, energy;
const char* platformName;
// Set up OpenMM data structures; returns OpenMM Platform name.
/* Set up OpenMM data structures; returns OpenMM Platform name. */
MyOpenMMData* omm = myInitializeOpenMM(atoms, Temperature, FrictionInPerPs,
SolventDielectric, SoluteDielectric,
StepSizeInFs, &platformName);
// Run the simulation:
// (1) Write the first line of the PDB file and the initial configuration.
// (2) Run silently entirely within OpenMM between reporting intervals.
// (3) Write a PDB frame when the time comes.
/* Run the simulation:
* (1) Write the first line of the PDB file and the initial configuration.
* (2) Run silently entirely within OpenMM between reporting intervals.
* (3) Write a PDB frame when the time comes. */
printf("REMARK Using OpenMM platform %s\n", platformName);
myGetOpenMMState(omm, WantEnergy, &time, &energy, atoms);
myWritePDBFrame(0, time, energy, atoms);
......@@ -142,10 +142,10 @@ int main() {
myWritePDBFrame(frame, time, energy, atoms);
}
// Clean up OpenMM data structures.
/* Clean up OpenMM data structures. */
myTerminateOpenMM(omm);
return 0; // Normal return from main.
return 0; /* Normal return from main. */
}
......
......@@ -32,9 +32,15 @@ using namespace OpenMM;
static inline Vec3 toVec3(const OpenMM_Vec3 src) {
return Vec3(src[0], src[1], src[2]);
}
static inline Vec3 scaleToVec3(const OpenMM_Vec3 src, double s) {
return Vec3(s*src[0], s*src[1], s*src[2]);
}
static inline void fromVec3(const Vec3& src, OpenMM_Vec3 dest) {
dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2];
}
static inline void scaleFromVec3(const Vec3& src, double s, OpenMM_Vec3 dest) {
dest[0] = s*src[0]; dest[1] = s*src[1]; dest[2] = s*src[2];
}
extern "C" {
......@@ -80,6 +86,31 @@ void OpenMM_Vec3Array_get(const OpenMM_Vec3Array* a, int i0, OpenMM_Vec3 ov3) {
void openmm_vec3array_get_(const OpenMM_Vec3Array* const& a, const int& i1, OpenMM_Vec3 ov3)
{ OpenMM_Vec3Array_get(a, i1-1, ov3); }
// Get a single Vec3 element from the array and scale it. Index is 0-relative in C,
// 1-relative in Fortran.
void OpenMM_Vec3Array_getScaled(const OpenMM_Vec3Array* a, int i0, double s, OpenMM_Vec3 ov3) {
scaleFromVec3((*(const std::vector<Vec3>*)a)[i0], s, ov3);
}
void openmm_vec3array_getscaled_(const OpenMM_Vec3Array* const& a, const int& i1, const double& s, OpenMM_Vec3 ov3)
{ OpenMM_Vec3Array_getScaled(a, i1-1, s, ov3); }
// Set a single Vec3 element in the array. Index is 0-relative in C, 1-relative in Fortran.
void OpenMM_Vec3Array_set(OpenMM_Vec3Array* a, int i0, const OpenMM_Vec3 v3)
{ (*(std::vector<Vec3>*)a)[i0] = toVec3(v3); }
void openmm_vec3array_set_(OpenMM_Vec3Array* const& a, const int& i1, const OpenMM_Vec3 v3)
{ OpenMM_Vec3Array_set(a, i1-1, v3); }
// Set a single Vec3 element in the array to a scaling of the input vector.
// Index is 0-relative in C, 1-relative in Fortran.
void OpenMM_Vec3Array_setScaled(OpenMM_Vec3Array* a, int i0, const OpenMM_Vec3 v3, double s)
{ (*(std::vector<Vec3>*)a)[i0] = scaleToVec3(v3, s); }
void openmm_vec3array_setscaled_(OpenMM_Vec3Array* const& a, const int& i1, const OpenMM_Vec3 v3, const double& s)
{ OpenMM_Vec3Array_setScaled(a, i1-1, v3, s); }
void OpenMM_Vec3_scale(const double in[3], double s, double out[3])
{ out[0]=s*in[0]; out[1]=s*in[1]; out[2]=s*in[2]; }
void openmm_vec3_scale_(const double in[3], const double& s, double out[3])
{ out[0]=s*in[0]; out[1]=s*in[1]; out[2]=s*in[2]; }
/////////////////
// std::string //
......@@ -440,4 +471,58 @@ void openmm_state_getvelocities_(const OpenMM_State* const& state, const OpenMM_
{ velocities = OpenMM_State_getVelocities(state); }
///////////////////////////
// OpenMM_RuntimeObjects //
///////////////////////////
OpenMM_RuntimeObjects* OpenMM_RuntimeObjects_create() {
OpenMM_RuntimeObjects* ommrt = new OpenMM_RuntimeObjects();
ommrt->system = 0;
ommrt->integrator = 0;
ommrt->context = 0;
return ommrt;
}
void openmm_runtimeobjects_create_(OpenMM_RuntimeObjects*& ommrt)
{ ommrt = OpenMM_RuntimeObjects_create(); }
void OpenMM_RuntimeObjects_clear(OpenMM_RuntimeObjects* ommrt) {
if (!ommrt) return;
OpenMM_Context_destroy(ommrt->context); ommrt->context = 0;
OpenMM_Integrator_destroy(ommrt->integrator); ommrt->integrator = 0;
OpenMM_System_destroy(ommrt->system); ommrt->system = 0;
}
void openmm_runtimeobjects_clear_(OpenMM_RuntimeObjects*& ommrt)
{ OpenMM_RuntimeObjects_clear(ommrt); }
void OpenMM_RuntimeObjects_destroy(OpenMM_RuntimeObjects* ommrt)
{ OpenMM_RuntimeObjects_clear(ommrt); delete ommrt; }
void openmm_runtimeobjects_destroy_(OpenMM_RuntimeObjects*& ommrt)
{ OpenMM_RuntimeObjects_destroy(ommrt); ommrt = 0; }
void OpenMM_RuntimeObjects_setSystem(OpenMM_RuntimeObjects* ommrt, OpenMM_System* sys)
{ OpenMM_System_destroy(ommrt->system); ommrt->system = sys; }
void openmm_runtimeobjects_setsystem_(OpenMM_RuntimeObjects*& ommrt, OpenMM_System*& sys)
{ OpenMM_RuntimeObjects_setSystem(ommrt, sys); }
OpenMM_System* OpenMM_RuntimeObjects_getSystem(OpenMM_RuntimeObjects* ommrt)
{ return ommrt->system; }
void openmm_runtimeobjects_getsystem_(OpenMM_RuntimeObjects*& ommrt, OpenMM_System*& sys)
{ sys = OpenMM_RuntimeObjects_getSystem(ommrt); }
void OpenMM_RuntimeObjects_setIntegrator(OpenMM_RuntimeObjects* ommrt, OpenMM_Integrator* integ)
{ OpenMM_Integrator_destroy(ommrt->integrator); ommrt->integrator = integ; }
void openmm_runtimeobjects_setintegrator_(OpenMM_RuntimeObjects*& ommrt, OpenMM_Integrator*& integ)
{ OpenMM_RuntimeObjects_setIntegrator(ommrt, integ); }
OpenMM_Integrator* OpenMM_RuntimeObjects_getIntegrator(OpenMM_RuntimeObjects* ommrt)
{ return ommrt->integrator; }
void openmm_runtimeobjects_getintegrator_(OpenMM_RuntimeObjects*& ommrt, OpenMM_Integrator*& integ)
{ integ = OpenMM_RuntimeObjects_getIntegrator(ommrt); }
void OpenMM_RuntimeObjects_setContext(OpenMM_RuntimeObjects* ommrt, OpenMM_Context* context)
{ OpenMM_Context_destroy(ommrt->context); ommrt->context = context; }
void openmm_runtimeobjects_setcontext_(OpenMM_RuntimeObjects*& ommrt, OpenMM_Context*& context)
{ OpenMM_RuntimeObjects_setContext(ommrt, context); }
OpenMM_Context* OpenMM_RuntimeObjects_getContext(OpenMM_RuntimeObjects* ommrt)
{ return ommrt->context; }
void openmm_runtimeobjects_getcontext_(OpenMM_RuntimeObjects*& ommrt, OpenMM_Context*& context)
{ context = OpenMM_RuntimeObjects_getContext(ommrt); }
} // extern "C"
......@@ -14,15 +14,27 @@
#ifndef OPENMM_CWRAPPER_H_
#define OPENMM_CWRAPPER_H_
//#if defined(__cplusplus)
// #include <cmath>
//#else
// #include <math.h>
//#endif
/* 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.
*/
/* These incomplete types are declared so we can have unique pointer types. */
/* These first three types represent the three OpenMM runtime objects that
* must persist from call to call during an OpenMM-powered simulation. */
typedef struct OpenMM_System_s OpenMM_System;
typedef struct OpenMM_Integrator_s OpenMM_Integrator;
typedef struct OpenMM_Context_s OpenMM_Context;
/* 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;
typedef double OpenMM_Vec3[3];
typedef struct OpenMM_Vec3Array_s OpenMM_Vec3Array;
typedef struct OpenMM_String_s OpenMM_String;
......@@ -32,7 +44,6 @@ typedef struct OpenMM_String_s OpenMM_String;
* specific pointer type to the generic one for communication with functions
* that take type OpenMM_Integrator.
*/
typedef struct OpenMM_Integrator_s OpenMM_Integrator;
typedef struct OpenMM_VerletIntegrator_s OpenMM_VerletIntegrator;
typedef struct OpenMM_LangevinIntegrator_s OpenMM_LangevinIntegrator;
......@@ -115,6 +126,10 @@ 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]);
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);
extern void OpenMM_Vec3_scale(const double[3], double s, double[3]);
/* OpenMM_String */
extern OpenMM_String* OpenMM_String_create(const char* init);
......@@ -129,7 +144,6 @@ extern void OpenMM_Platform_loadPluginsFromDirectory(const char*);
extern const char* OpenMM_Platform_getDefaultPluginsDirectory();
/* OpenMM::System */
extern OpenMM_System* OpenMM_System_create();
extern void OpenMM_System_destroy (OpenMM_System*);
extern void OpenMM_System_addForce(OpenMM_System*, OpenMM_Force*);
......@@ -168,7 +182,7 @@ extern void OpenMM_VerletIntegrator_destroy(OpenMM_VerletInt
extern void OpenMM_VerletIntegrator_step(OpenMM_VerletIntegrator*, int numSteps);
/* OpenMM::LangevinIntegrator */
extern OpenMM_LangevinIntegrator* OpenMM_LangevinIntegrator_create(double temperature, double frictionInPerPs, double stepSzInPs);
extern void OpenMM_VLangevinIntegrator_destroy(OpenMM_LangevinIntegrator*);
extern void OpenMM_LangevinIntegrator_destroy(OpenMM_LangevinIntegrator*);
extern void OpenMM_LangevinIntegrator_step(OpenMM_LangevinIntegrator*, int numSteps);
/* OpenMM::Context */
......@@ -188,21 +202,22 @@ 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*);
/* 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*);
#if defined(__cplusplus)
}
#endif
static void OpenMM_Vec3_scale(const OpenMM_Vec3 in, double s, OpenMM_Vec3 out) {
out[0] = in[0]*s; out[1] = in[1]*s; out[2] = in[2]*s;
}
static void OpenMM_Vec3_set(double x, double y, double z, OpenMM_Vec3 out) {
out[0] = x; out[1] = y; out[2] = z;
}
#endif /*OPENMM_CWRAPPER_H_*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment