Skip to content

Commit

Permalink
Fix repr method in Molecule, add residue and molecule to repr func of…
Browse files Browse the repository at this point in the history
… Site
  • Loading branch information
chrisjonesBSU committed Sep 18, 2024
1 parent bab6b75 commit 2413e3a
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}, 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

Check notice

Code scanning / CodeQL

Statement has no effect Note test

This statement has no effect.
assert molecule.number == 0
assert molecule.isrigid is False

def test_residue(self):
residue = Residue()
residue

Check notice

Code scanning / CodeQL

Statement has no effect Note test

This statement has no effect.
assert residue.number == 0

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

0 comments on commit 2413e3a

Please sign in to comment.