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

Fix __repr__ method in abstract_site.Molecule and abstract_site.Residue #851

Merged
merged 14 commits into from
Sep 19, 2024

Conversation

chrisjonesBSU
Copy link
Contributor

@chrisjonesBSU chrisjonesBSU commented Sep 18, 2024

When poking around some things while working on #850 I got a strange error when trying to look at a Molecule instance in a notebook. There is an error in the __repr__ method of both the Molecule and Residue classes in abstract_site.py where it tries to call an attribute that doesn't exist.

This PR fixes that, and adds some extremely simple tests that should have caught this.

Also, I added fields for Residue and Molecule to the __repr__ method for Site as I think it provides helpful info.

>>> from gmso.abc.abstract_site import Molecule
>>> mol = Molecule()
>>> mol

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chris/mambaforge/envs/flowermd-dev/lib/python3.11/site-packages/gmso/abc/abstract_site.py", line 27, in __repr__
    f"Molecule(name={self.name}, residue={self.residue}, isrigid={self.isrigid}"
                                          ^^^^^^^^^^^^
  File "/home/chris/mambaforge/envs/flowermd-dev/lib/python3.11/site-packages/pydantic/main.py", line 828, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'Molecule' object has no attribute 'residue'

@chrisjonesBSU chrisjonesBSU added the bug Something isn't working label Sep 18, 2024
gmso/tests/abc/test_abc.py Fixed Show fixed Hide fixed
gmso/tests/abc/test_abc.py Fixed Show fixed Hide fixed
Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.07%. Comparing base (5a4f17d) to head (c8c62ae).
Report is 29 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #851   +/-   ##
=======================================
  Coverage   94.07%   94.07%           
=======================================
  Files          65       65           
  Lines        6953     6953           
=======================================
  Hits         6541     6541           
  Misses        412      412           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chrisjonesBSU chrisjonesBSU changed the title Fix __repr__ method in abstract_site.Molecule Fix __repr__ method in abstract_site.Molecule and abstract_site.Residue Sep 18, 2024
@chrisjonesBSU
Copy link
Contributor Author

I'm not sure why all of these merge with upstream are showing up as commits here..I'll try and fix that after these recent PRs are done.

Copy link
Contributor

@CalCraven CalCraven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chrisjonesBSU chrisjonesBSU merged commit 6479930 into mosdef-hub:main Sep 19, 2024
17 checks passed
@chrisjonesBSU chrisjonesBSU deleted the fix/molecule branch September 19, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants