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
9c8db8bf
Commit
9c8db8bf
authored
Jun 02, 2009
by
Michael Sherman
Browse files
fix up ugly line endings
parent
f809d190
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
85 deletions
+85
-85
examples/HelloSodiumChloride.cpp
examples/HelloSodiumChloride.cpp
+85
-85
No files found.
examples/HelloSodiumChloride.cpp
View file @
9c8db8bf
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
* OpenMM(tm) HelloSodiumChloride example (May 2009)
* OpenMM(tm) HelloSodiumChloride example (May 2009)
* -----------------------------------------------------------------------------
* -----------------------------------------------------------------------------
* This is a complete, self-contained "hello world" example demonstrating
* This is a complete, self-contained "hello world" example demonstrating
* GPU-accelerated constant energy simulation of a very simple system with just
* GPU-accelerated constant energy simulation of a very simple system with just
* nonbonded forces, consisting of several sodium (Na+) and chloride (Cl-) ions.
* nonbonded forces, consisting of several sodium (Na+) and chloride (Cl-) ions.
* A multi-frame PDB file is written to stdout which can be read by VMD or other
* 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.
* visualization tool to produce an animation of the 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 of Angstroms and kCals while correctly
* continue to work with Amber-style units of Angstroms and kCals while correctly
* communicating with OpenMM in nanometers and kJoules.
* communicating with OpenMM in nanometers and kJoules.
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
// Suppress irrelevant warnings from Microsoft's compiler.
// Suppress irrelevant warnings from Microsoft's compiler.
#ifdef _MSC_VER
#ifdef _MSC_VER
#pragma warning(disable:4996) // sprintf is unsafe
#pragma warning(disable:4996) // sprintf is unsafe
#pragma warning(disable:4251) // no dll interface for some classes
#pragma warning(disable:4251) // no dll interface for some classes
#endif
#endif
#include "OpenMM.h"
#include "OpenMM.h"
...
@@ -26,41 +26,41 @@
...
@@ -26,41 +26,41 @@
using
OpenMM
::
Vec3
;
// so we can just say "Vec3" below
using
OpenMM
::
Vec3
;
// so we can just say "Vec3" below
// -----------------------------------------------------------------------------
// MODELING AND SIMULATION PARAMETERS
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
const
double
StepSizeInFs
=
2
;
// integration step size (fs)
// MODELING AND SIMULATION PARAMETERS
const
double
ReportIntervalInFs
=
10
;
// how often to generate PDB frame (fs)
// -----------------------------------------------------------------------------
const
double
StepSizeInFs
=
2
;
// integration step size (fs)
const
double
ReportIntervalInFs
=
10
;
// how often to generate PDB frame (fs)
const
double
SimulationTimeInPs
=
100
;
// total simulation time (ps)
const
double
SimulationTimeInPs
=
100
;
// total simulation time (ps)
static
void
simulateNaCl
();
static
void
simulateNaCl
();
static
void
writePDB
(
const
OpenMM
::
OpenMMContext
&
);
// PDB file writer; see below.
static
void
writePDB
(
const
OpenMM
::
OpenMMContext
&
);
// PDB file writer; see below.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// MAIN PROGRAM
// MAIN PROGRAM
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
int
main
()
{
int
main
()
{
// ALWAYS enclose all OpenMM calls with a try/catch block to make sure that
// ALWAYS enclose all OpenMM calls with a try/catch block to make sure that
// usage and runtime errors are caught and reported.
// usage and runtime errors are caught and reported.
try
{
try
{
// Load all available OpenMM plugins from their default location.
// Load all available OpenMM plugins from their default location.
OpenMM
::
Platform
::
loadPluginsFromDirectory
OpenMM
::
Platform
::
loadPluginsFromDirectory
(
OpenMM
::
Platform
::
getDefaultPluginsDirectory
());
(
OpenMM
::
Platform
::
getDefaultPluginsDirectory
());
simulateNaCl
();
simulateNaCl
();
return
0
;
// Normal return from main.
return
0
;
// Normal return from main.
}
}
// Catch and report usage and runtime errors detected by OpenMM and fail.
// Catch and report usage and runtime errors detected by OpenMM and fail.
catch
(
const
std
::
exception
&
e
)
{
catch
(
const
std
::
exception
&
e
)
{
printf
(
"EXCEPTION: %s
\n
"
,
e
.
what
());
printf
(
"EXCEPTION: %s
\n
"
,
e
.
what
());
return
1
;
return
1
;
}
}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// ATOM AND FORCE FIELD DATA
// ATOM AND FORCE FIELD DATA
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// This is not part of OpenMM; just a struct we can use to collect
// This is not part of OpenMM; just a struct we can use to collect
// atom parameters for this example. Normally atom parameters would
// atom parameters for this example. Normally atom parameters would
...
@@ -83,22 +83,22 @@ struct AtomInfo {
...
@@ -83,22 +83,22 @@ struct AtomInfo {
{
""
}
// end of list
{
""
}
// end of list
};
};
// Add missing scalar product operators for OpenMM::Vec3.
// Add missing scalar product operators for OpenMM::Vec3.
Vec3
operator
*
(
const
Vec3
&
v
,
double
r
)
{
return
Vec3
(
v
[
0
]
*
r
,
v
[
1
]
*
r
,
v
[
2
]
*
r
);}
Vec3
operator
*
(
const
Vec3
&
v
,
double
r
)
{
return
Vec3
(
v
[
0
]
*
r
,
v
[
1
]
*
r
,
v
[
2
]
*
r
);}
Vec3
operator
*
(
double
r
,
const
Vec3
&
v
)
{
return
Vec3
(
r
*
v
[
0
],
r
*
v
[
1
],
r
*
v
[
2
]);}
Vec3
operator
*
(
double
r
,
const
Vec3
&
v
)
{
return
Vec3
(
r
*
v
[
0
],
r
*
v
[
1
],
r
*
v
[
2
]);}
// This is the conversion factor that takes you from a van der Waals radius
// This is the conversion factor that takes you from a van der Waals radius
// (defined as 1/2 the minimum energy separation) to the related Lennard Jones
// (defined as 1/2 the minimum energy separation) to the related Lennard Jones
// "sigma" parameter (defined as the zero crossing separation).
// "sigma" parameter (defined as the zero crossing separation).
static
const
double
SigmaPerVdwRadius
=
2
*
std
::
pow
(
2.
,
-
1.
/
6.
);
static
const
double
SigmaPerVdwRadius
=
2
*
std
::
pow
(
2.
,
-
1.
/
6.
);
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// NaCl SIMULATION
// NaCl SIMULATION
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
static
void
simulateNaCl
()
{
static
void
simulateNaCl
()
{
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Create a System and Force objects within the System. Retain a reference
// Create a System and Force objects within the System. Retain a reference
// to each force object so we can fill in the forces. Note: OpenMM owns
// to each force object so we can fill in the forces. Note: OpenMM owns
// the objects and will take care of deleting them; don't do it yourself!
// the objects and will take care of deleting them; don't do it yourself!
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
OpenMM
::
System
system
;
OpenMM
::
System
system
;
OpenMM
::
NonbondedForce
*
nonbond
=
new
OpenMM
::
NonbondedForce
();
OpenMM
::
NonbondedForce
*
nonbond
=
new
OpenMM
::
NonbondedForce
();
...
@@ -108,11 +108,11 @@ static void simulateNaCl() {
...
@@ -108,11 +108,11 @@ static void simulateNaCl() {
nonbond
->
setCutoffDistance
(
2
);
nonbond
->
setCutoffDistance
(
2
);
nonbond
->
setPeriodicBoxVectors
(
Vec3
(
5
,
0
,
0
),
Vec3
(
0
,
5
,
0
),
Vec3
(
0
,
0
,
5
));
nonbond
->
setPeriodicBoxVectors
(
Vec3
(
5
,
0
,
0
),
Vec3
(
0
,
5
,
0
),
Vec3
(
0
,
0
,
5
));
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// 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) Collect default positions for initializing the simulation later.
// (3) Collect default positions for initializing the simulation later.
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
std
::
vector
<
Vec3
>
initialPositions
;
std
::
vector
<
Vec3
>
initialPositions
;
for
(
int
n
=
0
;
*
atoms
[
n
].
pdb
;
++
n
)
{
for
(
int
n
=
0
;
*
atoms
[
n
].
pdb
;
++
n
)
{
...
@@ -122,25 +122,25 @@ static void simulateNaCl() {
...
@@ -122,25 +122,25 @@ static void simulateNaCl() {
atom
.
vdwRadiusInAng
*
OpenMM
::
NmPerAngstrom
atom
.
vdwRadiusInAng
*
OpenMM
::
NmPerAngstrom
*
SigmaPerVdwRadius
,
*
SigmaPerVdwRadius
,
atom
.
vdwEnergyInKcal
*
OpenMM
::
KJPerKcal
);
atom
.
vdwEnergyInKcal
*
OpenMM
::
KJPerKcal
);
initialPositions
.
push_back
(
atoms
[
n
].
initPosInAngstroms
initialPositions
.
push_back
(
atoms
[
n
].
initPosInAngstroms
*
OpenMM
::
NmPerAngstrom
);
*
OpenMM
::
NmPerAngstrom
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// 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.
// positions we collected above. Initial velocities will be zero.
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
OpenMM
::
VerletIntegrator
integrator
(
StepSizeInFs
*
OpenMM
::
PsPerFs
);
OpenMM
::
VerletIntegrator
integrator
(
StepSizeInFs
*
OpenMM
::
PsPerFs
);
OpenMM
::
OpenMMContext
context
(
system
,
integrator
);
OpenMM
::
OpenMMContext
context
(
system
,
integrator
);
context
.
setPositions
(
initialPositions
);
context
.
setPositions
(
initialPositions
);
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// 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.
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
printf
(
"REMARK Using OpenMM platform %s
\n
"
,
context
.
getPlatform
().
getName
().
c_str
()
);
printf
(
"REMARK Using OpenMM platform %s
\n
"
,
context
.
getPlatform
().
getName
().
c_str
()
);
writePDB
(
context
);
writePDB
(
context
);
...
@@ -152,8 +152,8 @@ static void simulateNaCl() {
...
@@ -152,8 +152,8 @@ static void simulateNaCl() {
}
while
(
context
.
getTime
()
<
SimulationTimeInPs
);
}
while
(
context
.
getTime
()
<
SimulationTimeInPs
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// PDB FILE WRITER
// PDB FILE WRITER
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
static
void
static
void
writePDB
(
const
OpenMM
::
OpenMMContext
&
context
)
{
writePDB
(
const
OpenMM
::
OpenMMContext
&
context
)
{
...
...
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