Coverage for /builds/ase/ase/ase/ga/particle_comparator.py : 100.00%

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)"""
12 def __init__(self, d=0.2, elements=None, mic=False):
13 self.d = d
14 if elements is None:
15 elements = []
16 self.elements = elements
17 self.mic = mic
19 def looks_like(self, a1, a2):
20 """ Return if structure a1 or a2 are similar or not. """
21 elements = self.elements
22 if elements == []:
23 elements = sorted(set(a1.get_chemical_symbols()))
24 a1, a2 = a1.copy(), a2.copy()
25 a1.set_constraint()
26 a2.set_constraint()
27 del a1[[a.index for a in a1 if a.symbol not in elements]]
28 del a2[[a.index for a in a2 if a.symbol not in elements]]
30 nnmat_a1 = get_nnmat(a1, mic=self.mic)
31 nnmat_a2 = get_nnmat(a2, mic=self.mic)
33 diff = np.linalg.norm(nnmat_a1 - nnmat_a2)
35 if diff < self.d:
36 return True
37 else:
38 return False