Skip to content

Commit

Permalink
Test case for bond breakage with new strings as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bindgens1 authored and jngrad committed Feb 24, 2022
1 parent 8de0a6e commit 57b0965
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions testsuite/python/bond_breakage.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def tearDown(self):
def test_00_interface(self):
self.assertEqual(len(self.system.bond_breakage), 0)

spec2 = BreakageSpec(breakage_length=1.2, action_type=1)
spec4 = BreakageSpec(breakage_length=0.2, action_type=2)
spec2 = BreakageSpec(
breakage_length=1.2,
action_type="revert_center_bond")
spec4 = BreakageSpec(breakage_length=0.2, action_type="revert_vs_bond")
self.system.bond_breakage[2] = spec2
self.system.bond_breakage[4] = spec4
self.assertEqual(self.system.bond_breakage[2], spec2)
Expand All @@ -91,7 +93,7 @@ def test_ignore(self):

# Particles closer than cutoff
system.bond_breakage[self.h1._bond_id] = BreakageSpec(
breakage_length=2, action_type=1)
breakage_length=2, action_type="revert_center_bond")

self.p1.bonds = ((self.h1, self.p2))
system.integrator.run(1)
Expand All @@ -103,7 +105,7 @@ def test_ignore(self):

# Different bond type
system.bond_breakage[self.h1._bond_id] = BreakageSpec(
breakage_length=0.2, action_type=1)
breakage_length=0.2, action_type="revert_center_bond")
self.p1.bonds = [(self.h2, self.p2)]
self.p2.bonds = [(self.h2, self.p1)]
system.integrator.run(1)
Expand All @@ -115,7 +117,7 @@ def test_delete_bond(self):

# Particles closer than cutoff
system.bond_breakage[self.h1._bond_id] = BreakageSpec(
breakage_length=0, action_type=1)
breakage_length=0, action_type="revert_center_bond")

self.p1.bonds = [(self.h1, self.p2)]
system.integrator.run(1)
Expand All @@ -130,7 +132,7 @@ def test_revert_bind_at_point_of_collision(self):

# Particles closer than cutoff
system.bond_breakage[self.h1._bond_id] = BreakageSpec(
breakage_length=0.5, action_type=2)
breakage_length=0.5, action_type="revert_vs_bond")

self.p1.bonds = [(self.h2, self.p2)]
self.p1v.bonds = [(self.h1, self.p2v)]
Expand Down Expand Up @@ -167,6 +169,17 @@ def setUpClass(cls):
cls.system.time_step = 0.01
cls.system.cell_system.skin = 0.4

def count_bonds(self, pairs):
bonds_count = 0
for pair in pairs:
for bond in self.system.part.by_id(pair[0]).bonds:
if bond[1] == pair[1]:
bonds_count += 1
for bond in self.system.part.by_id(pair[1]).bonds:
if bond[1] == pair[0]:
bonds_count += 1
return bonds_count

def setUp(self):

box_vol = self.system.box_l[0]**3.
Expand Down Expand Up @@ -213,7 +226,7 @@ def test_center_bonds(self):

self.system.collision_detection.set_params(mode="off")
self.system.bond_breakage[harm._bond_id] = BreakageSpec(
breakage_length=crit, action_type=1)
breakage_length=crit, action_type="revert_center_bond")
self.system.integrator.run(1)

bonds_dist = 0
Expand All @@ -225,17 +238,7 @@ def test_center_bonds(self):
if dist <= crit:
bonds_dist += 1

bonds_count = 0
for pair in pairs:
num_bonds = len(self.system.part.by_id(pair[0]).bonds)
for i in range(num_bonds):
if self.system.part.by_id(pair[0]).bonds[i][1] == pair[1]:
bonds_count += 1
num_bonds = len(self.system.part.by_id(pair[1]).bonds)
for i in range(num_bonds):
if self.system.part.by_id(pair[1]).bonds[i][1] == pair[0]:
bonds_count += 1

bonds_count = self.count_bonds(pairs)
np.testing.assert_equal(bonds_dist, bonds_count)

@utx.skipIfMissingFeatures("VIRTUAL_SITES_RELATIVE")
Expand All @@ -256,7 +259,7 @@ def test_vs_bonds(self):

self.system.collision_detection.set_params(mode="off")
self.system.bond_breakage[harm._bond_id] = BreakageSpec(
breakage_length=crit_vs, action_type=2)
breakage_length=crit_vs, action_type="revert_vs_bond")
self.system.integrator.run(1)

bonds_dist = 0
Expand All @@ -277,16 +280,7 @@ def test_vs_bonds(self):
if dist > 0.0:
bonds_dist += 1

bonds_count = 0
for pair in pairs:
num_bonds = len(self.system.part.by_id(pair[0]).bonds)
for i in range(num_bonds):
if self.system.part.by_id(pair[0]).bonds[i][1] == pair[1]:
bonds_count += 1
num_bonds = len(self.system.part.by_id(pair[1]).bonds)
for i in range(num_bonds):
if self.system.part.by_id(pair[1]).bonds[i][1] == pair[0]:
bonds_count += 1
bonds_count = self.count_bonds(pairs)

np.testing.assert_equal(bonds_dist, bonds_count)

Expand Down

0 comments on commit 57b0965

Please sign in to comment.