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
050e1262
"plugins/amoeba/vscode:/vscode.git/clone" did not exist on "3e42a37290db1f20417020707caa5564eed72531"
Commit
050e1262
authored
Feb 05, 2015
by
Peter Eastman
Browse files
Bug fixes to triclinic boxes
parent
5b846af6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
28 deletions
+96
-28
platforms/cuda/src/CudaContext.cpp
platforms/cuda/src/CudaContext.cpp
+15
-10
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+5
-4
platforms/cuda/tests/TestCudaNonbondedForce.cpp
platforms/cuda/tests/TestCudaNonbondedForce.cpp
+28
-0
platforms/opencl/src/OpenCLContext.cpp
platforms/opencl/src/OpenCLContext.cpp
+15
-10
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+5
-4
platforms/opencl/tests/TestOpenCLNonbondedForce.cpp
platforms/opencl/tests/TestOpenCLNonbondedForce.cpp
+28
-0
No files found.
platforms/cuda/src/CudaContext.cpp
View file @
050e1262
...
@@ -1138,16 +1138,21 @@ void CudaContext::reorderAtomsImpl() {
...
@@ -1138,16 +1138,21 @@ void CudaContext::reorderAtomsImpl() {
// Move each molecule position into the same box.
// Move each molecule position into the same box.
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
int
xcell
=
(
int
)
floor
(
molPos
[
i
].
x
*
invPeriodicBoxSize
.
x
);
Real4
center
=
molPos
[
i
];
int
ycell
=
(
int
)
floor
(
molPos
[
i
].
y
*
invPeriodicBoxSize
.
y
);
int
zcell
=
(
int
)
floor
(
center
.
z
*
invPeriodicBoxSize
.
z
);
int
zcell
=
(
int
)
floor
(
molPos
[
i
].
z
*
invPeriodicBoxSize
.
z
);
center
.
x
-=
zcell
*
periodicBoxVecZ
.
x
;
Real
dx
=
xcell
*
periodicBoxSize
.
x
;
center
.
y
-=
zcell
*
periodicBoxVecZ
.
y
;
Real
dy
=
ycell
*
periodicBoxSize
.
y
;
center
.
z
-=
zcell
*
periodicBoxVecZ
.
z
;
Real
dz
=
zcell
*
periodicBoxSize
.
z
;
int
ycell
=
(
int
)
floor
(
center
.
y
*
invPeriodicBoxSize
.
y
);
if
(
dx
!=
0.0
f
||
dy
!=
0.0
f
||
dz
!=
0.0
f
)
{
center
.
x
-=
ycell
*
periodicBoxVecY
.
x
;
molPos
[
i
].
x
-=
dx
;
center
.
y
-=
ycell
*
periodicBoxVecY
.
y
;
molPos
[
i
].
y
-=
dy
;
int
xcell
=
(
int
)
floor
(
center
.
x
*
invPeriodicBoxSize
.
x
);
molPos
[
i
].
z
-=
dz
;
center
.
x
-=
xcell
*
periodicBoxVecX
.
x
;
if
(
xcell
!=
0
||
ycell
!=
0
||
zcell
!=
0
)
{
Real
dx
=
molPos
[
i
].
x
-
center
.
x
;
Real
dy
=
molPos
[
i
].
y
-
center
.
y
;
Real
dz
=
molPos
[
i
].
z
-
center
.
z
;
molPos
[
i
]
=
center
;
for
(
int
j
=
0
;
j
<
(
int
)
atoms
.
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
atoms
.
size
();
j
++
)
{
int
atom
=
atoms
[
j
]
+
mol
.
offsets
[
i
];
int
atom
=
atoms
[
j
]
+
mol
.
offsets
[
i
];
Real4
p
=
oldPosq
[
atom
];
Real4
p
=
oldPosq
[
atom
];
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
050e1262
...
@@ -147,14 +147,15 @@ void CudaUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3>&
...
@@ -147,14 +147,15 @@ void CudaUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3>&
const
vector
<
int
>&
order
=
cu
.
getAtomIndex
();
const
vector
<
int
>&
order
=
cu
.
getAtomIndex
();
int
numParticles
=
context
.
getSystem
().
getNumParticles
();
int
numParticles
=
context
.
getSystem
().
getNumParticles
();
positions
.
resize
(
numParticles
);
positions
.
resize
(
numParticles
);
double4
periodicBoxSize
=
cu
.
getPeriodicBoxSize
();
Vec3
boxVectors
[
3
];
cu
.
getPeriodicBoxVectors
(
boxVectors
[
0
],
boxVectors
[
1
],
boxVectors
[
2
]);
if
(
cu
.
getUseDoublePrecision
())
{
if
(
cu
.
getUseDoublePrecision
())
{
double4
*
posq
=
(
double4
*
)
cu
.
getPinnedBuffer
();
double4
*
posq
=
(
double4
*
)
cu
.
getPinnedBuffer
();
cu
.
getPosq
().
download
(
posq
);
cu
.
getPosq
().
download
(
posq
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
double4
pos
=
posq
[
i
];
double4
pos
=
posq
[
i
];
int4
offset
=
cu
.
getPosCellOffsets
()[
i
];
int4
offset
=
cu
.
getPosCellOffsets
()[
i
];
positions
[
order
[
i
]]
=
Vec3
(
pos
.
x
-
offset
.
x
*
periodicBoxSize
.
x
,
pos
.
y
-
offset
.
y
*
periodicBoxSize
.
y
,
pos
.
z
-
offset
.
z
*
periodicBoxSize
.
z
)
;
positions
[
order
[
i
]]
=
Vec3
(
pos
.
x
,
pos
.
y
,
pos
.
z
)
-
boxVectors
[
0
]
*
offset
.
x
-
boxVectors
[
1
]
*
offset
.
y
-
boxVectors
[
2
]
*
offset
.
z
;
}
}
}
}
else
if
(
cu
.
getUseMixedPrecision
())
{
else
if
(
cu
.
getUseMixedPrecision
())
{
...
@@ -166,7 +167,7 @@ void CudaUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3>&
...
@@ -166,7 +167,7 @@ void CudaUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3>&
float4
pos1
=
posq
[
i
];
float4
pos1
=
posq
[
i
];
float4
pos2
=
posCorrection
[
i
];
float4
pos2
=
posCorrection
[
i
];
int4
offset
=
cu
.
getPosCellOffsets
()[
i
];
int4
offset
=
cu
.
getPosCellOffsets
()[
i
];
positions
[
order
[
i
]]
=
Vec3
((
double
)
pos1
.
x
+
(
double
)
pos2
.
x
-
offset
.
x
*
periodicBoxSize
.
x
,
(
double
)
pos1
.
y
+
(
double
)
pos2
.
y
-
offset
.
y
*
periodicBoxSize
.
y
,
(
double
)
pos1
.
z
+
(
double
)
pos2
.
z
-
offset
.
z
*
periodicBoxSize
.
z
)
;
positions
[
order
[
i
]]
=
Vec3
((
double
)
pos1
.
x
+
(
double
)
pos2
.
x
,
(
double
)
pos1
.
y
+
(
double
)
pos2
.
y
,
(
double
)
pos1
.
z
+
(
double
)
pos2
.
z
)
-
boxVectors
[
0
]
*
offset
.
x
-
boxVectors
[
1
]
*
offset
.
y
-
boxVectors
[
2
]
*
offset
.
z
;
}
}
}
}
else
{
else
{
...
@@ -175,7 +176,7 @@ void CudaUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3>&
...
@@ -175,7 +176,7 @@ void CudaUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3>&
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
float4
pos
=
posq
[
i
];
float4
pos
=
posq
[
i
];
int4
offset
=
cu
.
getPosCellOffsets
()[
i
];
int4
offset
=
cu
.
getPosCellOffsets
()[
i
];
positions
[
order
[
i
]]
=
Vec3
(
pos
.
x
-
offset
.
x
*
periodicBoxSize
.
x
,
pos
.
y
-
offset
.
y
*
periodicBoxSize
.
y
,
pos
.
z
-
offset
.
z
*
periodicBoxSize
.
z
)
;
positions
[
order
[
i
]]
=
Vec3
(
pos
.
x
,
pos
.
y
,
pos
.
z
)
-
boxVectors
[
0
]
*
offset
.
x
-
boxVectors
[
1
]
*
offset
.
y
-
boxVectors
[
2
]
*
offset
.
z
;
}
}
}
}
}
}
...
...
platforms/cuda/tests/TestCudaNonbondedForce.cpp
View file @
050e1262
...
@@ -923,6 +923,33 @@ void testSwitchingFunction(NonbondedForce::NonbondedMethod method) {
...
@@ -923,6 +923,33 @@ void testSwitchingFunction(NonbondedForce::NonbondedMethod method) {
}
}
}
}
void
testReordering
()
{
// Check that reordering of atoms doesn't alter their positions.
const
int
numParticles
=
200
;
System
system
;
system
.
setDefaultPeriodicBoxVectors
(
Vec3
(
6
,
0
,
0
),
Vec3
(
2.1
,
6
,
0
),
Vec3
(
-
1.5
,
-
0.5
,
6
));
NonbondedForce
*
nonbonded
=
new
NonbondedForce
();
nonbonded
->
setNonbondedMethod
(
NonbondedForce
::
PME
);
system
.
addForce
(
nonbonded
);
vector
<
Vec3
>
positions
;
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
system
.
addParticle
(
1.0
);
nonbonded
->
addParticle
(
0.0
,
0.0
,
0.0
);
positions
.
push_back
(
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
)
*
20
);
}
VerletIntegrator
integrator
(
0.001
);
Context
context
(
system
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
integrator
.
step
(
1
);
State
state
=
context
.
getState
(
State
::
Positions
|
State
::
Velocities
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
ASSERT_EQUAL_VEC
(
positions
[
i
],
state
.
getPositions
()[
i
],
1e-6
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
try
{
if
(
argc
>
1
)
if
(
argc
>
1
)
...
@@ -944,6 +971,7 @@ int main(int argc, char* argv[]) {
...
@@ -944,6 +971,7 @@ int main(int argc, char* argv[]) {
testParallelComputation
(
NonbondedForce
::
PME
);
testParallelComputation
(
NonbondedForce
::
PME
);
testSwitchingFunction
(
NonbondedForce
::
CutoffNonPeriodic
);
testSwitchingFunction
(
NonbondedForce
::
CutoffNonPeriodic
);
testSwitchingFunction
(
NonbondedForce
::
PME
);
testSwitchingFunction
(
NonbondedForce
::
PME
);
testReordering
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/src/OpenCLContext.cpp
View file @
050e1262
...
@@ -1087,16 +1087,21 @@ void OpenCLContext::reorderAtomsImpl() {
...
@@ -1087,16 +1087,21 @@ void OpenCLContext::reorderAtomsImpl() {
// Move each molecule position into the same box.
// Move each molecule position into the same box.
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
int
xcell
=
(
int
)
floor
(
molPos
[
i
].
x
*
invPeriodicBoxSizeDouble
.
x
);
Real4
center
=
molPos
[
i
];
int
ycell
=
(
int
)
floor
(
molPos
[
i
].
y
*
invPeriodicBoxSizeDouble
.
y
);
int
zcell
=
(
int
)
floor
(
center
.
z
*
invPeriodicBoxSize
.
z
);
int
zcell
=
(
int
)
floor
(
molPos
[
i
].
z
*
invPeriodicBoxSizeDouble
.
z
);
center
.
x
-=
zcell
*
periodicBoxVecZ
.
x
;
Real
dx
=
xcell
*
periodicBoxSizeDouble
.
x
;
center
.
y
-=
zcell
*
periodicBoxVecZ
.
y
;
Real
dy
=
ycell
*
periodicBoxSizeDouble
.
y
;
center
.
z
-=
zcell
*
periodicBoxVecZ
.
z
;
Real
dz
=
zcell
*
periodicBoxSizeDouble
.
z
;
int
ycell
=
(
int
)
floor
(
center
.
y
*
invPeriodicBoxSize
.
y
);
if
(
dx
!=
0.0
f
||
dy
!=
0.0
f
||
dz
!=
0.0
f
)
{
center
.
x
-=
ycell
*
periodicBoxVecY
.
x
;
molPos
[
i
].
x
-=
dx
;
center
.
y
-=
ycell
*
periodicBoxVecY
.
y
;
molPos
[
i
].
y
-=
dy
;
int
xcell
=
(
int
)
floor
(
center
.
x
*
invPeriodicBoxSize
.
x
);
molPos
[
i
].
z
-=
dz
;
center
.
x
-=
xcell
*
periodicBoxVecX
.
x
;
if
(
xcell
!=
0
||
ycell
!=
0
||
zcell
!=
0
)
{
Real
dx
=
molPos
[
i
].
x
-
center
.
x
;
Real
dy
=
molPos
[
i
].
y
-
center
.
y
;
Real
dz
=
molPos
[
i
].
z
-
center
.
z
;
molPos
[
i
]
=
center
;
for
(
int
j
=
0
;
j
<
(
int
)
atoms
.
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
atoms
.
size
();
j
++
)
{
int
atom
=
atoms
[
j
]
+
mol
.
offsets
[
i
];
int
atom
=
atoms
[
j
]
+
mol
.
offsets
[
i
];
Real4
p
=
oldPosq
[
atom
];
Real4
p
=
oldPosq
[
atom
];
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
050e1262
...
@@ -170,14 +170,15 @@ void OpenCLUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3
...
@@ -170,14 +170,15 @@ void OpenCLUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3
const vector<cl_int>& order = cl.getAtomIndex();
const vector<cl_int>& order = cl.getAtomIndex();
int numParticles = context.getSystem().getNumParticles();
int numParticles = context.getSystem().getNumParticles();
positions.resize(numParticles);
positions.resize(numParticles);
mm_double4 periodicBoxSize = cl.getPeriodicBoxSizeDouble();
Vec3 boxVectors[3];
cl.getPeriodicBoxVectors(boxVectors[0], boxVectors[1], boxVectors[2]);
if (cl.getUseDoublePrecision()) {
if (cl.getUseDoublePrecision()) {
mm_double4* posq = (mm_double4*) cl.getPinnedBuffer();
mm_double4* posq = (mm_double4*) cl.getPinnedBuffer();
cl.getPosq().download(posq);
cl.getPosq().download(posq);
for (int i = 0; i < numParticles; ++i) {
for (int i = 0; i < numParticles; ++i) {
mm_double4 pos = posq[i];
mm_double4 pos = posq[i];
mm_int4 offset = cl.getPosCellOffsets()[i];
mm_int4 offset = cl.getPosCellOffsets()[i];
positions[order[i]] = Vec3(pos.x
-offset.x*periodicBoxSize.x, pos.y-offset.y*periodicBoxSize.y, pos.z-offset.z*periodicBoxSize
.z
)
;
positions[order[i]] = Vec3(pos.x
, pos.y, pos.z)-boxVectors[0]*offset.x-boxVectors[1]*offset.y-boxVectors[2]*offset
.z;
}
}
}
}
else if (cl.getUseMixedPrecision()) {
else if (cl.getUseMixedPrecision()) {
...
@@ -189,7 +190,7 @@ void OpenCLUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3
...
@@ -189,7 +190,7 @@ void OpenCLUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3
mm_float4 pos1 = posq[i];
mm_float4 pos1 = posq[i];
mm_float4 pos2 = posCorrection[i];
mm_float4 pos2 = posCorrection[i];
mm_int4 offset = cl.getPosCellOffsets()[i];
mm_int4 offset = cl.getPosCellOffsets()[i];
positions[order[i]] = Vec3((double)pos1.x+(double)pos2.x
-offset.x*periodicBoxSize.x
, (double)pos1.y+(double)pos2.y
-offset.y*periodicBoxSize.y
, (double)pos1.z+(double)pos2.z
-offset.z*periodicBoxSize
.z
)
;
positions[order[i]] = Vec3((double)pos1.x+(double)pos2.x, (double)pos1.y+(double)pos2.y, (double)pos1.z+(double)pos2.z
)-boxVectors[0]*offset.x-boxVectors[1]*offset.y-boxVectors[2]*offset
.z;
}
}
}
}
else {
else {
...
@@ -198,7 +199,7 @@ void OpenCLUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3
...
@@ -198,7 +199,7 @@ void OpenCLUpdateStateDataKernel::getPositions(ContextImpl& context, vector<Vec3
for (int i = 0; i < numParticles; ++i) {
for (int i = 0; i < numParticles; ++i) {
mm_float4 pos = posq[i];
mm_float4 pos = posq[i];
mm_int4 offset = cl.getPosCellOffsets()[i];
mm_int4 offset = cl.getPosCellOffsets()[i];
positions[order[i]] = Vec3(pos.x
-offset.x*periodicBoxSize.x, pos.y-offset.y*periodicBoxSize.y, pos.z-offset.z*periodicBoxSize
.z
)
;
positions[order[i]] = Vec3(pos.x
, pos.y, pos.z)-boxVectors[0]*offset.x-boxVectors[1]*offset.y-boxVectors[2]*offset
.z;
}
}
}
}
}
}
...
...
platforms/opencl/tests/TestOpenCLNonbondedForce.cpp
View file @
050e1262
...
@@ -926,6 +926,33 @@ void testSwitchingFunction(NonbondedForce::NonbondedMethod method) {
...
@@ -926,6 +926,33 @@ void testSwitchingFunction(NonbondedForce::NonbondedMethod method) {
}
}
}
}
void
testReordering
()
{
// Check that reordering of atoms doesn't alter their positions.
const
int
numParticles
=
200
;
System
system
;
system
.
setDefaultPeriodicBoxVectors
(
Vec3
(
6
,
0
,
0
),
Vec3
(
2.1
,
6
,
0
),
Vec3
(
-
1.5
,
-
0.5
,
6
));
NonbondedForce
*
nonbonded
=
new
NonbondedForce
();
nonbonded
->
setNonbondedMethod
(
NonbondedForce
::
PME
);
system
.
addForce
(
nonbonded
);
vector
<
Vec3
>
positions
;
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
system
.
addParticle
(
1.0
);
nonbonded
->
addParticle
(
0.0
,
0.0
,
0.0
);
positions
.
push_back
(
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
)
*
20
);
}
VerletIntegrator
integrator
(
0.001
);
Context
context
(
system
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
integrator
.
step
(
1
);
State
state
=
context
.
getState
(
State
::
Positions
|
State
::
Velocities
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
ASSERT_EQUAL_VEC
(
positions
[
i
],
state
.
getPositions
()[
i
],
1e-6
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
try
{
if
(
argc
>
1
)
if
(
argc
>
1
)
...
@@ -947,6 +974,7 @@ int main(int argc, char* argv[]) {
...
@@ -947,6 +974,7 @@ int main(int argc, char* argv[]) {
testParallelComputation
(
NonbondedForce
::
PME
);
testParallelComputation
(
NonbondedForce
::
PME
);
testSwitchingFunction
(
NonbondedForce
::
CutoffNonPeriodic
);
testSwitchingFunction
(
NonbondedForce
::
CutoffNonPeriodic
);
testSwitchingFunction
(
NonbondedForce
::
PME
);
testSwitchingFunction
(
NonbondedForce
::
PME
);
testReordering
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
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