|
1 | 1 | import openmm |
2 | 2 | from openmmtools.integrators import AlchemicalNonequilibriumLangevinIntegrator |
| 3 | +import logging |
3 | 4 |
|
| 5 | +logger = logging.getLogger(__name__) |
4 | 6 | # Energy unit used by OpenMM unit system |
5 | 7 | _OPENMM_ENERGY_UNIT = openmm.unit.kilojoules_per_mole |
6 | 8 |
|
@@ -156,57 +158,7 @@ def _get_prop_lambda(self, prop_lambda): |
156 | 158 |
|
157 | 159 | return prop_lambda_min, prop_lambda_max |
158 | 160 |
|
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 | + |
210 | 162 |
|
211 | 163 | def _add_alchemical_perturbation_step(self): |
212 | 164 | """ |
@@ -235,6 +187,14 @@ def getLogAcceptanceProbability(self, context): |
235 | 187 | protocol = self.getGlobalVariableByName("protocol_work") |
236 | 188 | shadow = self.getGlobalVariableByName("shadow_work") |
237 | 189 | 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 | + |
238 | 198 | return logp_accept |
239 | 199 |
|
240 | 200 | def reset(self): |
|
0 commit comments