Skip to content

Commit 502ae41

Browse files
committed
Added support for the kabsch implementation in ARCSpecies API
1 parent 793ada9 commit 502ae41

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

arc/species/species.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
order_atoms_in_mol_list,
4747
remove_dummies,
4848
rmg_mol_from_inchi,
49+
sort_xyz_using_indices,
4950
str_to_xyz,
5051
translate_to_center_of_mass,
5152
xyz_from_data,
5253
xyz_to_str,
54+
kabsch,
5355
)
5456
from arc.species.perceive import perceive_molecule_from_xyz, is_mol_valid
5557
from arc.species.vectors import calculate_angle, calculate_distance, calculate_dihedral_angle
@@ -2142,6 +2144,27 @@ def get_bonds(self) -> List[tuple]:
21422144
for atom2, bond12 in atom1.edges.items():
21432145
bonds.append(tuple(sorted((self.mol.atoms.index(atom1), self.mol.atoms.index(atom2)))))
21442146
return list(set(bonds))
2147+
2148+
def kabsch(self, other: 'ARCSpecies', map_: list) -> float:
2149+
"""
2150+
Calculate the Kabsch RMSD between this species and another species.
2151+
2152+
Args:
2153+
other (ARCSpecies): The other species to compare to.
2154+
map_ (list): A list of atom indices mapping atoms from this species to the other species. (i.e., if
2155+
this species has atoms [A, B, C] and the other species has atoms [C, A, B], then map_ would be [1, 2, 0]
2156+
Returns:
2157+
float: The Kabsch RMSD value.
2158+
"""
2159+
if not isinstance(other, ARCSpecies):
2160+
raise SpeciesError(f'Other must be an ARCSpecies instance, got {type(other)}.\n'
2161+
f'If you meant to use the XYZ coordinates directly, use arc.species.converter.kabsch.')
2162+
2163+
if len(map_) != self.number_of_atoms:
2164+
raise SpeciesError(f'The map_ list must have the same length as the number of atoms in {self.label} '
2165+
f'({self.number_of_atoms}), got {len(map_)}.')
2166+
2167+
return kabsch(self.get_xyz(), sort_xyz_using_indices(other.get_xyz(), map_))
21452168

21462169

21472170
class TSGuess(object):

0 commit comments

Comments
 (0)