Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
2b1b486c
"platforms/reference/vscode:/vscode.git/clone" did not exist on "a416009a9f850944bf8cfb355712b2510182c02c"
Commit
2b1b486c
authored
Jun 17, 2011
by
Peter Eastman
Browse files
Added the enforcePeriodicBox flag to the C and Fortran wrappers
parent
9f700f0d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
471 additions
and
667 deletions
+471
-667
examples/CMakeLists.txt
examples/CMakeLists.txt
+2
-2
examples/HelloArgonInC.c
examples/HelloArgonInC.c
+1
-1
examples/HelloArgonInFortran.f90
examples/HelloArgonInFortran.f90
+113
-113
examples/HelloSodiumChlorideInC.c
examples/HelloSodiumChlorideInC.c
+1
-1
examples/HelloSodiumChlorideInFortran.f90
examples/HelloSodiumChlorideInFortran.f90
+346
-346
examples/HelloWaterBox.cpp
examples/HelloWaterBox.cpp
+1
-1
plugins/amoeba/wrappers/FortranWrapper_Source.xslt
plugins/amoeba/wrappers/FortranWrapper_Source.xslt
+0
-196
wrappers/CWrapper_Header.xslt
wrappers/CWrapper_Header.xslt
+1
-1
wrappers/CWrapper_Source.xslt
wrappers/CWrapper_Source.xslt
+2
-2
wrappers/FortranWrapper_Source.xslt
wrappers/FortranWrapper_Source.xslt
+4
-4
No files found.
examples/CMakeLists.txt
View file @
2b1b486c
...
@@ -53,7 +53,7 @@ FOREACH(EX_ROOT ${CPP_EXAMPLES})
...
@@ -53,7 +53,7 @@ FOREACH(EX_ROOT ${CPP_EXAMPLES})
ENDFOREACH
(
EX_ROOT
${
CPP_EXAMPLES
}
)
ENDFOREACH
(
EX_ROOT
${
CPP_EXAMPLES
}
)
# Only build wrapper examples if wrappers have been built
# Only build wrapper examples if wrappers have been built
IF
(
OPENMM_BUILD_
API
_WRAPPERS
)
IF
(
OPENMM_BUILD_
C_AND_FORTRAN
_WRAPPERS
)
INCLUDE_DIRECTORIES
(
BEFORE
${
PROJECT_BINARY_DIR
}
/wrappers
)
INCLUDE_DIRECTORIES
(
BEFORE
${
PROJECT_BINARY_DIR
}
/wrappers
)
FOREACH
(
EX_ROOT
${
C_EXAMPLES
}
)
FOREACH
(
EX_ROOT
${
C_EXAMPLES
}
)
...
@@ -83,7 +83,7 @@ IF(OPENMM_BUILD_API_WRAPPERS)
...
@@ -83,7 +83,7 @@ IF(OPENMM_BUILD_API_WRAPPERS)
ADD_DEPENDENCIES
(
${
EX_STATIC
}
ApiWrappers
)
ADD_DEPENDENCIES
(
${
EX_STATIC
}
ApiWrappers
)
ENDIF
(
BUILD_TESTING_STATIC
)
ENDIF
(
BUILD_TESTING_STATIC
)
ENDFOREACH
(
EX_ROOT
${
C_EXAMPLES
}
)
ENDFOREACH
(
EX_ROOT
${
C_EXAMPLES
}
)
ENDIF
(
OPENMM_BUILD_
API
_WRAPPERS
)
ENDIF
(
OPENMM_BUILD_
C_AND_FORTRAN
_WRAPPERS
)
FOREACH
(
EX_ROOT
${
C_EXAMPLES
}
)
FOREACH
(
EX_ROOT
${
C_EXAMPLES
}
)
INSTALL
(
FILES
${
EX_ROOT
}
.c DESTINATION examples
)
INSTALL
(
FILES
${
EX_ROOT
}
.c DESTINATION examples
)
...
...
examples/HelloArgonInC.c
View file @
2b1b486c
...
@@ -68,7 +68,7 @@ void simulateArgon()
...
@@ -68,7 +68,7 @@ void simulateArgon()
/* Simulate. */
/* Simulate. */
for
(
frameNum
=
1
;
;
++
frameNum
)
{
for
(
frameNum
=
1
;
;
++
frameNum
)
{
/* Output current state information. */
/* Output current state information. */
OpenMM_State
*
state
=
OpenMM_Context_getState
(
context
,
OpenMM_State_Positions
);
OpenMM_State
*
state
=
OpenMM_Context_getState
(
context
,
OpenMM_State_Positions
,
0
);
const
double
timeInPs
=
OpenMM_State_getTime
(
state
);
const
double
timeInPs
=
OpenMM_State_getTime
(
state
);
writePdbFrame
(
frameNum
,
state
);
/*output coordinates*/
writePdbFrame
(
frameNum
,
state
);
/*output coordinates*/
OpenMM_State_destroy
(
state
);
OpenMM_State_destroy
(
state
);
...
...
examples/HelloArgonInFortran.f90
View file @
2b1b486c
! -----------------------------------------------------------------------------
! -----------------------------------------------------------------------------
! OpenMM(tm) HelloArgon example in Fortran 95 (June 2009)
! OpenMM(tm) HelloArgon example in Fortran 95 (June 2009)
! -----------------------------------------------------------------------------
! -----------------------------------------------------------------------------
! This program demonstrates a simple molecular simulation using the OpenMM
! This program demonstrates a simple molecular simulation using the OpenMM
! API for GPU-accelerated molecular dynamics simulation. The primary goal is
! API for GPU-accelerated molecular dynamics simulation. The primary goal is
! to make sure you can compile, link, and run with OpenMM and view the output.
! to make sure you can compile, link, and run with OpenMM and view the output.
! The example is available in C++, C, and Fortran 95.
! The example is available in C++, C, and Fortran 95.
!
!
! The system modeled here is a small number of argon atoms in a vacuum.
! The system modeled here is a small number of argon atoms in a vacuum.
! A multi-frame PDB file is written to stdout which can be read by VMD or
! A multi-frame PDB file is written to stdout which can be read by VMD or
! other visualization tool to produce an animation of the resulting trajectory.
! other visualization tool to produce an animation of the resulting trajectory.
! -----------------------------------------------------------------------------
! -----------------------------------------------------------------------------
PROGRAM
HelloArgon
PROGRAM
HelloArgon
use
OpenMM
;
implicit
none
use
OpenMM
;
implicit
none
type
(
OpenMM_System
)
system
type
(
OpenMM_System
)
system
type
(
OpenMM_VerletIntegrator
)
verlet
type
(
OpenMM_VerletIntegrator
)
verlet
type
(
OpenMM_Context
)
context
type
(
OpenMM_Context
)
context
type
(
OpenMM_Platform
)
platform
type
(
OpenMM_Platform
)
platform
type
(
OpenMM_NonbondedForce
)
nonbond
type
(
OpenMM_NonbondedForce
)
nonbond
type
(
OpenMM_Vec3Array
)
initPosInNm
type
(
OpenMM_Vec3Array
)
initPosInNm
type
(
OpenMM_State
)
state
type
(
OpenMM_State
)
state
type
(
OpenMM_StringArray
)
pluginList
type
(
OpenMM_StringArray
)
pluginList
real
*
8
timeInPs
real
*
8
timeInPs
integer
*
4
a
,
ix
,
frameNum
integer
*
4
a
,
ix
,
frameNum
character
*
10
platformName
character
*
10
platformName
character
*
100
dirName
character
*
100
dirName
! Load any shared libraries containing GPU implementations.
! Load any shared libraries containing GPU implementations.
call
OpenMM_Platform_getDefaultPluginsDirectory
(
dirName
)
call
OpenMM_Platform_getDefaultPluginsDirectory
(
dirName
)
call
OpenMM_Platform_loadPluginsFromDirectory
(
dirName
,
pluginList
)
call
OpenMM_Platform_loadPluginsFromDirectory
(
dirName
,
pluginList
)
call
OpenMM_StringArray_destroy
(
pluginList
)
call
OpenMM_StringArray_destroy
(
pluginList
)
! Create a system with nonbonded forces. System takes ownership
! Create a system with nonbonded forces. System takes ownership
! of Force; don't destroy it yourself. (We're using transfer here
! of Force; don't destroy it yourself. (We're using transfer here
! to recast the specific NonbondedForce to a general Force.)
! to recast the specific NonbondedForce to a general Force.)
call
OpenMM_System_create
(
system
)
call
OpenMM_System_create
(
system
)
call
OpenMM_NonbondedForce_create
(
nonbond
)
call
OpenMM_NonbondedForce_create
(
nonbond
)
ix
=
OpenMM_System_addForce
(
system
,
transfer
(
nonbond
,
OpenMM_Force
(
0
)))
ix
=
OpenMM_System_addForce
(
system
,
transfer
(
nonbond
,
OpenMM_Force
(
0
)))
! Create three atoms.
! Create three atoms.
call
OpenMM_Vec3Array_create
(
initPosInNm
,
3
)
call
OpenMM_Vec3Array_create
(
initPosInNm
,
3
)
do
a
=
1
,
3
do
a
=
1
,
3
! Space the atoms out evenly by atom index.
! Space the atoms out evenly by atom index.
call
OpenMM_Vec3Array_set
(
initPosInNm
,
a
,
(/
0.5d0
*
(
a
-1
),
0d0
,
0d0
/))
call
OpenMM_Vec3Array_set
(
initPosInNm
,
a
,
(/
0.5d0
*
(
a
-1
),
0d0
,
0d0
/))
ix
=
OpenMM_System_addParticle
(
system
,
39.95d0
)
!mass of Ar, grams/mole
ix
=
OpenMM_System_addParticle
(
system
,
39.95d0
)
!mass of Ar, grams/mole
! charge, L-J sigma (nm), well depth (kJ) (vdWRad(Ar)=.188 nm)
! charge, L-J sigma (nm), well depth (kJ) (vdWRad(Ar)=.188 nm)
ix
=
OpenMM_NonbondedForce_addParticle
(
nonbond
,
0d0
,
0.3350d0
,
0.996d0
)
ix
=
OpenMM_NonbondedForce_addParticle
(
nonbond
,
0d0
,
0.3350d0
,
0.996d0
)
end
do
end
do
! Create particular integrator, and recast to generic one.
! Create particular integrator, and recast to generic one.
call
OpenMM_VerletIntegrator_create
(
verlet
,
4d-3
)
!step size in ps
call
OpenMM_VerletIntegrator_create
(
verlet
,
4d-3
)
!step size in ps
! Let OpenMM Context choose best platform.
! Let OpenMM Context choose best platform.
call
OpenMM_Context_create
(
context
,
system
,
&
call
OpenMM_Context_create
(
context
,
system
,
&
transfer
(
verlet
,
OpenMM_Integrator
(
0
)))
transfer
(
verlet
,
OpenMM_Integrator
(
0
)))
call
OpenMM_Context_getPlatform
(
context
,
platform
)
call
OpenMM_Context_getPlatform
(
context
,
platform
)
call
OpenMM_Platform_getName
(
platform
,
platformName
)
call
OpenMM_Platform_getName
(
platform
,
platformName
)
print
"('REMARK Using OpenMM platform ', A)"
,
platformName
print
"('REMARK Using OpenMM platform ', A)"
,
platformName
! Set starting positions of the atoms. Leave time and velocity zero.
! Set starting positions of the atoms. Leave time and velocity zero.
call
OpenMM_Context_setPositions
(
context
,
initPosInNm
)
call
OpenMM_Context_setPositions
(
context
,
initPosInNm
)
! Simulate.
! Simulate.
frameNum
=
1
frameNum
=
1
do
do
! Output current state information.
! Output current state information.
call
OpenMM_Context_getState
(
context
,
OpenMM_State_Positions
,
state
)
call
OpenMM_Context_getState
(
context
,
OpenMM_State_Positions
,
state
,
0
)
timeInPs
=
OpenMM_State_getTime
(
state
)
timeInPs
=
OpenMM_State_getTime
(
state
)
call
writePdbFrame
(
frameNum
,
state
)
!output coordinates
call
writePdbFrame
(
frameNum
,
state
)
!output coordinates
call
OpenMM_State_destroy
(
state
)
call
OpenMM_State_destroy
(
state
)
if
(
timeInPs
.ge.
10.
)
then
if
(
timeInPs
.ge.
10.
)
then
exit
exit
end
if
end
if
! Advance state many steps at a time, for efficient use of OpenMM.
! Advance state many steps at a time, for efficient use of OpenMM.
! (use a lot more than 10 normally)
! (use a lot more than 10 normally)
call
OpenMM_VerletIntegrator_step
(
verlet
,
10
)
call
OpenMM_VerletIntegrator_step
(
verlet
,
10
)
frameNum
=
frameNum
+
1
frameNum
=
frameNum
+
1
end
do
end
do
! Free heap space for all the objects created above.
! Free heap space for all the objects created above.
call
OpenMM_Vec3Array_destroy
(
initPosInNm
)
call
OpenMM_Vec3Array_destroy
(
initPosInNm
)
call
OpenMM_Context_destroy
(
context
)
call
OpenMM_Context_destroy
(
context
)
call
OpenMM_VerletIntegrator_destroy
(
verlet
)
call
OpenMM_VerletIntegrator_destroy
(
verlet
)
call
OpenMM_System_destroy
(
system
)
call
OpenMM_System_destroy
(
system
)
END
PROGRAM
END
PROGRAM
! Handy homebrew PDB writer for quick-and-dirty trajectory output.
! Handy homebrew PDB writer for quick-and-dirty trajectory output.
SUBROUTINE
writePDBFrame
(
frameNum
,
state
)
SUBROUTINE
writePDBFrame
(
frameNum
,
state
)
use
OpenMM
;
implicit
none
use
OpenMM
;
implicit
none
integer
frameNum
integer
frameNum
type
(
OpenMM_State
)
state
type
(
OpenMM_State
)
state
type
(
OpenMM_Vec3Array
)
allPosInNm
type
(
OpenMM_Vec3Array
)
allPosInNm
real
*
8
posInNm
(
3
),
posInAng
(
3
)
real
*
8
posInNm
(
3
),
posInAng
(
3
)
integer
n
integer
n
! Reference atomic positions in the OpenMM State.
! Reference atomic positions in the OpenMM State.
call
OpenMM_State_getPositions
(
state
,
allPosInNm
)
call
OpenMM_State_getPositions
(
state
,
allPosInNm
)
print
"('MODEL',5X,I0)"
,
frameNum
! start of frame
print
"('MODEL',5X,I0)"
,
frameNum
! start of frame
do
n
=
1
,
OpenMM_Vec3Array_getSize
(
allPosInNm
)
do
n
=
1
,
OpenMM_Vec3Array_getSize
(
allPosInNm
)
call
OpenMM_Vec3Array_get
(
allPosInNm
,
n
,
posInNm
)
call
OpenMM_Vec3Array_get
(
allPosInNm
,
n
,
posInNm
)
call
OpenMM_Vec3_scale
(
posInNm
,
10d0
,
posInAng
)
call
OpenMM_Vec3_scale
(
posInNm
,
10d0
,
posInAng
)
print
"('ATOM ', I5, ' AR AR 1 ', 3F8.3, ' 1.00 0.00')"
,
&
print
"('ATOM ', I5, ' AR AR 1 ', 3F8.3, ' 1.00 0.00')"
,
&
n
,
posInAng
n
,
posInAng
end
do
end
do
print
"('ENDMDL')"
print
"('ENDMDL')"
END
SUBROUTINE
END
SUBROUTINE
examples/HelloSodiumChlorideInC.c
View file @
2b1b486c
...
@@ -289,7 +289,7 @@ myGetOpenMMState(MyOpenMMData* omm, int wantEnergy,
...
@@ -289,7 +289,7 @@ myGetOpenMMState(MyOpenMMData* omm, int wantEnergy,
/* Forces are also available (and cheap). */
/* Forces are also available (and cheap). */
/* State object is created here and must be explicitly destroyed below. */
/* State object is created here and must be explicitly destroyed below. */
state
=
OpenMM_Context_getState
(
omm
->
context
,
infoMask
);
state
=
OpenMM_Context_getState
(
omm
->
context
,
infoMask
,
0
);
*
timeInPs
=
OpenMM_State_getTime
(
state
);
/* OpenMM time is in ps already. */
*
timeInPs
=
OpenMM_State_getTime
(
state
);
/* OpenMM time is in ps already. */
/* Positions are maintained as a Vec3Array inside the State. This will give
/* Positions are maintained as a Vec3Array inside the State. This will give
...
...
examples/HelloSodiumChlorideInFortran.f90
View file @
2b1b486c
! -----------------------------------------------------------------------------
! -----------------------------------------------------------------------------
! OpenMM(tm) HelloSodiumChloride example in Fortran 95 (June 2009)
! OpenMM(tm) HelloSodiumChloride example in Fortran 95 (June 2009)
! ------------------------------------------------------------------------------
! ------------------------------------------------------------------------------
! This is a complete, self-contained "hello world" example demonstrating
! This is a complete, self-contained "hello world" example demonstrating
! GPU-accelerated constant temperature simulation of a very simple system with
! GPU-accelerated constant temperature simulation of a very simple system with
! just nonbonded forces, consisting of several sodium (Na+) and chloride (Cl-)
! just nonbonded forces, consisting of several sodium (Na+) and chloride (Cl-)
! ions in implicit solvent. A multi-frame PDB file is written to stdout which
! ions in implicit solvent. A multi-frame PDB file is written to stdout which
! can be read by VMD or other visualization tool to produce an animation of the
! can be read by VMD or other visualization tool to produce an animation of the
! resulting trajectory.
! resulting trajectory.
!
!
! Pay particular attention to the handling of units in this example. Incorrect
! Pay particular attention to the handling of units in this example. Incorrect
! handling of units is a very common error; this example shows how you can
! handling of units is a very common error; this example shows how you can
! 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 the OpenMM Fortran
! This example is written entirely in Fortran 95, using the OpenMM Fortran
! interface module.
! interface module.
! ------------------------------------------------------------------------------
! ------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! ATOM, FORCE FIELD, AND SIMULATION PARAMETERS
! ATOM, FORCE FIELD, AND SIMULATION PARAMETERS
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! We'll define this module as a simplified example of the kinds of data
! We'll define this module as a simplified example of the kinds of data
! structures that may already be in an MD program that is to be converted
! structures that may already be in an MD program that is to be converted
! to use OpenMM. Note that we're using data in Angstrom and kcal units; we'll
! to use OpenMM. Note that we're using data in Angstrom and kcal units; we'll
! show how to safely convert to and from OpenMM's internal units as we go.
! show how to safely convert to and from OpenMM's internal units as we go.
MODULE
MyAtomInfo
MODULE
MyAtomInfo
! Simulation parameters
! Simulation parameters
! ---------------------
! ---------------------
real
*
8
Temperature
,
FrictionInPerPs
,
SolventDielectric
,
SoluteDielectric
real
*
8
Temperature
,
FrictionInPerPs
,
SolventDielectric
,
SoluteDielectric
parameter
(
Temperature
=
300
)
!Kelvins
parameter
(
Temperature
=
300
)
!Kelvins
parameter
(
FrictionInPerPs
=
91
)
!collisions per picosecond
parameter
(
FrictionInPerPs
=
91
)
!collisions per picosecond
parameter
(
SolventDielectric
=
80
)
!typical for water
parameter
(
SolventDielectric
=
80
)
!typical for water
parameter
(
SoluteDielectric
=
2
)
!typical for protein
parameter
(
SoluteDielectric
=
2
)
!typical for protein
real
*
8
StepSizeInFs
,
ReportIntervalInFs
,
SimulationTimeInPs
real
*
8
StepSizeInFs
,
ReportIntervalInFs
,
SimulationTimeInPs
parameter
(
StepSizeInFs
=
2
)
!integration step size (fs)
parameter
(
StepSizeInFs
=
2
)
!integration step size (fs)
parameter
(
ReportIntervalInFs
=
50
)
!how often for PDB frame (fs)
parameter
(
ReportIntervalInFs
=
50
)
!how often for PDB frame (fs)
parameter
(
SimulationTimeInPs
=
100
)
!total simulation time (ps)
parameter
(
SimulationTimeInPs
=
100
)
!total simulation time (ps)
! Currently energy calculation is not available in the GPU kernels so
! Currently energy calculation is not available in the GPU kernels so
! asking for it requires slow Reference Platform computation at
! asking for it requires slow Reference Platform computation at
! reporting intervals. If you have a big system you'll want this off.
! reporting intervals. If you have a big system you'll want this off.
logical
,
parameter
::
WantEnergy
=
.true.
logical
,
parameter
::
WantEnergy
=
.true.
! Atom and force field information
! Atom and force field information
! --------------------------------
! --------------------------------
type
Atom
type
Atom
character
*
4
pdb
character
*
4
pdb
real
*
8
mass
,
charge
,
vdwRadiusInAng
,
vdwEnergyInKcal
real
*
8
mass
,
charge
,
vdwRadiusInAng
,
vdwEnergyInKcal
real
*
8
gbsaRadiusInAng
,
gbsaScaleFactor
real
*
8
gbsaRadiusInAng
,
gbsaScaleFactor
real
*
8
initPosInAng
(
3
)
real
*
8
initPosInAng
(
3
)
real
*
8
posInAng
(
3
)
! leave room for runtime state info
real
*
8
posInAng
(
3
)
! leave room for runtime state info
end
type
end
type
integer
,
parameter
::
NumAtoms
=
6
integer
,
parameter
::
NumAtoms
=
6
type
(
Atom
)
::
atoms
(
NumAtoms
)
=
(/
&
type
(
Atom
)
::
atoms
(
NumAtoms
)
=
(/
&
! pdb mass charge vdwRad vdwEnergy gbRad gbScale initPos runtime
! pdb mass charge vdwRad vdwEnergy gbRad gbScale initPos runtime
Atom
(
' NA '
,
22.99
,
1
,
1.8680
,
0.00277
,
1.992
,
0.8
,
(/
8
,
0
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' NA '
,
22.99
,
1
,
1.8680
,
0.00277
,
1.992
,
0.8
,
(/
8
,
0
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' CL '
,
35.45
,
-1
,
2.4700
,
0.1000
,
1.735
,
0.8
,
(/
-8
,
0
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' CL '
,
35.45
,
-1
,
2.4700
,
0.1000
,
1.735
,
0.8
,
(/
-8
,
0
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' NA '
,
22.99
,
1
,
1.8680
,
0.00277
,
1.992
,
0.8
,
(/
0
,
9
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' NA '
,
22.99
,
1
,
1.8680
,
0.00277
,
1.992
,
0.8
,
(/
0
,
9
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' CL '
,
35.45
,
-1
,
2.4700
,
0.1000
,
1.735
,
0.8
,
(/
0
,
-9
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' CL '
,
35.45
,
-1
,
2.4700
,
0.1000
,
1.735
,
0.8
,
(/
0
,
-9
,
0
/),
(/
0
,
0
,
0
/)),&
Atom
(
' NA '
,
22.99
,
1
,
1.8680
,
0.00277
,
1.992
,
0.8
,
(/
0
,
0
,
-10
/),
(/
0
,
0
,
0
/)),&
Atom
(
' NA '
,
22.99
,
1
,
1.8680
,
0.00277
,
1.992
,
0.8
,
(/
0
,
0
,
-10
/),
(/
0
,
0
,
0
/)),&
Atom
(
' CL '
,
35.45
,
-1
,
2.4700
,
0.1000
,
1.735
,
0.8
,
(/
0
,
0
,
10
/),
(/
0
,
0
,
0
/))
&
Atom
(
' CL '
,
35.45
,
-1
,
2.4700
,
0.1000
,
1.735
,
0.8
,
(/
0
,
0
,
10
/),
(/
0
,
0
,
0
/))
&
/)
/)
END
MODULE
END
MODULE
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! MAIN PROGRAM
! MAIN PROGRAM
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! This makes use of four subroutines that encapsulate all the OpenMM calls:
! This makes use of four subroutines that encapsulate all the OpenMM calls:
! myInitializeOpenMM
! myInitializeOpenMM
! myStepWithOpenMM
! myStepWithOpenMM
! myGetOpenMMState
! myGetOpenMMState
! myTerminateOpenMM
! myTerminateOpenMM
! and one minimalist PDB file writer that has nothing to do with OpenMM:
! and one minimalist PDB file writer that has nothing to do with OpenMM:
! myWritePDBFrame
! myWritePDBFrame
! All of these subroutines can be found later in this file. For use in a real
! All of these subroutines can be found later in this file. For use in a real
! MD code you would need to write your own interface routines along these lines.
! MD code you would need to write your own interface routines along these lines.
! Note that the main program does NOT include the OpenMM module.
! Note that the main program does NOT include the OpenMM module.
PROGRAM
HelloSodiumChloride
PROGRAM
HelloSodiumChloride
use
MyAtomInfo
use
MyAtomInfo
! Calculate the number of PDB frames we want to write out and how
! Calculate the number of PDB frames we want to write out and how
! many steps to take on the GPU in between.
! many steps to take on the GPU in between.
integer
NumReports
,
NumSilentSteps
integer
NumReports
,
NumSilentSteps
parameter
(
NumReports
=
(
SimulationTimeInPs
*
1000
/
ReportIntervalInFs
+
0.5
))
parameter
(
NumReports
=
(
SimulationTimeInPs
*
1000
/
ReportIntervalInFs
+
0.5
))
parameter
(
NumSilentSteps
=
(
ReportIntervalInFs
/
StepSizeInFs
+
0.5
))
parameter
(
NumSilentSteps
=
(
ReportIntervalInFs
/
StepSizeInFs
+
0.5
))
character
*
10
platformName
;
real
*
8
timeInPs
,
energyInKcal
;
integer
frame
character
*
10
platformName
;
real
*
8
timeInPs
,
energyInKcal
;
integer
frame
! This is an opaque handle to a container that holds the OpenMM runtime
! This is an opaque handle to a container that holds the OpenMM runtime
! objects. You can use any type for this purpose as long as it is
! objects. You can use any type for this purpose as long as it is
! big enough to hold a pointer. (If you use a pointer type you'll have
! big enough to hold a pointer. (If you use a pointer type you'll have
! to declare the subroutine interfaces before calling them.)
! to declare the subroutine interfaces before calling them.)
integer
*
8
ommHandle
integer
*
8
ommHandle
! Set up OpenMM data structures; returns platform name and handle.
! Set up OpenMM data structures; returns platform name and handle.
call
myInitializeOpenMM
(
ommHandle
,
platformName
)
call
myInitializeOpenMM
(
ommHandle
,
platformName
)
! Run the simulation:
! Run the simulation:
! (1) Write the first line of the PDB file and the initial configuration.
! (1) Write the first line of the PDB file and the initial configuration.
! (2) Run silently entirely within OpenMM between reporting intervals.
! (2) Run silently entirely within OpenMM between reporting intervals.
! (3) Write a PDB frame when the time comes.
! (3) Write a PDB frame when the time comes.
print
"('REMARK Using OpenMM platform ', A)"
,
platformName
print
"('REMARK Using OpenMM platform ', A)"
,
platformName
call
myGetOpenMMState
(
ommHandle
,
timeInPs
,
energyInKcal
)
call
myGetOpenMMState
(
ommHandle
,
timeInPs
,
energyInKcal
)
call
myWritePDBFrame
(
0
,
timeInPs
,
energyInKcal
)
call
myWritePDBFrame
(
0
,
timeInPs
,
energyInKcal
)
do
frame
=
1
,
NumReports
do
frame
=
1
,
NumReports
call
myStepWithOpenMM
(
ommHandle
,
NumSilentSteps
)
call
myStepWithOpenMM
(
ommHandle
,
NumSilentSteps
)
call
myGetOpenMMState
(
ommHandle
,
timeInPs
,
energyInKcal
)
call
myGetOpenMMState
(
ommHandle
,
timeInPs
,
energyInKcal
)
call
myWritePDBFrame
(
frame
,
timeInPs
,
energyInKcal
)
call
myWritePDBFrame
(
frame
,
timeInPs
,
energyInKcal
)
end
do
end
do
! Clean up OpenMM data structures.
! Clean up OpenMM data structures.
call
myTerminateOpenMM
(
ommHandle
)
call
myTerminateOpenMM
(
ommHandle
)
END
PROGRAM
END
PROGRAM
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! PDB FILE WRITER
! PDB FILE WRITER
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! Given state data which was written into the atoms array of the MyAtomInfo
! Given state data which was written into the atoms array of the MyAtomInfo
! module, output a single frame (pdb "model") of the trajectory. This has
! module, output a single frame (pdb "model") of the trajectory. This has
! nothing to do with OpenMM.
! nothing to do with OpenMM.
SUBROUTINE
myWritePDBFrame
(
frameNum
,
timeInPs
,
energyInKcal
)
SUBROUTINE
myWritePDBFrame
(
frameNum
,
timeInPs
,
energyInKcal
)
use
MyAtomInfo
;
implicit
none
use
MyAtomInfo
;
implicit
none
integer
frameNum
;
real
*
8
timeInPs
,
energyInKcal
integer
frameNum
;
real
*
8
timeInPs
,
energyInKcal
integer
n
integer
n
print
"('MODEL',5X,I0)"
,
frameNum
print
"('MODEL',5X,I0)"
,
frameNum
print
"('REMARK 250 time=', F0.3, ' picoseconds; Energy=', F0.3, ' kcal/mole')"
,
&
print
"('REMARK 250 time=', F0.3, ' picoseconds; Energy=', F0.3, ' kcal/mole')"
,
&
timeInPs
,
energyInKcal
timeInPs
,
energyInKcal
do
n
=
1
,
NumAtoms
do
n
=
1
,
NumAtoms
print
"('ATOM ', I5, ' ', A4, ' SLT 1 ', 3F8.3, ' 1.00 0.00')"
,
&
print
"('ATOM ', I5, ' ', A4, ' SLT 1 ', 3F8.3, ' 1.00 0.00')"
,
&
n
,
atoms
(
n
)
%
pdb
,
atoms
(
n
)
%
posInAng
n
,
atoms
(
n
)
%
pdb
,
atoms
(
n
)
%
posInAng
end
do
end
do
print
"('ENDMDL')"
print
"('ENDMDL')"
END
SUBROUTINE
END
SUBROUTINE
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! OpenMM-USING CODE
! OpenMM-USING CODE
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! The OpenMM Fortran interface module is included only at this point and below.
! The OpenMM Fortran interface module is included only at this point and below.
! Normally these subroutines would be in a separate compilation module; we're
! Normally these subroutines would be in a separate compilation module; we're
! including them here for simplicity. We suggest that you write them in C++
! including them here for simplicity. We suggest that you write them in C++
! if possible, using extern "C" functions to make then callable from your
! if possible, using extern "C" functions to make then callable from your
! Fortran main program. (See the C++ version of this example program for
! Fortran main program. (See the C++ version of this example program for
! an implementation of very similar routines.) However, these routines are
! an implementation of very similar routines.) However, these routines are
! reimplemented entirely in Fortran 95 below in case you prefer.
! reimplemented entirely in Fortran 95 below in case you prefer.
! ------------------------------------------------------------------------------
! ------------------------------------------------------------------------------
! INITIALIZE OpenMM DATA STRUCTURES
! INITIALIZE OpenMM DATA STRUCTURES
! ------------------------------------------------------------------------------
! ------------------------------------------------------------------------------
! We take these actions here:
! We take these actions here:
! (1) Load any available OpenMM plugins, e.g. Cuda and Brook.
! (1) Load any available OpenMM plugins, e.g. Cuda and Brook.
! (2) Fill the OpenMM::System with the force field parameters we want to
! (2) Fill the OpenMM::System with the force field parameters we want to
! use and the particular set of atoms to be simulated.
! use and the particular set of atoms to be simulated.
! (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) Return an opaque handle to the Context object and the name of the
! (5) Return an opaque handle to the Context object 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
! force field data structures so will need to be customized for each MD code.
! force field data structures so will need to be customized for each MD code.
SUBROUTINE
myInitializeOpenMM
(
ommHandle
,
platformName
)
SUBROUTINE
myInitializeOpenMM
(
ommHandle
,
platformName
)
use
OpenMM
;
use
MyAtomInfo
;
implicit
none
use
OpenMM
;
use
MyAtomInfo
;
implicit
none
integer
*
8
,
intent
(
out
)
::
ommHandle
integer
*
8
,
intent
(
out
)
::
ommHandle
character
*
10
,
intent
(
out
)
::
platformName
character
*
10
,
intent
(
out
)
::
platformName
! These are the objects we'll create here thare are stored in the
! These are the objects we'll create here thare are stored in the
! Context for later access. Don't forget to delete them at the end.
! Context for later access. Don't forget to delete them at the end.
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.
call
OpenMM_Platform_getDefaultPluginsDirectory
(
dirName
)
call
OpenMM_Platform_getDefaultPluginsDirectory
(
dirName
)
call
OpenMM_Platform_loadPluginsFromDirectory
(
dirName
,
pluginList
)
call
OpenMM_Platform_loadPluginsFromDirectory
(
dirName
,
pluginList
)
call
OpenMM_StringArray_destroy
(
pluginList
)
call
OpenMM_StringArray_destroy
(
pluginList
)
! Create a System and Force objects for it. The System will take
! Create a System and Force objects for it. The System will take
! over ownership of the Forces; don't destroy them yourself.
! over ownership of the Forces; don't destroy them yourself.
call
OpenMM_System_create
(
system
)
call
OpenMM_System_create
(
system
)
call
OpenMM_NonbondedForce_create
(
nonbond
)
call
OpenMM_NonbondedForce_create
(
nonbond
)
call
OpenMM_GBSAOBCForce_create
(
gbsa
)
call
OpenMM_GBSAOBCForce_create
(
gbsa
)
! Convert specific force types to generic OpenMM_Force so that we can
! Convert specific force types to generic OpenMM_Force so that we can
! add them to the OpenMM_System.
! add them to the OpenMM_System.
ix
=
OpenMM_System_addForce
(
system
,
transfer
(
nonbond
,
OpenMM_Force
(
0
)))
ix
=
OpenMM_System_addForce
(
system
,
transfer
(
nonbond
,
OpenMM_Force
(
0
)))
ix
=
OpenMM_System_addForce
(
system
,
transfer
(
gbsa
,
OpenMM_Force
(
0
)))
ix
=
OpenMM_System_addForce
(
system
,
transfer
(
gbsa
,
OpenMM_Force
(
0
)))
! Specify dielectrics for GBSA implicit solvation.
! Specify dielectrics for GBSA implicit solvation.
call
OpenMM_GBSAOBCForce_setSolventDielectric
(
gbsa
,
SolventDielectric
)
call
OpenMM_GBSAOBCForce_setSolventDielectric
(
gbsa
,
SolventDielectric
)
call
OpenMM_GBSAOBCForce_setSoluteDielectric
(
gbsa
,
SoluteDielectric
)
call
OpenMM_GBSAOBCForce_setSoluteDielectric
(
gbsa
,
SoluteDielectric
)
! Specify the atoms and their properties:
! Specify the atoms and their properties:
! (1) System needs to know the masses.
! (1) System needs to know the masses.
! (2) NonbondedForce needs charges,van der Waals properties (in MD units!).
! (2) NonbondedForce needs charges,van der Waals properties (in MD units!).
! (3) GBSA needs charge, radius, and scale factor.
! (3) GBSA needs charge, radius, and scale factor.
! (4) Collect default positions for initializing the simulation later.
! (4) Collect default positions for initializing the simulation later.
call
OpenMM_Vec3Array_create
(
initialPosInNm
,
NumAtoms
)
call
OpenMM_Vec3Array_create
(
initialPosInNm
,
NumAtoms
)
do
n
=
1
,
NumAtoms
do
n
=
1
,
NumAtoms
ix
=
OpenMM_System_addParticle
(
system
,
atoms
(
n
)
%
mass
)
ix
=
OpenMM_System_addParticle
(
system
,
atoms
(
n
)
%
mass
)
ix
=
OpenMM_NonbondedForce_addParticle
(
nonbond
,
&
ix
=
OpenMM_NonbondedForce_addParticle
(
nonbond
,
&
atoms
(
n
)
%
charge
,
&
atoms
(
n
)
%
charge
,
&
atoms
(
n
)
%
vdwRadiusInAng
*
OpenMM_NmPerAngstrom
&
atoms
(
n
)
%
vdwRadiusInAng
*
OpenMM_NmPerAngstrom
&
*
OpenMM_SigmaPerVdwRadius
,
&
*
OpenMM_SigmaPerVdwRadius
,
&
atoms
(
n
)
%
vdwEnergyInKcal
*
OpenMM_KJPerKcal
)
atoms
(
n
)
%
vdwEnergyInKcal
*
OpenMM_KJPerKcal
)
ix
=
OpenMM_GBSAOBCForce_addParticle
(
gbsa
,
&
ix
=
OpenMM_GBSAOBCForce_addParticle
(
gbsa
,
&
atoms
(
n
)
%
charge
,
&
atoms
(
n
)
%
charge
,
&
atoms
(
n
)
%
gbsaRadiusInAng
*
OpenMM_NmPerAngstrom
,
&
atoms
(
n
)
%
gbsaRadiusInAng
*
OpenMM_NmPerAngstrom
,
&
atoms
(
n
)
%
gbsaScaleFactor
)
atoms
(
n
)
%
gbsaScaleFactor
)
! Sets initPos(n) = atoms(n)%initPos * nm/Angstrom.
! Sets initPos(n) = atoms(n)%initPos * nm/Angstrom.
call
OpenMM_Vec3_scale
(
atoms
(
n
)
%
initPosInAng
,
&
call
OpenMM_Vec3_scale
(
atoms
(
n
)
%
initPosInAng
,
&
OpenMM_NmPerAngstrom
,
posInNm
)
OpenMM_NmPerAngstrom
,
posInNm
)
call
OpenMM_Vec3Array_set
(
initialPosInNm
,
n
,
posInNm
)
call
OpenMM_Vec3Array_set
(
initialPosInNm
,
n
,
posInNm
)
end
do
end
do
! Choose an Integrator for advancing time, and a Context connecting the
! Choose an Integrator for advancing time, and a Context connecting the
! System with the Integrator for simulation. Let the Context choose the
! System with the Integrator for simulation. Let the Context choose the
! best available Platform. Initialize the configuration from the default
! best available Platform. Initialize the configuration from the default
! positions we collected above. Initial velocities will be zero but could
! positions we collected above. Initial velocities will be zero but could
! have been set here.
! have been set here.
call
OpenMM_LangevinIntegrator_create
(
langevin
,
&
call
OpenMM_LangevinIntegrator_create
(
langevin
,
&
Temperature
,
FrictionInPerPs
,
&
Temperature
,
FrictionInPerPs
,
&
StepSizeInFs
*
OpenMM_PsPerFs
)
StepSizeInFs
*
OpenMM_PsPerFs
)
! Convert LangevinIntegrator to generic Integrator type for this call.
! Convert LangevinIntegrator to generic Integrator type for this call.
call
OpenMM_Context_create
(
context
,
system
,
&
call
OpenMM_Context_create
(
context
,
system
,
&
transfer
(
langevin
,
OpenMM_Integrator
(
0
)))
transfer
(
langevin
,
OpenMM_Integrator
(
0
)))
call
OpenMM_Context_setPositions
(
context
,
initialPosInNm
)
call
OpenMM_Context_setPositions
(
context
,
initialPosInNm
)
! Get the platform name to return.
! Get the platform name to return.
call
OpenMM_Context_getPlatform
(
context
,
platform
)
call
OpenMM_Context_getPlatform
(
context
,
platform
)
call
OpenMM_Platform_getName
(
platform
,
platformName
)
call
OpenMM_Platform_getName
(
platform
,
platformName
)
! References to the System and Integrator are in the Context, so
! References to the System and Integrator are in the Context, so
! we can extract them later for stepping and cleanup. Return an opaque
! we can extract them later for stepping and cleanup. Return an opaque
! reference to the Context for use by the main program.
! reference to the Context for use by the main program.
ommHandle
=
transfer
(
context
,
ommHandle
)
ommHandle
=
transfer
(
context
,
ommHandle
)
END
SUBROUTINE
END
SUBROUTINE
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! COPY STATE BACK TO CPU FROM OpenMM
! COPY STATE BACK TO CPU FROM OpenMM
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
SUBROUTINE
myGetOpenMMState
(
ommHandle
,
timeInPs
,
energyInKcal
)
SUBROUTINE
myGetOpenMMState
(
ommHandle
,
timeInPs
,
energyInKcal
)
use
OpenMM
;
use
MyAtomInfo
;
implicit
none
use
OpenMM
;
use
MyAtomInfo
;
implicit
none
integer
*
8
,
intent
(
in
)
::
ommHandle
integer
*
8
,
intent
(
in
)
::
ommHandle
real
*
8
,
intent
(
out
)
::
timeInPs
,
energyInKcal
real
*
8
,
intent
(
out
)
::
timeInPs
,
energyInKcal
type
(
OpenMM_State
)
state
type
(
OpenMM_State
)
state
type
(
OpenMM_Vec3Array
)
posArrayInNm
type
(
OpenMM_Vec3Array
)
posArrayInNm
integer
infoMask
,
n
integer
infoMask
,
n
real
*
8
posInNm
(
3
)
real
*
8
posInNm
(
3
)
type
(
OpenMM_Context
)
context
type
(
OpenMM_Context
)
context
context
=
transfer
(
ommHandle
,
context
)
context
=
transfer
(
ommHandle
,
context
)
infoMask
=
OpenMM_State_Positions
infoMask
=
OpenMM_State_Positions
if
(
WantEnergy
)
then
if
(
WantEnergy
)
then
infoMask
=
infoMask
+
OpenMM_State_Velocities
! for KE (cheap)
infoMask
=
infoMask
+
OpenMM_State_Velocities
! for KE (cheap)
infoMask
=
infoMask
+
OpenMM_State_Energy
! for PE (very expensive)
infoMask
=
infoMask
+
OpenMM_State_Energy
! for PE (very expensive)
end
if
end
if
! Forces are also available (and cheap).
! Forces are also available (and cheap).
! Don't forget to destroy this State when you're done with it.
! Don't forget to destroy this State when you're done with it.
call
OpenMM_Context_getState
(
context
,
infoMask
,
state
)
call
OpenMM_Context_getState
(
context
,
infoMask
,
state
,
0
)
timeInPs
=
OpenMM_State_getTime
(
state
)
! OpenMM time is in ps already.
timeInPs
=
OpenMM_State_getTime
(
state
)
! OpenMM time is in ps already.
! Positions are maintained as a Vec3Array inside the State. This will give
! Positions are maintained as a Vec3Array inside the State. This will give
! us access, but don't destroy it yourself -- it will go away with the State.
! us access, but don't destroy it yourself -- it will go away with the State.
call
OpenMM_State_getPositions
(
state
,
posArrayInNm
)
call
OpenMM_State_getPositions
(
state
,
posArrayInNm
)
do
n
=
1
,
NumAtoms
do
n
=
1
,
NumAtoms
! Sets atoms(n)%pos = posArray(n) * Angstroms/nm.
! Sets atoms(n)%pos = posArray(n) * Angstroms/nm.
call
OpenMM_Vec3Array_get
(
posArrayInNm
,
n
,
posInNm
)
call
OpenMM_Vec3Array_get
(
posArrayInNm
,
n
,
posInNm
)
call
OpenMM_Vec3_scale
(
posInNm
,
OpenMM_AngstromsPerNm
,
&
call
OpenMM_Vec3_scale
(
posInNm
,
OpenMM_AngstromsPerNm
,
&
atoms
(
n
)
%
posInAng
)
atoms
(
n
)
%
posInAng
)
end
do
end
do
energyInKcal
=
0
energyInKcal
=
0
if
(
WantEnergy
)
then
if
(
WantEnergy
)
then
energyInKcal
=
(
OpenMM_State_getPotentialEnergy
(
state
)
&
energyInKcal
=
(
OpenMM_State_getPotentialEnergy
(
state
)
&
+
OpenMM_State_getKineticEnergy
(
state
))
&
+
OpenMM_State_getKineticEnergy
(
state
))
&
*
OpenMM_KcalPerKJ
*
OpenMM_KcalPerKJ
end
if
end
if
! Clean up the State memory
! Clean up the State memory
call
OpenMM_State_destroy
(
state
)
call
OpenMM_State_destroy
(
state
)
END
SUBROUTINE
END
SUBROUTINE
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! TAKE MULTIPLE STEPS USING OpenMM
! TAKE MULTIPLE STEPS USING OpenMM
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
SUBROUTINE
myStepWithOpenMM
(
ommHandle
,
numSteps
)
SUBROUTINE
myStepWithOpenMM
(
ommHandle
,
numSteps
)
use
OpenMM
;
implicit
none
use
OpenMM
;
implicit
none
integer
*
8
,
intent
(
in
)
::
ommHandle
integer
*
8
,
intent
(
in
)
::
ommHandle
integer
,
intent
(
in
)
::
numSteps
integer
,
intent
(
in
)
::
numSteps
type
(
OpenMM_Context
)
context
type
(
OpenMM_Context
)
context
type
(
OpenMM_Integrator
)
integrator
type
(
OpenMM_Integrator
)
integrator
context
=
transfer
(
ommHandle
,
context
)
context
=
transfer
(
ommHandle
,
context
)
call
OpenMM_Context_getIntegrator
(
context
,
integrator
)
call
OpenMM_Context_getIntegrator
(
context
,
integrator
)
call
OpenMM_Integrator_step
(
integrator
,
numSteps
)
call
OpenMM_Integrator_step
(
integrator
,
numSteps
)
END
SUBROUTINE
END
SUBROUTINE
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! DEALLOCATE ALL OpenMM OBJECTS
! DEALLOCATE ALL OpenMM OBJECTS
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
SUBROUTINE
myTerminateOpenMM
(
ommHandle
)
SUBROUTINE
myTerminateOpenMM
(
ommHandle
)
use
OpenMM
;
implicit
none
use
OpenMM
;
implicit
none
integer
*
8
,
intent
(
inout
)
::
ommHandle
integer
*
8
,
intent
(
inout
)
::
ommHandle
type
(
OpenMM_Context
)
context
type
(
OpenMM_Context
)
context
type
(
OpenMM_Integrator
)
integrator
type
(
OpenMM_Integrator
)
integrator
type
(
OpenMM_System
)
system
type
(
OpenMM_System
)
system
context
=
transfer
(
ommHandle
,
context
)
context
=
transfer
(
ommHandle
,
context
)
call
OpenMM_Context_getIntegrator
(
context
,
integrator
)
call
OpenMM_Context_getIntegrator
(
context
,
integrator
)
call
OpenMM_Context_getSystem
(
context
,
system
)
call
OpenMM_Context_getSystem
(
context
,
system
)
call
OpenMM_Context_destroy
(
context
)
call
OpenMM_Context_destroy
(
context
)
call
OpenMM_Integrator_destroy
(
integrator
)
call
OpenMM_Integrator_destroy
(
integrator
)
call
OpenMM_System_destroy
(
system
)
call
OpenMM_System_destroy
(
system
)
END
SUBROUTINE
END
SUBROUTINE
examples/HelloWaterBox.cpp
View file @
2b1b486c
...
@@ -356,7 +356,7 @@ myGetOpenMMState(MyOpenMMData* omm, double& timeInPs,
...
@@ -356,7 +356,7 @@ myGetOpenMMState(MyOpenMMData* omm, double& timeInPs,
std
::
vector
<
double
>&
atomPositionsInAng
)
std
::
vector
<
double
>&
atomPositionsInAng
)
{
{
// We don't calculate energy in this example because it would take most of the time
// We don't calculate energy in this example because it would take most of the time
const
OpenMM
::
State
state
=
omm
->
context
->
getState
(
OpenMM
::
State
::
Positions
);
const
OpenMM
::
State
state
=
omm
->
context
->
getState
(
OpenMM
::
State
::
Positions
,
true
);
timeInPs
=
state
.
getTime
();
// OpenMM time is in ps already
timeInPs
=
state
.
getTime
();
// OpenMM time is in ps already
// Copy OpenMM positions into output array and change units from nm to Angstroms.
// Copy OpenMM positions into output array and change units from nm to Angstroms.
...
...
plugins/amoeba/wrappers/FortranWrapper_Source.xslt
View file @
2b1b486c
...
@@ -68,202 +68,6 @@ static string makeString(const char* fsrc, int length) {
...
@@ -68,202 +68,6 @@ static string makeString(const char* fsrc, int length) {
extern "C" {
extern "C" {
/* OpenMM_Vec3 */
OPENMM_EXPORT void openmm_vec3_scale_(const OpenMM_Vec3
&
vec, double const
&
scale, OpenMM_Vec3
&
result) {
result = OpenMM_Vec3_scale(vec, scale);
}
OPENMM_EXPORT void OPENMM_VEC3_SCALE(const OpenMM_Vec3
&
vec, double const
&
scale, OpenMM_Vec3
&
result) {
result = OpenMM_Vec3_scale(vec, scale);
}
/* OpenMM_Vec3Array */
OPENMM_EXPORT void openmm_vec3array_create_(OpenMM_Vec3Array*
&
result, const int
&
size) {
result = OpenMM_Vec3Array_create(size);
}
OPENMM_EXPORT void OPENMM_VEC3ARRAY_CREATE(OpenMM_Vec3Array*
&
result, const int
&
size) {
result = OpenMM_Vec3Array_create(size);
}
OPENMM_EXPORT void openmm_vec3array_destroy_(OpenMM_Vec3Array*
&
array) {
OpenMM_Vec3Array_destroy(array);
array = 0;
}
OPENMM_EXPORT void OPENMM_VEC3ARRAY_DESTROY(OpenMM_Vec3Array*
&
array) {
OpenMM_Vec3Array_destroy(array);
array = 0;
}
OPENMM_EXPORT int openmm_vec3array_getsize_(const OpenMM_Vec3Array* const
&
array) {
return OpenMM_Vec3Array_getSize(array);
}
OPENMM_EXPORT int OPENMM_VEC3ARRAY_GETSIZE(const OpenMM_Vec3Array* const
&
array) {
return OpenMM_Vec3Array_getSize(array);
}
OPENMM_EXPORT void openmm_vec3array_resize_(OpenMM_Vec3Array* const
&
array, const int
&
size) {
OpenMM_Vec3Array_resize(array, size);
}
OPENMM_EXPORT void OPENMM_VEC3ARRAY_RESIZE(OpenMM_Vec3Array* const
&
array, const int
&
size) {
OpenMM_Vec3Array_resize(array, size);
}
OPENMM_EXPORT void openmm_vec3array_append_(OpenMM_Vec3Array* const
&
array, const OpenMM_Vec3
&
vec) {
OpenMM_Vec3Array_append(array, vec);
}
OPENMM_EXPORT void OPENMM_VEC3ARRAY_APPEND(OpenMM_Vec3Array* const
&
array, const OpenMM_Vec3
&
vec) {
OpenMM_Vec3Array_append(array, vec);
}
OPENMM_EXPORT void openmm_vec3array_set_(OpenMM_Vec3Array* const
&
array, const int
&
index, const OpenMM_Vec3
&
vec) {
OpenMM_Vec3Array_set(array, index-1, vec);
}
OPENMM_EXPORT void OPENMM_VEC3ARRAY_SET(OpenMM_Vec3Array* const
&
array, const int
&
index, const OpenMM_Vec3
&
vec) {
OpenMM_Vec3Array_set(array, index-1, vec);
}
OPENMM_EXPORT void openmm_vec3array_get_(const OpenMM_Vec3Array* const
&
array, const int
&
index, OpenMM_Vec3
&
result) {
result = *OpenMM_Vec3Array_get(array, index-1);
}
OPENMM_EXPORT void OPENMM_VEC3ARRAY_GET(const OpenMM_Vec3Array* const
&
array, const int
&
index, OpenMM_Vec3
&
result) {
result = *OpenMM_Vec3Array_get(array, index-1);
}
/* OpenMM_StringArray */
OPENMM_EXPORT void openmm_stringarray_create_(OpenMM_StringArray*
&
result, const int
&
size) {
result = OpenMM_StringArray_create(size);
}
OPENMM_EXPORT void OPENMM_STRINGARRAY_CREATE(OpenMM_StringArray*
&
result, const int
&
size) {
result = OpenMM_StringArray_create(size);
}
OPENMM_EXPORT void openmm_stringarray_destroy_(OpenMM_StringArray*
&
array) {
OpenMM_StringArray_destroy(array);
array = 0;
}
OPENMM_EXPORT void OPENMM_STRINGARRAY_DESTROY(OpenMM_StringArray*
&
array) {
OpenMM_StringArray_destroy(array);
array = 0;
}
OPENMM_EXPORT int openmm_stringarray_getsize_(const OpenMM_StringArray* const
&
array) {
return OpenMM_StringArray_getSize(array);
}
OPENMM_EXPORT int OPENMM_STRINGARRAY_GETSIZE(const OpenMM_StringArray* const
&
array) {
return OpenMM_StringArray_getSize(array);
}
OPENMM_EXPORT void openmm_stringarray_resize_(OpenMM_StringArray* const
&
array, const int
&
size) {
OpenMM_StringArray_resize(array, size);
}
OPENMM_EXPORT void OPENMM_STRINGARRAY_RESIZE(OpenMM_StringArray* const
&
array, const int
&
size) {
OpenMM_StringArray_resize(array, size);
}
OPENMM_EXPORT void openmm_stringarray_append_(OpenMM_StringArray* const
&
array, const char* str, int length) {
OpenMM_StringArray_append(array, makeString(str, length).c_str());
}
OPENMM_EXPORT void OPENMM_STRINGARRAY_APPEND(OpenMM_StringArray* const
&
array, const char* str, int length) {
OpenMM_StringArray_append(array, makeString(str, length).c_str());
}
OPENMM_EXPORT void openmm_stringarray_set_(OpenMM_StringArray* const
&
array, const int
&
index, const char* str, int length) {
OpenMM_StringArray_set(array, index-1, makeString(str, length).c_str());
}
OPENMM_EXPORT void OPENMM_STRINGARRAY_SET(OpenMM_StringArray* const
&
array, const int
&
index, const char* str, int length) {
OpenMM_StringArray_set(array, index-1, makeString(str, length).c_str());
}
OPENMM_EXPORT 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);
copyAndPadString(result, str, length);
}
OPENMM_EXPORT 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);
copyAndPadString(result, str, length);
}
/* OpenMM_BondArray */
OPENMM_EXPORT void openmm_bondarray_create_(OpenMM_BondArray*
&
result, const int
&
size) {
result = OpenMM_BondArray_create(size);
}
OPENMM_EXPORT void OPENMM_BONDARRAY_CREATE(OpenMM_BondArray*
&
result, const int
&
size) {
result = OpenMM_BondArray_create(size);
}
OPENMM_EXPORT void openmm_bondarray_destroy_(OpenMM_BondArray*
&
array) {
OpenMM_BondArray_destroy(array);
array = 0;
}
OPENMM_EXPORT void OPENMM_BONDARRAY_DESTROY(OpenMM_BondArray*
&
array) {
OpenMM_BondArray_destroy(array);
array = 0;
}
OPENMM_EXPORT int openmm_bondarray_getsize_(const OpenMM_BondArray* const
&
array) {
return OpenMM_BondArray_getSize(array);
}
OPENMM_EXPORT int OPENMM_BONDARRAY_GETSIZE(const OpenMM_BondArray* const
&
array) {
return OpenMM_BondArray_getSize(array);
}
OPENMM_EXPORT void openmm_bondarray_resize_(OpenMM_BondArray* const
&
array, const int
&
size) {
OpenMM_BondArray_resize(array, size);
}
OPENMM_EXPORT void OPENMM_BONDARRAY_RESIZE(OpenMM_BondArray* const
&
array, const int
&
size) {
OpenMM_BondArray_resize(array, size);
}
OPENMM_EXPORT void openmm_bondarray_append_(OpenMM_BondArray* const
&
array, const int
&
particle1, const int
&
particle2) {
OpenMM_BondArray_append(array, particle1, particle2);
}
OPENMM_EXPORT void OPENMM_BONDARRAY_APPEND(OpenMM_BondArray* const
&
array, const int
&
particle1, const int
&
particle2) {
OpenMM_BondArray_append(array, particle1, particle2);
}
OPENMM_EXPORT void openmm_bondarray_set_(OpenMM_BondArray* const
&
array, const int
&
index, const int
&
particle1, const int
&
particle2) {
OpenMM_BondArray_set(array, index-1, particle1, particle2);
}
OPENMM_EXPORT void OPENMM_BONDARRAY_SET(OpenMM_BondArray* const
&
array, const int
&
index, const int
&
particle1, const int
&
particle2) {
OpenMM_BondArray_set(array, index-1, particle1, particle2);
}
OPENMM_EXPORT void openmm_bondarray_get_(const OpenMM_BondArray* const
&
array, const int
&
index, int* particle1, int* particle2) {
OpenMM_BondArray_get(array, index-1, particle1, particle2);
}
OPENMM_EXPORT void OPENMM_BONDARRAY_GET(const OpenMM_BondArray* const
&
array, const int
&
index, int* particle1, int* particle2) {
OpenMM_BondArray_get(array, index-1, particle1, particle2);
}
/* OpenMM_ParameterArray */
OPENMM_EXPORT int openmm_parameterarray_getsize_(const OpenMM_ParameterArray* const
&
array) {
return OpenMM_ParameterArray_getSize(array);
}
OPENMM_EXPORT int OPENMM_PARAMETERARRAY_GETSIZE(const OpenMM_ParameterArray* const
&
array) {
return OpenMM_ParameterArray_getSize(array);
}
OPENMM_EXPORT double openmm_parameterarray_get_(const OpenMM_ParameterArray* const
&
array, const char* name, int length) {
return OpenMM_ParameterArray_get(array, makeString(name, length).c_str());
}
OPENMM_EXPORT double OPENMM_PARAMETERARRAY_GET(const OpenMM_ParameterArray* const
&
array, const char* name, int length) {
return OpenMM_ParameterArray_get(array, makeString(name, length).c_str());
}
/* OpenMM_PropertyArray */
OPENMM_EXPORT int openmm_propertyarray_getsize_(const OpenMM_PropertyArray* const
&
array) {
return OpenMM_PropertyArray_getSize(array);
}
OPENMM_EXPORT int OPENMM_PROPERTYARRAY_GETSIZE(const OpenMM_PropertyArray* const
&
array) {
return OpenMM_PropertyArray_getSize(array);
}
OPENMM_EXPORT const char* openmm_propertyarray_get_(const OpenMM_PropertyArray* const
&
array, const char* name, int length) {
return OpenMM_PropertyArray_get(array, makeString(name, length).c_str());
}
OPENMM_EXPORT const char* OPENMM_PROPERTYARRAY_GET(const OpenMM_PropertyArray* const
&
array, const char* name, int length) {
return OpenMM_PropertyArray_get(array, makeString(name, length).c_str());
}
<xsl:call-template
name=
"primitive_array"
>
<xsl:with-param
name=
"element_type"
select=
"'int'"
/>
<xsl:with-param
name=
"name"
select=
"'OpenMM_IntArray'"
/>
</xsl:call-template>
/* These methods need to be handled specially, since their C++ APIs cannot be directly translated to C.
Unlike the C++ versions, the return value is allocated on the heap, and you must delete it yourself. */
OPENMM_EXPORT void openmm_context_getstate_(const OpenMM_Context*
&
target, int const
&
types, OpenMM_State*
&
result) {
result = OpenMM_Context_getState(target, types);
};
OPENMM_EXPORT void OPENMM_CONTEXT_GETSTATE(const OpenMM_Context*
&
target, int const
&
types, OpenMM_State*
&
result) {
result = OpenMM_Context_getState(target, types);
};
OPENMM_EXPORT void openmm_platform_loadpluginsfromdirectory_(const char* directory, OpenMM_StringArray*
&
result, int length) {
result = OpenMM_Platform_loadPluginsFromDirectory(makeString(directory, length).c_str());
};
OPENMM_EXPORT void OPENMM_PLATFORM_LOADPLUGINSFROMDIRECTORY(const char* directory, OpenMM_StringArray*
&
result, int length) {
result = OpenMM_Platform_loadPluginsFromDirectory(makeString(directory, length).c_str());
};
<!-- Class members -->
<!-- Class members -->
<xsl:for-each
select=
"Class[@context=$openmm_namespace_id and empty(index-of($skip_classes, @name))]"
>
<xsl:for-each
select=
"Class[@context=$openmm_namespace_id and empty(index-of($skip_classes, @name))]"
>
<xsl:call-template
name=
"class"
/>
<xsl:call-template
name=
"class"
/>
...
...
wrappers/CWrapper_Header.xslt
View file @
2b1b486c
...
@@ -100,7 +100,7 @@ extern OPENMM_EXPORT const char* OpenMM_PropertyArray_get(const OpenMM_PropertyA
...
@@ -100,7 +100,7 @@ extern OPENMM_EXPORT const char* OpenMM_PropertyArray_get(const OpenMM_PropertyA
/* These methods need to be handled specially, since their C++ APIs cannot be directly translated to C.
/* These methods need to be handled specially, since their C++ APIs cannot be directly translated to C.
Unlike the C++ versions, the return value is allocated on the heap, and you must delete it yourself. */
Unlike the C++ versions, the return value is allocated on the heap, and you must delete it yourself. */
extern OPENMM_EXPORT OpenMM_State* OpenMM_Context_getState(const OpenMM_Context* target, int types);
extern OPENMM_EXPORT OpenMM_State* OpenMM_Context_getState(const OpenMM_Context* target, int types
, int enforcePeriodicBox
);
extern OPENMM_EXPORT OpenMM_StringArray* OpenMM_Platform_loadPluginsFromDirectory(const char* directory);
extern OPENMM_EXPORT OpenMM_StringArray* OpenMM_Platform_loadPluginsFromDirectory(const char* directory);
<!-- Class members -->
<!-- Class members -->
...
...
wrappers/CWrapper_Source.xslt
View file @
2b1b486c
...
@@ -150,8 +150,8 @@ OPENMM_EXPORT const char* OpenMM_PropertyArray_get(const OpenMM_PropertyArray* a
...
@@ -150,8 +150,8 @@ OPENMM_EXPORT const char* OpenMM_PropertyArray_get(const OpenMM_PropertyArray* a
/* These methods need to be handled specially, since their C++ APIs cannot be directly translated to C.
/* These methods need to be handled specially, since their C++ APIs cannot be directly translated to C.
Unlike the C++ versions, the return value is allocated on the heap, and you must delete it yourself. */
Unlike the C++ versions, the return value is allocated on the heap, and you must delete it yourself. */
OPENMM_EXPORT OpenMM_State* OpenMM_Context_getState(const OpenMM_Context* target, int types) {
OPENMM_EXPORT OpenMM_State* OpenMM_Context_getState(const OpenMM_Context* target, int types
, int enforcePeriodicBox
) {
State result = reinterpret_cast
<
const Context*
>
(target)->getState(types);
State result = reinterpret_cast
<
const Context*
>
(target)->getState(types
, enforcePeriodicBox
);
return reinterpret_cast
<
OpenMM_State*
>
(new State(result));
return reinterpret_cast
<
OpenMM_State*
>
(new State(result));
};
};
OPENMM_EXPORT OpenMM_StringArray* OpenMM_Platform_loadPluginsFromDirectory(const char* directory) {
OPENMM_EXPORT OpenMM_StringArray* OpenMM_Platform_loadPluginsFromDirectory(const char* directory) {
...
...
wrappers/FortranWrapper_Source.xslt
View file @
2b1b486c
...
@@ -245,11 +245,11 @@ OPENMM_EXPORT const char* OPENMM_PROPERTYARRAY_GET(const OpenMM_PropertyArray* c
...
@@ -245,11 +245,11 @@ OPENMM_EXPORT const char* OPENMM_PROPERTYARRAY_GET(const OpenMM_PropertyArray* c
/* These methods need to be handled specially, since their C++ APIs cannot be directly translated to C.
/* These methods need to be handled specially, since their C++ APIs cannot be directly translated to C.
Unlike the C++ versions, the return value is allocated on the heap, and you must delete it yourself. */
Unlike the C++ versions, the return value is allocated on the heap, and you must delete it yourself. */
OPENMM_EXPORT void openmm_context_getstate_(const OpenMM_Context*
&
target, int const
&
types, OpenMM_State*
&
result) {
OPENMM_EXPORT void openmm_context_getstate_(const OpenMM_Context*
&
target, int const
&
types,
int const
&
enforcePeriodicBox,
OpenMM_State*
&
result) {
result = OpenMM_Context_getState(target, types);
result = OpenMM_Context_getState(target, types
, enforcePeriodicBox
);
};
};
OPENMM_EXPORT void OPENMM_CONTEXT_GETSTATE(const OpenMM_Context*
&
target, int const
&
types, OpenMM_State*
&
result) {
OPENMM_EXPORT void OPENMM_CONTEXT_GETSTATE(const OpenMM_Context*
&
target, int const
&
types,
int const
&
enforcePeriodicBox,
OpenMM_State*
&
result) {
result = OpenMM_Context_getState(target, types);
result = OpenMM_Context_getState(target, types
, enforcePeriodicBox
);
};
};
OPENMM_EXPORT void openmm_platform_loadpluginsfromdirectory_(const char* directory, OpenMM_StringArray*
&
result, int length) {
OPENMM_EXPORT void openmm_platform_loadpluginsfromdirectory_(const char* directory, OpenMM_StringArray*
&
result, int length) {
result = OpenMM_Platform_loadPluginsFromDirectory(makeString(directory, length).c_str());
result = OpenMM_Platform_loadPluginsFromDirectory(makeString(directory, length).c_str());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment