Skip to content

Commit

Permalink
Refactor: Add __len__ method to AtomicSystem class
Browse files Browse the repository at this point in the history
  • Loading branch information
galjos committed Aug 5, 2024
1 parent 6f5102d commit d787e94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions PQAnalysis/atomic_system/atomic_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,17 @@ def __getitem__(
topology=self.topology[keys]
)

def __len__(self) -> int:
"""
Returns the number of atoms in the AtomicSystem.
Returns
-------
int
The number of atoms in the AtomicSystem.
"""
return self.n_atoms

def __str__(self) -> str:
"""
Returns the string representation of the AtomicSystem.
Expand Down
14 changes: 14 additions & 0 deletions tests/atomicSystem/test_atomic_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ def test_n_atoms(self, caplog):
system
)

def test__len__(self):
system = AtomicSystem()
assert len(system) == 0

system = AtomicSystem(pos=np.array([[0, 0, 0], [1, 1, 1]]))
assert len(system) == 2

system = AtomicSystem(
pos=np.array([[0, 0, 0], [1, 1, 1]]),
atoms=[Atom('C'), Atom('H')],
cell=Cell(0.75, 0.75, 0.75)
)
assert len(system) == 2

def test__str__(self):
"""
Test the __str__ method of the AtomicSystem class.
Expand Down

0 comments on commit d787e94

Please sign in to comment.