Skip to content

Commit 59837a7

Browse files
committed
Tests: species methods.
1 parent 3a31c3b commit 59837a7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

arc/species/species_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,6 +2804,45 @@ def test_species_indexing(self):
28042804
self.assertEqual(spc_b.index, 1)
28052805
self.assertEqual(spc_c.index, 2)
28062806

2807+
def test_kabsch(self):
2808+
"""Test the kabsch() method."""
2809+
# Test with self (RMSD should be 0)
2810+
rmsd = self.spc1.kabsch(self.spc1, [0, 1, 2, 3, 4, 5])
2811+
self.assertAlmostEqual(rmsd, 0.0, delta=1e-5)
2812+
2813+
# Test with a copy (RMSD should be 0)
2814+
spc1_copy = self.spc1.copy()
2815+
rmsd = self.spc1.kabsch(spc1_copy, [0, 1, 2, 3, 4, 5])
2816+
self.assertAlmostEqual(rmsd, 0.0, delta=1e-5)
2817+
2818+
# Test with shuffled atoms
2819+
# Create a shuffled version of spc1: swap first two C atoms
2820+
# spc1: C, C, O, H, H, H
2821+
# shuffled: C(1), C(0), O(2), H(3), H(4), H(5)
2822+
# xyz of spc1
2823+
xyz = self.spc1.get_xyz()
2824+
new_coords = (xyz['coords'][1], xyz['coords'][0]) + xyz['coords'][2:]
2825+
new_symbols = (xyz['symbols'][1], xyz['symbols'][0]) + xyz['symbols'][2:]
2826+
new_isotopes = (xyz['isotopes'][1], xyz['isotopes'][0]) + xyz['isotopes'][2:]
2827+
shuffled_xyz = {'symbols': new_symbols, 'isotopes': new_isotopes, 'coords': new_coords}
2828+
spc_shuffled = ARCSpecies(label='shuffled', xyz=shuffled_xyz, smiles='C=C[O]')
2829+
2830+
# Map: we want to pull atoms from spc_shuffled to match spc1
2831+
# spc1[0] is C(0). In spc_shuffled, C(0) is at index 1.
2832+
# spc1[1] is C(1). In spc_shuffled, C(1) is at index 0.
2833+
# Rest are same.
2834+
map_indices = [1, 0, 2, 3, 4, 5]
2835+
rmsd = self.spc1.kabsch(spc_shuffled, map_indices)
2836+
self.assertAlmostEqual(rmsd, 0.0, delta=1e-5)
2837+
2838+
# Test exception
2839+
with self.assertRaises(SpeciesError):
2840+
self.spc1.kabsch("not a species", [])
2841+
2842+
# Test incorrect map_ length
2843+
with self.assertRaises(SpeciesError):
2844+
self.spc1.kabsch(self.spc1, [0, 1, 2])
2845+
28072846

28082847
class TestTSGuess(unittest.TestCase):
28092848
"""

0 commit comments

Comments
 (0)