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
403686a0
"platforms/vscode:/vscode.git/clone" did not exist on "3a0fa3b268f2c3206f3d8aaf9cb345010ab4e806"
Commit
403686a0
authored
Jun 11, 2009
by
Christopher Bruns
Browse files
Refactor HelloArgon toward better first example program
parent
fcd7b0c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
29 deletions
+59
-29
examples/HelloArgon.cpp
examples/HelloArgon.cpp
+59
-29
No files found.
examples/HelloArgon.cpp
View file @
403686a0
...
@@ -3,49 +3,79 @@
...
@@ -3,49 +3,79 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
void
writePdb
(
const
OpenMMContext
&
context
)
{
// forward declaration of subroutine defined later in this file.
const
State
state
=
context
.
getState
(
State
::
Positions
);
void
writePdb
(
const
OpenMMContext
&
context
);
const
std
::
vector
<
Vec3
>&
pos
=
state
.
getPositions
();
static
int
modelFrameNumber
=
0
;
// numbering for MODEL records in pdb output
void
simulateArgon
()
// write out in PDB format
{
modelFrameNumber
++
;
// Load any shared libraries containing GPU implementations
printf
(
"MODEL %d
\n
"
,
modelFrameNumber
);
Platform
::
loadPluginsFromDirectory
(
for
(
int
a
=
0
;
a
<
context
.
getSystem
().
getNumParticles
();
++
a
)
Platform
::
getDefaultPluginsDirectory
());
printf
(
"ATOM %5d AR AR 1 %8.3f%8.3f%8.3f 1.00 0.00 AR
\n
"
,
a
+
1
,
pos
[
a
][
0
]
*
10
,
pos
[
a
][
1
]
*
10
,
pos
[
a
][
2
]
*
10
);
printf
(
"ENDMDL
\n
"
);
}
int
main
()
{
Platform
::
loadPluginsFromDirectory
(
Platform
::
getDefaultPluginsDirectory
());
System
system
;
System
system
;
NonbondedForce
*
nonbond
=
new
NonbondedForce
();
NonbondedForce
*
nonbond
=
new
NonbondedForce
();
system
.
addForce
(
nonbond
);
system
.
addForce
(
nonbond
);
// Create atoms
// Create three atoms
int
numAtoms
=
3
;
std
::
vector
<
Vec3
>
initialPositions
(
3
);
for
(
int
a
=
0
;
a
<
numAtoms
;
++
a
)
{
for
(
int
a
=
0
;
a
<
3
;
++
a
)
{
system
.
addParticle
(
39.95
);
// mass
system
.
addParticle
(
39.95
);
// mass
nonbond
->
addParticle
(
0.0
,
0.3350
,
0.001603
);
// charge, diameter, well depth
nonbond
->
addParticle
(
0.0
,
0.3350
,
0.001603
);
// charge, sigma, well depth
initialPositions
[
a
]
=
Vec3
(
0.5
*
a
,
0
,
0
);
// location
}
}
// Large step size may be required for stability with small forces
VerletIntegrator
integrator
(
0.020
);
// step size in picoseconds
VerletIntegrator
integrator
(
0.020
);
// step size in picoseconds
// Let OpenMM Context choose best platform.
// Let OpenMM Context choose best platform.
OpenMMContext
context
(
system
,
integrator
);
OpenMMContext
context
(
system
,
integrator
);
printf
(
"REMARK Using OpenMM platform %s
\n
"
,
context
.
getPlatform
().
getName
().
c_str
()
);
printf
(
"REMARK Using OpenMM platform %s
\n
"
,
context
.
getPlatform
().
getName
().
c_str
()
);
// Set the starting positions in the OpenMM context. Velocities will be zero.
// Set the starting positions of the atoms. Velocities will be zero.
std
::
vector
<
Vec3
>
positions
(
numAtoms
);
context
.
setPositions
(
initialPositions
);
for
(
int
a
=
0
;
a
<
numAtoms
;
++
a
)
positions
[
a
]
=
Vec3
(
0.5
*
a
,
0
,
0
);
context
.
setPositions
(
positions
);
// Simulate
while
(
context
.
getTime
()
<
500.0
)
{
// picoseconds
while
(
context
.
getTime
()
<
500.0
)
{
// picoseconds
writePdb
(
context
);
writePdb
(
context
);
// output coordinates
integrator
.
step
(
100
);
// number of steps between reports
// Run 100 steps at a time, for efficient use of OpenMM
integrator
.
step
(
100
);
}
writePdb
(
context
);
// output final coordinates
}
int
main
()
{
try
{
simulateArgon
();
return
0
;
// success!
}
}
writePdb
(
context
);
// Catch and report usage and runtime errors detected by OpenMM and fail.
catch
(
const
std
::
exception
&
e
)
{
printf
(
"EXCEPTION: %s
\n
"
,
e
.
what
());
return
1
;
// failure!
}
}
// writePdb() subroutine for quick-and-dirty trajectory output.
void
writePdb
(
const
OpenMMContext
&
context
)
{
// Request atomic positions from OpenMM
const
State
state
=
context
.
getState
(
State
::
Positions
);
const
std
::
vector
<
Vec3
>&
pos
=
state
.
getPositions
();
return
0
;
// write out in PDB format
// Use PDB MODEL cards to number trajectory frames
static
int
modelFrameNumber
=
0
;
modelFrameNumber
++
;
printf
(
"MODEL %d
\n
"
,
modelFrameNumber
);
// start of frame
for
(
int
a
=
0
;
a
<
context
.
getSystem
().
getNumParticles
();
++
a
)
{
printf
(
"ATOM %5d AR AR 1 "
,
a
+
1
);
// atom number
printf
(
"%8.3f%8.3f%8.3f 1.00 0.00 AR
\n
"
,
// notice "*10" converts nanometers to Angstroms
pos
[
a
][
0
]
*
10
,
pos
[
a
][
1
]
*
10
,
pos
[
a
][
2
]
*
10
);
}
printf
(
"ENDMDL
\n
"
);
// end of frame
}
}
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