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