Skip to content

Commit 1a967fb

Browse files
author
Steven Ayoub
committed
fix: remove custom _add_integrator_steps to restore proper lambda updates via superclass
The custom _add_integrator_steps() was interfering with OpenMM's handling of the H step, preventing lambda from updating during NCMC. Reverting to the superclass implementation ensures correct protocol behavior and lambda progression.
1 parent a9a0d34 commit 1a967fb

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

blues/integrators.py

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import openmm
22
from openmmtools.integrators import AlchemicalNonequilibriumLangevinIntegrator
3+
import logging
34

5+
logger = logging.getLogger(__name__)
46
# Energy unit used by OpenMM unit system
57
_OPENMM_ENERGY_UNIT = openmm.unit.kilojoules_per_mole
68

@@ -156,57 +158,7 @@ def _get_prop_lambda(self, prop_lambda):
156158

157159
return prop_lambda_min, prop_lambda_max
158160

159-
def _add_integrator_steps(self):
160-
"""
161-
Override the base class to insert reset steps around the integrator.
162-
"""
163-
164-
# First step: Constrain positions and velocities and reset work accumulators and alchemical integrators
165-
self.beginIfBlock('step = 0')
166-
self.addComputeGlobal("perturbed_pe", "energy")
167-
self.addComputeGlobal("unperturbed_pe", "energy")
168-
self.addConstrainPositions()
169-
self.addConstrainVelocities()
170-
self._add_reset_protocol_work_step()
171-
self._add_alchemical_reset_step()
172-
self.endBlock()
173-
174-
# Main body
175-
if self._n_steps_neq == 0:
176-
# If nsteps = 0, we need to force execution on the first step only.
177-
self.beginIfBlock('step = 0')
178-
super(AlchemicalNonequilibriumLangevinIntegrator, self)._add_integrator_steps()
179-
self.addComputeGlobal("step", "step + 1")
180-
self.endBlock()
181-
else:
182-
#call the superclass function to insert the appropriate steps, provided the step number is less than n_steps
183-
self.beginIfBlock("step < nsteps")
184-
self.addComputeGlobal("perturbed_pe", "energy")
185-
self.beginIfBlock("first_step < 1")
186-
#TODO write better test that checks that the initial work isn't gigantic
187-
self.addComputeGlobal("first_step", "1")
188-
self.addComputeGlobal("unperturbed_pe", "energy")
189-
self.endBlock()
190-
#initial iteration
191-
self.addComputeGlobal("protocol_work", "protocol_work + (perturbed_pe - unperturbed_pe)")
192-
super(AlchemicalNonequilibriumLangevinIntegrator, self)._add_integrator_steps()
193-
#if more propogation steps are requested
194-
self.beginIfBlock("lambda > prop_lambda_min")
195-
self.beginIfBlock("lambda <= prop_lambda_max")
196-
197-
self.beginWhileBlock("prop < nprop")
198-
self.addComputeGlobal("prop", "prop + 1")
199-
200-
super(AlchemicalNonequilibriumLangevinIntegrator, self)._add_integrator_steps()
201-
self.endBlock()
202-
self.endBlock()
203-
self.endBlock()
204-
#ending variables to reset
205-
self.addComputeGlobal("unperturbed_pe", "energy")
206-
self.addComputeGlobal("step", "step + 1")
207-
self.addComputeGlobal("prop", "1")
208-
209-
self.endBlock()
161+
210162

211163
def _add_alchemical_perturbation_step(self):
212164
"""
@@ -235,6 +187,14 @@ def getLogAcceptanceProbability(self, context):
235187
protocol = self.getGlobalVariableByName("protocol_work")
236188
shadow = self.getGlobalVariableByName("shadow_work")
237189
logp_accept = -1.0 * (protocol + shadow) * _OPENMM_ENERGY_UNIT / self.kT
190+
191+
# sa
192+
import numpy as np
193+
logger.info(f"Protocol work: {protocol}")
194+
logger.info(f"Shadow work: {shadow}")
195+
logger.info(f"log_accept_prob: {logp_accept}")
196+
logger.info(f"acceptance_prob: {np.exp(logp_accept)}")
197+
238198
return logp_accept
239199

240200
def reset(self):

0 commit comments

Comments
 (0)