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
4c490d9c
Commit
4c490d9c
authored
Nov 01, 2015
by
Robert McGibbon
Browse files
Add test
parent
1a513a66
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
tests/TestEnforcePeriodicBox.cpp
tests/TestEnforcePeriodicBox.cpp
+65
-0
No files found.
tests/TestEnforcePeriodicBox.cpp
0 → 100644
View file @
4c490d9c
// ((6.7929, 0.0, 0.0), (-2.264163559406279, 6.404455775962287, 0.0), (-2.264163559406279, -3.2019384603140684, 5.54658849047036))
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/NonbondedForce.h"
#include "openmm/Platform.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testTrunactedOctahedron
()
{
const
int
numMolecules
=
5
;
const
int
numParticles
=
numMolecules
*
2
;
const
float
cutoff
=
2.0
;
Vec3
a
(
6.7929
,
0
,
0
);
Vec3
b
(
-
2.264163559406279
,
6.404455775962287
,
0
);
Vec3
c
(
-
2.264163559406279
,
-
3.2019384603140684
,
5.54658849047036
);
System
system
;
system
.
setDefaultPeriodicBoxVectors
(
a
,
b
,
c
);
NonbondedForce
*
force
=
new
NonbondedForce
();
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
vector
<
Vec3
>
positions
(
numParticles
);
force
->
setCutoffDistance
(
cutoff
);
force
->
setNonbondedMethod
(
NonbondedForce
::
CutoffPeriodic
);
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
force
->
addParticle
(
-
1
,
0.2
,
0.2
);
force
->
addParticle
(
1
,
0.2
,
0.2
);
positions
[
2
*
i
]
=
a
*
genrand_real2
(
sfmt
)
+
b
*
genrand_real2
(
sfmt
)
+
c
*
genrand_real2
(
sfmt
);
positions
[
2
*
i
+
1
]
=
positions
[
2
*
i
]
+
Vec3
(
1.0
,
0.0
,
0.0
);
system
.
addConstraint
(
2
*
i
,
2
*
i
+
1
,
1.0
);
}
system
.
addForce
(
force
);
VerletIntegrator
integrator
(
0.01
);
Context
context
(
system
,
integrator
,
Platform
::
getPlatformByName
(
"Reference"
));
context
.
setPositions
(
positions
);
State
initialState
=
context
.
getState
(
State
::
Positions
|
State
::
Energy
,
true
);
double
initialEnergy
=
initialState
.
getPotentialEnergy
();
context
.
setState
(
initialState
);
State
finalState
=
context
.
getState
(
State
::
Positions
|
State
::
Energy
,
true
);
double
finalEnergy
=
finalState
.
getPotentialEnergy
();
ASSERT_EQUAL_TOL
(
initialEnergy
,
finalEnergy
,
1e-4
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
testTrunactedOctahedron
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
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