choderalab / openmmtools

A batteries-included toolkit for the GPU-accelerated OpenMM molecular simulation engine.
http://openmmtools.readthedocs.io
MIT License
250 stars 80 forks source link

Import error on Google Colab #532

Closed bcallen95 closed 2 years ago

bcallen95 commented 2 years ago

Hi there! I've been trying to run the "Alchemical Free Energy Calculations" Tutorial on the OpenMM Page. When I try to import openmmtools I get the following traceback:


AttributeError Traceback (most recent call last)

in () ----> 1 import openmmtools 2 frames /usr/local/envs/openmm/lib/python3.7/site-packages/openmmtools/__init__.py in () 6 """ 7 ----> 8 from openmmtools import testsystems, integrators, alchemy, mcmc, states, cache, utils, constants, forces, forcefactories, storage, multistate 9 10 # Handle versioneer /usr/local/envs/openmm/lib/python3.7/site-packages/openmmtools/multistate/__init__.py in () 63 64 from openmmtools.multistate.multistatesampler import MultiStateSampler ---> 65 from openmmtools.multistate.multistatereporter import MultiStateReporter 66 from openmmtools.multistate.replicaexchange import ReplicaExchangeSampler, ReplicaExchangeAnalyzer 67 from openmmtools.multistate.paralleltempering import ParallelTemperingSampler, ParallelTemperingAnalyzer /usr/local/envs/openmm/lib/python3.7/site-packages/openmmtools/multistate/multistatereporter.py in () 1752 # ============================================================================== 1753 -> 1754 class _DictYamlLoader(yaml.CLoader): 1755 """PyYAML Loader that reads !Quantity tags.""" 1756 def __init__(self, *args, **kwargs): AttributeError: module 'yaml' has no attribute 'CLoader' Do you have any thoughts/advice on how to go about fixing this issue? Thanks!
bcallen95 commented 2 years ago

It appears that my environment set-up was the issue. Alternatively setting up the Conda environment (in Google Colab) in the following way appears to fix all issues (with each separate "code block" representing a separate cell):

!pip install -q condacolab
import condacolab
condacolab.install()
import condacolab
condacolab.check()
!mamba install -q openmmtools

However, this does lead to a new issue in the "Analyzing the Data with MBAR" Section... Running the following code:

from pymbar import MBAR, timeseries
N_k = np.zeros([nstates], np.int32) # number of uncorrelated samples
for k in range(nstates):
      [nequil, g, Neff_max] = timeseries.detectEquilibration(u_kln[k,k,:])
      indices = timeseries.subsampleCorrelatedData(u_kln[k,k,:], g=g)
      N_k[k] = len(indices)
      u_kln[k,:,0:N_k[k]] = u_kln[k,:,indices].T
mbar = MBAR(u_kln, N_k)
[DeltaF_ij, dDeltaF_ij, Theta_ij] = mbar.getFreeEnergyDifferences()

Results in this traceback:


ParameterError Traceback (most recent call last)

in () 10 # Compute the Free Energy Differences and Statistical Uncertainties 11 mbar = MBAR(u_kln, N_k) ---> 12 [DeltaF_ij, dDeltaF_ij, Theta_ij] = mbar.getFreeEnergyDifferences() 2 frames /usr/local/lib/python3.7/site-packages/pymbar/utils.py in check_w_normalized(W, N_k, tolerance) 367 raise ParameterError( 368 'Warning: Should have \sum_k N_k W_nk = 1. Actual row sum for sample %d was %f. %d other rows have similar problems' % --> 369 (firstbad, row_sums[firstbad], np.sum(badrows))) 370 371 return ParameterError: Warning: Should have \sum_k N_k W_nk = 1. Actual row sum for sample 6 was 0.999696. 7 other rows have similar problems
mikemhenry commented 2 years ago

@bcallen95 Sorry I just saw this, that error you are getting now is from pymbar, see this issue: https://github.com/choderalab/pymbar/issues/419