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
a783b996
Commit
a783b996
authored
Jan 13, 2017
by
peastman
Browse files
Eliminated RealOpenMM type
parent
9500f3af
Changes
148
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
552 additions
and
778 deletions
+552
-778
platforms/reference/src/SimTKReference/ReferenceConstraints.cpp
...rms/reference/src/SimTKReference/ReferenceConstraints.cpp
+8
-8
platforms/reference/src/SimTKReference/ReferenceCustomAngleIxn.cpp
.../reference/src/SimTKReference/ReferenceCustomAngleIxn.cpp
+18
-18
platforms/reference/src/SimTKReference/ReferenceCustomBondIxn.cpp
...s/reference/src/SimTKReference/ReferenceCustomBondIxn.cpp
+15
-15
platforms/reference/src/SimTKReference/ReferenceCustomCentroidBondIxn.cpp
...nce/src/SimTKReference/ReferenceCustomCentroidBondIxn.cpp
+38
-38
platforms/reference/src/SimTKReference/ReferenceCustomCompoundBondIxn.cpp
...nce/src/SimTKReference/ReferenceCustomCompoundBondIxn.cpp
+36
-36
platforms/reference/src/SimTKReference/ReferenceCustomDynamics.cpp
.../reference/src/SimTKReference/ReferenceCustomDynamics.cpp
+19
-19
platforms/reference/src/SimTKReference/ReferenceCustomExternalIxn.cpp
...ference/src/SimTKReference/ReferenceCustomExternalIxn.cpp
+8
-17
platforms/reference/src/SimTKReference/ReferenceCustomGBIxn.cpp
...rms/reference/src/SimTKReference/ReferenceCustomGBIxn.cpp
+51
-51
platforms/reference/src/SimTKReference/ReferenceCustomHbondIxn.cpp
.../reference/src/SimTKReference/ReferenceCustomHbondIxn.cpp
+38
-44
platforms/reference/src/SimTKReference/ReferenceCustomManyParticleIxn.cpp
...nce/src/SimTKReference/ReferenceCustomManyParticleIxn.cpp
+41
-41
platforms/reference/src/SimTKReference/ReferenceCustomNonbondedIxn.cpp
...erence/src/SimTKReference/ReferenceCustomNonbondedIxn.cpp
+19
-26
platforms/reference/src/SimTKReference/ReferenceCustomTorsionIxn.cpp
...eference/src/SimTKReference/ReferenceCustomTorsionIxn.cpp
+25
-25
platforms/reference/src/SimTKReference/ReferenceDynamics.cpp
platforms/reference/src/SimTKReference/ReferenceDynamics.cpp
+7
-88
platforms/reference/src/SimTKReference/ReferenceForce.cpp
platforms/reference/src/SimTKReference/ReferenceForce.cpp
+17
-17
platforms/reference/src/SimTKReference/ReferenceGayBerneForce.cpp
...s/reference/src/SimTKReference/ReferenceGayBerneForce.cpp
+61
-61
platforms/reference/src/SimTKReference/ReferenceHarmonicBondIxn.cpp
...reference/src/SimTKReference/ReferenceHarmonicBondIxn.cpp
+11
-20
platforms/reference/src/SimTKReference/ReferenceLJCoulomb14.cpp
...rms/reference/src/SimTKReference/ReferenceLJCoulomb14.cpp
+13
-51
platforms/reference/src/SimTKReference/ReferenceLJCoulombIxn.cpp
...ms/reference/src/SimTKReference/ReferenceLJCoulombIxn.cpp
+89
-126
platforms/reference/src/SimTKReference/ReferenceLincsAlgorithm.cpp
.../reference/src/SimTKReference/ReferenceLincsAlgorithm.cpp
+31
-70
platforms/reference/src/SimTKReference/ReferenceMonteCarloBarostat.cpp
...erence/src/SimTKReference/ReferenceMonteCarloBarostat.cpp
+7
-7
No files found.
platforms/reference/src/SimTKReference/ReferenceConstraints.cpp
View file @
a783b996
...
@@ -43,9 +43,9 @@ using namespace std;
...
@@ -43,9 +43,9 @@ using namespace std;
ReferenceConstraints
::
ReferenceConstraints
(
const
System
&
system
)
:
ccma
(
NULL
),
settle
(
NULL
)
{
ReferenceConstraints
::
ReferenceConstraints
(
const
System
&
system
)
:
ccma
(
NULL
),
settle
(
NULL
)
{
int
numParticles
=
system
.
getNumParticles
();
int
numParticles
=
system
.
getNumParticles
();
vector
<
RealOpenMM
>
masses
(
numParticles
);
vector
<
double
>
masses
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
(
RealOpenMM
)
system
.
getParticleMass
(
i
);
masses
[
i
]
=
system
.
getParticleMass
(
i
);
// Record the set of constraints and how many constraints each atom is involved in.
// Record the set of constraints and how many constraints each atom is involved in.
...
@@ -102,8 +102,8 @@ ReferenceConstraints::ReferenceConstraints(const System& system) : ccma(NULL), s
...
@@ -102,8 +102,8 @@ ReferenceConstraints::ReferenceConstraints(const System& system) : ccma(NULL), s
vector
<
int
>
atom1
;
vector
<
int
>
atom1
;
vector
<
int
>
atom2
;
vector
<
int
>
atom2
;
vector
<
int
>
atom3
;
vector
<
int
>
atom3
;
vector
<
RealOpenMM
>
distance1
;
vector
<
double
>
distance1
;
vector
<
RealOpenMM
>
distance2
;
vector
<
double
>
distance2
;
for
(
int
i
=
0
;
i
<
settleClusters
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
settleClusters
.
size
();
i
++
)
{
int
p1
=
settleClusters
[
i
];
int
p1
=
settleClusters
[
i
];
int
p2
=
settleConstraints
[
p1
].
begin
()
->
first
;
int
p2
=
settleConstraints
[
p1
].
begin
()
->
first
;
...
@@ -156,7 +156,7 @@ ReferenceConstraints::ReferenceConstraints(const System& system) : ccma(NULL), s
...
@@ -156,7 +156,7 @@ ReferenceConstraints::ReferenceConstraints(const System& system) : ccma(NULL), s
// Record particles and distances for CCMA.
// Record particles and distances for CCMA.
vector
<
pair
<
int
,
int
>
>
ccmaIndices
(
numCCMA
);
vector
<
pair
<
int
,
int
>
>
ccmaIndices
(
numCCMA
);
vector
<
RealOpenMM
>
ccmaDistance
(
numCCMA
);
vector
<
double
>
ccmaDistance
(
numCCMA
);
for
(
int
i
=
0
;
i
<
numCCMA
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numCCMA
;
i
++
)
{
int
index
=
ccmaConstraints
[
i
];
int
index
=
ccmaConstraints
[
i
];
ccmaIndices
[
i
]
=
make_pair
(
atom1
[
index
],
atom2
[
index
]);
ccmaIndices
[
i
]
=
make_pair
(
atom1
[
index
],
atom2
[
index
]);
...
@@ -173,7 +173,7 @@ ReferenceConstraints::ReferenceConstraints(const System& system) : ccma(NULL), s
...
@@ -173,7 +173,7 @@ ReferenceConstraints::ReferenceConstraints(const System& system) : ccma(NULL), s
int
atom1
,
atom2
,
atom3
;
int
atom1
,
atom2
,
atom3
;
double
angle
,
k
;
double
angle
,
k
;
force
->
getAngleParameters
(
j
,
atom1
,
atom2
,
atom3
,
angle
,
k
);
force
->
getAngleParameters
(
j
,
atom1
,
atom2
,
atom3
,
angle
,
k
);
angles
.
push_back
(
ReferenceCCMAAlgorithm
::
AngleInfo
(
atom1
,
atom2
,
atom3
,
(
RealOpenMM
)
angle
));
angles
.
push_back
(
ReferenceCCMAAlgorithm
::
AngleInfo
(
atom1
,
atom2
,
atom3
,
angle
));
}
}
}
}
}
}
...
@@ -191,14 +191,14 @@ ReferenceConstraints::~ReferenceConstraints() {
...
@@ -191,14 +191,14 @@ ReferenceConstraints::~ReferenceConstraints() {
delete
settle
;
delete
settle
;
}
}
void
ReferenceConstraints
::
apply
(
vector
<
OpenMM
::
Real
Vec
>&
atomCoordinates
,
vector
<
OpenMM
::
Real
Vec
>&
atomCoordinatesP
,
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
)
{
void
ReferenceConstraints
::
apply
(
vector
<
OpenMM
::
Vec
3
>&
atomCoordinates
,
vector
<
OpenMM
::
Vec
3
>&
atomCoordinatesP
,
vector
<
double
>&
inverseMasses
,
double
tolerance
)
{
if
(
ccma
!=
NULL
)
if
(
ccma
!=
NULL
)
ccma
->
apply
(
atomCoordinates
,
atomCoordinatesP
,
inverseMasses
,
tolerance
);
ccma
->
apply
(
atomCoordinates
,
atomCoordinatesP
,
inverseMasses
,
tolerance
);
if
(
settle
!=
NULL
)
if
(
settle
!=
NULL
)
settle
->
apply
(
atomCoordinates
,
atomCoordinatesP
,
inverseMasses
,
tolerance
);
settle
->
apply
(
atomCoordinates
,
atomCoordinatesP
,
inverseMasses
,
tolerance
);
}
}
void
ReferenceConstraints
::
applyToVelocities
(
vector
<
OpenMM
::
Real
Vec
>&
atomCoordinates
,
vector
<
OpenMM
::
Real
Vec
>&
velocities
,
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
)
{
void
ReferenceConstraints
::
applyToVelocities
(
vector
<
OpenMM
::
Vec
3
>&
atomCoordinates
,
vector
<
OpenMM
::
Vec
3
>&
velocities
,
vector
<
double
>&
inverseMasses
,
double
tolerance
)
{
if
(
ccma
!=
NULL
)
if
(
ccma
!=
NULL
)
ccma
->
applyToVelocities
(
atomCoordinates
,
velocities
,
inverseMasses
,
tolerance
);
ccma
->
applyToVelocities
(
atomCoordinates
,
velocities
,
inverseMasses
,
tolerance
);
if
(
settle
!=
NULL
)
if
(
settle
!=
NULL
)
...
...
platforms/reference/src/SimTKReference/ReferenceCustomAngleIxn.cpp
View file @
a783b996
...
@@ -62,7 +62,7 @@ ReferenceCustomAngleIxn::ReferenceCustomAngleIxn(const Lepton::CompiledExpressio
...
@@ -62,7 +62,7 @@ ReferenceCustomAngleIxn::ReferenceCustomAngleIxn(const Lepton::CompiledExpressio
ReferenceCustomAngleIxn
::~
ReferenceCustomAngleIxn
()
{
ReferenceCustomAngleIxn
::~
ReferenceCustomAngleIxn
()
{
}
}
void
ReferenceCustomAngleIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceCustomAngleIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
usePeriodic
=
true
;
usePeriodic
=
true
;
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
1
]
=
vectors
[
1
];
boxVectors
[
1
]
=
vectors
[
1
];
...
@@ -82,11 +82,11 @@ void ReferenceCustomAngleIxn::setPeriodic(OpenMM::RealVec* vectors) {
...
@@ -82,11 +82,11 @@ void ReferenceCustomAngleIxn::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomAngleIxn
::
calculateBondIxn
(
int
*
atomIndices
,
void
ReferenceCustomAngleIxn
::
calculateBondIxn
(
int
*
atomIndices
,
vector
<
Real
Vec
>&
atomCoordinates
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
double
*
parameters
,
vector
<
Real
Vec
>&
forces
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
RealOpenMM
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
expressionSet
.
setVariable
(
angleParamIndex
[
i
],
parameters
[
i
]);
expressionSet
.
setVariable
(
angleParamIndex
[
i
],
parameters
[
i
]);
...
@@ -105,30 +105,30 @@ void ReferenceCustomAngleIxn::calculateBondIxn(int* atomIndices,
...
@@ -105,30 +105,30 @@ void ReferenceCustomAngleIxn::calculateBondIxn(int* atomIndices,
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomAIndex
],
atomCoordinates
[
atomBIndex
],
deltaR
[
0
]);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomAIndex
],
atomCoordinates
[
atomBIndex
],
deltaR
[
0
]);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomCIndex
],
atomCoordinates
[
atomBIndex
],
deltaR
[
1
]);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomCIndex
],
atomCoordinates
[
atomBIndex
],
deltaR
[
1
]);
}
}
RealOpenMM
pVector
[
3
];
double
pVector
[
3
];
SimTKOpenMMUtilities
::
crossProductVector3
(
deltaR
[
0
],
deltaR
[
1
],
pVector
);
SimTKOpenMMUtilities
::
crossProductVector3
(
deltaR
[
0
],
deltaR
[
1
],
pVector
);
RealOpenMM
rp
=
SQRT
(
DOT3
(
pVector
,
pVector
));
double
rp
=
sqrt
(
DOT3
(
pVector
,
pVector
));
if
(
rp
<
1.0e-06
)
if
(
rp
<
1.0e-06
)
rp
=
(
RealOpenMM
)
1.0e-06
;
rp
=
1.0e-06
;
RealOpenMM
dot
=
DOT3
(
deltaR
[
0
],
deltaR
[
1
]);
double
dot
=
DOT3
(
deltaR
[
0
],
deltaR
[
1
]);
RealOpenMM
cosine
=
dot
/
SQRT
((
deltaR
[
0
][
ReferenceForce
::
R2Index
]
*
deltaR
[
1
][
ReferenceForce
::
R2Index
]));
double
cosine
=
dot
/
sqrt
((
deltaR
[
0
][
ReferenceForce
::
R2Index
]
*
deltaR
[
1
][
ReferenceForce
::
R2Index
]));
RealOpenMM
angle
;
double
angle
;
if
(
cosine
>=
1.0
)
if
(
cosine
>=
1.0
)
angle
=
0.0
;
angle
=
0.0
;
else
if
(
cosine
<=
-
1.0
)
else
if
(
cosine
<=
-
1.0
)
angle
=
PI_M
;
angle
=
PI_M
;
else
else
angle
=
ACOS
(
cosine
);
angle
=
acos
(
cosine
);
expressionSet
.
setVariable
(
thetaIndex
,
angle
);
expressionSet
.
setVariable
(
thetaIndex
,
angle
);
// Compute the force and energy, and apply them to the atoms.
// Compute the force and energy, and apply them to the atoms.
RealOpenMM
energy
=
(
RealOpenMM
)
energyExpression
.
evaluate
();
double
energy
=
energyExpression
.
evaluate
();
RealOpenMM
dEdR
=
(
RealOpenMM
)
forceExpression
.
evaluate
();
double
dEdR
=
forceExpression
.
evaluate
();
RealOpenMM
termA
=
dEdR
/
(
deltaR
[
0
][
ReferenceForce
::
R2Index
]
*
rp
);
double
termA
=
dEdR
/
(
deltaR
[
0
][
ReferenceForce
::
R2Index
]
*
rp
);
RealOpenMM
termC
=
-
dEdR
/
(
deltaR
[
1
][
ReferenceForce
::
R2Index
]
*
rp
);
double
termC
=
-
dEdR
/
(
deltaR
[
1
][
ReferenceForce
::
R2Index
]
*
rp
);
RealOpenMM
deltaCrossP
[
3
][
3
];
double
deltaCrossP
[
3
][
3
];
SimTKOpenMMUtilities
::
crossProductVector3
(
deltaR
[
0
],
pVector
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
deltaR
[
0
],
pVector
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
deltaR
[
1
],
pVector
,
deltaCrossP
[
2
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
deltaR
[
1
],
pVector
,
deltaCrossP
[
2
]);
...
...
platforms/reference/src/SimTKReference/ReferenceCustomBondIxn.cpp
View file @
a783b996
...
@@ -63,7 +63,7 @@ ReferenceCustomBondIxn::ReferenceCustomBondIxn(const Lepton::CompiledExpression&
...
@@ -63,7 +63,7 @@ ReferenceCustomBondIxn::ReferenceCustomBondIxn(const Lepton::CompiledExpression&
ReferenceCustomBondIxn
::~
ReferenceCustomBondIxn
()
{
ReferenceCustomBondIxn
::~
ReferenceCustomBondIxn
()
{
}
}
void
ReferenceCustomBondIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceCustomBondIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
usePeriodic
=
true
;
usePeriodic
=
true
;
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
1
]
=
vectors
[
1
];
boxVectors
[
1
]
=
vectors
[
1
];
...
@@ -83,11 +83,11 @@ void ReferenceCustomBondIxn::setPeriodic(OpenMM::RealVec* vectors) {
...
@@ -83,11 +83,11 @@ void ReferenceCustomBondIxn::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomBondIxn
::
calculateBondIxn
(
int
*
atomIndices
,
void
ReferenceCustomBondIxn
::
calculateBondIxn
(
int
*
atomIndices
,
vector
<
Real
Vec
>&
atomCoordinates
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
double
*
parameters
,
vector
<
Real
Vec
>&
forces
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
RealOpenMM
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
expressionSet
.
setVariable
(
bondParamIndex
[
i
],
parameters
[
i
]);
expressionSet
.
setVariable
(
bondParamIndex
[
i
],
parameters
[
i
]);
...
@@ -103,19 +103,19 @@ void ReferenceCustomBondIxn::calculateBondIxn(int* atomIndices,
...
@@ -103,19 +103,19 @@ void ReferenceCustomBondIxn::calculateBondIxn(int* atomIndices,
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomAIndex
],
atomCoordinates
[
atomBIndex
],
deltaR
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomAIndex
],
atomCoordinates
[
atomBIndex
],
deltaR
);
expressionSet
.
setVariable
(
rIndex
,
deltaR
[
ReferenceForce
::
RIndex
]);
expressionSet
.
setVariable
(
rIndex
,
deltaR
[
ReferenceForce
::
RIndex
]);
RealOpenMM
dEdR
=
(
RealOpenMM
)
forceExpression
.
evaluate
();
double
dEdR
=
forceExpression
.
evaluate
();
dEdR
=
deltaR
[
ReferenceForce
::
RIndex
]
>
0
?
(
dEdR
/
deltaR
[
ReferenceForce
::
RIndex
])
:
0
;
dEdR
=
deltaR
[
ReferenceForce
::
RIndex
]
>
0
?
(
dEdR
/
deltaR
[
ReferenceForce
::
RIndex
])
:
0
;
forces
[
atomAIndex
][
0
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
XIndex
];
forces
[
atomAIndex
][
0
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
XIndex
];
forces
[
atomAIndex
][
1
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
YIndex
];
forces
[
atomAIndex
][
1
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
YIndex
];
forces
[
atomAIndex
][
2
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
ZIndex
];
forces
[
atomAIndex
][
2
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
ZIndex
];
forces
[
atomBIndex
][
0
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
XIndex
];
forces
[
atomBIndex
][
0
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
XIndex
];
forces
[
atomBIndex
][
1
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
YIndex
];
forces
[
atomBIndex
][
1
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
YIndex
];
forces
[
atomBIndex
][
2
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
ZIndex
];
forces
[
atomBIndex
][
2
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
ZIndex
];
for
(
int
i
=
0
;
i
<
energyParamDerivExpressions
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
energyParamDerivExpressions
.
size
();
i
++
)
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
i
].
evaluate
();
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
i
].
evaluate
();
if
(
totalEnergy
!=
NULL
)
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpression
.
evaluate
();
*
totalEnergy
+=
energyExpression
.
evaluate
();
}
}
platforms/reference/src/SimTKReference/ReferenceCustomCentroidBondIxn.cpp
View file @
a783b996
...
@@ -86,21 +86,21 @@ ReferenceCustomCentroidBondIxn::ReferenceCustomCentroidBondIxn(int numGroupsPerB
...
@@ -86,21 +86,21 @@ ReferenceCustomCentroidBondIxn::ReferenceCustomCentroidBondIxn(int numGroupsPerB
ReferenceCustomCentroidBondIxn
::~
ReferenceCustomCentroidBondIxn
()
{
ReferenceCustomCentroidBondIxn
::~
ReferenceCustomCentroidBondIxn
()
{
}
}
void
ReferenceCustomCentroidBondIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceCustomCentroidBondIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
usePeriodic
=
true
;
usePeriodic
=
true
;
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
1
]
=
vectors
[
1
];
boxVectors
[
1
]
=
vectors
[
1
];
boxVectors
[
2
]
=
vectors
[
2
];
boxVectors
[
2
]
=
vectors
[
2
];
}
}
void
ReferenceCustomCentroidBondIxn
::
calculatePairIxn
(
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
bondParameters
,
void
ReferenceCustomCentroidBondIxn
::
calculatePairIxn
(
vector
<
Vec
3
>&
atomCoordinates
,
double
**
bondParameters
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Real
Vec
>&
forces
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
// First compute the center of each group.
// First compute the center of each group.
int
numGroups
=
groupAtoms
.
size
();
int
numGroups
=
groupAtoms
.
size
();
vector
<
Real
Vec
>
groupCenters
(
numGroups
);
vector
<
Vec
3
>
groupCenters
(
numGroups
);
for
(
int
group
=
0
;
group
<
numGroups
;
group
++
)
{
for
(
int
group
=
0
;
group
<
numGroups
;
group
++
)
{
for
(
int
i
=
0
;
i
<
groupAtoms
[
group
].
size
();
i
++
)
for
(
int
i
=
0
;
i
<
groupAtoms
[
group
].
size
();
i
++
)
groupCenters
[
group
]
+=
atomCoordinates
[
groupAtoms
[
group
][
i
]]
*
normalizedWeights
[
group
][
i
];
groupCenters
[
group
]
+=
atomCoordinates
[
groupAtoms
[
group
][
i
]]
*
normalizedWeights
[
group
][
i
];
...
@@ -110,7 +110,7 @@ void ReferenceCustomCentroidBondIxn::calculatePairIxn(vector<RealVec>& atomCoord
...
@@ -110,7 +110,7 @@ void ReferenceCustomCentroidBondIxn::calculatePairIxn(vector<RealVec>& atomCoord
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
vector
<
Real
Vec
>
groupForces
(
numGroups
);
vector
<
Vec
3
>
groupForces
(
numGroups
);
int
numBonds
=
bondGroups
.
size
();
int
numBonds
=
bondGroups
.
size
();
for
(
int
bond
=
0
;
bond
<
numBonds
;
bond
++
)
{
for
(
int
bond
=
0
;
bond
<
numBonds
;
bond
++
)
{
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
...
@@ -126,8 +126,8 @@ void ReferenceCustomCentroidBondIxn::calculatePairIxn(vector<RealVec>& atomCoord
...
@@ -126,8 +126,8 @@ void ReferenceCustomCentroidBondIxn::calculatePairIxn(vector<RealVec>& atomCoord
}
}
}
}
void
ReferenceCustomCentroidBondIxn
::
calculateOneIxn
(
int
bond
,
vector
<
Real
Vec
>&
groupCenters
,
void
ReferenceCustomCentroidBondIxn
::
calculateOneIxn
(
int
bond
,
vector
<
Vec
3
>&
groupCenters
,
vector
<
Real
Vec
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
vector
<
Vec
3
>&
forces
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
// Compute all of the variables the energy can depend on.
// Compute all of the variables the energy can depend on.
const
vector
<
int
>&
groups
=
bondGroups
[
bond
];
const
vector
<
int
>&
groups
=
bondGroups
[
bond
];
...
@@ -151,8 +151,8 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -151,8 +151,8 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
computeDelta
(
groups
[
term
.
g2
],
groups
[
term
.
g1
],
term
.
delta1
,
groupCenters
);
computeDelta
(
groups
[
term
.
g2
],
groups
[
term
.
g1
],
term
.
delta1
,
groupCenters
);
computeDelta
(
groups
[
term
.
g2
],
groups
[
term
.
g3
],
term
.
delta2
,
groupCenters
);
computeDelta
(
groups
[
term
.
g2
],
groups
[
term
.
g3
],
term
.
delta2
,
groupCenters
);
computeDelta
(
groups
[
term
.
g4
],
groups
[
term
.
g3
],
term
.
delta3
,
groupCenters
);
computeDelta
(
groups
[
term
.
g4
],
groups
[
term
.
g3
],
term
.
delta3
,
groupCenters
);
RealOpenMM
dotDihedral
,
signOfDihedral
;
double
dotDihedral
,
signOfDihedral
;
RealOpenMM
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
double
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
expressionSet
.
setVariable
(
term
.
index
,
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
));
expressionSet
.
setVariable
(
term
.
index
,
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
));
}
}
...
@@ -167,9 +167,9 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -167,9 +167,9 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
RealOpenMM
dEdR
=
(
RealOpenMM
)
(
term
.
forceExpression
.
evaluate
()
/
(
term
.
delta
[
ReferenceForce
::
RIndex
])
)
;
double
dEdR
=
term
.
forceExpression
.
evaluate
()
/
(
term
.
delta
[
ReferenceForce
::
RIndex
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
RealOpenMM
force
=
-
dEdR
*
term
.
delta
[
i
];
double
force
=
-
dEdR
*
term
.
delta
[
i
];
forces
[
groups
[
term
.
g1
]][
i
]
-=
force
;
forces
[
groups
[
term
.
g1
]][
i
]
-=
force
;
forces
[
groups
[
term
.
g2
]][
i
]
+=
force
;
forces
[
groups
[
term
.
g2
]][
i
]
+=
force
;
}
}
...
@@ -179,15 +179,15 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -179,15 +179,15 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
();
double
dEdTheta
=
term
.
forceExpression
.
evaluate
();
RealOpenMM
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
double
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
RealOpenMM
lengthThetaCross
=
SQRT
(
DOT3
(
thetaCross
,
thetaCross
));
double
lengthThetaCross
=
sqrt
(
DOT3
(
thetaCross
,
thetaCross
));
if
(
lengthThetaCross
<
1.0e-06
)
if
(
lengthThetaCross
<
1.0e-06
)
lengthThetaCross
=
(
RealOpenMM
)
1.0e-06
;
lengthThetaCross
=
1.0e-06
;
RealOpenMM
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
deltaCrossP
[
3
][
3
];
double
deltaCrossP
[
3
][
3
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
...
@@ -206,22 +206,22 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -206,22 +206,22 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
();
double
dEdTheta
=
term
.
forceExpression
.
evaluate
();
RealOpenMM
internalF
[
4
][
3
];
double
internalF
[
4
][
3
];
RealOpenMM
forceFactors
[
4
];
double
forceFactors
[
4
];
RealOpenMM
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
double
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
RealOpenMM
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
double
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
RealOpenMM
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
double
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
RealOpenMM
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
double
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
}
}
...
@@ -236,7 +236,7 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -236,7 +236,7 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
// Add the energy
// Add the energy
if
(
totalEnergy
)
if
(
totalEnergy
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpression
.
evaluate
();
*
totalEnergy
+=
energyExpression
.
evaluate
();
// Compute derivatives of the energy.
// Compute derivatives of the energy.
...
@@ -244,22 +244,22 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -244,22 +244,22 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<RealVec>&
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
i
].
evaluate
();
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
i
].
evaluate
();
}
}
void
ReferenceCustomCentroidBondIxn
::
computeDelta
(
int
group1
,
int
group2
,
RealOpenMM
*
delta
,
vector
<
Real
Vec
>&
groupCenters
)
const
{
void
ReferenceCustomCentroidBondIxn
::
computeDelta
(
int
group1
,
int
group2
,
double
*
delta
,
vector
<
Vec
3
>&
groupCenters
)
const
{
if
(
usePeriodic
)
if
(
usePeriodic
)
ReferenceForce
::
getDeltaRPeriodic
(
groupCenters
[
group1
],
groupCenters
[
group2
],
boxVectors
,
delta
);
ReferenceForce
::
getDeltaRPeriodic
(
groupCenters
[
group1
],
groupCenters
[
group2
],
boxVectors
,
delta
);
else
else
ReferenceForce
::
getDeltaR
(
groupCenters
[
group1
],
groupCenters
[
group2
],
delta
);
ReferenceForce
::
getDeltaR
(
groupCenters
[
group1
],
groupCenters
[
group2
],
delta
);
}
}
RealOpenMM
ReferenceCustomCentroidBondIxn
::
computeAngle
(
RealOpenMM
*
vec1
,
RealOpenMM
*
vec2
)
{
double
ReferenceCustomCentroidBondIxn
::
computeAngle
(
double
*
vec1
,
double
*
vec2
)
{
RealOpenMM
dot
=
DOT3
(
vec1
,
vec2
);
double
dot
=
DOT3
(
vec1
,
vec2
);
RealOpenMM
cosine
=
dot
/
SQRT
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
double
cosine
=
dot
/
sqrt
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
RealOpenMM
angle
;
double
angle
;
if
(
cosine
>=
1
)
if
(
cosine
>=
1
)
angle
=
0
;
angle
=
0
;
else
if
(
cosine
<=
-
1
)
else
if
(
cosine
<=
-
1
)
angle
=
PI_M
;
angle
=
PI_M
;
else
else
angle
=
ACOS
(
cosine
);
angle
=
acos
(
cosine
);
return
angle
;
return
angle
;
}
}
platforms/reference/src/SimTKReference/ReferenceCustomCompoundBondIxn.cpp
View file @
a783b996
...
@@ -97,7 +97,7 @@ ReferenceCustomCompoundBondIxn::ReferenceCustomCompoundBondIxn(int numParticlesP
...
@@ -97,7 +97,7 @@ ReferenceCustomCompoundBondIxn::ReferenceCustomCompoundBondIxn(int numParticlesP
ReferenceCustomCompoundBondIxn
::~
ReferenceCustomCompoundBondIxn
()
{
ReferenceCustomCompoundBondIxn
::~
ReferenceCustomCompoundBondIxn
()
{
}
}
void
ReferenceCustomCompoundBondIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceCustomCompoundBondIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
usePeriodic
=
true
;
usePeriodic
=
true
;
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
1
]
=
vectors
[
1
];
boxVectors
[
1
]
=
vectors
[
1
];
...
@@ -116,9 +116,9 @@ void ReferenceCustomCompoundBondIxn::setPeriodic(OpenMM::RealVec* vectors) {
...
@@ -116,9 +116,9 @@ void ReferenceCustomCompoundBondIxn::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomCompoundBondIxn
::
calculatePairIxn
(
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
bondParameters
,
void
ReferenceCustomCompoundBondIxn
::
calculatePairIxn
(
vector
<
Vec
3
>&
atomCoordinates
,
double
**
bondParameters
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Real
Vec
>&
forces
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
int
numBonds
=
bondAtoms
.
size
();
int
numBonds
=
bondAtoms
.
size
();
...
@@ -141,8 +141,8 @@ void ReferenceCustomCompoundBondIxn::calculatePairIxn(vector<RealVec>& atomCoord
...
@@ -141,8 +141,8 @@ void ReferenceCustomCompoundBondIxn::calculatePairIxn(vector<RealVec>& atomCoord
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomCompoundBondIxn
::
calculateOneIxn
(
int
bond
,
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceCustomCompoundBondIxn
::
calculateOneIxn
(
int
bond
,
vector
<
Vec
3
>&
atomCoordinates
,
vector
<
Real
Vec
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
vector
<
Vec
3
>&
forces
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
// Compute all of the variables the energy can depend on.
// Compute all of the variables the energy can depend on.
const
vector
<
int
>&
atoms
=
bondAtoms
[
bond
];
const
vector
<
int
>&
atoms
=
bondAtoms
[
bond
];
...
@@ -166,8 +166,8 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -166,8 +166,8 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p1
],
term
.
delta1
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p1
],
term
.
delta1
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p3
],
term
.
delta2
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p3
],
term
.
delta2
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p4
],
atoms
[
term
.
p3
],
term
.
delta3
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p4
],
atoms
[
term
.
p3
],
term
.
delta3
,
atomCoordinates
);
RealOpenMM
dotDihedral
,
signOfDihedral
;
double
dotDihedral
,
signOfDihedral
;
RealOpenMM
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
double
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
expressionSet
.
setVariable
(
term
.
index
,
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
));
expressionSet
.
setVariable
(
term
.
index
,
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
));
}
}
...
@@ -182,9 +182,9 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -182,9 +182,9 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
RealOpenMM
dEdR
=
(
RealOpenMM
)
(
term
.
forceExpression
.
evaluate
()
/
(
term
.
delta
[
ReferenceForce
::
RIndex
])
)
;
double
dEdR
=
term
.
forceExpression
.
evaluate
()
/
(
term
.
delta
[
ReferenceForce
::
RIndex
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
RealOpenMM
force
=
-
dEdR
*
term
.
delta
[
i
];
double
force
=
-
dEdR
*
term
.
delta
[
i
];
forces
[
atoms
[
term
.
p1
]][
i
]
-=
force
;
forces
[
atoms
[
term
.
p1
]][
i
]
-=
force
;
forces
[
atoms
[
term
.
p2
]][
i
]
+=
force
;
forces
[
atoms
[
term
.
p2
]][
i
]
+=
force
;
}
}
...
@@ -194,15 +194,15 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -194,15 +194,15 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
();
double
dEdTheta
=
term
.
forceExpression
.
evaluate
();
RealOpenMM
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
double
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
RealOpenMM
lengthThetaCross
=
SQRT
(
DOT3
(
thetaCross
,
thetaCross
));
double
lengthThetaCross
=
sqrt
(
DOT3
(
thetaCross
,
thetaCross
));
if
(
lengthThetaCross
<
1.0e-06
)
if
(
lengthThetaCross
<
1.0e-06
)
lengthThetaCross
=
(
RealOpenMM
)
1.0e-06
;
lengthThetaCross
=
1.0e-06
;
RealOpenMM
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
deltaCrossP
[
3
][
3
];
double
deltaCrossP
[
3
][
3
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
...
@@ -221,22 +221,22 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -221,22 +221,22 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
();
double
dEdTheta
=
term
.
forceExpression
.
evaluate
();
RealOpenMM
internalF
[
4
][
3
];
double
internalF
[
4
][
3
];
RealOpenMM
forceFactors
[
4
];
double
forceFactors
[
4
];
RealOpenMM
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
double
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
RealOpenMM
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
double
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
RealOpenMM
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
double
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
RealOpenMM
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
double
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
}
}
...
@@ -251,7 +251,7 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -251,7 +251,7 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
// Add the energy
// Add the energy
if
(
totalEnergy
)
if
(
totalEnergy
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpression
.
evaluate
();
*
totalEnergy
+=
energyExpression
.
evaluate
();
// Compute derivatives of the energy.
// Compute derivatives of the energy.
...
@@ -259,22 +259,22 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
...
@@ -259,22 +259,22 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<RealVec>&
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
i
].
evaluate
();
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
i
].
evaluate
();
}
}
void
ReferenceCustomCompoundBondIxn
::
computeDelta
(
int
atom1
,
int
atom2
,
RealOpenMM
*
delta
,
vector
<
Real
Vec
>&
atomCoordinates
)
const
{
void
ReferenceCustomCompoundBondIxn
::
computeDelta
(
int
atom1
,
int
atom2
,
double
*
delta
,
vector
<
Vec
3
>&
atomCoordinates
)
const
{
if
(
usePeriodic
)
if
(
usePeriodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
boxVectors
,
delta
);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
boxVectors
,
delta
);
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
delta
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
delta
);
}
}
RealOpenMM
ReferenceCustomCompoundBondIxn
::
computeAngle
(
RealOpenMM
*
vec1
,
RealOpenMM
*
vec2
)
{
double
ReferenceCustomCompoundBondIxn
::
computeAngle
(
double
*
vec1
,
double
*
vec2
)
{
RealOpenMM
dot
=
DOT3
(
vec1
,
vec2
);
double
dot
=
DOT3
(
vec1
,
vec2
);
RealOpenMM
cosine
=
dot
/
SQRT
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
double
cosine
=
dot
/
sqrt
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
RealOpenMM
angle
;
double
angle
;
if
(
cosine
>=
1
)
if
(
cosine
>=
1
)
angle
=
0
;
angle
=
0
;
else
if
(
cosine
<=
-
1
)
else
if
(
cosine
<=
-
1
)
angle
=
PI_M
;
angle
=
PI_M
;
else
else
angle
=
ACOS
(
cosine
);
angle
=
acos
(
cosine
);
return
angle
;
return
angle
;
}
}
platforms/reference/src/SimTKReference/ReferenceCustomDynamics.cpp
View file @
a783b996
...
@@ -89,7 +89,7 @@ ReferenceCustomDynamics::ReferenceCustomDynamics(int numberOfAtoms, const Custom
...
@@ -89,7 +89,7 @@ ReferenceCustomDynamics::ReferenceCustomDynamics(int numberOfAtoms, const Custom
ReferenceCustomDynamics
::~
ReferenceCustomDynamics
()
{
ReferenceCustomDynamics
::~
ReferenceCustomDynamics
()
{
}
}
void
ReferenceCustomDynamics
::
initialize
(
ContextImpl
&
context
,
vector
<
RealOpenMM
>&
masses
,
map
<
string
,
RealOpenMM
>&
globals
)
{
void
ReferenceCustomDynamics
::
initialize
(
ContextImpl
&
context
,
vector
<
double
>&
masses
,
map
<
string
,
double
>&
globals
)
{
// Some initialization can't be done in the constructor, since we need a ContextImpl from which to get the list of
// Some initialization can't be done in the constructor, since we need a ContextImpl from which to get the list of
// Context parameters. Instead, we do it the first time update() or computeKineticEnergy() is called.
// Context parameters. Instead, we do it the first time update() or computeKineticEnergy() is called.
...
@@ -197,14 +197,14 @@ ExpressionTreeNode ReferenceCustomDynamics::replaceDerivFunctions(const Expressi
...
@@ -197,14 +197,14 @@ ExpressionTreeNode ReferenceCustomDynamics::replaceDerivFunctions(const Expressi
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomDynamics
::
update
(
ContextImpl
&
context
,
int
numberOfAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceCustomDynamics
::
update
(
ContextImpl
&
context
,
int
numberOfAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
vector
<
Real
Vec
>&
velocities
,
vector
<
Real
Vec
>&
forces
,
vector
<
RealOpenMM
>&
masses
,
vector
<
Vec
3
>&
velocities
,
vector
<
Vec
3
>&
forces
,
vector
<
double
>&
masses
,
map
<
string
,
RealOpenMM
>&
globals
,
vector
<
vector
<
Real
Vec
>
>&
perDof
,
bool
&
forcesAreValid
,
RealOpenMM
tolerance
)
{
map
<
string
,
double
>&
globals
,
vector
<
vector
<
Vec
3
>
>&
perDof
,
bool
&
forcesAreValid
,
double
tolerance
)
{
if
(
invalidatesForces
.
size
()
==
0
)
if
(
invalidatesForces
.
size
()
==
0
)
initialize
(
context
,
masses
,
globals
);
initialize
(
context
,
masses
,
globals
);
int
numSteps
=
stepType
.
size
();
int
numSteps
=
stepType
.
size
();
globals
.
insert
(
context
.
getParameters
().
begin
(),
context
.
getParameters
().
end
());
globals
.
insert
(
context
.
getParameters
().
begin
(),
context
.
getParameters
().
end
());
for
(
map
<
string
,
RealOpenMM
>::
const_iterator
iter
=
globals
.
begin
();
iter
!=
globals
.
end
();
++
iter
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globals
.
begin
();
iter
!=
globals
.
end
();
++
iter
)
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
oldPos
=
atomCoordinates
;
oldPos
=
atomCoordinates
;
...
@@ -217,7 +217,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
...
@@ -217,7 +217,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
bool
computeForce
=
needsForces
[
step
]
||
computeBothForceAndEnergy
[
step
];
bool
computeForce
=
needsForces
[
step
]
||
computeBothForceAndEnergy
[
step
];
bool
computeEnergy
=
needsEnergy
[
step
]
||
computeBothForceAndEnergy
[
step
];
bool
computeEnergy
=
needsEnergy
[
step
]
||
computeBothForceAndEnergy
[
step
];
recordChangedParameters
(
context
,
globals
);
recordChangedParameters
(
context
,
globals
);
RealOpenMM
e
=
context
.
calcForcesAndEnergy
(
computeForce
,
computeEnergy
,
forceGroupFlags
[
step
]);
double
e
=
context
.
calcForcesAndEnergy
(
computeForce
,
computeEnergy
,
forceGroupFlags
[
step
]);
if
(
computeEnergy
)
{
if
(
computeEnergy
)
{
energy
=
e
;
energy
=
e
;
context
.
getEnergyParameterDerivatives
(
energyParamDerivs
);
context
.
getEnergyParameterDerivatives
(
energyParamDerivs
);
...
@@ -232,13 +232,13 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
...
@@ -232,13 +232,13 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
case
CustomIntegrator
::
ComputeGlobal
:
{
case
CustomIntegrator
::
ComputeGlobal
:
{
uniform
=
SimTKOpenMMUtilities
::
getUniformlyDistributedRandomNumber
();
uniform
=
SimTKOpenMMUtilities
::
getUniformlyDistributedRandomNumber
();
gaussian
=
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
();
gaussian
=
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
();
RealOpenMM
result
=
stepExpressions
[
step
][
0
].
evaluate
();
double
result
=
stepExpressions
[
step
][
0
].
evaluate
();
globals
[
stepVariable
[
step
]]
=
result
;
globals
[
stepVariable
[
step
]]
=
result
;
expressionSet
.
setVariable
(
stepVariableIndex
[
step
],
result
);
expressionSet
.
setVariable
(
stepVariableIndex
[
step
],
result
);
break
;
break
;
}
}
case
CustomIntegrator
::
ComputePerDof
:
{
case
CustomIntegrator
::
ComputePerDof
:
{
vector
<
Real
Vec
>*
results
=
NULL
;
vector
<
Vec
3
>*
results
=
NULL
;
if
(
stepVariableIndex
[
step
]
==
xIndex
)
if
(
stepVariableIndex
[
step
]
==
xIndex
)
results
=
&
atomCoordinates
;
results
=
&
atomCoordinates
;
else
if
(
stepVariableIndex
[
step
]
==
vIndex
)
else
if
(
stepVariableIndex
[
step
]
==
vIndex
)
...
@@ -255,7 +255,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
...
@@ -255,7 +255,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
}
}
case
CustomIntegrator
::
ComputeSum
:
{
case
CustomIntegrator
::
ComputeSum
:
{
computePerDof
(
numberOfAtoms
,
sumBuffer
,
atomCoordinates
,
velocities
,
forces
,
masses
,
perDof
,
stepExpressions
[
step
][
0
]);
computePerDof
(
numberOfAtoms
,
sumBuffer
,
atomCoordinates
,
velocities
,
forces
,
masses
,
perDof
,
stepExpressions
[
step
][
0
]);
RealOpenMM
sum
=
0.0
;
double
sum
=
0.0
;
for
(
int
j
=
0
;
j
<
numberOfAtoms
;
j
++
)
for
(
int
j
=
0
;
j
<
numberOfAtoms
;
j
++
)
if
(
masses
[
j
]
!=
0.0
)
if
(
masses
[
j
]
!=
0.0
)
sum
+=
sumBuffer
[
j
][
0
]
+
sumBuffer
[
j
][
1
]
+
sumBuffer
[
j
][
2
];
sum
+=
sumBuffer
[
j
][
0
]
+
sumBuffer
[
j
][
1
]
+
sumBuffer
[
j
][
2
];
...
@@ -276,7 +276,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
...
@@ -276,7 +276,7 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
recordChangedParameters
(
context
,
globals
);
recordChangedParameters
(
context
,
globals
);
context
.
updateContextState
();
context
.
updateContextState
();
globals
.
insert
(
context
.
getParameters
().
begin
(),
context
.
getParameters
().
end
());
globals
.
insert
(
context
.
getParameters
().
begin
(),
context
.
getParameters
().
end
());
for
(
map
<
string
,
RealOpenMM
>::
const_iterator
iter
=
globals
.
begin
();
iter
!=
globals
.
end
();
++
iter
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globals
.
begin
();
iter
!=
globals
.
end
();
++
iter
)
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
break
;
break
;
}
}
...
@@ -305,9 +305,9 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
...
@@ -305,9 +305,9 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
recordChangedParameters
(
context
,
globals
);
recordChangedParameters
(
context
,
globals
);
}
}
void
ReferenceCustomDynamics
::
computePerDof
(
int
numberOfAtoms
,
vector
<
Real
Vec
>&
results
,
const
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceCustomDynamics
::
computePerDof
(
int
numberOfAtoms
,
vector
<
Vec
3
>&
results
,
const
vector
<
Vec
3
>&
atomCoordinates
,
const
vector
<
Real
Vec
>&
velocities
,
const
vector
<
Real
Vec
>&
forces
,
const
vector
<
RealOpenMM
>&
masses
,
const
vector
<
Vec
3
>&
velocities
,
const
vector
<
Vec
3
>&
forces
,
const
vector
<
double
>&
masses
,
const
vector
<
vector
<
Real
Vec
>
>&
perDof
,
const
CompiledExpression
&
expression
)
{
const
vector
<
vector
<
Vec
3
>
>&
perDof
,
const
CompiledExpression
&
expression
)
{
// Loop over all degrees of freedom.
// Loop over all degrees of freedom.
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
...
@@ -354,7 +354,7 @@ bool ReferenceCustomDynamics::evaluateCondition(int step) {
...
@@ -354,7 +354,7 @@ bool ReferenceCustomDynamics::evaluateCondition(int step) {
/**
/**
* Check which context parameters have changed and register them with the context.
* Check which context parameters have changed and register them with the context.
*/
*/
void
ReferenceCustomDynamics
::
recordChangedParameters
(
OpenMM
::
ContextImpl
&
context
,
std
::
map
<
std
::
string
,
RealOpenMM
>&
globals
)
{
void
ReferenceCustomDynamics
::
recordChangedParameters
(
OpenMM
::
ContextImpl
&
context
,
std
::
map
<
std
::
string
,
double
>&
globals
)
{
for
(
map
<
string
,
double
>::
const_iterator
iter
=
context
.
getParameters
().
begin
();
iter
!=
context
.
getParameters
().
end
();
++
iter
)
{
for
(
map
<
string
,
double
>::
const_iterator
iter
=
context
.
getParameters
().
begin
();
iter
!=
context
.
getParameters
().
end
();
++
iter
)
{
string
name
=
iter
->
first
;
string
name
=
iter
->
first
;
double
value
=
globals
[
name
];
double
value
=
globals
[
name
];
...
@@ -379,20 +379,20 @@ void ReferenceCustomDynamics::recordChangedParameters(OpenMM::ContextImpl& conte
...
@@ -379,20 +379,20 @@ void ReferenceCustomDynamics::recordChangedParameters(OpenMM::ContextImpl& conte
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
double
ReferenceCustomDynamics
::
computeKineticEnergy
(
OpenMM
::
ContextImpl
&
context
,
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
Real
Vec
>&
atomCoordinates
,
double
ReferenceCustomDynamics
::
computeKineticEnergy
(
OpenMM
::
ContextImpl
&
context
,
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
Vec
3
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
Real
Vec
>&
velocities
,
std
::
vector
<
OpenMM
::
Real
Vec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
std
::
vector
<
OpenMM
::
Vec
3
>&
velocities
,
std
::
vector
<
OpenMM
::
Vec
3
>&
forces
,
std
::
vector
<
double
>&
masses
,
std
::
map
<
std
::
string
,
RealOpenMM
>&
globals
,
std
::
vector
<
std
::
vector
<
OpenMM
::
Real
Vec
>
>&
perDof
,
bool
&
forcesAreValid
)
{
std
::
map
<
std
::
string
,
double
>&
globals
,
std
::
vector
<
std
::
vector
<
OpenMM
::
Vec
3
>
>&
perDof
,
bool
&
forcesAreValid
)
{
if
(
invalidatesForces
.
size
()
==
0
)
if
(
invalidatesForces
.
size
()
==
0
)
initialize
(
context
,
masses
,
globals
);
initialize
(
context
,
masses
,
globals
);
globals
.
insert
(
context
.
getParameters
().
begin
(),
context
.
getParameters
().
end
());
globals
.
insert
(
context
.
getParameters
().
begin
(),
context
.
getParameters
().
end
());
for
(
map
<
string
,
RealOpenMM
>::
const_iterator
iter
=
globals
.
begin
();
iter
!=
globals
.
end
();
++
iter
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globals
.
begin
();
iter
!=
globals
.
end
();
++
iter
)
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
if
(
kineticEnergyNeedsForce
)
{
if
(
kineticEnergyNeedsForce
)
{
energy
=
context
.
calcForcesAndEnergy
(
true
,
true
,
-
1
);
energy
=
context
.
calcForcesAndEnergy
(
true
,
true
,
-
1
);
forcesAreValid
=
true
;
forcesAreValid
=
true
;
}
}
computePerDof
(
numberOfAtoms
,
sumBuffer
,
atomCoordinates
,
velocities
,
forces
,
masses
,
perDof
,
kineticEnergyExpression
);
computePerDof
(
numberOfAtoms
,
sumBuffer
,
atomCoordinates
,
velocities
,
forces
,
masses
,
perDof
,
kineticEnergyExpression
);
RealOpenMM
sum
=
0.0
;
double
sum
=
0.0
;
for
(
int
j
=
0
;
j
<
numberOfAtoms
;
j
++
)
for
(
int
j
=
0
;
j
<
numberOfAtoms
;
j
++
)
if
(
masses
[
j
]
!=
0.0
)
if
(
masses
[
j
]
!=
0.0
)
sum
+=
sumBuffer
[
j
][
0
]
+
sumBuffer
[
j
][
1
]
+
sumBuffer
[
j
][
2
];
sum
+=
sumBuffer
[
j
][
0
]
+
sumBuffer
[
j
][
1
]
+
sumBuffer
[
j
][
2
];
...
...
platforms/reference/src/SimTKReference/ReferenceCustomExternalIxn.cpp
View file @
a783b996
...
@@ -78,13 +78,6 @@ ReferenceCustomExternalIxn::ReferenceCustomExternalIxn(const Lepton::CompiledExp
...
@@ -78,13 +78,6 @@ ReferenceCustomExternalIxn::ReferenceCustomExternalIxn(const Lepton::CompiledExp
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceCustomExternalIxn
::~
ReferenceCustomExternalIxn
()
{
ReferenceCustomExternalIxn
::~
ReferenceCustomExternalIxn
()
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceCustomExternalIxn::~ReferenceCustomExternalIxn";
// ---------------------------------------------------------------------------------------
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -100,12 +93,10 @@ ReferenceCustomExternalIxn::~ReferenceCustomExternalIxn() {
...
@@ -100,12 +93,10 @@ ReferenceCustomExternalIxn::~ReferenceCustomExternalIxn() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomExternalIxn
::
calculateForce
(
int
atomIndex
,
void
ReferenceCustomExternalIxn
::
calculateForce
(
int
atomIndex
,
vector
<
RealVec
>&
atomCoordinates
,
vector
<
Vec3
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
double
*
parameters
,
vector
<
RealVec
>&
forces
,
vector
<
Vec3
>&
forces
,
RealOpenMM
*
energy
)
const
{
double
*
energy
)
const
{
static
const
std
::
string
methodName
=
"
\n
ReferenceCustomExternalIxn::calculateBondIxn"
;
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
{
ReferenceForce
::
setVariable
(
energyParams
[
i
],
parameters
[
i
]);
ReferenceForce
::
setVariable
(
energyParams
[
i
],
parameters
[
i
]);
...
@@ -128,9 +119,9 @@ void ReferenceCustomExternalIxn::calculateForce(int atomIndex,
...
@@ -128,9 +119,9 @@ void ReferenceCustomExternalIxn::calculateForce(int atomIndex,
// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
forces
[
atomIndex
][
0
]
-=
(
RealOpenMM
)
forceExpressionX
.
evaluate
();
forces
[
atomIndex
][
0
]
-=
forceExpressionX
.
evaluate
();
forces
[
atomIndex
][
1
]
-=
(
RealOpenMM
)
forceExpressionY
.
evaluate
();
forces
[
atomIndex
][
1
]
-=
forceExpressionY
.
evaluate
();
forces
[
atomIndex
][
2
]
-=
(
RealOpenMM
)
forceExpressionZ
.
evaluate
();
forces
[
atomIndex
][
2
]
-=
forceExpressionZ
.
evaluate
();
if
(
energy
!=
NULL
)
if
(
energy
!=
NULL
)
*
energy
+=
(
RealOpenMM
)
energyExpression
.
evaluate
();
*
energy
+=
energyExpression
.
evaluate
();
}
}
platforms/reference/src/SimTKReference/ReferenceCustomGBIxn.cpp
View file @
a783b996
...
@@ -120,7 +120,7 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() {
...
@@ -120,7 +120,7 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomGBIxn
::
setUseCutoff
(
RealOpenMM
distance
,
const
OpenMM
::
NeighborList
&
neighbors
)
{
void
ReferenceCustomGBIxn
::
setUseCutoff
(
double
distance
,
const
OpenMM
::
NeighborList
&
neighbors
)
{
cutoff
=
true
;
cutoff
=
true
;
cutoffDistance
=
distance
;
cutoffDistance
=
distance
;
...
@@ -137,7 +137,7 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() {
...
@@ -137,7 +137,7 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomGBIxn
::
setPeriodic
(
Real
Vec
*
vectors
)
{
void
ReferenceCustomGBIxn
::
setPeriodic
(
Vec
3
*
vectors
)
{
if
(
cutoff
)
{
if
(
cutoff
)
{
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
...
@@ -150,9 +150,9 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() {
...
@@ -150,9 +150,9 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() {
periodicBoxVectors
[
2
]
=
vectors
[
2
];
periodicBoxVectors
[
2
]
=
vectors
[
2
];
}
}
void
ReferenceCustomGBIxn
::
calculateIxn
(
int
numberOfAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
void
ReferenceCustomGBIxn
::
calculateIxn
(
int
numberOfAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
,
const
vector
<
set
<
int
>
>&
exclusions
,
map
<
string
,
double
>&
globalParameters
,
vector
<
Real
Vec
>&
forces
,
const
vector
<
set
<
int
>
>&
exclusions
,
map
<
string
,
double
>&
globalParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
...
@@ -161,10 +161,10 @@ void ReferenceCustomGBIxn::calculateIxn(int numberOfAtoms, vector<RealVec>& atom
...
@@ -161,10 +161,10 @@ void ReferenceCustomGBIxn::calculateIxn(int numberOfAtoms, vector<RealVec>& atom
int
numValues
=
valueTypes
.
size
();
int
numValues
=
valueTypes
.
size
();
int
numDerivs
=
valueParamDerivExpressions
[
0
].
size
();
int
numDerivs
=
valueParamDerivExpressions
[
0
].
size
();
values
.
resize
(
numValues
);
values
.
resize
(
numValues
);
dEdV
.
resize
(
numValues
,
vector
<
RealOpenMM
>
(
numberOfAtoms
,
0.0
));
dEdV
.
resize
(
numValues
,
vector
<
double
>
(
numberOfAtoms
,
0.0
));
dValuedParam
.
resize
(
numValues
);
dValuedParam
.
resize
(
numValues
);
for
(
int
i
=
0
;
i
<
numValues
;
i
++
)
for
(
int
i
=
0
;
i
<
numValues
;
i
++
)
dValuedParam
[
i
].
resize
(
numDerivs
,
vector
<
RealOpenMM
>
(
numberOfAtoms
,
0.0
));
dValuedParam
[
i
].
resize
(
numDerivs
,
vector
<
double
>
(
numberOfAtoms
,
0.0
));
// First calculate the computed values.
// First calculate the computed values.
...
@@ -193,7 +193,7 @@ void ReferenceCustomGBIxn::calculateIxn(int numberOfAtoms, vector<RealVec>& atom
...
@@ -193,7 +193,7 @@ void ReferenceCustomGBIxn::calculateIxn(int numberOfAtoms, vector<RealVec>& atom
calculateChainRuleForces
(
numberOfAtoms
,
atomCoordinates
,
atomParameters
,
exclusions
,
forces
,
energyParamDerivs
);
calculateChainRuleForces
(
numberOfAtoms
,
atomCoordinates
,
atomParameters
,
exclusions
,
forces
,
energyParamDerivs
);
}
}
void
ReferenceCustomGBIxn
::
calculateSingleParticleValue
(
int
index
,
int
numAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
)
{
void
ReferenceCustomGBIxn
::
calculateSingleParticleValue
(
int
index
,
int
numAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
)
{
values
[
index
].
resize
(
numAtoms
);
values
[
index
].
resize
(
numAtoms
);
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
{
expressionSet
.
setVariable
(
xIndex
,
atomCoordinates
[
i
][
0
]);
expressionSet
.
setVariable
(
xIndex
,
atomCoordinates
[
i
][
0
]);
...
@@ -203,25 +203,25 @@ void ReferenceCustomGBIxn::calculateSingleParticleValue(int index, int numAtoms,
...
@@ -203,25 +203,25 @@ void ReferenceCustomGBIxn::calculateSingleParticleValue(int index, int numAtoms,
expressionSet
.
setVariable
(
paramIndex
[
j
],
atomParameters
[
i
][
j
]);
expressionSet
.
setVariable
(
paramIndex
[
j
],
atomParameters
[
i
][
j
]);
for
(
int
j
=
0
;
j
<
index
;
j
++
)
for
(
int
j
=
0
;
j
<
index
;
j
++
)
expressionSet
.
setVariable
(
valueIndex
[
j
],
values
[
j
][
i
]);
expressionSet
.
setVariable
(
valueIndex
[
j
],
values
[
j
][
i
]);
values
[
index
][
i
]
=
(
RealOpenMM
)
valueExpressions
[
index
].
evaluate
();
values
[
index
][
i
]
=
valueExpressions
[
index
].
evaluate
();
// Calculate derivatives with respect to parameters.
// Calculate derivatives with respect to parameters.
for
(
int
j
=
0
;
j
<
valueParamDerivExpressions
[
index
].
size
();
j
++
)
for
(
int
j
=
0
;
j
<
valueParamDerivExpressions
[
index
].
size
();
j
++
)
dValuedParam
[
index
][
j
][
i
]
+=
valueParamDerivExpressions
[
index
][
j
].
evaluate
();
dValuedParam
[
index
][
j
][
i
]
+=
valueParamDerivExpressions
[
index
][
j
].
evaluate
();
for
(
int
j
=
0
;
j
<
index
;
j
++
)
{
for
(
int
j
=
0
;
j
<
index
;
j
++
)
{
RealOpenMM
dVdV
=
valueDerivExpressions
[
index
][
j
].
evaluate
();
double
dVdV
=
valueDerivExpressions
[
index
][
j
].
evaluate
();
for
(
int
k
=
0
;
k
<
valueParamDerivExpressions
[
index
].
size
();
k
++
)
for
(
int
k
=
0
;
k
<
valueParamDerivExpressions
[
index
].
size
();
k
++
)
dValuedParam
[
index
][
k
][
i
]
+=
dVdV
*
dValuedParam
[
j
][
k
][
i
];
dValuedParam
[
index
][
k
][
i
]
+=
dVdV
*
dValuedParam
[
j
][
k
][
i
];
}
}
}
}
}
}
void
ReferenceCustomGBIxn
::
calculateParticlePairValue
(
int
index
,
int
numAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
void
ReferenceCustomGBIxn
::
calculateParticlePairValue
(
int
index
,
int
numAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
,
const
vector
<
set
<
int
>
>&
exclusions
,
bool
useExclusions
)
{
const
vector
<
set
<
int
>
>&
exclusions
,
bool
useExclusions
)
{
values
[
index
].
resize
(
numAtoms
);
values
[
index
].
resize
(
numAtoms
);
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
values
[
index
][
i
]
=
(
RealOpenMM
)
0.0
;
values
[
index
][
i
]
=
0.0
;
if
(
cutoff
)
{
if
(
cutoff
)
{
// Loop over all pairs in the neighbor list.
// Loop over all pairs in the neighbor list.
...
@@ -247,13 +247,13 @@ void ReferenceCustomGBIxn::calculateParticlePairValue(int index, int numAtoms, v
...
@@ -247,13 +247,13 @@ void ReferenceCustomGBIxn::calculateParticlePairValue(int index, int numAtoms, v
}
}
}
}
void
ReferenceCustomGBIxn
::
calculateOnePairValue
(
int
index
,
int
atom1
,
int
atom2
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
)
{
void
ReferenceCustomGBIxn
::
calculateOnePairValue
(
int
index
,
int
atom1
,
int
atom2
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
)
{
RealOpenMM
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
if
(
periodic
)
if
(
periodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
periodicBoxVectors
,
deltaR
);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
periodicBoxVectors
,
deltaR
);
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
deltaR
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
deltaR
);
RealOpenMM
r
=
deltaR
[
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
ReferenceForce
::
RIndex
];
if
(
cutoff
&&
r
>=
cutoffDistance
)
if
(
cutoff
&&
r
>=
cutoffDistance
)
return
;
return
;
for
(
int
i
=
0
;
i
<
(
int
)
paramIndex
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
paramIndex
.
size
();
i
++
)
{
...
@@ -265,7 +265,7 @@ void ReferenceCustomGBIxn::calculateOnePairValue(int index, int atom1, int atom2
...
@@ -265,7 +265,7 @@ void ReferenceCustomGBIxn::calculateOnePairValue(int index, int atom1, int atom2
expressionSet
.
setVariable
(
particleValueIndex
[
i
*
2
],
values
[
i
][
atom1
]);
expressionSet
.
setVariable
(
particleValueIndex
[
i
*
2
],
values
[
i
][
atom1
]);
expressionSet
.
setVariable
(
particleValueIndex
[
i
*
2
+
1
],
values
[
i
][
atom2
]);
expressionSet
.
setVariable
(
particleValueIndex
[
i
*
2
+
1
],
values
[
i
][
atom2
]);
}
}
values
[
index
][
atom1
]
+=
(
RealOpenMM
)
valueExpressions
[
index
].
evaluate
();
values
[
index
][
atom1
]
+=
valueExpressions
[
index
].
evaluate
();
// Calculate derivatives with respect to parameters.
// Calculate derivatives with respect to parameters.
...
@@ -273,8 +273,8 @@ void ReferenceCustomGBIxn::calculateOnePairValue(int index, int atom1, int atom2
...
@@ -273,8 +273,8 @@ void ReferenceCustomGBIxn::calculateOnePairValue(int index, int atom1, int atom2
dValuedParam
[
index
][
i
][
atom1
]
+=
valueParamDerivExpressions
[
index
][
i
].
evaluate
();
dValuedParam
[
index
][
i
][
atom1
]
+=
valueParamDerivExpressions
[
index
][
i
].
evaluate
();
}
}
void
ReferenceCustomGBIxn
::
calculateSingleParticleEnergyTerm
(
int
index
,
int
numAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceCustomGBIxn
::
calculateSingleParticleEnergyTerm
(
int
index
,
int
numAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
vector
<
Real
Vec
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
**
atomParameters
,
vector
<
Vec
3
>&
forces
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
{
expressionSet
.
setVariable
(
xIndex
,
atomCoordinates
[
i
][
0
]);
expressionSet
.
setVariable
(
xIndex
,
atomCoordinates
[
i
][
0
]);
expressionSet
.
setVariable
(
yIndex
,
atomCoordinates
[
i
][
1
]);
expressionSet
.
setVariable
(
yIndex
,
atomCoordinates
[
i
][
1
]);
...
@@ -287,12 +287,12 @@ void ReferenceCustomGBIxn::calculateSingleParticleEnergyTerm(int index, int numA
...
@@ -287,12 +287,12 @@ void ReferenceCustomGBIxn::calculateSingleParticleEnergyTerm(int index, int numA
// Compute energy and force.
// Compute energy and force.
if
(
totalEnergy
!=
NULL
)
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpressions
[
index
].
evaluate
();
*
totalEnergy
+=
energyExpressions
[
index
].
evaluate
();
for
(
int
j
=
0
;
j
<
(
int
)
valueIndex
.
size
();
j
++
)
for
(
int
j
=
0
;
j
<
(
int
)
valueIndex
.
size
();
j
++
)
dEdV
[
j
][
i
]
+=
(
RealOpenMM
)
energyDerivExpressions
[
index
][
j
].
evaluate
();
dEdV
[
j
][
i
]
+=
energyDerivExpressions
[
index
][
j
].
evaluate
();
forces
[
i
][
0
]
-=
(
RealOpenMM
)
energyGradientExpressions
[
index
][
0
].
evaluate
();
forces
[
i
][
0
]
-=
energyGradientExpressions
[
index
][
0
].
evaluate
();
forces
[
i
][
1
]
-=
(
RealOpenMM
)
energyGradientExpressions
[
index
][
1
].
evaluate
();
forces
[
i
][
1
]
-=
energyGradientExpressions
[
index
][
1
].
evaluate
();
forces
[
i
][
2
]
-=
(
RealOpenMM
)
energyGradientExpressions
[
index
][
2
].
evaluate
();
forces
[
i
][
2
]
-=
energyGradientExpressions
[
index
][
2
].
evaluate
();
// Compute derivatives with respect to parameters.
// Compute derivatives with respect to parameters.
...
@@ -301,8 +301,8 @@ void ReferenceCustomGBIxn::calculateSingleParticleEnergyTerm(int index, int numA
...
@@ -301,8 +301,8 @@ void ReferenceCustomGBIxn::calculateSingleParticleEnergyTerm(int index, int numA
}
}
}
}
void
ReferenceCustomGBIxn
::
calculateParticlePairEnergyTerm
(
int
index
,
int
numAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
void
ReferenceCustomGBIxn
::
calculateParticlePairEnergyTerm
(
int
index
,
int
numAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
,
const
vector
<
set
<
int
>
>&
exclusions
,
bool
useExclusions
,
vector
<
Real
Vec
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
const
vector
<
set
<
int
>
>&
exclusions
,
bool
useExclusions
,
vector
<
Vec
3
>&
forces
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
if
(
cutoff
)
{
if
(
cutoff
)
{
// Loop over all pairs in the neighbor list.
// Loop over all pairs in the neighbor list.
...
@@ -326,16 +326,16 @@ void ReferenceCustomGBIxn::calculateParticlePairEnergyTerm(int index, int numAto
...
@@ -326,16 +326,16 @@ void ReferenceCustomGBIxn::calculateParticlePairEnergyTerm(int index, int numAto
}
}
}
}
void
ReferenceCustomGBIxn
::
calculateOnePairEnergyTerm
(
int
index
,
int
atom1
,
int
atom2
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
void
ReferenceCustomGBIxn
::
calculateOnePairEnergyTerm
(
int
index
,
int
atom1
,
int
atom2
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
,
vector
<
Real
Vec
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
vector
<
Vec
3
>&
forces
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
// Compute the displacement.
// Compute the displacement.
RealOpenMM
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
if
(
periodic
)
if
(
periodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
periodicBoxVectors
,
deltaR
);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
periodicBoxVectors
,
deltaR
);
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
deltaR
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
deltaR
);
RealOpenMM
r
=
deltaR
[
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
ReferenceForce
::
RIndex
];
if
(
cutoff
&&
r
>=
cutoffDistance
)
if
(
cutoff
&&
r
>=
cutoffDistance
)
return
;
return
;
...
@@ -354,16 +354,16 @@ void ReferenceCustomGBIxn::calculateOnePairEnergyTerm(int index, int atom1, int
...
@@ -354,16 +354,16 @@ void ReferenceCustomGBIxn::calculateOnePairEnergyTerm(int index, int atom1, int
// Evaluate the energy and its derivatives.
// Evaluate the energy and its derivatives.
if
(
totalEnergy
!=
NULL
)
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpressions
[
index
].
evaluate
();
*
totalEnergy
+=
energyExpressions
[
index
].
evaluate
();
RealOpenMM
dEdR
=
(
RealOpenMM
)
energyDerivExpressions
[
index
][
0
].
evaluate
();
double
dEdR
=
energyDerivExpressions
[
index
][
0
].
evaluate
();
dEdR
*=
1
/
r
;
dEdR
*=
1
/
r
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
forces
[
atom1
][
i
]
-=
dEdR
*
deltaR
[
i
];
forces
[
atom1
][
i
]
-=
dEdR
*
deltaR
[
i
];
forces
[
atom2
][
i
]
+=
dEdR
*
deltaR
[
i
];
forces
[
atom2
][
i
]
+=
dEdR
*
deltaR
[
i
];
}
}
for
(
int
i
=
0
;
i
<
(
int
)
valueIndex
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
valueIndex
.
size
();
i
++
)
{
dEdV
[
i
][
atom1
]
+=
(
RealOpenMM
)
energyDerivExpressions
[
index
][
2
*
i
+
1
].
evaluate
();
dEdV
[
i
][
atom1
]
+=
energyDerivExpressions
[
index
][
2
*
i
+
1
].
evaluate
();
dEdV
[
i
][
atom2
]
+=
(
RealOpenMM
)
energyDerivExpressions
[
index
][
2
*
i
+
2
].
evaluate
();
dEdV
[
i
][
atom2
]
+=
energyDerivExpressions
[
index
][
2
*
i
+
2
].
evaluate
();
}
}
// Compute derivatives with respect to parameters.
// Compute derivatives with respect to parameters.
...
@@ -372,8 +372,8 @@ void ReferenceCustomGBIxn::calculateOnePairEnergyTerm(int index, int atom1, int
...
@@ -372,8 +372,8 @@ void ReferenceCustomGBIxn::calculateOnePairEnergyTerm(int index, int atom1, int
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
index
][
i
].
evaluate
();
energyParamDerivs
[
i
]
+=
energyParamDerivExpressions
[
index
][
i
].
evaluate
();
}
}
void
ReferenceCustomGBIxn
::
calculateChainRuleForces
(
int
numAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
void
ReferenceCustomGBIxn
::
calculateChainRuleForces
(
int
numAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
,
const
vector
<
set
<
int
>
>&
exclusions
,
vector
<
Real
Vec
>&
forces
,
double
*
energyParamDerivs
)
{
const
vector
<
set
<
int
>
>&
exclusions
,
vector
<
Vec
3
>&
forces
,
double
*
energyParamDerivs
)
{
if
(
cutoff
)
{
if
(
cutoff
)
{
// Loop over all pairs in the neighbor list.
// Loop over all pairs in the neighbor list.
...
@@ -402,22 +402,22 @@ void ReferenceCustomGBIxn::calculateChainRuleForces(int numAtoms, vector<RealVec
...
@@ -402,22 +402,22 @@ void ReferenceCustomGBIxn::calculateChainRuleForces(int numAtoms, vector<RealVec
expressionSet
.
setVariable
(
xIndex
,
atomCoordinates
[
i
][
0
]);
expressionSet
.
setVariable
(
xIndex
,
atomCoordinates
[
i
][
0
]);
expressionSet
.
setVariable
(
yIndex
,
atomCoordinates
[
i
][
1
]);
expressionSet
.
setVariable
(
yIndex
,
atomCoordinates
[
i
][
1
]);
expressionSet
.
setVariable
(
zIndex
,
atomCoordinates
[
i
][
2
]);
expressionSet
.
setVariable
(
zIndex
,
atomCoordinates
[
i
][
2
]);
vector
<
RealOpenMM
>
dVdX
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
double
>
dVdX
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
RealOpenMM
>
dVdY
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
double
>
dVdY
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
RealOpenMM
>
dVdZ
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
double
>
dVdZ
(
valueDerivExpressions
.
size
(),
0.0
);
for
(
int
j
=
0
;
j
<
(
int
)
paramIndex
.
size
();
j
++
)
for
(
int
j
=
0
;
j
<
(
int
)
paramIndex
.
size
();
j
++
)
expressionSet
.
setVariable
(
paramIndex
[
j
],
atomParameters
[
i
][
j
]);
expressionSet
.
setVariable
(
paramIndex
[
j
],
atomParameters
[
i
][
j
]);
for
(
int
j
=
1
;
j
<
(
int
)
valueIndex
.
size
();
j
++
)
{
for
(
int
j
=
1
;
j
<
(
int
)
valueIndex
.
size
();
j
++
)
{
expressionSet
.
setVariable
(
valueIndex
[
j
-
1
],
values
[
j
-
1
][
i
]);
expressionSet
.
setVariable
(
valueIndex
[
j
-
1
],
values
[
j
-
1
][
i
]);
for
(
int
k
=
1
;
k
<
j
;
k
++
)
{
for
(
int
k
=
1
;
k
<
j
;
k
++
)
{
RealOpenMM
dVdV
=
(
RealOpenMM
)
valueDerivExpressions
[
j
][
k
].
evaluate
();
double
dVdV
=
valueDerivExpressions
[
j
][
k
].
evaluate
();
dVdX
[
j
]
+=
dVdV
*
dVdX
[
k
];
dVdX
[
j
]
+=
dVdV
*
dVdX
[
k
];
dVdY
[
j
]
+=
dVdV
*
dVdY
[
k
];
dVdY
[
j
]
+=
dVdV
*
dVdY
[
k
];
dVdZ
[
j
]
+=
dVdV
*
dVdZ
[
k
];
dVdZ
[
j
]
+=
dVdV
*
dVdZ
[
k
];
}
}
dVdX
[
j
]
+=
(
RealOpenMM
)
valueGradientExpressions
[
j
][
0
].
evaluate
();
dVdX
[
j
]
+=
valueGradientExpressions
[
j
][
0
].
evaluate
();
dVdY
[
j
]
+=
(
RealOpenMM
)
valueGradientExpressions
[
j
][
1
].
evaluate
();
dVdY
[
j
]
+=
valueGradientExpressions
[
j
][
1
].
evaluate
();
dVdZ
[
j
]
+=
(
RealOpenMM
)
valueGradientExpressions
[
j
][
2
].
evaluate
();
dVdZ
[
j
]
+=
valueGradientExpressions
[
j
][
2
].
evaluate
();
forces
[
i
][
0
]
-=
dEdV
[
j
][
i
]
*
dVdX
[
j
];
forces
[
i
][
0
]
-=
dEdV
[
j
][
i
]
*
dVdX
[
j
];
forces
[
i
][
1
]
-=
dEdV
[
j
][
i
]
*
dVdY
[
j
];
forces
[
i
][
1
]
-=
dEdV
[
j
][
i
]
*
dVdY
[
j
];
forces
[
i
][
2
]
-=
dEdV
[
j
][
i
]
*
dVdZ
[
j
];
forces
[
i
][
2
]
-=
dEdV
[
j
][
i
]
*
dVdZ
[
j
];
...
@@ -432,16 +432,16 @@ void ReferenceCustomGBIxn::calculateChainRuleForces(int numAtoms, vector<RealVec
...
@@ -432,16 +432,16 @@ void ReferenceCustomGBIxn::calculateChainRuleForces(int numAtoms, vector<RealVec
energyParamDerivs
[
k
]
+=
dEdV
[
j
][
i
]
*
dValuedParam
[
j
][
k
][
i
];
energyParamDerivs
[
k
]
+=
dEdV
[
j
][
i
]
*
dValuedParam
[
j
][
k
][
i
];
}
}
void
ReferenceCustomGBIxn
::
calculateOnePairChainRule
(
int
atom1
,
int
atom2
,
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
void
ReferenceCustomGBIxn
::
calculateOnePairChainRule
(
int
atom1
,
int
atom2
,
vector
<
Vec
3
>&
atomCoordinates
,
double
**
atomParameters
,
vector
<
Real
Vec
>&
forces
,
bool
isExcluded
)
{
vector
<
Vec
3
>&
forces
,
bool
isExcluded
)
{
// Compute the displacement.
// Compute the displacement.
RealOpenMM
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
if
(
periodic
)
if
(
periodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
periodicBoxVectors
,
deltaR
);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
periodicBoxVectors
,
deltaR
);
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
deltaR
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom2
],
atomCoordinates
[
atom1
],
deltaR
);
RealOpenMM
r
=
deltaR
[
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
ReferenceForce
::
RIndex
];
if
(
cutoff
&&
r
>=
cutoffDistance
)
if
(
cutoff
&&
r
>=
cutoffDistance
)
return
;
return
;
...
@@ -457,14 +457,14 @@ void ReferenceCustomGBIxn::calculateOnePairChainRule(int atom1, int atom2, vecto
...
@@ -457,14 +457,14 @@ void ReferenceCustomGBIxn::calculateOnePairChainRule(int atom1, int atom2, vecto
// Evaluate the derivative of each parameter with respect to position and apply forces.
// Evaluate the derivative of each parameter with respect to position and apply forces.
RealOpenMM
rinv
=
1
/
r
;
double
rinv
=
1
/
r
;
deltaR
[
0
]
*=
rinv
;
deltaR
[
0
]
*=
rinv
;
deltaR
[
1
]
*=
rinv
;
deltaR
[
1
]
*=
rinv
;
deltaR
[
2
]
*=
rinv
;
deltaR
[
2
]
*=
rinv
;
vector
<
RealOpenMM
>
dVdR1
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
double
>
dVdR1
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
RealOpenMM
>
dVdR2
(
valueDerivExpressions
.
size
(),
0.0
);
vector
<
double
>
dVdR2
(
valueDerivExpressions
.
size
(),
0.0
);
if
(
!
isExcluded
||
valueTypes
[
0
]
!=
OpenMM
::
CustomGBForce
::
ParticlePair
)
{
if
(
!
isExcluded
||
valueTypes
[
0
]
!=
OpenMM
::
CustomGBForce
::
ParticlePair
)
{
dVdR1
[
0
]
=
(
RealOpenMM
)
valueDerivExpressions
[
0
][
0
].
evaluate
();
dVdR1
[
0
]
=
valueDerivExpressions
[
0
][
0
].
evaluate
();
dVdR2
[
0
]
=
-
dVdR1
[
0
];
dVdR2
[
0
]
=
-
dVdR1
[
0
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
forces
[
atom1
][
i
]
-=
dEdV
[
0
][
atom1
]
*
dVdR1
[
0
]
*
deltaR
[
i
];
forces
[
atom1
][
i
]
-=
dEdV
[
0
][
atom1
]
*
dVdR1
[
0
]
*
deltaR
[
i
];
...
@@ -480,7 +480,7 @@ void ReferenceCustomGBIxn::calculateOnePairChainRule(int atom1, int atom2, vecto
...
@@ -480,7 +480,7 @@ void ReferenceCustomGBIxn::calculateOnePairChainRule(int atom1, int atom2, vecto
expressionSet
.
setVariable
(
yIndex
,
atomCoordinates
[
atom1
][
1
]);
expressionSet
.
setVariable
(
yIndex
,
atomCoordinates
[
atom1
][
1
]);
expressionSet
.
setVariable
(
zIndex
,
atomCoordinates
[
atom1
][
2
]);
expressionSet
.
setVariable
(
zIndex
,
atomCoordinates
[
atom1
][
2
]);
for
(
int
j
=
0
;
j
<
i
;
j
++
)
{
for
(
int
j
=
0
;
j
<
i
;
j
++
)
{
RealOpenMM
dVdV
=
(
RealOpenMM
)
valueDerivExpressions
[
i
][
j
].
evaluate
();
double
dVdV
=
valueDerivExpressions
[
i
][
j
].
evaluate
();
dVdR1
[
i
]
+=
dVdV
*
dVdR1
[
j
];
dVdR1
[
i
]
+=
dVdV
*
dVdR1
[
j
];
dVdR2
[
i
]
+=
dVdV
*
dVdR2
[
j
];
dVdR2
[
i
]
+=
dVdV
*
dVdR2
[
j
];
}
}
...
...
platforms/reference/src/SimTKReference/ReferenceCustomHbondIxn.cpp
View file @
a783b996
...
@@ -74,7 +74,7 @@ ReferenceCustomHbondIxn::~ReferenceCustomHbondIxn() {
...
@@ -74,7 +74,7 @@ ReferenceCustomHbondIxn::~ReferenceCustomHbondIxn() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomHbondIxn
::
setUseCutoff
(
RealOpenMM
distance
)
{
void
ReferenceCustomHbondIxn
::
setUseCutoff
(
double
distance
)
{
cutoff
=
true
;
cutoff
=
true
;
cutoffDistance
=
distance
;
cutoffDistance
=
distance
;
}
}
...
@@ -89,7 +89,7 @@ void ReferenceCustomHbondIxn::setUseCutoff(RealOpenMM distance) {
...
@@ -89,7 +89,7 @@ void ReferenceCustomHbondIxn::setUseCutoff(RealOpenMM distance) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomHbondIxn
::
setPeriodic
(
Real
Vec
*
vectors
)
{
void
ReferenceCustomHbondIxn
::
setPeriodic
(
Vec
3
*
vectors
)
{
assert
(
cutoff
);
assert
(
cutoff
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
1
][
1
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
1
][
1
]
>=
2.0
*
cutoffDistance
);
...
@@ -116,9 +116,9 @@ void ReferenceCustomHbondIxn::setPeriodic(RealVec* vectors) {
...
@@ -116,9 +116,9 @@ void ReferenceCustomHbondIxn::setPeriodic(RealVec* vectors) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomHbondIxn
::
calculatePairIxn
(
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
donorParameters
,
RealOpenMM
**
acceptorParameters
,
void
ReferenceCustomHbondIxn
::
calculatePairIxn
(
vector
<
Vec
3
>&
atomCoordinates
,
double
**
donorParameters
,
double
**
acceptorParameters
,
vector
<
set
<
int
>
>&
exclusions
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Real
Vec
>&
forces
,
vector
<
set
<
int
>
>&
exclusions
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
{
double
*
totalEnergy
)
const
{
map
<
string
,
double
>
variables
=
globalParameters
;
map
<
string
,
double
>
variables
=
globalParameters
;
...
@@ -159,14 +159,8 @@ void ReferenceCustomHbondIxn::calculatePairIxn(vector<RealVec>& atomCoordinates,
...
@@ -159,14 +159,8 @@ void ReferenceCustomHbondIxn::calculatePairIxn(vector<RealVec>& atomCoordinates,
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomHbondIxn
::
calculateOneIxn
(
int
donor
,
int
acceptor
,
vector
<
RealVec
>&
atomCoordinates
,
void
ReferenceCustomHbondIxn
::
calculateOneIxn
(
int
donor
,
int
acceptor
,
vector
<
Vec3
>&
atomCoordinates
,
map
<
string
,
double
>&
variables
,
vector
<
RealVec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
{
map
<
string
,
double
>&
variables
,
vector
<
Vec3
>&
forces
,
double
*
totalEnergy
)
const
{
// ---------------------------------------------------------------------------------------
static
const
std
::
string
methodName
=
"
\n
ReferenceCustomHbondIxn::calculateOneIxn"
;
// ---------------------------------------------------------------------------------------
int
atoms
[
6
];
int
atoms
[
6
];
atoms
[
0
]
=
acceptorAtoms
[
acceptor
][
0
];
atoms
[
0
]
=
acceptorAtoms
[
acceptor
][
0
];
...
@@ -179,7 +173,7 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
...
@@ -179,7 +173,7 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
// Compute the distance between the primary donor and acceptor atoms, and compare to the cutoff.
// Compute the distance between the primary donor and acceptor atoms, and compare to the cutoff.
if
(
cutoff
)
{
if
(
cutoff
)
{
RealOpenMM
delta
[
ReferenceForce
::
LastDeltaRIndex
];
double
delta
[
ReferenceForce
::
LastDeltaRIndex
];
computeDelta
(
atoms
[
0
],
atoms
[
3
],
delta
,
atomCoordinates
);
computeDelta
(
atoms
[
0
],
atoms
[
3
],
delta
,
atomCoordinates
);
if
(
delta
[
ReferenceForce
::
RIndex
]
>=
cutoffDistance
)
if
(
delta
[
ReferenceForce
::
RIndex
]
>=
cutoffDistance
)
return
;
return
;
...
@@ -203,8 +197,8 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
...
@@ -203,8 +197,8 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p1
],
term
.
delta1
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p1
],
term
.
delta1
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p3
],
term
.
delta2
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p2
],
atoms
[
term
.
p3
],
term
.
delta2
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p4
],
atoms
[
term
.
p3
],
term
.
delta3
,
atomCoordinates
);
computeDelta
(
atoms
[
term
.
p4
],
atoms
[
term
.
p3
],
term
.
delta3
,
atomCoordinates
);
RealOpenMM
dotDihedral
,
signOfDihedral
;
double
dotDihedral
,
signOfDihedral
;
RealOpenMM
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
double
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
variables
[
term
.
name
]
=
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
);
variables
[
term
.
name
]
=
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
);
}
}
...
@@ -212,9 +206,9 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
...
@@ -212,9 +206,9 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
RealOpenMM
dEdR
=
(
RealOpenMM
)
(
term
.
forceExpression
.
evaluate
(
variables
)
/
(
term
.
delta
[
ReferenceForce
::
RIndex
])
)
;
double
dEdR
=
term
.
forceExpression
.
evaluate
(
variables
)
/
(
term
.
delta
[
ReferenceForce
::
RIndex
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
RealOpenMM
force
=
-
dEdR
*
term
.
delta
[
i
];
double
force
=
-
dEdR
*
term
.
delta
[
i
];
forces
[
atoms
[
term
.
p1
]][
i
]
-=
force
;
forces
[
atoms
[
term
.
p1
]][
i
]
-=
force
;
forces
[
atoms
[
term
.
p2
]][
i
]
+=
force
;
forces
[
atoms
[
term
.
p2
]][
i
]
+=
force
;
}
}
...
@@ -224,15 +218,15 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
...
@@ -224,15 +218,15 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
(
variables
);
double
dEdTheta
=
term
.
forceExpression
.
evaluate
(
variables
);
RealOpenMM
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
double
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
RealOpenMM
lengthThetaCross
=
SQRT
(
DOT3
(
thetaCross
,
thetaCross
));
double
lengthThetaCross
=
sqrt
(
DOT3
(
thetaCross
,
thetaCross
));
if
(
lengthThetaCross
<
1.0e-06
)
if
(
lengthThetaCross
<
1.0e-06
)
lengthThetaCross
=
(
RealOpenMM
)
1.0e-06
;
lengthThetaCross
=
1.0e-06
;
RealOpenMM
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
deltaCrossP
[
3
][
3
];
double
deltaCrossP
[
3
][
3
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
...
@@ -251,22 +245,22 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
...
@@ -251,22 +245,22 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
(
variables
);
double
dEdTheta
=
term
.
forceExpression
.
evaluate
(
variables
);
RealOpenMM
internalF
[
4
][
3
];
double
internalF
[
4
][
3
];
RealOpenMM
forceFactors
[
4
];
double
forceFactors
[
4
];
RealOpenMM
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
double
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
RealOpenMM
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
double
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
RealOpenMM
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
double
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
RealOpenMM
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
double
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
}
}
...
@@ -281,25 +275,25 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
...
@@ -281,25 +275,25 @@ void ReferenceCustomHbondIxn::calculateOneIxn(int donor, int acceptor, vector<Re
// Add the energy
// Add the energy
if
(
totalEnergy
)
if
(
totalEnergy
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpression
.
evaluate
(
variables
);
*
totalEnergy
+=
energyExpression
.
evaluate
(
variables
);
}
}
void
ReferenceCustomHbondIxn
::
computeDelta
(
int
atom1
,
int
atom2
,
RealOpenMM
*
delta
,
vector
<
Real
Vec
>&
atomCoordinates
)
const
{
void
ReferenceCustomHbondIxn
::
computeDelta
(
int
atom1
,
int
atom2
,
double
*
delta
,
vector
<
Vec
3
>&
atomCoordinates
)
const
{
if
(
periodic
)
if
(
periodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
periodicBoxVectors
,
delta
);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
periodicBoxVectors
,
delta
);
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
delta
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
delta
);
}
}
RealOpenMM
ReferenceCustomHbondIxn
::
computeAngle
(
RealOpenMM
*
vec1
,
RealOpenMM
*
vec2
)
{
double
ReferenceCustomHbondIxn
::
computeAngle
(
double
*
vec1
,
double
*
vec2
)
{
RealOpenMM
dot
=
DOT3
(
vec1
,
vec2
);
double
dot
=
DOT3
(
vec1
,
vec2
);
RealOpenMM
cosine
=
dot
/
SQRT
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
double
cosine
=
dot
/
sqrt
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
RealOpenMM
angle
;
double
angle
;
if
(
cosine
>=
1
)
if
(
cosine
>=
1
)
angle
=
0
;
angle
=
0
;
else
if
(
cosine
<=
-
1
)
else
if
(
cosine
<=
-
1
)
angle
=
PI_M
;
angle
=
PI_M
;
else
else
angle
=
ACOS
(
cosine
);
angle
=
acos
(
cosine
);
return
angle
;
return
angle
;
}
}
platforms/reference/src/SimTKReference/ReferenceCustomManyParticleIxn.cpp
View file @
a783b996
...
@@ -105,20 +105,20 @@ ReferenceCustomManyParticleIxn::ReferenceCustomManyParticleIxn(const CustomManyP
...
@@ -105,20 +105,20 @@ ReferenceCustomManyParticleIxn::ReferenceCustomManyParticleIxn(const CustomManyP
ReferenceCustomManyParticleIxn
::~
ReferenceCustomManyParticleIxn
()
{
ReferenceCustomManyParticleIxn
::~
ReferenceCustomManyParticleIxn
()
{
}
}
void
ReferenceCustomManyParticleIxn
::
calculateIxn
(
vector
<
Real
Vec
>&
atomCoordinates
,
RealOpenMM
**
particleParameters
,
void
ReferenceCustomManyParticleIxn
::
calculateIxn
(
vector
<
Vec
3
>&
atomCoordinates
,
double
**
particleParameters
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Real
Vec
>&
forces
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
{
double
*
totalEnergy
)
const
{
map
<
string
,
double
>
variables
=
globalParameters
;
map
<
string
,
double
>
variables
=
globalParameters
;
vector
<
int
>
particles
(
numParticlesPerSet
);
vector
<
int
>
particles
(
numParticlesPerSet
);
loopOverInteractions
(
particles
,
0
,
atomCoordinates
,
particleParameters
,
variables
,
forces
,
totalEnergy
);
loopOverInteractions
(
particles
,
0
,
atomCoordinates
,
particleParameters
,
variables
,
forces
,
totalEnergy
);
}
}
void
ReferenceCustomManyParticleIxn
::
setUseCutoff
(
RealOpenMM
distance
)
{
void
ReferenceCustomManyParticleIxn
::
setUseCutoff
(
double
distance
)
{
useCutoff
=
true
;
useCutoff
=
true
;
cutoffDistance
=
distance
;
cutoffDistance
=
distance
;
}
}
void
ReferenceCustomManyParticleIxn
::
setPeriodic
(
Real
Vec
*
vectors
)
{
void
ReferenceCustomManyParticleIxn
::
setPeriodic
(
Vec
3
*
vectors
)
{
assert
(
useCutoff
);
assert
(
useCutoff
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
1
][
1
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
1
][
1
]
>=
2.0
*
cutoffDistance
);
...
@@ -129,9 +129,9 @@ void ReferenceCustomManyParticleIxn::setPeriodic(RealVec* vectors) {
...
@@ -129,9 +129,9 @@ void ReferenceCustomManyParticleIxn::setPeriodic(RealVec* vectors) {
periodicBoxVectors
[
2
]
=
vectors
[
2
];
periodicBoxVectors
[
2
]
=
vectors
[
2
];
}
}
void
ReferenceCustomManyParticleIxn
::
loopOverInteractions
(
vector
<
int
>&
particles
,
int
loopIndex
,
vector
<
OpenMM
::
Real
Vec
>&
atomCoordinates
,
void
ReferenceCustomManyParticleIxn
::
loopOverInteractions
(
vector
<
int
>&
particles
,
int
loopIndex
,
vector
<
OpenMM
::
Vec
3
>&
atomCoordinates
,
RealOpenMM
**
particleParameters
,
map
<
string
,
double
>&
variables
,
vector
<
OpenMM
::
Real
Vec
>&
forces
,
double
**
particleParameters
,
map
<
string
,
double
>&
variables
,
vector
<
OpenMM
::
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
{
double
*
totalEnergy
)
const
{
int
numParticles
=
atomCoordinates
.
size
();
int
numParticles
=
atomCoordinates
.
size
();
int
firstPartialLoop
=
(
centralParticleMode
?
2
:
1
);
int
firstPartialLoop
=
(
centralParticleMode
?
2
:
1
);
int
start
=
(
loopIndex
<
firstPartialLoop
?
0
:
particles
[
loopIndex
-
1
]
+
1
);
int
start
=
(
loopIndex
<
firstPartialLoop
?
0
:
particles
[
loopIndex
-
1
]
+
1
);
...
@@ -146,8 +146,8 @@ void ReferenceCustomManyParticleIxn::loopOverInteractions(vector<int>& particles
...
@@ -146,8 +146,8 @@ void ReferenceCustomManyParticleIxn::loopOverInteractions(vector<int>& particles
}
}
}
}
void
ReferenceCustomManyParticleIxn
::
calculateOneIxn
(
const
vector
<
int
>&
particles
,
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceCustomManyParticleIxn
::
calculateOneIxn
(
const
vector
<
int
>&
particles
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
**
particleParameters
,
map
<
string
,
double
>&
variables
,
vector
<
Real
Vec
>&
forces
,
RealOpenMM
*
totalEnergy
)
const
{
double
**
particleParameters
,
map
<
string
,
double
>&
variables
,
vector
<
Vec
3
>&
forces
,
double
*
totalEnergy
)
const
{
// Select the ordering to use for the particles.
// Select the ordering to use for the particles.
vector
<
int
>
permutedParticles
(
numParticlesPerSet
);
vector
<
int
>
permutedParticles
(
numParticlesPerSet
);
...
@@ -176,7 +176,7 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
...
@@ -176,7 +176,7 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
if
(
exclusions
[
p1
].
find
(
p2
)
!=
exclusions
[
p1
].
end
())
if
(
exclusions
[
p1
].
find
(
p2
)
!=
exclusions
[
p1
].
end
())
return
;
return
;
if
(
useCutoff
&&
(
i
==
0
||
!
centralParticleMode
))
{
if
(
useCutoff
&&
(
i
==
0
||
!
centralParticleMode
))
{
RealOpenMM
delta
[
ReferenceForce
::
LastDeltaRIndex
];
double
delta
[
ReferenceForce
::
LastDeltaRIndex
];
computeDelta
(
p1
,
p2
,
delta
,
atomCoordinates
);
computeDelta
(
p1
,
p2
,
delta
,
atomCoordinates
);
if
(
delta
[
ReferenceForce
::
RIndex
]
>=
cutoffDistance
)
if
(
delta
[
ReferenceForce
::
RIndex
]
>=
cutoffDistance
)
return
;
return
;
...
@@ -212,8 +212,8 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
...
@@ -212,8 +212,8 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
computeDelta
(
permutedParticles
[
term
.
p2
],
permutedParticles
[
term
.
p1
],
term
.
delta1
,
atomCoordinates
);
computeDelta
(
permutedParticles
[
term
.
p2
],
permutedParticles
[
term
.
p1
],
term
.
delta1
,
atomCoordinates
);
computeDelta
(
permutedParticles
[
term
.
p2
],
permutedParticles
[
term
.
p3
],
term
.
delta2
,
atomCoordinates
);
computeDelta
(
permutedParticles
[
term
.
p2
],
permutedParticles
[
term
.
p3
],
term
.
delta2
,
atomCoordinates
);
computeDelta
(
permutedParticles
[
term
.
p4
],
permutedParticles
[
term
.
p3
],
term
.
delta3
,
atomCoordinates
);
computeDelta
(
permutedParticles
[
term
.
p4
],
permutedParticles
[
term
.
p3
],
term
.
delta3
,
atomCoordinates
);
RealOpenMM
dotDihedral
,
signOfDihedral
;
double
dotDihedral
,
signOfDihedral
;
RealOpenMM
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
double
*
crossProduct
[]
=
{
term
.
cross1
,
term
.
cross2
};
variables
[
term
.
name
]
=
ReferenceBondIxn
::
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
);
variables
[
term
.
name
]
=
ReferenceBondIxn
::
getDihedralAngleBetweenThreeVectors
(
term
.
delta1
,
term
.
delta2
,
term
.
delta3
,
crossProduct
,
&
dotDihedral
,
term
.
delta1
,
&
signOfDihedral
,
1
);
}
}
...
@@ -228,9 +228,9 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
...
@@ -228,9 +228,9 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
distanceTerms
.
size
();
i
++
)
{
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
const
DistanceTermInfo
&
term
=
distanceTerms
[
i
];
RealOpenMM
dEdR
=
(
RealOpenMM
)
(
term
.
forceExpression
.
evaluate
(
variables
)
/
(
term
.
delta
[
ReferenceForce
::
RIndex
])
)
;
double
dEdR
=
term
.
forceExpression
.
evaluate
(
variables
)
/
(
term
.
delta
[
ReferenceForce
::
RIndex
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
RealOpenMM
force
=
-
dEdR
*
term
.
delta
[
i
];
double
force
=
-
dEdR
*
term
.
delta
[
i
];
forces
[
permutedParticles
[
term
.
p1
]][
i
]
-=
force
;
forces
[
permutedParticles
[
term
.
p1
]][
i
]
-=
force
;
forces
[
permutedParticles
[
term
.
p2
]][
i
]
+=
force
;
forces
[
permutedParticles
[
term
.
p2
]][
i
]
+=
force
;
}
}
...
@@ -240,15 +240,15 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
...
@@ -240,15 +240,15 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
angleTerms
.
size
();
i
++
)
{
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
const
AngleTermInfo
&
term
=
angleTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
(
variables
);
double
dEdTheta
=
term
.
forceExpression
.
evaluate
(
variables
);
RealOpenMM
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
double
thetaCross
[
ReferenceForce
::
LastDeltaRIndex
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
term
.
delta2
,
thetaCross
);
RealOpenMM
lengthThetaCross
=
SQRT
(
DOT3
(
thetaCross
,
thetaCross
));
double
lengthThetaCross
=
sqrt
(
DOT3
(
thetaCross
,
thetaCross
));
if
(
lengthThetaCross
<
1.0e-06
)
if
(
lengthThetaCross
<
1.0e-06
)
lengthThetaCross
=
(
RealOpenMM
)
1.0e-06
;
lengthThetaCross
=
1.0e-06
;
RealOpenMM
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termA
=
dEdTheta
/
(
term
.
delta1
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
double
termC
=
-
dEdTheta
/
(
term
.
delta2
[
ReferenceForce
::
R2Index
]
*
lengthThetaCross
);
RealOpenMM
deltaCrossP
[
3
][
3
];
double
deltaCrossP
[
3
][
3
];
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta1
,
thetaCross
,
deltaCrossP
[
0
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
SimTKOpenMMUtilities
::
crossProductVector3
(
term
.
delta2
,
thetaCross
,
deltaCrossP
[
2
]);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
...
@@ -267,22 +267,22 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
...
@@ -267,22 +267,22 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
dihedralTerms
.
size
();
i
++
)
{
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
const
DihedralTermInfo
&
term
=
dihedralTerms
[
i
];
RealOpenMM
dEdTheta
=
(
RealOpenMM
)
term
.
forceExpression
.
evaluate
(
variables
);
double
dEdTheta
=
term
.
forceExpression
.
evaluate
(
variables
);
RealOpenMM
internalF
[
4
][
3
];
double
internalF
[
4
][
3
];
RealOpenMM
forceFactors
[
4
];
double
forceFactors
[
4
];
RealOpenMM
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
double
normCross1
=
DOT3
(
term
.
cross1
,
term
.
cross1
);
RealOpenMM
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
double
normBC
=
term
.
delta2
[
ReferenceForce
::
RIndex
];
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
forceFactors
[
0
]
=
(
-
dEdTheta
*
normBC
)
/
normCross1
;
RealOpenMM
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
double
normCross2
=
DOT3
(
term
.
cross2
,
term
.
cross2
);
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
3
]
=
(
dEdTheta
*
normBC
)
/
normCross2
;
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
=
DOT3
(
term
.
delta1
,
term
.
delta2
);
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
1
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
=
DOT3
(
term
.
delta3
,
term
.
delta2
);
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
/=
term
.
delta2
[
ReferenceForce
::
R2Index
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
0
][
i
]
=
forceFactors
[
0
]
*
term
.
cross1
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
internalF
[
3
][
i
]
=
forceFactors
[
3
]
*
term
.
cross2
[
i
];
RealOpenMM
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
double
s
=
forceFactors
[
1
]
*
internalF
[
0
][
i
]
-
forceFactors
[
2
]
*
internalF
[
3
][
i
];
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
1
][
i
]
=
internalF
[
0
][
i
]
-
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
internalF
[
2
][
i
]
=
internalF
[
3
][
i
]
+
s
;
}
}
...
@@ -297,25 +297,25 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
...
@@ -297,25 +297,25 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
// Add the energy
// Add the energy
if
(
totalEnergy
)
if
(
totalEnergy
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpression
.
evaluate
(
variables
);
*
totalEnergy
+=
energyExpression
.
evaluate
(
variables
);
}
}
void
ReferenceCustomManyParticleIxn
::
computeDelta
(
int
atom1
,
int
atom2
,
RealOpenMM
*
delta
,
vector
<
Real
Vec
>&
atomCoordinates
)
const
{
void
ReferenceCustomManyParticleIxn
::
computeDelta
(
int
atom1
,
int
atom2
,
double
*
delta
,
vector
<
Vec
3
>&
atomCoordinates
)
const
{
if
(
usePeriodic
)
if
(
usePeriodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
periodicBoxVectors
,
delta
);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
periodicBoxVectors
,
delta
);
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
delta
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atom1
],
atomCoordinates
[
atom2
],
delta
);
}
}
RealOpenMM
ReferenceCustomManyParticleIxn
::
computeAngle
(
RealOpenMM
*
vec1
,
RealOpenMM
*
vec2
)
{
double
ReferenceCustomManyParticleIxn
::
computeAngle
(
double
*
vec1
,
double
*
vec2
)
{
RealOpenMM
dot
=
DOT3
(
vec1
,
vec2
);
double
dot
=
DOT3
(
vec1
,
vec2
);
RealOpenMM
cosine
=
dot
/
SQRT
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
double
cosine
=
dot
/
sqrt
((
vec1
[
ReferenceForce
::
R2Index
]
*
vec2
[
ReferenceForce
::
R2Index
]));
RealOpenMM
angle
;
double
angle
;
if
(
cosine
>=
1
)
if
(
cosine
>=
1
)
angle
=
0
;
angle
=
0
;
else
if
(
cosine
<=
-
1
)
else
if
(
cosine
<=
-
1
)
angle
=
PI_M
;
angle
=
PI_M
;
else
else
angle
=
ACOS
(
cosine
);
angle
=
acos
(
cosine
);
return
angle
;
return
angle
;
}
}
platforms/reference/src/SimTKReference/ReferenceCustomNonbondedIxn.cpp
View file @
a783b996
...
@@ -69,13 +69,6 @@ ReferenceCustomNonbondedIxn::ReferenceCustomNonbondedIxn(const Lepton::CompiledE
...
@@ -69,13 +69,6 @@ ReferenceCustomNonbondedIxn::ReferenceCustomNonbondedIxn(const Lepton::CompiledE
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceCustomNonbondedIxn
::~
ReferenceCustomNonbondedIxn
()
{
ReferenceCustomNonbondedIxn
::~
ReferenceCustomNonbondedIxn
()
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceCustomNonbondedIxn::~ReferenceCustomNonbondedIxn";
// ---------------------------------------------------------------------------------------
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -87,7 +80,7 @@ ReferenceCustomNonbondedIxn::~ReferenceCustomNonbondedIxn() {
...
@@ -87,7 +80,7 @@ ReferenceCustomNonbondedIxn::~ReferenceCustomNonbondedIxn() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomNonbondedIxn
::
setUseCutoff
(
RealOpenMM
distance
,
const
OpenMM
::
NeighborList
&
neighbors
)
{
void
ReferenceCustomNonbondedIxn
::
setUseCutoff
(
double
distance
,
const
OpenMM
::
NeighborList
&
neighbors
)
{
cutoff
=
true
;
cutoff
=
true
;
cutoffDistance
=
distance
;
cutoffDistance
=
distance
;
...
@@ -115,7 +108,7 @@ void ReferenceCustomNonbondedIxn::setInteractionGroups(const vector<pair<set<int
...
@@ -115,7 +108,7 @@ void ReferenceCustomNonbondedIxn::setInteractionGroups(const vector<pair<set<int
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomNonbondedIxn
::
setUseSwitchingFunction
(
RealOpenMM
distance
)
{
void
ReferenceCustomNonbondedIxn
::
setUseSwitchingFunction
(
double
distance
)
{
useSwitch
=
true
;
useSwitch
=
true
;
switchingDistance
=
distance
;
switchingDistance
=
distance
;
}
}
...
@@ -130,7 +123,7 @@ void ReferenceCustomNonbondedIxn::setUseSwitchingFunction(RealOpenMM distance) {
...
@@ -130,7 +123,7 @@ void ReferenceCustomNonbondedIxn::setUseSwitchingFunction(RealOpenMM distance) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomNonbondedIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceCustomNonbondedIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
assert
(
cutoff
);
assert
(
cutoff
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
...
@@ -161,10 +154,10 @@ void ReferenceCustomNonbondedIxn::setUseSwitchingFunction(RealOpenMM distance) {
...
@@ -161,10 +154,10 @@ void ReferenceCustomNonbondedIxn::setUseSwitchingFunction(RealOpenMM distance) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomNonbondedIxn
::
calculatePairIxn
(
int
numberOfAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceCustomNonbondedIxn
::
calculatePairIxn
(
int
numberOfAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
vector
<
set
<
int
>
>&
exclusions
,
double
**
atomParameters
,
vector
<
set
<
int
>
>&
exclusions
,
RealOpenMM
*
fixedParameters
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Real
Vec
>&
forces
,
double
*
fixedParameters
,
const
map
<
string
,
double
>&
globalParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
energyByAtom
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
.
begin
();
iter
!=
globalParameters
.
end
();
++
iter
)
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
expressionSet
.
setVariable
(
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
...
@@ -232,38 +225,38 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea
...
@@ -232,38 +225,38 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Rea
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomNonbondedIxn
::
calculateOneIxn
(
int
ii
,
int
jj
,
vector
<
Real
Vec
>&
atomCoordinates
,
vector
<
Real
Vec
>&
forces
,
void
ReferenceCustomNonbondedIxn
::
calculateOneIxn
(
int
ii
,
int
jj
,
vector
<
Vec
3
>&
atomCoordinates
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
energyByAtom
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
// get deltaR, R2, and R between 2 atoms
// get deltaR, R2, and R between 2 atoms
RealOpenMM
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
if
(
periodic
)
if
(
periodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
periodicBoxVectors
,
deltaR
);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
periodicBoxVectors
,
deltaR
);
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
deltaR
);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
deltaR
);
RealOpenMM
r
=
deltaR
[
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
ReferenceForce
::
RIndex
];
if
(
cutoff
&&
r
>=
cutoffDistance
)
if
(
cutoff
&&
r
>=
cutoffDistance
)
return
;
return
;
// accumulate forces
// accumulate forces
expressionSet
.
setVariable
(
rIndex
,
r
);
expressionSet
.
setVariable
(
rIndex
,
r
);
RealOpenMM
dEdR
=
(
RealOpenMM
)
(
forceExpression
.
evaluate
()
/
(
deltaR
[
ReferenceForce
::
RIndex
])
)
;
double
dEdR
=
forceExpression
.
evaluate
()
/
(
deltaR
[
ReferenceForce
::
RIndex
]);
RealOpenMM
energy
=
(
RealOpenMM
)
energyExpression
.
evaluate
();
double
energy
=
energyExpression
.
evaluate
();
RealOpenMM
switchValue
=
1.0
;
double
switchValue
=
1.0
;
if
(
useSwitch
)
{
if
(
useSwitch
)
{
if
(
r
>
switchingDistance
)
{
if
(
r
>
switchingDistance
)
{
RealOpenMM
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
double
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
RealOpenMM
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
double
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
dEdR
=
switchValue
*
dEdR
+
energy
*
switchDeriv
/
r
;
dEdR
=
switchValue
*
dEdR
+
energy
*
switchDeriv
/
r
;
energy
*=
switchValue
;
energy
*=
switchValue
;
}
}
}
}
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
RealOpenMM
force
=
-
dEdR
*
deltaR
[
kk
];
double
force
=
-
dEdR
*
deltaR
[
kk
];
forces
[
ii
][
kk
]
+=
force
;
forces
[
ii
][
kk
]
+=
force
;
forces
[
jj
][
kk
]
-=
force
;
forces
[
jj
][
kk
]
-=
force
;
}
}
for
(
int
i
=
0
;
i
<
energyParamDerivExpressions
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
energyParamDerivExpressions
.
size
();
i
++
)
energyParamDerivs
[
i
]
+=
switchValue
*
energyParamDerivExpressions
[
i
].
evaluate
();
energyParamDerivs
[
i
]
+=
switchValue
*
energyParamDerivExpressions
[
i
].
evaluate
();
...
...
platforms/reference/src/SimTKReference/ReferenceCustomTorsionIxn.cpp
View file @
a783b996
...
@@ -62,7 +62,7 @@ ReferenceCustomTorsionIxn::ReferenceCustomTorsionIxn(const Lepton::CompiledExpre
...
@@ -62,7 +62,7 @@ ReferenceCustomTorsionIxn::ReferenceCustomTorsionIxn(const Lepton::CompiledExpre
ReferenceCustomTorsionIxn
::~
ReferenceCustomTorsionIxn
()
{
ReferenceCustomTorsionIxn
::~
ReferenceCustomTorsionIxn
()
{
}
}
void
ReferenceCustomTorsionIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceCustomTorsionIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
usePeriodic
=
true
;
usePeriodic
=
true
;
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
1
]
=
vectors
[
1
];
boxVectors
[
1
]
=
vectors
[
1
];
...
@@ -82,11 +82,11 @@ void ReferenceCustomTorsionIxn::setPeriodic(OpenMM::RealVec* vectors) {
...
@@ -82,11 +82,11 @@ void ReferenceCustomTorsionIxn::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceCustomTorsionIxn
::
calculateBondIxn
(
int
*
atomIndices
,
void
ReferenceCustomTorsionIxn
::
calculateBondIxn
(
int
*
atomIndices
,
vector
<
Real
Vec
>&
atomCoordinates
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
double
*
parameters
,
vector
<
Real
Vec
>&
forces
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
RealOpenMM
deltaR
[
3
][
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
3
][
ReferenceForce
::
LastDeltaRIndex
];
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
for
(
int
i
=
0
;
i
<
numParameters
;
i
++
)
expressionSet
.
setVariable
(
torsionParamIndex
[
i
],
parameters
[
i
]);
expressionSet
.
setVariable
(
torsionParamIndex
[
i
],
parameters
[
i
]);
...
@@ -111,45 +111,45 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices,
...
@@ -111,45 +111,45 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices,
// Visual Studio complains if crossProduct declared as 'crossProduct[2][3]'
// Visual Studio complains if crossProduct declared as 'crossProduct[2][3]'
RealOpenMM
crossProductMemory
[
6
];
double
crossProductMemory
[
6
];
RealOpenMM
*
crossProduct
[
2
];
double
*
crossProduct
[
2
];
crossProduct
[
0
]
=
crossProductMemory
;
crossProduct
[
0
]
=
crossProductMemory
;
crossProduct
[
1
]
=
crossProductMemory
+
3
;
crossProduct
[
1
]
=
crossProductMemory
+
3
;
// get dihedral angle
// get dihedral angle
RealOpenMM
dotDihedral
;
double
dotDihedral
;
RealOpenMM
signOfAngle
;
double
signOfAngle
;
RealOpenMM
angle
=
getDihedralAngleBetweenThreeVectors
(
deltaR
[
0
],
deltaR
[
1
],
deltaR
[
2
],
crossProduct
,
&
dotDihedral
,
deltaR
[
0
],
&
signOfAngle
,
1
);
double
angle
=
getDihedralAngleBetweenThreeVectors
(
deltaR
[
0
],
deltaR
[
1
],
deltaR
[
2
],
crossProduct
,
&
dotDihedral
,
deltaR
[
0
],
&
signOfAngle
,
1
);
expressionSet
.
setVariable
(
thetaIndex
,
angle
);
expressionSet
.
setVariable
(
thetaIndex
,
angle
);
// evaluate delta angle, dE/d(angle)
// evaluate delta angle, dE/d(angle)
RealOpenMM
dEdAngle
=
(
RealOpenMM
)
forceExpression
.
evaluate
();
double
dEdAngle
=
forceExpression
.
evaluate
();
// compute force
// compute force
RealOpenMM
internalF
[
4
][
3
];
double
internalF
[
4
][
3
];
RealOpenMM
forceFactors
[
4
];
double
forceFactors
[
4
];
RealOpenMM
normCross1
=
DOT3
(
crossProduct
[
0
],
crossProduct
[
0
]);
double
normCross1
=
DOT3
(
crossProduct
[
0
],
crossProduct
[
0
]);
RealOpenMM
normBC
=
deltaR
[
1
][
ReferenceForce
::
RIndex
];
double
normBC
=
deltaR
[
1
][
ReferenceForce
::
RIndex
];
forceFactors
[
0
]
=
(
-
dEdAngle
*
normBC
)
/
normCross1
;
forceFactors
[
0
]
=
(
-
dEdAngle
*
normBC
)
/
normCross1
;
RealOpenMM
normCross2
=
DOT3
(
crossProduct
[
1
],
crossProduct
[
1
]);
double
normCross2
=
DOT3
(
crossProduct
[
1
],
crossProduct
[
1
]);
forceFactors
[
3
]
=
(
dEdAngle
*
normBC
)
/
normCross2
;
forceFactors
[
3
]
=
(
dEdAngle
*
normBC
)
/
normCross2
;
forceFactors
[
1
]
=
DOT3
(
deltaR
[
0
],
deltaR
[
1
]);
forceFactors
[
1
]
=
DOT3
(
deltaR
[
0
],
deltaR
[
1
]);
forceFactors
[
1
]
/=
deltaR
[
1
][
ReferenceForce
::
R2Index
];
forceFactors
[
1
]
/=
deltaR
[
1
][
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
=
DOT3
(
deltaR
[
2
],
deltaR
[
1
]);
forceFactors
[
2
]
=
DOT3
(
deltaR
[
2
],
deltaR
[
1
]);
forceFactors
[
2
]
/=
deltaR
[
1
][
ReferenceForce
::
R2Index
];
forceFactors
[
2
]
/=
deltaR
[
1
][
ReferenceForce
::
R2Index
];
for
(
int
ii
=
0
;
ii
<
3
;
ii
++
)
{
for
(
int
ii
=
0
;
ii
<
3
;
ii
++
)
{
internalF
[
0
][
ii
]
=
forceFactors
[
0
]
*
crossProduct
[
0
][
ii
];
internalF
[
0
][
ii
]
=
forceFactors
[
0
]
*
crossProduct
[
0
][
ii
];
internalF
[
3
][
ii
]
=
forceFactors
[
3
]
*
crossProduct
[
1
][
ii
];
internalF
[
3
][
ii
]
=
forceFactors
[
3
]
*
crossProduct
[
1
][
ii
];
RealOpenMM
s
=
forceFactors
[
1
]
*
internalF
[
0
][
ii
]
-
forceFactors
[
2
]
*
internalF
[
3
][
ii
];
double
s
=
forceFactors
[
1
]
*
internalF
[
0
][
ii
]
-
forceFactors
[
2
]
*
internalF
[
3
][
ii
];
internalF
[
1
][
ii
]
=
internalF
[
0
][
ii
]
-
s
;
internalF
[
1
][
ii
]
=
internalF
[
0
][
ii
]
-
s
;
internalF
[
2
][
ii
]
=
internalF
[
3
][
ii
]
+
s
;
internalF
[
2
][
ii
]
=
internalF
[
3
][
ii
]
+
s
;
...
@@ -172,6 +172,6 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices,
...
@@ -172,6 +172,6 @@ void ReferenceCustomTorsionIxn::calculateBondIxn(int* atomIndices,
// accumulate energies
// accumulate energies
if
(
totalEnergy
!=
NULL
)
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
(
RealOpenMM
)
energyExpression
.
evaluate
();
*
totalEnergy
+=
energyExpression
.
evaluate
();
}
}
platforms/reference/src/SimTKReference/ReferenceDynamics.cpp
View file @
a783b996
...
@@ -44,19 +44,10 @@ using namespace OpenMM;
...
@@ -44,19 +44,10 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceDynamics
::
ReferenceDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
temperature
)
:
ReferenceDynamics
::
ReferenceDynamics
(
int
numberOfAtoms
,
double
deltaT
,
double
temperature
)
:
_numberOfAtoms
(
numberOfAtoms
),
_deltaT
(
deltaT
),
_temperature
(
temperature
)
{
_numberOfAtoms
(
numberOfAtoms
),
_deltaT
(
deltaT
),
_temperature
(
temperature
)
{
// ---------------------------------------------------------------------------------------
_timeStep
=
0
;
// static const char* methodName = "\nReferenceDynamics::ReferenceDynamics";
static
const
RealOpenMM
one
=
1.0
;
// ---------------------------------------------------------------------------------------
_timeStep
=
0
;
_ownReferenceConstraint
=
false
;
_ownReferenceConstraint
=
false
;
_referenceConstraint
=
NULL
;
_referenceConstraint
=
NULL
;
}
}
...
@@ -68,13 +59,6 @@ ReferenceDynamics::ReferenceDynamics(int numberOfAtoms, RealOpenMM deltaT, Real
...
@@ -68,13 +59,6 @@ ReferenceDynamics::ReferenceDynamics(int numberOfAtoms, RealOpenMM deltaT, Real
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceDynamics
::~
ReferenceDynamics
()
{
ReferenceDynamics
::~
ReferenceDynamics
()
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::~ReferenceDynamics";
// ---------------------------------------------------------------------------------------
if
(
_ownReferenceConstraint
)
{
if
(
_ownReferenceConstraint
)
{
delete
_referenceConstraint
;
delete
_referenceConstraint
;
}
}
...
@@ -89,13 +73,6 @@ ReferenceDynamics::~ReferenceDynamics() {
...
@@ -89,13 +73,6 @@ ReferenceDynamics::~ReferenceDynamics() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
int
ReferenceDynamics
::
getNumberOfAtoms
()
const
{
int
ReferenceDynamics
::
getNumberOfAtoms
()
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::getNumberOfAtoms";
// ---------------------------------------------------------------------------------------
return
_numberOfAtoms
;
return
_numberOfAtoms
;
}
}
...
@@ -108,13 +85,6 @@ int ReferenceDynamics::getNumberOfAtoms() const {
...
@@ -108,13 +85,6 @@ int ReferenceDynamics::getNumberOfAtoms() const {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
int
ReferenceDynamics
::
getTimeStep
()
const
{
int
ReferenceDynamics
::
getTimeStep
()
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::getTimeStep";
// ---------------------------------------------------------------------------------------
return
_timeStep
;
return
_timeStep
;
}
}
...
@@ -127,13 +97,6 @@ int ReferenceDynamics::getTimeStep() const {
...
@@ -127,13 +97,6 @@ int ReferenceDynamics::getTimeStep() const {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
int
ReferenceDynamics
::
incrementTimeStep
()
{
int
ReferenceDynamics
::
incrementTimeStep
()
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::getTimeStep";
// ---------------------------------------------------------------------------------------
return
(
++
_timeStep
);
return
(
++
_timeStep
);
}
}
...
@@ -145,14 +108,7 @@ int ReferenceDynamics::incrementTimeStep() {
...
@@ -145,14 +108,7 @@ int ReferenceDynamics::incrementTimeStep() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
RealOpenMM
ReferenceDynamics
::
getDeltaT
()
const
{
double
ReferenceDynamics
::
getDeltaT
()
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::getDeltaT";
// ---------------------------------------------------------------------------------------
return
_deltaT
;
return
_deltaT
;
}
}
...
@@ -162,14 +118,7 @@ RealOpenMM ReferenceDynamics::getDeltaT() const {
...
@@ -162,14 +118,7 @@ RealOpenMM ReferenceDynamics::getDeltaT() const {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceDynamics
::
setDeltaT
(
RealOpenMM
deltaT
)
{
void
ReferenceDynamics
::
setDeltaT
(
double
deltaT
)
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::setDeltaT";
// ---------------------------------------------------------------------------------------
_deltaT
=
deltaT
;
_deltaT
=
deltaT
;
}
}
...
@@ -181,14 +130,7 @@ void ReferenceDynamics::setDeltaT(RealOpenMM deltaT) {
...
@@ -181,14 +130,7 @@ void ReferenceDynamics::setDeltaT(RealOpenMM deltaT) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
RealOpenMM
ReferenceDynamics
::
getTemperature
()
const
{
double
ReferenceDynamics
::
getTemperature
()
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::getTemperature";
// ---------------------------------------------------------------------------------------
return
_temperature
;
return
_temperature
;
}
}
...
@@ -201,13 +143,6 @@ RealOpenMM ReferenceDynamics::getTemperature() const {
...
@@ -201,13 +143,6 @@ RealOpenMM ReferenceDynamics::getTemperature() const {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceConstraintAlgorithm
*
ReferenceDynamics
::
getReferenceConstraintAlgorithm
()
const
{
ReferenceConstraintAlgorithm
*
ReferenceDynamics
::
getReferenceConstraintAlgorithm
()
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::getReferenceConstraint";
// ---------------------------------------------------------------------------------------
return
_referenceConstraint
;
return
_referenceConstraint
;
}
}
...
@@ -220,13 +155,6 @@ ReferenceConstraintAlgorithm* ReferenceDynamics::getReferenceConstraintAlgorithm
...
@@ -220,13 +155,6 @@ ReferenceConstraintAlgorithm* ReferenceDynamics::getReferenceConstraintAlgorithm
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceDynamics
::
setReferenceConstraintAlgorithm
(
ReferenceConstraintAlgorithm
*
referenceConstraint
)
{
void
ReferenceDynamics
::
setReferenceConstraintAlgorithm
(
ReferenceConstraintAlgorithm
*
referenceConstraint
)
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceDynamics::setReferenceConstraint";
// ---------------------------------------------------------------------------------------
// delete if own
// delete if own
if
(
_referenceConstraint
&&
_ownReferenceConstraint
)
{
if
(
_referenceConstraint
&&
_ownReferenceConstraint
)
{
...
@@ -251,15 +179,6 @@ void ReferenceDynamics::setReferenceConstraintAlgorithm(ReferenceConstraintAlgor
...
@@ -251,15 +179,6 @@ void ReferenceDynamics::setReferenceConstraintAlgorithm(ReferenceConstraintAlgor
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceDynamics
::
update
(
const
OpenMM
::
System
&
system
,
vector
<
RealVec
>&
atomCoordinates
,
void
ReferenceDynamics
::
update
(
const
OpenMM
::
System
&
system
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
RealVec
>&
velocities
,
vector
<
RealVec
>&
forces
,
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
tolerance
)
{
vector
<
Vec3
>&
velocities
,
vector
<
Vec3
>&
forces
,
vector
<
double
>&
masses
,
double
tolerance
)
{
// ---------------------------------------------------------------------------------------
static
const
char
*
methodName
=
"
\n
ReferenceDynamics::update"
;
static
const
RealOpenMM
zero
=
0.0
;
static
const
RealOpenMM
one
=
1.0
;
// ---------------------------------------------------------------------------------------
}
}
platforms/reference/src/SimTKReference/ReferenceForce.cpp
View file @
a783b996
...
@@ -56,40 +56,40 @@ ReferenceForce::~ReferenceForce() {
...
@@ -56,40 +56,40 @@ ReferenceForce::~ReferenceForce() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
RealOpenMM
ReferenceForce
::
periodicDifference
(
RealOpenMM
val1
,
RealOpenMM
val2
,
RealOpenMM
period
)
{
double
ReferenceForce
::
periodicDifference
(
double
val1
,
double
val2
,
double
period
)
{
RealOpenMM
diff
=
val1
-
val2
;
double
diff
=
val1
-
val2
;
RealOpenMM
base
=
(
RealOpenMM
)
(
floor
(
diff
/
period
+
0.5
)
*
period
)
;
double
base
=
floor
(
diff
/
period
+
0.5
)
*
period
;
return
diff
-
base
;
return
diff
-
base
;
}
}
void
ReferenceForce
::
getDeltaR
(
const
Real
Vec
&
atomCoordinatesI
,
const
Real
Vec
&
atomCoordinatesJ
,
void
ReferenceForce
::
getDeltaR
(
const
Vec
3
&
atomCoordinatesI
,
const
Vec
3
&
atomCoordinatesJ
,
RealOpenMM
*
deltaR
)
{
double
*
deltaR
)
{
deltaR
[
XIndex
]
=
atomCoordinatesJ
[
0
]
-
atomCoordinatesI
[
0
];
deltaR
[
XIndex
]
=
atomCoordinatesJ
[
0
]
-
atomCoordinatesI
[
0
];
deltaR
[
YIndex
]
=
atomCoordinatesJ
[
1
]
-
atomCoordinatesI
[
1
];
deltaR
[
YIndex
]
=
atomCoordinatesJ
[
1
]
-
atomCoordinatesI
[
1
];
deltaR
[
ZIndex
]
=
atomCoordinatesJ
[
2
]
-
atomCoordinatesI
[
2
];
deltaR
[
ZIndex
]
=
atomCoordinatesJ
[
2
]
-
atomCoordinatesI
[
2
];
deltaR
[
R2Index
]
=
DOT3
(
deltaR
,
deltaR
);
deltaR
[
R2Index
]
=
DOT3
(
deltaR
,
deltaR
);
deltaR
[
RIndex
]
=
(
RealOpenMM
)
SQRT
(
deltaR
[
R2Index
]);
deltaR
[
RIndex
]
=
sqrt
(
deltaR
[
R2Index
]);
}
}
Real
Vec
ReferenceForce
::
getDeltaR
(
const
Real
Vec
&
atomCoordinatesI
,
const
Real
Vec
&
atomCoordinatesJ
)
{
Vec
3
ReferenceForce
::
getDeltaR
(
const
Vec
3
&
atomCoordinatesI
,
const
Vec
3
&
atomCoordinatesJ
)
{
return
atomCoordinatesJ
-
atomCoordinatesI
;
return
atomCoordinatesJ
-
atomCoordinatesI
;
}
}
void
ReferenceForce
::
getDeltaRPeriodic
(
const
Real
Vec
&
atomCoordinatesI
,
const
Real
Vec
&
atomCoordinatesJ
,
void
ReferenceForce
::
getDeltaRPeriodic
(
const
Vec
3
&
atomCoordinatesI
,
const
Vec
3
&
atomCoordinatesJ
,
const
RealOpenMM
*
boxSize
,
RealOpenMM
*
deltaR
)
{
const
double
*
boxSize
,
double
*
deltaR
)
{
deltaR
[
XIndex
]
=
periodicDifference
(
atomCoordinatesJ
[
0
],
atomCoordinatesI
[
0
],
boxSize
[
0
]);
deltaR
[
XIndex
]
=
periodicDifference
(
atomCoordinatesJ
[
0
],
atomCoordinatesI
[
0
],
boxSize
[
0
]);
deltaR
[
YIndex
]
=
periodicDifference
(
atomCoordinatesJ
[
1
],
atomCoordinatesI
[
1
],
boxSize
[
1
]);
deltaR
[
YIndex
]
=
periodicDifference
(
atomCoordinatesJ
[
1
],
atomCoordinatesI
[
1
],
boxSize
[
1
]);
deltaR
[
ZIndex
]
=
periodicDifference
(
atomCoordinatesJ
[
2
],
atomCoordinatesI
[
2
],
boxSize
[
2
]);
deltaR
[
ZIndex
]
=
periodicDifference
(
atomCoordinatesJ
[
2
],
atomCoordinatesI
[
2
],
boxSize
[
2
]);
deltaR
[
R2Index
]
=
DOT3
(
deltaR
,
deltaR
);
deltaR
[
R2Index
]
=
DOT3
(
deltaR
,
deltaR
);
deltaR
[
RIndex
]
=
(
RealOpenMM
)
SQRT
(
deltaR
[
R2Index
]);
deltaR
[
RIndex
]
=
sqrt
(
deltaR
[
R2Index
]);
}
}
void
ReferenceForce
::
getDeltaRPeriodic
(
const
Real
Vec
&
atomCoordinatesI
,
const
Real
Vec
&
atomCoordinatesJ
,
void
ReferenceForce
::
getDeltaRPeriodic
(
const
Vec
3
&
atomCoordinatesI
,
const
Vec
3
&
atomCoordinatesJ
,
const
Real
Vec
*
boxVectors
,
RealOpenMM
*
deltaR
)
{
const
Vec
3
*
boxVectors
,
double
*
deltaR
)
{
Real
Vec
diff
=
atomCoordinatesJ
-
atomCoordinatesI
;
Vec
3
diff
=
atomCoordinatesJ
-
atomCoordinatesI
;
diff
-=
boxVectors
[
2
]
*
floor
(
diff
[
2
]
/
boxVectors
[
2
][
2
]
+
0.5
);
diff
-=
boxVectors
[
2
]
*
floor
(
diff
[
2
]
/
boxVectors
[
2
][
2
]
+
0.5
);
diff
-=
boxVectors
[
1
]
*
floor
(
diff
[
1
]
/
boxVectors
[
1
][
1
]
+
0.5
);
diff
-=
boxVectors
[
1
]
*
floor
(
diff
[
1
]
/
boxVectors
[
1
][
1
]
+
0.5
);
diff
-=
boxVectors
[
0
]
*
floor
(
diff
[
0
]
/
boxVectors
[
0
][
0
]
+
0.5
);
diff
-=
boxVectors
[
0
]
*
floor
(
diff
[
0
]
/
boxVectors
[
0
][
0
]
+
0.5
);
...
@@ -97,12 +97,12 @@ void ReferenceForce::getDeltaRPeriodic(const RealVec& atomCoordinatesI, const Re
...
@@ -97,12 +97,12 @@ void ReferenceForce::getDeltaRPeriodic(const RealVec& atomCoordinatesI, const Re
deltaR
[
YIndex
]
=
diff
[
1
];
deltaR
[
YIndex
]
=
diff
[
1
];
deltaR
[
ZIndex
]
=
diff
[
2
];
deltaR
[
ZIndex
]
=
diff
[
2
];
deltaR
[
R2Index
]
=
diff
.
dot
(
diff
);
deltaR
[
R2Index
]
=
diff
.
dot
(
diff
);
deltaR
[
RIndex
]
=
SQRT
(
deltaR
[
R2Index
]);
deltaR
[
RIndex
]
=
sqrt
(
deltaR
[
R2Index
]);
}
}
Real
Vec
ReferenceForce
::
getDeltaRPeriodic
(
const
Real
Vec
&
atomCoordinatesI
,
const
Real
Vec
&
atomCoordinatesJ
,
Vec
3
ReferenceForce
::
getDeltaRPeriodic
(
const
Vec
3
&
atomCoordinatesI
,
const
Vec
3
&
atomCoordinatesJ
,
const
Real
Vec
*
boxVectors
)
{
const
Vec
3
*
boxVectors
)
{
Real
Vec
diff
=
atomCoordinatesJ
-
atomCoordinatesI
;
Vec
3
diff
=
atomCoordinatesJ
-
atomCoordinatesI
;
diff
-=
boxVectors
[
2
]
*
floor
(
diff
[
2
]
/
boxVectors
[
2
][
2
]
+
0.5
);
diff
-=
boxVectors
[
2
]
*
floor
(
diff
[
2
]
/
boxVectors
[
2
][
2
]
+
0.5
);
diff
-=
boxVectors
[
1
]
*
floor
(
diff
[
1
]
/
boxVectors
[
1
][
1
]
+
0.5
);
diff
-=
boxVectors
[
1
]
*
floor
(
diff
[
1
]
/
boxVectors
[
1
][
1
]
+
0.5
);
diff
-=
boxVectors
[
0
]
*
floor
(
diff
[
0
]
/
boxVectors
[
0
][
0
]
+
0.5
);
diff
-=
boxVectors
[
0
]
*
floor
(
diff
[
0
]
/
boxVectors
[
0
][
0
]
+
0.5
);
...
...
platforms/reference/src/SimTKReference/ReferenceGayBerneForce.cpp
View file @
a783b996
...
@@ -78,11 +78,11 @@ ReferenceGayBerneForce::ReferenceGayBerneForce(const GayBerneForce& force) {
...
@@ -78,11 +78,11 @@ ReferenceGayBerneForce::ReferenceGayBerneForce(const GayBerneForce& force) {
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
ParticleInfo
&
p
=
particles
[
i
];
ParticleInfo
&
p
=
particles
[
i
];
s
[
i
]
=
(
p
.
rx
*
p
.
ry
+
p
.
rz
*
p
.
rz
)
*
SQRT
(
p
.
rx
*
p
.
ry
);
s
[
i
]
=
(
p
.
rx
*
p
.
ry
+
p
.
rz
*
p
.
rz
)
*
sqrt
(
p
.
rx
*
p
.
ry
);
}
}
}
}
RealOpenMM
ReferenceGayBerneForce
::
calculateForce
(
const
vector
<
Real
Vec
>&
positions
,
vector
<
Real
Vec
>&
forces
,
const
Real
Vec
*
boxVectors
)
{
double
ReferenceGayBerneForce
::
calculateForce
(
const
vector
<
Vec
3
>&
positions
,
vector
<
Vec
3
>&
forces
,
const
Vec
3
*
boxVectors
)
{
if
(
nonbondedMethod
==
GayBerneForce
::
CutoffPeriodic
)
{
if
(
nonbondedMethod
==
GayBerneForce
::
CutoffPeriodic
)
{
double
minAllowedSize
=
1.999999
*
cutoffDistance
;
double
minAllowedSize
=
1.999999
*
cutoffDistance
;
if
(
boxVectors
[
0
][
0
]
<
minAllowedSize
||
boxVectors
[
1
][
1
]
<
minAllowedSize
||
boxVectors
[
2
][
2
]
<
minAllowedSize
)
if
(
boxVectors
[
0
][
0
]
<
minAllowedSize
||
boxVectors
[
1
][
1
]
<
minAllowedSize
||
boxVectors
[
2
][
2
]
<
minAllowedSize
)
...
@@ -95,9 +95,9 @@ RealOpenMM ReferenceGayBerneForce::calculateForce(const vector<RealVec>& positio
...
@@ -95,9 +95,9 @@ RealOpenMM ReferenceGayBerneForce::calculateForce(const vector<RealVec>& positio
// Compute standard interactions.
// Compute standard interactions.
RealOpenMM
energy
=
0
;
double
energy
=
0
;
int
numParticles
=
particles
.
size
();
int
numParticles
=
particles
.
size
();
vector
<
Real
Vec
>
torques
(
numParticles
,
Vec3
());
vector
<
Vec
3
>
torques
(
numParticles
,
Vec3
());
for
(
int
i
=
1
;
i
<
numParticles
;
i
++
)
{
for
(
int
i
=
1
;
i
<
numParticles
;
i
++
)
{
if
(
particles
[
i
].
epsilon
==
0.0
)
if
(
particles
[
i
].
epsilon
==
0.0
)
continue
;
continue
;
...
@@ -106,8 +106,8 @@ RealOpenMM ReferenceGayBerneForce::calculateForce(const vector<RealVec>& positio
...
@@ -106,8 +106,8 @@ RealOpenMM ReferenceGayBerneForce::calculateForce(const vector<RealVec>& positio
continue
;
continue
;
if
(
exclusions
.
find
(
make_pair
(
j
,
i
))
!=
exclusions
.
end
())
if
(
exclusions
.
find
(
make_pair
(
j
,
i
))
!=
exclusions
.
end
())
continue
;
// This interaction will be handled by an exception.
continue
;
// This interaction will be handled by an exception.
RealOpenMM
sigma
=
0.5
*
(
particles
[
i
].
sigma
+
particles
[
j
].
sigma
);
double
sigma
=
0.5
*
(
particles
[
i
].
sigma
+
particles
[
j
].
sigma
);
RealOpenMM
epsilon
=
SQRT
(
particles
[
i
].
epsilon
*
particles
[
j
].
epsilon
);
double
epsilon
=
sqrt
(
particles
[
i
].
epsilon
*
particles
[
j
].
epsilon
);
energy
+=
computeOneInteraction
(
i
,
j
,
sigma
,
epsilon
,
positions
,
forces
,
torques
,
boxVectors
);
energy
+=
computeOneInteraction
(
i
,
j
,
sigma
,
epsilon
,
positions
,
forces
,
torques
,
boxVectors
);
}
}
}
}
...
@@ -126,39 +126,39 @@ RealOpenMM ReferenceGayBerneForce::calculateForce(const vector<RealVec>& positio
...
@@ -126,39 +126,39 @@ RealOpenMM ReferenceGayBerneForce::calculateForce(const vector<RealVec>& positio
return
energy
;
return
energy
;
}
}
void
ReferenceGayBerneForce
::
computeEllipsoidFrames
(
const
vector
<
Real
Vec
>&
positions
)
{
void
ReferenceGayBerneForce
::
computeEllipsoidFrames
(
const
vector
<
Vec
3
>&
positions
)
{
int
numParticles
=
particles
.
size
();
int
numParticles
=
particles
.
size
();
for
(
int
particle
=
0
;
particle
<
numParticles
;
particle
++
)
{
for
(
int
particle
=
0
;
particle
<
numParticles
;
particle
++
)
{
ParticleInfo
&
p
=
particles
[
particle
];
ParticleInfo
&
p
=
particles
[
particle
];
// Compute the local coordinate system of the ellipsoid;
// Compute the local coordinate system of the ellipsoid;
Real
Vec
xdir
,
ydir
,
zdir
;
Vec
3
xdir
,
ydir
,
zdir
;
if
(
p
.
xparticle
==
-
1
)
{
if
(
p
.
xparticle
==
-
1
)
{
xdir
=
Real
Vec
(
1
,
0
,
0
);
xdir
=
Vec
3
(
1
,
0
,
0
);
ydir
=
Real
Vec
(
0
,
1
,
0
);
ydir
=
Vec
3
(
0
,
1
,
0
);
}
}
else
{
else
{
xdir
=
positions
[
particle
]
-
positions
[
p
.
xparticle
];
xdir
=
positions
[
particle
]
-
positions
[
p
.
xparticle
];
xdir
/=
SQRT
(
xdir
.
dot
(
xdir
));
xdir
/=
sqrt
(
xdir
.
dot
(
xdir
));
if
(
p
.
yparticle
==
-
1
)
{
if
(
p
.
yparticle
==
-
1
)
{
if
(
xdir
[
1
]
>
-
0.5
&&
xdir
[
1
]
<
0.5
)
if
(
xdir
[
1
]
>
-
0.5
&&
xdir
[
1
]
<
0.5
)
ydir
=
Real
Vec
(
0
,
1
,
0
);
ydir
=
Vec
3
(
0
,
1
,
0
);
else
else
ydir
=
Real
Vec
(
1
,
0
,
0
);
ydir
=
Vec
3
(
1
,
0
,
0
);
}
}
else
else
ydir
=
positions
[
particle
]
-
positions
[
p
.
yparticle
];
ydir
=
positions
[
particle
]
-
positions
[
p
.
yparticle
];
ydir
-=
xdir
*
(
xdir
.
dot
(
ydir
));
ydir
-=
xdir
*
(
xdir
.
dot
(
ydir
));
ydir
/=
SQRT
(
ydir
.
dot
(
ydir
));
ydir
/=
sqrt
(
ydir
.
dot
(
ydir
));
}
}
zdir
=
xdir
.
cross
(
ydir
);
zdir
=
xdir
.
cross
(
ydir
);
// Compute matrices we will need later.
// Compute matrices we will need later.
RealOpenMM
(
&
a
)[
3
][
3
]
=
A
[
particle
].
v
;
double
(
&
a
)[
3
][
3
]
=
A
[
particle
].
v
;
RealOpenMM
(
&
b
)[
3
][
3
]
=
B
[
particle
].
v
;
double
(
&
b
)[
3
][
3
]
=
B
[
particle
].
v
;
RealOpenMM
(
&
g
)[
3
][
3
]
=
G
[
particle
].
v
;
double
(
&
g
)[
3
][
3
]
=
G
[
particle
].
v
;
a
[
0
][
0
]
=
xdir
[
0
];
a
[
0
][
0
]
=
xdir
[
0
];
a
[
0
][
1
]
=
xdir
[
1
];
a
[
0
][
1
]
=
xdir
[
1
];
a
[
0
][
2
]
=
xdir
[
2
];
a
[
0
][
2
]
=
xdir
[
2
];
...
@@ -168,8 +168,8 @@ void ReferenceGayBerneForce::computeEllipsoidFrames(const vector<RealVec>& posit
...
@@ -168,8 +168,8 @@ void ReferenceGayBerneForce::computeEllipsoidFrames(const vector<RealVec>& posit
a
[
2
][
0
]
=
zdir
[
0
];
a
[
2
][
0
]
=
zdir
[
0
];
a
[
2
][
1
]
=
zdir
[
1
];
a
[
2
][
1
]
=
zdir
[
1
];
a
[
2
][
2
]
=
zdir
[
2
];
a
[
2
][
2
]
=
zdir
[
2
];
Real
Vec
r2
(
p
.
rx
*
p
.
rx
,
p
.
ry
*
p
.
ry
,
p
.
rz
*
p
.
rz
);
Vec
3
r2
(
p
.
rx
*
p
.
rx
,
p
.
ry
*
p
.
ry
,
p
.
rz
*
p
.
rz
);
Real
Vec
e2
(
1
/
sqrt
(
p
.
ex
),
1
/
sqrt
(
p
.
ey
),
1
/
sqrt
(
p
.
ez
));
Vec
3
e2
(
1
/
sqrt
(
p
.
ex
),
1
/
sqrt
(
p
.
ey
),
1
/
sqrt
(
p
.
ez
));
for
(
int
i
=
0
;
i
<
3
;
i
++
)
for
(
int
i
=
0
;
i
<
3
;
i
++
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
b
[
i
][
j
]
=
0
;
b
[
i
][
j
]
=
0
;
...
@@ -182,26 +182,26 @@ void ReferenceGayBerneForce::computeEllipsoidFrames(const vector<RealVec>& posit
...
@@ -182,26 +182,26 @@ void ReferenceGayBerneForce::computeEllipsoidFrames(const vector<RealVec>& posit
}
}
}
}
void
ReferenceGayBerneForce
::
applyTorques
(
const
vector
<
Real
Vec
>&
positions
,
vector
<
Real
Vec
>&
forces
,
const
vector
<
Real
Vec
>&
torques
)
{
void
ReferenceGayBerneForce
::
applyTorques
(
const
vector
<
Vec
3
>&
positions
,
vector
<
Vec
3
>&
forces
,
const
vector
<
Vec
3
>&
torques
)
{
int
numParticles
=
particles
.
size
();
int
numParticles
=
particles
.
size
();
for
(
int
particle
=
0
;
particle
<
numParticles
;
particle
++
)
{
for
(
int
particle
=
0
;
particle
<
numParticles
;
particle
++
)
{
ParticleInfo
&
p
=
particles
[
particle
];
ParticleInfo
&
p
=
particles
[
particle
];
Real
Vec
pos
=
positions
[
particle
];
Vec
3
pos
=
positions
[
particle
];
if
(
p
.
xparticle
!=
-
1
)
{
if
(
p
.
xparticle
!=
-
1
)
{
// Apply a force to the x particle.
// Apply a force to the x particle.
Real
Vec
dx
=
positions
[
p
.
xparticle
]
-
pos
;
Vec
3
dx
=
positions
[
p
.
xparticle
]
-
pos
;
double
dx2
=
dx
.
dot
(
dx
);
double
dx2
=
dx
.
dot
(
dx
);
Real
Vec
f
=
torques
[
particle
].
cross
(
dx
)
/
dx2
;
Vec
3
f
=
torques
[
particle
].
cross
(
dx
)
/
dx2
;
forces
[
p
.
xparticle
]
+=
f
;
forces
[
p
.
xparticle
]
+=
f
;
forces
[
particle
]
-=
f
;
forces
[
particle
]
-=
f
;
if
(
p
.
yparticle
!=
-
1
)
{
if
(
p
.
yparticle
!=
-
1
)
{
// Apply a force to the y particle. This is based on the component of the torque
// Apply a force to the y particle. This is based on the component of the torque
// that was not already applied to the x particle.
// that was not already applied to the x particle.
Real
Vec
dy
=
positions
[
p
.
yparticle
]
-
pos
;
Vec
3
dy
=
positions
[
p
.
yparticle
]
-
pos
;
double
dy2
=
dy
.
dot
(
dy
);
double
dy2
=
dy
.
dot
(
dy
);
Real
Vec
torque
=
dx
*
(
torques
[
particle
].
dot
(
dx
)
/
dx2
);
Vec
3
torque
=
dx
*
(
torques
[
particle
].
dot
(
dx
)
/
dx2
);
f
=
torque
.
cross
(
dy
)
/
dy2
;
f
=
torque
.
cross
(
dy
)
/
dy2
;
forces
[
p
.
yparticle
]
+=
f
;
forces
[
p
.
yparticle
]
+=
f
;
forces
[
particle
]
-=
f
;
forces
[
particle
]
-=
f
;
...
@@ -210,62 +210,62 @@ void ReferenceGayBerneForce::applyTorques(const vector<RealVec>& positions, vect
...
@@ -210,62 +210,62 @@ void ReferenceGayBerneForce::applyTorques(const vector<RealVec>& positions, vect
}
}
}
}
RealOpenMM
ReferenceGayBerneForce
::
computeOneInteraction
(
int
particle1
,
int
particle2
,
RealOpenMM
sigma
,
RealOpenMM
epsilon
,
const
vector
<
Real
Vec
>&
positions
,
double
ReferenceGayBerneForce
::
computeOneInteraction
(
int
particle1
,
int
particle2
,
double
sigma
,
double
epsilon
,
const
vector
<
Vec
3
>&
positions
,
vector
<
Real
Vec
>&
forces
,
vector
<
Real
Vec
>&
torques
,
const
Real
Vec
*
boxVectors
)
{
vector
<
Vec
3
>&
forces
,
vector
<
Vec
3
>&
torques
,
const
Vec
3
*
boxVectors
)
{
// Compute the displacement and check against the cutoff.
// Compute the displacement and check against the cutoff.
RealOpenMM
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
if
(
nonbondedMethod
==
GayBerneForce
::
CutoffPeriodic
)
if
(
nonbondedMethod
==
GayBerneForce
::
CutoffPeriodic
)
ReferenceForce
::
getDeltaRPeriodic
(
positions
[
particle2
],
positions
[
particle1
],
boxVectors
,
deltaR
);
ReferenceForce
::
getDeltaRPeriodic
(
positions
[
particle2
],
positions
[
particle1
],
boxVectors
,
deltaR
);
else
else
ReferenceForce
::
getDeltaR
(
positions
[
particle2
],
positions
[
particle1
],
deltaR
);
ReferenceForce
::
getDeltaR
(
positions
[
particle2
],
positions
[
particle1
],
deltaR
);
RealOpenMM
r
=
deltaR
[
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
ReferenceForce
::
RIndex
];
if
(
nonbondedMethod
!=
GayBerneForce
::
NoCutoff
&&
r
>=
cutoffDistance
)
if
(
nonbondedMethod
!=
GayBerneForce
::
NoCutoff
&&
r
>=
cutoffDistance
)
return
0
;
return
0
;
// Compute vectors and matrices we'll be needing.
// Compute vectors and matrices we'll be needing.
RealOpenMM
rInv
=
1
/
r
;
double
rInv
=
1
/
r
;
Real
Vec
dr
(
deltaR
[
ReferenceForce
::
XIndex
],
deltaR
[
ReferenceForce
::
YIndex
],
deltaR
[
ReferenceForce
::
ZIndex
]);
Vec
3
dr
(
deltaR
[
ReferenceForce
::
XIndex
],
deltaR
[
ReferenceForce
::
YIndex
],
deltaR
[
ReferenceForce
::
ZIndex
]);
Real
Vec
drUnit
=
dr
*
rInv
;
Vec
3
drUnit
=
dr
*
rInv
;
Matrix
B12
=
B
[
particle1
]
+
B
[
particle2
];
Matrix
B12
=
B
[
particle1
]
+
B
[
particle2
];
Matrix
G12
=
G
[
particle1
]
+
G
[
particle2
];
Matrix
G12
=
G
[
particle1
]
+
G
[
particle2
];
Matrix
B12inv
=
B12
.
inverse
();
Matrix
B12inv
=
B12
.
inverse
();
Matrix
G12inv
=
G12
.
inverse
();
Matrix
G12inv
=
G12
.
inverse
();
RealOpenMM
detG12
=
G12
.
determinant
();
double
detG12
=
G12
.
determinant
();
// Compute the switching function.
// Compute the switching function.
RealOpenMM
switchValue
=
1
,
switchDeriv
=
0
;
double
switchValue
=
1
,
switchDeriv
=
0
;
if
(
useSwitchingFunction
&&
r
>
switchingDistance
)
{
if
(
useSwitchingFunction
&&
r
>
switchingDistance
)
{
RealOpenMM
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
double
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
}
}
// Estimate the distance between the ellipsoids and compute the first terms needed for the energy.
// Estimate the distance between the ellipsoids and compute the first terms needed for the energy.
RealOpenMM
sigma12
=
1
/
SQRT
(
0.5
*
drUnit
.
dot
(
G12inv
*
drUnit
));
double
sigma12
=
1
/
sqrt
(
0.5
*
drUnit
.
dot
(
G12inv
*
drUnit
));
RealOpenMM
h12
=
r
-
sigma12
;
double
h12
=
r
-
sigma12
;
RealOpenMM
rho
=
sigma
/
(
h12
+
sigma
);
double
rho
=
sigma
/
(
h12
+
sigma
);
RealOpenMM
rho2
=
rho
*
rho
;
double
rho2
=
rho
*
rho
;
RealOpenMM
rho6
=
rho2
*
rho2
*
rho2
;
double
rho6
=
rho2
*
rho2
*
rho2
;
RealOpenMM
u
=
4
*
epsilon
*
(
rho6
*
rho6
-
rho6
);
double
u
=
4
*
epsilon
*
(
rho6
*
rho6
-
rho6
);
RealOpenMM
eta
=
SQRT
(
2
*
s
[
particle1
]
*
s
[
particle2
]
/
detG12
);
double
eta
=
sqrt
(
2
*
s
[
particle1
]
*
s
[
particle2
]
/
detG12
);
RealOpenMM
chi
=
2
*
drUnit
.
dot
(
B12inv
*
drUnit
);
double
chi
=
2
*
drUnit
.
dot
(
B12inv
*
drUnit
);
chi
*=
chi
;
chi
*=
chi
;
RealOpenMM
energy
=
u
*
eta
*
chi
;
double
energy
=
u
*
eta
*
chi
;
// Compute the terms needed for the force.
// Compute the terms needed for the force.
Real
Vec
kappa
=
G12inv
*
dr
;
Vec
3
kappa
=
G12inv
*
dr
;
Real
Vec
iota
=
B12inv
*
dr
;
Vec
3
iota
=
B12inv
*
dr
;
RealOpenMM
rInv2
=
rInv
*
rInv
;
double
rInv2
=
rInv
*
rInv
;
RealOpenMM
dUSLJdr
=
24
*
epsilon
*
(
2
*
rho6
-
1
)
*
rho6
*
rho
/
sigma
;
double
dUSLJdr
=
24
*
epsilon
*
(
2
*
rho6
-
1
)
*
rho6
*
rho
/
sigma
;
RealOpenMM
temp
=
0.5
*
sigma12
*
sigma12
*
sigma12
*
rInv2
;
double
temp
=
0.5
*
sigma12
*
sigma12
*
sigma12
*
rInv2
;
Real
Vec
dudr
=
(
drUnit
+
(
kappa
-
drUnit
*
kappa
.
dot
(
drUnit
))
*
temp
)
*
dUSLJdr
;
Vec
3
dudr
=
(
drUnit
+
(
kappa
-
drUnit
*
kappa
.
dot
(
drUnit
))
*
temp
)
*
dUSLJdr
;
Real
Vec
dchidr
=
(
iota
-
drUnit
*
iota
.
dot
(
drUnit
))
*
(
-
8
*
rInv2
*
SQRT
(
chi
));
Vec
3
dchidr
=
(
iota
-
drUnit
*
iota
.
dot
(
drUnit
))
*
(
-
8
*
rInv2
*
sqrt
(
chi
));
Real
Vec
force
=
(
dchidr
*
u
+
dudr
*
chi
)
*
(
eta
*
switchValue
)
-
drUnit
*
(
energy
*
switchDeriv
);
Vec
3
force
=
(
dchidr
*
u
+
dudr
*
chi
)
*
(
eta
*
switchValue
)
-
drUnit
*
(
energy
*
switchDeriv
);
forces
[
particle1
]
+=
force
;
forces
[
particle1
]
+=
force
;
forces
[
particle2
]
-=
force
;
forces
[
particle2
]
-=
force
;
...
@@ -273,14 +273,14 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
...
@@ -273,14 +273,14 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
for
(
int
j
=
0
;
j
<
2
;
j
++
)
{
for
(
int
j
=
0
;
j
<
2
;
j
++
)
{
int
particle
=
(
j
==
0
?
particle1
:
particle2
);
int
particle
=
(
j
==
0
?
particle1
:
particle2
);
Real
Vec
dudq
=
(
kappa
*
G
[
particle
]).
cross
(
kappa
*
(
temp
*
dUSLJdr
));
Vec
3
dudq
=
(
kappa
*
G
[
particle
]).
cross
(
kappa
*
(
temp
*
dUSLJdr
));
Real
Vec
dchidq
=
(
iota
*
B
[
particle
]).
cross
(
iota
)
*
(
-
4
*
rInv2
);
Vec
3
dchidq
=
(
iota
*
B
[
particle
]).
cross
(
iota
)
*
(
-
4
*
rInv2
);
RealOpenMM
(
&
g12
)[
3
][
3
]
=
G12
.
v
;
double
(
&
g12
)[
3
][
3
]
=
G12
.
v
;
RealOpenMM
(
&
a
)[
3
][
3
]
=
A
[
particle
].
v
;
double
(
&
a
)[
3
][
3
]
=
A
[
particle
].
v
;
ParticleInfo
&
p
=
particles
[
particle
];
ParticleInfo
&
p
=
particles
[
particle
];
Real
Vec
scale
=
Real
Vec
(
p
.
rx
*
p
.
rx
,
p
.
ry
*
p
.
ry
,
p
.
rz
*
p
.
rz
)
*
(
-
0.5
*
eta
/
detG12
);
Vec
3
scale
=
Vec
3
(
p
.
rx
*
p
.
rx
,
p
.
ry
*
p
.
ry
,
p
.
rz
*
p
.
rz
)
*
(
-
0.5
*
eta
/
detG12
);
Matrix
D
;
Matrix
D
;
RealOpenMM
(
&
d
)[
3
][
3
]
=
D
.
v
;
double
(
&
d
)[
3
][
3
]
=
D
.
v
;
d
[
0
][
0
]
=
scale
[
0
]
*
(
2
*
a
[
0
][
0
]
*
(
g12
[
1
][
1
]
*
g12
[
2
][
2
]
-
g12
[
1
][
2
]
*
g12
[
2
][
1
])
+
d
[
0
][
0
]
=
scale
[
0
]
*
(
2
*
a
[
0
][
0
]
*
(
g12
[
1
][
1
]
*
g12
[
2
][
2
]
-
g12
[
1
][
2
]
*
g12
[
2
][
1
])
+
a
[
0
][
2
]
*
(
g12
[
1
][
2
]
*
g12
[
0
][
1
]
+
g12
[
1
][
0
]
*
g12
[
2
][
1
]
-
g12
[
1
][
1
]
*
(
g12
[
0
][
2
]
+
g12
[
2
][
0
]))
+
a
[
0
][
2
]
*
(
g12
[
1
][
2
]
*
g12
[
0
][
1
]
+
g12
[
1
][
0
]
*
g12
[
2
][
1
]
-
g12
[
1
][
1
]
*
(
g12
[
0
][
2
]
+
g12
[
2
][
0
]))
+
a
[
0
][
1
]
*
(
g12
[
0
][
2
]
*
g12
[
2
][
1
]
+
g12
[
2
][
0
]
*
g12
[
1
][
2
]
-
g12
[
2
][
2
]
*
(
g12
[
0
][
1
]
+
g12
[
1
][
0
])));
a
[
0
][
1
]
*
(
g12
[
0
][
2
]
*
g12
[
2
][
1
]
+
g12
[
2
][
0
]
*
g12
[
1
][
2
]
-
g12
[
2
][
2
]
*
(
g12
[
0
][
1
]
+
g12
[
1
][
0
])));
...
@@ -308,10 +308,10 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
...
@@ -308,10 +308,10 @@ RealOpenMM ReferenceGayBerneForce::computeOneInteraction(int particle1, int part
d
[
2
][
2
]
=
scale
[
2
]
*
(
a
[
2
][
0
]
*
(
g12
[
0
][
1
]
*
g12
[
1
][
2
]
+
g12
[
2
][
1
]
*
g12
[
1
][
0
]
-
g12
[
1
][
1
]
*
(
g12
[
0
][
2
]
+
g12
[
2
][
0
]))
+
d
[
2
][
2
]
=
scale
[
2
]
*
(
a
[
2
][
0
]
*
(
g12
[
0
][
1
]
*
g12
[
1
][
2
]
+
g12
[
2
][
1
]
*
g12
[
1
][
0
]
-
g12
[
1
][
1
]
*
(
g12
[
0
][
2
]
+
g12
[
2
][
0
]))
+
a
[
2
][
1
]
*
(
g12
[
1
][
0
]
*
g12
[
0
][
2
]
+
g12
[
2
][
0
]
*
g12
[
0
][
1
]
-
g12
[
0
][
0
]
*
(
g12
[
1
][
2
]
+
g12
[
2
][
1
]))
+
a
[
2
][
1
]
*
(
g12
[
1
][
0
]
*
g12
[
0
][
2
]
+
g12
[
2
][
0
]
*
g12
[
0
][
1
]
-
g12
[
0
][
0
]
*
(
g12
[
1
][
2
]
+
g12
[
2
][
1
]))
+
2
*
a
[
2
][
2
]
*
(
g12
[
1
][
1
]
*
g12
[
0
][
0
]
-
g12
[
1
][
0
]
*
g12
[
0
][
1
]));
2
*
a
[
2
][
2
]
*
(
g12
[
1
][
1
]
*
g12
[
0
][
0
]
-
g12
[
1
][
0
]
*
g12
[
0
][
1
]));
Real
Vec
detadq
;
Vec
3
detadq
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
for
(
int
i
=
0
;
i
<
3
;
i
++
)
detadq
+=
Real
Vec
(
a
[
i
][
0
],
a
[
i
][
1
],
a
[
i
][
2
]).
cross
(
Real
Vec
(
d
[
i
][
0
],
d
[
i
][
1
],
d
[
i
][
2
]));
detadq
+=
Vec
3
(
a
[
i
][
0
],
a
[
i
][
1
],
a
[
i
][
2
]).
cross
(
Vec
3
(
d
[
i
][
0
],
d
[
i
][
1
],
d
[
i
][
2
]));
Real
Vec
torque
=
(
dchidq
*
(
u
*
eta
)
+
detadq
*
(
u
*
chi
)
+
dudq
*
(
eta
*
chi
))
*
switchValue
;
Vec
3
torque
=
(
dchidq
*
(
u
*
eta
)
+
detadq
*
(
u
*
chi
)
+
dudq
*
(
eta
*
chi
))
*
switchValue
;
torques
[
particle
]
-=
torque
;
torques
[
particle
]
-=
torque
;
}
}
return
switchValue
*
energy
;
return
switchValue
*
energy
;
...
...
platforms/reference/src/SimTKReference/ReferenceHarmonicBondIxn.cpp
View file @
a783b996
...
@@ -50,7 +50,7 @@ ReferenceHarmonicBondIxn::ReferenceHarmonicBondIxn() : usePeriodic(false) {
...
@@ -50,7 +50,7 @@ ReferenceHarmonicBondIxn::ReferenceHarmonicBondIxn() : usePeriodic(false) {
ReferenceHarmonicBondIxn
::~
ReferenceHarmonicBondIxn
()
{
ReferenceHarmonicBondIxn
::~
ReferenceHarmonicBondIxn
()
{
}
}
void
ReferenceHarmonicBondIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceHarmonicBondIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
usePeriodic
=
true
;
usePeriodic
=
true
;
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
0
]
=
vectors
[
0
];
boxVectors
[
1
]
=
vectors
[
1
];
boxVectors
[
1
]
=
vectors
[
1
];
...
@@ -71,20 +71,11 @@ void ReferenceHarmonicBondIxn::setPeriodic(OpenMM::RealVec* vectors) {
...
@@ -71,20 +71,11 @@ void ReferenceHarmonicBondIxn::setPeriodic(OpenMM::RealVec* vectors) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceHarmonicBondIxn
::
calculateBondIxn
(
int
*
atomIndices
,
void
ReferenceHarmonicBondIxn
::
calculateBondIxn
(
int
*
atomIndices
,
vector
<
RealVec
>&
atomCoordinates
,
vector
<
Vec3
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
double
*
parameters
,
vector
<
RealVec
>&
forces
,
vector
<
Vec3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
static
const
std
::
string
methodName
=
"
\n
ReferenceHarmonicBondIxn::calculateBondIxn"
;
static
const
int
twoI
=
2
;
static
const
RealOpenMM
zero
=
0.0
;
static
const
RealOpenMM
two
=
2.0
;
static
const
RealOpenMM
half
=
0.5
;
RealOpenMM
deltaR
[
ReferenceForce
::
LastDeltaRIndex
];
// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
...
@@ -99,14 +90,14 @@ void ReferenceHarmonicBondIxn::calculateBondIxn(int* atomIndices,
...
@@ -99,14 +90,14 @@ void ReferenceHarmonicBondIxn::calculateBondIxn(int* atomIndices,
// deltaIdeal = r - r_0
// deltaIdeal = r - r_0
RealOpenMM
deltaIdeal
=
deltaR
[
ReferenceForce
::
RIndex
]
-
parameters
[
0
];
double
deltaIdeal
=
deltaR
[
ReferenceForce
::
RIndex
]
-
parameters
[
0
];
RealOpenMM
deltaIdeal2
=
deltaIdeal
*
deltaIdeal
;
double
deltaIdeal2
=
deltaIdeal
*
deltaIdeal
;
RealOpenMM
dEdR
=
parameters
[
1
]
*
deltaIdeal
;
double
dEdR
=
parameters
[
1
]
*
deltaIdeal
;
// chain rule
// chain rule
dEdR
=
deltaR
[
ReferenceForce
::
RIndex
]
>
zero
?
(
dEdR
/
deltaR
[
ReferenceForce
::
RIndex
])
:
zero
;
dEdR
=
deltaR
[
ReferenceForce
::
RIndex
]
>
0.0
?
(
dEdR
/
deltaR
[
ReferenceForce
::
RIndex
])
:
0.0
;
forces
[
atomAIndex
][
0
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
XIndex
];
forces
[
atomAIndex
][
0
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
XIndex
];
forces
[
atomAIndex
][
1
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
YIndex
];
forces
[
atomAIndex
][
1
]
+=
dEdR
*
deltaR
[
ReferenceForce
::
YIndex
];
...
@@ -117,5 +108,5 @@ void ReferenceHarmonicBondIxn::calculateBondIxn(int* atomIndices,
...
@@ -117,5 +108,5 @@ void ReferenceHarmonicBondIxn::calculateBondIxn(int* atomIndices,
forces
[
atomBIndex
][
2
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
ZIndex
];
forces
[
atomBIndex
][
2
]
-=
dEdR
*
deltaR
[
ReferenceForce
::
ZIndex
];
if
(
totalEnergy
!=
NULL
)
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
half
*
parameters
[
1
]
*
deltaIdeal2
;
*
totalEnergy
+=
0.5
*
parameters
[
1
]
*
deltaIdeal2
;
}
}
platforms/reference/src/SimTKReference/ReferenceLJCoulomb14.cpp
View file @
a783b996
...
@@ -39,13 +39,6 @@ using namespace OpenMM;
...
@@ -39,13 +39,6 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceLJCoulomb14
::
ReferenceLJCoulomb14
()
{
ReferenceLJCoulomb14
::
ReferenceLJCoulomb14
()
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJCoulomb14::ReferenceLJCoulomb14";
// ---------------------------------------------------------------------------------------
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -55,13 +48,6 @@ ReferenceLJCoulomb14::ReferenceLJCoulomb14() {
...
@@ -55,13 +48,6 @@ ReferenceLJCoulomb14::ReferenceLJCoulomb14() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceLJCoulomb14
::~
ReferenceLJCoulomb14
()
{
ReferenceLJCoulomb14
::~
ReferenceLJCoulomb14
()
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJCoulomb14::~ReferenceLJCoulomb14";
// ---------------------------------------------------------------------------------------
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -79,33 +65,10 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14() {
...
@@ -79,33 +65,10 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulomb14
::
calculateBondIxn
(
int
*
atomIndices
,
vector
<
RealVec
>&
atomCoordinates
,
void
ReferenceLJCoulomb14
::
calculateBondIxn
(
int
*
atomIndices
,
vector
<
Vec3
>&
atomCoordinates
,
RealOpenMM
*
parameters
,
vector
<
RealVec
>&
forces
,
double
*
parameters
,
vector
<
Vec3
>&
forces
,
RealOpenMM
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
static
const
std
::
string
methodName
=
"
\n
ReferenceLJCoulomb14::calculateBondIxn"
;
// constants -- reduce Visual Studio warnings regarding conversions between float & double
static
const
RealOpenMM
zero
=
0.0
;
static
const
RealOpenMM
one
=
1.0
;
static
const
RealOpenMM
two
=
2.0
;
static
const
RealOpenMM
three
=
3.0
;
static
const
RealOpenMM
six
=
6.0
;
static
const
RealOpenMM
twelve
=
12.0
;
static
const
RealOpenMM
oneM
=
-
1.0
;
static
const
int
threeI
=
3
;
// number of parameters
static
const
int
numberOfParameters
=
3
;
static
const
int
LastAtomIndex
=
2
;
RealOpenMM
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
// ---------------------------------------------------------------------------------------
// get deltaR, R2, and R between 2 atoms
// get deltaR, R2, and R between 2 atoms
...
@@ -113,20 +76,19 @@ void ReferenceLJCoulomb14::calculateBondIxn(int* atomIndices, vector<RealVec>& a
...
@@ -113,20 +76,19 @@ void ReferenceLJCoulomb14::calculateBondIxn(int* atomIndices, vector<RealVec>& a
int
atomBIndex
=
atomIndices
[
1
];
int
atomBIndex
=
atomIndices
[
1
];
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomBIndex
],
atomCoordinates
[
atomAIndex
],
deltaR
[
0
]);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomBIndex
],
atomCoordinates
[
atomAIndex
],
deltaR
[
0
]);
RealOpenMM
r2
=
deltaR
[
0
][
ReferenceForce
::
R2Index
];
double
inverseR
=
1.0
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
RealOpenMM
inverseR
=
one
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
double
sig2
=
inverseR
*
parameters
[
0
];
RealOpenMM
sig2
=
inverseR
*
parameters
[
0
];
sig2
*=
sig2
;
sig2
*=
sig2
;
double
sig6
=
sig2
*
sig2
*
sig2
;
RealOpenMM
sig6
=
sig2
*
sig2
*
sig2
;
RealOpenMM
dEdR
=
parameters
[
1
]
*
(
twelve
*
sig6
-
six
)
*
sig6
;
double
dEdR
=
parameters
[
1
]
*
(
12.0
*
sig6
-
6.0
)
*
sig6
;
dEdR
+=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
)
;
dEdR
+=
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
;
dEdR
*=
inverseR
*
inverseR
;
dEdR
*=
inverseR
*
inverseR
;
// accumulate forces
// accumulate forces
for
(
int
ii
=
0
;
ii
<
3
;
ii
++
)
{
for
(
int
ii
=
0
;
ii
<
3
;
ii
++
)
{
RealOpenMM
force
=
dEdR
*
deltaR
[
0
][
ii
];
double
force
=
dEdR
*
deltaR
[
0
][
ii
];
forces
[
atomAIndex
][
ii
]
+=
force
;
forces
[
atomAIndex
][
ii
]
+=
force
;
forces
[
atomBIndex
][
ii
]
-=
force
;
forces
[
atomBIndex
][
ii
]
-=
force
;
}
}
...
@@ -134,5 +96,5 @@ void ReferenceLJCoulomb14::calculateBondIxn(int* atomIndices, vector<RealVec>& a
...
@@ -134,5 +96,5 @@ void ReferenceLJCoulomb14::calculateBondIxn(int* atomIndices, vector<RealVec>& a
// accumulate energies
// accumulate energies
if
(
totalEnergy
!=
NULL
)
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
parameters
[
1
]
*
(
sig6
-
one
)
*
sig6
+
(
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
);
*
totalEnergy
+=
parameters
[
1
]
*
(
sig6
-
1.0
)
*
sig6
+
(
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
);
}
}
platforms/reference/src/SimTKReference/ReferenceLJCoulombIxn.cpp
View file @
a783b996
...
@@ -48,13 +48,6 @@ using namespace OpenMM;
...
@@ -48,13 +48,6 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceLJCoulombIxn
::
ReferenceLJCoulombIxn
()
:
cutoff
(
false
),
useSwitch
(
false
),
periodic
(
false
),
ewald
(
false
),
pme
(
false
)
{
ReferenceLJCoulombIxn
::
ReferenceLJCoulombIxn
()
:
cutoff
(
false
),
useSwitch
(
false
),
periodic
(
false
),
ewald
(
false
),
pme
(
false
)
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJCoulombIxn::ReferenceLJCoulombIxn";
// ---------------------------------------------------------------------------------------
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -64,13 +57,6 @@ ReferenceLJCoulombIxn::ReferenceLJCoulombIxn() : cutoff(false), useSwitch(false)
...
@@ -64,13 +57,6 @@ ReferenceLJCoulombIxn::ReferenceLJCoulombIxn() : cutoff(false), useSwitch(false)
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceLJCoulombIxn
::~
ReferenceLJCoulombIxn
()
{
ReferenceLJCoulombIxn
::~
ReferenceLJCoulombIxn
()
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLJCoulombIxn::~ReferenceLJCoulombIxn";
// ---------------------------------------------------------------------------------------
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -83,7 +69,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn() {
...
@@ -83,7 +69,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
setUseCutoff
(
RealOpenMM
distance
,
const
OpenMM
::
NeighborList
&
neighbors
,
RealOpenMM
solventDielectric
)
{
void
ReferenceLJCoulombIxn
::
setUseCutoff
(
double
distance
,
const
OpenMM
::
NeighborList
&
neighbors
,
double
solventDielectric
)
{
cutoff
=
true
;
cutoff
=
true
;
cutoffDistance
=
distance
;
cutoffDistance
=
distance
;
...
@@ -100,7 +86,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn() {
...
@@ -100,7 +86,7 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
setUseSwitchingFunction
(
RealOpenMM
distance
)
{
void
ReferenceLJCoulombIxn
::
setUseSwitchingFunction
(
double
distance
)
{
useSwitch
=
true
;
useSwitch
=
true
;
switchingDistance
=
distance
;
switchingDistance
=
distance
;
}
}
...
@@ -115,7 +101,7 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
...
@@ -115,7 +101,7 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
setPeriodic
(
OpenMM
::
Real
Vec
*
vectors
)
{
void
ReferenceLJCoulombIxn
::
setPeriodic
(
OpenMM
::
Vec
3
*
vectors
)
{
assert
(
cutoff
);
assert
(
cutoff
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
assert
(
vectors
[
0
][
0
]
>=
2.0
*
cutoffDistance
);
...
@@ -138,7 +124,7 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
...
@@ -138,7 +124,7 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
setUseEwald
(
RealOpenMM
alpha
,
int
kmaxx
,
int
kmaxy
,
int
kmaxz
)
{
void
ReferenceLJCoulombIxn
::
setUseEwald
(
double
alpha
,
int
kmaxx
,
int
kmaxy
,
int
kmaxz
)
{
alphaEwald
=
alpha
;
alphaEwald
=
alpha
;
numRx
=
kmaxx
;
numRx
=
kmaxx
;
numRy
=
kmaxy
;
numRy
=
kmaxy
;
...
@@ -155,7 +141,7 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
...
@@ -155,7 +141,7 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
setUsePME
(
RealOpenMM
alpha
,
int
meshSize
[
3
])
{
void
ReferenceLJCoulombIxn
::
setUsePME
(
double
alpha
,
int
meshSize
[
3
])
{
alphaEwald
=
alpha
;
alphaEwald
=
alpha
;
meshDim
[
0
]
=
meshSize
[
0
];
meshDim
[
0
]
=
meshSize
[
0
];
meshDim
[
1
]
=
meshSize
[
1
];
meshDim
[
1
]
=
meshSize
[
1
];
...
@@ -181,28 +167,25 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
...
@@ -181,28 +167,25 @@ void ReferenceLJCoulombIxn::setUseSwitchingFunction(RealOpenMM distance) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
calculateEwaldIxn
(
int
numberOfAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceLJCoulombIxn
::
calculateEwaldIxn
(
int
numberOfAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
vector
<
set
<
int
>
>&
exclusions
,
double
**
atomParameters
,
vector
<
set
<
int
>
>&
exclusions
,
RealOpenMM
*
fixedParameters
,
vector
<
Real
Vec
>&
forces
,
double
*
fixedParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
,
bool
includeDirect
,
bool
includeReciprocal
)
const
{
double
*
energyByAtom
,
double
*
totalEnergy
,
bool
includeDirect
,
bool
includeReciprocal
)
const
{
typedef
std
::
complex
<
RealOpenMM
>
d_complex
;
typedef
std
::
complex
<
double
>
d_complex
;
static
const
RealOpenMM
epsilon
=
1.0
;
static
const
double
epsilon
=
1.0
;
static
const
RealOpenMM
one
=
1.0
;
static
const
RealOpenMM
six
=
6.0
;
static
const
RealOpenMM
twelve
=
12.0
;
int
kmax
=
(
ewald
?
std
::
max
(
numRx
,
std
::
max
(
numRy
,
numRz
))
:
0
);
int
kmax
=
(
ewald
?
std
::
max
(
numRx
,
std
::
max
(
numRy
,
numRz
))
:
0
);
RealOpenMM
factorEwald
=
-
1
/
(
4
*
alphaEwald
*
alphaEwald
);
double
factorEwald
=
-
1
/
(
4
*
alphaEwald
*
alphaEwald
);
RealOpenMM
SQRT_PI
=
sqrt
(
PI_M
);
double
SQRT_PI
=
sqrt
(
PI_M
);
RealOpenMM
TWO_PI
=
2.0
*
PI_M
;
double
TWO_PI
=
2.0
*
PI_M
;
RealOpenMM
recipCoeff
=
(
RealOpenMM
)(
ONE_4PI_EPS0
*
4
*
PI_M
/
(
periodicBoxVectors
[
0
][
0
]
*
periodicBoxVectors
[
1
][
1
]
*
periodicBoxVectors
[
2
][
2
])
/
epsilon
)
;
double
recipCoeff
=
ONE_4PI_EPS0
*
4
*
PI_M
/
(
periodicBoxVectors
[
0
][
0
]
*
periodicBoxVectors
[
1
][
1
]
*
periodicBoxVectors
[
2
][
2
])
/
epsilon
;
RealOpenMM
totalSelfEwaldEnergy
=
0.0
;
double
totalSelfEwaldEnergy
=
0.0
;
RealOpenMM
realSpaceEwaldEnergy
=
0.0
;
double
realSpaceEwaldEnergy
=
0.0
;
RealOpenMM
recipEnergy
=
0.0
;
double
recipEnergy
=
0.0
;
RealOpenMM
totalRecipEnergy
=
0.0
;
double
totalRecipEnergy
=
0.0
;
RealOpenMM
vdwEnergy
=
0.0
;
double
vdwEnergy
=
0.0
;
// **************************************************************************************
// **************************************************************************************
// SELF ENERGY
// SELF ENERGY
...
@@ -210,7 +193,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -210,7 +193,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
if
(
includeReciprocal
)
{
if
(
includeReciprocal
)
{
for
(
int
atomID
=
0
;
atomID
<
numberOfAtoms
;
atomID
++
)
{
for
(
int
atomID
=
0
;
atomID
<
numberOfAtoms
;
atomID
++
)
{
RealOpenMM
selfEwaldEnergy
=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
atomID
][
QIndex
]
*
atomParameters
[
atomID
][
QIndex
]
*
alphaEwald
/
SQRT_PI
)
;
double
selfEwaldEnergy
=
ONE_4PI_EPS0
*
atomParameters
[
atomID
][
QIndex
]
*
atomParameters
[
atomID
][
QIndex
]
*
alphaEwald
/
SQRT_PI
;
totalSelfEwaldEnergy
-=
selfEwaldEnergy
;
totalSelfEwaldEnergy
-=
selfEwaldEnergy
;
if
(
energyByAtom
)
{
if
(
energyByAtom
)
{
energyByAtom
[
atomID
]
-=
selfEwaldEnergy
;
energyByAtom
[
atomID
]
-=
selfEwaldEnergy
;
...
@@ -232,7 +215,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -232,7 +215,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
pme_init
(
&
pmedata
,
alphaEwald
,
numberOfAtoms
,
meshDim
,
5
,
1
);
pme_init
(
&
pmedata
,
alphaEwald
,
numberOfAtoms
,
meshDim
,
5
,
1
);
vector
<
RealOpenMM
>
charges
(
numberOfAtoms
);
vector
<
double
>
charges
(
numberOfAtoms
);
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
charges
[
i
]
=
atomParameters
[
i
][
QIndex
];
charges
[
i
]
=
atomParameters
[
i
][
QIndex
];
pme_exec
(
pmedata
,
atomCoordinates
,
forces
,
charges
,
periodicBoxVectors
,
&
recipEnergy
);
pme_exec
(
pmedata
,
atomCoordinates
,
forces
,
charges
,
periodicBoxVectors
,
&
recipEnergy
);
...
@@ -253,7 +236,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -253,7 +236,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
// setup reciprocal box
// setup reciprocal box
RealOpenMM
recipBoxSize
[
3
]
=
{
TWO_PI
/
periodicBoxVectors
[
0
][
0
],
TWO_PI
/
periodicBoxVectors
[
1
][
1
],
TWO_PI
/
periodicBoxVectors
[
2
][
2
]};
double
recipBoxSize
[
3
]
=
{
TWO_PI
/
periodicBoxVectors
[
0
][
0
],
TWO_PI
/
periodicBoxVectors
[
1
][
1
],
TWO_PI
/
periodicBoxVectors
[
2
][
2
]};
// setup K-vectors
// setup K-vectors
...
@@ -286,11 +269,11 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -286,11 +269,11 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
for
(
int
rx
=
0
;
rx
<
numRx
;
rx
++
)
{
for
(
int
rx
=
0
;
rx
<
numRx
;
rx
++
)
{
RealOpenMM
kx
=
rx
*
recipBoxSize
[
0
];
double
kx
=
rx
*
recipBoxSize
[
0
];
for
(
int
ry
=
lowry
;
ry
<
numRy
;
ry
++
)
{
for
(
int
ry
=
lowry
;
ry
<
numRy
;
ry
++
)
{
RealOpenMM
ky
=
ry
*
recipBoxSize
[
1
];
double
ky
=
ry
*
recipBoxSize
[
1
];
if
(
ry
>=
0
)
{
if
(
ry
>=
0
)
{
for
(
int
n
=
0
;
n
<
numberOfAtoms
;
n
++
)
for
(
int
n
=
0
;
n
<
numberOfAtoms
;
n
++
)
...
@@ -314,20 +297,20 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -314,20 +297,20 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
tab_qxyz
[
n
]
=
atomParameters
[
n
][
QIndex
]
*
(
tab_xy
[
n
]
*
conj
(
EIR
(
-
rz
,
n
,
2
)));
tab_qxyz
[
n
]
=
atomParameters
[
n
][
QIndex
]
*
(
tab_xy
[
n
]
*
conj
(
EIR
(
-
rz
,
n
,
2
)));
}
}
RealOpenMM
cs
=
0.0
f
;
double
cs
=
0.0
f
;
RealOpenMM
ss
=
0.0
f
;
double
ss
=
0.0
f
;
for
(
int
n
=
0
;
n
<
numberOfAtoms
;
n
++
)
{
for
(
int
n
=
0
;
n
<
numberOfAtoms
;
n
++
)
{
cs
+=
tab_qxyz
[
n
].
real
();
cs
+=
tab_qxyz
[
n
].
real
();
ss
+=
tab_qxyz
[
n
].
imag
();
ss
+=
tab_qxyz
[
n
].
imag
();
}
}
RealOpenMM
kz
=
rz
*
recipBoxSize
[
2
];
double
kz
=
rz
*
recipBoxSize
[
2
];
RealOpenMM
k2
=
kx
*
kx
+
ky
*
ky
+
kz
*
kz
;
double
k2
=
kx
*
kx
+
ky
*
ky
+
kz
*
kz
;
RealOpenMM
ak
=
exp
(
k2
*
factorEwald
)
/
k2
;
double
ak
=
exp
(
k2
*
factorEwald
)
/
k2
;
for
(
int
n
=
0
;
n
<
numberOfAtoms
;
n
++
)
{
for
(
int
n
=
0
;
n
<
numberOfAtoms
;
n
++
)
{
RealOpenMM
force
=
ak
*
(
cs
*
tab_qxyz
[
n
].
imag
()
-
ss
*
tab_qxyz
[
n
].
real
());
double
force
=
ak
*
(
cs
*
tab_qxyz
[
n
].
imag
()
-
ss
*
tab_qxyz
[
n
].
real
());
forces
[
n
][
0
]
+=
2
*
recipCoeff
*
force
*
kx
;
forces
[
n
][
0
]
+=
2
*
recipCoeff
*
force
*
kx
;
forces
[
n
][
1
]
+=
2
*
recipCoeff
*
force
*
ky
;
forces
[
n
][
1
]
+=
2
*
recipCoeff
*
force
*
ky
;
forces
[
n
][
2
]
+=
2
*
recipCoeff
*
force
*
kz
;
forces
[
n
][
2
]
+=
2
*
recipCoeff
*
force
*
kz
;
...
@@ -356,37 +339,37 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -356,37 +339,37 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
if
(
!
includeDirect
)
if
(
!
includeDirect
)
return
;
return
;
RealOpenMM
totalVdwEnergy
=
0.0
f
;
double
totalVdwEnergy
=
0.0
f
;
RealOpenMM
totalRealSpaceEwaldEnergy
=
0.0
f
;
double
totalRealSpaceEwaldEnergy
=
0.0
f
;
for
(
int
i
=
0
;
i
<
(
int
)
neighborList
->
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
neighborList
->
size
();
i
++
)
{
OpenMM
::
AtomPair
pair
=
(
*
neighborList
)[
i
];
OpenMM
::
AtomPair
pair
=
(
*
neighborList
)[
i
];
int
ii
=
pair
.
first
;
int
ii
=
pair
.
first
;
int
jj
=
pair
.
second
;
int
jj
=
pair
.
second
;
RealOpenMM
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
periodicBoxVectors
,
deltaR
[
0
]);
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
periodicBoxVectors
,
deltaR
[
0
]);
RealOpenMM
r
=
deltaR
[
0
][
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
0
][
ReferenceForce
::
RIndex
];
RealOpenMM
inverseR
=
one
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
double
inverseR
=
1.0
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
RealOpenMM
switchValue
=
1
,
switchDeriv
=
0
;
double
switchValue
=
1
,
switchDeriv
=
0
;
if
(
useSwitch
&&
r
>
switchingDistance
)
{
if
(
useSwitch
&&
r
>
switchingDistance
)
{
RealOpenMM
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
double
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
}
}
RealOpenMM
alphaR
=
alphaEwald
*
r
;
double
alphaR
=
alphaEwald
*
r
;
RealOpenMM
dEdR
=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
inverseR
*
inverseR
)
;
double
dEdR
=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
inverseR
*
inverseR
;
dEdR
=
(
RealOpenMM
)
(
dEdR
*
(
erfc
(
alphaR
)
+
2
*
alphaR
*
exp
(
-
alphaR
*
alphaR
)
/
SQRT_PI
)
)
;
dEdR
=
dEdR
*
(
erfc
(
alphaR
)
+
2
*
alphaR
*
exp
(
-
alphaR
*
alphaR
)
/
SQRT_PI
);
RealOpenMM
sig
=
atomParameters
[
ii
][
SigIndex
]
+
atomParameters
[
jj
][
SigIndex
];
double
sig
=
atomParameters
[
ii
][
SigIndex
]
+
atomParameters
[
jj
][
SigIndex
];
RealOpenMM
sig2
=
inverseR
*
sig
;
double
sig2
=
inverseR
*
sig
;
sig2
*=
sig2
;
sig2
*=
sig2
;
RealOpenMM
sig6
=
sig2
*
sig2
*
sig2
;
double
sig6
=
sig2
*
sig2
*
sig2
;
RealOpenMM
eps
=
atomParameters
[
ii
][
EpsIndex
]
*
atomParameters
[
jj
][
EpsIndex
];
double
eps
=
atomParameters
[
ii
][
EpsIndex
]
*
atomParameters
[
jj
][
EpsIndex
];
dEdR
+=
switchValue
*
eps
*
(
twelve
*
sig6
-
six
)
*
sig6
*
inverseR
*
inverseR
;
dEdR
+=
switchValue
*
eps
*
(
12.0
*
sig6
-
6.0
)
*
sig6
*
inverseR
*
inverseR
;
vdwEnergy
=
eps
*
(
sig6
-
one
)
*
sig6
;
vdwEnergy
=
eps
*
(
sig6
-
1.0
)
*
sig6
;
if
(
useSwitch
)
{
if
(
useSwitch
)
{
dEdR
-=
vdwEnergy
*
switchDeriv
*
inverseR
;
dEdR
-=
vdwEnergy
*
switchDeriv
*
inverseR
;
vdwEnergy
*=
switchValue
;
vdwEnergy
*=
switchValue
;
...
@@ -395,14 +378,14 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -395,14 +378,14 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
// accumulate forces
// accumulate forces
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
RealOpenMM
force
=
dEdR
*
deltaR
[
0
][
kk
];
double
force
=
dEdR
*
deltaR
[
0
][
kk
];
forces
[
ii
][
kk
]
+=
force
;
forces
[
ii
][
kk
]
+=
force
;
forces
[
jj
][
kk
]
-=
force
;
forces
[
jj
][
kk
]
-=
force
;
}
}
// accumulate energies
// accumulate energies
realSpaceEwaldEnergy
=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
erfc
(
alphaR
)
)
;
realSpaceEwaldEnergy
=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
erfc
(
alphaR
);
totalVdwEnergy
+=
vdwEnergy
;
totalVdwEnergy
+=
vdwEnergy
;
totalRealSpaceEwaldEnergy
+=
realSpaceEwaldEnergy
;
totalRealSpaceEwaldEnergy
+=
realSpaceEwaldEnergy
;
...
@@ -419,7 +402,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -419,7 +402,7 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
// Now subtract off the exclusions, since they were implicitly included in the reciprocal space sum.
// Now subtract off the exclusions, since they were implicitly included in the reciprocal space sum.
RealOpenMM
totalExclusionEnergy
=
0.0
f
;
double
totalExclusionEnergy
=
0.0
f
;
const
double
TWO_OVER_SQRT_PI
=
2
/
sqrt
(
PI_M
);
const
double
TWO_OVER_SQRT_PI
=
2
/
sqrt
(
PI_M
);
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
for
(
set
<
int
>::
const_iterator
iter
=
exclusions
[
i
].
begin
();
iter
!=
exclusions
[
i
].
end
();
++
iter
)
{
for
(
set
<
int
>::
const_iterator
iter
=
exclusions
[
i
].
begin
();
iter
!=
exclusions
[
i
].
end
();
++
iter
)
{
...
@@ -427,29 +410,29 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -427,29 +410,29 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
int
ii
=
i
;
int
ii
=
i
;
int
jj
=
*
iter
;
int
jj
=
*
iter
;
RealOpenMM
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
deltaR
[
0
]);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
deltaR
[
0
]);
RealOpenMM
r
=
deltaR
[
0
][
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
0
][
ReferenceForce
::
RIndex
];
RealOpenMM
inverseR
=
one
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
double
inverseR
=
1.0
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
RealOpenMM
alphaR
=
alphaEwald
*
r
;
double
alphaR
=
alphaEwald
*
r
;
if
(
erf
(
alphaR
)
>
1e-6
)
{
if
(
erf
(
alphaR
)
>
1e-6
)
{
RealOpenMM
dEdR
=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
inverseR
*
inverseR
)
;
double
dEdR
=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
inverseR
*
inverseR
;
dEdR
=
(
RealOpenMM
)
(
dEdR
*
(
erf
(
alphaR
)
-
2
*
alphaR
*
exp
(
-
alphaR
*
alphaR
)
/
SQRT_PI
)
)
;
dEdR
=
dEdR
*
(
erf
(
alphaR
)
-
2
*
alphaR
*
exp
(
-
alphaR
*
alphaR
)
/
SQRT_PI
);
// accumulate forces
// accumulate forces
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
RealOpenMM
force
=
dEdR
*
deltaR
[
0
][
kk
];
double
force
=
dEdR
*
deltaR
[
0
][
kk
];
forces
[
ii
][
kk
]
-=
force
;
forces
[
ii
][
kk
]
-=
force
;
forces
[
jj
][
kk
]
+=
force
;
forces
[
jj
][
kk
]
+=
force
;
}
}
// accumulate energies
// accumulate energies
realSpaceEwaldEnergy
=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
erf
(
alphaR
)
)
;
realSpaceEwaldEnergy
=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
*
erf
(
alphaR
);
}
}
else
{
else
{
realSpaceEwaldEnergy
=
(
RealOpenMM
)
(
alphaEwald
*
TWO_OVER_SQRT_PI
*
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
)
;
realSpaceEwaldEnergy
=
alphaEwald
*
TWO_OVER_SQRT_PI
*
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
];
}
}
totalExclusionEnergy
+=
realSpaceEwaldEnergy
;
totalExclusionEnergy
+=
realSpaceEwaldEnergy
;
...
@@ -483,10 +466,10 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
...
@@ -483,10 +466,10 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<RealVec>
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
calculatePairIxn
(
int
numberOfAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
void
ReferenceLJCoulombIxn
::
calculatePairIxn
(
int
numberOfAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
vector
<
set
<
int
>
>&
exclusions
,
double
**
atomParameters
,
vector
<
set
<
int
>
>&
exclusions
,
RealOpenMM
*
fixedParameters
,
vector
<
Real
Vec
>&
forces
,
double
*
fixedParameters
,
vector
<
Vec
3
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
,
bool
includeDirect
,
bool
includeReciprocal
)
const
{
double
*
energyByAtom
,
double
*
totalEnergy
,
bool
includeDirect
,
bool
includeReciprocal
)
const
{
if
(
ewald
||
pme
)
{
if
(
ewald
||
pme
)
{
calculateEwaldIxn
(
numberOfAtoms
,
atomCoordinates
,
atomParameters
,
exclusions
,
fixedParameters
,
forces
,
energyByAtom
,
calculateEwaldIxn
(
numberOfAtoms
,
atomCoordinates
,
atomParameters
,
exclusions
,
fixedParameters
,
forces
,
energyByAtom
,
...
@@ -526,31 +509,11 @@ void ReferenceLJCoulombIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>&
...
@@ -526,31 +509,11 @@ void ReferenceLJCoulombIxn::calculatePairIxn(int numberOfAtoms, vector<RealVec>&
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLJCoulombIxn
::
calculateOneIxn
(
int
ii
,
int
jj
,
vector
<
RealVec
>&
atomCoordinates
,
void
ReferenceLJCoulombIxn
::
calculateOneIxn
(
int
ii
,
int
jj
,
vector
<
Vec3
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
vector
<
RealVec
>&
forces
,
double
**
atomParameters
,
vector
<
Vec3
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
)
const
{
double
*
energyByAtom
,
double
*
totalEnergy
)
const
{
// ---------------------------------------------------------------------------------------
static
const
std
::
string
methodName
=
"
\n
ReferenceLJCoulombIxn::calculateOneIxn"
;
// ---------------------------------------------------------------------------------------
// constants -- reduce Visual Studio warnings regarding conversions between float & double
static
const
RealOpenMM
zero
=
0.0
;
static
const
RealOpenMM
one
=
1.0
;
static
const
RealOpenMM
two
=
2.0
;
static
const
RealOpenMM
three
=
3.0
;
static
const
RealOpenMM
six
=
6.0
;
static
const
RealOpenMM
twelve
=
12.0
;
static
const
RealOpenMM
oneM
=
-
1.0
;
static
const
int
threeI
=
3
;
static
const
int
LastAtomIndex
=
2
;
RealOpenMM
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
// get deltaR, R2, and R between 2 atoms
// get deltaR, R2, and R between 2 atoms
...
@@ -559,45 +522,45 @@ void ReferenceLJCoulombIxn::calculateOneIxn(int ii, int jj, vector<RealVec>& ato
...
@@ -559,45 +522,45 @@ void ReferenceLJCoulombIxn::calculateOneIxn(int ii, int jj, vector<RealVec>& ato
else
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
deltaR
[
0
]);
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
jj
],
atomCoordinates
[
ii
],
deltaR
[
0
]);
RealOpenMM
r2
=
deltaR
[
0
][
ReferenceForce
::
R2Index
];
double
r2
=
deltaR
[
0
][
ReferenceForce
::
R2Index
];
RealOpenMM
inverseR
=
one
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
double
inverseR
=
1.0
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
RealOpenMM
switchValue
=
1
,
switchDeriv
=
0
;
double
switchValue
=
1
,
switchDeriv
=
0
;
if
(
useSwitch
)
{
if
(
useSwitch
)
{
RealOpenMM
r
=
deltaR
[
0
][
ReferenceForce
::
RIndex
];
double
r
=
deltaR
[
0
][
ReferenceForce
::
RIndex
];
if
(
r
>
switchingDistance
)
{
if
(
r
>
switchingDistance
)
{
RealOpenMM
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
double
t
=
(
r
-
switchingDistance
)
/
(
cutoffDistance
-
switchingDistance
);
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
switchValue
=
1
+
t
*
t
*
t
*
(
-
10
+
t
*
(
15
-
t
*
6
));
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
switchDeriv
=
t
*
t
*
(
-
30
+
t
*
(
60
-
t
*
30
))
/
(
cutoffDistance
-
switchingDistance
);
}
}
}
}
RealOpenMM
sig
=
atomParameters
[
ii
][
SigIndex
]
+
atomParameters
[
jj
][
SigIndex
];
double
sig
=
atomParameters
[
ii
][
SigIndex
]
+
atomParameters
[
jj
][
SigIndex
];
RealOpenMM
sig2
=
inverseR
*
sig
;
double
sig2
=
inverseR
*
sig
;
sig2
*=
sig2
;
sig2
*=
sig2
;
RealOpenMM
sig6
=
sig2
*
sig2
*
sig2
;
double
sig6
=
sig2
*
sig2
*
sig2
;
RealOpenMM
eps
=
atomParameters
[
ii
][
EpsIndex
]
*
atomParameters
[
jj
][
EpsIndex
];
double
eps
=
atomParameters
[
ii
][
EpsIndex
]
*
atomParameters
[
jj
][
EpsIndex
];
RealOpenMM
dEdR
=
switchValue
*
eps
*
(
twelve
*
sig6
-
six
)
*
sig6
;
double
dEdR
=
switchValue
*
eps
*
(
12.0
*
sig6
-
6.0
)
*
sig6
;
if
(
cutoff
)
if
(
cutoff
)
dEdR
+=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
(
inverseR
-
2.0
f
*
krf
*
r2
)
)
;
dEdR
+=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
(
inverseR
-
2.0
f
*
krf
*
r2
);
else
else
dEdR
+=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
)
;
dEdR
+=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
;
dEdR
*=
inverseR
*
inverseR
;
dEdR
*=
inverseR
*
inverseR
;
RealOpenMM
energy
=
eps
*
(
sig6
-
one
)
*
sig6
;
double
energy
=
eps
*
(
sig6
-
1.0
)
*
sig6
;
if
(
useSwitch
)
{
if
(
useSwitch
)
{
dEdR
-=
energy
*
switchDeriv
*
inverseR
;
dEdR
-=
energy
*
switchDeriv
*
inverseR
;
energy
*=
switchValue
;
energy
*=
switchValue
;
}
}
if
(
cutoff
)
if
(
cutoff
)
energy
+=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
(
inverseR
+
krf
*
r2
-
crf
)
)
;
energy
+=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
(
inverseR
+
krf
*
r2
-
crf
);
else
else
energy
+=
(
RealOpenMM
)
(
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
)
;
energy
+=
ONE_4PI_EPS0
*
atomParameters
[
ii
][
QIndex
]
*
atomParameters
[
jj
][
QIndex
]
*
inverseR
;
// accumulate forces
// accumulate forces
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
for
(
int
kk
=
0
;
kk
<
3
;
kk
++
)
{
RealOpenMM
force
=
dEdR
*
deltaR
[
0
][
kk
];
double
force
=
dEdR
*
deltaR
[
0
][
kk
];
forces
[
ii
][
kk
]
+=
force
;
forces
[
ii
][
kk
]
+=
force
;
forces
[
jj
][
kk
]
-=
force
;
forces
[
jj
][
kk
]
-=
force
;
}
}
// accumulate energies
// accumulate energies
...
...
platforms/reference/src/SimTKReference/ReferenceLincsAlgorithm.cpp
View file @
a783b996
...
@@ -44,13 +44,7 @@ using namespace OpenMM;
...
@@ -44,13 +44,7 @@ using namespace OpenMM;
ReferenceLincsAlgorithm
::
ReferenceLincsAlgorithm
(
int
numberOfConstraints
,
ReferenceLincsAlgorithm
::
ReferenceLincsAlgorithm
(
int
numberOfConstraints
,
int
**
atomIndices
,
int
**
atomIndices
,
RealOpenMM
*
distance
)
{
double
*
distance
)
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLincsAlgorithm::ReferenceLincsAlgorithm";
// ---------------------------------------------------------------------------------------
_numberOfConstraints
=
numberOfConstraints
;
_numberOfConstraints
=
numberOfConstraints
;
_atomIndices
=
atomIndices
;
_atomIndices
=
atomIndices
;
...
@@ -69,13 +63,6 @@ ReferenceLincsAlgorithm::ReferenceLincsAlgorithm(int numberOfConstraints,
...
@@ -69,13 +63,6 @@ ReferenceLincsAlgorithm::ReferenceLincsAlgorithm(int numberOfConstraints,
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
int
ReferenceLincsAlgorithm
::
getNumberOfConstraints
()
const
{
int
ReferenceLincsAlgorithm
::
getNumberOfConstraints
()
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLincsAlgorithm::getNumberOfConstraints";
// ---------------------------------------------------------------------------------------
return
_numberOfConstraints
;
return
_numberOfConstraints
;
}
}
...
@@ -88,13 +75,6 @@ int ReferenceLincsAlgorithm::getNumberOfConstraints() const {
...
@@ -88,13 +75,6 @@ int ReferenceLincsAlgorithm::getNumberOfConstraints() const {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
int
ReferenceLincsAlgorithm
::
getNumTerms
()
const
{
int
ReferenceLincsAlgorithm
::
getNumTerms
()
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLincsAlgorithm::getNumTerms";
// ---------------------------------------------------------------------------------------
return
_numTerms
;
return
_numTerms
;
}
}
...
@@ -105,13 +85,6 @@ int ReferenceLincsAlgorithm::getNumTerms() const {
...
@@ -105,13 +85,6 @@ int ReferenceLincsAlgorithm::getNumTerms() const {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLincsAlgorithm
::
setNumTerms
(
int
terms
)
{
void
ReferenceLincsAlgorithm
::
setNumTerms
(
int
terms
)
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceLincsAlgorithm::setNumTerms";
// ---------------------------------------------------------------------------------------
_numTerms
=
terms
;
_numTerms
=
terms
;
}
}
...
@@ -125,8 +98,7 @@ void ReferenceLincsAlgorithm::setNumTerms(int terms) {
...
@@ -125,8 +98,7 @@ void ReferenceLincsAlgorithm::setNumTerms(int terms) {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLincsAlgorithm
::
initialize
(
int
numberOfAtoms
,
vector
<
RealOpenMM
>&
inverseMasses
)
{
void
ReferenceLincsAlgorithm
::
initialize
(
int
numberOfAtoms
,
vector
<
double
>&
inverseMasses
)
{
static
const
RealOpenMM
one
=
1.0
;
_hasInitialized
=
true
;
_hasInitialized
=
true
;
vector
<
vector
<
int
>
>
atomConstraints
(
numberOfAtoms
);
vector
<
vector
<
int
>
>
atomConstraints
(
numberOfAtoms
);
for
(
int
constraint
=
0
;
constraint
<
_numberOfConstraints
;
constraint
++
)
{
for
(
int
constraint
=
0
;
constraint
<
_numberOfConstraints
;
constraint
++
)
{
...
@@ -145,7 +117,7 @@ void ReferenceLincsAlgorithm::initialize(int numberOfAtoms, vector<RealOpenMM>&
...
@@ -145,7 +117,7 @@ void ReferenceLincsAlgorithm::initialize(int numberOfAtoms, vector<RealOpenMM>&
}
}
_sMatrix
.
resize
(
_numberOfConstraints
);
_sMatrix
.
resize
(
_numberOfConstraints
);
for
(
int
constraint
=
0
;
constraint
<
_numberOfConstraints
;
constraint
++
)
for
(
int
constraint
=
0
;
constraint
<
_numberOfConstraints
;
constraint
++
)
_sMatrix
[
constraint
]
=
one
/
SQRT
(
inverseMasses
[
_atomIndices
[
constraint
][
0
]]
+
inverseMasses
[
_atomIndices
[
constraint
][
1
]]);
_sMatrix
[
constraint
]
=
1.0
/
sqrt
(
inverseMasses
[
_atomIndices
[
constraint
][
0
]]
+
inverseMasses
[
_atomIndices
[
constraint
][
1
]]);
_couplingMatrix
.
resize
(
_numberOfConstraints
);
_couplingMatrix
.
resize
(
_numberOfConstraints
);
for
(
int
constraint
=
0
;
constraint
<
_numberOfConstraints
;
constraint
++
)
for
(
int
constraint
=
0
;
constraint
<
_numberOfConstraints
;
constraint
++
)
_couplingMatrix
[
constraint
].
resize
(
_linkedConstraints
[
constraint
].
size
());
_couplingMatrix
[
constraint
].
resize
(
_linkedConstraints
[
constraint
].
size
());
...
@@ -162,12 +134,11 @@ void ReferenceLincsAlgorithm::initialize(int numberOfAtoms, vector<RealOpenMM>&
...
@@ -162,12 +134,11 @@ void ReferenceLincsAlgorithm::initialize(int numberOfAtoms, vector<RealOpenMM>&
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLincsAlgorithm
::
solveMatrix
()
{
void
ReferenceLincsAlgorithm
::
solveMatrix
()
{
static
const
RealOpenMM
zero
=
0.0
;
for
(
int
iteration
=
0
;
iteration
<
_numTerms
;
iteration
++
)
{
for
(
int
iteration
=
0
;
iteration
<
_numTerms
;
iteration
++
)
{
vector
<
RealOpenMM
>&
rhs1
=
(
iteration
%
2
==
0
?
_rhs1
:
_rhs2
);
vector
<
double
>&
rhs1
=
(
iteration
%
2
==
0
?
_rhs1
:
_rhs2
);
vector
<
RealOpenMM
>&
rhs2
=
(
iteration
%
2
==
0
?
_rhs2
:
_rhs1
);
vector
<
double
>&
rhs2
=
(
iteration
%
2
==
0
?
_rhs2
:
_rhs1
);
for
(
int
c1
=
0
;
c1
<
_numberOfConstraints
;
c1
++
)
{
for
(
int
c1
=
0
;
c1
<
_numberOfConstraints
;
c1
++
)
{
rhs2
[
c1
]
=
zero
;
rhs2
[
c1
]
=
0.0
;
for
(
int
j
=
0
;
j
<
(
int
)
_linkedConstraints
[
c1
].
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
_linkedConstraints
[
c1
].
size
();
j
++
)
{
int
c2
=
_linkedConstraints
[
c1
][
j
];
int
c2
=
_linkedConstraints
[
c1
][
j
];
rhs2
[
c1
]
+=
_couplingMatrix
[
c1
][
j
]
*
rhs1
[
c2
];
rhs2
[
c1
]
+=
_couplingMatrix
[
c1
][
j
]
*
rhs1
[
c2
];
...
@@ -187,19 +158,19 @@ void ReferenceLincsAlgorithm::solveMatrix() {
...
@@ -187,19 +158,19 @@ void ReferenceLincsAlgorithm::solveMatrix() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLincsAlgorithm
::
updateAtomPositions
(
int
numberOfAtoms
,
vector
<
Real
Vec
>&
atomCoordinates
,
vector
<
RealOpenMM
>&
inverseMasses
)
{
void
ReferenceLincsAlgorithm
::
updateAtomPositions
(
int
numberOfAtoms
,
vector
<
Vec
3
>&
atomCoordinates
,
vector
<
double
>&
inverseMasses
)
{
for
(
int
i
=
0
;
i
<
_numberOfConstraints
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_numberOfConstraints
;
i
++
)
{
Real
Vec
delta
(
_sMatrix
[
i
]
*
_solution
[
i
]
*
_constraintDir
[
i
][
0
],
Vec
3
delta
(
_sMatrix
[
i
]
*
_solution
[
i
]
*
_constraintDir
[
i
][
0
],
_sMatrix
[
i
]
*
_solution
[
i
]
*
_constraintDir
[
i
][
1
],
_sMatrix
[
i
]
*
_solution
[
i
]
*
_constraintDir
[
i
][
1
],
_sMatrix
[
i
]
*
_solution
[
i
]
*
_constraintDir
[
i
][
2
]);
_sMatrix
[
i
]
*
_solution
[
i
]
*
_constraintDir
[
i
][
2
]);
int
atom1
=
_atomIndices
[
i
][
0
];
int
atom1
=
_atomIndices
[
i
][
0
];
int
atom2
=
_atomIndices
[
i
][
1
];
int
atom2
=
_atomIndices
[
i
][
1
];
atomCoordinates
[
atom1
][
0
]
-=
(
RealOpenMM
)(
inverseMasses
[
atom1
]
*
delta
[
0
]
)
;
atomCoordinates
[
atom1
][
0
]
-=
inverseMasses
[
atom1
]
*
delta
[
0
];
atomCoordinates
[
atom1
][
1
]
-=
(
RealOpenMM
)(
inverseMasses
[
atom1
]
*
delta
[
1
]
)
;
atomCoordinates
[
atom1
][
1
]
-=
inverseMasses
[
atom1
]
*
delta
[
1
];
atomCoordinates
[
atom1
][
2
]
-=
(
RealOpenMM
)(
inverseMasses
[
atom1
]
*
delta
[
2
]
)
;
atomCoordinates
[
atom1
][
2
]
-=
inverseMasses
[
atom1
]
*
delta
[
2
];
atomCoordinates
[
atom2
][
0
]
+=
(
RealOpenMM
)(
inverseMasses
[
atom2
]
*
delta
[
0
]
)
;
atomCoordinates
[
atom2
][
0
]
+=
inverseMasses
[
atom2
]
*
delta
[
0
];
atomCoordinates
[
atom2
][
1
]
+=
(
RealOpenMM
)(
inverseMasses
[
atom2
]
*
delta
[
1
]
)
;
atomCoordinates
[
atom2
][
1
]
+=
inverseMasses
[
atom2
]
*
delta
[
1
];
atomCoordinates
[
atom2
][
2
]
+=
(
RealOpenMM
)(
inverseMasses
[
atom2
]
*
delta
[
2
]
)
;
atomCoordinates
[
atom2
][
2
]
+=
inverseMasses
[
atom2
]
*
delta
[
2
];
}
}
}
}
...
@@ -214,19 +185,9 @@ void ReferenceLincsAlgorithm::updateAtomPositions(int numberOfAtoms, vector<Real
...
@@ -214,19 +185,9 @@ void ReferenceLincsAlgorithm::updateAtomPositions(int numberOfAtoms, vector<Real
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLincsAlgorithm
::
apply
(
int
numberOfAtoms
,
vector
<
RealVec
>&
atomCoordinates
,
void
ReferenceLincsAlgorithm
::
apply
(
int
numberOfAtoms
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
RealVec
>&
atomCoordinatesP
,
vector
<
Vec3
>&
atomCoordinatesP
,
vector
<
RealOpenMM
>&
inverseMasses
)
{
vector
<
double
>&
inverseMasses
)
{
// ---------------------------------------------------------------------------------------
static
const
char
*
methodName
=
"
\n
ReferenceLincsAlgorithm::apply"
;
static
const
RealOpenMM
zero
=
0.0
;
static
const
RealOpenMM
one
=
1.0
;
static
const
RealOpenMM
two
=
2.0
;
// ---------------------------------------------------------------------------------------
if
(
_numberOfConstraints
==
0
)
if
(
_numberOfConstraints
==
0
)
return
;
return
;
...
@@ -239,27 +200,27 @@ void ReferenceLincsAlgorithm::apply(int numberOfAtoms, vector<RealVec>& atomCoor
...
@@ -239,27 +200,27 @@ void ReferenceLincsAlgorithm::apply(int numberOfAtoms, vector<RealVec>& atomCoor
for
(
int
i
=
0
;
i
<
_numberOfConstraints
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_numberOfConstraints
;
i
++
)
{
int
atom1
=
_atomIndices
[
i
][
0
];
int
atom1
=
_atomIndices
[
i
][
0
];
int
atom2
=
_atomIndices
[
i
][
1
];
int
atom2
=
_atomIndices
[
i
][
1
];
_constraintDir
[
i
]
=
Real
Vec
(
atomCoordinatesP
[
atom1
][
0
]
-
atomCoordinatesP
[
atom2
][
0
],
_constraintDir
[
i
]
=
Vec
3
(
atomCoordinatesP
[
atom1
][
0
]
-
atomCoordinatesP
[
atom2
][
0
],
atomCoordinatesP
[
atom1
][
1
]
-
atomCoordinatesP
[
atom2
][
1
],
atomCoordinatesP
[
atom1
][
1
]
-
atomCoordinatesP
[
atom2
][
1
],
atomCoordinatesP
[
atom1
][
2
]
-
atomCoordinatesP
[
atom2
][
2
]);
atomCoordinatesP
[
atom1
][
2
]
-
atomCoordinatesP
[
atom2
][
2
]);
RealOpenMM
invLength
=
(
RealOpenMM
)(
1
/
SQRT
((
RealOpenMM
)
_constraintDir
[
i
].
dot
(
_constraintDir
[
i
]))
)
;
double
invLength
=
1
/
sqrt
(
_constraintDir
[
i
].
dot
(
_constraintDir
[
i
]));
_constraintDir
[
i
][
0
]
*=
invLength
;
_constraintDir
[
i
][
0
]
*=
invLength
;
_constraintDir
[
i
][
1
]
*=
invLength
;
_constraintDir
[
i
][
1
]
*=
invLength
;
_constraintDir
[
i
][
2
]
*=
invLength
;
_constraintDir
[
i
][
2
]
*=
invLength
;
_rhs1
[
i
]
=
_solution
[
i
]
=
_sMatrix
[
i
]
*
(
one
/
invLength
-
_distance
[
i
]);
_rhs1
[
i
]
=
_solution
[
i
]
=
_sMatrix
[
i
]
*
(
1.0
/
invLength
-
_distance
[
i
]);
}
}
// Build the coupling matrix.
// Build the coupling matrix.
for
(
int
c1
=
0
;
c1
<
(
int
)
_couplingMatrix
.
size
();
c1
++
)
{
for
(
int
c1
=
0
;
c1
<
(
int
)
_couplingMatrix
.
size
();
c1
++
)
{
Real
Vec
&
dir1
=
_constraintDir
[
c1
];
Vec
3
&
dir1
=
_constraintDir
[
c1
];
for
(
int
j
=
0
;
j
<
(
int
)
_couplingMatrix
[
c1
].
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
_couplingMatrix
[
c1
].
size
();
j
++
)
{
int
c2
=
_linkedConstraints
[
c1
][
j
];
int
c2
=
_linkedConstraints
[
c1
][
j
];
Real
Vec
&
dir2
=
_constraintDir
[
c2
];
Vec
3
&
dir2
=
_constraintDir
[
c2
];
if
(
_atomIndices
[
c1
][
0
]
==
_atomIndices
[
c2
][
0
]
||
_atomIndices
[
c1
][
1
]
==
_atomIndices
[
c2
][
1
])
if
(
_atomIndices
[
c1
][
0
]
==
_atomIndices
[
c2
][
0
]
||
_atomIndices
[
c1
][
1
]
==
_atomIndices
[
c2
][
1
])
_couplingMatrix
[
c1
][
j
]
=
(
RealOpenMM
)(
-
inverseMasses
[
_atomIndices
[
c1
][
0
]]
*
_sMatrix
[
c1
]
*
dir1
.
dot
(
dir2
)
*
_sMatrix
[
c2
]
)
;
_couplingMatrix
[
c1
][
j
]
=
-
inverseMasses
[
_atomIndices
[
c1
][
0
]]
*
_sMatrix
[
c1
]
*
dir1
.
dot
(
dir2
)
*
_sMatrix
[
c2
];
else
else
_couplingMatrix
[
c1
][
j
]
=
(
RealOpenMM
)(
inverseMasses
[
_atomIndices
[
c1
][
1
]]
*
_sMatrix
[
c1
]
*
dir1
.
dot
(
dir2
)
*
_sMatrix
[
c2
]
)
;
_couplingMatrix
[
c1
][
j
]
=
inverseMasses
[
_atomIndices
[
c1
][
1
]]
*
_sMatrix
[
c1
]
*
dir1
.
dot
(
dir2
)
*
_sMatrix
[
c2
];
}
}
}
}
...
@@ -273,13 +234,13 @@ void ReferenceLincsAlgorithm::apply(int numberOfAtoms, vector<RealVec>& atomCoor
...
@@ -273,13 +234,13 @@ void ReferenceLincsAlgorithm::apply(int numberOfAtoms, vector<RealVec>& atomCoor
for
(
int
i
=
0
;
i
<
_numberOfConstraints
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_numberOfConstraints
;
i
++
)
{
int
atom1
=
_atomIndices
[
i
][
0
];
int
atom1
=
_atomIndices
[
i
][
0
];
int
atom2
=
_atomIndices
[
i
][
1
];
int
atom2
=
_atomIndices
[
i
][
1
];
Real
Vec
delta
(
atomCoordinatesP
[
atom1
][
0
]
-
atomCoordinatesP
[
atom2
][
0
],
Vec
3
delta
(
atomCoordinatesP
[
atom1
][
0
]
-
atomCoordinatesP
[
atom2
][
0
],
atomCoordinatesP
[
atom1
][
1
]
-
atomCoordinatesP
[
atom2
][
1
],
atomCoordinatesP
[
atom1
][
1
]
-
atomCoordinatesP
[
atom2
][
1
],
atomCoordinatesP
[
atom1
][
2
]
-
atomCoordinatesP
[
atom2
][
2
]);
atomCoordinatesP
[
atom1
][
2
]
-
atomCoordinatesP
[
atom2
][
2
]);
RealOpenMM
p2
=
(
RealOpenMM
)(
two
*
_distance
[
i
]
*
_distance
[
i
]
-
delta
.
dot
(
delta
)
)
;
double
p2
=
2.0
*
_distance
[
i
]
*
_distance
[
i
]
-
delta
.
dot
(
delta
);
if
(
p2
<
zero
)
if
(
p2
<
0.0
)
p2
=
zero
;
p2
=
0.0
;
_rhs1
[
i
]
=
_solution
[
i
]
=
_sMatrix
[
i
]
*
(
_distance
[
i
]
-
SQRT
(
p2
));
_rhs1
[
i
]
=
_solution
[
i
]
=
_sMatrix
[
i
]
*
(
_distance
[
i
]
-
sqrt
(
p2
));
}
}
solveMatrix
();
solveMatrix
();
updateAtomPositions
(
numberOfAtoms
,
atomCoordinatesP
,
inverseMasses
);
updateAtomPositions
(
numberOfAtoms
,
atomCoordinatesP
,
inverseMasses
);
...
@@ -296,7 +257,7 @@ void ReferenceLincsAlgorithm::apply(int numberOfAtoms, vector<RealVec>& atomCoor
...
@@ -296,7 +257,7 @@ void ReferenceLincsAlgorithm::apply(int numberOfAtoms, vector<RealVec>& atomCoor
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceLincsAlgorithm
::
applyToVelocities
(
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
Real
Vec
>&
atomCoordinates
,
void
ReferenceLincsAlgorithm
::
applyToVelocities
(
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
Vec
3
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
Real
Vec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
)
{
std
::
vector
<
OpenMM
::
Vec
3
>&
velocities
,
std
::
vector
<
double
>&
inverseMasses
)
{
throw
OpenMM
::
OpenMMException
(
"applyToVelocities is not implemented"
);
throw
OpenMM
::
OpenMMException
(
"applyToVelocities is not implemented"
);
}
}
platforms/reference/src/SimTKReference/ReferenceMonteCarloBarostat.cpp
View file @
a783b996
...
@@ -64,7 +64,7 @@ ReferenceMonteCarloBarostat::~ReferenceMonteCarloBarostat() {
...
@@ -64,7 +64,7 @@ ReferenceMonteCarloBarostat::~ReferenceMonteCarloBarostat() {
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceMonteCarloBarostat
::
applyBarostat
(
vector
<
Real
Vec
>&
atomPositions
,
const
Real
Vec
*
boxVectors
,
RealOpenMM
scaleX
,
RealOpenMM
scaleY
,
RealOpenMM
scaleZ
)
{
void
ReferenceMonteCarloBarostat
::
applyBarostat
(
vector
<
Vec
3
>&
atomPositions
,
const
Vec
3
*
boxVectors
,
double
scaleX
,
double
scaleY
,
double
scaleZ
)
{
int
numAtoms
=
savedAtomPositions
[
0
].
size
();
int
numAtoms
=
savedAtomPositions
[
0
].
size
();
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
...
@@ -75,16 +75,16 @@ void ReferenceMonteCarloBarostat::applyBarostat(vector<RealVec>& atomPositions,
...
@@ -75,16 +75,16 @@ void ReferenceMonteCarloBarostat::applyBarostat(vector<RealVec>& atomPositions,
for
(
int
i
=
0
;
i
<
(
int
)
molecules
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
molecules
.
size
();
i
++
)
{
// Find the molecule center.
// Find the molecule center.
Real
Vec
pos
(
0
,
0
,
0
);
Vec
3
pos
(
0
,
0
,
0
);
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
{
Real
Vec
&
atomPos
=
atomPositions
[
molecules
[
i
][
j
]];
Vec
3
&
atomPos
=
atomPositions
[
molecules
[
i
][
j
]];
pos
+=
atomPos
;
pos
+=
atomPos
;
}
}
pos
/=
molecules
[
i
].
size
();
pos
/=
molecules
[
i
].
size
();
// Move it into the first periodic box.
// Move it into the first periodic box.
Real
Vec
newPos
=
pos
;
Vec
3
newPos
=
pos
;
newPos
-=
boxVectors
[
2
]
*
floor
(
newPos
[
2
]
/
boxVectors
[
2
][
2
]);
newPos
-=
boxVectors
[
2
]
*
floor
(
newPos
[
2
]
/
boxVectors
[
2
][
2
]);
newPos
-=
boxVectors
[
1
]
*
floor
(
newPos
[
1
]
/
boxVectors
[
1
][
1
]);
newPos
-=
boxVectors
[
1
]
*
floor
(
newPos
[
1
]
/
boxVectors
[
1
][
1
]);
newPos
-=
boxVectors
[
0
]
*
floor
(
newPos
[
0
]
/
boxVectors
[
0
][
0
]);
newPos
-=
boxVectors
[
0
]
*
floor
(
newPos
[
0
]
/
boxVectors
[
0
][
0
]);
...
@@ -94,9 +94,9 @@ void ReferenceMonteCarloBarostat::applyBarostat(vector<RealVec>& atomPositions,
...
@@ -94,9 +94,9 @@ void ReferenceMonteCarloBarostat::applyBarostat(vector<RealVec>& atomPositions,
newPos
[
0
]
*=
scaleX
;
newPos
[
0
]
*=
scaleX
;
newPos
[
1
]
*=
scaleY
;
newPos
[
1
]
*=
scaleY
;
newPos
[
2
]
*=
scaleZ
;
newPos
[
2
]
*=
scaleZ
;
Real
Vec
offset
=
newPos
-
pos
;
Vec
3
offset
=
newPos
-
pos
;
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
{
Real
Vec
&
atomPos
=
atomPositions
[
molecules
[
i
][
j
]];
Vec
3
&
atomPos
=
atomPositions
[
molecules
[
i
][
j
]];
atomPos
+=
offset
;
atomPos
+=
offset
;
}
}
}
}
...
@@ -110,7 +110,7 @@ void ReferenceMonteCarloBarostat::applyBarostat(vector<RealVec>& atomPositions,
...
@@ -110,7 +110,7 @@ void ReferenceMonteCarloBarostat::applyBarostat(vector<RealVec>& atomPositions,
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
void
ReferenceMonteCarloBarostat
::
restorePositions
(
vector
<
Real
Vec
>&
atomPositions
)
{
void
ReferenceMonteCarloBarostat
::
restorePositions
(
vector
<
Vec
3
>&
atomPositions
)
{
int
numAtoms
=
savedAtomPositions
[
0
].
size
();
int
numAtoms
=
savedAtomPositions
[
0
].
size
();
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
for
(
int
i
=
0
;
i
<
numAtoms
;
i
++
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
for
(
int
j
=
0
;
j
<
3
;
j
++
)
...
...
Prev
1
2
3
4
5
6
7
8
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