Esempio n. 1
0
def test_particle_comparators(seed):

    # set up the random number generator
    rng = np.random.RandomState(seed)

    ico1 = make_ico('Cu')
    ico1.info['confid'] = 1
    ico2 = make_ico('Ni')
    ico1.numbers[:55] = [28] * 55
    ico2.numbers[:92] = [29] * 92

    ico1.info['data'] = {}
    ico1.info['data']['nnmat'] = get_nnmat(ico1)
    ico2.info['data'] = {}
    ico2.info['data']['nnmat'] = get_nnmat(ico2)
    comp = NNMatComparator()
    assert not comp.looks_like(ico1, ico2)

    op = RandomPermutation(rng=rng)
    a3, desc = op.get_new_individual([ico1])

    assert a3.get_chemical_formula() == ico1.get_chemical_formula()

    hard_comp = NNMatComparator(d=100)
    assert hard_comp.looks_like(ico1, a3)

    soft_comp = NNMatComparator(d=.0001)
    assert not soft_comp.looks_like(ico1, a3)
def test_particle_comparators():
    from ase.cluster import Icosahedron
    from ase.ga.particle_comparator import NNMatComparator
    from ase.ga.utilities import get_nnmat
    from ase.ga.particle_mutations import RandomPermutation

    ico1 = Icosahedron('Cu', 4)
    ico1.info['confid'] = 1
    ico2 = Icosahedron('Ni', 4)
    ico1.numbers[:55] = [28] * 55
    ico2.numbers[:92] = [29] * 92

    ico1.info['data'] = {}
    ico1.info['data']['nnmat'] = get_nnmat(ico1)
    ico2.info['data'] = {}
    ico2.info['data']['nnmat'] = get_nnmat(ico2)
    comp = NNMatComparator()
    assert not comp.looks_like(ico1, ico2)

    op = RandomPermutation()
    a3, desc = op.get_new_individual([ico1])

    assert a3.get_chemical_formula() == ico1.get_chemical_formula()

    hard_comp = NNMatComparator(d=100)
    assert hard_comp.looks_like(ico1, a3)

    soft_comp = NNMatComparator(d=.0001)
    assert not soft_comp.looks_like(ico1, a3)
Esempio n. 3
0
    def looks_like(self, a1, a2):
        """ Return if structure a1 or a2 are similar or not. """
        elements = self.elements
        if elements == []:
            elements = sorted(set(a1.get_chemical_symbols()))
        a1, a2 = a1.copy(), a2.copy()
        del a1[[a.index for a in a1 if a.symbol not in elements]]
        del a2[[a.index for a in a2 if a.symbol not in elements]]

        nnmat_a1 = get_nnmat(a1)
        nnmat_a2 = get_nnmat(a2)

        diff = np.linalg.norm(nnmat_a1 - nnmat_a2)

        if diff < self.d:
            return True
        else:
            return False
Esempio n. 4
0
    def looks_like(self, a1, a2):
        """ Return if structure a1 or a2 are similar or not. """
        elements = self.elements
        if elements == []:
            elements = sorted(set(a1.get_chemical_symbols()))
        a1, a2 = a1.copy(), a2.copy()
        del a1[[a.index for a in a1 if a.symbol not in elements]]
        del a2[[a.index for a in a2 if a.symbol not in elements]]

        nnmat_a1 = get_nnmat(a1)
        nnmat_a2 = get_nnmat(a2)

        diff = np.linalg.norm(nnmat_a1 - nnmat_a2)

        if diff < self.d:
            return True
        else:
            return False
Esempio n. 5
0
from ase.cluster import Icosahedron
from ase.ga.particle_comparator import NNMatComparator
from ase.ga.utilities import get_nnmat
from ase.ga.particle_mutations import RandomPermutation

ico1 = Icosahedron('Cu', 4)
ico1.info['confid'] = 1
ico2 = Icosahedron('Ni', 4)
ico1.numbers[:55] = [28] * 55
ico2.numbers[:92] = [29] * 92

ico1.info['data'] = {}
ico1.info['data']['nnmat'] = get_nnmat(ico1)
ico2.info['data'] = {}
ico2.info['data']['nnmat'] = get_nnmat(ico2)
comp = NNMatComparator()
assert not comp.looks_like(ico1, ico2)

op = RandomPermutation()
a3, desc = op.get_new_individual([ico1])

assert a3.get_chemical_formula() == ico1.get_chemical_formula()

hard_comp = NNMatComparator(d=100)
assert hard_comp.looks_like(ico1, a3)

soft_comp = NNMatComparator(d=.0001)
assert not soft_comp.looks_like(ico1, a3)