alchemistry / alchemlyb

the simple alchemistry library
https://alchemlyb.readthedocs.io
BSD 3-Clause "New" or "Revised" License
189 stars 49 forks source link

Error in reading amber energy files #287

Closed xiki-tempula closed 1 year ago

xiki-tempula commented 1 year ago

@pablo-arantes reported an issue where the current amber parser cannot read the energy output file. @DrDomenicoMarson many thanks for your contribution to the amber parser. I wonder if you have any thoughts on why this file cannot be parsed. Thank you.

In [1]: from alchemlyb.parsing.amber import extract_u_nk
In [2]: df = extract_u_nk('mdnvt_prod_8.out', 300)
11962 MBAR energies are > 0.0 kcal/mol
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 df = extract_u_nk('mdnvt_prod_8.out', 300)

File ~/miniconda3_x86/envs/alchemlyb/lib/python3.8/site-packages/alchemlyb/parsing/amber.py:419, in extract_u_nk(outfile, T)
    397 def extract_u_nk(outfile, T):
    398     """Return reduced potentials `u_nk` from AMBER outputfile.
    399 
    400     Parameters
   (...)
    417 
    418     """
--> 419     extracted = extract(outfile, T)
    420     return extracted['u_nk']

File ~/miniconda3_x86/envs/alchemlyb/lib/python3.8/site-packages/alchemlyb/parsing/__init__.py:27, in _init_attrs_dict.<locals>.wrapper(outfile, T, *args, **kwargs)
     25 @wraps(func)
     26 def wrapper(outfile, T, *args, **kwargs):
---> 27     dict_with_df = func(outfile, T, *args, **kwargs)
     28     for k in dict_with_df.keys():
     29         if dict_with_df[k] is not None:

File ~/miniconda3_x86/envs/alchemlyb/lib/python3.8/site-packages/alchemlyb/parsing/amber.py:347, in extract(outfile, T)
    344     logger.warning('WARNING: file %s is a prematurely terminated run', outfile)
    346 if file_datum.have_mbar:
--> 347     mbar_time = [
    348         file_datum.t0 + (frame_index + 1) * file_datum.dt * file_datum.ntpr
    349         for frame_index in range(len(file_datum.mbar_energies[0]))]
    351     mbar_df = pd.DataFrame(
    352         file_datum.mbar_energies,
    353         index=np.array(file_datum.mbar_lambdas, dtype=np.float64),
    354         columns=pd.MultiIndex.from_arrays(
    355             [mbar_time, np.repeat(file_datum.clambda, len(mbar_time))], names=['time', 'lambdas'])
    356             ).T
    357 else:

File ~/miniconda3_x86/envs/alchemlyb/lib/python3.8/site-packages/alchemlyb/parsing/amber.py:348, in <listcomp>(.0)
    344     logger.warning('WARNING: file %s is a prematurely terminated run', outfile)
    346 if file_datum.have_mbar:
    347     mbar_time = [
--> 348         file_datum.t0 + (frame_index + 1) * file_datum.dt * file_datum.ntpr
    349         for frame_index in range(len(file_datum.mbar_energies[0]))]
    351     mbar_df = pd.DataFrame(
    352         file_datum.mbar_energies,
    353         index=np.array(file_datum.mbar_lambdas, dtype=np.float64),
    354         columns=pd.MultiIndex.from_arrays(
    355             [mbar_time, np.repeat(file_datum.clambda, len(mbar_time))], names=['time', 'lambdas'])
    356             ).T
    357 else:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'

mdnvt_prod_8.out.zip

DrDomenicoMarson commented 1 year ago

Hi, I'll have a look at it tomorrow morning! I hope it will be nothing serious ;)

DrDomenicoMarson commented 1 year ago

I'm out at the pub but I was curious and spent a couple of minutes in the file, just two quick comments, also as a reference for "tomorrow morning me":

xiki-tempula commented 1 year ago

@DrDomenicoMarson There is the output for another window as well, which seems to be working fine. mdnvt_prod_1.out.zip

DrDomenicoMarson commented 1 year ago

@xiki-tempula @pablo-arantes I tried on the current git version of alchemlyb and it all seems fine, with both files.

This is the same problem as the one that was recently addressed (#272)!

xiki-tempula commented 1 year ago

I can confirm that this is solved. Thanks @DrDomenicoMarson .

pablo-arantes commented 1 year ago

Hi @xiki-tempula,

Thank you so much for the help. It's working now. :-)

Thank you.

Best,

Pablo