openmm / openmm-cookbook

The OpenMM Cookbook and Tutorials
38 stars 10 forks source link

Alchemical free energy tutorial recently stopped working #28

Closed JJHuse closed 1 year ago

JJHuse commented 1 year ago

I have been learning how to use OpenMM for alchemical free energy calculations, and the tutorial notebook here has been really useful. I refer back to it frequently for reference as I apply it to a much larger system. I was able to apply all but the last cell of code, which I'm slowly working to understand. As far as I can recall, it was only a few weeks ago that the notebook worked without any issues, but as I try to run through it now, I consistently get this error:

"OpenMMException: All nonbonded Forces must agree on whether to apply a cutoff." The error comes when I run this line: simulation = Simulation(topology, system, integrator)

I have tried exploring and investigating the error, but I haven't found any solutions. Might there be a backward compatibility issue with a new update to one of the packages downloaded?

sef43 commented 1 year ago

Hi @JJHuse thanks for raising this. Can you confirm the platform you are running on? I am seeing this error happen on CPU but I do not get the error on CUDA.

I think there is an error in the tutorial. The custom non bonded force should be set to use a periodic cutoff. I will check and update this soon.

JJHuse commented 1 year ago

I have been running the notebook with Google Colab, as it is, "out of the box."

sef43 commented 1 year ago

Can you try with this version? https://openmm.github.io/openmm-cookbook/PR30/notebooks/tutorials/Alchemical_free_energy_calculations.html

I have added these lines:

# Set the custom force to use a cutoff
custom_force.setNonbondedMethod(CustomNonbondedForce.CutoffPeriodic)
# and set the cutoff distance to be the same as the existing nbforce
custom_force.setCutoffDistance(nbforce.getCutoffDistance())
JJHuse commented 1 year ago

That seems to work now!

JJHuse commented 1 year ago

Also I noticed this:

# Pin pymbar to version 3 as this tutorial is not compatible with pymbar 4 API yet
!mamba install -y -c conda-forge openmmtools pymbar=3

As far as I can tell the only necessary modifications for pymbar 4 are changing three function names (mainly a snake case update) and adjusting for the tuple/dictionary return value of compute_free_energy_differences(). Is there something else that would cause issues that are harder to notice at first glance?

sef43 commented 1 year ago

Yes you are correct! thanks for pointing out the changes. I have updated to the pymbar 4 syntax as this is now the default version that gets installed from conda-forge. Additionally the compute_uncertainty option for MBAR now works again. My guess is the problem was incorrect energies from not having the periodic cutoff correctly specified.