Skip to content
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Changelog
* Pass `opencl_platform_index` to the GCMC sampler, so that GCMC runs on the same OpenCL device as the dynamics when there are multiple OpenCL platforms [#266](https://github.com/OpenBioSim/somd2/pull/266).
* Fixed energy trajectory times for ABFE bound legs without a Boresch restraint being offset by up to the `restraint_search_time`, since production started from the time of the restraint search frame rather than the input system [#268](https://github.com/OpenBioSim/somd2/pull/268).
* Raise an error when a `perturbed_system` with a different periodic box from the reference system is used for GCMC in the NVT ensemble, since every replica must share the same box. GCMC in the osmotic ensemble, with a pressure set, is unaffected [#271](https://github.com/OpenBioSim/somd2/pull/271).
* Add a `chain_equilibration` option for replica exchange, which speeds up setup by starting each replica from a neighbour that has already been set up. Replicas in the first parallel batch, which is spread across lambda, are minimised and equilibrated from the input system. The rest skip minimisation and are equilibrated for `chain_equilibration_scale` times the `equilibration_time`, which defaults to a quarter [#273](https://github.com/OpenBioSim/somd2/pull/273).

[2026.2.0](https://github.com/openbiosim/somd2/compare/2026.1.0...2026.2.0) - Sep 2026
--------------------------------------------------------------------------------------
Expand Down
49 changes: 49 additions & 0 deletions src/somd2/config/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class Config:
"equilibration_time",
"equilibration_timestep",
"equilibration_constraints",
"chain_equilibration",
"chain_equilibration_scale",
"energy_frequency",
"frame_frequency",
"save_velocities",
Expand Down Expand Up @@ -176,6 +178,8 @@ def __init__(
equilibration_time="0 ps",
equilibration_timestep="2 fs",
equilibration_constraints=True,
chain_equilibration=False,
chain_equilibration_scale=0.25,
energy_frequency="1 ps",
save_trajectories=True,
frame_frequency="100 ps",
Expand Down Expand Up @@ -421,6 +425,23 @@ def __init__(
will be used. If True, then the values specified by 'constraint' and
'perturbable_constraint' will be used.

chain_equilibration: bool
Whether to start each replica from the state of a neighbouring one
that has already been set up, for replica exchange simulations. The
replicas set up in the first parallel batch, which are spread across
lambda, are minimised and equilibrated from the input system. Every
other replica starts from the equilibrated state of the closest one
already set up, and is equilibrated for 'chain_equilibration_scale'
times the 'equilibration_time', without minimisation. If there is no
equilibration, then each replica is minimised from the minimised
state of its neighbour instead. Replicas never start from one that
was seeded from the other end state by 'perturbed_system'.

chain_equilibration_scale: float
The fraction of the 'equilibration_time' for which replicas started
from a neighbour's state are equilibrated when 'chain_equilibration'
is True.

energy_frequency: str
Frequency at which to output energy data. If running using 'replica_exchange',
then this will also be the frequency at which replica swaps are attempted.
Expand Down Expand Up @@ -825,6 +846,8 @@ def __init__(
self.equilibration_time = equilibration_time
self.equilibration_timestep = equilibration_timestep
self.equilibration_constraints = equilibration_constraints
self.chain_equilibration = chain_equilibration
self.chain_equilibration_scale = chain_equilibration_scale
self.energy_frequency = energy_frequency
self.save_trajectories = save_trajectories
self.frame_frequency = frame_frequency
Expand Down Expand Up @@ -1924,6 +1947,32 @@ def equilibration_constraints(self, equilibration_constraints):
"using a timestep greater than 1fs."
)

@property
def chain_equilibration(self):
return self._chain_equilibration

@chain_equilibration.setter
def chain_equilibration(self, chain_equilibration):
if not isinstance(chain_equilibration, bool):
raise ValueError("'chain_equilibration' must be of type 'bool'")
self._chain_equilibration = chain_equilibration

@property
def chain_equilibration_scale(self):
return self._chain_equilibration_scale

@chain_equilibration_scale.setter
def chain_equilibration_scale(self, chain_equilibration_scale):
if isinstance(chain_equilibration_scale, bool):
raise ValueError("'chain_equilibration_scale' must be a float")
try:
chain_equilibration_scale = float(chain_equilibration_scale)
except Exception:
raise ValueError("'chain_equilibration_scale' must be a float")
if not 0.0 < chain_equilibration_scale <= 1.0:
raise ValueError("'chain_equilibration_scale' must be in (0, 1]")
self._chain_equilibration_scale = chain_equilibration_scale

@property
def energy_frequency(self):
return self._energy_frequency
Expand Down
13 changes: 13 additions & 0 deletions src/somd2/runner/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,19 @@ def _set_schedule(self, pert_idxs, ion_indices):
_logger.error(msg)
raise ValueError(msg)

if self._config.chain_equilibration:
if not self._config.replica_exchange:
msg = "'chain_equilibration' requires 'replica_exchange'."
_logger.error(msg)
raise ValueError(msg)
if isinstance(self._config.equilibration_time, list):
msg = (
"'chain_equilibration' can't be used with a list of "
"'equilibration_time' values."
)
_logger.error(msg)
raise ValueError(msg)

# Set the equilibration time for each window.
if isinstance(self._config.equilibration_time, list):
if len(self._config.equilibration_time) != len(self._lambda_values):
Expand Down
32 changes: 32 additions & 0 deletions src/somd2/runner/_dynamics_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ def _create_dynamics(
str(output_directory / f"gcmc_ghosts_{lam:.5f}.txt") for lam in lambdas
]

# Whether each replica starts from the perturbed end state coordinates.
self._start_perturbed = [False] * num_replicas

# Create the dynamics objects in serial. Each slot is created at the
# lambda value of the first replica that it hosts.
for i in range(self._num_slots):
Expand Down Expand Up @@ -455,6 +458,8 @@ def _create_dynamics(
# starting coordinates and periodic space.
elif perturbed_system is not None and seed_perturbed:
mols = perturbed_system
for replica in self._groups[i]:
self._start_perturbed[replica] = True
else:
mols = system

Expand Down Expand Up @@ -853,6 +858,26 @@ def _apply_openmm_state(context, state):
# format change.
context.setState(state)

def copy_state(self, source, target):
"""
Copy the stored state of one replica to another, so that the target
starts from the source's positions, velocities, box and GCMC water
state when it is next loaded.

Parameters
----------

source: int
The index of the replica to copy from.

target: int
The index of the replica to copy to.
"""
self._openmm_states[target] = dict(self._openmm_states[source])
if self._gcmc_states[source] is not None:
self._gcmc_states[target] = self._gcmc_states[source].copy()
self._state_moved[target] = True

def save_gcmc_state(self, slot, replica):
"""
Save the current GCMC water state of a slot as that of a replica.
Expand Down Expand Up @@ -1261,6 +1286,13 @@ def groups(self):
"""
return self._groups

@property
def start_perturbed(self):
"""
Whether each replica starts from the perturbed end state coordinates.
"""
return self._start_perturbed

@property
def time(self):
"""
Expand Down
Loading
Loading