diff --git a/src/core/particle_data.cpp b/src/core/particle_data.cpp index cd684f670b6..6f23357a56a 100644 --- a/src/core/particle_data.cpp +++ b/src/core/particle_data.cpp @@ -1071,7 +1071,7 @@ void local_remove_particle(int part) { cell = c; position = i; } else { - remove_all_bonds_to(p, i); + remove_all_bonds_to(p, part); } } } diff --git a/testsuite/python/particle.py b/testsuite/python/particle.py index 59ed98f54a5..bcef750b0cf 100644 --- a/testsuite/python/particle.py +++ b/testsuite/python/particle.py @@ -271,6 +271,18 @@ def test_parallel_property_setters(self): # Cause a different mpi callback to uncover deadlock immediately _ = getattr(s.part[:], p) + def test_remove_particle(self): + """Tests that if a particle is removed, + it no longer exists and bonds to the removed particle are + also removed.""" + + p1 = self.system.part[self.pid] + p2 = self.system.part.add(pos=p1.pos, bonds=[(self.f1, p1.id)]) + + p1.remove() + self.assertFalse(self.system.part.exists(self.pid)) + self.assertEqual(len(p2.bonds), 0) + def test_zz_remove_all(self): for id in self.system.part[:].id: self.system.part[id].remove()