Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing for fragment attribute #2635

Closed
PicoCentauri opened this issue Mar 19, 2020 · 1 comment · Fixed by #2636
Closed

Testing for fragment attribute #2635

PicoCentauri opened this issue Mar 19, 2020 · 1 comment · Fixed by #2636

Comments

@PicoCentauri
Copy link
Contributor

Expected behavior

Checking for the fragment attribute

from MDAnalysisTests.core.util import UnWrapUniverse
u = UnWrapUniverse(have_molnums=False, have_bonds=False)

print(hasattr(u,"fragments"))
print(hasattr(u.atoms, "fragments"))

should give the following consistent output

False
False

Actual behavior

However, while the first works fine and returns False the second raises a NoDataError.

/usr/local/lib/python3.7/site-packages/MDAnalysis/core/groups.py in __getattr__(self, attr)
   2222             # raise NDE(_ATTR_ERRORS[attr])
   2223             raise NoDataError("AtomGroup.{} not available; this requires Bonds"
-> 2224                               "".format(attr))
   2225         raise AttributeError("{cls} has no attribute {attr}".format(
   2226             cls=self.__class__.__name__, attr=attr))

NoDataError: AtomGroup.fragments not available; this requires Bonds

Current version of MDAnalysis

  • Which version are you using? 0.20.2-dev0
  • Which version of Python: 3.7
  • Which operating system? macOS
@lilyminium
Copy link
Member

lilyminium commented Mar 20, 2020

Interesting. I guess you could define __hasattr__ but... would making NoDataError a subclass of AttributeError fix this?

Edit: yes, but then it breaks a bunch of properties. Also __hasattr__ doesn't exist and hasattr just calls __getattr__ and checks for an AttributeError (from Python 3+) so there's no getting around this without raising an AttributeError...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants