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
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions gmso/abc/abstract_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class Molecule(GMSOBase):
def __repr__(self):
return (
f"Molecule(name={self.name}, residue={self.residue}, isrigid={self.isrigid}"
f"Molecule(name={self.name}, number={self.number}, isrigid={self.isrigid})"
)

__iterable_attributes__: ClassVar[set] = {
Expand Down Expand Up @@ -88,7 +88,7 @@ def __eq__(self, other):

class Residue(GMSOBase):
def __repr__(self):
return f"Residue(name={self.name}, residue={self.residue}"
return f"Residue(name={self.name}, number={self.number}, residue={self.residue}"

__iterable_attributes__: ClassVar[set] = {
"name",
Expand Down Expand Up @@ -149,6 +149,17 @@ def default_position():


class Site(GMSOBase):
def __repr__(self):
"""Return the formatted representation of the site."""
return (
f"<{self.__class__.__name__} {self.name},\n "
f"position: {self.position},\n "
f"label: {self.label if self.label else None},\n "
f"Molecule: {self.molecule},\n"
f"Residue: {self.residue},\n"
f"id: {id(self)}>"
)

__iterable_attributes__: ClassVar[set] = {
"name",
"label",
Expand Down Expand Up @@ -254,15 +265,6 @@ def residue(self):
def serialize_position(self, position_: PositionType):
return unyt_to_dict(position_)

def __repr__(self):
"""Return the formatted representation of the site."""
return (
f"<{self.__class__.__name__} {self.name},\n "
f"position: {self.position},\n "
f"label: {self.label if self.label else None},\n "
f"id: {id(self)}>"
)

def __str__(self):
"""Return the string representation of the site."""
return (
Expand Down
21 changes: 21 additions & 0 deletions gmso/tests/abc/test_abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from gmso.abc.abstract_site import Molecule, Residue, Site
from gmso.tests.base_test import BaseTest


class TestSite(BaseTest):
def test_molecule(self):
molecule = Molecule()
molecule
Fixed Show fixed Hide fixed
assert molecule.number == 0
assert molecule.isrigid is False

def test_residue(self):
residue = Residue()
residue
Fixed Show fixed Hide fixed
assert residue.number == 0

def test_site(self):
with pytest.raises(TypeError):
Site()
Loading