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
dd140429
Commit
dd140429
authored
Sep 23, 2016
by
peastman
Browse files
Throw an exception if a barostat is used with a non-periodic system
parent
9a0fcf72
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
31 additions
and
18 deletions
+31
-18
openmmapi/include/openmm/MonteCarloAnisotropicBarostat.h
openmmapi/include/openmm/MonteCarloAnisotropicBarostat.h
+1
-1
openmmapi/include/openmm/MonteCarloBarostat.h
openmmapi/include/openmm/MonteCarloBarostat.h
+1
-1
openmmapi/include/openmm/MonteCarloMembraneBarostat.h
openmmapi/include/openmm/MonteCarloMembraneBarostat.h
+1
-1
openmmapi/src/MonteCarloAnisotropicBarostatImpl.cpp
openmmapi/src/MonteCarloAnisotropicBarostatImpl.cpp
+3
-0
openmmapi/src/MonteCarloBarostatImpl.cpp
openmmapi/src/MonteCarloBarostatImpl.cpp
+4
-1
openmmapi/src/MonteCarloMembraneBarostatImpl.cpp
openmmapi/src/MonteCarloMembraneBarostatImpl.cpp
+3
-0
platforms/reference/tests/TestReferenceMonteCarloMembraneBarostat.cpp
...ference/tests/TestReferenceMonteCarloMembraneBarostat.cpp
+4
-4
tests/TestMonteCarloAnisotropicBarostat.h
tests/TestMonteCarloAnisotropicBarostat.h
+10
-6
tests/TestMonteCarloBarostat.h
tests/TestMonteCarloBarostat.h
+4
-4
No files found.
openmmapi/include/openmm/MonteCarloAnisotropicBarostat.h
View file @
dd140429
...
@@ -191,7 +191,7 @@ public:
...
@@ -191,7 +191,7 @@ public:
* @returns true if force uses PBC and false otherwise
* @returns true if force uses PBC and false otherwise
*/
*/
bool
usesPeriodicBoundaryConditions
()
const
{
bool
usesPeriodicBoundaryConditions
()
const
{
return
tru
e
;
return
fals
e
;
}
}
protected:
protected:
ForceImpl
*
createImpl
()
const
;
ForceImpl
*
createImpl
()
const
;
...
...
openmmapi/include/openmm/MonteCarloBarostat.h
View file @
dd140429
...
@@ -147,7 +147,7 @@ public:
...
@@ -147,7 +147,7 @@ public:
* @returns true if force uses PBC and false otherwise
* @returns true if force uses PBC and false otherwise
*/
*/
bool
usesPeriodicBoundaryConditions
()
const
{
bool
usesPeriodicBoundaryConditions
()
const
{
return
tru
e
;
return
fals
e
;
}
}
protected:
protected:
ForceImpl
*
createImpl
()
const
;
ForceImpl
*
createImpl
()
const
;
...
...
openmmapi/include/openmm/MonteCarloMembraneBarostat.h
View file @
dd140429
...
@@ -244,7 +244,7 @@ public:
...
@@ -244,7 +244,7 @@ public:
* @returns true if force uses PBC and false otherwise
* @returns true if force uses PBC and false otherwise
*/
*/
bool
usesPeriodicBoundaryConditions
()
const
{
bool
usesPeriodicBoundaryConditions
()
const
{
return
tru
e
;
return
fals
e
;
}
}
protected:
protected:
ForceImpl
*
createImpl
()
const
;
ForceImpl
*
createImpl
()
const
;
...
...
openmmapi/src/MonteCarloAnisotropicBarostatImpl.cpp
View file @
dd140429
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include "openmm/internal/OSRngSeed.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/kernels.h"
#include "openmm/kernels.h"
#include "openmm/OpenMMException.h"
#include <cmath>
#include <cmath>
#include <vector>
#include <vector>
#include <algorithm>
#include <algorithm>
...
@@ -51,6 +52,8 @@ MonteCarloAnisotropicBarostatImpl::MonteCarloAnisotropicBarostatImpl(const Monte
...
@@ -51,6 +52,8 @@ MonteCarloAnisotropicBarostatImpl::MonteCarloAnisotropicBarostatImpl(const Monte
}
}
void
MonteCarloAnisotropicBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
void
MonteCarloAnisotropicBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
if
(
!
context
.
getSystem
().
usesPeriodicBoundaryConditions
())
throw
OpenMMException
(
"A barostat cannot be used with a non-periodic system"
);
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
Vec3
box
[
3
];
Vec3
box
[
3
];
...
...
openmmapi/src/MonteCarloBarostatImpl.cpp
View file @
dd140429
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2010 Stanford University and the Authors.
*
* Portions copyright (c) 2010
-2016
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include "openmm/internal/OSRngSeed.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/kernels.h"
#include "openmm/kernels.h"
#include "openmm/OpenMMException.h"
#include <cmath>
#include <cmath>
#include <vector>
#include <vector>
#include <algorithm>
#include <algorithm>
...
@@ -51,6 +52,8 @@ MonteCarloBarostatImpl::MonteCarloBarostatImpl(const MonteCarloBarostat& owner)
...
@@ -51,6 +52,8 @@ MonteCarloBarostatImpl::MonteCarloBarostatImpl(const MonteCarloBarostat& owner)
}
}
void
MonteCarloBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
void
MonteCarloBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
if
(
!
context
.
getSystem
().
usesPeriodicBoundaryConditions
())
throw
OpenMMException
(
"A barostat cannot be used with a non-periodic system"
);
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
Vec3
box
[
3
];
Vec3
box
[
3
];
...
...
openmmapi/src/MonteCarloMembraneBarostatImpl.cpp
View file @
dd140429
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include "openmm/internal/OSRngSeed.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/kernels.h"
#include "openmm/kernels.h"
#include "openmm/OpenMMException.h"
#include <cmath>
#include <cmath>
#include <vector>
#include <vector>
#include <algorithm>
#include <algorithm>
...
@@ -51,6 +52,8 @@ MonteCarloMembraneBarostatImpl::MonteCarloMembraneBarostatImpl(const MonteCarloM
...
@@ -51,6 +52,8 @@ MonteCarloMembraneBarostatImpl::MonteCarloMembraneBarostatImpl(const MonteCarloM
}
}
void
MonteCarloMembraneBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
void
MonteCarloMembraneBarostatImpl
::
initialize
(
ContextImpl
&
context
)
{
if
(
!
context
.
getSystem
().
usesPeriodicBoundaryConditions
())
throw
OpenMMException
(
"A barostat cannot be used with a non-periodic system"
);
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
=
context
.
getPlatform
().
createKernel
(
ApplyMonteCarloBarostatKernel
::
Name
(),
context
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
kernel
.
getAs
<
ApplyMonteCarloBarostatKernel
>
().
initialize
(
context
.
getSystem
(),
owner
);
Vec3
box
[
3
];
Vec3
box
[
3
];
...
...
platforms/reference/tests/TestReferenceMonteCarloMembraneBarostat.cpp
View file @
dd140429
...
@@ -37,6 +37,7 @@
...
@@ -37,6 +37,7 @@
#include "openmm/MonteCarloMembraneBarostat.h"
#include "openmm/MonteCarloMembraneBarostat.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "ReferencePlatform.h"
#include "ReferencePlatform.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/LangevinIntegrator.h"
...
@@ -76,8 +77,9 @@ void testIdealGas(MonteCarloMembraneBarostat::XYMode xymode, MonteCarloMembraneB
...
@@ -76,8 +77,9 @@ void testIdealGas(MonteCarloMembraneBarostat::XYMode xymode, MonteCarloMembraneB
}
}
MonteCarloMembraneBarostat
*
barostat
=
new
MonteCarloMembraneBarostat
(
pressure
,
tension
,
temp
[
0
],
xymode
,
zmode
,
frequency
);
MonteCarloMembraneBarostat
*
barostat
=
new
MonteCarloMembraneBarostat
(
pressure
,
tension
,
temp
[
0
],
xymode
,
zmode
,
frequency
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
ASSERT
(
barostat
->
usesPeriodicBoundaryConditions
());
HarmonicBondForce
*
bonds
=
new
HarmonicBondForce
();
ASSERT
(
system
.
usesPeriodicBoundaryConditions
());
bonds
->
setUsesPeriodicBoundaryConditions
(
true
);
system
.
addForce
(
bonds
);
// So it won't complain the system is non-periodic.
// Test it for three different temperatures.
// Test it for three different temperatures.
...
@@ -134,8 +136,6 @@ void testRandomSeed() {
...
@@ -134,8 +136,6 @@ void testRandomSeed() {
system
.
addForce
(
forceField
);
system
.
addForce
(
forceField
);
MonteCarloMembraneBarostat
*
barostat
=
new
MonteCarloMembraneBarostat
(
pressure
,
tension
,
temp
,
MonteCarloMembraneBarostat
::
XYAnisotropic
,
MonteCarloMembraneBarostat
::
ZFree
,
1
);
MonteCarloMembraneBarostat
*
barostat
=
new
MonteCarloMembraneBarostat
(
pressure
,
tension
,
temp
,
MonteCarloMembraneBarostat
::
XYAnisotropic
,
MonteCarloMembraneBarostat
::
ZFree
,
1
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
ASSERT
(
barostat
->
usesPeriodicBoundaryConditions
());
ASSERT
(
system
.
usesPeriodicBoundaryConditions
());
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
...
...
tests/TestMonteCarloAnisotropicBarostat.h
View file @
dd140429
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/CustomExternalForce.h"
#include "openmm/CustomExternalForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
...
@@ -69,8 +70,9 @@ void testIdealGas() {
...
@@ -69,8 +70,9 @@ void testIdealGas() {
}
}
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temp
[
0
],
true
,
true
,
true
,
frequency
);
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temp
[
0
],
true
,
true
,
true
,
frequency
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
ASSERT
(
barostat
->
usesPeriodicBoundaryConditions
());
HarmonicBondForce
*
bonds
=
new
HarmonicBondForce
();
ASSERT
(
system
.
usesPeriodicBoundaryConditions
());
bonds
->
setUsesPeriodicBoundaryConditions
(
true
);
system
.
addForce
(
bonds
);
// So it won't complain the system is non-periodic.
// Test it for three different temperatures.
// Test it for three different temperatures.
...
@@ -129,8 +131,9 @@ void testIdealGasAxis(int axis) {
...
@@ -129,8 +131,9 @@ void testIdealGasAxis(int axis) {
}
}
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temp
[
0
],
scaleX
,
scaleY
,
scaleZ
,
frequency
);
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temp
[
0
],
scaleX
,
scaleY
,
scaleZ
,
frequency
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
ASSERT
(
barostat
->
usesPeriodicBoundaryConditions
());
HarmonicBondForce
*
bonds
=
new
HarmonicBondForce
();
ASSERT
(
system
.
usesPeriodicBoundaryConditions
());
bonds
->
setUsesPeriodicBoundaryConditions
(
true
);
system
.
addForce
(
bonds
);
// So it won't complain the system is non-periodic.
// Test it for three different temperatures.
// Test it for three different temperatures.
...
@@ -187,8 +190,6 @@ void testRandomSeed() {
...
@@ -187,8 +190,6 @@ void testRandomSeed() {
system
.
addForce
(
forceField
);
system
.
addForce
(
forceField
);
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temp
,
true
,
true
,
true
,
1
);
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temp
,
true
,
true
,
true
,
1
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
ASSERT
(
barostat
->
usesPeriodicBoundaryConditions
());
ASSERT
(
system
.
usesPeriodicBoundaryConditions
());
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
...
@@ -262,6 +263,9 @@ void testTriclinic() {
...
@@ -262,6 +263,9 @@ void testTriclinic() {
}
}
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temperature
,
true
,
true
,
true
,
frequency
);
MonteCarloAnisotropicBarostat
*
barostat
=
new
MonteCarloAnisotropicBarostat
(
Vec3
(
pressure
,
pressure
,
pressure
),
temperature
,
true
,
true
,
true
,
frequency
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
HarmonicBondForce
*
bonds
=
new
HarmonicBondForce
();
bonds
->
setUsesPeriodicBoundaryConditions
(
true
);
system
.
addForce
(
bonds
);
// So it won't complain the system is non-periodic.
// Run a simulation
// Run a simulation
...
...
tests/TestMonteCarloBarostat.h
View file @
dd140429
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/LangevinIntegrator.h"
...
@@ -105,8 +106,9 @@ void testIdealGas() {
...
@@ -105,8 +106,9 @@ void testIdealGas() {
}
}
MonteCarloBarostat
*
barostat
=
new
MonteCarloBarostat
(
pressure
,
temp
[
0
],
frequency
);
MonteCarloBarostat
*
barostat
=
new
MonteCarloBarostat
(
pressure
,
temp
[
0
],
frequency
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
ASSERT
(
barostat
->
usesPeriodicBoundaryConditions
());
HarmonicBondForce
*
bonds
=
new
HarmonicBondForce
();
ASSERT
(
system
.
usesPeriodicBoundaryConditions
());
bonds
->
setUsesPeriodicBoundaryConditions
(
true
);
system
.
addForce
(
bonds
);
// So it won't complain the system is non-periodic.
// Test it for three different temperatures.
// Test it for three different temperatures.
...
@@ -153,8 +155,6 @@ void testRandomSeed() {
...
@@ -153,8 +155,6 @@ void testRandomSeed() {
system
.
addForce
(
forceField
);
system
.
addForce
(
forceField
);
MonteCarloBarostat
*
barostat
=
new
MonteCarloBarostat
(
pressure
,
temp
,
1
);
MonteCarloBarostat
*
barostat
=
new
MonteCarloBarostat
(
pressure
,
temp
,
1
);
system
.
addForce
(
barostat
);
system
.
addForce
(
barostat
);
ASSERT
(
barostat
->
usesPeriodicBoundaryConditions
());
ASSERT
(
system
.
usesPeriodicBoundaryConditions
());
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
...
...
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