Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #234 #235

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
* Add support for boresch restraints to PME.
* Port SOMD torsion fix to PME code.
* Fix issues with ``atomtype`` and ``atom`` records for dummy atoms in GROMACS topology files.
* Fixes issue with runnning ``sire.morph.replica_exchange`` on systems in an NPT ensemble.


`2024.2.0 <https://github.com/openbiosim/sire/compare/2024.1.0...2024.2.0>`__ - June 2024
Expand Down
18 changes: 8 additions & 10 deletions src/sire/morph/_repex.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ def replica_exchange(
# delta = beta_b * [ H_b_i - H_b_j + P_b (V_b_i - V_b_j) ] +
# beta_a * [ H_a_i - H_a_j + P_a (V_a_i - V_a_j) ]

from ..units import k_boltz
from ..units import k_boltz, mole

N_A = 6.02214076e23 / mole

beta0 = 1.0 / (k_boltz * temperature0)
beta1 = 1.0 / (k_boltz * temperature1)

if not ensemble0.is_constant_pressure():
delta = beta1 * (nrgs1[0] - nrgs1[1]) + beta0 * (nrgs0[0] - nrgs0[1])
delta = beta1 * (nrgs1[1] - nrgs1[0]) + beta0 * (nrgs0[0] - nrgs0[1])
else:
volume0 = replica0.current_space().volume()
volume1 = replica1.current_space().volume()
Expand All @@ -102,8 +104,8 @@ def replica_exchange(
pressure1 = ensemble1.pressure()

delta = beta1 * (
nrgs1[0] - nrgs1[1] + pressure1 * (volume1 - volume0)
) + beta0 * (nrgs0[0] - nrgs0[1] + pressure0 * (volume0 - volume1))
(nrgs1[1] - nrgs1[0]) + (pressure1 * (volume1 - volume0) * N_A)
) + beta0 * ((nrgs0[0] - nrgs0[1]) + (pressure0 * (volume0 - volume1) * N_A))

from math import exp

Expand All @@ -118,12 +120,8 @@ def replica_exchange(
replica1.set_lambda(lam0)

if ensemble0 != ensemble1:
replica0.set_ensemble(
ensemble1, rescale_velocities=rescale_velocities
)
replica1.set_ensemble(
ensemble0, rescale_velocities=rescale_velocities
)
replica0.set_ensemble(ensemble1, rescale_velocities=rescale_velocities)
replica1.set_ensemble(ensemble0, rescale_velocities=rescale_velocities)

return (replica1, replica0, True)
else:
Expand Down