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
58378cce
Unverified
Commit
58378cce
authored
Oct 21, 2025
by
Peter Eastman
Committed by
GitHub
Oct 21, 2025
Browse files
Fixed errors in computeCurrentPressure() (#5114)
parent
b64a82a8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
7 deletions
+47
-7
platforms/common/src/kernels/monteCarloBarostat.cc
platforms/common/src/kernels/monteCarloBarostat.cc
+1
-1
platforms/reference/src/SimTKReference/ReferenceMonteCarloBarostat.cpp
...erence/src/SimTKReference/ReferenceMonteCarloBarostat.cpp
+2
-1
tests/TestMonteCarloBarostat.h
tests/TestMonteCarloBarostat.h
+12
-3
wrappers/python/src/swig_doxygen/swigInputConfig.py
wrappers/python/src/swig_doxygen/swigInputConfig.py
+1
-0
wrappers/python/tests/TestAPIUnits.py
wrappers/python/tests/TestAPIUnits.py
+31
-2
No files found.
platforms/common/src/kernels/monteCarloBarostat.cc
View file @
58378cce
...
...
@@ -79,7 +79,7 @@ KERNEL void computeMolecularKineticEnergy(int numMolecules, GLOBAL mixed4* RESTR
molVel
+=
mass
*
trimTo3
(
v
);
molMass
+=
mass
;
}
molVel
*=
RECIP
((
mixed
)
molMass
);
molVel
*=
(
molMass
==
0
?
0
:
RECIP
((
mixed
)
molMass
)
)
;
#if COMPONENTS == 1
ke
[
0
]
+=
0.5
f
*
molMass
*
dot
(
molVel
,
molVel
);
#else
...
...
platforms/reference/src/SimTKReference/ReferenceMonteCarloBarostat.cpp
View file @
58378cce
...
...
@@ -133,7 +133,8 @@ void ReferenceMonteCarloBarostat::computeMolecularKineticEnergy(const vector<Vec
molVel
+=
masses
[
atom
]
*
velocities
[
atom
];
molMass
+=
masses
[
atom
];
}
molVel
/=
molMass
;
if
(
molMass
!=
0
)
molVel
/=
molMass
;
if
(
components
==
1
)
ke
[
0
]
+=
0.5
*
molMass
*
molVel
.
dot
(
molVel
);
else
{
...
...
tests/TestMonteCarloBarostat.h
View file @
58378cce
...
...
@@ -164,9 +164,18 @@ void testMolecularGas() {
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
for
(
int
i
=
0
;
i
<
numMolecules
;
++
i
)
{
system
.
addParticle
(
1.0
);
system
.
addParticle
(
2.0
);
system
.
addParticle
(
3.0
);
if
(
i
==
0
)
{
// Make one molecule massless to make sure that doesn't cause any problems.
system
.
addParticle
(
0.0
);
system
.
addParticle
(
0.0
);
system
.
addParticle
(
0.0
);
}
else
{
system
.
addParticle
(
1.0
);
system
.
addParticle
(
2.0
);
system
.
addParticle
(
3.0
);
}
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
,
10.0
);
system
.
addConstraint
(
positions
.
size
(),
positions
.
size
()
+
2
,
0.1
);
...
...
wrappers/python/src/swig_doxygen/swigInputConfig.py
View file @
58378cce
...
...
@@ -493,6 +493,7 @@ UNITS = {
(
"MonteCarloMembraneBarostat"
,
"MonteCarloMembraneBarostat"
)
:
(
None
,
(
"unit.bar"
,
"unit.bar*unit.nanometer"
,
"unit.kelvin"
,
None
,
None
,
None
)),
(
"MonteCarloMembraneBarostat"
,
"getXYMode"
)
:
(
None
,
()),
(
"MonteCarloMembraneBarostat"
,
"getZMode"
)
:
(
None
,
()),
(
"*"
,
"computeCurrentPressure"
)
:
(
"unit.bar"
,
()),
(
"CustomIntegrator"
,
"CustomIntegrator"
)
:
(
None
,
(
"unit.picosecond"
,)),
(
"BrownianIntegrator"
,
"BrownianIntegrator"
)
:
(
None
,
(
"unit.kelvin"
,
"unit.picosecond**-1"
,
"unit.picosecond"
)),
(
"LangevinIntegrator"
,
"LangevinIntegrator"
)
:
(
None
,
(
"unit.kelvin"
,
"unit.picosecond**-1"
,
"unit.picosecond"
)),
...
...
wrappers/python/tests/TestAPIUnits.py
View file @
58378cce
...
...
@@ -1242,8 +1242,31 @@ class TestAPIUnits(unittest.TestCase):
self
.
assertEqual
(
force
.
getDefaultTemperature
(),
298.15
*
kelvin
)
self
.
assertAlmostEqualUnit
(
force
.
getDefaultCollisionFrequency
(),
1
/
picosecond
)
def
testMonteCarloMembraneBarostat
(
self
):
""" Tests the MonteCarloMembraneBarostat API features """
def
testMonteCarloBarostat
(
self
):
""" Tests the various Monte Carlo barostats API features """
def
checkPressureUnits
(
force
):
system
=
System
()
system
.
addParticle
(
0.0
)
system
.
addForce
(
force
)
bonds
=
HarmonicBondForce
()
bonds
.
setUsesPeriodicBoundaryConditions
(
True
)
system
.
addForce
(
bonds
)
context
=
Context
(
system
,
VerletIntegrator
(
0.001
))
context
.
setPositions
([
Vec3
(
0
,
0
,
0
)])
pressure
=
force
.
computeCurrentPressure
(
context
)
self
.
assertTrue
(
is_quantity
(
pressure
))
self
.
assertTrue
(
pressure
.
unit
==
bar
)
force
=
MonteCarloBarostat
(
1.1
*
bar
,
350
*
kelvin
)
self
.
assertEqual
(
force
.
getDefaultPressure
(),
1.1
*
bar
)
self
.
assertEqual
(
force
.
getDefaultTemperature
(),
350
*
kelvin
)
checkPressureUnits
(
force
)
force
=
MonteCarloFlexibleBarostat
(
1.1
*
bar
,
350
*
kelvin
)
self
.
assertEqual
(
force
.
getDefaultPressure
(),
1.1
*
bar
)
self
.
assertEqual
(
force
.
getDefaultTemperature
(),
350
*
kelvin
)
checkPressureUnits
(
force
)
force
=
MonteCarloMembraneBarostat
(
1.0
,
1.5
,
300
,
MonteCarloMembraneBarostat
.
XYAnisotropic
,
MonteCarloMembraneBarostat
.
ZFixed
,
25
)
self
.
assertEqual
(
force
.
getDefaultPressure
(),
1.0
*
bar
)
self
.
assertEqual
(
force
.
getDefaultSurfaceTension
(),
1.5
*
bar
*
nanometer
)
...
...
@@ -1251,6 +1274,7 @@ class TestAPIUnits(unittest.TestCase):
self
.
assertEqual
(
force
.
getXYMode
(),
MonteCarloMembraneBarostat
.
XYAnisotropic
)
self
.
assertEqual
(
force
.
getZMode
(),
MonteCarloMembraneBarostat
.
ZFixed
)
self
.
assertEqual
(
force
.
getFrequency
(),
25
)
checkPressureUnits
(
force
)
force
=
MonteCarloMembraneBarostat
(
1.1
*
bar
,
2.0
*
bar
*
nanometer
,
350
*
kelvin
,
MonteCarloMembraneBarostat
.
XYAnisotropic
,
MonteCarloMembraneBarostat
.
ZFixed
,
25
)
self
.
assertEqual
(
force
.
getDefaultPressure
(),
1.1
*
bar
)
...
...
@@ -1264,6 +1288,11 @@ class TestAPIUnits(unittest.TestCase):
self
.
assertEqual
(
force
.
getDefaultSurfaceTension
(),
2.5
*
bar
*
nanometer
)
self
.
assertEqual
(
force
.
getDefaultTemperature
(),
298.15
*
kelvin
)
force
=
MonteCarloAnisotropicBarostat
(
Vec3
(
1.1
,
2.2
,
3.3
)
*
bar
,
350
*
kelvin
)
self
.
assertEqual
(
force
.
getDefaultPressure
(),
Vec3
(
1.1
,
2.2
,
3.3
)
*
bar
)
self
.
assertEqual
(
force
.
getDefaultTemperature
(),
350
*
kelvin
)
checkPressureUnits
(
force
)
def
testDrudeSCFIntegrator
(
self
):
""" Tests the DrudeSCFIntegrator API features """
integrator
=
DrudeSCFIntegrator
(
0.002
)
...
...
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