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
1f2203f6
Unverified
Commit
1f2203f6
authored
Apr 02, 2026
by
Peter Eastman
Committed by
GitHub
Apr 02, 2026
Browse files
Fixed pressure calculation in MOnteCarloFlexibleBarostat (#5251)
parent
9f17d0f8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
openmmapi/src/MonteCarloFlexibleBarostatImpl.cpp
openmmapi/src/MonteCarloFlexibleBarostatImpl.cpp
+3
-3
tests/TestMonteCarloFlexibleBarostat.h
tests/TestMonteCarloFlexibleBarostat.h
+5
-5
No files found.
openmmapi/src/MonteCarloFlexibleBarostatImpl.cpp
View file @
1f2203f6
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* See https://openmm.org/development. *
* *
* *
* Portions copyright (c) 2010-202
5
Stanford University and the Authors. *
* Portions copyright (c) 2010-202
6
Stanford University and the Authors. *
* Authors: Peter Eastman, Sander Vandenhaute *
* Authors: Peter Eastman, Sander Vandenhaute *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -159,7 +159,7 @@ void MonteCarloFlexibleBarostatImpl::computeCurrentPressure(ContextImpl& context
...
@@ -159,7 +159,7 @@ void MonteCarloFlexibleBarostatImpl::computeCurrentPressure(ContextImpl& context
// Compute each component of the pressure tensor.
// Compute each component of the pressure tensor.
for
(
int
component
=
0
;
component
<
6
;
component
++
)
for
(
int
component
=
0
;
component
<
6
;
component
++
)
pressure
[
component
]
=
(
2.0
*
ke
[
component
]
-
computePressureComponent
(
context
,
delta
,
component
))
/
(
volume
*
AVOGADRO
*
1e-25
);
pressure
[
component
]
=
(
2.0
*
ke
[
component
]
/
volume
-
computePressureComponent
(
context
,
delta
,
component
))
/
(
AVOGADRO
*
1e-25
);
// Restore the context to its original state.
// Restore the context to its original state.
...
@@ -223,7 +223,7 @@ double MonteCarloFlexibleBarostatImpl::computePressureComponent(ContextImpl& con
...
@@ -223,7 +223,7 @@ double MonteCarloFlexibleBarostatImpl::computePressureComponent(ContextImpl& con
// Compute the potential energy contribution to this element of the pressure tensor.
// Compute the potential energy contribution to this element of the pressure tensor.
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
double
volume
=
box
[
0
][
0
]
*
box
[
1
][
1
]
*
box
[
2
][
2
];
return
(
energy
2
-
energy
1
)
/
(
volume
*
2
*
delta
);
return
(
energy
1
-
energy
2
)
/
(
volume
*
2
*
delta
);
}
}
void
MonteCarloFlexibleBarostatImpl
::
setBoxVectors
(
ContextImpl
&
context
,
Vec3
a
,
Vec3
b
,
Vec3
c
)
{
void
MonteCarloFlexibleBarostatImpl
::
setBoxVectors
(
ContextImpl
&
context
,
Vec3
a
,
Vec3
b
,
Vec3
c
)
{
...
...
tests/TestMonteCarloFlexibleBarostat.h
View file @
1f2203f6
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* See https://openmm.org/development. *
* *
* *
* Portions copyright (c) 2008-202
1
Stanford University and the Authors. *
* Portions copyright (c) 2008-202
6
Stanford University and the Authors. *
* Authors: Peter Eastman, Lee-Ping Wang *
* Authors: Peter Eastman, Lee-Ping Wang *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -180,12 +180,12 @@ void testMoleculeScaling(bool rigid) {
...
@@ -180,12 +180,12 @@ void testMoleculeScaling(bool rigid) {
}
}
void
testMolecularGas
(
bool
rigid
)
{
void
testMolecularGas
(
bool
rigid
)
{
const
int
numMolecules
=
6
4
;
const
int
numMolecules
=
25
6
;
const
int
frequency
=
5
;
const
int
frequency
=
5
;
const
int
steps
=
5000
;
const
int
steps
=
5000
;
const
double
pressure
=
3.0
;
const
double
pressure
=
3.0
;
const
double
pressureInMD
=
pressure
*
(
AVOGADRO
*
1e-25
);
// pressure in kJ/mol/nm^3
const
double
pressureInMD
=
pressure
*
(
AVOGADRO
*
1e-25
);
// pressure in kJ/mol/nm^3
const
double
temp
=
300.0
;
const
double
temp
=
300.0
;
const
double
initialVolume
=
numMolecules
*
BOLTZ
*
temp
/
pressureInMD
;
const
double
initialVolume
=
numMolecules
*
BOLTZ
*
temp
/
pressureInMD
;
const
double
initialLength
=
std
::
pow
(
initialVolume
,
1.0
/
3.0
);
const
double
initialLength
=
std
::
pow
(
initialVolume
,
1.0
/
3.0
);
...
@@ -206,8 +206,8 @@ void testMolecularGas(bool rigid) {
...
@@ -206,8 +206,8 @@ void testMolecularGas(bool rigid) {
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
Vec3
pos
(
initialLength
*
genrand_real2
(
sfmt
),
0.5
*
initialLength
*
genrand_real2
(
sfmt
),
2
*
initialLength
*
genrand_real2
(
sfmt
));
Vec3
pos
(
initialLength
*
genrand_real2
(
sfmt
),
0.5
*
initialLength
*
genrand_real2
(
sfmt
),
2
*
initialLength
*
genrand_real2
(
sfmt
));
bonds
->
addBond
(
positions
.
size
(),
positions
.
size
()
+
1
,
0.1
,
0
.0
);
bonds
->
addBond
(
positions
.
size
(),
positions
.
size
()
+
1
,
0.1
,
1
.0
);
bonds
->
addBond
(
positions
.
size
(),
positions
.
size
()
+
2
,
0.1
,
0
.0
);
bonds
->
addBond
(
positions
.
size
(),
positions
.
size
()
+
2
,
0.1
,
1
.0
);
positions
.
push_back
(
pos
);
positions
.
push_back
(
pos
);
positions
.
push_back
(
pos
+
Vec3
(
0.1
,
0.0
,
0.0
));
positions
.
push_back
(
pos
+
Vec3
(
0.1
,
0.0
,
0.0
));
positions
.
push_back
(
pos
+
Vec3
(
0.0
,
0.1
,
0.0
));
positions
.
push_back
(
pos
+
Vec3
(
0.0
,
0.1
,
0.0
));
...
...
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