Coverage for /builds/ase/ase/ase/ga/particle_comparator.py: 100.00%
24 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
1# fmt: off
3"""Comparators originally meant to be used with particles"""
4import numpy as np
6from ase.ga.utilities import get_nnmat
9class NNMatComparator:
10 """Use the nearest neighbor matrix to determine differences
11 in the distribution (and to a slighter degree structure)
12 of atoms. As specified in
13 S. Lysgaard et al., Top. Catal., 57 (1-4), pp 33-39, (2014)"""
15 def __init__(self, d=0.2, elements=None, mic=False):
16 self.d = d
17 if elements is None:
18 elements = []
19 self.elements = elements
20 self.mic = mic
22 def looks_like(self, a1, a2):
23 """ Return if structure a1 or a2 are similar or not. """
24 elements = self.elements
25 if elements == []:
26 elements = sorted(set(a1.get_chemical_symbols()))
27 a1, a2 = a1.copy(), a2.copy()
28 a1.set_constraint()
29 a2.set_constraint()
30 del a1[[a.index for a in a1 if a.symbol not in elements]]
31 del a2[[a.index for a in a2 if a.symbol not in elements]]
33 nnmat_a1 = get_nnmat(a1, mic=self.mic)
34 nnmat_a2 = get_nnmat(a2, mic=self.mic)
36 diff = np.linalg.norm(nnmat_a1 - nnmat_a2)
38 if diff < self.d:
39 return True
40 else:
41 return False