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
9dd055eb
Commit
9dd055eb
authored
Oct 06, 2011
by
Mark Friedrichs
Browse files
Add unit test for NonbondedSoftcoreForce
Cleanup code associated w/ NonbondedSoftcoreForce
parent
ab60bff4
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
337 additions
and
721 deletions
+337
-721
plugins/freeEnergy/platforms/reference/src/ReferenceFreeEnergyKernels.cpp
...gy/platforms/reference/src/ReferenceFreeEnergyKernels.cpp
+6
-46
plugins/freeEnergy/platforms/reference/src/SimTKReference/ReferenceFreeEnergyLJCoulomb14Softcore.cpp
...SimTKReference/ReferenceFreeEnergyLJCoulomb14Softcore.cpp
+4
-6
plugins/freeEnergy/platforms/reference/src/SimTKReference/ReferenceFreeEnergyLJCoulombSoftcoreIxn.cpp
...imTKReference/ReferenceFreeEnergyLJCoulombSoftcoreIxn.cpp
+24
-571
plugins/freeEnergy/platforms/reference/src/SimTKReference/ReferenceFreeEnergyLJCoulombSoftcoreIxn.h
.../SimTKReference/ReferenceFreeEnergyLJCoulombSoftcoreIxn.h
+8
-92
plugins/freeEnergy/platforms/reference/tests/TestReferenceLJSoftcoreForce.cpp
...latforms/reference/tests/TestReferenceLJSoftcoreForce.cpp
+290
-0
plugins/freeEnergy/platforms/reference/tests/TestReferenceOBCSoftcoreForce.cpp
...atforms/reference/tests/TestReferenceOBCSoftcoreForce.cpp
+5
-6
No files found.
plugins/freeEnergy/platforms/reference/src/ReferenceFreeEnergyKernels.cpp
View file @
9dd055eb
...
...
@@ -155,7 +155,6 @@ void ReferenceFreeEnergyCalcNonbondedSoftcoreForceKernel::initialize(const Syste
nonbondedMethod
=
CalcNonbondedSoftcoreForceKernel
::
NonbondedSoftcoreMethod
(
force
.
getNonbondedMethod
());
nonbondedCutoff
=
(
RealOpenMM
)
force
.
getCutoffDistance
();
//softCoreLJLambda = (RealOpenMM) force.getSoftCoreLJLambda();
Vec3
boxVectors
[
3
];
system
.
getDefaultPeriodicBoxVectors
(
boxVectors
[
0
],
boxVectors
[
1
],
boxVectors
[
2
]);
...
...
@@ -168,42 +167,6 @@ void ReferenceFreeEnergyCalcNonbondedSoftcoreForceKernel::initialize(const Syste
else
neighborList
=
new
NeighborList
();
#if 0
if (nonbondedMethod == Ewald || nonbondedMethod == PME) {
RealOpenMM ewaldErrorTol = (RealOpenMM) force.getEwaldErrorTolerance();
ewaldAlpha = (RealOpenMM) (std::sqrt(-std::log(ewaldErrorTol))/nonbondedCutoff);
RealOpenMM mx = periodicBoxSize[0]/nonbondedCutoff;
RealOpenMM my = periodicBoxSize[1]/nonbondedCutoff;
RealOpenMM mz = periodicBoxSize[2]/nonbondedCutoff;
RealOpenMM pi = (RealOpenMM) 3.1415926535897932385;
kmax[0] = (int)std::ceil(-(mx/pi)*std::log(ewaldErrorTol));
kmax[1] = (int)std::ceil(-(my/pi)*std::log(ewaldErrorTol));
kmax[2] = (int)std::ceil(-(mz/pi)*std::log(ewaldErrorTol));
if (kmax[0]%2 == 0)
kmax[0]++;
if (kmax[1]%2 == 0)
kmax[1]++;
if (kmax[2]%2 == 0)
kmax[2]++;
}
if (nonbondedMethod == Ewald || nonbondedMethod == PME) {
RealOpenMM ewaldErrorTol = (RealOpenMM) force.getEwaldErrorTolerance();
ewaldAlpha = (RealOpenMM) (std::sqrt(-std::log(ewaldErrorTol))/nonbondedCutoff);
RealOpenMM mx = periodicBoxSize[0]/nonbondedCutoff;
RealOpenMM my = periodicBoxSize[1]/nonbondedCutoff;
RealOpenMM mz = periodicBoxSize[2]/nonbondedCutoff;
RealOpenMM pi = (RealOpenMM) 3.1415926535897932385;
kmax[0] = (int)std::ceil(-(mx/pi)*std::log(ewaldErrorTol));
kmax[1] = (int)std::ceil(-(my/pi)*std::log(ewaldErrorTol));
kmax[2] = (int)std::ceil(-(mz/pi)*std::log(ewaldErrorTol));
if (kmax[0]%2 == 0)
kmax[0]++;
if (kmax[1]%2 == 0)
kmax[1]++;
if (kmax[2]%2 == 0)
kmax[2]++;
}
#endif
rfDielectric
=
(
RealOpenMM
)
force
.
getReactionFieldDielectric
();
}
...
...
@@ -214,21 +177,18 @@ double ReferenceFreeEnergyCalcNonbondedSoftcoreForceKernel::execute(ContextImpl&
RealOpenMM
energy
=
0
;
ReferenceFreeEnergyLJCoulombSoftcoreIxn
clj
;
// clj.setSoftCoreLJLambda( softCoreLJLambda );
bool
periodic
=
(
nonbondedMethod
==
CutoffPeriodic
);
bool
ewald
=
(
nonbondedMethod
==
Ewald
);
bool
pme
=
(
nonbondedMethod
==
PME
);
if
(
nonbondedMethod
!=
NoCutoff
)
{
computeNeighborListVoxelHash
(
*
neighborList
,
numParticles
,
posData
,
exclusions
,
periodicBoxSize
,
periodic
||
ewald
||
pme
,
nonbondedCutoff
,
0.0
);
computeNeighborListVoxelHash
(
*
neighborList
,
numParticles
,
posData
,
exclusions
,
periodicBoxSize
,
periodic
,
nonbondedCutoff
,
0.0
);
clj
.
setUseCutoff
(
nonbondedCutoff
,
*
neighborList
,
rfDielectric
);
}
if
(
periodic
||
ewald
||
pme
)
if
(
periodic
)
clj
.
setPeriodic
(
periodicBoxSize
);
if
(
ewald
)
clj
.
setUseEwald
(
ewaldAlpha
,
kmax
[
0
],
kmax
[
1
],
kmax
[
2
]);
if
(
pme
)
clj
.
setUsePME
(
ewaldAlpha
);
clj
.
calculatePairIxn
(
numParticles
,
posData
,
particleParamArray
,
exclusionArray
,
0
,
forceData
,
0
,
&
energy
);
ReferenceBondForce
refBondForce
;
ReferenceFreeEnergyLJCoulomb14Softcore
nonbonded14
;
if
(
nonbondedMethod
==
CutoffNonPeriodic
||
nonbondedMethod
==
CutoffPeriodic
)
...
...
plugins/freeEnergy/platforms/reference/src/SimTKReference/ReferenceFreeEnergyLJCoulomb14Softcore.cpp
View file @
9dd055eb
...
...
@@ -100,13 +100,11 @@ ReferenceFreeEnergyLJCoulomb14Softcore::~ReferenceFreeEnergyLJCoulomb14Softcore(
--------------------------------------------------------------------------------------- */
void
ReferenceFreeEnergyLJCoulomb14Softcore
::
getDerivedParameters
(
RealOpenMM
c6
,
RealOpenMM
c12
,
RealOpenMM
q1
,
RealOpenMM
q2
,
RealOpenMM
epsfac
,
RealOpenMM
*
parameters
)
const
{
RealOpenMM
q2
,
RealOpenMM
epsfac
,
RealOpenMM
*
parameters
)
const
{
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceFreeEnergyLJCoulomb14Softcore::getDerivedParameters";
static
const
RealOpenMM
zero
=
0.0
;
static
const
RealOpenMM
one
=
1.0
;
static
const
RealOpenMM
six
=
6.0
;
...
...
@@ -218,7 +216,7 @@ void ReferenceFreeEnergyLJCoulomb14Softcore::calculateBondIxn( int* atomIndices,
*
totalEnergy
+=
energy
;
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
Calculate LJ pair ixn between two atoms
...
...
@@ -231,7 +229,7 @@ void ReferenceFreeEnergyLJCoulomb14Softcore::calculateBondIxn( int* atomIndices,
--------------------------------------------------------------------------------------- */
void
ReferenceFreeEnergyLJCoulomb14Softcore
::
calculateOneLJ14Ixn
(
RealOpenMM
inverseR
,
RealOpenMM
sig
,
RealOpenMM
eps
,
RealOpenMM
*
dEdR
,
RealOpenMM
*
energy
)
const
{
RealOpenMM
*
dEdR
,
RealOpenMM
*
energy
)
const
{
// ---------------------------------------------------------------------------------------
...
...
plugins/freeEnergy/platforms/reference/src/SimTKReference/ReferenceFreeEnergyLJCoulombSoftcoreIxn.cpp
View file @
9dd055eb
This diff is collapsed.
Click to expand it.
plugins/freeEnergy/platforms/reference/src/SimTKReference/ReferenceFreeEnergyLJCoulombSoftcoreIxn.h
View file @
9dd055eb
...
...
@@ -42,7 +42,6 @@ class ReferenceFreeEnergyLJCoulombSoftcoreIxn : public ReferencePairIxn {
RealOpenMM
periodicBoxSize
[
3
];
RealOpenMM
cutoffDistance
;
RealOpenMM
krf
,
crf
;
RealOpenMM
softCoreLJLambda
;
int
numRx
,
numRy
,
numRz
;
RealOpenMM
alphaEwald
;
...
...
@@ -62,15 +61,13 @@ class ReferenceFreeEnergyLJCoulombSoftcoreIxn : public ReferencePairIxn {
@param atomCoordinates atom coordinates
@param atomParameters atom parameters (charges, c6, c12, ...) atomParameters[atomIndex][paramterIndex]
@param forces force array (forces added)
@param energyByAtom atom energy
@param totalEnergy total energy
--------------------------------------------------------------------------------------- */
void
calculateOneIxn
(
int
atom1
,
int
atom2
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
*
totalEnergy
)
const
;
public:
...
...
@@ -116,41 +113,7 @@ class ReferenceFreeEnergyLJCoulombSoftcoreIxn : public ReferencePairIxn {
/**---------------------------------------------------------------------------------------
Set the force to use Ewald summation.
@param alpha the Ewald separation parameter
@param kmaxx the largest wave vector in the x direction
@param kmaxy the largest wave vector in the y direction
@param kmaxz the largest wave vector in the z direction
--------------------------------------------------------------------------------------- */
void
setUseEwald
(
RealOpenMM
alpha
,
int
kmaxx
,
int
kmaxy
,
int
kmaxz
);
/**---------------------------------------------------------------------------------------
Set the force to use Particle-Mesh Ewald (PME) summation.
@param alpha the Ewald separation parameter
--------------------------------------------------------------------------------------- */
void
setUsePME
(
RealOpenMM
alpha
);
/**---------------------------------------------------------------------------------------
Set the soft core LJ lambda
@param lambda the soft core LJ lambda
--------------------------------------------------------------------------------------- */
void
setSoftCoreLJLambda
(
RealOpenMM
lambda
);
/**---------------------------------------------------------------------------------------
Calculate parameters for LJ 1-4 ixn
Calculate parameters for ixn
@param c6 c6
@param c12 c12
...
...
@@ -164,8 +127,7 @@ class ReferenceFreeEnergyLJCoulombSoftcoreIxn : public ReferencePairIxn {
--------------------------------------------------------------------------------------- */
void
getDerivedParameters
(
RealOpenMM
c6
,
RealOpenMM
c12
,
RealOpenMM
q1
,
RealOpenMM
epsfacSqrt
,
RealOpenMM
*
parameters
)
const
;
RealOpenMM
epsfacSqrt
,
RealOpenMM
*
parameters
)
const
;
/**---------------------------------------------------------------------------------------
...
...
@@ -180,62 +142,16 @@ class ReferenceFreeEnergyLJCoulombSoftcoreIxn : public ReferencePairIxn {
interacting w/ atom atomIndex
@param fixedParameters non atom parameters (not currently used)
@param forces force array (forces added)
@param energyByAtom atom energy
@param totalEnergy total energy
--------------------------------------------------------------------------------------- */
void
calculatePairIxn
(
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
int
**
exclusions
,
RealOpenMM
*
fixedParameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
)
const
;
RealOpenMM
**
atomParameters
,
int
**
exclusions
,
RealOpenMM
*
fixedParameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
)
const
;
private:
/**---------------------------------------------------------------------------------------
Calculate Ewald ixn
@param numberOfAtoms number of atoms
@param atomCoordinates atom coordinates
@param atomParameters atom parameters (charges, c6, c12, ...) atomParameters[atomIndex][paramterIndex]
@param exclusions atom exclusion indices exclusions[atomIndex][atomToExcludeIndex]
exclusions[atomIndex][0] = number of exclusions
exclusions[atomIndex][1-no.] = atom indices of atoms to excluded from
interacting w/ atom atomIndex
@param fixedParameters non atom parameters (not currently used)
@param forces force array (forces added)
@param energyByAtom atom energy
@param totalEnergy total energy
--------------------------------------------------------------------------------------- */
void
calculateEwaldIxn
(
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
int
**
exclusions
,
RealOpenMM
*
fixedParameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
)
const
;
/**---------------------------------------------------------------------------------------
Calculate PME ixn
@param numberOfAtoms number of atoms
@param atomCoordinates atom coordinates
@param atomParameters atom parameters (charges, c6, c12, ...) atomParameters[atomIndex][paramterIndex]
@param exclusions atom exclusion indices exclusions[atomIndex][atomToExcludeIndex]
exclusions[atomIndex][0] = number of exclusions
exclusions[atomIndex][1-no.] = atom indices of atoms to excluded from
interacting w/ atom atomIndex
@param fixedParameters non atom parameters (not currently used)
@param forces force array (forces added)
@param energyByAtom atom energy
@param totalEnergy total energy
--------------------------------------------------------------------------------------- */
void
calculatePMEIxn
(
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
RealOpenMM
**
atomParameters
,
int
**
exclusions
,
RealOpenMM
*
fixedParameters
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
RealOpenMM
*
energyByAtom
,
RealOpenMM
*
totalEnergy
)
const
;
/**---------------------------------------------------------------------------------------
...
...
@@ -250,7 +166,7 @@ private:
--------------------------------------------------------------------------------------- */
void
calculateOneLJIxn
(
RealOpenMM
inverseR
,
RealOpenMM
sig
,
RealOpenMM
eps
,
RealOpenMM
*
dEdR
,
RealOpenMM
*
energy
)
const
;
RealOpenMM
*
dEdR
,
RealOpenMM
*
energy
)
const
;
/**---------------------------------------------------------------------------------------
...
...
@@ -266,7 +182,7 @@ private:
--------------------------------------------------------------------------------------- */
void
calculateOneSoftCoreLJIxn
(
RealOpenMM
r
,
RealOpenMM
sig
,
RealOpenMM
eps
,
RealOpenMM
lambda
,
RealOpenMM
*
dEdR
,
RealOpenMM
*
energy
)
const
;
RealOpenMM
lambda
,
RealOpenMM
*
dEdR
,
RealOpenMM
*
energy
)
const
;
};
...
...
plugins/freeEnergy/platforms/reference/tests/TestReferenceLJSoftcoreForce.cpp
0 → 100644
View file @
9dd055eb
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2009 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests all the different force terms in the reference implementation of CustomGBForce.
*/
#include "../../../tests/AssertionUtilities.h"
#include "sfmt/SFMT.h"
#include "openmm/Context.h"
#include "openmm/CustomBondForce.h"
#include "openmm/CustomNonbondedForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/NonbondedSoftcoreForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include <iostream>
#include <vector>
#include <algorithm>
using
namespace
OpenMM
;
using
namespace
std
;
const
double
TOL
=
1e-5
;
static
const
int
NoCutoff
=
0
;
static
const
int
CutoffNonPeriodic
=
1
;
static
const
int
CutoffPeriodic
=
2
;
void
testNonbondedSoftcore
(
double
lambda1
,
double
lambda2
,
int
nonbondedMethod
){
const
int
numMolecules
=
70
;
const
int
numParticles
=
numMolecules
*
2
;
const
double
boxSize
=
10.0
;
const
double
reactionFieldDielectric
=
80.0
;
const
double
cutoffDistance
=
0.4
*
boxSize
;
// Create two systems: one with a NonbondedSoftcoreForce, and one using a CustomNonbondedForce to implement the same interaction.
System
standardSystem
;
System
customSystem
;
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
standardSystem
.
addParticle
(
1.0
);
customSystem
.
addParticle
(
1.0
);
}
standardSystem
.
setDefaultPeriodicBoxVectors
(
Vec3
(
boxSize
,
0
,
0
),
Vec3
(
0
,
boxSize
,
0
),
Vec3
(
0
,
0
,
boxSize
));
customSystem
.
setDefaultPeriodicBoxVectors
(
Vec3
(
boxSize
,
0
,
0
),
Vec3
(
0
,
boxSize
,
0
),
Vec3
(
0
,
0
,
boxSize
));
NonbondedSoftcoreForce
*
nonbondedSoftcoreForce
=
new
NonbondedSoftcoreForce
();
CustomNonbondedForce
*
customNonbonded
;
CustomBondForce
*
customBond
;
if
(
nonbondedMethod
==
NoCutoff
){
nonbondedSoftcoreForce
->
setNonbondedMethod
(
NonbondedSoftcoreForce
::
NoCutoff
);
customNonbonded
=
new
CustomNonbondedForce
(
"lambda*4*eps*(dem^2-dem)+138.935456*q/r;"
"q=q1*q2;"
"dem=1.0/(soft+rsig);"
"rsig=(r/sigma)^6;"
"rsig=(r/sigma)^6;"
"soft=0.5*(1.0-lambda);"
"sigma=0.5*(sigma1+sigma2);"
"eps=sqrt(eps1*eps2);"
"lambda=min(lambda1,lambda2)"
);
customNonbonded
->
setNonbondedMethod
(
CustomNonbondedForce
::
NoCutoff
);
customBond
=
new
CustomBondForce
(
"lambda*4*eps*(dem^2-dem)+138.935456*q/r;"
"dem=1.0/(soft+rsig);"
"rsig=(r/sigma)^6;"
"soft=0.5*(1.0-lambda)"
);
}
else
{
nonbondedSoftcoreForce
->
setCutoffDistance
(
cutoffDistance
);
nonbondedSoftcoreForce
->
setReactionFieldDielectric
(
reactionFieldDielectric
);
if
(
nonbondedMethod
==
CutoffNonPeriodic
){
nonbondedSoftcoreForce
->
setNonbondedMethod
(
NonbondedSoftcoreForce
::
CutoffNonPeriodic
);
}
else
{
nonbondedSoftcoreForce
->
setNonbondedMethod
(
NonbondedSoftcoreForce
::
CutoffPeriodic
);
}
customNonbonded
=
new
CustomNonbondedForce
(
"lambda*4*eps*(dem^2-dem)+138.935456*q*(1.0/r+(krf*r*r)-crf);"
"q=q1*q2;"
"dem=1.0/(soft+rsig);"
"rsig=(r/sigma)^6;"
"rsig=(r/sigma)^6;"
"soft=0.5*(1.0-lambda);"
"sigma=0.5*(sigma1+sigma2);"
"eps=sqrt(eps1*eps2);"
"lambda=min(lambda1,lambda2)"
);
customBond
=
new
CustomBondForce
(
"withinCutoff*(lambda*4*eps*(dem^2-dem)+138.935456*q*(1.0/r+(krf*r*r)-crf));"
"withinCutoff=step(cutoff-r);"
"dem=1.0/(soft+rsig);"
"rsig=(r/sigma)^6;"
"soft=0.5*(1.0-lambda)"
);
customNonbonded
->
setCutoffDistance
(
cutoffDistance
);
if
(
nonbondedMethod
==
CutoffNonPeriodic
){
customNonbonded
->
setNonbondedMethod
(
CustomNonbondedForce
::
CutoffNonPeriodic
);
}
else
{
customNonbonded
->
setNonbondedMethod
(
CustomNonbondedForce
::
CutoffPeriodic
);
}
double
eps2
=
(
reactionFieldDielectric
-
1.0
)
/
(
2.0
*
reactionFieldDielectric
+
1.0
);
double
kValue
=
eps2
/
(
cutoffDistance
*
cutoffDistance
*
cutoffDistance
);
customNonbonded
->
addGlobalParameter
(
"krf"
,
kValue
);
customBond
->
addGlobalParameter
(
"krf"
,
kValue
);
double
cValue
=
(
1.0
/
cutoffDistance
)
*
(
3.0
*
reactionFieldDielectric
)
/
(
2.0
*
reactionFieldDielectric
+
1.0
);
customNonbonded
->
addGlobalParameter
(
"crf"
,
cValue
);
customBond
->
addGlobalParameter
(
"crf"
,
cValue
);
customBond
->
addGlobalParameter
(
"cutoff"
,
cutoffDistance
);
}
customNonbonded
->
addPerParticleParameter
(
"q"
);
customNonbonded
->
addPerParticleParameter
(
"sigma"
);
customNonbonded
->
addPerParticleParameter
(
"eps"
);
customNonbonded
->
addPerParticleParameter
(
"lambda"
);
customBond
->
addPerBondParameter
(
"q"
);
customBond
->
addPerBondParameter
(
"sigma"
);
customBond
->
addPerBondParameter
(
"eps"
);
customBond
->
addPerBondParameter
(
"lambda"
);
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
vector
<
double
>
params
(
4
);
// periodic boundary conditions not possible w/ CustomBond?
int
includeExceptions
=
nonbondedMethod
==
CutoffPeriodic
?
0
:
1
;
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
if
(
i
<
numMolecules
/
2
)
{
double
charge
=
1.0
;
nonbondedSoftcoreForce
->
addParticle
(
charge
,
0.2
,
0.5
,
lambda1
);
nonbondedSoftcoreForce
->
addParticle
(
-
charge
,
0.1
,
0.5
,
lambda1
);
params
[
0
]
=
charge
;
params
[
1
]
=
0.2
;
params
[
2
]
=
0.5
;
params
[
3
]
=
lambda1
;
customNonbonded
->
addParticle
(
params
);
params
[
0
]
=
-
charge
;
params
[
1
]
=
0.1
;
customNonbonded
->
addParticle
(
params
);
if
(
includeExceptions
&&
i
&&
((
i
%
4
)
==
0
)
){
vector
<
double
>
bondParams
(
4
);
nonbondedSoftcoreForce
->
addException
(
i
-
4
,
i
,
charge
*
charge
,
0.2
,
0.5
,
false
,
lambda1
);
customNonbonded
->
addExclusion
(
i
-
4
,
i
);
bondParams
[
0
]
=
charge
*
charge
;
bondParams
[
1
]
=
0.2
;
bondParams
[
2
]
=
0.5
;
bondParams
[
3
]
=
lambda1
;
customBond
->
addBond
(
i
-
4
,
i
,
bondParams
);
}
}
else
{
double
charge
=
1.2
;
nonbondedSoftcoreForce
->
addParticle
(
charge
,
0.2
,
0.8
,
lambda2
);
nonbondedSoftcoreForce
->
addParticle
(
-
charge
,
0.1
,
0.8
,
lambda2
);
params
[
0
]
=
charge
;
params
[
1
]
=
0.2
;
params
[
2
]
=
0.8
;
params
[
3
]
=
lambda2
;
customNonbonded
->
addParticle
(
params
);
params
[
0
]
=
-
charge
;
params
[
1
]
=
0.1
;
customNonbonded
->
addParticle
(
params
);
if
(
includeExceptions
&&
i
&&
((
i
%
4
)
==
0
)
){
vector
<
double
>
bondParams
(
4
);
nonbondedSoftcoreForce
->
addException
(
i
-
4
,
i
,
charge
*
charge
,
0.2
,
0.5
,
false
,
lambda1
);
customNonbonded
->
addExclusion
(
i
-
4
,
i
);
bondParams
[
0
]
=
charge
*
charge
;
bondParams
[
1
]
=
0.2
;
bondParams
[
2
]
=
0.5
;
bondParams
[
3
]
=
lambda2
;
customBond
->
addBond
(
i
-
4
,
i
,
bondParams
);
}
}
positions
[
2
*
i
]
=
Vec3
(
boxSize
*
genrand_real2
(
sfmt
),
boxSize
*
genrand_real2
(
sfmt
),
boxSize
*
genrand_real2
(
sfmt
));
positions
[
2
*
i
+
1
]
=
Vec3
(
positions
[
2
*
i
][
0
]
+
1.0
,
positions
[
2
*
i
][
1
],
positions
[
2
*
i
][
2
]);
velocities
[
2
*
i
]
=
Vec3
(
genrand_real2
(
sfmt
),
genrand_real2
(
sfmt
),
genrand_real2
(
sfmt
));
velocities
[
2
*
i
+
1
]
=
Vec3
(
genrand_real2
(
sfmt
),
genrand_real2
(
sfmt
),
genrand_real2
(
sfmt
));
}
standardSystem
.
addForce
(
nonbondedSoftcoreForce
);
customSystem
.
addForce
(
customNonbonded
);
customSystem
.
addForce
(
customBond
);
VerletIntegrator
integrator1
(
0.01
);
VerletIntegrator
integrator2
(
0.01
);
Context
context1
(
standardSystem
,
integrator1
,
Platform
::
getPlatformByName
(
"Reference"
));
context1
.
setPositions
(
positions
);
context1
.
setVelocities
(
velocities
);
State
state1
=
context1
.
getState
(
State
::
Forces
|
State
::
Energy
);
Context
context2
(
customSystem
,
integrator2
,
Platform
::
getPlatformByName
(
"Reference"
));
context2
.
setPositions
(
positions
);
context2
.
setVelocities
(
velocities
);
State
state2
=
context2
.
getState
(
State
::
Forces
|
State
::
Energy
);
// (void) fprintf( stderr, "%10.1f %10.1f %15.7e %15.7e\n", lambda1, lambda2, state1.getPotentialEnergy(), state2.getPotentialEnergy());
ASSERT_EQUAL_TOL
(
state1
.
getPotentialEnergy
(),
state2
.
getPotentialEnergy
(),
1e-4
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
{
ASSERT_EQUAL_VEC
(
state1
.
getForces
()[
i
],
state2
.
getForces
()[
i
],
1e-4
);
}
}
int
main
()
{
try
{
// test various combinations of lambdas and boundary conditions/cutoffs
testNonbondedSoftcore
(
1.0
,
1.0
,
NoCutoff
);
testNonbondedSoftcore
(
1.0
,
0.0
,
NoCutoff
);
testNonbondedSoftcore
(
1.0
,
0.5
,
NoCutoff
);
testNonbondedSoftcore
(
0.0
,
0.0
,
NoCutoff
);
testNonbondedSoftcore
(
1.0
,
1.0
,
CutoffNonPeriodic
);
testNonbondedSoftcore
(
1.0
,
0.0
,
CutoffNonPeriodic
);
testNonbondedSoftcore
(
1.0
,
0.5
,
CutoffNonPeriodic
);
testNonbondedSoftcore
(
0.0
,
0.0
,
CutoffNonPeriodic
);
testNonbondedSoftcore
(
1.0
,
1.0
,
CutoffPeriodic
);
testNonbondedSoftcore
(
1.0
,
0.0
,
CutoffPeriodic
);
testNonbondedSoftcore
(
1.0
,
0.5
,
CutoffPeriodic
);
testNonbondedSoftcore
(
0.0
,
0.0
,
CutoffPeriodic
);
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
plugins/freeEnergy/platforms/reference/tests/TestReferenceOBCSoftcoreForce.cpp
View file @
9dd055eb
...
...
@@ -37,13 +37,12 @@
#include "sfmt/SFMT.h"
#include "openmm/Context.h"
#include "ReferencePlatform.h"
#include "openmm/CustomGBForce.h"
#include "openmm/GBSAOBCSoftcoreForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include <iostream>
#include <vector>
#include <algorithm>
...
...
@@ -53,7 +52,7 @@ using namespace std;
const
double
TOL
=
1e-5
;
void
testSoftcore
OBC
(
double
lambda1
,
double
lambda2
){
void
test
OBC
Softcore
(
double
lambda1
,
double
lambda2
){
const
int
numMolecules
=
70
;
const
int
numParticles
=
numMolecules
*
2
;
...
...
@@ -168,9 +167,9 @@ int main() {
// test various combinations of lambdas
testSoftcore
OBC
(
1.0
,
1.0
);
testSoftcore
OBC
(
1.0
,
0.0
);
testSoftcore
OBC
(
1.0
,
0.5
);
test
OBC
Softcore
(
1.0
,
1.0
);
test
OBC
Softcore
(
1.0
,
0.0
);
test
OBC
Softcore
(
1.0
,
0.5
);
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment