From d787e943df481b871e098ee8da569a3700c40a13 Mon Sep 17 00:00:00 2001 From: "Josef M. Gallmetzer" Date: Mon, 5 Aug 2024 21:13:40 +0200 Subject: [PATCH 1/4] Refactor: Add __len__ method to AtomicSystem class --- PQAnalysis/atomic_system/atomic_system.py | 11 +++++++++++ tests/atomicSystem/test_atomic_system.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/PQAnalysis/atomic_system/atomic_system.py b/PQAnalysis/atomic_system/atomic_system.py index cca73fa..7729a4e 100644 --- a/PQAnalysis/atomic_system/atomic_system.py +++ b/PQAnalysis/atomic_system/atomic_system.py @@ -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. diff --git a/tests/atomicSystem/test_atomic_system.py b/tests/atomicSystem/test_atomic_system.py index 9bcc15d..4e73580 100644 --- a/tests/atomicSystem/test_atomic_system.py +++ b/tests/atomicSystem/test_atomic_system.py @@ -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. From f43393d657915992903be93864c2ed492c9d7f8a Mon Sep 17 00:00:00 2001 From: "Josef M. Gallmetzer" Date: Mon, 5 Aug 2024 21:33:24 +0200 Subject: [PATCH 2/4] chore: Update setup.py with compiler directive for Python 3 compatibility --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index c9a87ad..e02fd11 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ sources=['PQAnalysis/io/traj_file/process_lines.pyx'], include_dirs=[np.get_include()] ) + compiler_directives={'language_level': 3} ) setup( From b2a96002dfb9df97a3a1e40df4403b198a4ccb90 Mon Sep 17 00:00:00 2001 From: "Josef M. Gallmetzer" Date: Mon, 5 Aug 2024 21:40:36 +0200 Subject: [PATCH 3/4] bug: Missing comma in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e02fd11..978e8d0 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ 'PQAnalysis.io.traj_file.process_lines', sources=['PQAnalysis/io/traj_file/process_lines.pyx'], include_dirs=[np.get_include()] - ) + ), compiler_directives={'language_level': 3} ) From 7048666713c287af16772ea2b1c1c22b041241c0 Mon Sep 17 00:00:00 2001 From: "Josef M. Gallmetzer" Date: Tue, 6 Aug 2024 09:06:01 +0200 Subject: [PATCH 4/4] chore: Update setup.py, compiler directive for Python 3 compatibility is not needed --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 978e8d0..c9a87ad 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,7 @@ 'PQAnalysis.io.traj_file.process_lines', sources=['PQAnalysis/io/traj_file/process_lines.pyx'], include_dirs=[np.get_include()] - ), - compiler_directives={'language_level': 3} + ) ) setup(