Skip to content

Commit

Permalink
Merge pull request #851 from chrisjonesBSU/fix/molecule
Browse files Browse the repository at this point in the history
Fix `__repr__` method in `abstract_site.Molecule` and `abstract_site.Residue`
  • Loading branch information
chrisjonesBSU authored Sep 19, 2024
2 parents 5db9449 + c8c62ae commit 6479930
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
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}"

__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.__repr__()
assert molecule.number == 0
assert molecule.isrigid is False

def test_residue(self):
residue = Residue()
residue.__repr__()
assert residue.number == 0

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

0 comments on commit 6479930

Please sign in to comment.