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

Feature: length __len__ in AtomicSystem #109

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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
Loading