mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

Improve error message when calling `AtmGroup.unwrap()` without bonds

Open PicoCentauri opened this issue 2 years ago • 2 comments

When calling the unwrap() method of an AtomGroup the method correctly checks for existing bonds and raises an error if this is not the case.

https://github.com/MDAnalysis/mdanalysis/blob/24abb160788ef87a48ed6eb196c1704d68fbc2da/package/MDAnalysis/core/groups.py#L1827-L1829

Even though the error message is clear I recently experienced issues that users do not know what to do in this case. It might worse improve this error message giving a hint what users can do. Maybe something along the lines:

if not hasattr(atoms, 'bonds'): 
    raise NoDataError(
        f"{self.__class__.__name__}.unwrap() not available; this AtomGroup lacks defined bonds."
        "To resolve this, you can either (1) guess the bonds at universe creation using `guess_bonds=True`"
        " or (2) create a universe using a topology format where bonds are pre-defined."
    )

PicoCentauri avatar Jan 19 '24 10:01 PicoCentauri

The new error message sounds very sensible to me, and definitely more helpful that the current "no can do!".

RMeli avatar Feb 07 '24 14:02 RMeli

Sounds like a very good idea. And easy to implement for new contributors!

orbeckst avatar Mar 25 '24 19:03 orbeckst

May I work on this issue with a little bit of your guidance?

laksh-krishna-sharma avatar Jul 22 '24 20:07 laksh-krishna-sharma

@laksh-krishna-sharma you're generally welcome to work on any issue and contribute. The first step is to create a pull request (PR) with your proposed changes and then developers will comment on the PR. Our User Guide has a section on Contributing to the code base that you should read if you haven't done so already.

orbeckst avatar Jul 23 '24 00:07 orbeckst

Thanks for the reply and guidance, @orbeckst. I will check and understand the issue thoroughly and then create a PR.

laksh-krishna-sharma avatar Jul 23 '24 12:07 laksh-krishna-sharma

@orbeckst. I created a PR . Please let me know if there are any issues. I will try my best to resolve them with your guidance. Thanks for giving me a chance, as this is my first time contributing to open source.

laksh-krishna-sharma avatar Jul 23 '24 21:07 laksh-krishna-sharma