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
0fa56f2e
Commit
0fa56f2e
authored
Apr 13, 2016
by
peastman
Browse files
Merge pull request #1461 from peastman/periodic
Allow periodic boundary conditions for bonded forces
parents
4bd2f9d2
b458028f
Changes
69
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
175 additions
and
35 deletions
+175
-35
platforms/cpu/include/CpuKernels.h
platforms/cpu/include/CpuKernels.h
+6
-3
platforms/cpu/src/CpuKernels.cpp
platforms/cpu/src/CpuKernels.cpp
+9
-0
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+25
-12
platforms/cuda/src/kernels/angleForce.cu
platforms/cuda/src/kernels/angleForce.cu
+4
-0
platforms/cuda/src/kernels/bondForce.cu
platforms/cuda/src/kernels/bondForce.cu
+3
-0
platforms/cuda/src/kernels/cmapTorsionForce.cu
platforms/cuda/src/kernels/cmapTorsionForce.cu
+10
-0
platforms/cuda/src/kernels/customCentroidBond.cu
platforms/cuda/src/kernels/customCentroidBond.cu
+5
-2
platforms/cuda/src/kernels/customCompoundBond.cu
platforms/cuda/src/kernels/customCompoundBond.cu
+4
-1
platforms/cuda/src/kernels/torsionForce.cu
platforms/cuda/src/kernels/torsionForce.cu
+5
-0
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+22
-12
platforms/opencl/src/kernels/angleForce.cl
platforms/opencl/src/kernels/angleForce.cl
+4
-0
platforms/opencl/src/kernels/bondForce.cl
platforms/opencl/src/kernels/bondForce.cl
+3
-0
platforms/opencl/src/kernels/cmapTorsionForce.cl
platforms/opencl/src/kernels/cmapTorsionForce.cl
+10
-0
platforms/opencl/src/kernels/customCentroidBond.cl
platforms/opencl/src/kernels/customCentroidBond.cl
+5
-2
platforms/opencl/src/kernels/customCompoundBond.cl
platforms/opencl/src/kernels/customCompoundBond.cl
+4
-1
platforms/opencl/src/kernels/torsionForce.cl
platforms/opencl/src/kernels/torsionForce.cl
+5
-0
platforms/reference/include/ReferenceAngleBondIxn.h
platforms/reference/include/ReferenceAngleBondIxn.h
+13
-0
platforms/reference/include/ReferenceCMAPTorsionIxn.h
platforms/reference/include/ReferenceCMAPTorsionIxn.h
+12
-0
platforms/reference/include/ReferenceCustomAngleIxn.h
platforms/reference/include/ReferenceCustomAngleIxn.h
+13
-1
platforms/reference/include/ReferenceCustomBondIxn.h
platforms/reference/include/ReferenceCustomBondIxn.h
+13
-1
No files found.
platforms/cpu/include/CpuKernels.h
View file @
0fa56f2e
...
...
@@ -98,7 +98,7 @@ private:
class
CpuCalcHarmonicAngleForceKernel
:
public
CalcHarmonicAngleForceKernel
{
public:
CpuCalcHarmonicAngleForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CpuPlatform
::
PlatformData
&
data
)
:
CalcHarmonicAngleForceKernel
(
name
,
platform
),
data
(
data
),
angleIndexArray
(
NULL
),
angleParamArray
(
NULL
)
{
CalcHarmonicAngleForceKernel
(
name
,
platform
),
data
(
data
),
angleIndexArray
(
NULL
),
angleParamArray
(
NULL
)
,
usePeriodic
(
false
)
{
}
~
CpuCalcHarmonicAngleForceKernel
();
/**
...
...
@@ -130,6 +130,7 @@ private:
int
**
angleIndexArray
;
RealOpenMM
**
angleParamArray
;
CpuBondForce
bondForce
;
bool
usePeriodic
;
};
/**
...
...
@@ -138,7 +139,7 @@ private:
class
CpuCalcPeriodicTorsionForceKernel
:
public
CalcPeriodicTorsionForceKernel
{
public:
CpuCalcPeriodicTorsionForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CpuPlatform
::
PlatformData
&
data
)
:
CalcPeriodicTorsionForceKernel
(
name
,
platform
),
data
(
data
),
torsionIndexArray
(
NULL
),
torsionParamArray
(
NULL
)
{
CalcPeriodicTorsionForceKernel
(
name
,
platform
),
data
(
data
),
torsionIndexArray
(
NULL
),
torsionParamArray
(
NULL
)
,
usePeriodic
(
false
)
{
}
~
CpuCalcPeriodicTorsionForceKernel
();
/**
...
...
@@ -170,6 +171,7 @@ private:
int
**
torsionIndexArray
;
RealOpenMM
**
torsionParamArray
;
CpuBondForce
bondForce
;
bool
usePeriodic
;
};
/**
...
...
@@ -178,7 +180,7 @@ private:
class
CpuCalcRBTorsionForceKernel
:
public
CalcRBTorsionForceKernel
{
public:
CpuCalcRBTorsionForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CpuPlatform
::
PlatformData
&
data
)
:
CalcRBTorsionForceKernel
(
name
,
platform
),
data
(
data
),
torsionIndexArray
(
NULL
),
torsionParamArray
(
NULL
)
{
CalcRBTorsionForceKernel
(
name
,
platform
),
data
(
data
),
torsionIndexArray
(
NULL
),
torsionParamArray
(
NULL
)
,
usePeriodic
(
false
)
{
}
~
CpuCalcRBTorsionForceKernel
();
/**
...
...
@@ -210,6 +212,7 @@ private:
int
**
torsionIndexArray
;
RealOpenMM
**
torsionParamArray
;
CpuBondForce
bondForce
;
bool
usePeriodic
;
};
/**
...
...
platforms/cpu/src/CpuKernels.cpp
View file @
0fa56f2e
...
...
@@ -283,6 +283,7 @@ void CpuCalcHarmonicAngleForceKernel::initialize(const System& system, const Har
angleParamArray
[
i
][
1
]
=
(
RealOpenMM
)
k
;
}
bondForce
.
initialize
(
system
.
getNumParticles
(),
numAngles
,
3
,
angleIndexArray
,
data
.
threads
);
usePeriodic
=
force
.
usesPeriodicBoundaryConditions
();
}
double
CpuCalcHarmonicAngleForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
...
...
@@ -290,6 +291,8 @@ double CpuCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool inclu
vector
<
RealVec
>&
forceData
=
extractForces
(
context
);
RealOpenMM
energy
=
0
;
ReferenceAngleBondIxn
angleBond
;
if
(
usePeriodic
)
angleBond
.
setPeriodic
(
extractBoxVectors
(
context
));
bondForce
.
calculateForce
(
posData
,
angleParamArray
,
forceData
,
includeEnergy
?
&
energy
:
NULL
,
angleBond
);
return
energy
;
}
...
...
@@ -343,6 +346,7 @@ void CpuCalcPeriodicTorsionForceKernel::initialize(const System& system, const P
torsionParamArray
[
i
][
2
]
=
(
RealOpenMM
)
periodicity
;
}
bondForce
.
initialize
(
system
.
getNumParticles
(),
numTorsions
,
4
,
torsionIndexArray
,
data
.
threads
);
usePeriodic
=
force
.
usesPeriodicBoundaryConditions
();
}
double
CpuCalcPeriodicTorsionForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
...
...
@@ -350,6 +354,8 @@ double CpuCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool inc
vector
<
RealVec
>&
forceData
=
extractForces
(
context
);
RealOpenMM
energy
=
0
;
ReferenceProperDihedralBond
periodicTorsionBond
;
if
(
usePeriodic
)
periodicTorsionBond
.
setPeriodic
(
extractBoxVectors
(
context
));
bondForce
.
calculateForce
(
posData
,
torsionParamArray
,
forceData
,
includeEnergy
?
&
energy
:
NULL
,
periodicTorsionBond
);
return
energy
;
}
...
...
@@ -407,6 +413,7 @@ void CpuCalcRBTorsionForceKernel::initialize(const System& system, const RBTorsi
torsionParamArray
[
i
][
5
]
=
(
RealOpenMM
)
c5
;
}
bondForce
.
initialize
(
system
.
getNumParticles
(),
numTorsions
,
4
,
torsionIndexArray
,
data
.
threads
);
usePeriodic
=
force
.
usesPeriodicBoundaryConditions
();
}
double
CpuCalcRBTorsionForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
...
...
@@ -414,6 +421,8 @@ double CpuCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeFo
vector
<
RealVec
>&
forceData
=
extractForces
(
context
);
RealOpenMM
energy
=
0
;
ReferenceRbDihedralBond
rbTorsionBond
;
if
(
usePeriodic
)
rbTorsionBond
.
setPeriodic
(
extractBoxVectors
(
context
));
bondForce
.
calculateForce
(
posData
,
torsionParamArray
,
forceData
,
includeEnergy
?
&
energy
:
NULL
,
rbTorsionBond
);
return
energy
;
}
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
0fa56f2e
...
...
@@ -502,6 +502,7 @@ void CudaCalcHarmonicBondForceKernel::initialize(const System& system, const Har
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
CudaKernelSources
::
harmonicBondForce
;
replacements
[
"PARAMS"
]
=
cu
.
getBondedUtilities
().
addArgument
(
params
->
getDevicePointer
(),
"float2"
);
cu
.
getBondedUtilities
().
addInteraction
(
atoms
,
cu
.
replaceStrings
(
CudaKernelSources
::
bondForce
,
replacements
),
force
.
getForceGroup
());
...
...
@@ -638,6 +639,7 @@ void CudaCalcCustomBondForceKernel::initialize(const System& system, const Custo
vector
<
pair
<
string
,
string
>
>
functionNames
;
compute
<<
cu
.
getExpressionUtilities
().
createExpressions
(
expressions
,
variables
,
functions
,
functionNames
,
"temp"
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
compute
.
str
();
cu
.
getBondedUtilities
().
addInteraction
(
atoms
,
cu
.
replaceStrings
(
CudaKernelSources
::
bondForce
,
replacements
),
force
.
getForceGroup
());
}
...
...
@@ -737,6 +739,7 @@ void CudaCalcHarmonicAngleForceKernel::initialize(const System& system, const Ha
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
CudaKernelSources
::
harmonicAngleForce
;
replacements
[
"PARAMS"
]
=
cu
.
getBondedUtilities
().
addArgument
(
params
->
getDevicePointer
(),
"float2"
);
cu
.
getBondedUtilities
().
addInteraction
(
atoms
,
cu
.
replaceStrings
(
CudaKernelSources
::
angleForce
,
replacements
),
force
.
getForceGroup
());
...
...
@@ -874,6 +877,7 @@ void CudaCalcCustomAngleForceKernel::initialize(const System& system, const Cust
vector
<
pair
<
string
,
string
>
>
functionNames
;
compute
<<
cu
.
getExpressionUtilities
().
createExpressions
(
expressions
,
variables
,
functions
,
functionNames
,
"temp"
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
compute
.
str
();
cu
.
getBondedUtilities
().
addInteraction
(
atoms
,
cu
.
replaceStrings
(
CudaKernelSources
::
angleForce
,
replacements
),
force
.
getForceGroup
());
}
...
...
@@ -974,6 +978,7 @@ void CudaCalcPeriodicTorsionForceKernel::initialize(const System& system, const
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
CudaKernelSources
::
periodicTorsionForce
;
replacements
[
"PARAMS"
]
=
cu
.
getBondedUtilities
().
addArgument
(
params
->
getDevicePointer
(),
"float4"
);
cu
.
getBondedUtilities
().
addInteraction
(
atoms
,
cu
.
replaceStrings
(
CudaKernelSources
::
torsionForce
,
replacements
),
force
.
getForceGroup
());
...
...
@@ -1069,6 +1074,7 @@ void CudaCalcRBTorsionForceKernel::initialize(const System& system, const RBTors
params1
->
upload
(
paramVector1
);
params2
->
upload
(
paramVector2
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
CudaKernelSources
::
rbTorsionForce
;
replacements
[
"PARAMS1"
]
=
cu
.
getBondedUtilities
().
addArgument
(
params1
->
getDevicePointer
(),
"float4"
);
replacements
[
"PARAMS2"
]
=
cu
.
getBondedUtilities
().
addArgument
(
params2
->
getDevicePointer
(),
"float2"
);
...
...
@@ -1186,6 +1192,7 @@ void CudaCalcCMAPTorsionForceKernel::initialize(const System& system, const CMAP
mapPositions
->
upload
(
mapPositionsVec
);
torsionMaps
->
upload
(
torsionMapsVec
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COEFF"
]
=
cu
.
getBondedUtilities
().
addArgument
(
coefficients
->
getDevicePointer
(),
"float4"
);
replacements
[
"MAP_POS"
]
=
cu
.
getBondedUtilities
().
addArgument
(
mapPositions
->
getDevicePointer
(),
"int2"
);
replacements
[
"MAPS"
]
=
cu
.
getBondedUtilities
().
addArgument
(
torsionMaps
->
getDevicePointer
(),
"int"
);
...
...
@@ -1341,6 +1348,7 @@ void CudaCalcCustomTorsionForceKernel::initialize(const System& system, const Cu
vector
<
pair
<
string
,
string
>
>
functionNames
;
compute
<<
cu
.
getExpressionUtilities
().
createExpressions
(
expressions
,
variables
,
functions
,
functionNames
,
"temp"
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
compute
.
str
();
cu
.
getBondedUtilities
().
addInteraction
(
atoms
,
cu
.
replaceStrings
(
CudaKernelSources
::
torsionForce
,
replacements
),
force
.
getForceGroup
());
}
...
...
@@ -4457,6 +4465,11 @@ void CudaCalcCustomCentroidBondForceKernel::initialize(const System& system, con
groupForcesArgs
.
push_back
(
NULL
);
// Energy buffer hasn't been created yet
groupForcesArgs
.
push_back
(
&
centerPositions
->
getDevicePointer
());
groupForcesArgs
.
push_back
(
&
bondGroups
->
getDevicePointer
());
groupForcesArgs
.
push_back
(
cu
.
getPeriodicBoxSizePointer
());
groupForcesArgs
.
push_back
(
cu
.
getInvPeriodicBoxSizePointer
());
groupForcesArgs
.
push_back
(
cu
.
getPeriodicBoxVecXPointer
());
groupForcesArgs
.
push_back
(
cu
.
getPeriodicBoxVecYPointer
());
groupForcesArgs
.
push_back
(
cu
.
getPeriodicBoxVecZPointer
());
// Record the tabulated functions.
...
...
@@ -4537,7 +4550,7 @@ void CudaCalcCustomCentroidBondForceKernel::initialize(const System& system, con
const
vector
<
int
>&
groups
=
iter
->
second
;
string
deltaName
=
atomNames
[
groups
[
0
]]
+
atomNames
[
groups
[
1
]];
if
(
computedDeltas
.
count
(
deltaName
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName
);
}
compute
<<
"real r_"
<<
deltaName
<<
" = sqrt(delta"
<<
deltaName
<<
".w);
\n
"
;
...
...
@@ -4551,11 +4564,11 @@ void CudaCalcCustomCentroidBondForceKernel::initialize(const System& system, con
string
deltaName2
=
atomNames
[
groups
[
1
]]
+
atomNames
[
groups
[
2
]];
string
angleName
=
"angle_"
+
atomNames
[
groups
[
0
]]
+
atomNames
[
groups
[
1
]]
+
atomNames
[
groups
[
2
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
0
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
0
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
2
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
2
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
compute
<<
"real "
<<
angleName
<<
" = computeAngle(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
@@ -4572,15 +4585,15 @@ void CudaCalcCustomCentroidBondForceKernel::initialize(const System& system, con
string
crossName2
=
"cross_"
+
deltaName2
+
"_"
+
deltaName3
;
string
dihedralName
=
"dihedral_"
+
atomNames
[
groups
[
0
]]
+
atomNames
[
groups
[
1
]]
+
atomNames
[
groups
[
2
]]
+
atomNames
[
groups
[
3
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
if
(
computedDeltas
.
count
(
deltaName3
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName3
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
3
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName3
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
3
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName3
);
}
compute
<<
"real4 "
<<
crossName1
<<
" = computeCross(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
@@ -4871,7 +4884,7 @@ void CudaCalcCustomCompoundBondForceKernel::initialize(const System& system, con
const
vector
<
int
>&
atoms
=
iter
->
second
;
string
deltaName
=
atomNames
[
atoms
[
0
]]
+
atomNames
[
atoms
[
1
]];
if
(
computedDeltas
.
count
(
deltaName
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName
);
}
compute
<<
"real r_"
<<
deltaName
<<
" = sqrt(delta"
<<
deltaName
<<
".w);
\n
"
;
...
...
@@ -4885,11 +4898,11 @@ void CudaCalcCustomCompoundBondForceKernel::initialize(const System& system, con
string
deltaName2
=
atomNames
[
atoms
[
1
]]
+
atomNames
[
atoms
[
2
]];
string
angleName
=
"angle_"
+
atomNames
[
atoms
[
0
]]
+
atomNames
[
atoms
[
1
]]
+
atomNames
[
atoms
[
2
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
0
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
0
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
2
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
2
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
compute
<<
"real "
<<
angleName
<<
" = ccb_computeAngle(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
@@ -4906,15 +4919,15 @@ void CudaCalcCustomCompoundBondForceKernel::initialize(const System& system, con
string
crossName2
=
"cross_"
+
deltaName2
+
"_"
+
deltaName3
;
string
dihedralName
=
"dihedral_"
+
atomNames
[
atoms
[
0
]]
+
atomNames
[
atoms
[
1
]]
+
atomNames
[
atoms
[
2
]]
+
atomNames
[
atoms
[
3
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
if
(
computedDeltas
.
count
(
deltaName3
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName3
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
3
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName3
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
3
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName3
);
}
compute
<<
"real4 "
<<
crossName1
<<
" = ccb_computeCross(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
platforms/cuda/src/kernels/angleForce.cu
View file @
0fa56f2e
real3
v0
=
make_real3
(
pos2
.
x
-
pos1
.
x
,
pos2
.
y
-
pos1
.
y
,
pos2
.
z
-
pos1
.
z
);
real3
v1
=
make_real3
(
pos2
.
x
-
pos3
.
x
,
pos2
.
y
-
pos3
.
y
,
pos2
.
z
-
pos3
.
z
);
#if APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
v0
)
APPLY_PERIODIC_TO_DELTA
(
v1
)
#endif
real3
cp
=
cross
(
v0
,
v1
);
real
rp
=
cp
.
x
*
cp
.
x
+
cp
.
y
*
cp
.
y
+
cp
.
z
*
cp
.
z
;
rp
=
max
(
SQRT
(
rp
),
(
real
)
1.0e-06
f
);
...
...
platforms/cuda/src/kernels/bondForce.cu
View file @
0fa56f2e
real3
delta
=
make_real3
(
pos2
.
x
-
pos1
.
x
,
pos2
.
y
-
pos1
.
y
,
pos2
.
z
-
pos1
.
z
);
#if APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
delta
)
#endif
real
r
=
SQRT
(
delta
.
x
*
delta
.
x
+
delta
.
y
*
delta
.
y
+
delta
.
z
*
delta
.
z
);
COMPUTE_FORCE
dEdR
=
(
r
>
0
)
?
(
dEdR
/
r
)
:
0
;
...
...
platforms/cuda/src/kernels/cmapTorsionForce.cu
View file @
0fa56f2e
...
...
@@ -5,6 +5,11 @@ const real PI = (real) 3.14159265358979323846;
real3
v0a
=
make_real3
(
pos1
.
x
-
pos2
.
x
,
pos1
.
y
-
pos2
.
y
,
pos1
.
z
-
pos2
.
z
);
real3
v1a
=
make_real3
(
pos3
.
x
-
pos2
.
x
,
pos3
.
y
-
pos2
.
y
,
pos3
.
z
-
pos2
.
z
);
real3
v2a
=
make_real3
(
pos3
.
x
-
pos4
.
x
,
pos3
.
y
-
pos4
.
y
,
pos3
.
z
-
pos4
.
z
);
#if APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
v0a
)
APPLY_PERIODIC_TO_DELTA
(
v1a
)
APPLY_PERIODIC_TO_DELTA
(
v2a
)
#endif
real3
cp0a
=
cross
(
v0a
,
v1a
);
real3
cp1a
=
cross
(
v1a
,
v2a
);
real
cosangle
=
dot
(
normalize
(
cp0a
),
normalize
(
cp1a
));
...
...
@@ -28,6 +33,11 @@ angleA = fmod(angleA+2.0f*PI, 2.0f*PI);
real3
v0b
=
make_real3
(
pos5
.
x
-
pos6
.
x
,
pos5
.
y
-
pos6
.
y
,
pos5
.
z
-
pos6
.
z
);
real3
v1b
=
make_real3
(
pos7
.
x
-
pos6
.
x
,
pos7
.
y
-
pos6
.
y
,
pos7
.
z
-
pos6
.
z
);
real3
v2b
=
make_real3
(
pos7
.
x
-
pos8
.
x
,
pos7
.
y
-
pos8
.
y
,
pos7
.
z
-
pos8
.
z
);
#if APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
v0b
)
APPLY_PERIODIC_TO_DELTA
(
v1b
)
APPLY_PERIODIC_TO_DELTA
(
v2b
)
#endif
real3
cp0b
=
cross
(
v0b
,
v1b
);
real3
cp1b
=
cross
(
v1b
,
v2b
);
cosangle
=
dot
(
normalize
(
cp0b
),
normalize
(
cp1b
));
...
...
platforms/cuda/src/kernels/customCentroidBond.cu
View file @
0fa56f2e
...
...
@@ -66,8 +66,11 @@ inline __device__ real3 trim(real4 v) {
/**
* Compute the difference between two vectors, setting the fourth component to the squared magnitude.
*/
inline
__device__
real4
delta
(
real4
vec1
,
real4
vec2
)
{
inline
__device__
real4
delta
(
real4
vec1
,
real4
vec2
,
bool
periodic
,
real4
periodicBoxSize
,
real4
invPeriodicBoxSize
,
real4
periodicBoxVecX
,
real4
periodicBoxVecY
,
real4
periodicBoxVecZ
)
{
real4
result
=
make_real4
(
vec1
.
x
-
vec2
.
x
,
vec1
.
y
-
vec2
.
y
,
vec1
.
z
-
vec2
.
z
,
0
);
if
(
periodic
)
APPLY_PERIODIC_TO_DELTA
(
result
);
result
.
w
=
result
.
x
*
result
.
x
+
result
.
y
*
result
.
y
+
result
.
z
*
result
.
z
;
return
result
;
}
...
...
@@ -105,7 +108,7 @@ inline __device__ real4 computeCross(real4 vec1, real4 vec2) {
* Compute the forces on groups based on the bonds.
*/
extern
"C"
__global__
void
computeGroupForces
(
unsigned
long
long
*
__restrict__
groupForce
,
mixed
*
__restrict__
energyBuffer
,
const
real4
*
__restrict__
centerPositions
,
const
int
*
__restrict__
bondGroups
const
int
*
__restrict__
bondGroups
,
real4
periodicBoxSize
,
real4
invPeriodicBoxSize
,
real4
periodicBoxVecX
,
real4
periodicBoxVecY
,
real4
periodicBoxVecZ
EXTRA_ARGS
)
{
mixed
energy
=
0
;
for
(
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
index
<
NUM_BONDS
;
index
+=
blockDim
.
x
*
gridDim
.
x
)
{
...
...
platforms/cuda/src/kernels/customCompoundBond.cu
View file @
0fa56f2e
...
...
@@ -8,8 +8,11 @@ inline __device__ real3 ccb_trim(real4 v) {
/**
* Compute the difference between two vectors, setting the fourth component to the squared magnitude.
*/
inline
__device__
real4
ccb_delta
(
real4
vec1
,
real4
vec2
)
{
inline
__device__
real4
ccb_delta
(
real4
vec1
,
real4
vec2
,
bool
periodic
,
real4
periodicBoxSize
,
real4
invPeriodicBoxSize
,
real4
periodicBoxVecX
,
real4
periodicBoxVecY
,
real4
periodicBoxVecZ
)
{
real4
result
=
make_real4
(
vec1
.
x
-
vec2
.
x
,
vec1
.
y
-
vec2
.
y
,
vec1
.
z
-
vec2
.
z
,
0
);
if
(
periodic
)
APPLY_PERIODIC_TO_DELTA
(
result
);
result
.
w
=
result
.
x
*
result
.
x
+
result
.
y
*
result
.
y
+
result
.
z
*
result
.
z
;
return
result
;
}
...
...
platforms/cuda/src/kernels/torsionForce.cu
View file @
0fa56f2e
...
...
@@ -2,6 +2,11 @@ const real PI = (real) 3.14159265358979323846;
real3
v0
=
make_real3
(
pos1
.
x
-
pos2
.
x
,
pos1
.
y
-
pos2
.
y
,
pos1
.
z
-
pos2
.
z
);
real3
v1
=
make_real3
(
pos3
.
x
-
pos2
.
x
,
pos3
.
y
-
pos2
.
y
,
pos3
.
z
-
pos2
.
z
);
real3
v2
=
make_real3
(
pos3
.
x
-
pos4
.
x
,
pos3
.
y
-
pos4
.
y
,
pos3
.
z
-
pos4
.
z
);
#if APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
v0
)
APPLY_PERIODIC_TO_DELTA
(
v1
)
APPLY_PERIODIC_TO_DELTA
(
v2
)
#endif
real3
cp0
=
cross
(
v0
,
v1
);
real3
cp1
=
cross
(
v1
,
v2
);
real
cosangle
=
dot
(
normalize
(
cp0
),
normalize
(
cp1
));
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
0fa56f2e
...
...
@@ -527,6 +527,7 @@ void OpenCLCalcHarmonicBondForceKernel::initialize(const System& system, const H
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
OpenCLKernelSources
::
harmonicBondForce
;
replacements
[
"PARAMS"
]
=
cl
.
getBondedUtilities
().
addArgument
(
params
->
getDeviceBuffer
(),
"float2"
);
cl
.
getBondedUtilities
().
addInteraction
(
atoms
,
cl
.
replaceStrings
(
OpenCLKernelSources
::
bondForce
,
replacements
),
force
.
getForceGroup
());
...
...
@@ -660,6 +661,7 @@ void OpenCLCalcCustomBondForceKernel::initialize(const System& system, const Cus
vector
<
pair
<
string
,
string
>
>
functionNames
;
compute
<<
cl
.
getExpressionUtilities
().
createExpressions
(
expressions
,
variables
,
functions
,
functionNames
,
"temp"
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
compute
.
str
();
cl
.
getBondedUtilities
().
addInteraction
(
atoms
,
cl
.
replaceStrings
(
OpenCLKernelSources
::
bondForce
,
replacements
),
force
.
getForceGroup
());
}
...
...
@@ -756,6 +758,7 @@ void OpenCLCalcHarmonicAngleForceKernel::initialize(const System& system, const
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
OpenCLKernelSources
::
harmonicAngleForce
;
replacements
[
"PARAMS"
]
=
cl
.
getBondedUtilities
().
addArgument
(
params
->
getDeviceBuffer
(),
"float2"
);
cl
.
getBondedUtilities
().
addInteraction
(
atoms
,
cl
.
replaceStrings
(
OpenCLKernelSources
::
angleForce
,
replacements
),
force
.
getForceGroup
());
...
...
@@ -890,6 +893,7 @@ void OpenCLCalcCustomAngleForceKernel::initialize(const System& system, const Cu
vector
<
pair
<
string
,
string
>
>
functionNames
;
compute
<<
cl
.
getExpressionUtilities
().
createExpressions
(
expressions
,
variables
,
functions
,
functionNames
,
"temp"
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
compute
.
str
();
cl
.
getBondedUtilities
().
addInteraction
(
atoms
,
cl
.
replaceStrings
(
OpenCLKernelSources
::
angleForce
,
replacements
),
force
.
getForceGroup
());
}
...
...
@@ -987,6 +991,7 @@ void OpenCLCalcPeriodicTorsionForceKernel::initialize(const System& system, cons
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
OpenCLKernelSources
::
periodicTorsionForce
;
replacements
[
"PARAMS"
]
=
cl
.
getBondedUtilities
().
addArgument
(
params
->
getDeviceBuffer
(),
"float4"
);
cl
.
getBondedUtilities
().
addInteraction
(
atoms
,
cl
.
replaceStrings
(
OpenCLKernelSources
::
torsionForce
,
replacements
),
force
.
getForceGroup
());
...
...
@@ -1073,6 +1078,7 @@ void OpenCLCalcRBTorsionForceKernel::initialize(const System& system, const RBTo
}
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
OpenCLKernelSources
::
rbTorsionForce
;
replacements
[
"PARAMS"
]
=
cl
.
getBondedUtilities
().
addArgument
(
params
->
getDeviceBuffer
(),
"float8"
);
cl
.
getBondedUtilities
().
addInteraction
(
atoms
,
cl
.
replaceStrings
(
OpenCLKernelSources
::
torsionForce
,
replacements
),
force
.
getForceGroup
());
...
...
@@ -1184,6 +1190,7 @@ void OpenCLCalcCMAPTorsionForceKernel::initialize(const System& system, const CM
mapPositions
->
upload
(
mapPositionsVec
);
torsionMaps
->
upload
(
torsionMapsVec
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COEFF"
]
=
cl
.
getBondedUtilities
().
addArgument
(
coefficients
->
getDeviceBuffer
(),
"float4"
);
replacements
[
"MAP_POS"
]
=
cl
.
getBondedUtilities
().
addArgument
(
mapPositions
->
getDeviceBuffer
(),
"int2"
);
replacements
[
"MAPS"
]
=
cl
.
getBondedUtilities
().
addArgument
(
torsionMaps
->
getDeviceBuffer
(),
"int"
);
...
...
@@ -1338,6 +1345,7 @@ void OpenCLCalcCustomTorsionForceKernel::initialize(const System& system, const
vector
<
pair
<
string
,
string
>
>
functionNames
;
compute
<<
cl
.
getExpressionUtilities
().
createExpressions
(
expressions
,
variables
,
functions
,
functionNames
,
"temp"
);
map
<
string
,
string
>
replacements
;
replacements
[
"APPLY_PERIODIC"
]
=
(
force
.
usesPeriodicBoundaryConditions
()
?
"1"
:
"0"
);
replacements
[
"COMPUTE_FORCE"
]
=
compute
.
str
();
cl
.
getBondedUtilities
().
addInteraction
(
atoms
,
cl
.
replaceStrings
(
OpenCLKernelSources
::
torsionForce
,
replacements
),
force
.
getForceGroup
());
}
...
...
@@ -4721,7 +4729,7 @@ void OpenCLCalcCustomCentroidBondForceKernel::initialize(const System& system, c
const
vector
<
int
>&
groups
=
iter
->
second
;
string
deltaName
=
atomNames
[
groups
[
0
]]
+
atomNames
[
groups
[
1
]];
if
(
computedDeltas
.
count
(
deltaName
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName
);
}
compute
<<
"real r_"
<<
deltaName
<<
" = sqrt(delta"
<<
deltaName
<<
".w);
\n
"
;
...
...
@@ -4735,11 +4743,11 @@ void OpenCLCalcCustomCentroidBondForceKernel::initialize(const System& system, c
string
deltaName2
=
atomNames
[
groups
[
1
]]
+
atomNames
[
groups
[
2
]];
string
angleName
=
"angle_"
+
atomNames
[
groups
[
0
]]
+
atomNames
[
groups
[
1
]]
+
atomNames
[
groups
[
2
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
0
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
0
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
2
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
1
]]
<<
", "
<<
posNames
[
groups
[
2
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
compute
<<
"real "
<<
angleName
<<
" = computeAngle(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
@@ -4756,15 +4764,15 @@ void OpenCLCalcCustomCentroidBondForceKernel::initialize(const System& system, c
string
crossName2
=
"cross_"
+
deltaName2
+
"_"
+
deltaName3
;
string
dihedralName
=
"dihedral_"
+
atomNames
[
groups
[
0
]]
+
atomNames
[
groups
[
1
]]
+
atomNames
[
groups
[
2
]]
+
atomNames
[
groups
[
3
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = delta("
<<
posNames
[
groups
[
0
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
if
(
computedDeltas
.
count
(
deltaName3
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName3
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
3
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName3
<<
" = delta("
<<
posNames
[
groups
[
2
]]
<<
", "
<<
posNames
[
groups
[
3
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName3
);
}
compute
<<
"real4 "
<<
crossName1
<<
" = computeCross(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
@@ -4885,6 +4893,7 @@ void OpenCLCalcCustomCentroidBondForceKernel::initialize(const System& system, c
index
++
;
// Energy buffer hasn't been created yet
groupForcesKernel
.
setArg
<
cl
::
Buffer
>
(
index
++
,
centerPositions
->
getDeviceBuffer
());
groupForcesKernel
.
setArg
<
cl
::
Buffer
>
(
index
++
,
bondGroups
->
getDeviceBuffer
());
index
+=
5
;
// Periodic box information
for
(
int
i
=
0
;
i
<
tabulatedFunctions
.
size
();
i
++
)
groupForcesKernel
.
setArg
<
cl
::
Buffer
>
(
index
++
,
tabulatedFunctions
[
i
]
->
getDeviceBuffer
());
if
(
globals
!=
NULL
)
...
...
@@ -4915,6 +4924,7 @@ double OpenCLCalcCustomCentroidBondForceKernel::execute(ContextImpl& context, bo
}
cl
.
executeKernel
(
computeCentersKernel
,
OpenCLContext
::
TileSize
*
numGroups
);
groupForcesKernel
.
setArg
<
cl
::
Buffer
>
(
1
,
cl
.
getEnergyBuffer
().
getDeviceBuffer
());
setPeriodicBoxArgs
(
cl
,
groupForcesKernel
,
4
);
cl
.
executeKernel
(
groupForcesKernel
,
numBonds
);
applyForcesKernel
.
setArg
<
cl
::
Buffer
>
(
4
,
cl
.
getLongForceBuffer
().
getDeviceBuffer
());
cl
.
executeKernel
(
applyForcesKernel
,
OpenCLContext
::
TileSize
*
numGroups
);
...
...
@@ -5070,7 +5080,7 @@ void OpenCLCalcCustomCompoundBondForceKernel::initialize(const System& system, c
const
vector
<
int
>&
atoms
=
iter
->
second
;
string
deltaName
=
atomNames
[
atoms
[
0
]]
+
atomNames
[
atoms
[
1
]];
if
(
computedDeltas
.
count
(
deltaName
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName
);
}
compute
<<
"real r_"
<<
deltaName
<<
" = sqrt(delta"
<<
deltaName
<<
".w);
\n
"
;
...
...
@@ -5084,11 +5094,11 @@ void OpenCLCalcCustomCompoundBondForceKernel::initialize(const System& system, c
string
deltaName2
=
atomNames
[
atoms
[
1
]]
+
atomNames
[
atoms
[
2
]];
string
angleName
=
"angle_"
+
atomNames
[
atoms
[
0
]]
+
atomNames
[
atoms
[
1
]]
+
atomNames
[
atoms
[
2
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
0
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
0
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
2
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
1
]]
<<
", "
<<
posNames
[
atoms
[
2
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
compute
<<
"real "
<<
angleName
<<
" = ccb_computeAngle(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
@@ -5105,15 +5115,15 @@ void OpenCLCalcCustomCompoundBondForceKernel::initialize(const System& system, c
string
crossName2
=
"cross_"
+
deltaName2
+
"_"
+
deltaName3
;
string
dihedralName
=
"dihedral_"
+
atomNames
[
atoms
[
0
]]
+
atomNames
[
atoms
[
1
]]
+
atomNames
[
atoms
[
2
]]
+
atomNames
[
atoms
[
3
]];
if
(
computedDeltas
.
count
(
deltaName1
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName1
<<
" = ccb_delta("
<<
posNames
[
atoms
[
0
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName1
);
}
if
(
computedDeltas
.
count
(
deltaName2
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName2
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
1
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName2
);
}
if
(
computedDeltas
.
count
(
deltaName3
)
==
0
)
{
compute
<<
"real4 delta"
<<
deltaName3
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
3
]]
<<
");
\n
"
;
compute
<<
"real4 delta"
<<
deltaName3
<<
" = ccb_delta("
<<
posNames
[
atoms
[
2
]]
<<
", "
<<
posNames
[
atoms
[
3
]]
<<
"
, "
<<
force
.
usesPeriodicBoundaryConditions
()
<<
", periodicBoxSize, invPeriodicBoxSize, periodicBoxVecX, periodicBoxVecY, periodicBoxVecZ
);
\n
"
;
computedDeltas
.
insert
(
deltaName3
);
}
compute
<<
"real4 "
<<
crossName1
<<
" = ccb_computeCross(delta"
<<
deltaName1
<<
", delta"
<<
deltaName2
<<
");
\n
"
;
...
...
platforms/opencl/src/kernels/angleForce.cl
View file @
0fa56f2e
real4
v0
=
pos2-pos1
;
real4
v1
=
pos2-pos3
;
#
if
APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
v0
)
APPLY_PERIODIC_TO_DELTA
(
v1
)
#
endif
real4
cp
=
cross
(
v0,
v1
)
;
real
rp
=
cp.x*cp.x
+
cp.y*cp.y
+
cp.z*cp.z
;
rp
=
max
(
SQRT
(
rp
)
,
(
real
)
1.0e-06f
)
;
...
...
platforms/opencl/src/kernels/bondForce.cl
View file @
0fa56f2e
real4
delta
=
pos2-pos1
;
#
if
APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
delta
)
#
endif
real
r
=
SQRT
(
delta.x*delta.x
+
delta.y*delta.y
+
delta.z*delta.z
)
;
COMPUTE_FORCE
dEdR
=
(
r
>
0.0f
)
?
(
dEdR
/
r
)
:
0.0f
;
...
...
platforms/opencl/src/kernels/cmapTorsionForce.cl
View file @
0fa56f2e
...
...
@@ -5,6 +5,11 @@ const real PI = 3.14159265358979323846f;
real4
v0a
=
(
real4
)
(
pos1.xyz-pos2.xyz,
0.0f
)
;
real4
v1a
=
(
real4
)
(
pos3.xyz-pos2.xyz,
0.0f
)
;
real4
v2a
=
(
real4
)
(
pos3.xyz-pos4.xyz,
0.0f
)
;
#
if
APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
v0a
)
APPLY_PERIODIC_TO_DELTA
(
v1a
)
APPLY_PERIODIC_TO_DELTA
(
v2a
)
#
endif
real4
cp0a
=
cross
(
v0a,
v1a
)
;
real4
cp1a
=
cross
(
v1a,
v2a
)
;
real
cosangle
=
dot
(
normalize
(
cp0a
)
,
normalize
(
cp1a
))
;
...
...
@@ -28,6 +33,11 @@ angleA = fmod(angleA+2.0f*PI, 2.0f*PI);
real4 v0b = (real4) (pos5.xyz-pos6.xyz, 0.0f);
real4 v1b = (real4) (pos7.xyz-pos6.xyz, 0.0f);
real4 v2b = (real4) (pos7.xyz-pos8.xyz, 0.0f);
#if APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA(v0b)
APPLY_PERIODIC_TO_DELTA(v1b)
APPLY_PERIODIC_TO_DELTA(v2b)
#endif
real4 cp0b = cross(v0b, v1b);
real4 cp1b = cross(v1b, v2b);
cosangle = dot(normalize(cp0b), normalize(cp1b));
...
...
platforms/opencl/src/kernels/customCentroidBond.cl
View file @
0fa56f2e
...
...
@@ -70,8 +70,11 @@ __kernel void computeGroupCenters(__global const real4* restrict posq, __global
/**
*
Compute
the
difference
between
two
vectors,
setting
the
fourth
component
to
the
squared
magnitude.
*/
real4
delta
(
real4
vec1,
real4
vec2
)
{
real4
delta
(
real4
vec1,
real4
vec2,
bool
periodic,
real4
periodicBoxSize,
real4
invPeriodicBoxSize,
real4
periodicBoxVecX,
real4
periodicBoxVecY,
real4
periodicBoxVecZ
)
{
real4
result
=
(
real4
)
(
vec1.x-vec2.x,
vec1.y-vec2.y,
vec1.z-vec2.z,
0
)
;
if
(
periodic
)
APPLY_PERIODIC_TO_DELTA
(
result
)
;
result.w
=
result.x*result.x
+
result.y*result.y
+
result.z*result.z
;
return
result
;
}
...
...
@@ -110,7 +113,7 @@ real4 computeCross(real4 vec1, real4 vec2) {
*
Compute
the
forces
on
groups
based
on
the
bonds.
*/
__kernel
void
computeGroupForces
(
__global
long*
restrict
groupForce,
__global
mixed*
restrict
energyBuffer,
__global
const
real4*
restrict
centerPositions,
__global
const
int*
restrict
bondGroups
__global
const
int*
restrict
bondGroups
,
real4
periodicBoxSize,
real4
invPeriodicBoxSize,
real4
periodicBoxVecX,
real4
periodicBoxVecY,
real4
periodicBoxVecZ
EXTRA_ARGS
)
{
mixed
energy
=
0
;
for
(
int
index
=
get_global_id
(
0
)
; index < NUM_BONDS; index += get_global_size(0)) {
...
...
platforms/opencl/src/kernels/customCompoundBond.cl
View file @
0fa56f2e
/**
*
Compute
the
difference
between
two
vectors,
setting
the
fourth
component
to
the
squared
magnitude.
*/
real4
ccb_delta
(
real4
vec1,
real4
vec2
)
{
real4
ccb_delta
(
real4
vec1,
real4
vec2,
bool
periodic,
real4
periodicBoxSize,
real4
invPeriodicBoxSize,
real4
periodicBoxVecX,
real4
periodicBoxVecY,
real4
periodicBoxVecZ
)
{
real4
result
=
(
real4
)
(
vec1.x-vec2.x,
vec1.y-vec2.y,
vec1.z-vec2.z,
0
)
;
if
(
periodic
)
APPLY_PERIODIC_TO_DELTA
(
result
)
;
result.w
=
result.x*result.x
+
result.y*result.y
+
result.z*result.z
;
return
result
;
}
...
...
platforms/opencl/src/kernels/torsionForce.cl
View file @
0fa56f2e
...
...
@@ -2,6 +2,11 @@ const real PI = 3.14159265358979323846f;
real4
v0
=
(
real4
)
(
pos1.xyz-pos2.xyz,
0.0f
)
;
real4
v1
=
(
real4
)
(
pos3.xyz-pos2.xyz,
0.0f
)
;
real4
v2
=
(
real4
)
(
pos3.xyz-pos4.xyz,
0.0f
)
;
#
if
APPLY_PERIODIC
APPLY_PERIODIC_TO_DELTA
(
v0
)
APPLY_PERIODIC_TO_DELTA
(
v1
)
APPLY_PERIODIC_TO_DELTA
(
v2
)
#
endif
real4
cp0
=
cross
(
v0,
v1
)
;
real4
cp1
=
cross
(
v1,
v2
)
;
real
cosangle
=
dot
(
normalize
(
cp0
)
,
normalize
(
cp1
))
;
...
...
platforms/reference/include/ReferenceAngleBondIxn.h
View file @
0fa56f2e
...
...
@@ -33,6 +33,9 @@ class OPENMM_EXPORT ReferenceAngleBondIxn : public ReferenceBondIxn {
private:
bool
usePeriodic
;
RealVec
boxVectors
[
3
];
public:
/**---------------------------------------------------------------------------------------
...
...
@@ -51,6 +54,16 @@ class OPENMM_EXPORT ReferenceAngleBondIxn : public ReferenceBondIxn {
~
ReferenceAngleBondIxn
();
/**---------------------------------------------------------------------------------------
Set the force to use periodic boundary conditions.
@param vectors the vectors defining the periodic box
--------------------------------------------------------------------------------------- */
void
setPeriodic
(
OpenMM
::
RealVec
*
vectors
);
/**---------------------------------------------------------------------------------------
Get dEdR and energy term for angle bond
...
...
platforms/reference/include/ReferenceCMAPTorsionIxn.h
View file @
0fa56f2e
...
...
@@ -38,6 +38,8 @@ private:
std
::
vector
<
std
::
vector
<
std
::
vector
<
RealOpenMM
>
>
>
coeff
;
std
::
vector
<
int
>
torsionMaps
;
std
::
vector
<
std
::
vector
<
int
>
>
torsionIndices
;
bool
usePeriodic
;
RealVec
boxVectors
[
3
];
/**---------------------------------------------------------------------------------------
...
...
@@ -65,6 +67,16 @@ public:
const
std
::
vector
<
int
>&
torsionMaps
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
torsionIndices
);
/**---------------------------------------------------------------------------------------
Set the force to use periodic boundary conditions.
@param vectors the vectors defining the periodic box
--------------------------------------------------------------------------------------- */
void
setPeriodic
(
OpenMM
::
RealVec
*
vectors
);
/**---------------------------------------------------------------------------------------
Calculate torsion interaction
...
...
platforms/reference/include/ReferenceCustomAngleIxn.h
View file @
0fa56f2e
/* Portions copyright (c) 2010-201
3
Stanford University and Simbios.
/* Portions copyright (c) 2010-201
6
Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
...
...
@@ -39,6 +39,8 @@ class ReferenceCustomAngleIxn : public ReferenceBondIxn {
double
*
energyTheta
;
double
*
forceTheta
;
int
numParameters
;
bool
usePeriodic
;
RealVec
boxVectors
[
3
];
public:
...
...
@@ -59,6 +61,16 @@ class ReferenceCustomAngleIxn : public ReferenceBondIxn {
~
ReferenceCustomAngleIxn
();
/**---------------------------------------------------------------------------------------
Set the force to use periodic boundary conditions.
@param vectors the vectors defining the periodic box
--------------------------------------------------------------------------------------- */
void
setPeriodic
(
OpenMM
::
RealVec
*
vectors
);
/**---------------------------------------------------------------------------------------
Calculate Custom Angle Ixn
...
...
platforms/reference/include/ReferenceCustomBondIxn.h
View file @
0fa56f2e
/* Portions copyright (c) 2009-201
3
Stanford University and Simbios.
/* Portions copyright (c) 2009-201
6
Stanford University and Simbios.
* Contributors: Peter Eastman
*
* Permission is hereby granted, free of charge, to any person obtaining
...
...
@@ -40,6 +40,8 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
double
*
energyR
;
double
*
forceR
;
int
numParameters
;
bool
usePeriodic
;
RealVec
boxVectors
[
3
];
public:
...
...
@@ -60,6 +62,16 @@ class ReferenceCustomBondIxn : public ReferenceBondIxn {
~
ReferenceCustomBondIxn
();
/**---------------------------------------------------------------------------------------
Set the force to use periodic boundary conditions.
@param vectors the vectors defining the periodic box
--------------------------------------------------------------------------------------- */
void
setPeriodic
(
OpenMM
::
RealVec
*
vectors
);
/**---------------------------------------------------------------------------------------
Calculate Custom Bond Ixn
...
...
Prev
1
2
3
4
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