Commit c6c034ba authored by Michael Sherman's avatar Michael Sherman
Browse files

Upgrade examples to track Peter's automatically-generated C and Fortran...

Upgrade examples to track Peter's automatically-generated C and Fortran bindings. These are still using a snapshot of the wrappers, slightly hand modified, but they are much closer to the final ones now. When the automated ones are ready and part of the build, these checked-in ones will no longer be necessary.
parent 259cb45a
......@@ -13,8 +13,9 @@
# versions of the executable.
SET(OpenMM_CWRAPPER "OpenMM_CWrapper")
SET(OpenMM_FMODULE "OpenMM_Module")
SET(OpenMM_CWRAPPER "OpenMMCWrapper")
SET(OpenMM_FWRAPPER "OpenMMFortranWrapper")
SET(OpenMM_FMODULE "OpenMMFortranModule")
# CWrapper is always a static library but you need a different
# one if you want to link with the OpenMM static library.
......@@ -35,13 +36,15 @@ SET(F_EXAMPLES HelloArgonInFortran HelloSodiumChlorideInFortran)
SET(BUILD_TESTING_SHARED 1)
SET(BUILD_TESTING_STATIC 1)
ADD_LIBRARY(${CWRAPPER_FOR_SHARED} ${OpenMM_CWRAPPER}.cpp ${OpenMM_CWRAPPER}.h)
ADD_LIBRARY(${CWRAPPER_FOR_SHARED}
${OpenMM_CWRAPPER}.cpp ${OpenMM_FWRAPPER}.cpp ${OpenMM_CWRAPPER}.h)
SET_TARGET_PROPERTIES(${CWRAPPER_FOR_SHARED}
PROPERTIES
PROJECT_LABEL "C Bindings")
TARGET_LINK_LIBRARIES(${CWRAPPER_FOR_SHARED} ${SHARED_TARGET})
ADD_LIBRARY(${CWRAPPER_FOR_STATIC} ${OpenMM_CWRAPPER}.cpp ${OpenMM_CWRAPPER}.h)
ADD_LIBRARY(${CWRAPPER_FOR_STATIC}
${OpenMM_CWRAPPER}.cpp ${OpenMM_FWRAPPER}.cpp ${OpenMM_CWRAPPER}.h)
SET_TARGET_PROPERTIES(${CWRAPPER_FOR_STATIC}
PROPERTIES
COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
......@@ -109,11 +112,12 @@ FOREACH(EX_ROOT ${F_EXAMPLES})
INSTALL(FILES ${EX_ROOT}.f90 DESTINATION examples)
ENDFOREACH(EX_ROOT ${F_EXAMPLES})
INSTALL(FILES ${OpenMM_CWRAPPER}.h ${OpenMM_CWRAPPER}.cpp DESTINATION examples)
INSTALL(FILES ${OpenMM_CWRAPPER}.h ${OpenMM_CWRAPPER}.cpp ${OpenMM_FWRAPPER}.cpp
DESTINATION examples)
INSTALL(FILES ${OpenMM_FMODULE}.f90 DESTINATION examples)
INSTALL(FILES README.txt DESTINATION examples)
INSTALL(FILES Makefile DESTINATION examples)
INSTALL(FILES Makefile NMakefile DESTINATION examples)
INSTALL(FILES HelloArgonVS8/HelloArgon.vcproj
HelloArgonVS8/HelloArgon.sln
......
......@@ -11,7 +11,7 @@
* other visualization tool to produce an animation of the resulting trajectory.
* -------------------------------------------------------------------------- */
#include "OpenMM_CWrapper.h"
#include "OpenMMCWrapper.h"
#include <stdio.h>
/* Forward declaration of routine for printing one frame of the
......@@ -23,6 +23,7 @@ void simulateArgon()
OpenMM_System* system;
OpenMM_Integrator* integrator;
OpenMM_Context* context;
OpenMM_Platform* platform;
OpenMM_NonbondedForce* nonbond;
OpenMM_Vec3Array* initPosInNm;
int a, frameNum;
......@@ -41,7 +42,7 @@ void simulateArgon()
initPosInNm = OpenMM_Vec3Array_create(3);
for (a = 0; a < 3; ++a)
{
const double posNm[3] = {0.5*a, 0, 0}; /*location, nm*/
const OpenMM_Vec3 posNm = {0.5*a, 0, 0}; /*location, nm*/
OpenMM_Vec3Array_set(initPosInNm, a, posNm);
OpenMM_System_addParticle(system, 39.95); /*mass of Ar, grams/mole*/
......@@ -55,8 +56,9 @@ void simulateArgon()
/* Let OpenMM Context choose best platform. */
context = OpenMM_Context_create(system, integrator);
platform = OpenMM_Context_getPlatform(context);
printf( "REMARK Using OpenMM platform %s\n",
OpenMM_Context_getPlatformName(context));
OpenMM_Platform_getName(platform));
/* Set starting positions of the atoms. Leave time and velocity zero. */
OpenMM_Context_setPositions(context, initPosInNm);
......@@ -64,7 +66,7 @@ void simulateArgon()
/* Simulate. */
for (frameNum=1; ;++frameNum) {
/* Output current state information. */
OpenMM_State* state = OpenMM_Context_createState(context, OpenMM_State_Positions);
OpenMM_State* state = OpenMM_Context_getState(context, OpenMM_State_Positions);
const double timeInPs = OpenMM_State_getTime(state);
writePdbFrame(frameNum, state); /*output coordinates*/
OpenMM_State_destroy(state);
......@@ -99,14 +101,14 @@ void writePdbFrame(int frameNum, const OpenMM_State* state)
/* Use PDB MODEL cards to number trajectory frames. */
printf("MODEL %d\n", frameNum); /*start of frame*/
for (a = 0; a < OpenMM_Vec3Array_size(posInNm); ++a)
for (a = 0; a < OpenMM_Vec3Array_getSize(posInNm); ++a)
{
double posInAng[3];
OpenMM_Vec3 posInAng;
/* "10" here converts nanometers to Angstroms */
OpenMM_Vec3Array_getScaled(posInNm, a, 10., posInAng);
posInAng = OpenMM_Vec3_scale(*OpenMM_Vec3Array_get(posInNm, a), 10.);
printf("ATOM %5d AR AR 1 ", a+1); /*atom number*/
printf("%8.3f%8.3f%8.3f 1.00 0.00\n", /*coordinates*/
posInAng[0], posInAng[1], posInAng[2]);
posInAng.x, posInAng.y, posInAng.z);
}
printf("ENDMDL\n"); /*end of frame*/
}
......@@ -61,7 +61,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="OpenMM_CWrapper_d.lib OpenMM_d.lib"
AdditionalDependencies="OpenMMCWrapper_d.lib OpenMM_d.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(ProgramFiles)\OpenMM\lib&quot;"
GenerateDebugInformation="true"
......@@ -137,7 +137,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="OpenMM_CWrapper.lib OpenMM.lib"
AdditionalDependencies="OpenMMCWrapper.lib OpenMM.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;$(ProgramFiles)\OpenMM\lib&quot;"
GenerateDebugInformation="true"
......
......@@ -16,19 +16,20 @@ PROGRAM HelloArgon
type(OpenMM_System) system
type(OpenMM_VerletIntegrator) verlet
type(OpenMM_Context) context
type(OpenMM_Platform) platform
type(OpenMM_NonbondedForce) nonbond
type(OpenMM_Vec3Array) initPosInNm
type(OpenMM_State) state
type(OpenMM_String) dirName
type(OpenMM_StringArray) pluginList
real*8 timeInPs
integer*4 a, ix, frameNum
character*10 platformName
character*100 dirName
! Load any shared libraries containing GPU implementations.
call OpenMM_String_create(dirName,'')
call OpenMM_Platform_getDefaultPluginsDirectory(dirName)
call OpenMM_Platform_loadPluginsFromDirectory(dirName)
call OpenMM_String_destroy(dirName)
call OpenMM_Platform_getDefaultPluginsDirectory(dirName)
call OpenMM_Platform_loadPluginsFromDirectory(dirName, pluginList)
call OpenMM_StringArray_destroy(pluginList)
! Create a system with nonbonded forces. System takes ownership
! of Force; don't destroy it yourself. (We're using transfer here
......@@ -36,13 +37,13 @@ PROGRAM HelloArgon
call OpenMM_System_create(system)
call OpenMM_NonbondedForce_create(nonbond)
ix = OpenMM_System_addForce(system, transfer(nonbond, OpenMM_Force(0)))
! Create three atoms.
call OpenMM_Vec3Array_create(initPosInNm, 3)
do a=1,3
! Space the atoms out evenly by atom index.
call OpenMM_Vec3Array_set(initPosInNm, a, (/ 0.5d0*(a-1), 0d0, 0d0 /))
ix = OpenMM_System_addParticle(system, 39.95d0) !mass of Ar, grams/mole
! charge, L-J sigma (nm), well depth (kJ) (vdWRad(Ar)=.188 nm)
......@@ -55,7 +56,8 @@ PROGRAM HelloArgon
! Let OpenMM Context choose best platform.
call OpenMM_Context_create(context, system, &
transfer(verlet, OpenMM_Integrator(0)))
call OpenMM_Context_getPlatformName(context, platformName)
call OpenMM_Context_getPlatform(context, platform)
call OpenMM_Platform_getName(platform, platformName)
print "('REMARK Using OpenMM platform ', A)", platformName
! Set starting positions of the atoms. Leave time and velocity zero.
......@@ -65,7 +67,7 @@ PROGRAM HelloArgon
frameNum = 1
do
! Output current state information.
call OpenMM_Context_createState(context, OpenMM_State_Positions, state)
call OpenMM_Context_getState(context, OpenMM_State_Positions, state)
timeInPs = OpenMM_State_getTime(state)
call writePdbFrame(frameNum, state) !output coordinates
call OpenMM_State_destroy(state)
......@@ -93,16 +95,17 @@ SUBROUTINE writePDBFrame(frameNum, state)
integer frameNum
type(OpenMM_State) state
type(OpenMM_Vec3Array) posInNm
real*8 posInAng(3)
type(OpenMM_Vec3Array) allPosInNm
real*8 posInNm(3), posInAng(3)
integer n
! Reference atomic positions in the OpenMM State.
call OpenMM_State_getPositions(state, posInNm)
call OpenMM_State_getPositions(state, allPosInNm)
print "('MODEL',5X,I0)", frameNum ! start of frame
do n = 1,OpenMM_Vec3Array_size(posInNm)
call OpenMM_Vec3Array_getScaled(posInNm, n, 10d0, posInAng)
do n = 1,OpenMM_Vec3Array_getSize(allPosInNm)
call OpenMM_Vec3Array_get(allPosInNm, n, posInNm)
call OpenMM_Vec3_scale(posInNm, 10d0, posInAng)
print "('ATOM ', I5, ' AR AR 1 ', 3F8.3, ' 1.00 0.00')", &
n, posInAng
end do
......
......@@ -5,7 +5,7 @@
<Configurations>
<Configuration Name="Debug|Win32">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" Interfaces="true" WarnInterfaces="true" Traceback="true" BoundsCheck="true" RuntimeLibrary="rtMultiThreadedDebugDLL"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="C:\Program Files\OpenMM\lib" GenerateDebugInformation="true" SubSystem="subSystemConsole" AdditionalDependencies="OpenMM_CWrapper_d.lib OpenMM_d.lib"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="C:\Program Files\OpenMM\lib" GenerateDebugInformation="true" SubSystem="subSystemConsole" AdditionalDependencies="OpenMMCWrapper_d.lib OpenMM_d.lib"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
<Tool Name="VFCustomBuildTool"/>
......@@ -15,7 +15,7 @@
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
<Configuration Name="Release|Win32">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" RuntimeLibrary="rtMultiThreadedDLL"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="C:\Program Files\OpenMM\lib" SubSystem="subSystemConsole" AdditionalDependencies="OpenMM_CWrapper.lib OpenMM.lib"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="C:\Program Files\OpenMM\lib" SubSystem="subSystemConsole" AdditionalDependencies="OpenMMCWrapper.lib OpenMM.lib"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
<Tool Name="VFCustomBuildTool"/>
......@@ -28,5 +28,5 @@
<Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"/>
<Filter Name="Source Files" Filter="f90;for;f;fpp;ftn;def;odl;idl">
<File RelativePath="..\HelloArgonInFortran.f90"/>
<File RelativePath="..\OpenMM_Module.f90"/></Filter></Files>
<File RelativePath="..\OpenMMFortranModule.f90"/></Filter></Files>
<Globals/></VisualStudioProject>
......@@ -158,7 +158,7 @@ int main() {
* can use the implementation from the C++ version of this example if you
* want. However, the methods are reimplemented in C below in case you prefer.
*/
#include "OpenMM_CWrapper.h"
#include "OpenMMCWrapper.h"
struct MyOpenMMData_s {
......@@ -200,6 +200,7 @@ myInitializeOpenMM( const MyAtomInfo atoms[],
OpenMM_Vec3Array* initialPosInNm;
OpenMM_NonbondedForce* nonbond;
OpenMM_GBSAOBCForce* gbsa;
OpenMM_Platform* platform;
int n;
/* Load all available OpenMM plugins from their default location. */
......@@ -227,7 +228,7 @@ myInitializeOpenMM( const MyAtomInfo atoms[],
initialPosInNm = OpenMM_Vec3Array_create(0);
for (n=0; *atoms[n].pdb; ++n) {
const MyAtomInfo* atom = &atoms[n];
double posInNm[3];
OpenMM_Vec3 posInNm;
OpenMM_System_addParticle(omm->system, atom->mass);
......@@ -243,7 +244,7 @@ myInitializeOpenMM( const MyAtomInfo atoms[],
atom->gbsaScaleFactor);
/* Convert the initial position to nm and append to the array. */
OpenMM_Vec3_scale(atom->initPosInAng, OpenMM_NmPerAngstrom, posInNm);
posInNm = OpenMM_Vec3_scale(*(const OpenMM_Vec3*)atom->initPosInAng, OpenMM_NmPerAngstrom);
OpenMM_Vec3Array_append(initialPosInNm, posInNm);
}
......@@ -258,7 +259,8 @@ myInitializeOpenMM( const MyAtomInfo atoms[],
omm->context = OpenMM_Context_create(omm->system, omm->integrator);
OpenMM_Context_setPositions(omm->context, initialPosInNm);
*platformName = OpenMM_Context_getPlatformName(omm->context);
platform = OpenMM_Context_getPlatform(omm->context);
*platformName = OpenMM_Platform_getName(platform);
return omm;
}
......@@ -286,7 +288,7 @@ myGetOpenMMState(MyOpenMMData* omm, int wantEnergy,
/* Forces are also available (and cheap). */
/* State object is created here and must be explicitly destroyed below. */
state = OpenMM_Context_createState(omm->context, infoMask);
state = OpenMM_Context_getState(omm->context, infoMask);
*timeInPs = OpenMM_State_getTime(state); /* OpenMM time is in ps already. */
/* Positions are maintained as a Vec3Array inside the State. This will give
......@@ -294,8 +296,9 @@ myGetOpenMMState(MyOpenMMData* omm, int wantEnergy,
posArrayInNm = OpenMM_State_getPositions(state);
for (n=0; *atoms[n].pdb; ++n)
/* Sets atoms[n].pos = posArray[n] * Angstroms/nm. */
OpenMM_Vec3Array_getScaled(posArrayInNm, n, OpenMM_AngstromsPerNm,
atoms[n].posInAng);
*(OpenMM_Vec3*)atoms[n].posInAng =
OpenMM_Vec3_scale(*OpenMM_Vec3Array_get(posArrayInNm, n),
OpenMM_AngstromsPerNm);
/* If energy has been requested, obtain it and convert from kJ to kcal. */
*energyInKcal = 0;
......
This diff is collapsed.
......@@ -59,26 +59,30 @@ fortran: $(ALL_F95_EXAMPLES)
HelloArgon HelloSodiumChloride HelloEthane HelloWaterBox:
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $*.cpp /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloArgonInC: HelloArgonInC.c OpenMM_CWrapper.obj
$(CC) $(CFLAGS) -I. $*.c OpenMM_CWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloArgonInC: HelloArgonInC.c OpenMMCWrapper.obj
$(CC) $(CFLAGS) -I. $*.c OpenMMCWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloSodiumChlorideInC: HelloSodiumChlorideInC.c OpenMM_CWrapper.obj
$(CC) $(CFLAGS) -I. $*.c OpenMM_CWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloSodiumChlorideInC: HelloSodiumChlorideInC.c OpenMMCWrapper.obj
$(CC) $(CFLAGS) -I. $*.c OpenMMCWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloArgonInFortran: HelloArgonInFortran.f90 openmm.mod OpenMM_CWrapper.obj
$(FC) $(FFLAGS) $*.f90 OpenMM_CWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloArgonInFortran: HelloArgonInFortran.f90 openmm.mod OpenMMFortranWrapper.obj OpenMMCWrapper.obj
$(FC) $(FFLAGS) $*.f90 OpenMMFortranWrapper.obj OpenMMCWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloSodiumChlorideInFortran: HelloSodiumChlorideInFortran.f90 openmm.mod OpenMM_CWrapper.obj
$(FC) $(FFLAGS) $*.f90 OpenMM_CWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
HelloSodiumChlorideInFortran: HelloSodiumChlorideInFortran.f90 openmm.mod OpenMMFortranWrapper.obj OpenMMCWrapper.obj
$(FC) $(FFLAGS) $*.f90 OpenMMFortranWrapper.obj OpenMMCWrapper.obj /link /libpath:$(LIB_DIR) $(LIBS) /out:$*.exe
# Build C Wrappers (Fortran depends on this too)
OpenMM_CWrapper.obj: OpenMM_CWrapper.cpp
$(CC) $(CFLAGS) -c -I. -I$(INCLUDE_DIR) OpenMM_CWrapper.cpp
OpenMMCWrapper.obj: OpenMMCWrapper.cpp
$(CC) $(CFLAGS) -c -I. -I$(INCLUDE_DIR) OpenMMCWrapper.cpp
# Build Fortran Wrappers
OpenMMFortranWrapper.obj: OpenMMFortranWrapper.cpp
$(CC) $(CFLAGS) -c -I. -I$(INCLUDE_DIR) OpenMMFortranWrapper.cpp
# Build Fortran 95 Module file
openmm.mod: OpenMM_Module.f90
$(FC) -c $(FFLAGS) OpenMM_Module.f90
openmm.mod: OpenMMFortranModule.f90
$(FC) -c $(FFLAGS) OpenMMFortranModule.f90
clean :
del *.mod *.obj *.exe *.pdb *.exe.manifest
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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