Commit 8f8f0786 authored by Michael Sherman's avatar Michael Sherman
Browse files

Updated examples and snapshot of wrappers to what I think is their final form....

Updated examples and snapshot of wrappers to what I think is their final form. Fortran no longer uses a RuntimeObjects structure; instead it passes around an opaque handle directly to the Context.
parent ae051ee6
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
* continue to work with Amber-style units like Angstroms, kCals, and van der * continue to work with Amber-style units like Angstroms, kCals, and van der
* Waals radii while correctly communicating with OpenMM in nm, kJ, and sigma. * Waals radii while correctly communicating with OpenMM in nm, kJ, and sigma.
* *
* This example is written entirely in ANSI C, using a set of wrappers which * This example is written entirely in ANSI C, using the OpenMM C bindings.
* are NOT an official part of OpenMM.
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
! continue to work with Amber-style units like Angstroms, kCals, and van der ! continue to work with Amber-style units like Angstroms, kCals, and van der
! Waals radii while correctly communicating with OpenMM in nm, kJ, and sigma. ! Waals radii while correctly communicating with OpenMM in nm, kJ, and sigma.
! !
! This example is written entirely in Fortran 95, using a Fortran interface ! This example is written entirely in Fortran 95, using the OpenMM Fortran
! module which is NOT official parts of the OpenMM distribution. ! interface module.
! ------------------------------------------------------------------------------ ! ------------------------------------------------------------------------------
!------------------------------------------------------------------------------- !-------------------------------------------------------------------------------
...@@ -158,9 +158,7 @@ END SUBROUTINE ...@@ -158,9 +158,7 @@ END SUBROUTINE
! (3) Create an Integrator and a Context associating the Integrator with ! (3) Create an Integrator and a Context associating the Integrator with
! the System. ! the System.
! (4) Select the OpenMM platform to be used. ! (4) Select the OpenMM platform to be used.
! (5) Allocate a RuntimeObjects container to hang on to the System, ! (5) Return an opaque handle to the Context object and the name of the
! Integrator, and Context.
! (6) Return an opaque handle to the RuntimeObjects and the name of the
! Platform in use. ! Platform in use.
! !
! Note that this routine must understand the calling MD code's molecule and ! Note that this routine must understand the calling MD code's molecule and
...@@ -171,23 +169,21 @@ SUBROUTINE myInitializeOpenMM(ommHandle, platformName) ...@@ -171,23 +169,21 @@ SUBROUTINE myInitializeOpenMM(ommHandle, platformName)
integer*8, intent(out) :: ommHandle integer*8, intent(out) :: ommHandle
character*10, intent(out) :: platformName character*10, intent(out) :: platformName
! This is the actual type of the opaque handle. ! These are the objects we'll create here thare are stored in the
type (OpenMM_RuntimeObjects) omm ! Context for later access. Don't forget to delete them at the end.
! These are the objects we'll create here and store in the
! RuntimeObjects container for later access.
type (OpenMM_System) system type (OpenMM_System) system
type (OpenMM_LangevinIntegrator) langevin type (OpenMM_LangevinIntegrator) langevin
type (OpenMM_Context) context type (OpenMM_Context) context
! These are temporary OpenMM objects used and discarded here. ! These are temporary OpenMM objects used and discarded here.
type (OpenMM_StringArray) pluginList type (OpenMM_StringArray) pluginList
type (OpenMM_Vec3Array) initialPosInNm type (OpenMM_Vec3Array) initialPosInNm
type (OpenMM_NonbondedForce) nonbond type (OpenMM_NonbondedForce) nonbond
type (OpenMM_GBSAOBCForce) gbsa type (OpenMM_GBSAOBCForce) gbsa
type (OpenMM_Platform) platform type (OpenMM_Platform) platform
character*100 dirName character*100 dirName
integer*4 n, ix integer*4 n, ix
real*8 posInNm(3) real*8 posInNm(3)
! Get the name of the default plugins directory, ! Get the name of the default plugins directory,
! and then load all the plugins found there. ! and then load all the plugins found there.
...@@ -254,14 +250,10 @@ SUBROUTINE myInitializeOpenMM(ommHandle, platformName) ...@@ -254,14 +250,10 @@ SUBROUTINE myInitializeOpenMM(ommHandle, platformName)
call OpenMM_Context_getPlatform(context, platform) call OpenMM_Context_getPlatform(context, platform)
call OpenMM_Platform_getName(platform, platformName) call OpenMM_Platform_getName(platform, platformName)
! Put the System, Integrator, and Context in the RuntimeObjects ! References to the System and Integrator are in the Context, so
! container and return an opaque reference to the container. ! we can extract them later for stepping and cleanup. Return an opaque
call OpenMM_RuntimeObjects_create(omm) ! reference to the Context for use by the main program.
call OpenMM_RuntimeObjects_setSystem(omm, system) ommHandle = transfer(context, ommHandle)
call OpenMM_RuntimeObjects_setIntegrator(omm, &
transfer(langevin, OpenMM_Integrator(0)))
call OpenMM_RuntimeObjects_setContext(omm, context)
ommHandle = transfer(omm, ommHandle)
END SUBROUTINE END SUBROUTINE
...@@ -278,11 +270,9 @@ SUBROUTINE myGetOpenMMState(ommHandle, timeInPs, energyInKcal) ...@@ -278,11 +270,9 @@ SUBROUTINE myGetOpenMMState(ommHandle, timeInPs, energyInKcal)
integer infoMask, n integer infoMask, n
real*8 posInNm(3) real*8 posInNm(3)
type (OpenMM_RuntimeObjects) omm
type (OpenMM_Context) context type (OpenMM_Context) context
omm = transfer(ommHandle, omm) context = transfer(ommHandle, context)
call OpenMM_RuntimeObjects_getContext(omm, context)
infoMask = OpenMM_State_Positions infoMask = OpenMM_State_Positions
if (WantEnergy) then if (WantEnergy) then
...@@ -325,10 +315,11 @@ SUBROUTINE myStepWithOpenMM(ommHandle, numSteps) ...@@ -325,10 +315,11 @@ SUBROUTINE myStepWithOpenMM(ommHandle, numSteps)
integer*8, intent(in) :: ommHandle integer*8, intent(in) :: ommHandle
integer, intent(in) :: numSteps integer, intent(in) :: numSteps
type (OpenMM_RuntimeObjects) omm type (OpenMM_Context) context
type (OpenMM_Integrator) integrator type (OpenMM_Integrator) integrator
omm = transfer(ommHandle, omm)
call OpenMM_RuntimeObjects_getIntegrator(omm, integrator) context = transfer(ommHandle, context)
call OpenMM_Context_getIntegrator(context, integrator)
call OpenMM_Integrator_step(integrator, numSteps) call OpenMM_Integrator_step(integrator, numSteps)
END SUBROUTINE END SUBROUTINE
...@@ -339,10 +330,17 @@ END SUBROUTINE ...@@ -339,10 +330,17 @@ END SUBROUTINE
!------------------------------------------------------------------------------- !-------------------------------------------------------------------------------
SUBROUTINE myTerminateOpenMM(ommHandle) SUBROUTINE myTerminateOpenMM(ommHandle)
use OpenMM; implicit none use OpenMM; implicit none
integer*8, intent(in) :: ommHandle integer*8, intent(inout) :: ommHandle
type (OpenMM_RuntimeObjects) omm type (OpenMM_Context) context
omm = transfer(ommHandle, omm) type (OpenMM_Integrator) integrator
type (OpenMM_System) system
call OpenMM_RuntimeObjects_destroy(omm)
context = transfer(ommHandle, context)
call OpenMM_Context_getIntegrator(context, integrator)
call OpenMM_Context_getSystem(context, system)
call OpenMM_Context_destroy(context)
call OpenMM_Integrator_destroy(integrator)
call OpenMM_System_destroy(system)
END SUBROUTINE END SUBROUTINE
...@@ -958,92 +958,7 @@ OpenMM_Force* OpenMM_System_getForce(OpenMM_System* target, int index) { ...@@ -958,92 +958,7 @@ OpenMM_Force* OpenMM_System_getForce(OpenMM_System* target, int index) {
return reinterpret_cast<OpenMM_Force*>(result); return reinterpret_cast<OpenMM_Force*>(result);
}; };
///////////////////////////
// OpenMM_RuntimeObjects //
///////////////////////////
// create
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_CREATE(OpenMM_RuntimeObjects*& ommrt)
{ ommrt = OpenMM_RuntimeObjects_create(); }
// clear
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* const& ommrt)
{ OpenMM_RuntimeObjects_clear(ommrt); }
void OPENMM_RUNTIMEOBJECTS_CLEAR(OpenMM_RuntimeObjects* const& ommrt)
{ OpenMM_RuntimeObjects_clear(ommrt); }
// destroy
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_DESTROY(OpenMM_RuntimeObjects*& ommrt)
{ OpenMM_RuntimeObjects_destroy(ommrt); ommrt = 0; }
// setSystem
void OpenMM_RuntimeObjects_setSystem(OpenMM_RuntimeObjects* ommrt, OpenMM_System* sys)
{ OpenMM_System_destroy(ommrt->system); ommrt->system = sys; }
void openmm_runtimeobjects_setsystem_(OpenMM_RuntimeObjects* const& ommrt, OpenMM_System* const& sys)
{ OpenMM_RuntimeObjects_setSystem(ommrt, sys); }
void OPENMM_RUNTIMEOBJECTS_SETSYSTEM(OpenMM_RuntimeObjects* const& ommrt, OpenMM_System* const& sys)
{ OpenMM_RuntimeObjects_setSystem(ommrt, sys); }
// getSystem
OpenMM_System* OpenMM_RuntimeObjects_getSystem(OpenMM_RuntimeObjects* ommrt)
{ return ommrt->system; }
void openmm_runtimeobjects_getsystem_(OpenMM_RuntimeObjects* const& ommrt, OpenMM_System*& sys)
{ sys = OpenMM_RuntimeObjects_getSystem(ommrt); }
void OPENMM_RUNTIMEOBJECTS_GETSYSTEM(OpenMM_RuntimeObjects* const& ommrt, OpenMM_System*& sys)
{ sys = OpenMM_RuntimeObjects_getSystem(ommrt); }
// setIntegrator
void OpenMM_RuntimeObjects_setIntegrator(OpenMM_RuntimeObjects* ommrt, OpenMM_Integrator* integ)
{ OpenMM_Integrator_destroy(ommrt->integrator); ommrt->integrator = integ; }
void openmm_runtimeobjects_setintegrator_(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Integrator* const& integ)
{ OpenMM_RuntimeObjects_setIntegrator(ommrt, integ); }
void OPENMM_RUNTIMEOBJECTS_SETINTEGRATOR(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Integrator* const& integ)
{ OpenMM_RuntimeObjects_setIntegrator(ommrt, integ); }
// getIntegrator
OpenMM_Integrator* OpenMM_RuntimeObjects_getIntegrator(OpenMM_RuntimeObjects* ommrt)
{ return ommrt->integrator; }
void openmm_runtimeobjects_getintegrator_(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Integrator*& integ)
{ integ = OpenMM_RuntimeObjects_getIntegrator(ommrt); }
void OPENMM_RUNTIMEOBJECTS_GETINTEGRATOR(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Integrator*& integ)
{ integ = OpenMM_RuntimeObjects_getIntegrator(ommrt); }
// setContext
void OpenMM_RuntimeObjects_setContext(OpenMM_RuntimeObjects* ommrt, OpenMM_Context* context)
{ OpenMM_Context_destroy(ommrt->context); ommrt->context = context; }
void openmm_runtimeobjects_setcontext_(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Context*& context)
{ OpenMM_RuntimeObjects_setContext(ommrt, context); }
void OPENMM_RUNTIMEOBJECTS_SETCONTEXT(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Context*& context)
{ OpenMM_RuntimeObjects_setContext(ommrt, context); }
// getContext
OpenMM_Context* OpenMM_RuntimeObjects_getContext(OpenMM_RuntimeObjects* ommrt)
{ return ommrt->context; }
void openmm_runtimeobjects_getcontext_(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Context*& context)
{ context = OpenMM_RuntimeObjects_getContext(ommrt); }
void OPENMM_RUNTIMEOBJECTS_GETCONTEXT(OpenMM_RuntimeObjects* const& ommrt, OpenMM_Context*& context)
{ context = OpenMM_RuntimeObjects_getContext(ommrt); }
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif
...@@ -46,16 +46,6 @@ typedef struct OpenMM_BondArray_struct OpenMM_BondArray; ...@@ -46,16 +46,6 @@ typedef struct OpenMM_BondArray_struct OpenMM_BondArray;
typedef struct OpenMM_ParameterArray_struct OpenMM_ParameterArray; typedef struct OpenMM_ParameterArray_struct OpenMM_ParameterArray;
typedef struct {double x, y, z;} OpenMM_Vec3; typedef struct {double x, y, z;} OpenMM_Vec3;
/* 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 enum {OpenMM_False = 0, OpenMM_True = 1} OpenMM_Boolean; typedef enum {OpenMM_False = 0, OpenMM_True = 1} OpenMM_Boolean;
#if defined(__cplusplus) #if defined(__cplusplus)
......
...@@ -24,13 +24,6 @@ MODULE OpenMM_Types ...@@ -24,13 +24,6 @@ MODULE OpenMM_Types
parameter(OpenMM_SigmaPerVdwRadius=1.7817974362806785) parameter(OpenMM_SigmaPerVdwRadius=1.7817974362806785)
parameter(OpenMM_VdwRadiusPerSigma=0.5612310241546865) parameter(OpenMM_VdwRadiusPerSigma=0.5612310241546865)
parameter(OpenMM_DegreesPerRadian=57.29577951308232) parameter(OpenMM_DegreesPerRadian=57.29577951308232)
! This data structure can be used to hold the set of OpenMM objects
! that must persist from call to call while running a simulation.
! It contains an OpenMM_System, _Integrator, and _Context.
type OpenMM_RuntimeObjects
integer*8 :: handle = 0
end type
! Type Declarations ! Type Declarations
...@@ -1367,51 +1360,5 @@ MODULE OpenMM ...@@ -1367,51 +1360,5 @@ MODULE OpenMM
integer*4 index integer*4 index
type (OpenMM_Force) result type (OpenMM_Force) result
end end
! -------------------------
! OpenMM::RuntimeObjects
! -------------------------
subroutine OpenMM_RuntimeObjects_create(omm)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
end
subroutine OpenMM_RuntimeObjects_clear(omm)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
end
subroutine OpenMM_RuntimeObjects_destroy(omm)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
end
subroutine OpenMM_RuntimeObjects_setSystem(omm,sys)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
type (OpenMM_System) sys
end
subroutine OpenMM_RuntimeObjects_setIntegrator(omm,integ)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
type (OpenMM_Integrator) integ
end
subroutine OpenMM_RuntimeObjects_setContext(omm,context)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
type (OpenMM_Context) context
end
subroutine OpenMM_RuntimeObjects_getSystem(omm,sys)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
type (OpenMM_System) sys
end
subroutine OpenMM_RuntimeObjects_getIntegrator(omm,integ)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
type (OpenMM_Integrator) integ
end
subroutine OpenMM_RuntimeObjects_getContext(omm,context)
use OpenMM_Types; implicit none
type (OpenMM_RuntimeObjects) omm
type (OpenMM_Context) context
end
end interface end interface
END MODULE OpenMM END MODULE OpenMM
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
#if defined(__cplusplus)
extern "C" { extern "C" {
#endif
/* OpenMM_Vec3 */ /* OpenMM_Vec3 */
void openmm_vec3_scale_(const OpenMM_Vec3& vec, double const& scale, OpenMM_Vec3& result) { void openmm_vec3_scale_(const OpenMM_Vec3& vec, double const& scale, OpenMM_Vec3& result) {
...@@ -66,6 +64,14 @@ void OPENMM_VEC3ARRAY_GET(const OpenMM_Vec3Array* const& array, const int& index ...@@ -66,6 +64,14 @@ void OPENMM_VEC3ARRAY_GET(const OpenMM_Vec3Array* const& array, const int& index
} }
/* OpenMM_StringArray */ /* OpenMM_StringArray */
void copyAndPadString(char* dest, const char* source, int length) {
bool reachedEnd = false;
for (int i = 0; i < length; i++) {
if (source[i] == 0)
reachedEnd = true;
dest[i] = (reachedEnd ? ' ' : source[i]);
}
}
void openmm_stringarray_create_(OpenMM_StringArray*& result, const int& size) { void openmm_stringarray_create_(OpenMM_StringArray*& result, const int& size) {
result = OpenMM_StringArray_create(size); result = OpenMM_StringArray_create(size);
} }
...@@ -106,11 +112,11 @@ void OPENMM_STRINGARRAY_SET(OpenMM_StringArray* const& array, const int& index, ...@@ -106,11 +112,11 @@ void OPENMM_STRINGARRAY_SET(OpenMM_StringArray* const& array, const int& index,
} }
void openmm_stringarray_get_(const OpenMM_StringArray* const& array, const int& index, char* result, int length) { void openmm_stringarray_get_(const OpenMM_StringArray* const& array, const int& index, char* result, int length) {
const char* str = OpenMM_StringArray_get(array, index-1); const char* str = OpenMM_StringArray_get(array, index-1);
strncpy(result, str, length); copyAndPadString(result, str, length);
} }
void OPENMM_STRINGARRAY_GET(const OpenMM_StringArray* const& array, const int& index, char* result, int length) { void OPENMM_STRINGARRAY_GET(const OpenMM_StringArray* const& array, const int& index, char* result, int length) {
const char* str = OpenMM_StringArray_get(array, index-1); const char* str = OpenMM_StringArray_get(array, index-1);
strncpy(result, str, length); copyAndPadString(result, str, length);
} }
/* OpenMM_BondArray */ /* OpenMM_BondArray */
...@@ -308,13 +314,11 @@ void OPENMM_OPENMMEXCEPTION_DESTROY(OpenMM_OpenMMException*& destroy) { ...@@ -308,13 +314,11 @@ void OPENMM_OPENMMEXCEPTION_DESTROY(OpenMM_OpenMMException*& destroy) {
} }
void openmm_openmmexception_what_(const OpenMM_OpenMMException*& target, char* result, int result_length) { void openmm_openmmexception_what_(const OpenMM_OpenMMException*& target, char* result, int result_length) {
const char* result_chars = OpenMM_OpenMMException_what(target); const char* result_chars = OpenMM_OpenMMException_what(target);
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void OPENMM_OPENMMEXCEPTION_WHAT(const OpenMM_OpenMMException*& target, char* result, int result_length) { void OPENMM_OPENMMEXCEPTION_WHAT(const OpenMM_OpenMMException*& target, char* result, int result_length) {
const char* result_chars = OpenMM_OpenMMException_what(target); const char* result_chars = OpenMM_OpenMMException_what(target);
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
...@@ -995,23 +999,19 @@ void OPENMM_ANDERSENTHERMOSTAT_DESTROY(OpenMM_AndersenThermostat*& destroy) { ...@@ -995,23 +999,19 @@ void OPENMM_ANDERSENTHERMOSTAT_DESTROY(OpenMM_AndersenThermostat*& destroy) {
} }
void openmm_andersenthermostat_temperature_(char* result, int result_length) { void openmm_andersenthermostat_temperature_(char* result, int result_length) {
const char* result_chars = OpenMM_AndersenThermostat_Temperature(); const char* result_chars = OpenMM_AndersenThermostat_Temperature();
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void OPENMM_ANDERSENTHERMOSTAT_TEMPERATURE(char* result, int result_length) { void OPENMM_ANDERSENTHERMOSTAT_TEMPERATURE(char* result, int result_length) {
const char* result_chars = OpenMM_AndersenThermostat_Temperature(); const char* result_chars = OpenMM_AndersenThermostat_Temperature();
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void openmm_andersenthermostat_collisionfrequency_(char* result, int result_length) { void openmm_andersenthermostat_collisionfrequency_(char* result, int result_length) {
const char* result_chars = OpenMM_AndersenThermostat_CollisionFrequency(); const char* result_chars = OpenMM_AndersenThermostat_CollisionFrequency();
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void OPENMM_ANDERSENTHERMOSTAT_COLLISIONFREQUENCY(char* result, int result_length) { void OPENMM_ANDERSENTHERMOSTAT_COLLISIONFREQUENCY(char* result, int result_length) {
const char* result_chars = OpenMM_AndersenThermostat_CollisionFrequency(); const char* result_chars = OpenMM_AndersenThermostat_CollisionFrequency();
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
double openmm_andersenthermostat_getdefaulttemperature_(const OpenMM_AndersenThermostat*& target) { double openmm_andersenthermostat_getdefaulttemperature_(const OpenMM_AndersenThermostat*& target) {
return OpenMM_AndersenThermostat_getDefaultTemperature(target); return OpenMM_AndersenThermostat_getDefaultTemperature(target);
...@@ -1050,13 +1050,11 @@ void OPENMM_PLATFORM_DESTROY(OpenMM_Platform*& destroy) { ...@@ -1050,13 +1050,11 @@ void OPENMM_PLATFORM_DESTROY(OpenMM_Platform*& destroy) {
} }
void openmm_platform_getname_(const OpenMM_Platform*& target, char* result, int result_length) { void openmm_platform_getname_(const OpenMM_Platform*& target, char* result, int result_length) {
const char* result_chars = OpenMM_Platform_getName(target); const char* result_chars = OpenMM_Platform_getName(target);
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void OPENMM_PLATFORM_GETNAME(const OpenMM_Platform*& target, char* result, int result_length) { void OPENMM_PLATFORM_GETNAME(const OpenMM_Platform*& target, char* result, int result_length) {
const char* result_chars = OpenMM_Platform_getName(target); const char* result_chars = OpenMM_Platform_getName(target);
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
double openmm_platform_getspeed_(const OpenMM_Platform*& target) { double openmm_platform_getspeed_(const OpenMM_Platform*& target) {
return OpenMM_Platform_getSpeed(target); return OpenMM_Platform_getSpeed(target);
...@@ -1078,13 +1076,11 @@ void OPENMM_PLATFORM_GETPROPERTYNAMES(OpenMM_Platform*& target, const OpenMM_Str ...@@ -1078,13 +1076,11 @@ void OPENMM_PLATFORM_GETPROPERTYNAMES(OpenMM_Platform*& target, const OpenMM_Str
}; };
void openmm_platform_getpropertyvalue_(const OpenMM_Platform*& target, const OpenMM_Context*& context, const char* property, char* result, int property_length, int result_length) { void openmm_platform_getpropertyvalue_(const OpenMM_Platform*& target, const OpenMM_Context*& context, const char* property, char* result, int property_length, int result_length) {
const char* result_chars = OpenMM_Platform_getPropertyValue(target, context, string(property, property_length).c_str()); const char* result_chars = OpenMM_Platform_getPropertyValue(target, context, string(property, property_length).c_str());
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void OPENMM_PLATFORM_GETPROPERTYVALUE(const OpenMM_Platform*& target, const OpenMM_Context*& context, const char* property, char* result, int property_length, int result_length) { void OPENMM_PLATFORM_GETPROPERTYVALUE(const OpenMM_Platform*& target, const OpenMM_Context*& context, const char* property, char* result, int property_length, int result_length) {
const char* result_chars = OpenMM_Platform_getPropertyValue(target, context, string(property, property_length).c_str()); const char* result_chars = OpenMM_Platform_getPropertyValue(target, context, string(property, property_length).c_str());
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void openmm_platform_setpropertyvalue_(const OpenMM_Platform*& target, OpenMM_Context*& context, const char* property, const char* value, int property_length, int value_length) { void openmm_platform_setpropertyvalue_(const OpenMM_Platform*& target, OpenMM_Context*& context, const char* property, const char* value, int property_length, int value_length) {
OpenMM_Platform_setPropertyValue(target, context, string(property, property_length).c_str(), string(value, value_length).c_str()); OpenMM_Platform_setPropertyValue(target, context, string(property, property_length).c_str(), string(value, value_length).c_str());
...@@ -1094,13 +1090,11 @@ void OPENMM_PLATFORM_SETPROPERTYVALUE(const OpenMM_Platform*& target, OpenMM_Con ...@@ -1094,13 +1090,11 @@ void OPENMM_PLATFORM_SETPROPERTYVALUE(const OpenMM_Platform*& target, OpenMM_Con
}; };
void openmm_platform_getpropertydefaultvalue_(const OpenMM_Platform*& target, const char* property, char* result, int property_length, int result_length) { void openmm_platform_getpropertydefaultvalue_(const OpenMM_Platform*& target, const char* property, char* result, int property_length, int result_length) {
const char* result_chars = OpenMM_Platform_getPropertyDefaultValue(target, string(property, property_length).c_str()); const char* result_chars = OpenMM_Platform_getPropertyDefaultValue(target, string(property, property_length).c_str());
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void OPENMM_PLATFORM_GETPROPERTYDEFAULTVALUE(const OpenMM_Platform*& target, const char* property, char* result, int property_length, int result_length) { void OPENMM_PLATFORM_GETPROPERTYDEFAULTVALUE(const OpenMM_Platform*& target, const char* property, char* result, int property_length, int result_length) {
const char* result_chars = OpenMM_Platform_getPropertyDefaultValue(target, string(property, property_length).c_str()); const char* result_chars = OpenMM_Platform_getPropertyDefaultValue(target, string(property, property_length).c_str());
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void openmm_platform_setpropertydefaultvalue_(OpenMM_Platform*& target, const char* property, const char* value, int property_length, int value_length) { void openmm_platform_setpropertydefaultvalue_(OpenMM_Platform*& target, const char* property, const char* value, int property_length, int value_length) {
OpenMM_Platform_setPropertyDefaultValue(target, string(property, property_length).c_str(), string(value, value_length).c_str()); OpenMM_Platform_setPropertyDefaultValue(target, string(property, property_length).c_str(), string(value, value_length).c_str());
...@@ -1158,13 +1152,11 @@ void OPENMM_PLATFORM_LOADPLUGINLIBRARY(const char* file, int file_length) { ...@@ -1158,13 +1152,11 @@ void OPENMM_PLATFORM_LOADPLUGINLIBRARY(const char* file, int file_length) {
}; };
void openmm_platform_getdefaultpluginsdirectory_(char* result, int result_length) { void openmm_platform_getdefaultpluginsdirectory_(char* result, int result_length) {
const char* result_chars = OpenMM_Platform_getDefaultPluginsDirectory(); const char* result_chars = OpenMM_Platform_getDefaultPluginsDirectory();
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
void OPENMM_PLATFORM_GETDEFAULTPLUGINSDIRECTORY(char* result, int result_length) { void OPENMM_PLATFORM_GETDEFAULTPLUGINSDIRECTORY(char* result, int result_length) {
const char* result_chars = OpenMM_Platform_getDefaultPluginsDirectory(); const char* result_chars = OpenMM_Platform_getDefaultPluginsDirectory();
strncpy(result, result_chars, result_length); copyAndPadString(result, result_chars, result_length);
}; };
...@@ -1386,6 +1378,4 @@ void OPENMM_SYSTEM_GETFORCE(OpenMM_System*& target, int const& index, OpenMM_For ...@@ -1386,6 +1378,4 @@ void OPENMM_SYSTEM_GETFORCE(OpenMM_System*& target, int const& index, OpenMM_For
}; };
#if defined(__cplusplus)
} }
#endif
...@@ -27,11 +27,11 @@ workshop on June 24, 2009 at Stanford. ...@@ -27,11 +27,11 @@ workshop on June 24, 2009 at Stanford.
In addition to the example programs here, there are also two sets In addition to the example programs here, there are also two sets
of prototype wrappers to enable C and Fortran 95 to call the of wrappers to enable C and Fortran 95 to call the
OpenMM API. However, even if your calling code is in C or Fortran, OpenMM API. However, even if your calling code is in C or Fortran,
please consider instead writing your OpenMM-calling routines in please consider instead writing your OpenMM-calling routines in
C++, using 'extern "C"' so that your main program can call them. C++, using 'extern "C"' so that your main program can call them.
If that isn't feasible for you, try out our prototype wrappers If that isn't feasible for you, try out our wrappers
and let us know what troubles or better ideas you have. (Post to and let us know what troubles or better ideas you have. (Post to
the OpenMM Forum at the above URL.) the OpenMM Forum at the above URL.)
...@@ -47,10 +47,9 @@ NMake program to build the examples using Microsoft's "cl" compiler ...@@ -47,10 +47,9 @@ NMake program to build the examples using Microsoft's "cl" compiler
for C++ and C, and Intel's "ifort" Fortran compiler. for C++ and C, and Intel's "ifort" Fortran compiler.
There is a subdirectory here providing Visual Studio "solutions" There is a subdirectory here providing Visual Studio "solutions"
for building HelloArgon in C++ or C. You will have to make your for building HelloArgon in C++, C, and Fortran. You will have to
own for the other examples or just substitute a different source make your own for the other examples or just substitute a different
file for HelloArgon.cpp. We do not currently have a Visual Studio source file for HelloArgon.cpp.
project for building the Fortran examples.
HelloArgon (C++, C, Fortran 95) HelloArgon (C++, C, Fortran 95)
------------------------------- -------------------------------
...@@ -89,11 +88,11 @@ C Wrapper ...@@ -89,11 +88,11 @@ C Wrapper
--------- ---------
This consists of two files: This consists of two files:
OpenMM_CWrapper.h OpenMMCWrapper.h
OpenMM_CWrapper.cpp OpenMMCWrapper.cpp
Your C code (and the C examples above) include the header file Your C code (and the C examples above) include the header file
and link with OpenMM_CWrapper.o along with the OpenMM library. and link with OpenMMCWrapper.o along with the OpenMM library.
Consult the code or the example programs to figure out how Consult the code or the example programs to figure out how
to use the wrappers; they are for the most part a very to use the wrappers; they are for the most part a very
straightforward rehashing of the well-documented OpenMM C++ straightforward rehashing of the well-documented OpenMM C++
...@@ -102,17 +101,16 @@ API. ...@@ -102,17 +101,16 @@ API.
Fortran Wrapper Fortran Wrapper
--------------- ---------------
The file that defines the OpenMM module is: The files that define the OpenMM Fortran bindings are:
OpenMM_Module.f90 OpenMMFortranModule.f90
OpenMMFortranWrapper.cpp
This consists of a Fortran '95 Module "OpenMM" so that your This consists of a Fortran 95 Module "OpenMM" so that your
Fortran program units have "use OpenMM" statements. You will Fortran program units have "use OpenMM" statements. You will
need access to the OpenMM*.mod files generated for the modules, need access to the OpenMM*.mod files generated for the modules,
and you must also link with the OpenMM_CWrapper.o as described and you must also link with the OpenMMCWrapper.o as described
above for C. That's because the C Wrapper also provides bindings above for C, PLUS the OpenMMFortranWrapper.o. That's because
that treat arguments in a manner appropriate to Fortran, and the Fortran Wrapper makes use of the C Wrapper.
the Fortran Module describes those rather than attempting to
match the C or C++ signatures.
......
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