Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Comparators originally meant to be used with particles"""
2import numpy as np
3from ase.ga.utilities import get_nnmat
6class NNMatComparator:
7 """Use the nearest neighbor matrix to determine differences
8 in the distribution (and to a slighter degree structure)
9 of atoms. As specified in
10 S. Lysgaard et al., Top. Catal., 57 (1-4), pp 33-39, (2014)"""
11 def __init__(self, d=0.2, elements=None, mic=False):
12 self.d = d
13 if elements is None:
14 elements = []
15 self.elements = elements
16 self.mic = mic
18 def looks_like(self, a1, a2):
19 """ Return if structure a1 or a2 are similar or not. """
20 elements = self.elements
21 if elements == []:
22 elements = sorted(set(a1.get_chemical_symbols()))
23 a1, a2 = a1.copy(), a2.copy()
24 a1.set_constraint()
25 a2.set_constraint()
26 del a1[[a.index for a in a1 if a.symbol not in elements]]
27 del a2[[a.index for a in a2 if a.symbol not in elements]]
29 nnmat_a1 = get_nnmat(a1, mic=self.mic)
30 nnmat_a2 = get_nnmat(a2, mic=self.mic)
32 diff = np.linalg.norm(nnmat_a1 - nnmat_a2)
34 if diff < self.d:
35 return True
36 else:
37 return False