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
8df54762
Commit
8df54762
authored
Nov 19, 2013
by
Lee-Ping Wang
Browse files
Merge branch 'master' of github.com:leeping/openmm
parents
3cb25ad8
59854c5e
Changes
178
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
535 additions
and
211 deletions
+535
-211
platforms/reference/tests/TestReferenceNeighborList.cpp
platforms/reference/tests/TestReferenceNeighborList.cpp
+10
-11
platforms/reference/tests/TestReferenceSettle.cpp
platforms/reference/tests/TestReferenceSettle.cpp
+116
-0
platforms/reference/tests/TestReferenceVariableLangevinIntegrator.cpp
...ference/tests/TestReferenceVariableLangevinIntegrator.cpp
+33
-0
platforms/reference/tests/TestReferenceVariableVerletIntegrator.cpp
...reference/tests/TestReferenceVariableVerletIntegrator.cpp
+33
-0
platforms/reference/tests/TestReferenceVerletIntegrator.cpp
platforms/reference/tests/TestReferenceVerletIntegrator.cpp
+33
-0
plugins/amoeba/openmmapi/include/openmm/AmoebaMultipoleForce.h
...ns/amoeba/openmmapi/include/openmm/AmoebaMultipoleForce.h
+8
-0
plugins/amoeba/openmmapi/include/openmm/amoebaKernels.h
plugins/amoeba/openmmapi/include/openmm/amoebaKernels.h
+2
-0
plugins/amoeba/openmmapi/include/openmm/internal/AmoebaMultipoleForceImpl.h
...nmmapi/include/openmm/internal/AmoebaMultipoleForceImpl.h
+2
-0
plugins/amoeba/openmmapi/src/AmoebaMultipoleForce.cpp
plugins/amoeba/openmmapi/src/AmoebaMultipoleForce.cpp
+4
-0
plugins/amoeba/openmmapi/src/AmoebaMultipoleForceImpl.cpp
plugins/amoeba/openmmapi/src/AmoebaMultipoleForceImpl.cpp
+4
-0
plugins/amoeba/platforms/cuda/src/AmoebaCudaKernels.cpp
plugins/amoeba/platforms/cuda/src/AmoebaCudaKernels.cpp
+18
-0
plugins/amoeba/platforms/cuda/src/AmoebaCudaKernels.h
plugins/amoeba/platforms/cuda/src/AmoebaCudaKernels.h
+7
-0
plugins/amoeba/platforms/cuda/tests/TestCudaAmoebaMultipoleForce.cpp
...eba/platforms/cuda/tests/TestCudaAmoebaMultipoleForce.cpp
+38
-0
plugins/amoeba/platforms/reference/src/AmoebaReferenceKernels.cpp
...amoeba/platforms/reference/src/AmoebaReferenceKernels.cpp
+19
-4
plugins/amoeba/platforms/reference/src/AmoebaReferenceKernels.h
...s/amoeba/platforms/reference/src/AmoebaReferenceKernels.h
+7
-0
plugins/amoeba/platforms/reference/src/SimTKReference/AmoebaReferenceMultipoleForce.cpp
...ence/src/SimTKReference/AmoebaReferenceMultipoleForce.cpp
+22
-0
plugins/amoeba/platforms/reference/src/SimTKReference/AmoebaReferenceMultipoleForce.h
...erence/src/SimTKReference/AmoebaReferenceMultipoleForce.h
+32
-0
plugins/amoeba/platforms/reference/tests/TestReferenceAmoebaMultipoleForce.cpp
...rms/reference/tests/TestReferenceAmoebaMultipoleForce.cpp
+38
-0
plugins/cpupme/src/CpuPmeKernels.cpp
plugins/cpupme/src/CpuPmeKernels.cpp
+87
-156
plugins/drude/platforms/reference/src/ReferenceDrudeKernels.cpp
...s/drude/platforms/reference/src/ReferenceDrudeKernels.cpp
+22
-40
No files found.
platforms/reference/tests/TestReferenceNeighborList.cpp
View file @
8df54762
...
...
@@ -86,7 +86,7 @@ void verifyNeighborList(NeighborList& list, int numParticles, vector<RealVec>& p
for
(
int
j
=
i
+
1
;
j
<
numParticles
;
j
++
)
if
(
distance2
(
positions
[
i
],
positions
[
j
],
periodicBoxSize
)
<=
cutoff
*
cutoff
)
count
++
;
ASSERT
(
count
==
list
.
size
());
ASSERT
_EQUAL
(
count
,
list
.
size
());
}
void
testPeriodic
()
{
...
...
@@ -112,16 +112,15 @@ void testPeriodic() {
int
main
()
{
try
{
testNeighborList
();
testPeriodic
();
cout
<<
"Test Passed"
<<
endl
;
try
{
testNeighborList
();
testPeriodic
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
catch
(...)
{
cerr
<<
"*** ERROR: Test Failed ***"
<<
endl
;
return
1
;
}
}
platforms/reference/tests/TestReferenceSettle.cpp
0 → 100644
View file @
8df54762
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2009 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the reference implementation of the SETTLE algorithm.
*/
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "ReferencePlatform.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using
namespace
OpenMM
;
using
namespace
std
;
void
testConstraints
()
{
const
int
numMolecules
=
10
;
const
int
numParticles
=
numMolecules
*
3
;
const
int
numConstraints
=
numMolecules
*
3
;
const
double
temp
=
100.0
;
ReferencePlatform
platform
;
System
system
;
LangevinIntegrator
integrator
(
temp
,
2.0
,
0.001
);
integrator
.
setConstraintTolerance
(
1e-5
);
NonbondedForce
*
forceField
=
new
NonbondedForce
();
for
(
int
i
=
0
;
i
<
numMolecules
;
++
i
)
{
system
.
addParticle
(
16.0
);
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
forceField
->
addParticle
(
-
0.82
,
0.317
,
0.65
);
forceField
->
addParticle
(
0.41
,
1.0
,
0.0
);
forceField
->
addParticle
(
0.41
,
1.0
,
0.0
);
system
.
addConstraint
(
i
*
3
,
i
*
3
+
1
,
0.1
);
system
.
addConstraint
(
i
*
3
,
i
*
3
+
2
,
0.1
);
system
.
addConstraint
(
i
*
3
+
1
,
i
*
3
+
2
,
0.163
);
}
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
for
(
int
i
=
0
;
i
<
numMolecules
;
++
i
)
{
positions
[
i
*
3
]
=
Vec3
((
i
%
4
)
*
0.4
,
(
i
/
4
)
*
0.4
,
0
);
positions
[
i
*
3
+
1
]
=
positions
[
i
*
3
]
+
Vec3
(
0.1
,
0
,
0
);
positions
[
i
*
3
+
2
]
=
positions
[
i
*
3
]
+
Vec3
(
-
0.03333
,
0.09428
,
0
);
velocities
[
i
*
3
]
=
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
);
velocities
[
i
*
3
+
1
]
=
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
);
velocities
[
i
*
3
+
2
]
=
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
);
}
context
.
setPositions
(
positions
);
context
.
setVelocities
(
velocities
);
// Simulate it and see whether the constraints remain satisfied.
for
(
int
i
=
0
;
i
<
1000
;
++
i
)
{
integrator
.
step
(
1
);
State
state
=
context
.
getState
(
State
::
Positions
|
State
::
Forces
);
for
(
int
j
=
0
;
j
<
numConstraints
;
++
j
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
j
,
particle1
,
particle2
,
distance
);
Vec3
p1
=
state
.
getPositions
()[
particle1
];
Vec3
p2
=
state
.
getPositions
()[
particle2
];
double
dist
=
std
::
sqrt
((
p1
[
0
]
-
p2
[
0
])
*
(
p1
[
0
]
-
p2
[
0
])
+
(
p1
[
1
]
-
p2
[
1
])
*
(
p1
[
1
]
-
p2
[
1
])
+
(
p1
[
2
]
-
p2
[
2
])
*
(
p1
[
2
]
-
p2
[
2
]));
ASSERT_EQUAL_TOL
(
distance
,
dist
,
1e-5
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
testConstraints
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
platforms/reference/tests/TestReferenceVariableLangevinIntegrator.cpp
View file @
8df54762
...
...
@@ -173,6 +173,38 @@ void testConstraints() {
}
}
void
testConstrainedMasslessParticles
()
{
ReferencePlatform
platform
;
System
system
;
system
.
addParticle
(
0.0
);
system
.
addParticle
(
1.0
);
system
.
addConstraint
(
0
,
1
,
1.5
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
-
1
,
0
,
0
);
positions
[
1
]
=
Vec3
(
1
,
0
,
0
);
VariableLangevinIntegrator
integrator
(
300.0
,
2.0
,
0.01
);
bool
failed
=
false
;
try
{
// This should throw an exception.
Context
context
(
system
,
integrator
,
platform
);
}
catch
(
exception
&
ex
)
{
failed
=
true
;
}
ASSERT
(
failed
);
// Now make both particles massless, which should work.
system
.
setParticleMass
(
1
,
0.0
);
Context
context
(
system
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
context
.
setVelocitiesToTemperature
(
300.0
);
integrator
.
step
(
1
);
State
state
=
context
.
getState
(
State
::
Velocities
|
State
::
Positions
);
ASSERT_EQUAL
(
0.0
,
state
.
getVelocities
()[
0
][
0
]);
}
void
testRandomSeed
()
{
const
int
numParticles
=
8
;
const
double
temp
=
100.0
;
...
...
@@ -296,6 +328,7 @@ int main() {
testSingleBond
();
testTemperature
();
testConstraints
();
testConstrainedMasslessParticles
();
testRandomSeed
();
testArgonBox
();
}
...
...
platforms/reference/tests/TestReferenceVariableVerletIntegrator.cpp
View file @
8df54762
...
...
@@ -210,6 +210,38 @@ void testConstrainedClusters() {
ASSERT
(
context
.
getState
(
State
::
Positions
).
getTime
()
>
0.1
);
}
void
testConstrainedMasslessParticles
()
{
ReferencePlatform
platform
;
System
system
;
system
.
addParticle
(
0.0
);
system
.
addParticle
(
1.0
);
system
.
addConstraint
(
0
,
1
,
1.5
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
-
1
,
0
,
0
);
positions
[
1
]
=
Vec3
(
1
,
0
,
0
);
VariableVerletIntegrator
integrator
(
0.01
);
bool
failed
=
false
;
try
{
// This should throw an exception.
Context
context
(
system
,
integrator
,
platform
);
}
catch
(
exception
&
ex
)
{
failed
=
true
;
}
ASSERT
(
failed
);
// Now make both particles massless, which should work.
system
.
setParticleMass
(
1
,
0.0
);
Context
context
(
system
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
context
.
setVelocitiesToTemperature
(
300.0
);
integrator
.
step
(
1
);
State
state
=
context
.
getState
(
State
::
Velocities
|
State
::
Positions
);
ASSERT_EQUAL
(
0.0
,
state
.
getVelocities
()[
0
][
0
]);
}
void
testArgonBox
()
{
const
int
gridSize
=
8
;
const
double
mass
=
40.0
;
// Ar atomic mass
...
...
@@ -272,6 +304,7 @@ int main() {
testSingleBond
();
testConstraints
();
testConstrainedClusters
();
testConstrainedMasslessParticles
();
testArgonBox
();
}
catch
(
const
exception
&
e
)
{
...
...
platforms/reference/tests/TestReferenceVerletIntegrator.cpp
View file @
8df54762
...
...
@@ -200,11 +200,44 @@ void testConstrainedClusters() {
}
}
void
testConstrainedMasslessParticles
()
{
ReferencePlatform
platform
;
System
system
;
system
.
addParticle
(
0.0
);
system
.
addParticle
(
1.0
);
system
.
addConstraint
(
0
,
1
,
1.5
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
-
1
,
0
,
0
);
positions
[
1
]
=
Vec3
(
1
,
0
,
0
);
VerletIntegrator
integrator
(
0.01
);
bool
failed
=
false
;
try
{
// This should throw an exception.
Context
context
(
system
,
integrator
,
platform
);
}
catch
(
exception
&
ex
)
{
failed
=
true
;
}
ASSERT
(
failed
);
// Now make both particles massless, which should work.
system
.
setParticleMass
(
1
,
0.0
);
Context
context
(
system
,
integrator
,
platform
);
context
.
setPositions
(
positions
);
context
.
setVelocitiesToTemperature
(
300.0
);
integrator
.
step
(
1
);
State
state
=
context
.
getState
(
State
::
Velocities
|
State
::
Positions
);
ASSERT_EQUAL
(
0.0
,
state
.
getVelocities
()[
0
][
0
]);
}
int
main
()
{
try
{
testSingleBond
();
testConstraints
();
testConstrainedClusters
();
testConstrainedMasslessParticles
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
plugins/amoeba/openmmapi/include/openmm/AmoebaMultipoleForce.h
View file @
8df54762
...
...
@@ -301,6 +301,14 @@ public:
*/
void
setEwaldErrorTolerance
(
double
tol
);
/**
* Get the induced dipole moments of all particles.
*
* @param context the Context for which to get the induced dipoles
* @param dipoles the induced dipole moment of particle i is stored into the i'th element
*/
void
getInducedDipoles
(
Context
&
context
,
std
::
vector
<
Vec3
>&
dipoles
);
/**
* Get the electrostatic potential.
*
...
...
plugins/amoeba/openmmapi/include/openmm/amoebaKernels.h
View file @
8df54762
...
...
@@ -348,6 +348,8 @@ public:
*/
virtual
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
=
0
;
virtual
void
getInducedDipoles
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
dipoles
)
=
0
;
virtual
void
getElectrostaticPotential
(
ContextImpl
&
context
,
const
std
::
vector
<
Vec3
>&
inputGrid
,
std
::
vector
<
double
>&
outputElectrostaticPotential
)
=
0
;
...
...
plugins/amoeba/openmmapi/include/openmm/internal/AmoebaMultipoleForceImpl.h
View file @
8df54762
...
...
@@ -82,6 +82,8 @@ public:
*/
static
void
getCovalentDegree
(
const
AmoebaMultipoleForce
&
force
,
std
::
vector
<
int
>&
covalentDegree
);
void
getInducedDipoles
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
dipoles
);
void
getElectrostaticPotential
(
ContextImpl
&
context
,
const
std
::
vector
<
Vec3
>&
inputGrid
,
std
::
vector
<
double
>&
outputElectrostaticPotential
);
...
...
plugins/amoeba/openmmapi/src/AmoebaMultipoleForce.cpp
View file @
8df54762
...
...
@@ -226,6 +226,10 @@ void AmoebaMultipoleForce::getCovalentMaps(int index, std::vector< std::vector<i
}
}
void
AmoebaMultipoleForce
::
getInducedDipoles
(
Context
&
context
,
vector
<
Vec3
>&
dipoles
)
{
dynamic_cast
<
AmoebaMultipoleForceImpl
&>
(
getImplInContext
(
context
)).
getInducedDipoles
(
getContextImpl
(
context
),
dipoles
);
}
void
AmoebaMultipoleForce
::
getElectrostaticPotential
(
const
std
::
vector
<
Vec3
>&
inputGrid
,
Context
&
context
,
std
::
vector
<
double
>&
outputElectrostaticPotential
){
dynamic_cast
<
AmoebaMultipoleForceImpl
&>
(
getImplInContext
(
context
)).
getElectrostaticPotential
(
getContextImpl
(
context
),
inputGrid
,
outputElectrostaticPotential
);
}
...
...
plugins/amoeba/openmmapi/src/AmoebaMultipoleForceImpl.cpp
View file @
8df54762
...
...
@@ -183,6 +183,10 @@ void AmoebaMultipoleForceImpl::getCovalentDegree( const AmoebaMultipoleForce& fo
return
;
}
void
AmoebaMultipoleForceImpl
::
getInducedDipoles
(
ContextImpl
&
context
,
vector
<
Vec3
>&
dipoles
)
{
kernel
.
getAs
<
CalcAmoebaMultipoleForceKernel
>
().
getInducedDipoles
(
context
,
dipoles
);
}
void
AmoebaMultipoleForceImpl
::
getElectrostaticPotential
(
ContextImpl
&
context
,
const
std
::
vector
<
Vec3
>&
inputGrid
,
std
::
vector
<
double
>&
outputElectrostaticPotential
){
kernel
.
getAs
<
CalcAmoebaMultipoleForceKernel
>
().
getElectrostaticPotential
(
context
,
inputGrid
,
outputElectrostaticPotential
);
...
...
plugins/amoeba/platforms/cuda/src/AmoebaCudaKernels.cpp
View file @
8df54762
...
...
@@ -1639,6 +1639,24 @@ void CudaCalcAmoebaMultipoleForceKernel::ensureMultipolesValid(ContextImpl& cont
context
.
calcForcesAndEnergy
(
false
,
false
,
-
1
);
}
void
CudaCalcAmoebaMultipoleForceKernel
::
getInducedDipoles
(
ContextImpl
&
context
,
vector
<
Vec3
>&
dipoles
)
{
ensureMultipolesValid
(
context
);
int
numParticles
=
cu
.
getNumAtoms
();
dipoles
.
resize
(
numParticles
);
if
(
cu
.
getUseDoublePrecision
())
{
vector
<
double
>
d
;
inducedDipole
->
download
(
d
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
dipoles
[
i
]
=
Vec3
(
d
[
3
*
i
],
d
[
3
*
i
+
1
],
d
[
3
*
i
+
2
]);
}
else
{
vector
<
float
>
d
;
inducedDipole
->
download
(
d
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
dipoles
[
i
]
=
Vec3
(
d
[
3
*
i
],
d
[
3
*
i
+
1
],
d
[
3
*
i
+
2
]);
}
}
void
CudaCalcAmoebaMultipoleForceKernel
::
getElectrostaticPotential
(
ContextImpl
&
context
,
const
vector
<
Vec3
>&
inputGrid
,
vector
<
double
>&
outputElectrostaticPotential
)
{
ensureMultipolesValid
(
context
);
int
numPoints
=
inputGrid
.
size
();
...
...
plugins/amoeba/platforms/cuda/src/AmoebaCudaKernels.h
View file @
8df54762
...
...
@@ -327,6 +327,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Get the induced dipole moments of all particles.
*
* @param context the Context for which to get the induced dipoles
* @param dipoles the induced dipole moment of particle i is stored into the i'th element
*/
void
getInducedDipoles
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
dipoles
);
/**
* Execute the kernel to calculate the electrostatic potential
*
...
...
plugins/amoeba/platforms/cuda/tests/TestCudaAmoebaMultipoleForce.cpp
View file @
8df54762
...
...
@@ -2700,6 +2700,40 @@ static void testPMEMutualPolarizationLargeWater( FILE* log ) {
}
// test querying particle induced dipoles
static
void
testParticleInducedDipoles
()
{
int
numberOfParticles
=
8
;
int
inputPmeGridDimension
=
0
;
double
cutoff
=
9000000.0
;
std
::
vector
<
Vec3
>
forces
;
double
energy
;
System
system
;
AmoebaMultipoleForce
*
amoebaMultipoleForce
=
new
AmoebaMultipoleForce
();;
setupMultipoleAmmonia
(
system
,
amoebaMultipoleForce
,
AmoebaMultipoleForce
::
NoCutoff
,
AmoebaMultipoleForce
::
Mutual
,
cutoff
,
inputPmeGridDimension
);
LangevinIntegrator
integrator
(
0.0
,
0.1
,
0.01
);
Context
context
(
system
,
integrator
,
Platform
::
getPlatformByName
(
"CUDA"
));
getForcesEnergyMultipoleAmmonia
(
context
,
forces
,
energy
);
std
::
vector
<
Vec3
>
dipole
;
amoebaMultipoleForce
->
getInducedDipoles
(
context
,
dipole
);
// Compare to values calculated by TINKER.
std
::
vector
<
Vec3
>
expectedDipole
(
numberOfParticles
);
expectedDipole
[
0
]
=
Vec3
(
0.0031710288
,
9.3687453e-7
,
-
0.0006919963
);
expectedDipole
[
1
]
=
Vec3
(
8.0279737504e-5
,
-
0.000279376
,
4.778060103e-5
);
expectedDipole
[
2
]
=
Vec3
(
0.000079322
,
0.0002789804
,
4.8696656126e-5
);
expectedDipole
[
3
]
=
Vec3
(
-
0.0001407394
,
1.540638116e-6
,
-
0.0007077775
);
expectedDipole
[
4
]
=
Vec3
(
0.0019564439
,
-
1.0409717e-7
,
0.0007332188
);
expectedDipole
[
5
]
=
Vec3
(
0.0008213891
,
-
0.0007749618
,
-
0.0003883865
);
expectedDipole
[
6
]
=
Vec3
(
0.0046133992
,
-
7.2868019e-7
,
0.0002500622
);
expectedDipole
[
7
]
=
Vec3
(
0.0008204731
,
0.0007772727
,
-
0.0003856176
);
for
(
int
i
=
0
;
i
<
numberOfParticles
;
i
++
)
ASSERT_EQUAL_VEC
(
expectedDipole
[
i
],
dipole
[
i
],
1e-4
);
}
// test computation of system multipole moments
static
void
testSystemMultipoleMoments
(
FILE
*
log
)
{
...
...
@@ -2963,6 +2997,10 @@ int main(int argc, char* argv[]) {
testMultipoleIonsAndWaterPMEMutualPolarization
(
log
);
testMultipoleIonsAndWaterPMEDirectPolarization
(
log
);
// test querying induced dipoles
testParticleInducedDipoles
();
// test computation of system multipole moments
testSystemMultipoleMoments
(
log
);
...
...
plugins/amoeba/platforms/reference/src/AmoebaReferenceKernels.cpp
View file @
8df54762
...
...
@@ -683,6 +683,25 @@ double ReferenceCalcAmoebaMultipoleForceKernel::execute(ContextImpl& context, bo
return
static_cast
<
double
>
(
energy
);
}
void
ReferenceCalcAmoebaMultipoleForceKernel
::
getInducedDipoles
(
ContextImpl
&
context
,
vector
<
Vec3
>&
outputDipoles
)
{
int
numParticles
=
context
.
getSystem
().
getNumParticles
();
outputDipoles
.
resize
(
numParticles
);
// Create an AmoebaReferenceMultipoleForce to do the calculation.
AmoebaReferenceMultipoleForce
*
amoebaReferenceMultipoleForce
=
setupAmoebaReferenceMultipoleForce
(
context
);
vector
<
RealVec
>&
posData
=
extractPositions
(
context
);
// Retrieve the induced dipoles.
vector
<
RealVec
>
inducedDipoles
;
amoebaReferenceMultipoleForce
->
calculateInducedDipoles
(
posData
,
charges
,
dipoles
,
quadrupoles
,
tholes
,
dampingFactors
,
polarity
,
axisTypes
,
multipoleAtomZs
,
multipoleAtomXs
,
multipoleAtomYs
,
multipoleAtomCovalentInfo
,
inducedDipoles
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
outputDipoles
[
i
]
=
inducedDipoles
[
i
];
delete
amoebaReferenceMultipoleForce
;
}
void
ReferenceCalcAmoebaMultipoleForceKernel
::
getElectrostaticPotential
(
ContextImpl
&
context
,
const
std
::
vector
<
Vec3
>&
inputGrid
,
std
::
vector
<
double
>&
outputElectrostaticPotential
){
...
...
@@ -704,8 +723,6 @@ void ReferenceCalcAmoebaMultipoleForceKernel::getElectrostaticPotential(ContextI
}
delete
amoebaReferenceMultipoleForce
;
return
;
}
void
ReferenceCalcAmoebaMultipoleForceKernel
::
getSystemMultipoleMoments
(
ContextImpl
&
context
,
std
::
vector
<
double
>&
outputMultipoleMoments
){
...
...
@@ -726,8 +743,6 @@ void ReferenceCalcAmoebaMultipoleForceKernel::getSystemMultipoleMoments(ContextI
multipoleAtomCovalentInfo
,
outputMultipoleMoments
);
delete
amoebaReferenceMultipoleForce
;
return
;
}
void
ReferenceCalcAmoebaMultipoleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
AmoebaMultipoleForce
&
force
)
{
...
...
plugins/amoeba/platforms/reference/src/AmoebaReferenceKernels.h
View file @
8df54762
...
...
@@ -366,6 +366,13 @@ public:
* @return the potential energy due to the force
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Get the induced dipole moments of all particles.
*
* @param context the Context for which to get the induced dipoles
* @param dipoles the induced dipole moment of particle i is stored into the i'th element
*/
void
getInducedDipoles
(
ContextImpl
&
context
,
std
::
vector
<
Vec3
>&
dipoles
);
/**
* Calculate the electrostatic potential given vector of grid coordinates.
*
...
...
plugins/amoeba/platforms/reference/src/SimTKReference/AmoebaReferenceMultipoleForce.cpp
View file @
8df54762
...
...
@@ -1563,6 +1563,28 @@ RealOpenMM AmoebaReferenceMultipoleForce::calculateForceAndEnergy( const std::ve
return
energy
;
}
void
AmoebaReferenceMultipoleForce
::
calculateInducedDipoles
(
const
std
::
vector
<
RealVec
>&
particlePositions
,
const
std
::
vector
<
RealOpenMM
>&
charges
,
const
std
::
vector
<
RealOpenMM
>&
dipoles
,
const
std
::
vector
<
RealOpenMM
>&
quadrupoles
,
const
std
::
vector
<
RealOpenMM
>&
tholes
,
const
std
::
vector
<
RealOpenMM
>&
dampingFactors
,
const
std
::
vector
<
RealOpenMM
>&
polarity
,
const
std
::
vector
<
int
>&
axisTypes
,
const
std
::
vector
<
int
>&
multipoleAtomZs
,
const
std
::
vector
<
int
>&
multipoleAtomXs
,
const
std
::
vector
<
int
>&
multipoleAtomYs
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>
>
>&
multipoleAtomCovalentInfo
,
std
::
vector
<
RealVec
>&
outputInducedDipoles
)
{
// setup, including calculating induced dipoles
std
::
vector
<
MultipoleParticleData
>
particleData
;
setup
(
particlePositions
,
charges
,
dipoles
,
quadrupoles
,
tholes
,
dampingFactors
,
polarity
,
axisTypes
,
multipoleAtomZs
,
multipoleAtomXs
,
multipoleAtomYs
,
multipoleAtomCovalentInfo
,
particleData
);
outputInducedDipoles
=
_inducedDipole
;
}
void
AmoebaReferenceMultipoleForce
::
calculateAmoebaSystemMultipoleMoments
(
const
std
::
vector
<
RealOpenMM
>&
masses
,
const
std
::
vector
<
RealVec
>&
particlePositions
,
const
std
::
vector
<
RealOpenMM
>&
charges
,
...
...
plugins/amoeba/platforms/reference/src/SimTKReference/AmoebaReferenceMultipoleForce.h
View file @
8df54762
...
...
@@ -471,6 +471,38 @@ public:
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>
>
>&
multipoleAtomCovalentInfo
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
);
/**
* Calculate particle induced dipoles.
*
* @param masses particle masses
* @param particlePositions Cartesian coordinates of particles
* @param charges scalar charges for each particle
* @param dipoles molecular frame dipoles for each particle
* @param quadrupoles molecular frame quadrupoles for each particle
* @param tholes Thole factors for each particle
* @param dampingFactors dampling factors for each particle
* @param polarity polarity for each particle
* @param axisTypes axis type (Z-then-X, ... ) for each particle
* @param multipoleAtomZs indicies of particle specifying the molecular frame z-axis for each particle
* @param multipoleAtomXs indicies of particle specifying the molecular frame x-axis for each particle
* @param multipoleAtomYs indicies of particle specifying the molecular frame y-axis for each particle
* @param multipoleAtomCovalentInfo covalent info needed to set scaling factors
* @param outputMultipoleMoments output multipole moments
*/
void
calculateInducedDipoles
(
const
std
::
vector
<
OpenMM
::
RealVec
>&
particlePositions
,
const
std
::
vector
<
RealOpenMM
>&
charges
,
const
std
::
vector
<
RealOpenMM
>&
dipoles
,
const
std
::
vector
<
RealOpenMM
>&
quadrupoles
,
const
std
::
vector
<
RealOpenMM
>&
tholes
,
const
std
::
vector
<
RealOpenMM
>&
dampingFactors
,
const
std
::
vector
<
RealOpenMM
>&
polarity
,
const
std
::
vector
<
int
>&
axisTypes
,
const
std
::
vector
<
int
>&
multipoleAtomZs
,
const
std
::
vector
<
int
>&
multipoleAtomXs
,
const
std
::
vector
<
int
>&
multipoleAtomYs
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>
>
>&
multipoleAtomCovalentInfo
,
std
::
vector
<
RealVec
>&
outputInducedDipoles
);
/**
* Calculate system multipole moments.
*
...
...
plugins/amoeba/platforms/reference/tests/TestReferenceAmoebaMultipoleForce.cpp
View file @
8df54762
...
...
@@ -2605,6 +2605,40 @@ static void testPMEMutualPolarizationLargeWater( FILE* log ) {
}
// test querying particle induced dipoles
static
void
testParticleInducedDipoles
()
{
int
numberOfParticles
=
8
;
int
inputPmeGridDimension
=
0
;
double
cutoff
=
9000000.0
;
std
::
vector
<
Vec3
>
forces
;
double
energy
;
System
system
;
AmoebaMultipoleForce
*
amoebaMultipoleForce
=
new
AmoebaMultipoleForce
();;
setupMultipoleAmmonia
(
system
,
amoebaMultipoleForce
,
AmoebaMultipoleForce
::
NoCutoff
,
AmoebaMultipoleForce
::
Mutual
,
cutoff
,
inputPmeGridDimension
);
LangevinIntegrator
integrator
(
0.0
,
0.1
,
0.01
);
Context
context
(
system
,
integrator
,
Platform
::
getPlatformByName
(
"Reference"
));
getForcesEnergyMultipoleAmmonia
(
context
,
forces
,
energy
);
std
::
vector
<
Vec3
>
dipole
;
amoebaMultipoleForce
->
getInducedDipoles
(
context
,
dipole
);
// Compare to values calculated by TINKER.
std
::
vector
<
Vec3
>
expectedDipole
(
numberOfParticles
);
expectedDipole
[
0
]
=
Vec3
(
0.0031710288
,
9.3687453e-7
,
-
0.0006919963
);
expectedDipole
[
1
]
=
Vec3
(
8.0279737504e-5
,
-
0.000279376
,
4.778060103e-5
);
expectedDipole
[
2
]
=
Vec3
(
0.000079322
,
0.0002789804
,
4.8696656126e-5
);
expectedDipole
[
3
]
=
Vec3
(
-
0.0001407394
,
1.540638116e-6
,
-
0.0007077775
);
expectedDipole
[
4
]
=
Vec3
(
0.0019564439
,
-
1.0409717e-7
,
0.0007332188
);
expectedDipole
[
5
]
=
Vec3
(
0.0008213891
,
-
0.0007749618
,
-
0.0003883865
);
expectedDipole
[
6
]
=
Vec3
(
0.0046133992
,
-
7.2868019e-7
,
0.0002500622
);
expectedDipole
[
7
]
=
Vec3
(
0.0008204731
,
0.0007772727
,
-
0.0003856176
);
for
(
int
i
=
0
;
i
<
numberOfParticles
;
i
++
)
ASSERT_EQUAL_VEC
(
expectedDipole
[
i
],
dipole
[
i
],
1e-4
);
}
// test computation of system multipole moments
static
void
testSystemMultipoleMoments
(
FILE
*
log
)
{
...
...
@@ -2778,6 +2812,10 @@ int main( int numberOfArguments, char* argv[] ) {
testMultipoleAmmoniaDirectPolarization
(
log
);
// test querying induced dipoles
testParticleInducedDipoles
();
// test mutual polarization, no cutoff
testMultipoleAmmoniaMutualPolarization
(
log
);
...
...
plugins/cpupme/src/CpuPmeKernels.cpp
View file @
8df54762
...
...
@@ -34,9 +34,10 @@
#endif
#include "CpuPmeKernels.h"
#include "SimTKOpenMMRealType.h"
#include "openmm/internal/hardware.h"
#include "openmm/internal/vectorize.h"
#include <cmath>
#include <cstring>
#include <smmintrin.h>
using
namespace
OpenMM
;
using
namespace
std
;
...
...
@@ -46,145 +47,73 @@ static const int PME_ORDER = 5;
bool
CpuCalcPmeReciprocalForceKernel
::
hasInitializedThreads
=
false
;
int
CpuCalcPmeReciprocalForceKernel
::
numThreads
=
0
;
#define EXTRACT_FLOAT(v, element) _mm_cvtss_f32(_mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, element)))
// Define function to get the number of processors.
#ifdef __APPLE__
#include <sys/sysctl.h>
#include <dlfcn.h>
#else
#ifdef WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#include <unistd.h>
#endif
#endif
static
int
getNumProcessors
()
{
#ifdef __APPLE__
int
ncpu
;
size_t
len
=
4
;
if
(
sysctlbyname
(
"hw.logicalcpu"
,
&
ncpu
,
&
len
,
NULL
,
0
)
==
0
)
return
ncpu
;
else
return
1
;
#else
#ifdef WIN32
SYSTEM_INFO
siSysInfo
;
int
ncpu
;
GetSystemInfo
(
&
siSysInfo
);
ncpu
=
siSysInfo
.
dwNumberOfProcessors
;
if
(
ncpu
<
1
)
ncpu
=
1
;
return
ncpu
;
#else
long
nProcessorsOnline
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
if
(
nProcessorsOnline
==
-
1
)
return
1
;
else
return
(
int
)
nProcessorsOnline
;
#endif
#endif
}
// Define a function to check the CPU's capabilities.
#ifdef _WIN32
#define cpuid __cpuid
#else
static
void
cpuid
(
int
cpuInfo
[
4
],
int
infoType
){
#ifdef __LP64__
__asm__
__volatile__
(
"cpuid"
:
"=a"
(
cpuInfo
[
0
]),
"=b"
(
cpuInfo
[
1
]),
"=c"
(
cpuInfo
[
2
]),
"=d"
(
cpuInfo
[
3
])
:
"a"
(
infoType
)
);
#else
__asm__
__volatile__
(
"pushl %%ebx
\n
"
"cpuid
\n
"
"movl %%ebx, %1
\n
"
"popl %%ebx
\n
"
:
"=a"
(
cpuInfo
[
0
]),
"=r"
(
cpuInfo
[
1
]),
"=c"
(
cpuInfo
[
2
]),
"=d"
(
cpuInfo
[
3
])
:
"a"
(
infoType
)
);
#endif
}
#endif
static
void
spreadCharge
(
int
start
,
int
end
,
float
*
posq
,
float
*
grid
,
int
gridx
,
int
gridy
,
int
gridz
,
int
numParticles
,
Vec3
periodicBoxSize
)
{
float
temp
[
4
];
__m128
boxSize
=
_mm_set_ps
(
0
,
(
float
)
periodicBoxSize
[
2
],
(
float
)
periodicBoxSize
[
1
],
(
float
)
periodicBoxSize
[
0
]
);
__m128
invBoxSize
=
_mm_set_ps
(
0
,
(
float
)
(
1
/
periodicBoxSize
[
2
]),
(
float
)
(
1
/
periodicBoxSize
[
1
]),
(
float
)
(
1
/
periodicBoxSize
[
0
]));
__m128
gridSize
=
_mm_set_ps
(
0
,
grid
z
,
gridy
,
grid
x
);
__m128i
gridSizeInt
=
_mm_set_epi32
(
0
,
grid
z
,
gridy
,
grid
x
);
__m128
one
=
_mm_set1_ps
(
1
);
__m128
scale
=
_mm_set1_ps
(
1.0
f
/
(
PME_ORDER
-
1
));
fvec4
boxSize
(
(
float
)
periodicBoxSize
[
0
],
(
float
)
periodicBoxSize
[
1
],
(
float
)
periodicBoxSize
[
2
],
0
);
fvec4
invBoxSize
(
(
float
)
(
1
/
periodicBoxSize
[
0
]),
(
float
)
(
1
/
periodicBoxSize
[
1
]),
(
float
)
(
1
/
periodicBoxSize
[
2
])
,
0
);
fvec4
gridSize
(
grid
x
,
gridy
,
grid
z
,
0
);
ivec4
gridSizeInt
(
grid
x
,
gridy
,
grid
z
,
0
);
fvec4
one
(
1
);
fvec4
scale
(
1.0
f
/
(
PME_ORDER
-
1
));
const
float
epsilonFactor
=
sqrt
(
ONE_4PI_EPS0
);
memset
(
grid
,
0
,
sizeof
(
float
)
*
gridx
*
gridy
*
gridz
);
for
(
int
i
=
start
;
i
<
end
;
i
++
)
{
// Find the position relative to the nearest grid point.
__m128
pos
=
_mm_loadu_p
s
(
&
posq
[
4
*
i
]);
__m128
posFloor
=
_mm_
floor
_ps
(
_mm_mul_ps
(
pos
,
invBoxSize
)
)
;
__m128
posInBox
=
_mm_sub_ps
(
pos
,
_mm_mul_ps
(
boxSize
,
posFloor
))
;
__m128
t
=
_mm_mul_ps
(
_mm_mul_ps
(
posInBox
,
invBoxSize
),
gridSize
)
;
__m128i
ti
=
_mm_cvttps_epi32
(
t
)
;
__m128
dr
=
_mm_sub_ps
(
t
,
_mm_cvtepi32_ps
(
ti
))
;
__m128i
gridIndex
=
_mm_sub_epi32
(
ti
,
_mm_and_si128
(
gridSizeInt
,
_mm_cmpeq_epi32
(
ti
,
gridSizeInt
)
))
;
fvec4
po
s
(
&
posq
[
4
*
i
]);
fvec4
posFloor
=
floor
(
pos
*
invBoxSize
);
fvec4
posInBox
=
pos
-
boxSize
*
posFloor
;
fvec4
t
=
posInBox
*
invBoxSize
*
gridSize
;
ivec4
ti
=
t
;
fvec4
dr
=
t
-
ti
;
ivec4
gridIndex
=
ti
-
(
gridSizeInt
&
ti
==
gridSizeInt
);
// Compute the B-spline coefficients.
__m128
data
[
PME_ORDER
];
data
[
PME_ORDER
-
1
]
=
_mm_setzero_ps
()
;
fvec4
data
[
PME_ORDER
];
data
[
PME_ORDER
-
1
]
=
0.0
f
;
data
[
1
]
=
dr
;
data
[
0
]
=
_mm_sub_ps
(
one
,
dr
)
;
data
[
0
]
=
one
-
dr
;
for
(
int
j
=
3
;
j
<
PME_ORDER
;
j
++
)
{
__m128
div
=
_mm_set1_ps
(
1.0
f
/
(
j
-
1
));
data
[
j
-
1
]
=
_mm_mul_ps
(
_mm_mul_ps
(
div
,
dr
),
data
[
j
-
2
]
)
;
fvec4
div
(
1.0
f
/
(
j
-
1
));
data
[
j
-
1
]
=
div
*
dr
*
data
[
j
-
2
];
for
(
int
k
=
1
;
k
<
j
-
1
;
k
++
)
data
[
j
-
k
-
1
]
=
_mm_mul_ps
(
div
,
_mm_add_ps
(
_mm_mul_ps
(
_mm_add_ps
(
dr
,
_mm_set1_ps
(
k
)),
data
[
j
-
k
-
2
]),
_mm_mul_ps
(
_mm_sub_ps
(
_mm_set1_ps
(
j
-
k
)
,
dr
)
,
data
[
j
-
k
-
1
])
))
;
data
[
0
]
=
_mm_mul_ps
(
_mm_mul_ps
(
div
,
_mm_sub_ps
(
one
,
dr
)
),
data
[
0
]
)
;
data
[
j
-
k
-
1
]
=
div
*
((
dr
+
k
)
*
data
[
j
-
k
-
2
]
+
(
fvec4
(
j
-
k
)
-
dr
)
*
data
[
j
-
k
-
1
]);
data
[
0
]
=
div
*
(
one
-
dr
)
*
data
[
0
];
}
data
[
PME_ORDER
-
1
]
=
_mm_mul_ps
(
_mm_mul_ps
(
scale
,
dr
),
data
[
PME_ORDER
-
2
]
)
;
data
[
PME_ORDER
-
1
]
=
scale
*
dr
*
data
[
PME_ORDER
-
2
];
for
(
int
j
=
1
;
j
<
(
PME_ORDER
-
1
);
j
++
)
data
[
PME_ORDER
-
j
-
1
]
=
_mm_mul_ps
(
scale
,
_mm_add_ps
(
_mm_mul_ps
(
_mm_add_ps
(
dr
,
_mm_set1_ps
(
j
)),
data
[
PME_ORDER
-
j
-
2
]),
_mm_mul_ps
(
_mm_sub_ps
(
_mm_set1_ps
(
PME_ORDER
-
j
)
,
dr
)
,
data
[
PME_ORDER
-
j
-
1
])
))
;
data
[
0
]
=
_mm_mul_ps
(
_mm_mul_ps
(
scale
,
_mm_sub_ps
(
one
,
dr
)
),
data
[
0
]
)
;
data
[
PME_ORDER
-
j
-
1
]
=
scale
*
((
dr
+
j
)
*
data
[
PME_ORDER
-
j
-
2
]
+
(
fvec4
(
PME_ORDER
-
j
)
-
dr
)
*
data
[
PME_ORDER
-
j
-
1
]);
data
[
0
]
=
scale
*
(
one
-
dr
)
*
data
[
0
];
// Spread the charges.
int
gridIndexX
=
_mm_extract_epi32
(
gridIndex
,
0
);
int
gridIndexY
=
_mm_extract_epi32
(
gridIndex
,
1
);
int
gridIndexZ
=
_mm_extract_epi32
(
gridIndex
,
2
);
int
gridIndexX
=
gridIndex
[
0
];
int
gridIndexY
=
gridIndex
[
1
];
int
gridIndexZ
=
gridIndex
[
2
];
if
(
gridIndexX
<
0
)
return
;
// This happens when a simulation blows up and coordinates become NaN.
int
zindex
[
PME_ORDER
];
for
(
int
j
=
0
;
j
<
PME_ORDER
;
j
++
)
{
zindex
[
j
]
=
gridIndexZ
+
j
;
zindex
[
j
]
-=
(
zindex
[
j
]
>=
gridz
?
gridz
:
0
);
}
float
charge
=
epsilonFactor
*
posq
[
4
*
i
+
3
];
__m128
zdata0to3
=
_mm_set_ps
(
EXTRACT_FLOAT
(
data
[
3
],
2
),
EXTRACT_FLOAT
(
data
[
2
],
2
),
EXTRACT_FLOAT
(
data
[
1
],
2
),
EXTRACT_FLOAT
(
data
[
0
],
2
)
);
float
zdata4
=
EXTRACT_FLOAT
(
data
[
4
]
,
2
)
;
fvec4
zdata0to3
(
data
[
0
][
2
],
data
[
1
][
2
],
data
[
2
][
2
],
data
[
3
][
2
]
);
float
zdata4
=
data
[
4
]
[
2
]
;
if
(
gridIndexZ
+
4
<
gridz
)
{
for
(
int
ix
=
0
;
ix
<
PME_ORDER
;
ix
++
)
{
int
xbase
=
gridIndexX
+
ix
;
xbase
-=
(
xbase
>=
gridx
?
gridx
:
0
);
xbase
=
xbase
*
gridy
*
gridz
;
float
xdata
=
charge
*
EXTRACT_FLOAT
(
data
[
ix
]
,
0
)
;
float
xdata
=
charge
*
data
[
ix
]
[
0
]
;
for
(
int
iy
=
0
;
iy
<
PME_ORDER
;
iy
++
)
{
int
ybase
=
gridIndexY
+
iy
;
ybase
-=
(
ybase
>=
gridy
?
gridy
:
0
);
ybase
=
xbase
+
ybase
*
gridz
;
float
multiplier
=
xdata
*
EXTRACT_FLOAT
(
data
[
iy
]
,
1
)
;
__m128
add0to3
=
_mm_mul_ps
(
zdata0to3
,
_mm_set1_ps
(
multiplier
))
;
_mm_storeu_ps
(
&
grid
[
ybase
+
gridIndexZ
]
,
_mm_add_ps
(
_mm_loadu_ps
(
&
grid
[
ybase
+
gridIndexZ
])
,
add0to3
))
;
float
multiplier
=
xdata
*
data
[
iy
]
[
1
]
;
fvec4
add0to3
=
zdata0to3
*
multiplier
;
(
fvec4
(
&
grid
[
ybase
+
gridIndexZ
]
)
+
add0to3
).
store
(
&
grid
[
ybase
+
gridIndexZ
]);
grid
[
ybase
+
zindex
[
4
]]
+=
multiplier
*
zdata4
;
}
}
...
...
@@ -194,14 +123,14 @@ static void spreadCharge(int start, int end, float* posq, float* grid, int gridx
int
xbase
=
gridIndexX
+
ix
;
xbase
-=
(
xbase
>=
gridx
?
gridx
:
0
);
xbase
=
xbase
*
gridy
*
gridz
;
float
xdata
=
charge
*
EXTRACT_FLOAT
(
data
[
ix
]
,
0
)
;
float
xdata
=
charge
*
data
[
ix
]
[
0
]
;
for
(
int
iy
=
0
;
iy
<
PME_ORDER
;
iy
++
)
{
int
ybase
=
gridIndexY
+
iy
;
ybase
-=
(
ybase
>=
gridy
?
gridy
:
0
);
ybase
=
xbase
+
ybase
*
gridz
;
float
multiplier
=
xdata
*
EXTRACT_FLOAT
(
data
[
iy
]
,
1
)
;
__m128
add0to3
=
_mm_mul_ps
(
zdata0to3
,
_mm_set1_ps
(
multiplier
))
;
_mm_
store
_ps
(
temp
,
add0to3
);
float
multiplier
=
xdata
*
data
[
iy
]
[
1
]
;
fvec4
add0to3
=
zdata0to3
*
multiplier
;
add0to3
.
store
(
temp
);
grid
[
ybase
+
zindex
[
0
]]
+=
temp
[
0
];
grid
[
ybase
+
zindex
[
1
]]
+=
temp
[
1
];
grid
[
ybase
+
zindex
[
2
]]
+=
temp
[
2
];
...
...
@@ -314,84 +243,86 @@ static void reciprocalConvolution(int start, int end, fftwf_complex* grid, int g
}
static
void
interpolateForces
(
int
start
,
int
end
,
float
*
posq
,
float
*
force
,
float
*
grid
,
int
gridx
,
int
gridy
,
int
gridz
,
int
numParticles
,
Vec3
periodicBoxSize
)
{
__m128
boxSize
=
_mm_set_ps
(
0
,
(
float
)
periodicBoxSize
[
2
],
(
float
)
periodicBoxSize
[
1
],
(
float
)
periodicBoxSize
[
0
]
);
__m128
invBoxSize
=
_mm_set_ps
(
0
,
(
float
)
(
1
/
periodicBoxSize
[
2
]),
(
float
)
(
1
/
periodicBoxSize
[
1
]),
(
float
)
(
1
/
periodicBoxSize
[
0
]));
__m128
gridSize
=
_mm_set_ps
(
0
,
grid
z
,
gridy
,
grid
x
);
__m128i
gridSizeInt
=
_mm_set_epi32
(
0
,
grid
z
,
gridy
,
grid
x
);
__m128
one
=
_mm_set1_ps
(
1
);
__m128
scale
=
_mm_set1_ps
(
1.0
f
/
(
PME_ORDER
-
1
));
fvec4
boxSize
(
(
float
)
periodicBoxSize
[
0
],
(
float
)
periodicBoxSize
[
1
],
(
float
)
periodicBoxSize
[
2
],
0
);
fvec4
invBoxSize
(
(
float
)
(
1
/
periodicBoxSize
[
0
]),
(
float
)
(
1
/
periodicBoxSize
[
1
]),
(
float
)
(
1
/
periodicBoxSize
[
2
])
,
0
);
fvec4
gridSize
(
grid
x
,
gridy
,
grid
z
,
0
);
ivec4
gridSizeInt
(
grid
x
,
gridy
,
grid
z
,
0
);
fvec4
one
(
1
);
fvec4
scale
(
1.0
f
/
(
PME_ORDER
-
1
));
const
float
epsilonFactor
=
sqrt
(
ONE_4PI_EPS0
);
for
(
int
i
=
start
;
i
<
end
;
i
++
)
{
// Find the position relative to the nearest grid point.
__m128
pos
=
_mm_loadu_p
s
(
&
posq
[
4
*
i
]);
__m128
posFloor
=
_mm_
floor
_ps
(
_mm_mul_ps
(
pos
,
invBoxSize
)
)
;
__m128
posInBox
=
_mm_sub_ps
(
pos
,
_mm_mul_ps
(
boxSize
,
posFloor
))
;
__m128
t
=
_mm_mul_ps
(
_mm_mul_ps
(
posInBox
,
invBoxSize
),
gridSize
)
;
__m128i
ti
=
_mm_cvttps_epi32
(
t
)
;
__m128
dr
=
_mm_sub_ps
(
t
,
_mm_cvtepi32_ps
(
ti
))
;
__m128i
gridIndex
=
_mm_sub_epi32
(
ti
,
_mm_and_si128
(
gridSizeInt
,
_mm_cmpeq_epi32
(
ti
,
gridSizeInt
)
))
;
fvec4
po
s
(
&
posq
[
4
*
i
]);
fvec4
posFloor
=
floor
(
pos
*
invBoxSize
);
fvec4
posInBox
=
pos
-
boxSize
*
posFloor
;
fvec4
t
=
posInBox
*
invBoxSize
*
gridSize
;
ivec4
ti
=
t
;
fvec4
dr
=
t
-
ti
;
ivec4
gridIndex
=
ti
-
(
gridSizeInt
&
ti
==
gridSizeInt
);
// Compute the B-spline coefficients.
__m128
data
[
PME_ORDER
];
__m128
ddata
[
PME_ORDER
];
data
[
PME_ORDER
-
1
]
=
_mm_setzero_ps
()
;
fvec4
data
[
PME_ORDER
];
fvec4
ddata
[
PME_ORDER
];
data
[
PME_ORDER
-
1
]
=
0.0
f
;
data
[
1
]
=
dr
;
data
[
0
]
=
_mm_sub_ps
(
one
,
dr
)
;
data
[
0
]
=
one
-
dr
;
for
(
int
j
=
3
;
j
<
PME_ORDER
;
j
++
)
{
__m128
div
=
_mm_set1_ps
(
1.0
f
/
(
j
-
1
));
data
[
j
-
1
]
=
_mm_mul_ps
(
_mm_mul_ps
(
div
,
dr
),
data
[
j
-
2
]
)
;
fvec4
div
(
1.0
f
/
(
j
-
1
));
data
[
j
-
1
]
=
div
*
dr
*
data
[
j
-
2
];
for
(
int
k
=
1
;
k
<
j
-
1
;
k
++
)
data
[
j
-
k
-
1
]
=
_mm_mul_ps
(
div
,
_mm_add_ps
(
_mm_mul_ps
(
_mm_add_ps
(
dr
,
_mm_set1_ps
(
k
)),
data
[
j
-
k
-
2
]),
_mm_mul_ps
(
_mm_sub_ps
(
_mm_set1_ps
(
j
-
k
)
,
dr
)
,
data
[
j
-
k
-
1
])
))
;
data
[
0
]
=
_mm_mul_ps
(
_mm_mul_ps
(
div
,
_mm_sub_ps
(
one
,
dr
)
),
data
[
0
]
)
;
data
[
j
-
k
-
1
]
=
div
*
((
dr
+
k
)
*
data
[
j
-
k
-
2
]
+
(
fvec4
(
j
-
k
)
-
dr
)
*
data
[
j
-
k
-
1
]);
data
[
0
]
=
div
*
(
one
-
dr
)
*
data
[
0
];
}
ddata
[
0
]
=
_mm_sub_ps
(
_mm_set1_ps
(
0
),
data
[
0
]
)
;
ddata
[
0
]
=
-
data
[
0
];
for
(
int
j
=
1
;
j
<
PME_ORDER
;
j
++
)
ddata
[
j
]
=
_mm_sub_ps
(
data
[
j
-
1
]
,
data
[
j
]
)
;
data
[
PME_ORDER
-
1
]
=
_mm_mul_ps
(
_mm_mul_ps
(
scale
,
dr
),
data
[
PME_ORDER
-
2
]
)
;
ddata
[
j
]
=
data
[
j
-
1
]
-
data
[
j
];
data
[
PME_ORDER
-
1
]
=
scale
*
dr
*
data
[
PME_ORDER
-
2
];
for
(
int
j
=
1
;
j
<
(
PME_ORDER
-
1
);
j
++
)
data
[
PME_ORDER
-
j
-
1
]
=
_mm_mul_ps
(
scale
,
_mm_add_ps
(
_mm_mul_ps
(
_mm_add_ps
(
dr
,
_mm_set1_ps
(
j
)),
data
[
PME_ORDER
-
j
-
2
]),
_mm_mul_ps
(
_mm_sub_ps
(
_mm_set1_ps
(
PME_ORDER
-
j
)
,
dr
)
,
data
[
PME_ORDER
-
j
-
1
])
))
;
data
[
0
]
=
_mm_mul_ps
(
_mm_mul_ps
(
scale
,
_mm_sub_ps
(
one
,
dr
)
),
data
[
0
]
)
;
data
[
PME_ORDER
-
j
-
1
]
=
scale
*
((
dr
+
j
)
*
data
[
PME_ORDER
-
j
-
2
]
+
(
fvec4
(
PME_ORDER
-
j
)
-
dr
)
*
data
[
PME_ORDER
-
j
-
1
]);
data
[
0
]
=
scale
*
(
one
-
dr
)
*
data
[
0
];
// Compute the force on this atom.
int
gridIndexX
=
_mm_extract_epi32
(
gridIndex
,
0
);
int
gridIndexY
=
_mm_extract_epi32
(
gridIndex
,
1
);
int
gridIndexZ
=
_mm_extract_epi32
(
gridIndex
,
2
);
int
gridIndexX
=
gridIndex
[
0
];
int
gridIndexY
=
gridIndex
[
1
];
int
gridIndexZ
=
gridIndex
[
2
];
if
(
gridIndexX
<
0
)
return
;
// This happens when a simulation blows up and coordinates become NaN.
int
zindex
[
PME_ORDER
];
for
(
int
j
=
0
;
j
<
PME_ORDER
;
j
++
)
{
zindex
[
j
]
=
gridIndexZ
+
j
;
zindex
[
j
]
-=
(
zindex
[
j
]
>=
gridz
?
gridz
:
0
);
}
__m128
zdata
[
PME_ORDER
];
fvec4
zdata
[
PME_ORDER
];
for
(
int
j
=
0
;
j
<
PME_ORDER
;
j
++
)
zdata
[
j
]
=
_mm_set_ps
(
0
,
EXTRACT_FLOAT
(
ddata
[
j
],
2
),
EXTRACT_FLOAT
(
data
[
j
],
2
),
EXTRACT_FLOAT
(
data
[
j
]
,
2
)
);
__m128
f
=
_mm_set1_ps
(
0
)
;
zdata
[
j
]
=
fvec4
(
data
[
j
][
2
],
data
[
j
][
2
],
d
data
[
j
]
[
2
],
0
);
fvec4
f
=
0.0
f
;
for
(
int
ix
=
0
;
ix
<
PME_ORDER
;
ix
++
)
{
int
xbase
=
gridIndexX
+
ix
;
xbase
-=
(
xbase
>=
gridx
?
gridx
:
0
);
xbase
=
xbase
*
gridy
*
gridz
;
float
dx
=
EXTRACT_FLOAT
(
data
[
ix
]
,
0
)
;
float
ddx
=
EXTRACT_FLOAT
(
ddata
[
ix
]
,
0
)
;
__m128
xdata
=
_mm_set_ps
(
0
,
dx
,
dx
,
ddx
);
float
dx
=
data
[
ix
]
[
0
]
;
float
ddx
=
ddata
[
ix
]
[
0
]
;
fvec4
xdata
(
ddx
,
dx
,
dx
,
0
);
for
(
int
iy
=
0
;
iy
<
PME_ORDER
;
iy
++
)
{
int
ybase
=
gridIndexY
+
iy
;
ybase
-=
(
ybase
>=
gridy
?
gridy
:
0
);
ybase
=
xbase
+
ybase
*
gridz
;
float
dy
=
EXTRACT_FLOAT
(
data
[
iy
]
,
1
)
;
float
ddy
=
EXTRACT_FLOAT
(
ddata
[
iy
]
,
1
)
;
__m128
xydata
=
_mm_mul_ps
(
xdata
,
_mm_set_ps
(
0
,
dy
,
ddy
,
dy
)
);
float
dy
=
data
[
iy
]
[
1
]
;
float
ddy
=
ddata
[
iy
]
[
1
]
;
fvec4
xydata
=
xdata
*
fvec4
(
dy
,
ddy
,
dy
,
0
);
for
(
int
iz
=
0
;
iz
<
PME_ORDER
;
iz
++
)
{
__m128
gridValue
=
_mm_set1_ps
(
grid
[
ybase
+
zindex
[
iz
]]);
f
=
_mm_add_ps
(
f
,
_mm_mul_ps
(
xydata
,
_mm_mul_ps
(
zdata
[
iz
]
,
gridValue
)))
;
fvec4
gridValue
(
grid
[
ybase
+
zindex
[
iz
]]);
f
=
f
+
xydata
*
zdata
[
iz
]
*
gridValue
;
}
}
}
f
=
_mm_mul_ps
(
invBoxSize
,
_mm_mul_ps
(
gridSize
,
_mm_mul_ps
(
f
,
_mm_set1_ps
(
-
epsilonFactor
*
posq
[
4
*
i
+
3
])
)))
;
_mm_
store
_ps
(
&
force
[
4
*
i
]
,
f
);
f
=
invBoxSize
*
gridSize
*
f
*
(
-
epsilonFactor
*
posq
[
4
*
i
+
3
]);
f
.
store
(
&
force
[
4
*
i
]
);
}
}
...
...
@@ -576,10 +507,10 @@ void CpuCalcPmeReciprocalForceKernel::runThread(int index) {
threadWait
();
int
numGrids
=
threadData
.
size
();
for
(
int
i
=
gridStart
;
i
<
gridEnd
;
i
+=
4
)
{
__m128
sum
=
_mm_load_ps
(
&
realGrid
[
i
]);
fvec4
sum
(
&
realGrid
[
i
]);
for
(
int
j
=
1
;
j
<
numGrids
;
j
++
)
sum
=
_mm_add_ps
(
sum
,
_mm_load_ps
(
&
threadData
[
j
]
->
tempGrid
[
i
])
)
;
_mm_
store
_ps
(
&
realGrid
[
i
]
,
sum
);
sum
+
=
fvec4
(
&
threadData
[
j
]
->
tempGrid
[
i
]);
sum
.
store
(
&
realGrid
[
i
]);
}
threadWait
();
if
(
lastBoxSize
!=
periodicBoxSize
)
{
...
...
plugins/drude/platforms/reference/src/ReferenceDrudeKernels.cpp
View file @
8df54762
...
...
@@ -34,7 +34,7 @@
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "SimTKOpenMMUtilities.h"
#include "ReferenceC
CMAAlgorithm
.h"
#include "ReferenceC
onstraints
.h"
#include "ReferenceVirtualSites.h"
#include <set>
...
...
@@ -56,20 +56,6 @@ static vector<RealVec>& extractForces(ContextImpl& context) {
return
*
((
vector
<
RealVec
>*
)
data
->
forces
);
}
static
void
findAnglesForCCMA
(
const
System
&
system
,
vector
<
ReferenceCCMAAlgorithm
::
AngleInfo
>&
angles
)
{
for
(
int
i
=
0
;
i
<
system
.
getNumForces
();
i
++
)
{
const
HarmonicAngleForce
*
force
=
dynamic_cast
<
const
HarmonicAngleForce
*>
(
&
system
.
getForce
(
i
));
if
(
force
!=
NULL
)
{
for
(
int
j
=
0
;
j
<
force
->
getNumAngles
();
j
++
)
{
int
atom1
,
atom2
,
atom3
;
double
angle
,
k
;
force
->
getAngleParameters
(
j
,
atom1
,
atom2
,
atom3
,
angle
,
k
);
angles
.
push_back
(
ReferenceCCMAAlgorithm
::
AngleInfo
(
atom1
,
atom2
,
atom3
,
(
RealOpenMM
)
angle
));
}
}
}
}
static
double
computeShiftedKineticEnergy
(
ContextImpl
&
context
,
vector
<
double
>&
inverseMasses
,
double
timeShift
,
ReferenceConstraintAlgorithm
*
constraints
)
{
const
System
&
system
=
context
.
getSystem
();
int
numParticles
=
system
.
getNumParticles
();
...
...
@@ -91,7 +77,7 @@ static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>&
if
(
constraints
!=
NULL
)
{
constraints
->
setTolerance
(
1e-4
);
constraints
->
applyToVelocities
(
numParticles
,
posData
,
shiftedVel
,
inverseMasses
);
constraints
->
applyToVelocities
(
posData
,
shiftedVel
,
inverseMasses
);
}
// Compute the kinetic energy.
...
...
@@ -271,21 +257,19 @@ void ReferenceIntegrateDrudeLangevinStepKernel::initialize(const System& system,
// Prepare constraints.
int
numConstraints
=
system
.
getNumConstraints
();
if
(
numConstraints
>
0
)
{
vector
<
pair
<
int
,
int
>
>
constraintIndices
(
numConstraints
);
vector
<
RealOpenMM
>
constraintDistances
(
numConstraints
);
for
(
int
i
=
0
;
i
<
numConstraints
;
++
i
)
{
if
(
system
.
getNumConstraints
()
>
0
)
{
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
constraintIndices
[
i
].
first
=
particle1
;
constraintIndices
[
i
].
second
=
particle2
;
constraintDistances
[
i
]
=
static_cast
<
RealOpenMM
>
(
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
vector
<
ReferenceCCMAAlgorithm
::
AngleInfo
>
angles
;
findAnglesForCCMA
(
system
,
angles
);
constraints
=
new
ReferenceCCMAAlgorithm
(
system
.
getNumParticles
(),
numConstraints
,
constraintIndices
,
constraintDistances
,
particleMass
,
angles
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
}
}
...
...
@@ -347,7 +331,7 @@ void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, co
// Apply constraints.
if
(
constraints
!=
NULL
)
constraints
->
apply
(
numParticles
,
pos
,
xPrime
,
particleInvMass
);
constraints
->
apply
(
pos
,
xPrime
,
particleInvMass
);
// Record the constrained positions and velocities.
...
...
@@ -395,21 +379,19 @@ void ReferenceIntegrateDrudeSCFStepKernel::initialize(const System& system, cons
// Prepare constraints.
int
numConstraints
=
system
.
getNumConstraints
();
if
(
numConstraints
>
0
)
{
vector
<
pair
<
int
,
int
>
>
constraintIndices
(
numConstraints
);
vector
<
RealOpenMM
>
constraintDistances
(
numConstraints
);
for
(
int
i
=
0
;
i
<
numConstraints
;
++
i
)
{
if
(
system
.
getNumConstraints
()
>
0
)
{
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
constraintIndices
[
i
].
first
=
particle1
;
constraintIndices
[
i
].
second
=
particle2
;
constraintDistances
[
i
]
=
static_cast
<
RealOpenMM
>
(
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
vector
<
ReferenceCCMAAlgorithm
::
AngleInfo
>
angles
;
findAnglesForCCMA
(
system
,
angles
);
constraints
=
new
ReferenceCCMAAlgorithm
(
system
.
getNumParticles
(),
numConstraints
,
constraintIndices
,
constraintDistances
,
particleMass
,
angles
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
}
// Initialize the energy minimizer.
...
...
@@ -443,7 +425,7 @@ void ReferenceIntegrateDrudeSCFStepKernel::execute(ContextImpl& context, const D
// Apply constraints.
if
(
constraints
!=
NULL
)
constraints
->
apply
(
numParticles
,
pos
,
xPrime
,
particleInvMass
);
constraints
->
apply
(
pos
,
xPrime
,
particleInvMass
);
// Record the constrained positions and velocities.
...
...
Prev
1
…
3
4
5
6
7
8
9
Next
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